bare-module-traverse 2.7.0 → 2.7.1

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/index.d.ts +6 -0
  2. package/index.js +29 -0
  3. package/package.json +2 -1
package/index.d.ts CHANGED
@@ -74,6 +74,12 @@ interface TraverseOptions extends ResolveOptions {
74
74
  * system; a tool that only links wants the error.
75
75
  */
76
76
  deferUnresolved?: boolean
77
+ /**
78
+ * The URL the entry is mounted at when it is a bundle, for consumers that
79
+ * load it with an explicit mount. The addons and assets it declares resolve
80
+ * relative to this. Defaults to the URL of the entry itself.
81
+ */
82
+ mount?: URL | string
77
83
  }
78
84
 
79
85
  /**
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ const Bundle = require('bare-bundle')
1
2
  const { lookupPackageScope, conditionMatches } = require('bare-module-resolve')
2
3
  const lex = require('bare-module-lexer')
3
4
  const MIME = require('bare-mime')
@@ -194,6 +195,11 @@ exports.alias = function alias(url, opts = {}) {
194
195
  exports.module = function* (url, source, attributes, artifacts, visited, opts = {}) {
195
196
  attributes = attributes || {}
196
197
 
198
+ // The mount only applies to the module the traversal starts from.
199
+ const { mount } = opts
200
+
201
+ if (mount !== undefined) opts = { ...opts, mount: undefined }
202
+
197
203
  if (opts.contexts === undefined) opts = { ...opts, contexts: new Map() }
198
204
  if (opts.addonContexts === undefined) opts = { ...opts, addonContexts: new Map() }
199
205
  if (opts.resolvedImports === undefined) opts = { ...opts, resolvedImports: new Map() }
@@ -262,6 +268,16 @@ exports.module = function* (url, source, attributes, artifacts, visited, opts =
262
268
  }
263
269
  }
264
270
 
271
+ // A bundle declares its own artifacts, whether or not its imports have been
272
+ // resolved before.
273
+ if (
274
+ asset === false &&
275
+ artifacts !== null &&
276
+ moduleType(url, attributes, null, opts) === constants.BUNDLE
277
+ ) {
278
+ addBundleArtifacts(source, mountFor(url, mount), artifacts)
279
+ }
280
+
265
281
  // A module resolves its imports once, however many contexts it is loaded in,
266
282
  // so a context that reaches it after another walks what the other resolved.
267
283
  // The addons that are reached are then checked against the context.
@@ -853,6 +869,19 @@ exports.assertAddonContext = function assertAddonContext(url, scope, context, ad
853
869
  }
854
870
  }
855
871
 
872
+ function addBundleArtifacts(source, mount, artifacts) {
873
+ const bundle = Bundle.from(source).mount(mount)
874
+
875
+ for (const href of bundle.addons) addURL(artifacts.addons, new URL(href))
876
+ for (const href of bundle.assets) addURL(artifacts.assets, new URL(href))
877
+ }
878
+
879
+ function mountFor(url, mount) {
880
+ const href = mount === undefined ? url.href : new URL(mount).href
881
+
882
+ return href.endsWith('/') ? href : href + '/'
883
+ }
884
+
856
885
  function isJavaScript(type) {
857
886
  return type === constants.SCRIPT || type === constants.MODULE
858
887
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module-traverse",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": {
@@ -55,6 +55,7 @@
55
55
  "homepage": "https://github.com/holepunchto/bare-module-traverse#readme",
56
56
  "dependencies": {
57
57
  "bare-addon-resolve": "^1.5.0",
58
+ "bare-bundle": "^1.11.0",
58
59
  "bare-mime": "^1.0.0",
59
60
  "bare-module-lexer": "^1.6.0",
60
61
  "bare-module-resolve": "^1.7.0"