bare-module-traverse 2.4.0 → 2.4.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.
- package/README.md +7 -4
- package/index.d.ts +8 -4
- package/index.js +28 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -165,11 +165,12 @@ The following generator functions implement the traversal algorithm. The yielded
|
|
|
165
165
|
|
|
166
166
|
**Source module**
|
|
167
167
|
|
|
168
|
-
A module to be read. The driver returns its source if it exists, otherwise `null`.
|
|
168
|
+
A module to be read. The driver returns its source if it exists, otherwise `null`. When `artifact` is `true`, the module is an addon or asset whose contents are loaded lazily and referenced by path. A driver that only needs to locate such artifacts, such as a module loader, may return `null` without reading, having already established existence by probing; a driver that embeds their contents, such as a bundler, reads them as normal.
|
|
169
169
|
|
|
170
170
|
```js
|
|
171
171
|
next.value = {
|
|
172
|
-
module: URL
|
|
172
|
+
module: URL,
|
|
173
|
+
artifact: boolean
|
|
173
174
|
}
|
|
174
175
|
```
|
|
175
176
|
|
|
@@ -265,7 +266,9 @@ function drive(generator) {
|
|
|
265
266
|
const value = next.value
|
|
266
267
|
|
|
267
268
|
if (value.module) {
|
|
268
|
-
// Read `value.module` if it exists, otherwise `null
|
|
269
|
+
// Read `value.module` if it exists, otherwise `null`. When
|
|
270
|
+
// `value.artifact` is `true`, the module is an addon or asset that may be
|
|
271
|
+
// left unread, returning `null`, unless its contents are needed
|
|
269
272
|
let source
|
|
270
273
|
|
|
271
274
|
next = generator.next(source)
|
|
@@ -322,7 +325,7 @@ Options are the same as `traverse()` for all functions.
|
|
|
322
325
|
|
|
323
326
|
#### `const generator = traverse.preresolved(url, source, resolutions, artifacts, visited[, options])`
|
|
324
327
|
|
|
325
|
-
#### `const generator = traverse.imports(parentURL, source, imports, artifacts, visited[, options])`
|
|
328
|
+
#### `const generator = traverse.imports(parentURL, source, imports, artifacts, lexer, visited[, options])`
|
|
326
329
|
|
|
327
330
|
#### `const generator = traverse.link(entry, specifier, condition, parentURL, imports, artifacts, visited[, options])`
|
|
328
331
|
|
package/index.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ declare namespace traverse {
|
|
|
77
77
|
export { type TraverseOptions }
|
|
78
78
|
|
|
79
79
|
export type Traversal = Generator<
|
|
80
|
-
| { module: URL }
|
|
80
|
+
| { module: URL; artifact: boolean }
|
|
81
81
|
| { probe: URL }
|
|
82
82
|
| { resolution: URL }
|
|
83
83
|
| { prefix: URL }
|
|
@@ -134,6 +134,10 @@ declare namespace traverse {
|
|
|
134
134
|
source: string | Buffer,
|
|
135
135
|
imports: ImportsMap,
|
|
136
136
|
artifacts: Artifacts,
|
|
137
|
+
lexer: {
|
|
138
|
+
imports: Import[]
|
|
139
|
+
exports: Export[]
|
|
140
|
+
},
|
|
137
141
|
visited: Set<string>,
|
|
138
142
|
opts?: TraverseOptions
|
|
139
143
|
): Traversal
|
|
@@ -149,8 +153,8 @@ declare namespace traverse {
|
|
|
149
153
|
opts?: TraverseOptions
|
|
150
154
|
): Traversal
|
|
151
155
|
|
|
152
|
-
export function
|
|
153
|
-
|
|
156
|
+
export function addons(
|
|
157
|
+
parentURL: URL,
|
|
154
158
|
artifacts: Artifacts,
|
|
155
159
|
visited: Set<string>,
|
|
156
160
|
opts?: TraverseOptions
|
|
@@ -158,7 +162,7 @@ declare namespace traverse {
|
|
|
158
162
|
|
|
159
163
|
export function assets(
|
|
160
164
|
patterns: ConditionalSpecifier,
|
|
161
|
-
|
|
165
|
+
parentURL: URL,
|
|
162
166
|
artifacts: Artifacts,
|
|
163
167
|
visited: Set<string>,
|
|
164
168
|
opts?: TraverseOptions
|
package/index.js
CHANGED
|
@@ -202,7 +202,7 @@ exports.module = function* (url, source, attributes, artifacts, visited, opts =
|
|
|
202
202
|
throw errors.MODULE_NOT_FOUND(`Cannot find module '${url.href}'`, url.href)
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
source = yield { module: url }
|
|
205
|
+
source = yield { module: url, artifact }
|
|
206
206
|
|
|
207
207
|
if (exists !== true && source === null) {
|
|
208
208
|
throw errors.MODULE_NOT_FOUND(`Cannot find module '${url.href}'`, url.href)
|
|
@@ -220,7 +220,7 @@ exports.module = function* (url, source, attributes, artifacts, visited, opts =
|
|
|
220
220
|
let info = null
|
|
221
221
|
|
|
222
222
|
for (const packageURL of lookupPackageScope(url, opts)) {
|
|
223
|
-
const source = yield { module: packageURL }
|
|
223
|
+
const source = yield { module: packageURL, artifact: false }
|
|
224
224
|
|
|
225
225
|
if (source !== null) {
|
|
226
226
|
info = JSON.parse(source)
|
|
@@ -239,7 +239,7 @@ exports.module = function* (url, source, attributes, artifacts, visited, opts =
|
|
|
239
239
|
if (typeof attributes.imports === 'string') {
|
|
240
240
|
const url = new URL(attributes.imports)
|
|
241
241
|
|
|
242
|
-
const source = yield { module: url }
|
|
242
|
+
const source = yield { module: url, artifact: false }
|
|
243
243
|
|
|
244
244
|
if (source !== null) {
|
|
245
245
|
opts = {
|
|
@@ -280,7 +280,7 @@ exports.package = function* (url, source, artifacts, visited, opts = {}) {
|
|
|
280
280
|
visited.add(url.href)
|
|
281
281
|
|
|
282
282
|
if (source === null) {
|
|
283
|
-
source = yield { module: url }
|
|
283
|
+
source = yield { module: url, artifact: false }
|
|
284
284
|
|
|
285
285
|
if (source === null) return false
|
|
286
286
|
}
|
|
@@ -339,16 +339,12 @@ exports.preresolved = function* (url, source, resolutions, artifacts, visited, o
|
|
|
339
339
|
} else if (asset) {
|
|
340
340
|
addURL(artifacts.assets, url)
|
|
341
341
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
asset: true
|
|
349
|
-
}),
|
|
350
|
-
deferred: true
|
|
351
|
-
}
|
|
342
|
+
yield {
|
|
343
|
+
children: exports.module(url, null, {}, artifacts, visited, {
|
|
344
|
+
...opts,
|
|
345
|
+
asset: true
|
|
346
|
+
}),
|
|
347
|
+
deferred: true
|
|
352
348
|
}
|
|
353
349
|
} else if (
|
|
354
350
|
url.protocol !== builtinProtocol &&
|
|
@@ -473,7 +469,7 @@ function* resolveImport(entry, specifier, condition, parentURL, imports, artifac
|
|
|
473
469
|
const value = next.value
|
|
474
470
|
|
|
475
471
|
if (value.package) {
|
|
476
|
-
next = resolver.next(JSON.parse(yield { module: value.package }))
|
|
472
|
+
next = resolver.next(JSON.parse(yield { module: value.package, artifact: false }))
|
|
477
473
|
} else {
|
|
478
474
|
const url = value.resolution
|
|
479
475
|
|
|
@@ -510,19 +506,22 @@ function* resolveImport(entry, specifier, condition, parentURL, imports, artifac
|
|
|
510
506
|
}
|
|
511
507
|
|
|
512
508
|
if (resolved) addResolution(imports, specifier, matchedConditions, url)
|
|
513
|
-
} else if (
|
|
509
|
+
} else if (
|
|
510
|
+
condition === 'addon' ||
|
|
511
|
+
moduleType(url, entry.attributes, null, opts) === constants.ADDON
|
|
512
|
+
) {
|
|
514
513
|
let exists = yield { probe: url }
|
|
515
514
|
let source = null
|
|
516
515
|
|
|
517
516
|
if (exists === undefined) {
|
|
518
|
-
source = yield { module: url }
|
|
517
|
+
source = yield { module: url, artifact: false }
|
|
519
518
|
exists = source !== null
|
|
520
519
|
}
|
|
521
520
|
|
|
522
521
|
if (exists) {
|
|
523
522
|
resolution = yield* postresolve(url)
|
|
524
523
|
|
|
525
|
-
addResolution(imports, specifier, matchedConditions, resolution)
|
|
524
|
+
addResolution(imports, specifier, matchedConditions, exports.alias(resolution, opts))
|
|
526
525
|
|
|
527
526
|
yield {
|
|
528
527
|
children: exports.module(resolution, source, {}, artifacts, visited, {
|
|
@@ -535,7 +534,7 @@ function* resolveImport(entry, specifier, condition, parentURL, imports, artifac
|
|
|
535
534
|
resolved = true
|
|
536
535
|
}
|
|
537
536
|
} else {
|
|
538
|
-
const source = yield { module: url }
|
|
537
|
+
const source = yield { module: url, artifact: false }
|
|
539
538
|
|
|
540
539
|
if (source !== null) {
|
|
541
540
|
resolution = yield* postresolve(url)
|
|
@@ -621,23 +620,19 @@ exports.assets = function* (patterns, parentURL, artifacts, visited, opts = {})
|
|
|
621
620
|
let yielded = false
|
|
622
621
|
|
|
623
622
|
for (const url of matches) {
|
|
624
|
-
const
|
|
625
|
-
|
|
626
|
-
if (source !== null) {
|
|
627
|
-
const resolution = yield* postresolve(url)
|
|
628
|
-
|
|
629
|
-
addURL(artifacts.assets, resolution)
|
|
623
|
+
const resolution = yield* postresolve(url)
|
|
630
624
|
|
|
631
|
-
|
|
632
|
-
children: exports.module(resolution, source, {}, artifacts, visited, {
|
|
633
|
-
...opts,
|
|
634
|
-
asset: true
|
|
635
|
-
}),
|
|
636
|
-
deferred: true
|
|
637
|
-
}
|
|
625
|
+
addURL(artifacts.assets, resolution)
|
|
638
626
|
|
|
639
|
-
|
|
627
|
+
yield {
|
|
628
|
+
children: exports.module(resolution, null, {}, artifacts, visited, {
|
|
629
|
+
...opts,
|
|
630
|
+
asset: true
|
|
631
|
+
}),
|
|
632
|
+
deferred: true
|
|
640
633
|
}
|
|
634
|
+
|
|
635
|
+
yielded = true
|
|
641
636
|
}
|
|
642
637
|
|
|
643
638
|
return yielded
|