bare-module 1.10.2 → 1.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +16 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,8 +6,9 @@ const errors = require('./lib/errors')
|
|
|
6
6
|
const binding = require('./binding')
|
|
7
7
|
|
|
8
8
|
const Module = module.exports = class Module {
|
|
9
|
-
constructor (filename) {
|
|
9
|
+
constructor (filename, main) {
|
|
10
10
|
this.filename = filename
|
|
11
|
+
this.main = main || this
|
|
11
12
|
this.exports = null
|
|
12
13
|
|
|
13
14
|
this._type = null
|
|
@@ -82,12 +83,21 @@ const Module = module.exports = class Module {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
meta.url = module.filename
|
|
86
|
+
meta.main = module.main === module
|
|
85
87
|
meta.resolve = resolve
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
static Protocol = Protocol
|
|
89
91
|
static Bundle = Bundle
|
|
90
92
|
|
|
93
|
+
static get cache () {
|
|
94
|
+
return this._cache
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static get builtinModules () {
|
|
98
|
+
return Object.keys(this._builtins)
|
|
99
|
+
}
|
|
100
|
+
|
|
91
101
|
static isBuiltin (name) {
|
|
92
102
|
return name in this._builtins
|
|
93
103
|
}
|
|
@@ -102,7 +112,8 @@ const Module = module.exports = class Module {
|
|
|
102
112
|
imports = this._imports,
|
|
103
113
|
protocol = this._protocolFor(specifier, this._protocols['file:']),
|
|
104
114
|
referrer = null,
|
|
105
|
-
dynamic = false
|
|
115
|
+
dynamic = false,
|
|
116
|
+
main = referrer ? referrer.main : null
|
|
106
117
|
} = opts
|
|
107
118
|
|
|
108
119
|
if (this._cache[specifier]) return this._transform(this._cache[specifier], referrer, dynamic)
|
|
@@ -123,7 +134,7 @@ const Module = module.exports = class Module {
|
|
|
123
134
|
})
|
|
124
135
|
}
|
|
125
136
|
|
|
126
|
-
const module = this._cache[specifier] = new this(specifier)
|
|
137
|
+
const module = this._cache[specifier] = new this(specifier, main)
|
|
127
138
|
|
|
128
139
|
let dirname = module.dirname
|
|
129
140
|
do {
|
|
@@ -427,7 +438,8 @@ Module._extensions['.cjs'] = function (module, source, referrer, protocol, impor
|
|
|
427
438
|
|
|
428
439
|
module.exports = {}
|
|
429
440
|
|
|
430
|
-
require.
|
|
441
|
+
require.main = module.main
|
|
442
|
+
require.cache = this.cache
|
|
431
443
|
require.resolve = resolve
|
|
432
444
|
|
|
433
445
|
binding.createFunction(module.filename, ['require', 'module', 'exports', '__filename', '__dirname'], source, 0)(
|