bare-module 7.0.3 → 7.1.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.
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import Buffer from 'bare-buffer'
2
2
  import URL from 'bare-url'
3
+ import { ResolutionsMap } from 'bare-module-resolve'
3
4
  import { constants } from 'bare-module-traverse'
4
5
  import Protocol from './lib/protocol'
5
6
  import Loader from './lib/loader'
@@ -38,6 +39,11 @@ interface Module {
38
39
  * [Protocols](https://github.com/holepunchto/bare-module#protocols) for usage.
39
40
  */
40
41
  readonly protocol: Protocol
42
+ /**
43
+ * The resolutions map of the module graph, with keys being serialized parent URLs and values
44
+ * being `"imports"` maps.
45
+ */
46
+ readonly resolutions: ResolutionsMap
41
47
  /** The WHATWG `URL` identifier of the module. */
42
48
  readonly url: URL
43
49
  }
package/lib/loader.js CHANGED
@@ -450,6 +450,7 @@ module.exports = class ModuleLoader {
450
450
  engines,
451
451
  ...opts,
452
452
  deferUnresolved: true,
453
+ resolutions: this._resolutions,
453
454
  packages: this._packages,
454
455
  prefixes: this._prefixes,
455
456
  resolve: traverse.resolve.bare
@@ -559,6 +560,10 @@ module.exports = class ModuleLoader {
559
560
  _linkBundle(bundle) {
560
561
  this._bundles.push(bundle)
561
562
 
563
+ for (const href in bundle.resolutions) {
564
+ if (href in this._resolutions === false) this._resolutions[href] = bundle.resolutions[href]
565
+ }
566
+
562
567
  const protocol = this._protocol.extend({
563
568
  exists(context, url) {
564
569
  if (bundleOwns(bundle, url)) return true
@@ -601,13 +606,7 @@ module.exports = class ModuleLoader {
601
606
  }
602
607
  })
603
608
 
604
- this._linkSync(
605
- this._root(new URL(bundle.main), null, {
606
- imports: bundle.imports,
607
- resolutions: bundle.resolutions
608
- }),
609
- protocol
610
- )
609
+ this._linkSync(this._root(new URL(bundle.main), null, { imports: bundle.imports }), protocol)
611
610
  }
612
611
 
613
612
  _ingest(dependency) {
@@ -749,13 +748,11 @@ module.exports = class ModuleLoader {
749
748
  }
750
749
 
751
750
  _cacheResolution(parentURL, specifier, condition, url) {
752
- let imports = this._resolutions[parentURL.href]
753
-
754
- if (typeof imports !== 'object' || imports === null) {
755
- imports = this._resolutions[parentURL.href] = Object.create(null)
756
- }
751
+ const imports = this._resolutions[parentURL.href]
757
752
 
758
- if (specifier in imports) return
753
+ // An entry is taken as every import of its module when that module is
754
+ // linked, so none is started for a module that isn't linked yet.
755
+ if (typeof imports !== 'object' || imports === null || specifier in imports) return
759
756
 
760
757
  imports[specifier] = { [condition]: url.href }
761
758
  }
package/lib/module.js CHANGED
@@ -63,6 +63,10 @@ module.exports = exports = class Module {
63
63
  return this._loader._protocolFor(this.url)
64
64
  }
65
65
 
66
+ get resolutions() {
67
+ return this._loader._resolutions
68
+ }
69
+
66
70
  // For Node.js compatibility
67
71
  get filename() {
68
72
  return urlToPath(this.url)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "7.0.3",
3
+ "version": "7.1.0",
4
4
  "description": "The module system that powers Bare",
5
5
  "exports": {
6
6
  "./package": "./package.json",