Skip to content

Commit 25295d6

Browse files
committed
docs: [api] packageSelfResolve
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 8fa7ae4 commit 25295d6

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,36 @@ Implements the [`PACKAGE_RESOLVE`][algorithm-package-resolve] algorithm.
506506

507507
<!--lint enable-->
508508

509+
Resolve the self-import of a package.
510+
509511
Implements the [`PACKAGE_SELF_RESOLVE`][algorithm-package-self-resolve] algorithm.
510512

511-
**TODO**: `packageSelfResolve`
513+
> 👉 **Note**: Returns a promise if [`lookupPackageScope`](#lookuppackagescopeturl-end-fs),
514+
> [`packageExportsResolve`](#packageexportsresolvetpackageurl-subpath-exports-conditions-parent-fs),
515+
> or [`readPackageJson`](#readpackagejsontid-specifier-parent-fs) returns a promise.
516+
517+
#### Type Parameters
518+
519+
- `T` ([`Awaitable<URL | undefined>`](#awaitablet))
520+
the resolved package url
521+
522+
#### Parameters
523+
524+
- `name` (`string`)
525+
the package name
526+
- `subpath` (`string`)
527+
the package subpath
528+
- `parent` ([`ModuleId`](#moduleid))
529+
the url of the parent module
530+
- `conditions` ([`List<Condition>`](#condition) | `null` | `undefined`)
531+
the list of export conditions
532+
- **default**: [`defaultConditions`](#defaultconditions)
533+
- `fs` ([`FileSystem`](#filesystem) | `null` | `undefined`)
534+
the file system api
535+
536+
#### Returns
537+
538+
(`T`) The resolved package URL
512539

513540
<!--lint disable-->
514541

docs/resolution-algorithm.md

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

163163
## `PACKAGE_SELF_RESOLVE(name, subpath, parent, conditions)`
164164

165-
**TODO**: `PACKAGE_SELF_RESOLVE`
165+
1. Let *packageUrl* be the result of [`LOOKUP_PACKAGE_SCOPE(packageUrl)`][lookup-package-scope]
166+
2. If *packageUrl* is `null`, then
167+
1. Return `undefined`
168+
3. Let *pjson* be the result of [`READ_PACKAGE_JSON(packageUrl)`][read-package-json]
169+
4. If *pjson* is `null` or if *pjson*.*exports* is `null` or `undefined`, then
170+
1. Return `undefined`
171+
5. If *pjson*.*name* is equal to `name`, then
172+
1. Return the result of
173+
[`PACKAGE_EXPORTS_RESOLVE(packageUrl, subpath, pjson.exports, conditions)`][package-exports-resolve]
174+
6. Otherwise, return `undefined`
166175

167176
<!--lint disable-->
168177

src/lib/resolver.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ function packageResolve(
13581358
* @see {@linkcode ModuleId}
13591359
*
13601360
* @template {Awaitable<URL | undefined>} T
1361-
* The resolved URL
1361+
* The resolved package URL
13621362
*
13631363
* @this {void}
13641364
*
@@ -1373,7 +1373,7 @@ function packageResolve(
13731373
* @param {FileSystem | null | undefined} [fs]
13741374
* The file system API
13751375
* @return {T}
1376-
* The resolved URL
1376+
* The resolved package URL
13771377
*/
13781378
function packageSelfResolve<T extends Awaitable<URL | undefined>>(
13791379
this: void,
@@ -1412,7 +1412,7 @@ function packageSelfResolve<T extends Awaitable<URL | undefined>>(
14121412
* @param {FileSystem | null | undefined} [fs]
14131413
* The file system API
14141414
* @return {Awaitable<URL | undefined>}
1415-
* The resolved URL
1415+
* The resolved package URL
14161416
*/
14171417
function packageSelfResolve(
14181418
this: void,

0 commit comments

Comments
 (0)