bare-module-traverse 2.0.2 → 2.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/README.md CHANGED
@@ -59,6 +59,11 @@ Options include:
59
59
  ```js
60
60
  options = {
61
61
  defaultType: constants.SCRIPT,
62
+ aliases: {
63
+ // Map an extension to a supported extension, e.g. `'.ts': '.js'`. The
64
+ // aliased extension is used for module type detection, so `readModule()`
65
+ // must return source compatible with that type.
66
+ },
62
67
  resolve: resolve.default
63
68
  }
64
69
  ```
package/index.d.ts CHANGED
@@ -17,8 +17,20 @@ interface Dependency {
17
17
  }
18
18
  }
19
19
 
20
+ type AliasableExtension =
21
+ | '.js'
22
+ | '.cjs'
23
+ | '.mjs'
24
+ | '.json'
25
+ | '.bundle'
26
+ | '.bare'
27
+ | '.node'
28
+ | '.bin'
29
+ | '.txt'
30
+
20
31
  interface TraverseOptions extends ResolveOptions {
21
32
  defaultType?: number
33
+ aliases?: Record<string, AliasableExtension>
22
34
  resolve?: (entry: Import, parentURL: URL, opts?: ResolveOptions) => Resolver
23
35
  }
24
36
 
package/index.js CHANGED
@@ -110,7 +110,7 @@ exports.constants = constants
110
110
  exports.resolve = resolve
111
111
 
112
112
  exports.module = function* (url, source, attributes, artifacts, visited, opts = {}) {
113
- const { resolutions = null, defaultType = constants.SCRIPT } = opts
113
+ const { resolutions = null, defaultType = constants.SCRIPT, aliases = null } = opts
114
114
 
115
115
  if (visited.has(url.href)) return false
116
116
 
@@ -195,7 +195,9 @@ exports.module = function* (url, source, attributes, artifacts, visited, opts =
195
195
  const match = url.pathname.match(/\.[a-z]+$/)
196
196
 
197
197
  if (match !== null) {
198
- const [extension] = match
198
+ let [extension] = match
199
+
200
+ if (aliases !== null && extension in aliases) extension = aliases[extension]
199
201
 
200
202
  switch (extension) {
201
203
  case '.js': {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module-traverse",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": {