bare-module 1.13.3 → 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 +24 -5
  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
@@ -164,18 +164,35 @@ module.exports = exports = class Module {
164
164
  return name in this._builtins
165
165
  }
166
166
 
167
- 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
+
168
175
  const module = new Module(filename)
176
+
177
+ module._type = type
178
+ module._defaultType = defaultType
179
+ module._imports = imports
180
+ module._protocol = protocol
181
+
169
182
  const referrer = module
170
183
 
171
184
  const resolve = (specifier) => {
172
185
  return this.resolve(specifier, path.dirname(module._filename), {
186
+ protocol: this._protocolFor(specifier, protocol),
187
+ imports,
173
188
  referrer
174
189
  })
175
190
  }
176
191
 
177
192
  const require = (specifier) => {
178
193
  const module = this.load(resolve(specifier), {
194
+ protocol: this._protocolFor(specifier, protocol),
195
+ imports,
179
196
  referrer
180
197
  })
181
198
 
@@ -223,7 +240,7 @@ module.exports = exports = class Module {
223
240
  })
224
241
  }
225
242
 
226
- const module = this._cache[specifier] = new this(specifier, main)
243
+ const module = this._cache[specifier] = new this(specifier)
227
244
 
228
245
  module._defaultType = defaultType
229
246
 
@@ -244,6 +261,8 @@ module.exports = exports = class Module {
244
261
  if (specifier in this._builtins) {
245
262
  module._exports = this._builtins[specifier]
246
263
  } else {
264
+ module._main = main || module
265
+
247
266
  let extension = this._extensionFor(type) || path.extname(specifier)
248
267
 
249
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.3",
3
+ "version": "1.13.4",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [