Skip to content

Commit 3d8abbc

Browse files
committed
Merge branch 'master' into develop
* master: Fixed SBT dependency Continued development 1. Added puny code (although it’s deprecated) 2. Fixes on stream.Writable class 3. Fixes for setInterval function 4. Fixed issue with process.hrtime() Pre-release v0.4.0-pre3: Miscellaneous fixes in OS and Stream packages Improved the repl binding # Conflicts: # src/main/scala/io/scalajs/nodejs/stream/Writable.scala
2 parents 54ae6f7 + 5a37777 commit 3d8abbc

File tree

18 files changed

+245
-96
lines changed

18 files changed

+245
-96
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ The following applications were developed using ScalaJs.io:
7676
| Application | Frontend | Backend | Scalajs.io version | Description |
7777
|------------------------------------------------------------------------|-----------------------|--------------------|--------------------|------------------------------------------|
7878
| [Phaser-Invaders](https://github.com/scalajs-io/phaser-invaders-demo) | Scala.js + DOM | Scala + NodeJS | 0.3.0.1 | Port of Phaser Invaders. |
79-
| [Socialize](https://github.com/ldaniels528/scalajs-nodejs-socialized) | Scala.js + AngularJS | Scala.js + NodeJS | 0.3.0.3 | A Facebook-inspired Social networking web application. |
80-
| [Todo MVC](https://github.com/ldaniels528/scalajs-nodejs-todomvc) | Scala.js + AngularJS | Scala.js + NodeJS | 0.2.3.1 | A simple Todo example application. |
81-
| [Trifecta](https://github.com/ldaniels528/trifecta) | Scala.js + AngularJS | Scala + Play 2.4.x | 0.3.0.0 | Trifecta is a web-based and CLI tool that simplifies inspecting Kafka messages and Zookeeper data. |
79+
| [Socialize](https://github.com/scalajs-io/scalajs-nodejs-socialized) | Scala.js + AngularJS | Scala.js + NodeJS | 0.3.0.3 | A Facebook-inspired Social networking web application. |
80+
| [Todo MVC](https://github.com/scalajs-io/scalajs-nodejs-todomvc) | Scala.js + AngularJS | Scala.js + NodeJS | 0.2.3.1 | A simple Todo example application. |
81+
| [Trifecta](https://github.com/scalajs-io/trifecta) | Scala.js + AngularJS | Scala + Play 2.4.x | 0.3.0.0 | Trifecta is a web-based and CLI tool that simplifies inspecting Kafka messages and Zookeeper data. |
8282

8383
### The MEAN Stack — AngularJS, MongoDB, Mongoose, Express and more
8484

@@ -101,7 +101,7 @@ The following applications were developed using ScalaJs.io:
101101
| [mongoose](https://github.com/scalajs-io/mongoose) | 4.8.1 | Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. |
102102
| [mpromise](https://github.com/scalajs-io/mpromise) | 0.5.5 | A promises/A+ conformant implementation, written for mongoose. |
103103

104-
Looking for a complete list of available bindings? Go [here](https://github.com/scalajs-io/scalajs.io-platform)
104+
Looking for a complete list of available bindings? Go [here](https://github.com/scalajs-io/scalajs-io-platform)
105105

106106
<a name="discussions"></a>
107107
### Discussions
@@ -231,7 +231,7 @@ The following core Node.js modules (v7.7.1) have been implemented:
231231
| vm | The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts.|
232232
| zlib | This provides bindings to Gzip/Gunzip, Deflate/Inflate, and DeflateRaw/InflateRaw classes. |
233233

234-
*NOTE*: The SBT artifact for the complete Node.js platform is: "io.scalajs.npm" %%% "nodejs" % "0.4.0-pre2"
234+
*NOTE*: The SBT artifact for the complete Node.js platform is: "io.scalajs" %%% "nodejs" % "0.4.0-pre4"
235235

236236
<a name="npm_modules">
237237
#### Third-party Modules
@@ -298,7 +298,7 @@ The following Third Party/OSS Node.js (npm) modules have been implemented:
298298
| [winston-daily-rotate-file](https://github.com/scalajs-io/winston-daily-rotate-file) | 1.4.4 | A multi-transport async logging library for Node.js. |
299299
| [xml2js](https://github.com/scalajs-io/xml2js) | 0.4.16 | Simple XML to JavaScript object converter. |
300300

301-
*NOTE*: The full SBT artifact expression is: "io.scalajs.npm" %%% "xxxx" % version (e.g. "io.scalajs.npm" %%% "express" % "0.4.0-pre2")
301+
*NOTE*: The full SBT artifact expression is: "io.scalajs.npm" %%% "xxxx" % version (e.g. "io.scalajs.npm" %%% "express" % "0.4.0-pre4")
302302

303303
I've provided an example to demonstrate how similar the Scala.js code is to the JavaScript
304304
that it replaces.

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import sbt._
55

66
import scala.language.postfixOps
77

8-
val scalaJsIOVersion = "0.4.0-pre2"
8+
val scalaJsIOVersion = "0.4.0-pre4"
99
val apiVersion = scalaJsIOVersion
1010
val scalaJsVersion = "2.12.1"
1111

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodejs-sfs",
3-
"version": "0.4.0-pre2",
3+
"version": "0.4.0-pre4",
44
"private": true,
55
"dependencies": {
66
"source-map": "^0.5.6"

src/main/scala/io/scalajs/nodejs/Process.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ trait Process extends IEventEmitter {
5353
/**
5454
* An object containing the user environment.
5555
*/
56-
def env: js.Dictionary[String] = js.native
56+
def env: Environment = js.native
5757

5858
/**
5959
* This is the set of Node.js-specific command line options from the executable that started the process.
@@ -245,9 +245,9 @@ trait Process extends IEventEmitter {
245245
* Returns the current high-resolution real time in a [seconds, nanoseconds] tuple Array. It is relative to an
246246
* arbitrary time in the past. It is not related to the time of day and therefore not subject to clock drift.
247247
* The primary use is for measuring performance between intervals.
248-
* @example process.hrtime()
248+
* @example process.hrtime([time])
249249
*/
250-
def hrtime(): js.Array[Int] = js.native
250+
def hrtime(time: js.Array[Int] = js.native): js.Array[Int] = js.native
251251

252252
/**
253253
* Reads /etc/group and initializes the group access list, using all groups of which the user is a member.

src/main/scala/io/scalajs/nodejs/fs/Fs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ trait Fs extends IEventEmitter {
674674
* data will be read from the current file position.
675675
* @return the number of bytesRead.
676676
*/
677-
def readSync(fd: FileDescriptor, buffer: Buffer, offset: Int, length: Int, position: Int): Buffer = js.native
677+
def readSync(fd: FileDescriptor, buffer: Buffer, offset: Int, length: Int, position: Int): Int = js.native
678678

679679
/**
680680
* Asynchronous readdir(3). Reads the contents of a directory.

src/main/scala/io/scalajs/nodejs/package.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package object nodejs {
1818
*/
1919
type FileDescriptor = Integer
2020

21+
type Environment = js.Dictionary[String]
22+
2123
/////////////////////////////////////////////////////////////////////////////////
2224
// Built-in Properties
2325
/////////////////////////////////////////////////////////////////////////////////
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package io.scalajs.nodejs.punycode
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSImport
5+
6+
/**
7+
* The version of the punycode module bundled in Node.js is being deprecated. In a future major version of Node.js
8+
* this module will be removed. Users currently depending on the punycode module should switch to using the
9+
* userland-provided Punycode.js module instead.
10+
* @see https://nodejs.org/dist/latest-v7.x/docs/api/punycode.html
11+
*/
12+
@js.native
13+
trait Punycode extends js.Object {
14+
15+
/**
16+
* The punycode.decode() method converts a Punycode string of ASCII-only characters to the equivalent
17+
* string of Unicode codepoints.
18+
* @param string a Punycode string of ASCII-only characters
19+
* @return the equivalent string of Unicode codepoints.
20+
*/
21+
def decode(string: String): String = js.native
22+
23+
/**
24+
* The punycode.encode() method converts a string of Unicode codepoints to a Punycode string of ASCII-only characters.
25+
* @param codePoints a string of Unicode codepoints
26+
* @return a Punycode string of ASCII-only characters.
27+
*/
28+
def encode(codePoints: String): String = js.native
29+
30+
/**
31+
* The punycode.toASCII() method converts a Unicode string representing an Internationalized Domain Name to Punycode.
32+
* Only the non-ASCII parts of the domain name will be converted. Calling punycode.toASCII() on a string that already
33+
* only contains ASCII characters will have no effect.
34+
* @param domain the domain name
35+
* @return a Unicode string representing an Internationalized Domain Name as Punycode
36+
*/
37+
def toASCII(domain: String): String = js.native
38+
39+
/**
40+
* The punycode.toUnicode() method converts a string representing a domain name containing Punycode encoded
41+
* characters into Unicode. Only the Punycode encoded parts of the domain name are be converted.
42+
* @param domain a string representing a domain name containing Punycode encoded characters
43+
* @return the Unicode string
44+
*/
45+
def toUnicode(domain: String): String = js.native
46+
47+
/**
48+
* The UCS2 object
49+
* @return The [[UCS2 UCS2]] object
50+
*/
51+
def ucs2: UCS2 = js.native
52+
53+
/**
54+
* Returns a string identifying the current Punycode.js version number.
55+
* @return a string identifying the current Punycode.js version number.
56+
*/
57+
def version: String = js.native
58+
59+
}
60+
61+
/**
62+
* Punycode.UCS2
63+
* @see https://nodejs.org/dist/latest-v7.x/docs/api/punycode.html
64+
*/
65+
@js.native
66+
trait UCS2 extends js.Object {
67+
68+
/**
69+
* The punycode.ucs2.decode() method returns an array containing the numeric codepoint values of each Unicode
70+
* symbol in the string.
71+
* @param string the string containing Unicode symbols
72+
* @return an array containing the numeric codepoint values of each Unicode symbol
73+
*/
74+
def decode(string: String): js.Array[Int] = js.native
75+
76+
/**
77+
* The punycode.ucs2.encode() method returns a string based on an array of numeric code point values.
78+
* @param codePoints an array of numeric code point values
79+
* @return a string based on an array of numeric code point values
80+
*/
81+
def encode(codePoints: js.Array[Int]): String = js.native
82+
83+
}
84+
85+
@js.native
86+
@JSImport("punycode", JSImport.Namespace)
87+
object Punycode extends Punycode

src/main/scala/io/scalajs/nodejs/repl/REPL.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import scala.scalajs.js.|
1818
trait REPL extends IEventEmitter {
1919
var REPL_MODE_SLOPPY: String = js.native
2020
var REPL_MODE_STRICT: String = js.native
21-
var REPL_MODE_MAGIC: String = js.native
21+
var REPL_MODE_MAGIC: String = js.native
2222

2323
/**
2424
* @example repl.start([options])

src/main/scala/io/scalajs/nodejs/repl/REPLServer.scala

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,34 @@ trait REPLServer extends IEventEmitter with Interface {
1515
/**
1616
* The REPL's context
1717
*/
18-
// TODO find document for this property
19-
val context: js.Dynamic = js.native
18+
val context: REPLContext = js.native
2019

2120
/**
22-
* Makes a command available in the REPL. The command is invoked by typing a . followed by the keyword.
23-
* The cmd is an object with the following values:
21+
* The replServer.defineCommand() method is used to add new .-prefixed commands to the REPL instance.
22+
* Such commands are invoked by typing a period (.) followed by the keyword. The cmd is either a Function
23+
* or an object with the following properties:
2424
* <ul>
25-
* <li>help - help text to be displayed when .help is entered (Optional).</li>
26-
* <li>action - a function to execute, potentially taking in a string argument, when the command is invoked,
27-
* bound to the REPLServer instance (Required).</li>
25+
* <li>help (string) Help text to be displayed when .help is entered (Optional).</li>
26+
* <li>action (Function) The function to execute, optionally accepting a single string argument.</li>
2827
* </ul>
29-
* If a function is provided instead of an object for cmd, it is treated as the action.
30-
* @example replServer.defineCommand(keyword, cmd)
28+
* @param keyword The command keyword (without a leading . character).
29+
* @param cmd The function to invoke when the command is processed.
3130
*/
32-
def defineCommand(keyword: String, cmd: js.Any): Unit = js.native
31+
def defineCommand(keyword: String, cmd: js.Function0[Any]): Unit = js.native
3332

3433
/**
35-
* Like readline.prompt except also adding indents with ellipses when inside blocks. The preserveCursor argument
36-
* is passed to readline.prompt. This is used primarily with defineCommand. It's also used internally to render
37-
* each prompt line.
38-
* @example replServer.displayPrompt([preserveCursor])
39-
* @see [[prompt()]]
34+
* The replServer.displayPrompt() method readies the REPL instance for input from the user, printing the
35+
* configured prompt to a new line in the output and resuming the input to accept new input.
36+
*
37+
* When multi-line input is being entered, an ellipsis is printed rather than the 'prompt'.
38+
* *
39+
* When preserveCursor is true, the cursor placement will not be reset to 0.
40+
*
41+
* The replServer.displayPrompt method is primarily intended to be called from within the action function
42+
* for commands registered using the replServer.defineCommand() method.
43+
* @param preserveCursor indicates whether to preserver the cursor (position?)
4044
*/
41-
def displayPrompt(preserveCursor: Boolean): Unit = js.native
45+
def displayPrompt(preserveCursor: Boolean = js.native): Unit = js.native
4246

4347
/**
4448
* Like readline.prompt except also adding indents with ellipses when inside blocks. The preserveCursor argument
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package io.scalajs.nodejs
2+
3+
import scala.scalajs.js
4+
5+
/**
6+
* repl package object
7+
* @author lawrence.daniels@gmail.com
8+
*/
9+
package object repl {
10+
11+
type REPLContext = js.Dynamic
12+
13+
/**
14+
* REPL Server events
15+
* @param server the given [[REPLServer instance]]
16+
*/
17+
final implicit class REPLServerEvents(val server: REPLServer) extends AnyVal {
18+
19+
@inline
20+
def contextAs[T]: T = server.context.asInstanceOf[T]
21+
22+
/**
23+
* The 'exit' event is emitted when the REPL is exited either by receiving the .exit command as input,
24+
* the user pressing CTRL-C twice to signal SIGINT, or by pressing CTRL-D to signal 'end' on the input stream.
25+
* The listener callback is invoked without any arguments.
26+
* @param listener The listener callback
27+
*/
28+
@inline
29+
def onExit(listener: () => Any): server.type = server.on("exit", listener)
30+
31+
/**
32+
* The 'reset' event is emitted when the REPL's context is reset. This occurs whenever the .clear command
33+
* is received as input unless the REPL is using the default evaluator and the repl.REPLServer instance
34+
* was created with the useGlobal option set to true. The listener callback will be called with a reference
35+
* to the context object as the only argument.
36+
* @param listener The listener callback
37+
*/
38+
@inline
39+
def onReset(listener: REPLContext => Any): server.type = server.on("reset", listener)
40+
41+
}
42+
43+
/**
44+
* Various behaviors of the Node.js REPL can be customized using the following environment variables:
45+
* <ul>
46+
* <li>NODE_REPL_HISTORY</li>
47+
* <li>NODE_REPL_HISTORY_SIZE</li>
48+
* <li>NODE_REPL_MODE</li>
49+
* </ul>
50+
*/
51+
final implicit class EnvironmentVariableOptions(val env: Environment) extends AnyVal {
52+
53+
/**
54+
* When a valid path is given, persistent REPL history will be saved to the specified file rather
55+
* than .node_repl_history in the user's home directory. Setting this value to "" will disable persistent
56+
* REPL history. Whitespace will be trimmed from the value.
57+
*/
58+
@inline
59+
def NODE_REPL_HISTORY: Option[String] = env.get("NODE_REPL_HISTORY")
60+
61+
/**
62+
* Previously in Node.js/io.js v2.x, REPL history was controlled by using a NODE_REPL_HISTORY_FILE environment
63+
* variable, and the history was saved in JSON format. This variable has now been deprecated, and the old
64+
* JSON REPL history file will be automatically converted to a simplified plain text format. This new file
65+
* will be saved to either the user's home directory, or a directory defined by the NODE_REPL_HISTORY variable,
66+
* as documented in the Environment Variable Options.
67+
*/
68+
@inline
69+
@deprecated("Use NODE_REPL_HISTORY instead.", since = "3.0.0")
70+
def NODE_REPL_HISTORY_FILE: Option[String] = env.get("NODE_REPL_HISTORY_FILE")
71+
72+
/**
73+
* Defaults to 1000. Controls how many lines of history will be persisted if history is available.
74+
* Must be a positive number.
75+
*/
76+
@inline
77+
def NODE_REPL_HISTORY_SIZE: Option[Int] = env.get("NODE_REPL_HISTORY_SIZE").map(_.toInt)
78+
79+
/**
80+
* May be any of sloppy, strict, or magic. Defaults to magic, which will automatically run "strict mode only"
81+
* statements in strict mode.
82+
*/
83+
@inline
84+
def NODE_REPL_MODE: Option[String] = env.get("NODE_REPL_MODE")
85+
86+
}
87+
88+
}

src/main/scala/io/scalajs/nodejs/stream/Writable.scala

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package io.scalajs.nodejs
22
package stream
33

4-
import io.scalajs.util.PromiseHelper._
5-
import io.scalajs.util.PromiseHelper.Implicits._
64
import io.scalajs.nodejs.buffer.Buffer
75
import io.scalajs.nodejs.events.IEventEmitter
6+
import io.scalajs.util.PromiseHelper._
87

98
import scala.concurrent.Promise
109
import scala.scalajs.js
@@ -136,6 +135,24 @@ trait Writable extends IEventEmitter {
136135
*/
137136
def uncork(): Unit = js.native
138137

138+
/**
139+
* Flush all data, buffered since stream.cork() call.
140+
* @param chunk The data to write (<String> | <Buffer>)
141+
* @param callback the Callback for when this chunk of data is flushed
142+
* @return true, if the data was handled completely
143+
* @example writable.write(chunk[, encoding][, callback])
144+
*/
145+
def write(chunk: Buffer | String, callback: js.Function1[Error, Any] = js.native): Boolean = js.native
146+
147+
/**
148+
* Flush all data, buffered since stream.cork() call.
149+
* @param chunk The data to write (<String> | <Buffer>)
150+
* @param encoding The encoding, if chunk is a String
151+
* @return true, if the data was handled completely
152+
* @example writable.write(chunk[, encoding][, callback])
153+
*/
154+
def write(chunk: Buffer | String, encoding: String): Boolean = js.native
155+
139156
/**
140157
* Flush all data, buffered since stream.cork() call.
141158
* @param chunk The data to write (<String> | <Buffer>)
@@ -145,8 +162,8 @@ trait Writable extends IEventEmitter {
145162
* @example writable.write(chunk[, encoding][, callback])
146163
*/
147164
def write(chunk: Buffer | String,
148-
encoding: String = js.native,
149-
callback: js.Function1[Error, Any] = js.native): Boolean = js.native
165+
encoding: String,
166+
callback: js.Function1[Error, Any]): Boolean = js.native
150167

151168
}
152169

@@ -160,7 +177,7 @@ object Writable {
160177
* Writable Events
161178
* @author lawrence.daniels@gmail.com
162179
*/
163-
implicit class WritableEvents(val writable: Writable) extends AnyVal {
180+
implicit class WritableEvents[T <: Writable](val writable: T) extends AnyVal {
164181

165182
/**
166183
* Emitted when the stream and any of its underlying resources (a file descriptor, for example) have been closed.
@@ -209,7 +226,7 @@ object Writable {
209226
* Writable Extensions
210227
* @author lawrence.daniels@gmail.com
211228
*/
212-
implicit class WritableExtensions(val writable: Writable) extends AnyVal {
229+
implicit class WritableExtensions[T <: Writable](val writable: T) extends AnyVal {
213230

214231
@inline
215232
def endAsync(chunk: Buffer): Promise[Unit] = promiseWithError0[Error](writable.end(chunk, _))

0 commit comments

Comments
 (0)