bare-module 2.8.0 → 2.8.2

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 +23 -26
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -97,25 +97,13 @@ const Module = module.exports = exports = class Module {
97
97
  Module._modules.delete(this)
98
98
  }
99
99
 
100
- _transform (referrer = null, dynamic = false) {
101
- if (dynamic) {
100
+ _transform (isImport, isDynamicImport) {
101
+ if (isDynamicImport) {
102
102
  this._synthesize()
103
103
  this._evaluate()
104
-
105
- return this
106
- }
107
-
108
- if (referrer) {
109
- if (referrer._type === constants.types.MODULE) {
110
- this._synthesize()
111
- } else if (this._type === constants.types.MODULE) {
112
- this._evaluate()
113
- }
114
-
115
- return this
116
- }
117
-
118
- if (this._type === constants.types.MODULE) {
104
+ } else if (isImport) {
105
+ this._synthesize()
106
+ } else if (this._type === constants.types.MODULE) {
119
107
  this._evaluate()
120
108
  }
121
109
 
@@ -171,16 +159,20 @@ const Module = module.exports = exports = class Module {
171
159
  static _protocols = Object.create(null)
172
160
  static _cache = Object.create(null)
173
161
  static _modules = new Set()
174
- static _conditions = ['import', 'require', 'bare', 'node']
162
+ static _conditions = ['bare', 'node']
175
163
 
176
164
  static _handle = binding.init(this, this._onimport, this._onevaluate, this._onmeta)
177
165
 
178
- static _onimport (specifier, assertions, referrerFilename, dynamic) {
166
+ static _onimport (specifier, assertions, referrerFilename, isDynamicImport) {
179
167
  const referrer = this._cache[referrerFilename]
180
168
 
181
169
  const protocol = this._protocolFor(specifier, referrer._protocol)
182
170
 
183
- specifier = this.resolve(specifier, { protocol, referrer })
171
+ specifier = this.resolve(specifier, {
172
+ isImport: true,
173
+ protocol,
174
+ referrer
175
+ })
184
176
 
185
177
  let type
186
178
 
@@ -194,9 +186,10 @@ const Module = module.exports = exports = class Module {
194
186
  }
195
187
 
196
188
  const module = this.load(specifier, {
189
+ isImport: true,
190
+ isDynamicImport,
197
191
  protocol: this._protocolFor(specifier, protocol),
198
192
  referrer,
199
- dynamic,
200
193
  type
201
194
  })
202
195
 
@@ -328,7 +321,9 @@ const Module = module.exports = exports = class Module {
328
321
  }
329
322
 
330
323
  let {
331
- dynamic = false,
324
+ isImport = false,
325
+ isDynamicImport = false,
326
+
332
327
  referrer = null,
333
328
  type = 0,
334
329
  defaultType = referrer ? referrer._defaultType : 0,
@@ -340,7 +335,7 @@ const Module = module.exports = exports = class Module {
340
335
  conditions = referrer ? referrer._conditions : self._conditions
341
336
  } = opts
342
337
 
343
- if (self._cache[specifier]) return self._cache[specifier]._transform(referrer, dynamic)
338
+ if (self._cache[specifier]) return self._cache[specifier]._transform(isImport, isDynamicImport)
344
339
 
345
340
  const bundle = self._bundleFor(path.dirname(specifier), protocol)
346
341
 
@@ -373,7 +368,7 @@ const Module = module.exports = exports = class Module {
373
368
  self._extensions[extension](module, source, referrer)
374
369
  }
375
370
 
376
- return module._transform(referrer, dynamic)
371
+ return module._transform(isImport, isDynamicImport)
377
372
  }
378
373
 
379
374
  static resolve (specifier, dirname = null, opts = {}) {
@@ -383,12 +378,14 @@ const Module = module.exports = exports = class Module {
383
378
  throw new TypeError(`Specifier must be a string. Received type ${typeof specifier} (${specifier})`)
384
379
  }
385
380
 
386
- if (typeof dirname !== 'string') {
381
+ if (typeof dirname !== 'string' && dirname !== null) {
387
382
  opts = dirname
388
383
  dirname = null
389
384
  }
390
385
 
391
386
  let {
387
+ isImport = false,
388
+
392
389
  referrer = null,
393
390
  protocol = referrer ? referrer._protocol : self._protocols['file:'],
394
391
  imports = referrer ? referrer._imports : null,
@@ -429,7 +426,7 @@ const Module = module.exports = exports = class Module {
429
426
  }
430
427
 
431
428
  for (const resolution of resolve(resolved, parentURL, {
432
- conditions,
429
+ conditions: isImport ? ['import', ...conditions] : ['require', ...conditions],
433
430
  imports,
434
431
  resolutions,
435
432
  builtins: builtins ? Object.keys(builtins) : [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [