bare-module-traverse 1.6.0 → 1.7.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/README.md CHANGED
@@ -78,6 +78,11 @@ dependency = {
78
78
  source: 'string' | Buffer, // Source as returned by `readModule()`
79
79
  imports: {
80
80
  // See https://github.com/holepunchto/bare-module#imports
81
+ },
82
+ lexer: {
83
+ imports: [
84
+ // See https://github.com/holepunchto/bare-module-lexer#api
85
+ ]
81
86
  }
82
87
  }
83
88
  ```
@@ -158,7 +163,7 @@ next.value = {
158
163
 
159
164
  ```js
160
165
  next.value = {
161
- children: URL
166
+ children: Generator
162
167
  }
163
168
  ```
164
169
 
@@ -166,7 +171,18 @@ next.value = {
166
171
 
167
172
  ```js
168
173
  next.value = {
169
- dependency: URL
174
+ dependency: {
175
+ url: URL,
176
+ source: 'string' | Buffer,
177
+ imports: {
178
+ // See https://github.com/holepunchto/bare-module#imports
179
+ },
180
+ lexer: {
181
+ imports: [
182
+ // See https://github.com/holepunchto/bare-module-lexer#api
183
+ ]
184
+ }
185
+ }
170
186
  }
171
187
  ```
172
188
 
package/index.d.ts CHANGED
@@ -12,6 +12,9 @@ interface Dependency {
12
12
  url: URL
13
13
  source: string | Buffer
14
14
  imports: ImportsMap
15
+ lexer: {
16
+ imports: Import[]
17
+ }
15
18
  }
16
19
 
17
20
  interface TraverseOptions extends ResolveOptions {
package/index.js CHANGED
@@ -180,9 +180,13 @@ exports.module = function* (
180
180
  }
181
181
  }
182
182
 
183
- yield* exports.imports(url, source, imports, artifacts, visited, opts)
183
+ const lexer = { imports: [] }
184
184
 
185
- yield { dependency: { url, source, imports: compressImportsMap(imports) } }
185
+ yield* exports.imports(url, source, imports, artifacts, lexer, visited, opts)
186
+
187
+ yield {
188
+ dependency: { url, source, imports: compressImportsMap(imports), lexer }
189
+ }
186
190
 
187
191
  return true
188
192
  }
@@ -195,7 +199,7 @@ exports.package = function* (url, source, artifacts, visited, opts = {}) {
195
199
  const info = JSON.parse(source)
196
200
 
197
201
  if (info) {
198
- yield { dependency: { url, source, imports: {} } }
202
+ yield { dependency: { url, source, imports: {}, lexer: { imports: [] } } }
199
203
 
200
204
  if (info.addon) {
201
205
  yield { children: exports.prebuilds(url, artifacts, visited, opts) }
@@ -249,7 +253,14 @@ exports.preresolved = function* (
249
253
  }
250
254
  }
251
255
 
252
- yield { dependency: { url, source, imports: compressImportsMap(imports) } }
256
+ yield {
257
+ dependency: {
258
+ url,
259
+ source,
260
+ imports: compressImportsMap(imports),
261
+ lexer: { imports: [] }
262
+ }
263
+ }
253
264
 
254
265
  return true
255
266
  }
@@ -259,6 +270,7 @@ exports.imports = function* (
259
270
  source,
260
271
  imports,
261
272
  artifacts,
273
+ lexer,
262
274
  visited,
263
275
  opts = {}
264
276
  ) {
@@ -301,6 +313,8 @@ exports.imports = function* (
301
313
  })
302
314
  }
303
315
 
316
+ lexer.imports.push(entry)
317
+
304
318
  queue.push({ entry, specifier, condition })
305
319
  }
306
320
 
@@ -397,14 +411,14 @@ exports.imports = function* (
397
411
 
398
412
  matchedConditions.pop()
399
413
 
400
- let message = `Cannot find ${condition === 'default' ? 'module' : condition} '${specifier}' imported from '${parentURL.href}'`
414
+ if (resolutions === 0) {
415
+ let message = `Cannot find ${condition === 'default' ? 'module' : condition} '${specifier}' imported from '${parentURL.href}'`
401
416
 
402
- if (candidates.length > 0) {
403
- message += '\nCandidates:'
404
- message += '\n' + candidates.map((url) => '- ' + url.href).join('\n')
405
- }
417
+ if (candidates.length > 0) {
418
+ message += '\nCandidates:'
419
+ message += '\n' + candidates.map((url) => '- ' + url.href).join('\n')
420
+ }
406
421
 
407
- if (resolutions === 0) {
408
422
  switch (condition) {
409
423
  case 'addon':
410
424
  throw errors.ADDON_NOT_FOUND(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module-traverse",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": {