bare-module 1.13.2 → 1.13.4

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.
Files changed (2) hide show
  1. package/index.js +25 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -8,12 +8,12 @@ const errors = require('./lib/errors')
8
8
  const binding = require('./binding')
9
9
 
10
10
  module.exports = exports = class Module {
11
- constructor (filename, main) {
11
+ constructor (filename) {
12
+ this._filename = filename
12
13
  this._state = 0
13
14
  this._type = 0
14
15
  this._defaultType = this._type
15
- this._filename = filename
16
- this._main = main || this
16
+ this._main = null
17
17
  this._exports = null
18
18
  this._imports = null
19
19
  this._info = null
@@ -49,10 +49,6 @@ module.exports = exports = class Module {
49
49
  this._exports = value
50
50
  }
51
51
 
52
- get imports () {
53
- return this._imports
54
- }
55
-
56
52
  // For Node.js compatibility
57
53
  get id () {
58
54
  return this.filename
@@ -72,8 +68,7 @@ module.exports = exports = class Module {
72
68
  filename: this.filename,
73
69
  dirname: this.dirname,
74
70
  main: this.main,
75
- exports: this.exports,
76
- imports: this.imports
71
+ exports: this.exports
77
72
  }
78
73
  }
79
74
 
@@ -169,18 +164,35 @@ module.exports = exports = class Module {
169
164
  return name in this._builtins
170
165
  }
171
166
 
172
- static createRequire (filename) {
167
+ static createRequire (filename, opts = {}) {
168
+ const {
169
+ imports = this._imports,
170
+ protocol = this._protocolFor(filename, this._protocols['file:']),
171
+ type = constants.types.SCRIPT,
172
+ defaultType = constants.types.SCRIPT
173
+ } = opts
174
+
173
175
  const module = new Module(filename)
176
+
177
+ module._type = type
178
+ module._defaultType = defaultType
179
+ module._imports = imports
180
+ module._protocol = protocol
181
+
174
182
  const referrer = module
175
183
 
176
184
  const resolve = (specifier) => {
177
185
  return this.resolve(specifier, path.dirname(module._filename), {
186
+ protocol: this._protocolFor(specifier, protocol),
187
+ imports,
178
188
  referrer
179
189
  })
180
190
  }
181
191
 
182
192
  const require = (specifier) => {
183
193
  const module = this.load(resolve(specifier), {
194
+ protocol: this._protocolFor(specifier, protocol),
195
+ imports,
184
196
  referrer
185
197
  })
186
198
 
@@ -228,7 +240,7 @@ module.exports = exports = class Module {
228
240
  })
229
241
  }
230
242
 
231
- const module = this._cache[specifier] = new this(specifier, main)
243
+ const module = this._cache[specifier] = new this(specifier)
232
244
 
233
245
  module._defaultType = defaultType
234
246
 
@@ -249,6 +261,8 @@ module.exports = exports = class Module {
249
261
  if (specifier in this._builtins) {
250
262
  module._exports = this._builtins[specifier]
251
263
  } else {
264
+ module._main = main || module
265
+
252
266
  let extension = this._extensionFor(type) || path.extname(specifier)
253
267
 
254
268
  if (extension in this._extensions === false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "1.13.2",
3
+ "version": "1.13.4",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [