Skip to content

Commit 7b5ac54

Browse files
committed
docs: [api] packageImportsExportsResolve
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent c369af2 commit 7b5ac54

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,43 @@ Implements the [`PACKAGE_EXPORTS_RESOLVE`][algorithm-package-exports-resolve] al
476476

477477
<!--lint enable-->
478478

479+
Resolve a package export or import.
480+
479481
Implements the [`PACKAGE_IMPORTS_EXPORTS_RESOLVE`][algorithm-package-imports-exports-resolve] algorithm.
480482

481-
**TODO**: `packageImportsExportsResolve`
483+
> 👉 **Note**: Returns a promise if
484+
> [`packageTargetResolve`](#packagetargetresolvetpackageurl-target-subpath-patternmatch-isimports-conditions-mainfields-parent-fs),
485+
> returns a promise.
486+
487+
#### Type Parameters
488+
489+
- `T` ([`Awaitable<URL | null | undefined>`](#awaitablet))
490+
the resolved package export or import url
491+
492+
#### Parameters
493+
494+
- `matchKey` (`string`)
495+
the package subpath extracted from a module specifier, or a dot character (`.`)
496+
- `matchObject` ([`ExportsObject`][pkg-exports-object] | [`Imports`][pkg-imports] | `null` | `undefined`)
497+
the package exports or imports
498+
- `packageUrl` ([`ModuleId`](#moduleid))
499+
the url of the directory containing the `package.json` file
500+
- `isImports` (`boolean` | `null` | `undefined`)
501+
whether `matchObject` is internal to the package
502+
- `conditions` ([`List<Condition>`](#condition) | `null` | `undefined`)
503+
the list of export/import conditions
504+
- **default**: [`defaultConditions`](#defaultconditions)
505+
- `mainFields` ([`List<MainField>`](#mainfield) | `null` | `undefined`)
506+
the list of legacy main fields
507+
- **default**: [`defaultMainFields`](#defaultmainfields)
508+
- `parent` ([`ModuleId`](#moduleid) | `null` | `undefined`)
509+
the url of the parent module
510+
- `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
511+
the file system api
512+
513+
#### Returns
514+
515+
(`T`) The resolved package export or import URL
482516

483517
<!--lint disable-->
484518

@@ -1295,8 +1329,12 @@ community you agree to abide by its terms.
12951329

12961330
[node-esm]: https://nodejs.org/api/esm.html
12971331

1332+
[pkg-exports-object]: https://github.com/flex-development/pkg-types/blob/main/src/exports-object.ts
1333+
12981334
[pkg-imports-subpath]: https://github.com/flex-development/pkg-types/blob/main/src/imports-subpath.ts
12991335

1336+
[pkg-imports]: https://github.com/flex-development/pkg-types/blob/main/src/imports.ts
1337+
13001338
[pkg-package-json]: https://github.com/flex-development/pkg-types/blob/main/src/package-json.ts
13011339

13021340
[subpath-imports]: https://nodejs.org/api/packages.html#subpath-imports

docs/resolution-algorithm.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,22 @@ The resolver can throw the following errors:
146146

147147
<!--lint enable-->
148148

149-
**TODO**: `PACKAGE_IMPORTS_EXPORTS_RESOLVE`
149+
1. If `matchKey` is a key of `matchObj` and does not contain `'*'`, then
150+
1. Let *target* be the value of `matchObj[matchKey]`
151+
2. Return the result of [`PACKAGE_TARGET_RESOLVE(packageUrl, target, null, isImports, conditions, mainFields, parent)`][package-target-resolve]
152+
2. Let *expansionKeys* be the list of keys of *matchObj* containing only a single `'*'`, sorted by the sorting function
153+
[`PATTERN_KEY_COMPARE`][pattern-key-compare] which orders in descending order of specificity
154+
3. For each key *expansionKey* in *expansionKeys*, do
155+
1. Let *patternBase* be the substring of *expansionKey* up to but excluding the first `'*'` character
156+
2. If *matchKey* starts with, but is not equal, to *patternBase*, then
157+
1. Let *patternTrailer* be the substring of *expansionKey* from the index after the first `'*'` character
158+
2. If *patternTrailer* has zero length, or if *matchKey* ends with *patternTrailer* and the length of *matchKey*
159+
is greater than or equal to the length of *expansionKey*, then
160+
1. Let *target* be the value of `matchObj[matchKey]`
161+
2. Let *patternMatch* be the substring of *matchKey* starting at the index of the length of *patternBase* up to
162+
the length of *matchKey* minus the length of *patternTrailer*
163+
3. Return the result of [`PACKAGE_TARGET_RESOLVE(packageUrl, target, patternMatch, isImports, conditions, mainFields, parent)`][package-target-resolve]
164+
4. Return `null`
150165

151166
<!--lint disable-->
152167

0 commit comments

Comments
 (0)