bare-module 2.4.0 → 2.5.0

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 +28 -19
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -239,9 +239,10 @@ const Module = module.exports = exports = class Module {
239
239
  }
240
240
 
241
241
  let {
242
- imports = null,
243
- protocol = this._protocolFor(specifier, this._protocols['file:']),
244
242
  referrer = null,
243
+ protocol = this._protocolFor(specifier, this._protocols['file:']),
244
+ imports = null,
245
+ builtins = null,
245
246
  dynamic = false,
246
247
  main = referrer ? referrer._main : null,
247
248
  type = 0,
@@ -270,22 +271,26 @@ const Module = module.exports = exports = class Module {
270
271
 
271
272
  const module = this._cache[specifier] = new this(specifier)
272
273
 
273
- module._defaultType = defaultType
274
- module._main = main || module
275
- module._info = this._loadPackageManifest(path.dirname(module._filename), protocol)
274
+ if (builtins && specifier in builtins) {
275
+ module._exports = builtins[specifier]
276
+ } else {
277
+ module._defaultType = defaultType
278
+ module._main = main || module
279
+ module._info = this._loadPackageManifest(path.dirname(module._filename), protocol)
276
280
 
277
- let extension = this._extensionFor(type) || path.extname(specifier)
281
+ let extension = this._extensionFor(type) || path.extname(specifier)
278
282
 
279
- if (extension in this._extensions === false) {
280
- if (defaultType) extension = this._extensionFor(defaultType) || '.js'
281
- else extension = '.js'
282
- }
283
+ if (extension in this._extensions === false) {
284
+ if (defaultType) extension = this._extensionFor(defaultType) || '.js'
285
+ else extension = '.js'
286
+ }
283
287
 
284
- if (extension === '.bundle' && path.extname(specifier) !== extension) {
285
- throw errors.INVALID_BUNDLE_EXTENSION(`Invalid extension for bundle '${specifier}'`)
286
- }
288
+ if (extension === '.bundle' && path.extname(specifier) !== extension) {
289
+ throw errors.INVALID_BUNDLE_EXTENSION(`Invalid extension for bundle '${specifier}'`)
290
+ }
287
291
 
288
- this._extensions[extension].call(this, module, source, referrer, protocol, imports)
292
+ this._extensions[extension].call(this, module, source, referrer, protocol, imports)
293
+ }
289
294
 
290
295
  return this._transform(module, referrer, dynamic)
291
296
  }
@@ -320,9 +325,10 @@ const Module = module.exports = exports = class Module {
320
325
  }
321
326
 
322
327
  let {
323
- imports = null,
324
- protocol = this._protocols['file:'],
325
328
  referrer = null,
329
+ protocol = this._protocols['file:'],
330
+ imports = null,
331
+ builtins = null,
326
332
  conditions = ['import', 'require', 'bare', 'node']
327
333
  } = opts
328
334
 
@@ -344,7 +350,7 @@ const Module = module.exports = exports = class Module {
344
350
  })
345
351
  }
346
352
 
347
- const [resolved = null] = this._resolve(specifier, dirname, protocol, imports, conditions)
353
+ const [resolved = null] = this._resolve(specifier, dirname, protocol, imports, builtins, conditions)
348
354
 
349
355
  if (resolved === null) {
350
356
  let msg = `Cannot find module '${specifier}'`
@@ -357,7 +363,7 @@ const Module = module.exports = exports = class Module {
357
363
  return protocol.postresolve(resolved, dirname)
358
364
  }
359
365
 
360
- static * _resolve (specifier, dirname, protocol, imports, conditions) {
366
+ static * _resolve (specifier, dirname, protocol, imports, builtins, conditions) {
361
367
  const info = this._loadPackageManifest(dirname, protocol)
362
368
 
363
369
  specifier = this._mapConditionalSpecifier(
@@ -372,6 +378,8 @@ const Module = module.exports = exports = class Module {
372
378
 
373
379
  yield * protocol.resolve(specifier, dirname, imports)
374
380
 
381
+ if (builtins && specifier in builtins) yield specifier
382
+
375
383
  if (path.isAbsolute(specifier)) {
376
384
  yield * this._resolveFile(specifier, protocol)
377
385
  yield * this._resolveDirectory(specifier, protocol, conditions)
@@ -783,7 +791,8 @@ Module._protocols['file:'] = new Protocol({
783
791
  },
784
792
 
785
793
  postresolve (specifier) {
786
- return binding.realpath(specifier)
794
+ if (path.isAbsolute(specifier)) return binding.realpath(specifier)
795
+ return specifier
787
796
  },
788
797
 
789
798
  exists (filename) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [