@flex-development/mlly 1.0.0-beta.4 → 1.0.0-beta.5

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 (121) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +162 -79
  3. package/dist/index.d.mts +1885 -5
  4. package/dist/index.mjs +1 -5
  5. package/dist/internal/chain-or-call.d.mts +51 -0
  6. package/dist/internal/chain-or-call.mjs +1 -34
  7. package/dist/internal/chars.d.mts +16 -0
  8. package/dist/internal/chars.mjs +1 -17
  9. package/dist/internal/check-invalid-segments.d.mts +18 -0
  10. package/dist/internal/check-invalid-segments.mjs +1 -49
  11. package/dist/internal/constant.d.mts +21 -0
  12. package/dist/internal/constant.mjs +1 -23
  13. package/dist/internal/fs.browser.d.mts +12 -0
  14. package/dist/internal/fs.browser.mjs +1 -42
  15. package/dist/internal/fs.node.d.mts +12 -0
  16. package/dist/internal/fs.node.mjs +1 -16
  17. package/dist/internal/identity.d.mts +21 -0
  18. package/dist/internal/identity.mjs +1 -23
  19. package/dist/internal/invalid-package-target.d.mts +31 -0
  20. package/dist/internal/invalid-package-target.mjs +1 -36
  21. package/dist/internal/invalid-subpath.d.mts +32 -0
  22. package/dist/internal/invalid-subpath.mjs +1 -37
  23. package/dist/internal/is-promise.d.mts +21 -0
  24. package/dist/internal/is-promise.mjs +1 -26
  25. package/dist/internal/process.browser.d.mts +9 -0
  26. package/dist/internal/process.browser.mjs +1 -8
  27. package/dist/lib/can-parse-url.mjs +1 -31
  28. package/dist/lib/cwd.mjs +1 -17
  29. package/dist/lib/default-conditions.mjs +1 -14
  30. package/dist/lib/default-extensions.mjs +1 -29
  31. package/dist/lib/default-main-fields.mjs +1 -13
  32. package/dist/lib/extension-format-map.mjs +1 -31
  33. package/dist/lib/formats.mjs +1 -22
  34. package/dist/lib/get-source.mjs +1 -153
  35. package/dist/lib/index.mjs +1 -41
  36. package/dist/lib/is-absolute-specifier.mjs +1 -34
  37. package/dist/lib/is-array-index.mjs +1 -28
  38. package/dist/lib/is-bare-specifier.mjs +1 -33
  39. package/dist/lib/is-directory.mjs +1 -54
  40. package/dist/lib/is-file.mjs +1 -54
  41. package/dist/lib/is-imports-subpath.mjs +1 -28
  42. package/dist/lib/is-module-id.mjs +1 -24
  43. package/dist/lib/is-relative-specifier.mjs +1 -36
  44. package/dist/lib/lookup-package-scope.mjs +1 -102
  45. package/dist/lib/pattern-key-compare.mjs +1 -71
  46. package/dist/lib/pattern-match.mjs +1 -85
  47. package/dist/lib/read-package-json.mjs +1 -114
  48. package/dist/lib/resolve-alias.mjs +1 -102
  49. package/dist/lib/resolve-module.mjs +1 -186
  50. package/dist/lib/resolver.mjs +1 -1015
  51. package/dist/lib/root.mjs +1 -12
  52. package/dist/lib/to-relative-specifier.mjs +1 -63
  53. package/dist/lib/to-url.mjs +1 -34
  54. package/package.json +28 -10
  55. package/dist/interfaces/aliases.d.mts +0 -21
  56. package/dist/interfaces/buffer-encoding-map.d.mts +0 -29
  57. package/dist/interfaces/condition-map.d.mts +0 -24
  58. package/dist/interfaces/file-system.d.mts +0 -29
  59. package/dist/interfaces/get-source-context.d.mts +0 -44
  60. package/dist/interfaces/get-source-options.d.mts +0 -56
  61. package/dist/interfaces/index.d.mts +0 -22
  62. package/dist/interfaces/is-directory.d.mts +0 -17
  63. package/dist/interfaces/is-file.d.mts +0 -17
  64. package/dist/interfaces/main-field-map.d.mts +0 -22
  65. package/dist/interfaces/module-format-map.d.mts +0 -26
  66. package/dist/interfaces/pattern-key-comparison-map.d.mts +0 -31
  67. package/dist/interfaces/protocol-map.d.mts +0 -44
  68. package/dist/interfaces/read-file.d.mts +0 -42
  69. package/dist/interfaces/realpath.d.mts +0 -29
  70. package/dist/interfaces/resolve-alias-options.d.mts +0 -43
  71. package/dist/interfaces/resolve-module-options.d.mts +0 -79
  72. package/dist/interfaces/stat.d.mts +0 -27
  73. package/dist/interfaces/stats.d.mts +0 -23
  74. package/dist/lib/can-parse-url.d.mts +0 -23
  75. package/dist/lib/cwd.d.mts +0 -14
  76. package/dist/lib/default-conditions.d.mts +0 -15
  77. package/dist/lib/default-extensions.d.mts +0 -14
  78. package/dist/lib/default-main-fields.d.mts +0 -14
  79. package/dist/lib/extension-format-map.d.mts +0 -16
  80. package/dist/lib/formats.d.mts +0 -21
  81. package/dist/lib/get-source.d.mts +0 -46
  82. package/dist/lib/index.d.mts +0 -41
  83. package/dist/lib/is-absolute-specifier.d.mts +0 -23
  84. package/dist/lib/is-array-index.d.mts +0 -19
  85. package/dist/lib/is-bare-specifier.d.mts +0 -23
  86. package/dist/lib/is-directory.d.mts +0 -27
  87. package/dist/lib/is-file.d.mts +0 -27
  88. package/dist/lib/is-imports-subpath.d.mts +0 -26
  89. package/dist/lib/is-module-id.d.mts +0 -23
  90. package/dist/lib/is-relative-specifier.d.mts +0 -23
  91. package/dist/lib/lookup-package-scope.d.mts +0 -49
  92. package/dist/lib/pattern-key-compare.d.mts +0 -28
  93. package/dist/lib/pattern-match.d.mts +0 -22
  94. package/dist/lib/read-package-json.d.mts +0 -63
  95. package/dist/lib/resolve-alias.d.mts +0 -21
  96. package/dist/lib/resolve-module.d.mts +0 -43
  97. package/dist/lib/resolver.d.mts +0 -346
  98. package/dist/lib/root.d.mts +0 -11
  99. package/dist/lib/to-relative-specifier.d.mts +0 -27
  100. package/dist/lib/to-url.d.mts +0 -26
  101. package/dist/types/awaitable.d.mts +0 -12
  102. package/dist/types/buffer-encoding.d.mts +0 -13
  103. package/dist/types/change-ext-fn.d.mts +0 -29
  104. package/dist/types/condition.d.mts +0 -13
  105. package/dist/types/dot.d.mts +0 -9
  106. package/dist/types/empty-array.d.mts +0 -9
  107. package/dist/types/empty-object.d.mts +0 -19
  108. package/dist/types/empty-string.d.mts +0 -9
  109. package/dist/types/ext.d.mts +0 -12
  110. package/dist/types/file-content.d.mts +0 -11
  111. package/dist/types/get-source-handler.d.mts +0 -23
  112. package/dist/types/get-source-handlers.d.mts +0 -15
  113. package/dist/types/index.d.mts +0 -24
  114. package/dist/types/list.d.mts +0 -12
  115. package/dist/types/main-field.d.mts +0 -13
  116. package/dist/types/module-format.d.mts +0 -13
  117. package/dist/types/module-id.d.mts +0 -12
  118. package/dist/types/numeric.d.mts +0 -9
  119. package/dist/types/pattern-key-comparison.d.mts +0 -14
  120. package/dist/types/pattern-match.d.mts +0 -10
  121. package/dist/types/protocol.d.mts +0 -13
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.0.0-beta.5](https://github.com/flex-development/mlly/compare/1.0.0-beta.4...1.0.0-beta.5) (2026-02-12)
2
+
3
+ ### :package: Build
4
+
5
+ - [[`ca18e2c`](https://github.com/flex-development/mlly/commit/ca18e2c00cce470c544247fc43ca3049c5b8a69c)] **deps-dev:** Bump msw from 2.12.9 to 2.12.10 ([#972](https://github.com/flex-development/mlly/issues/972))
6
+ - [[`7483ade`](https://github.com/flex-development/mlly/commit/7483ade2afe9017272edc094c0fdb14faa2eb7a3)] **deps-dev:** Bump vite-tsconfig-paths from 6.0.5 to 6.1.0 ([#970](https://github.com/flex-development/mlly/issues/970))
7
+ - [[`3435d7f`](https://github.com/flex-development/mlly/commit/3435d7f73f454b76317e950e5e0c252280cf0247)] **pkg:** bundle dts files
8
+ - [[`88d834e`](https://github.com/flex-development/mlly/commit/88d834e5c25092310631675a340b9e14a4c40a1f)] **pkg:** minify build files (`*.mjs`)
9
+
10
+ ### :pencil: Documentation
11
+
12
+ - [[`2bb51f5`](https://github.com/flex-development/mlly/commit/2bb51f5eda7c0145c7763b9425b9d9f7d6f071b2)] quick start, use cases
13
+ - [[`d638e57`](https://github.com/flex-development/mlly/commit/d638e57df5293a7aa382b6354f2726b2c1969c5a)] why this package, design goals, sponsors
14
+
1
15
  ## [1.0.0-beta.4](https://github.com/flex-development/mlly/compare/1.0.0-beta.3...1.0.0-beta.4) (2026-02-06)
2
16
 
3
17
  ### ⚠ BREAKING CHANGES
@@ -1297,3 +1311,4 @@
1297
1311
 
1298
1312
 
1299
1313
 
1314
+
package/README.md CHANGED
@@ -12,13 +12,21 @@
12
12
  [![vitest](https://img.shields.io/badge/-vitest-6e9f18?style=flat\&logo=vitest\&logoColor=ffffff)](https://vitest.dev)
13
13
  [![yarn](https://img.shields.io/badge/-yarn-2c8ebb?style=flat\&logo=yarn\&logoColor=ffffff)](https://yarnpkg.com)
14
14
 
15
- [ECMAScript module][node-esm] utilities.
15
+ [ESM][node-esm] utilities for modern tooling — spec-compliant, developer-friendly, and fully typed.
16
16
 
17
17
  ## Contents
18
18
 
19
19
  - [What is this?](#what-is-this)
20
+ - [Why this package?](#why-this-package)
20
21
  - [Install](#install)
21
- - [Use](#use)
22
+ - [Quick Start](#quick-start)
23
+ - [Resolve like Node.js](#resolve-like-nodejs)
24
+ - [Resolve with custom conditions](#resolve-with-custom-conditions)
25
+ - [Resolve a directory index](#resolve-a-directory-index)
26
+ - [Rewrite an extension](#rewrite-an-extension)
27
+ - [Use a custom file system](#use-a-custom-file-system)
28
+ - [Use Cases](#use-cases)
29
+ - [Design Goals](#design-goals)
22
30
  - [API](#api)
23
31
  - [`canParseUrl(input[, base])`](#canparseurlinput-base)
24
32
  - [`cwd()`](#cwd)
@@ -94,13 +102,44 @@
94
102
  - [`Stat`](#stat)
95
103
  - [`Stats`](#stats)
96
104
  - Additional Documentation
97
- - [Resolution Algorithm](./docs/resolution-algorithm.md)
105
+ - [Resolution Algorithm][resolution-algorithm]
106
+ - [Sponsors](#sponsors)
98
107
  - [Contribute](#contribute)
99
108
 
100
109
  ## What is this?
101
110
 
102
- `mlly` is a set of [ECMAScript module][node-esm] (ESM) utilities.\
103
- It exposes several tools to bridge the gap between developer experience and the current state of ECMAScript modules.
111
+ `@flex-development/mlly` is a set of [ECMAScript module][node-esm] (ESM) utilities
112
+ for building modern, Node.js-compatible tooling. It implements Node's [resolution algorithms][resolution-algorithm]
113
+ and provides additional helpers for resolving modules in real-world projects.
114
+
115
+ ### Features
116
+
117
+ - Comply with Node.js [resolution algorithms][resolution-algorithm]
118
+ - Resolve `exports` and `imports` maps (including subpaths + patterns)
119
+ - Support condition-based resolution (`development`, `production`, custom conditions, etc.)
120
+ - Support configurable `main` fields for legacy / fallback entrypoints
121
+ - Enhance DX/UX with high-level [`resolveModule`](#resolvemoduletspecifier-parent-options) ergonomics
122
+ on top of spec-compliant resolution
123
+ - Extensionless and directory index resolution
124
+ - Path alias resolution (TypeScript-style mappings)
125
+ - Rewrite file extensions (useful for TS/MTS/CTS, build outputs, or dual publishing)
126
+ - Scopeless `@types/*` resolution (`unist` → `@types/unist`)
127
+ - Utilities for specifier classification and conversion
128
+ - Work with custom file system adapters (sync/async, in-memory, browser)
129
+
130
+ ## Why this package?
131
+
132
+ Node's ESM support is powerful, but writing tooling around it can be painful.
133
+
134
+ If you're building a CLI, bundler, runtime tool, or plugin system, you often need to:
135
+
136
+ - resolve modules the same way Node does
137
+ - support `exports` / `imports` correctly
138
+ - work with custom resolution conditions
139
+ - handle extensionless paths, directory indexes, and TypeScript configurations
140
+
141
+ `@flex-development/mlly` provides these building blocks in a spec-aligned way,
142
+ while also bridging gaps in developer experience.
104
143
 
105
144
  ## Install
106
145
 
@@ -133,67 +172,106 @@ In browsers with [`esm.sh`][esmsh]:
133
172
  </script>
134
173
  ```
135
174
 
136
- ## Use
175
+ ## Quick Start
176
+
177
+ ### Resolve like Node.js
137
178
 
138
179
  ```ts
139
- import {
140
- lookupPackageScope,
141
- readPackageJson,
142
- resolveModule,
143
- type FileSystem
144
- } from '@flex-development/mlly'
145
- import pkg from '@flex-development/mlly/package.json' with { type: 'json' }
146
- import type { PackageJson } from '@flex-development/pkg-types'
147
- import nfs from 'node:fs'
180
+ import { moduleResolve } from '@flex-development/mlly'
148
181
 
149
182
  /**
150
- * A file system API with both asynchronous and synchronous methods.
183
+ * The resolved URL.
151
184
  *
152
- * @const {FileSystem} fs
185
+ * @const {URL} resolved
153
186
  */
154
- const fs: FileSystem = {
155
- readFile: nfs.promises.readFile,
156
- realpath: nfs.promises.realpath,
157
- stat: nfs.statSync
158
- }
187
+ const resolved: URL = moduleResolve('typescript', import.meta.url)
188
+ ```
189
+
190
+ ### Resolve with custom conditions
191
+
192
+ ```ts
193
+ import { moduleResolve } from '@flex-development/mlly'
159
194
 
160
195
  /**
161
- * The URL of the package directory.
196
+ * The resolved URL.
162
197
  *
163
- * @const {URL | null} scope
198
+ * @const {URL} resolved
164
199
  */
165
- const scope: URL | null = lookupPackageScope(import.meta.url, null, fs)
200
+ const resolved: URL = moduleResolve('devlop', import.meta.url, ['development'])
201
+ ```
166
202
 
167
- console.dir(scope) // file:///Users/lex/Projects/flex-development/mlly/
203
+ ### Resolve a directory index
204
+
205
+ ```ts
206
+ import { resolveModule } from '@flex-development/mlly'
168
207
 
169
208
  /**
170
- * The package manifest.
209
+ * The resolved URL.
171
210
  *
172
- * @const {PackageJson | null} manifest
211
+ * @const {URL} resolved
173
212
  */
174
- const manifest: PackageJson | null = await readPackageJson(
175
- scope,
176
- null,
177
- import.meta.url,
178
- fs
179
- )
213
+ const resolved: URL = resolveModule('./src/lib', import.meta.url, {
214
+ extensions: ['.mts']
215
+ })
216
+ ```
180
217
 
181
- console.dir(manifest?.name === pkg.name) // true
182
- console.dir(manifest) // `pkg`
218
+ ### Rewrite an extension
219
+
220
+ ```ts
221
+ import { resolveModule } from '@flex-development/mlly'
183
222
 
184
223
  /**
185
- * A fully resolved URL.
224
+ * The resolved URL.
186
225
  *
187
226
  * @const {URL} resolved
188
227
  */
189
- const resolved = resolveModule(pkg.name, import.meta.url, {
190
- conditions: new Set(['mlly']),
191
- ext: null
228
+ const resolved: URL = resolveModule('./src/index.ts', import.meta.url, {
229
+ ext: { '.cts': '.cjs', '.mts': '.mjs', '.ts': '.js' }
192
230
  })
231
+ ```
232
+
233
+ ### Use a custom file system
193
234
 
194
- console.dir(resolved) // file:///Users/lex/Projects/flex-development/mlly/src/
235
+ ```ts
236
+ import vfs from '#internal/vfs' // a virtual, async file system
237
+ import { resolveModule } from '@flex-development/mlly'
238
+
239
+ /**
240
+ * The resolved URL.
241
+ *
242
+ * @const {URL} resolved
243
+ */
244
+ const resolved: URL = await resolveModule('react', import.meta.url, { fs: vfs })
195
245
  ```
196
246
 
247
+ <br />
248
+
249
+ > \:eyes: See the [API reference](#api) for lower-level building blocks and resolution primitives.
250
+
251
+ ## Use Cases
252
+
253
+ `mlly` is designed for developers who need Node-compatible ESM resolution behavior.
254
+
255
+ Common use cases include:
256
+
257
+ - CLI tools that load user config files and/or plugins
258
+ - Plugin systems that resolve modules relative to a project root
259
+ - Bundlers and transpilers that need to interpret `exports`, `imports`, and `main` fields
260
+ - Test runners and code execution tools
261
+ - Monorepo tooling that resolves workspace dependencies
262
+ - Runtime loaders and developer tools that operate on virtual filesystems
263
+ - Framework tooling that needs resolution behavior matching Node.js
264
+
265
+ ## Design Goals
266
+
267
+ This package is built around a few core goals:
268
+
269
+ - Spec-compliant behavior where it matters (resolution rules, `exports`/`imports`)
270
+ - Developer-friendly ergonomics for real-world projects and workflows
271
+ - TypeScript-first APIs with strong typing and predictable return values
272
+ - Composable building blocks (low-level primitives + high-level helpers)
273
+ - Testability and deterministic behavior across environments
274
+
197
275
  ## API
198
276
 
199
277
  `mlly` exports the identifiers listed below.
@@ -204,7 +282,7 @@ There is no default export.
204
282
 
205
283
  Check if `input` can be parsed to a `URL`.
206
284
 
207
- > 👉 **Note**: If `input` is relative, `base` is required.
285
+ > \:point\_right: **Note**: If `input` is relative, `base` is required.
208
286
  > If `input` is absolute, `base` is ignored.
209
287
 
210
288
  #### Parameters
@@ -270,7 +348,7 @@ const enum formats {
270
348
 
271
349
  Get the source code for a module.
272
350
 
273
- > 👉 **Note**: Returns a promise if the [handler](#getsourcehandler) for `id` is async.
351
+ > \:point\_right: **Note**: Returns a promise if the [handler](#getsourcehandler) for `id` is async.
274
352
 
275
353
  #### Type Parameters
276
354
 
@@ -296,7 +374,7 @@ Get the source code for a module.
296
374
 
297
375
  Check if `value` is an *absolute specifier*.
298
376
 
299
- > 👉 **Note**: Only checks specifier syntax.\
377
+ > \:point\_right: **Note**: Only checks specifier syntax.\
300
378
  > Does **not** guarantee the specifier references an existing module.
301
379
 
302
380
  #### Parameters
@@ -325,7 +403,7 @@ Check if `value` is a valid array index.
325
403
 
326
404
  Check if `value` is a *bare specifier*.
327
405
 
328
- > 👉 **Note**: Only checks specifier syntax.\
406
+ > \:point\_right: **Note**: Only checks specifier syntax.\
329
407
  > Does **not** guarantee the specifier references an existing module.
330
408
 
331
409
  #### Parameters
@@ -341,7 +419,7 @@ Check if `value` is a *bare specifier*.
341
419
 
342
420
  Check if a directory exists.
343
421
 
344
- > 👉 **Note**: Returns a promise if `fs.stat` is async.
422
+ > \:point\_right: **Note**: Returns a promise if `fs.stat` is async.
345
423
 
346
424
  #### Type Parameters
347
425
 
@@ -363,7 +441,7 @@ Check if a directory exists.
363
441
 
364
442
  Check if a file exists.
365
443
 
366
- > 👉 **Note**: Returns a promise if `fs.stat` is async.
444
+ > \:point\_right: **Note**: Returns a promise if `fs.stat` is async.
367
445
 
368
446
  #### Type Parameters
369
447
 
@@ -385,7 +463,7 @@ Check if a file exists.
385
463
 
386
464
  Check if `value` is an [`imports`][subpath-imports] subpath.
387
465
 
388
- > 👉 **Note**: Only checks specifier syntax.\
466
+ > \:point\_right: **Note**: Only checks specifier syntax.\
389
467
  > Does **not** guarantee the specifier references an existing module.
390
468
 
391
469
  #### Parameters
@@ -414,7 +492,7 @@ Check if `value` is a module id.
414
492
 
415
493
  Check if `value` is a *relative specifier*.
416
494
 
417
- > 👉 **Note**: Only checks specifier syntax.\
495
+ > \:point\_right: **Note**: Only checks specifier syntax.\
418
496
  > Does **not** guarantee the specifier references an existing module.
419
497
 
420
498
  #### Parameters
@@ -436,7 +514,7 @@ Resolve a [`main`][main]-like package entry point.
436
514
 
437
515
  Implements the [`LEGACY_MAIN_RESOLVE`][algorithm-legacy-main-resolve] resolution algorithm.
438
516
 
439
- > 👉 **Note**: Returns a promise if `fs.stat` is async.
517
+ > \:point\_right: **Note**: Returns a promise if `fs.stat` is async.
440
518
 
441
519
  #### Type Parameters
442
520
 
@@ -471,7 +549,7 @@ Get the package scope URL for a module `url`.
471
549
 
472
550
  Implements the [`LOOKUP_PACKAGE_SCOPE`][algorithm-lookup-package-scope] algorithm.
473
551
 
474
- > 👉 **Note**: Returns a promise if `fs.stat` is async.
552
+ > \:point\_right: **Note**: Returns a promise if `fs.stat` is async.
475
553
 
476
554
  #### Overloads
477
555
 
@@ -522,8 +600,8 @@ Resolve a module `specifier`.
522
600
 
523
601
  Implements the [`ESM_RESOLVE`][algorithm-esm-resolve] algorithm.
524
602
 
525
- > 👉 **Note**: Returns a promise if `fs.realpath` or `fs.stat` is async, or one the following methods returns a promise:
526
- > [`packageImportsResolve`](#packageimportsresolvetspecifier-parent-conditions-mainfields-fs),
603
+ > \:point\_right: **Note**: Returns a promise if `fs.realpath` or `fs.stat` is async, or one the following methods
604
+ > returns a promise: [`packageImportsResolve`](#packageimportsresolvetspecifier-parent-conditions-mainfields-fs),
527
605
  > [`packageResolve`](#packageresolvetspecifier-parent-conditions-mainfields-fs).
528
606
 
529
607
  #### Type Parameters
@@ -562,7 +640,7 @@ Resolve a package export.
562
640
 
563
641
  Implements the [`PACKAGE_EXPORTS_RESOLVE`][algorithm-package-exports-resolve] algorithm.
564
642
 
565
- > 👉 **Note**: Never returns a promisee.
643
+ > \:point\_right: **Note**: Never returns a promisee.
566
644
 
567
645
  #### Type Parameters
568
646
 
@@ -599,7 +677,7 @@ Resolve a package export or import.
599
677
 
600
678
  Implements the [`PACKAGE_IMPORTS_EXPORTS_RESOLVE`][algorithm-package-imports-exports-resolve] algorithm.
601
679
 
602
- > 👉 **Note**: Returns a promise if
680
+ > \:point\_right: **Note**: Returns a promise if
603
681
  > [`packageTargetResolve`](#packagetargetresolvetpackageurl-target-subpath-patternmatch-isimports-conditions-mainfields-parent-fs),
604
682
  > returns a promise.
605
683
 
@@ -643,7 +721,7 @@ Resolve a package import.
643
721
 
644
722
  Implements the [`PACKAGE_IMPORTS_RESOLVE`][algorithm-package-imports-resolve] algorithm.
645
723
 
646
- > 👉 **Note**: Returns a promise if [`lookupPackageScope`](#lookuppackagescopeturl-end-fs),
724
+ > \:point\_right: **Note**: Returns a promise if [`lookupPackageScope`](#lookuppackagescopeturl-end-fs),
647
725
  > [`packageImportsExportsResolve`](#packageimportsexportsresolvetmatchkey-matchobject-packageurl-isimports-conditions-mainfields-parent-fs),
648
726
  > or [`readPackageJson`](#readpackagejsontid-specifier-parent-fs) returns a promise.
649
727
 
@@ -690,7 +768,7 @@ Implements the [`PACKAGE_RESOLVE`][algorithm-package-resolve] algorithm.
690
768
  > package name, or a specific feature module within a package prefixed by the package name.
691
769
  > Including the file extension is only necessary for packages without an [`exports`][exports] field.
692
770
 
693
- > 👉 **Note**: Returns a promise if `fs.stat` is async or one of the following methods returns a promise:
771
+ > \:point\_right: **Note**: Returns a promise if `fs.stat` is async or one of the following methods returns a promise:
694
772
  > [`legacyMainResolve`](#legacymainresolvetpackageurl-manifest-mainfields-parent-fs),
695
773
  > [`packageExportsResolve`](#packageexportsresolvetpackageurl-subpath-exports-conditions-parent-fs),
696
774
  > [`packageSelfResolve`](#packageselfresolvetname-subpath-parent-conditions-fs), or
@@ -735,7 +813,7 @@ Resolve the self-import of a package.
735
813
 
736
814
  Implements the [`PACKAGE_SELF_RESOLVE`][algorithm-package-self-resolve] algorithm.
737
815
 
738
- > 👉 **Note**: Returns a promise if [`lookupPackageScope`](#lookuppackagescopeturl-end-fs),
816
+ > \:point\_right: **Note**: Returns a promise if [`lookupPackageScope`](#lookuppackagescopeturl-end-fs),
739
817
  > [`packageExportsResolve`](#packageexportsresolvetpackageurl-subpath-exports-conditions-parent-fs),
740
818
  > or [`readPackageJson`](#readpackagejsontid-specifier-parent-fs) returns a promise.
741
819
 
@@ -772,7 +850,7 @@ Resolve a package target.
772
850
 
773
851
  Implements the [`PACKAGE_TARGET_RESOLVE`][algorithm-package-target-resolve] algorithm.
774
852
 
775
- > 👉 **Note**: Returns a promise if `target` is internal to the package and
853
+ > \:point\_right: **Note**: Returns a promise if `target` is internal to the package and
776
854
  > [`packageResolve`](#packageresolvetspecifier-parent-conditions-mainfields-fs) returns a promise.
777
855
 
778
856
  #### Type Parameters
@@ -851,7 +929,7 @@ Read a `package.json` file.
851
929
 
852
930
  Implements the [`READ_PACKAGE_JSON`][algorithm-read-package-json] algorithm.
853
931
 
854
- > 👉 **Note**: Returns a promise if `fs.readFile` or `fs.stat` is async.
932
+ > \:point\_right: **Note**: Returns a promise if `fs.readFile` or `fs.stat` is async.
855
933
 
856
934
  #### Overloads
857
935
 
@@ -886,7 +964,7 @@ function readPackageJson<T extends Awaitable<PackageJson | null>>(
886
964
  — the url of the package directory, the `package.json` file, or a module in the same directory as a `package.json`
887
965
  - `specifier` (`string` | `null` | `undefined`)
888
966
  — the module specifier that initiated the reading of the `package.json` file
889
- > 👉 **note**: should be a `file:` url if `parent` is not a url
967
+ > \:point\_right: **note**: should be a `file:` url if `parent` is not a url
890
968
  - `parent` ([`ModuleId`](#moduleid) | `null` | `undefined`)
891
969
  — the url of the parent module
892
970
  - `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
@@ -923,13 +1001,12 @@ Implements the [`ESM_RESOLVE`][algorithm-esm-resolve] algorithm, mostly \:wink:.
923
1001
 
924
1002
  Adds support for:
925
1003
 
926
- - Changing file extensions
927
- - Directory index resolution
928
- - Extensionless file resolution
1004
+ - Extensionless and directory index resolution
929
1005
  - Path alias resolution
1006
+ - Rewrite file extensions
930
1007
  - Scopeless `@types/*` resolution (i.e. `unist` -> `@types/unist`)
931
1008
 
932
- > 👉 **Note**: Returns a promise if
1009
+ > \:point\_right: **Note**: Returns a promise if
933
1010
  > [`moduleResolve`](#moduleresolvetspecifier-parent-conditions-mainfields-preservesymlinks-fs) returns a promise.
934
1011
 
935
1012
  #### Type Parameters
@@ -973,7 +1050,7 @@ The URL of the file system root.
973
1050
 
974
1051
  Turn `url` into a *relative specifier*.
975
1052
 
976
- > 👉 **Note**: The relative specifier will only have a file extension if `specifier` also has an extension.
1053
+ > \:point\_right: **Note**: The relative specifier will only have a file extension if `specifier` also has an extension.
977
1054
 
978
1055
  #### Parameters
979
1056
 
@@ -990,7 +1067,7 @@ Turn `url` into a *relative specifier*.
990
1067
 
991
1068
  Convert `id` to a `URL`.
992
1069
 
993
- > 👉 **Note**: If `id` cannot be parsed as a `URL` and is also not a [builtin module][builtin-module],
1070
+ > \:point\_right: **Note**: If `id` cannot be parsed as a `URL` and is also not a [builtin module][builtin-module],
994
1071
  > it will be assumed to be a path and converted to a [`file:` URL][file-url].
995
1072
 
996
1073
  #### Parameters
@@ -1040,7 +1117,7 @@ type Awaitable<T> = PromiseLike<T> | T
1040
1117
  #### Type Parameters
1041
1118
 
1042
1119
  - `T` (`any`)
1043
- - the value
1120
+ the value
1044
1121
 
1045
1122
  ### `BufferEncodingMap`
1046
1123
 
@@ -1240,7 +1317,7 @@ Options for retrieving source code (`interface`).
1240
1317
 
1241
1318
  - `encoding?` ([`BufferEncoding`](#bufferencoding) | `null` | `undefined`)
1242
1319
  — the encoding of the result
1243
- > 👉 **note**: used when the `file:` handler is called
1320
+ > \:point\_right: **note**: used when the `file:` handler is called
1244
1321
  - `format?` ([`ModuleFormat`](#moduleformat) | `null` | `undefined`)
1245
1322
  — the module format hint
1246
1323
  - `fs?` ([`FileSystem`](#filesystem) | `null` | `undefined`)
@@ -1282,7 +1359,7 @@ type List<T = unknown> = ReadonlySet<T> | readonly T[]
1282
1359
  #### Type Parameters
1283
1360
 
1284
1361
  - `T` (`any`, optional)
1285
- — list item type
1362
+ the list item type
1286
1363
 
1287
1364
  ### `MainFieldMap`
1288
1365
 
@@ -1443,7 +1520,7 @@ Read the entire contents of a file (`interface`).
1443
1520
 
1444
1521
  Compute a canonical pathname by resolving `.`, `..`, and symbolic links (`interface`).
1445
1522
 
1446
- > 👉 **Note**: A canonical pathname is not necessarily unique.
1523
+ > \:point\_right: **Note**: A canonical pathname is not necessarily unique.
1447
1524
  > Hard links and bind mounts can expose an entity through many pathnames.
1448
1525
 
1449
1526
  #### Type Parameters
@@ -1471,7 +1548,7 @@ Options for path alias resolution (`interface`).
1471
1548
  if `true`, the resolved specifier will be a [`file:` URL][file-url]
1472
1549
  - `aliases?` ([`Aliases`](#aliases) | `null` | `undefined`)
1473
1550
  — the path mappings dictionary
1474
- > 👉 **note**: paths should be relative to `cwd`
1551
+ > \:point\_right: **note**: paths should be relative to `cwd`
1475
1552
  - `cwd?` ([`ModuleId`](#moduleid) | `null` | `undefined`)
1476
1553
  — the url of the directory to resolve non-absolute modules from
1477
1554
  - **default**: [`cwd()`](#cwd)
@@ -1486,27 +1563,27 @@ Options for path alias resolution (`interface`).
1486
1563
 
1487
1564
  - `aliases?` ([`Aliases`](#aliases) | `null` | `undefined`)
1488
1565
  — the path mappings dictionary
1489
- > 👉 **note**: paths should be relative to `cwd`
1566
+ > \:point\_right: **note**: paths should be relative to `cwd`
1490
1567
  - `conditions?` ([`List<Condition>`](#condition) | `null` | `undefined`)
1491
1568
  — the list of export/import conditions
1492
1569
  - **default**: [`defaultConditions`](#defaultconditions)
1493
- > 👉 **note**: should be sorted by priority
1570
+ > \:point\_right: **note**: should be sorted by priority
1494
1571
  - `cwd?` ([`ModuleId`](#moduleid) | `null` | `undefined`)
1495
1572
  — the url of the directory to resolve path `aliases` from
1496
1573
  - **default**: [`cwd()`](#cwd)
1497
1574
  - `ext?` ([`ChangeExtFn`](#changeextfnext) | `string` | `null` | `undefined`)
1498
1575
  — a replacement file extension or a function that returns a file extension.
1499
- > 👉 **note**: an empty string (`''`) or `null` will remove a file extension
1576
+ > \:point\_right: **note**: an empty string (`''`) or `null` will remove a file extension
1500
1577
  - `extensions?` ([`List<string>`](#listt) | `null` | `undefined`)
1501
1578
  — the module extensions to probe for
1502
1579
  - **default**: [`defaultExtensions`](#defaultextensions)
1503
- > 👉 **note**: should be sorted by priority
1580
+ > \:point\_right: **note**: should be sorted by priority
1504
1581
  - `fs?` ([`FileSystem`](#filesystem) | `null` | `undefined`)
1505
1582
  — the file system api
1506
1583
  - `mainFields?` ([`List<MainField>`](#mainfield) | `null` | `undefined`)
1507
1584
  — the list of legacy `main` fields
1508
1585
  - **default**: [`defaultMainFields`](#defaultmainfields)
1509
- > 👉 **note**: should be sorted by priority
1586
+ > \:point\_right: **note**: should be sorted by priority
1510
1587
  - `preserveSymlinks?` (`boolean` | `null` | `undefined`)
1511
1588
  — whether to keep symlinks instead of resolving them
1512
1589
 
@@ -1539,12 +1616,16 @@ An object describing a directory or file (`interface`).
1539
1616
  - `isFile` ([`IsFile`](#isfile))
1540
1617
  — check if the stats object describes a file
1541
1618
 
1619
+ ## Sponsors
1620
+
1621
+ If you find this package helpful, consider sponsoring to support maintenance, tests, and long-term stability.
1622
+
1542
1623
  ## Contribute
1543
1624
 
1544
1625
  See [`CONTRIBUTING.md`](CONTRIBUTING.md).
1545
1626
 
1546
- This project has a [code of conduct](./CODE_OF_CONDUCT.md). By interacting with this repository, organization, or
1547
- community you agree to abide by its terms.
1627
+ This project has a [code of conduct](./CODE_OF_CONDUCT.md).
1628
+ By interacting with this repository, organization, or community you agree to abide by its terms.
1548
1629
 
1549
1630
  [algorithm-esm-resolve]: ./docs/resolution-algorithm.md#esm_resolvespecifier-parent-conditions-mainfields-preservesymlinks-extensionformatmap
1550
1631
 
@@ -1604,6 +1685,8 @@ community you agree to abide by its terms.
1604
1685
 
1605
1686
  [pkg-package-json]: https://github.com/flex-development/pkg-types/blob/main/src/package-json.ts
1606
1687
 
1688
+ [resolution-algorithm]: ./docs/resolution-algorithm.md
1689
+
1607
1690
  [subpath-imports]: https://nodejs.org/api/packages.html#subpath-imports
1608
1691
 
1609
1692
  [typescript]: https://www.typescriptlang.org