This repository was archived by the owner on Jul 30, 2024. It is now read-only.
File tree 5 files changed +98
-18
lines changed
main/scala/io/scalajs/nodejs
test/scala/io/scalajs/nodejs/module 5 files changed +98
-18
lines changed Original file line number Diff line number Diff line change 1
1
package io .scalajs .nodejs
2
2
3
- import com .thoughtworks .enableIf
4
-
5
3
import scala .scalajs .js
6
- import scala .scalajs .js .annotation .JSImport
7
4
8
5
/**
9
6
* In each module, the module free variable is a reference to the object representing the current module.
@@ -27,7 +24,7 @@ trait Module extends js.Object {
27
24
* the local exports variable, which is probably not what you want to do.
28
25
* @example module.exports
29
26
*/
30
- var exports : js.Dictionary [js. Any ] = js.native
27
+ var exports : js.Object = js.native
31
28
32
29
/**
33
30
* The fully resolved filename to the module.
@@ -62,19 +59,5 @@ trait Module extends js.Object {
62
59
* explicitly exported in order to be used.
63
60
*/
64
61
def require [T <: js.Any ](id : String ): T = js.native
65
- }
66
-
67
- /**
68
- * Module Companion
69
- */
70
- @ js.native
71
- @ JSImport (" module" , JSImport .Namespace )
72
- object Module extends Module {
73
- var builtinModules : js.Array [String ] = js.native
74
-
75
- @ enableIf(io.scalajs.nodejs.internal.CompilerSwitches .gteNodeJs12)
76
- def createRequire (filename : String ): Require = js.native
77
62
78
- @ enableIf(io.scalajs.nodejs.internal.CompilerSwitches .gteNodeJs12)
79
- def createRequire (filename : io.scalajs.nodejs.url.URL ): Require = js.native
80
63
}
Original file line number Diff line number Diff line change
1
+ package io .scalajs .nodejs .module
2
+
3
+ import com .thoughtworks .enableIf
4
+ import io .scalajs .nodejs .Require
5
+
6
+ import scala .scalajs .js
7
+ import scala .scalajs .js .annotation .JSImport
8
+
9
+ @ js.native
10
+ @ JSImport (" module" , JSImport .Namespace )
11
+ object Module extends js.Object {
12
+ var builtinModules : js.Array [String ] = js.native
13
+
14
+ @ enableIf(io.scalajs.nodejs.internal.CompilerSwitches .gteNodeJs12)
15
+ def createRequire (filename : String ): Require = js.native
16
+
17
+ @ enableIf(io.scalajs.nodejs.internal.CompilerSwitches .gteNodeJs12)
18
+ def createRequire (filename : io.scalajs.nodejs.url.URL ): Require = js.native
19
+
20
+ @ enableIf(io.scalajs.nodejs.internal.CompilerSwitches .gteNodeJs12)
21
+ def syncBuiltinESMExports (): Unit = js.native
22
+
23
+ @ deprecated(" Use createRequire" , " Node.js v12.2.0" )
24
+ def createRequireFromPath (filename : String ): Require = js.native
25
+
26
+ @ enableIf(io.scalajs.nodejs.internal.CompilerSwitches .gteNodeJs14)
27
+ def findSourceMap (path : String ): SourceMap = js.native
28
+
29
+ @ enableIf(io.scalajs.nodejs.internal.CompilerSwitches .gteNodeJs14)
30
+ def findSourceMap (path : String , error : io.scalajs.nodejs.Error ): SourceMap = js.native
31
+ }
Original file line number Diff line number Diff line change
1
+ package io .scalajs .nodejs .module
2
+
3
+ import com .thoughtworks .enableMembersIf
4
+ import net .exoego .scalajs .types .util .Factory
5
+
6
+ import scala .scalajs .js
7
+ import scala .scalajs .js .annotation .JSImport
8
+
9
+ @ js.native
10
+ @ enableMembersIf(io.scalajs.nodejs.internal.CompilerSwitches .gteNodeJs14)
11
+ @ JSImport (" module" , " SourceMap" )
12
+ class SourceMap (payload : SourceMapPayload ) extends js.Object {
13
+ def payload : SourceMapPayload = js.native
14
+ def findEntry (lineNumber : Int , columnNumber : Int ): SourceMapEntry = js.native
15
+ }
16
+
17
+ @ Factory
18
+ trait SourceMapPayload extends js.Object {
19
+ var file : String
20
+ var version : Double
21
+ var sources : js.Array [String ]
22
+ var sourcesContent : js.Array [String ]
23
+ var names : js.Array [String ]
24
+ var mappings : String
25
+ var sourceRoot : String
26
+ }
27
+
28
+ @ Factory
29
+ trait SourceMapEntry extends js.Object {
30
+ var generatedLine : Int
31
+ var generatedColumn : Int
32
+ var originalSource : String
33
+ var originalLine : Int
34
+ var originalColumn : Int
35
+ }
Original file line number Diff line number Diff line change @@ -102,4 +102,11 @@ package object nodejs {
102
102
@ inline
103
103
def toException (): Exception = js.JavaScriptException (error.message)
104
104
}
105
+
106
+ @ js.native
107
+ @ JSGlobal (" module" )
108
+ object moduleObject extends io.scalajs.nodejs.Module
109
+
110
+ @ deprecated(" Use io.scalajs.nodejs.module.Module" , " v0.13.0" )
111
+ val Module = io.scalajs.nodejs.module.Module
105
112
}
Original file line number Diff line number Diff line change
1
+ package io .scalajs .nodejs .module
2
+
3
+ import org .scalatest .funspec .AnyFunSpec
4
+
5
+ import scala .scalajs .js
6
+
7
+ class ModuleTest extends AnyFunSpec {
8
+ describe(" Module Object (module module)" ) {
9
+ it(" builtinModules" ) {
10
+ assert(io.scalajs.nodejs.module.Module .builtinModules.length >= 30 )
11
+ }
12
+ }
13
+
14
+ describe(" module Object" ) {
15
+ it(" children" ) {
16
+ // contents vary on runtime
17
+ assert(io.scalajs.nodejs.moduleObject.children.isInstanceOf [js.Array [_]])
18
+ }
19
+ it(" filename" ) {
20
+ // contents vary on runtime
21
+ assert(io.scalajs.nodejs.moduleObject.filename.nonEmpty)
22
+ }
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments