bare-module 6.1.2 → 6.1.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.
Files changed (3) hide show
  1. package/README.md +32 -32
  2. package/index.js +1 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -131,7 +131,7 @@ The following conditions are supported, listed in order from most specific to le
131
131
  | `"node"` | Matches for any Node.js environment. |
132
132
  | `"<platform>"` | Matches when equal to `Bare.platform`. See [`Bare.platform`](https://github.com/holepunchto/bare#bareplatform) for possible values. |
133
133
  | `"<arch>"` | Matches when equal to `Bare.arch`. See [`Bare.arch`](https://github.com/holepunchto/bare#barearch) for possible values. |
134
- | `"simulator"` | Matches when Bare was compiled for a simulator, i.e. when `Bare.simulator` is `true`. |
134
+ | `"simulator"` | Matches when Bare was compiled for a simulator. |
135
135
  | `"default"` | The fallback that always matches. This condition should always be last. |
136
136
 
137
137
  Export conditions are evaluated in the order they are defined in the `"exports"` field. This means that less specific conditionals defined first will override more specific conditions define later. For example, the following will always call `./fallback.js` because `"default"` always matches and is defined first.
@@ -237,7 +237,7 @@ The following conditions are supported, listed in order from most specific to le
237
237
  | `"node"` | Matches for any Node.js environment. |
238
238
  | `"<platform>"` | Matches when equal to `Bare.platform`. See [`Bare.platform`](https://github.com/holepunchto/bare#bareplatform) for possible values. |
239
239
  | `"<arch>"` | Matches when equal to `Bare.arch`. See [`Bare.arch`](https://github.com/holepunchto/bare#barearch) for possible values. |
240
- | `"simulator"` | Matches when Bare was compiled for a simulator, ie when `Bare.simulator` is `true`. |
240
+ | `"simulator"` | Matches when Bare was compiled for a simulator. |
241
241
  | `"default"` | The fallback that always matches. This condition should always be last. |
242
242
 
243
243
  The general rule is that conditions should be from most specific to least specific when defined.
@@ -332,6 +332,30 @@ options = {
332
332
  }
333
333
  ```
334
334
 
335
+ #### `const url = Module.asset(specifier, parentURL[, options])`
336
+
337
+ Get the asset URL by resolving `specifier` relative to `parentURL`. `specifier` is a string and `parentURL` is a WHATWG `URL`.
338
+
339
+ Options include:
340
+
341
+ ```js
342
+ options = {
343
+ // The referring module.
344
+ referrer: null,
345
+ // The ModuleProtocol to use resolve the specifier. Defaults to referrer's
346
+ // protocol if defined, otherwise defaults to Module.protocol
347
+ protocol,
348
+ // A default "imports" map to apply to all specifiers. Follows the same
349
+ // syntax and rules as the "imports" property defined in `package.json`.
350
+ imports,
351
+ // A map of preresolved imports with keys being serialized parent URLs and
352
+ // values being "imports" maps.
353
+ resolutions,
354
+ // The supported import conditions. "default" is always recognized.
355
+ conditions
356
+ }
357
+ ```
358
+
335
359
  #### `const module = Module.load(url[, source][, options])`
336
360
 
337
361
  Load a module with the provided `url`. `url` is a WHATWG `URL`. If provided, the `source` will be passed to the matching `extension` for the `url`.
@@ -380,41 +404,17 @@ options = {
380
404
  }
381
405
  ```
382
406
 
383
- #### `const url = Module.asset(specifier, parentURL[, options])`
384
-
385
- Get the asset URL by resolving `specifier` relative to `parentURL`. `specifier` is a string and `parentURL` is a WHATWG `URL`.
386
-
387
- Options include:
388
-
389
- ```js
390
- options = {
391
- // The referring module.
392
- referrer: null,
393
- // The ModuleProtocol to use resolve the specifier. Defaults to referrer's
394
- // protocol if defined, otherwise defaults to Module.protocol
395
- protocol,
396
- // A default "imports" map to apply to all specifiers. Follows the same
397
- // syntax and rules as the "imports" property defined in `package.json`.
398
- imports,
399
- // A map of preresolved imports with keys being serialized parent URLs and
400
- // values being "imports" maps.
401
- resolutions,
402
- // The supported import conditions. "default" is always recognized.
403
- conditions
404
- }
405
- ```
406
-
407
407
  #### `module.url`
408
408
 
409
- The WHATWG `URL` instance for the module.
409
+ The WHATWG `URL` identifier of the module.
410
410
 
411
411
  #### `module.filename`
412
412
 
413
- The pathname of the `module.url`.
413
+ The file portion of `module.url`.
414
414
 
415
415
  #### `module.dirname`
416
416
 
417
- The directory name of the module.
417
+ The directory portion of `module.url`.
418
418
 
419
419
  #### `module.type`
420
420
 
@@ -454,7 +454,7 @@ An array of conditions used to resolve dependencies while loading the module. Se
454
454
 
455
455
  #### `module.protocol`
456
456
 
457
- The `ModuleProtocol` class used for resolving, reading and loading modules. See [Protocols](#protocols).
457
+ The `ModuleProtocol` class used for resolving, reading, and loading modules. See [Protocols](#protocols).
458
458
 
459
459
  ### CommonJS modules
460
460
 
@@ -503,7 +503,7 @@ See [`bare-addon`](https://github.com/holepunchto/bare-addon) for a template of
503
503
 
504
504
  #### `require.addon.host`
505
505
 
506
- Returns the string representation of the platform and architecture used when resolving addons with the pattern `<platform>-<arch>[-simulator]`. Returns the same value as `Bare.Addon.host`.
506
+ Returns the string representation of the platform and architecture used when resolving addons with the pattern `<platform>-<arch>[-<environment>]`. Returns the same value as `Bare.Addon.host`.
507
507
 
508
508
  #### `const path = require.addon.resolve([specifier][, parentURL])`
509
509
 
@@ -552,7 +552,7 @@ Returns the exported module contents.
552
552
 
553
553
  #### `import.meta.addon.host`
554
554
 
555
- Returns the string representation of the platform and architecture used when resolving addons with the pattern `<platform>-<arch>[-simulator]`. Returns the same value as `Bare.Addon.host`.
555
+ Returns the string representation of the platform and architecture used when resolving addons with the pattern `<platform>-<arch>[-<environment>]`. Returns the same value as `Bare.Addon.host`.
556
556
 
557
557
  #### `const href = import.meta.addon.resolve([specifier][, parentURL])`
558
558
 
package/index.js CHANGED
@@ -248,7 +248,7 @@ module.exports = exports = class Module {
248
248
  static _cache =
249
249
  module[kind] === Module[kind] ? module.cache || Object.create(null) : Object.create(null)
250
250
 
251
- static _conditions = ['bare', 'node', Bare.platform, Bare.arch]
251
+ static _conditions = ['bare', 'node', ...Bare.Addon.host.split('-')]
252
252
 
253
253
  static _handle = binding.init(this, this._onimport, this._onevaluate, this._onmeta)
254
254
 
@@ -797,8 +797,6 @@ exports.createRequire = function createRequire(parentURL, opts = {}) {
797
797
  return require
798
798
  }
799
799
 
800
- if (Bare.simulator) Module._conditions.push('simulator')
801
-
802
800
  Module._extensions['.js'] = function (module, source, referrer) {
803
801
  const self = Module
804
802
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "6.1.2",
3
+ "version": "6.1.3",
4
4
  "description": "Module support for JavaScript",
5
5
  "exports": {
6
6
  ".": {