Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
1
Frontend-Learner/node_modules/@es-joy/resolve.exports/dist/index.js
generated
vendored
Normal file
1
Frontend-Learner/node_modules/@es-joy/resolve.exports/dist/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
function e(e,t,n){throw new Error(n?`No known conditions for "${t}" specifier in "${e}" package`:`Missing "${t}" specifier in "${e}" package`)}function t(e){let t=new Set(["default"]);e.unsafe||t.add(e.require?"require":"import"),e.unsafe||t.add(e.browser?"browser":"node");for(const n of e.conditions||[])n.startsWith("!")?t.delete(n.slice(1)):t.add(n);return t}function n(n,f,o,l){let u,g,c=i(n,o),a=t(l||{}),p=f[c];if(void 0===p){let e,t,n,r;for(r in f)t&&r.length<t.length||("/"===r[r.length-1]&&c.startsWith(r)?(g=c.substring(r.length),t=r):r.length>1&&(n=r.indexOf("*",1),~n&&(e=RegExp("^"+r.substring(0,n)+"(.*)"+r.substring(1+n)+"$").exec(c),e&&e[1]&&(g=e[1],t=r))));p=f[t]}return p||e(n,c),u=s(p,a),u||e(n,c,1),g&&r(u,g),u}function r(e,t){let n,r=0,i=e.length,s=/[*]/g,f=/[/]$/;for(;r<i;r++)e[r]=s.test(n=e[r])?n.replace(s,t):f.test(n)?n+t:n}function i(e,t,n){if(e===t||"."===t)return".";let r=e+"/",i=r.length,s=t.slice(0,i)===r,f=s?t.slice(i):t;return"#"===f[0]?f:s||!n?"./"===f.slice(0,2)?f:"./"+f:f}function s(e,t,n){if(e){if("string"==typeof e)return n&&n.add(e),[e];let r,i;if(Array.isArray(e)){for(i=n||new Set,r=0;r<e.length;r++)s(e[r],t,i);if(!n&&i.size)return[...i]}else for(r in e)if(t.has(r))return s(e[r],t,n)}}function f(n,s,f,l){let u,g,c=i(n,f),a=t(l||{}),p=s[c];if(void 0===p){let e,t,n,r;for(r in s)t&&r.length<t.length||("/"===r[r.length-1]&&c.startsWith(r)?(g=c.substring(r.length),t=r):r.length>1&&(n=r.indexOf("*",1),~n&&(e=RegExp("^"+r.substring(0,n)+"(.*)"+r.substring(1+n)+"$").exec(c),e&&e[1]&&(g=e[1],t=r))));p=s[t]}if(p||e(n,c),u=o(p,a),u)return g&&r(u,g),u}function o(e,t,n,r){if(null==e)return;if("string"==typeof e)return r?(n&&n.add(e),[e]):void 0;let i,s;if(Array.isArray(e)){for(s=n||new Set,i=0;i<e.length;i++)o(e[i],t,s,r);return!n&&s.size?[...s]:void 0}if("types"in e){const r=o(e.types,t,n,!0);if(r&&r.length)return r}else if("typings"in e){const r=o(e.typings,t,n,!0);if(r&&r.length)return r}for(i in e)if("types"!==i&&"types"!==i&&t.has(i)){const s=o(e[i],t,n,r);if(s&&s.length)return s}}function l(e,t={}){let n,r=0,s=t.browser,f=t.fields||["module","main"],o="string"==typeof s;for(s&&!f.includes("browser")&&(f.unshift("browser"),o&&(s=i(e.name,s,!0)));r<f.length;r++)if(n=e[f[r]]){if("string"==typeof n);else{if("object"!=typeof n||"browser"!=f[r])continue;if(o&&(n=n[s],null==n))return s}return"string"==typeof n?"./"+n.replace(/^\.?\//,""):n}}function u(e,t,r){let i,s=e.exports;if(s){if("string"==typeof s)s={".":s};else for(i in s){"."!==i[0]&&(s={".":s});break}return n(e.name,s,t||".",r)}}function g(e,t,r){if(e.imports)return n(e.name,e.imports,t,r)}function c(e,t,n){return"#"===(t=i(e.name,t||"."))[0]?g(e,t,n):u(e,t,n)}function a(e,t,n){let r,i=e.exports;if(i){if("string"==typeof i)i={".":i};else for(r in i){"."!==r[0]&&(i={".":i});break}return f(e.name,i,t||".",n)}}exports.exports=u;exports.imports=g;exports.legacy=l;exports.resolve=c;exports.types=a;
|
||||
1
Frontend-Learner/node_modules/@es-joy/resolve.exports/dist/index.mjs
generated
vendored
Normal file
1
Frontend-Learner/node_modules/@es-joy/resolve.exports/dist/index.mjs
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
function e(e,t,n){throw new Error(n?`No known conditions for "${t}" specifier in "${e}" package`:`Missing "${t}" specifier in "${e}" package`)}function t(e){let t=new Set(["default"]);e.unsafe||t.add(e.require?"require":"import"),e.unsafe||t.add(e.browser?"browser":"node");for(const n of e.conditions||[])n.startsWith("!")?t.delete(n.slice(1)):t.add(n);return t}function n(n,f,o,l){let u,g,c=i(n,o),a=t(l||{}),p=f[c];if(void 0===p){let e,t,n,r;for(r in f)t&&r.length<t.length||("/"===r[r.length-1]&&c.startsWith(r)?(g=c.substring(r.length),t=r):r.length>1&&(n=r.indexOf("*",1),~n&&(e=RegExp("^"+r.substring(0,n)+"(.*)"+r.substring(1+n)+"$").exec(c),e&&e[1]&&(g=e[1],t=r))));p=f[t]}return p||e(n,c),u=s(p,a),u||e(n,c,1),g&&r(u,g),u}function r(e,t){let n,r=0,i=e.length,s=/[*]/g,f=/[/]$/;for(;r<i;r++)e[r]=s.test(n=e[r])?n.replace(s,t):f.test(n)?n+t:n}function i(e,t,n){if(e===t||"."===t)return".";let r=e+"/",i=r.length,s=t.slice(0,i)===r,f=s?t.slice(i):t;return"#"===f[0]?f:s||!n?"./"===f.slice(0,2)?f:"./"+f:f}function s(e,t,n){if(e){if("string"==typeof e)return n&&n.add(e),[e];let r,i;if(Array.isArray(e)){for(i=n||new Set,r=0;r<e.length;r++)s(e[r],t,i);if(!n&&i.size)return[...i]}else for(r in e)if(t.has(r))return s(e[r],t,n)}}function f(n,s,f,l){let u,g,c=i(n,f),a=t(l||{}),p=s[c];if(void 0===p){let e,t,n,r;for(r in s)t&&r.length<t.length||("/"===r[r.length-1]&&c.startsWith(r)?(g=c.substring(r.length),t=r):r.length>1&&(n=r.indexOf("*",1),~n&&(e=RegExp("^"+r.substring(0,n)+"(.*)"+r.substring(1+n)+"$").exec(c),e&&e[1]&&(g=e[1],t=r))));p=s[t]}if(p||e(n,c),u=o(p,a),u)return g&&r(u,g),u}function o(e,t,n,r){if(null==e)return;if("string"==typeof e)return r?(n&&n.add(e),[e]):void 0;let i,s;if(Array.isArray(e)){for(s=n||new Set,i=0;i<e.length;i++)o(e[i],t,s,r);return!n&&s.size?[...s]:void 0}if("types"in e){const r=o(e.types,t,n,!0);if(r&&r.length)return r}else if("typings"in e){const r=o(e.typings,t,n,!0);if(r&&r.length)return r}for(i in e)if("types"!==i&&"types"!==i&&t.has(i)){const s=o(e[i],t,n,r);if(s&&s.length)return s}}function l(e,t={}){let n,r=0,s=t.browser,f=t.fields||["module","main"],o="string"==typeof s;for(s&&!f.includes("browser")&&(f.unshift("browser"),o&&(s=i(e.name,s,!0)));r<f.length;r++)if(n=e[f[r]]){if("string"==typeof n);else{if("object"!=typeof n||"browser"!=f[r])continue;if(o&&(n=n[s],null==n))return s}return"string"==typeof n?"./"+n.replace(/^\.?\//,""):n}}function u(e,t,r){let i,s=e.exports;if(s){if("string"==typeof s)s={".":s};else for(i in s){"."!==i[0]&&(s={".":s});break}return n(e.name,s,t||".",r)}}function g(e,t,r){if(e.imports)return n(e.name,e.imports,t,r)}function c(e,t,n){return"#"===(t=i(e.name,t||"."))[0]?g(e,t,n):u(e,t,n)}function a(e,t,n){let r,i=e.exports;if(i){if("string"==typeof i)i={".":i};else for(r in i){"."!==r[0]&&(i={".":i});break}return f(e.name,i,t||".",n)}}export{u as exports,g as imports,l as legacy,c as resolve,a as types};
|
||||
106
Frontend-Learner/node_modules/@es-joy/resolve.exports/index.d.ts
generated
vendored
Normal file
106
Frontend-Learner/node_modules/@es-joy/resolve.exports/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
export type Options = {
|
||||
/**
|
||||
* When true, adds the "browser" conditions.
|
||||
* Otherwise the "node" condition is enabled.
|
||||
* @default false
|
||||
*/
|
||||
browser?: boolean;
|
||||
/**
|
||||
* Any custom conditions to match.
|
||||
* @note Array order does not matter. Priority is determined by the key-order of conditions defined within a package's imports/exports mapping.
|
||||
* @default []
|
||||
*/
|
||||
conditions?: readonly string[];
|
||||
/**
|
||||
* When true, adds the "require" condition.
|
||||
* Otherwise the "import" condition is enabled.
|
||||
* @default false
|
||||
*/
|
||||
require?: boolean;
|
||||
/**
|
||||
* Prevents "require", "import", "browser", and/or "node" conditions from being added automatically.
|
||||
* When enabled, only `options.conditions` are added alongside the "default" condition.
|
||||
* @important Enabling this deviates from Node.js default behavior.
|
||||
* @default false
|
||||
*/
|
||||
unsafe?: boolean;
|
||||
}
|
||||
|
||||
export function resolve<T=Package>(pkg: T, entry?: string, options?: Options): Imports.Output | Exports.Output | void;
|
||||
export function imports<T=Package>(pkg: T, entry?: string, options?: Options): Imports.Output | void;
|
||||
export function exports<T=Package>(pkg: T, target: string, options?: Options): Exports.Output | void;
|
||||
|
||||
export function legacy<T=Package>(pkg: T, options: { browser: true, fields?: readonly string[] }): Browser | void;
|
||||
export function legacy<T=Package>(pkg: T, options: { browser: string, fields?: readonly string[] }): string | false | void;
|
||||
export function legacy<T=Package>(pkg: T, options: { browser: false, fields?: readonly string[] }): string | void;
|
||||
export function legacy<T=Package>(pkg: T, options?: {
|
||||
browser?: boolean | string;
|
||||
fields?: readonly string[];
|
||||
}): Browser | string;
|
||||
|
||||
/**
|
||||
* Resolve only `types` and `typings` entries within exports, even when nested under
|
||||
* condition branches like "import"/"require". Returns undefined if not found.
|
||||
*/
|
||||
export function types<T=Package>(pkg: T, target?: string, options?: Options): Exports.Output | void;
|
||||
|
||||
// ---
|
||||
|
||||
/**
|
||||
* A resolve condition
|
||||
* @example "node", "default", "production"
|
||||
*/
|
||||
export type Condition = string;
|
||||
|
||||
/** An internal file path */
|
||||
export type Path = `./${string}`;
|
||||
|
||||
export type Imports = {
|
||||
[entry: Imports.Entry]: Imports.Value;
|
||||
}
|
||||
|
||||
export namespace Imports {
|
||||
export type Entry = `#${string}`;
|
||||
|
||||
type External = string;
|
||||
|
||||
/** strings are dependency names OR internal paths */
|
||||
export type Value = External | Path | null | {
|
||||
[c: Condition]: Value;
|
||||
} | Value[];
|
||||
|
||||
|
||||
export type Output = Array<External|Path>;
|
||||
}
|
||||
|
||||
export type Exports = Path | {
|
||||
[path: Exports.Entry]: Exports.Value;
|
||||
[cond: Condition]: Exports.Value;
|
||||
}
|
||||
|
||||
export namespace Exports {
|
||||
/** Allows "." and "./{name}" */
|
||||
export type Entry = `.${string}`;
|
||||
|
||||
/** strings must be internal paths */
|
||||
export type Value = Path | null | {
|
||||
[c: Condition]: Value;
|
||||
} | Value[];
|
||||
|
||||
export type Output = Path[];
|
||||
}
|
||||
|
||||
export type Package = {
|
||||
name: string;
|
||||
version?: string;
|
||||
module?: string;
|
||||
main?: string;
|
||||
imports?: Imports;
|
||||
exports?: Exports;
|
||||
browser?: Browser;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export type Browser = string[] | string | {
|
||||
[file: Path | string]: string | false;
|
||||
}
|
||||
22
Frontend-Learner/node_modules/@es-joy/resolve.exports/license
generated
vendored
Normal file
22
Frontend-Learner/node_modules/@es-joy/resolve.exports/license
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.com),
|
||||
Brett Zamir
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
53
Frontend-Learner/node_modules/@es-joy/resolve.exports/package.json
generated
vendored
Normal file
53
Frontend-Learner/node_modules/@es-joy/resolve.exports/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
"version": "1.2.0",
|
||||
"name": "@es-joy/resolve.exports",
|
||||
"repository": "es-joy/resolve.exports",
|
||||
"description": "A tiny (952b), correct, general-purpose, and configurable \"exports\" and \"imports\" resolver without file-system reliance",
|
||||
"module": "dist/index.mjs",
|
||||
"main": "dist/index.js",
|
||||
"types": "index.d.ts",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Luke Edwards",
|
||||
"email": "luke.edwards05@gmail.com",
|
||||
"url": "https://lukeed.com"
|
||||
},
|
||||
"contributors": [
|
||||
"Brett Zamir"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"files": [
|
||||
"*.d.ts",
|
||||
"dist"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"keywords": [
|
||||
"esm",
|
||||
"exports",
|
||||
"esmodules",
|
||||
"fields",
|
||||
"modules",
|
||||
"resolution",
|
||||
"resolve"
|
||||
],
|
||||
"devDependencies": {
|
||||
"bundt": "next",
|
||||
"tsm": "2.3.0",
|
||||
"typescript": "5.9.3",
|
||||
"uvu": "0.5.6"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "bundt -m",
|
||||
"types": "tsc --noEmit",
|
||||
"test": "uvu -r tsm test"
|
||||
}
|
||||
}
|
||||
497
Frontend-Learner/node_modules/@es-joy/resolve.exports/readme.md
generated
vendored
Normal file
497
Frontend-Learner/node_modules/@es-joy/resolve.exports/readme.md
generated
vendored
Normal file
|
|
@ -0,0 +1,497 @@
|
|||
# @es-joy/resolve.exports [](https://github.com/es-joy/resolve.exports/actions) [](https://licenses.dev/npm/resolve.exports) [](https://codecov.io/gh/es-joy/resolve.exports)
|
||||
|
||||
> A tiny (952b), correct, general-purpose, and configurable `"exports"` and `"imports"` resolver without file-system reliance
|
||||
|
||||
***Why?***
|
||||
|
||||
Hopefully, this module may serve as a reference point (and/or be used directly) so that the varying tools and bundlers within the ecosystem can share a common approach with one another **as well as** with the native Node.js implementation.
|
||||
|
||||
With the push for ESM, we must be _very_ careful and avoid fragmentation. If we, as a community, begin propagating different _dialects_ of the resolution algorithm, then we're headed for deep trouble. It will make supporting (and using) `"exports"` nearly impossible, which may force its abandonment and along with it, its benefits.
|
||||
|
||||
Let's have nice things.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install @es-joy/resolve.exports
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
> Please see [`/test/`](/test) for examples.
|
||||
|
||||
```js
|
||||
import * as resolve from '@es-joy/resolve.exports';
|
||||
|
||||
// package.json contents
|
||||
const pkg = {
|
||||
"name": "foobar",
|
||||
"module": "dist/module.mjs",
|
||||
"main": "dist/require.js",
|
||||
"imports": {
|
||||
"#hash": {
|
||||
"import": {
|
||||
"browser": "./hash/web.mjs",
|
||||
"node": "./hash/node.mjs",
|
||||
},
|
||||
"default": "./hash/detect.js"
|
||||
}
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/module.mjs",
|
||||
"require": "./dist/require.js"
|
||||
},
|
||||
"./lite": {
|
||||
"worker": {
|
||||
"browser": "./lite/worker.browser.js",
|
||||
"node": "./lite/worker.node.js"
|
||||
},
|
||||
"import": "./lite/module.mjs",
|
||||
"require": "./lite/require.js"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// ---
|
||||
// Exports
|
||||
// ---
|
||||
|
||||
// entry: "foobar" === "." === default
|
||||
// conditions: ["default", "import", "node"]
|
||||
resolve.exports(pkg);
|
||||
resolve.exports(pkg, '.');
|
||||
resolve.exports(pkg, 'foobar');
|
||||
//=> ["./dist/module.mjs"]
|
||||
|
||||
// entry: "foobar/lite" === "./lite"
|
||||
// conditions: ["default", "import", "node"]
|
||||
resolve.exports(pkg, 'foobar/lite');
|
||||
resolve.exports(pkg, './lite');
|
||||
//=> ["./lite/module.mjs"]
|
||||
|
||||
// Enable `require` condition
|
||||
// conditions: ["default", "require", "node"]
|
||||
resolve.exports(pkg, 'foobar', { require: true }); //=> ["./dist/require.js"]
|
||||
resolve.exports(pkg, './lite', { require: true }); //=> ["./lite/require.js"]
|
||||
|
||||
// Throws "Missing <entry> specifier in <name> package" Error
|
||||
resolve.exports(pkg, 'foobar/hello');
|
||||
resolve.exports(pkg, './hello/world');
|
||||
|
||||
// Add custom condition(s)
|
||||
// conditions: ["default", "worker", "import", "node"]
|
||||
resolve.exports(pkg, 'foobar/lite', {
|
||||
conditions: ['worker']
|
||||
}); //=> ["./lite/worker.node.js"]
|
||||
|
||||
// Toggle "browser" condition
|
||||
// conditions: ["default", "worker", "import", "browser"]
|
||||
resolve.exports(pkg, 'foobar/lite', {
|
||||
conditions: ['worker'],
|
||||
browser: true
|
||||
}); //=> ["./lite/worker.browser.js"]
|
||||
|
||||
// ---
|
||||
// Types-only resolution
|
||||
// ---
|
||||
|
||||
// Find only `types` entries (or its synonym `typings`), even when nested under
|
||||
// conditions like `import`/`require`
|
||||
// Defaults to following the active branch (`import` by default, `require` when set)
|
||||
resolve.types({
|
||||
name: 'pkg',
|
||||
exports: {
|
||||
'.': {
|
||||
import: { types: './index.d.ts', default: './index.mjs' },
|
||||
require: { types: './index.cjs.d.ts', default: './index.cjs' }
|
||||
}
|
||||
}
|
||||
});
|
||||
//=> ["./index.d.ts"]
|
||||
|
||||
resolve.types({
|
||||
name: 'pkg',
|
||||
exports: {
|
||||
'.': {
|
||||
import: { types: './index.d.ts', default: './index.mjs' },
|
||||
require: { types: './index.cjs.d.ts', default: './index.cjs' }
|
||||
}
|
||||
}
|
||||
}, '.', { require: true });
|
||||
//=> ["./index.cjs.d.ts"]
|
||||
|
||||
// Disable non-"default" condition activate
|
||||
// NOTE: breaks from Node.js default behavior
|
||||
// conditions: ["default", "custom"]
|
||||
resolve.exports(pkg, 'foobar/lite', {
|
||||
conditions: ['custom'],
|
||||
unsafe: true,
|
||||
});
|
||||
//=> Error: No known conditions for "./lite" specifier in "foobar" package
|
||||
|
||||
// ---
|
||||
// Imports
|
||||
// ---
|
||||
|
||||
// conditions: ["default", "import", "node"]
|
||||
resolve.imports(pkg, '#hash');
|
||||
resolve.imports(pkg, 'foobar/#hash');
|
||||
//=> ["./hash/node.mjs"]
|
||||
|
||||
// conditions: ["default", "import", "browser"]
|
||||
resolve.imports(pkg, '#hash', { browser: true });
|
||||
resolve.imports(pkg, 'foobar/#hash');
|
||||
//=> ["./hash/web.mjs"]
|
||||
|
||||
// conditions: ["default"]
|
||||
resolve.imports(pkg, '#hash', { unsafe: true });
|
||||
resolve.imports(pkg, 'foobar/#hash');
|
||||
//=> ["./hash/detect.mjs"]
|
||||
|
||||
resolve.imports(pkg, '#hello/world');
|
||||
resolve.imports(pkg, 'foobar/#hello/world');
|
||||
//=> Error: Missing "#hello/world" specifier in "foobar" package
|
||||
|
||||
// ---
|
||||
// Legacy
|
||||
// ---
|
||||
|
||||
// prefer "module" > "main" (default)
|
||||
resolve.legacy(pkg); //=> "dist/module.mjs"
|
||||
|
||||
// customize fields order
|
||||
resolve.legacy(pkg, {
|
||||
fields: ['main', 'module']
|
||||
}); //=> "dist/require.js"
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
The [`resolve()`](#resolvepkg-entry-options), [`exports()`](#exportspkg-entry-options), and [`imports()`](#importspkg-target-options) functions share similar API signatures:
|
||||
|
||||
```ts
|
||||
export function resolve(pkg: Package, entry?: string, options?: Options): string[] | undefined;
|
||||
export function exports(pkg: Package, entry?: string, options?: Options): string[] | undefined;
|
||||
export function imports(pkg: Package, target: string, options?: Options): string[] | undefined;
|
||||
export function types(pkg: Package, entry?: string, options?: Options): string[] | undefined;
|
||||
// ^ not optional!
|
||||
```
|
||||
|
||||
All three:
|
||||
* accept a `package.json` file's contents as a JSON object
|
||||
* accept a target/entry identifier
|
||||
* may accept an [Options](#options) object
|
||||
* return `string[]`, `string`, or `undefined`
|
||||
|
||||
The only difference is that `imports()` must accept a target identifier as there can be no inferred default.
|
||||
|
||||
See below for further API descriptions.
|
||||
|
||||
> **Note:** There is also a [Legacy Resolver API](#legacy-resolver)
|
||||
|
||||
---
|
||||
|
||||
### resolve(pkg, entry?, options?)
|
||||
Returns: `string[]` or `undefined`
|
||||
|
||||
A convenience helper which automatically reroutes to [`exports()`](#exportspkg-entry-options) or [`imports()`](#importspkg-target-options) depending on the `entry` value.
|
||||
|
||||
When unspecified, `entry` defaults to the `"."` identifier, which means that `exports()` will be invoked.
|
||||
|
||||
```js
|
||||
import * as r from '@es-joy/resolve.exports';
|
||||
|
||||
let pkg = {
|
||||
name: 'foobar',
|
||||
// ...
|
||||
};
|
||||
|
||||
r.resolve(pkg);
|
||||
//~> r.exports(pkg, '.');
|
||||
|
||||
r.resolve(pkg, 'foobar');
|
||||
//~> r.exports(pkg, '.');
|
||||
|
||||
r.resolve(pkg, 'foobar/subpath');
|
||||
//~> r.exports(pkg, './subpath');
|
||||
|
||||
r.resolve(pkg, '#hash/md5');
|
||||
//~> r.imports(pkg, '#hash/md5');
|
||||
|
||||
r.resolve(pkg, 'foobar/#hash/md5');
|
||||
//~> r.imports(pkg, '#hash/md5');
|
||||
```
|
||||
|
||||
### exports(pkg, entry?, options?)
|
||||
Returns: `string[]` or `undefined`
|
||||
|
||||
Traverse the `"exports"` within the contents of a `package.json` file. <br>
|
||||
If the contents _does not_ contain an `"exports"` map, then `undefined` will be returned.
|
||||
|
||||
Successful resolutions will always result in a `string` or `string[]` value. This will be the value of the resolved mapping itself – which means that the output is a relative file path.
|
||||
|
||||
This function may throw an Error if:
|
||||
|
||||
* the requested `entry` cannot be resolved (aka, not defined in the `"exports"` map)
|
||||
* an `entry` _is_ defined but no known conditions were matched (see [`options.conditions`](#optionsconditions))
|
||||
|
||||
#### pkg
|
||||
Type: `object` <br>
|
||||
Required: `true`
|
||||
|
||||
The `package.json` contents.
|
||||
|
||||
#### entry
|
||||
Type: `string` <br>
|
||||
Required: `false` <br>
|
||||
Default: `.` (aka, root)
|
||||
|
||||
The desired target entry, or the original `import` path.
|
||||
|
||||
When `entry` _is not_ a relative path (aka, does not start with `'.'`), then `entry` is given the `'./'` prefix.
|
||||
|
||||
When `entry` begins with the package name (determined via the `pkg.name` value), then `entry` is truncated and made relative.
|
||||
|
||||
When `entry` is already relative, it is accepted as is.
|
||||
|
||||
***Examples***
|
||||
|
||||
Assume we have a module named "foobar" and whose `pkg` contains `"name": "foobar"`.
|
||||
|
||||
| `entry` value | treated as | reason |
|
||||
|-|-|-|
|
||||
| `null` / `undefined` | `'.'` | default |
|
||||
| `'.'` | `'.'` | value was relative |
|
||||
| `'foobar'` | `'.'` | value was `pkg.name` |
|
||||
| `'foobar/lite'` | `'./lite'` | value had `pkg.name` prefix |
|
||||
| `'./lite'` | `'./lite'` | value was relative |
|
||||
| `'lite'` | `'./lite'` | value was not relative & did not have `pkg.name` prefix |
|
||||
|
||||
|
||||
### imports(pkg, target, options?)
|
||||
Returns: `string[]` or `undefined`
|
||||
|
||||
Traverse the `"imports"` within the contents of a `package.json` file. <br>
|
||||
If the contents _does not_ contain an `"imports"` map, then `undefined` will be returned.
|
||||
|
||||
Successful resolutions will always result in a `string` or `string[]` value. This will be the value of the resolved mapping itself – which means that the output is a relative file path.
|
||||
|
||||
This function may throw an Error if:
|
||||
|
||||
* the requested `target` cannot be resolved (aka, not defined in the `"imports"` map)
|
||||
* an `target` _is_ defined but no known conditions were matched (see [`options.conditions`](#optionsconditions))
|
||||
|
||||
#### pkg
|
||||
Type: `object` <br>
|
||||
Required: `true`
|
||||
|
||||
The `package.json` contents.
|
||||
|
||||
#### target
|
||||
Type: `string` <br>
|
||||
Required: `true`
|
||||
|
||||
The target import identifier; for example, `#hash` or `#hash/md5`.
|
||||
|
||||
Import specifiers _must_ begin with the `#` character, as required by the resolution specification. However, if `target` begins with the package name (determined by the `pkg.name` value), then `resolve.exports` will trim it from the `target` identifier. For example, `"foobar/#hash/md5"` will be treated as `"#hash/md5"` for the `"foobar"` package.
|
||||
|
||||
## Options
|
||||
|
||||
The [`resolve()`](#resolvepkg-entry-options), [`imports()`](#importspkg-target-options), and [`exports()`](#exportspkg-entry-options) functions share these options. All properties are optional and you are not required to pass an `options` argument.
|
||||
|
||||
Collectively, the `options` are used to assemble a list of [conditions](https://nodejs.org/docs/latest-v18.x/api/packages.html#conditional-exports) that should be activated while resolving your target(s).
|
||||
|
||||
> **Note:** Although the Node.js documentation primarily showcases conditions alongside `"exports"` usage, they also apply to `"imports"` maps too. _([example](https://nodejs.org/docs/latest-v18.x/api/packages.html#subpath-imports))_
|
||||
|
||||
#### options.require
|
||||
Type: `boolean` <br>
|
||||
Default: `false`
|
||||
|
||||
When truthy, the `"require"` field is added to the list of allowed/known conditions. <br>
|
||||
Otherwise the `"import"` field is added instead.
|
||||
|
||||
#### options.browser
|
||||
Type: `boolean` <br>
|
||||
Default: `false`
|
||||
|
||||
When truthy, the `"browser"` field is added to the list of allowed/known conditions. <br>
|
||||
Otherwise the `"node"` field is added instead.
|
||||
|
||||
#### options.conditions
|
||||
Type: `string[]` <br>
|
||||
Default: `[]`
|
||||
|
||||
A list of additional/custom conditions that should be accepted when seen.
|
||||
|
||||
> **Important:** The order specified within `options.conditions` does not matter. <br>The matching order/priority is **always** determined by the `"exports"` map's key order.
|
||||
|
||||
For example, you may choose to accept a `"production"` condition in certain environments. Given the following `pkg` content:
|
||||
|
||||
```js
|
||||
const pkg = {
|
||||
// package.json ...
|
||||
"exports": {
|
||||
"worker": "./$worker.js",
|
||||
"require": "./$require.js",
|
||||
"production": "./$production.js",
|
||||
"import": "./$import.mjs",
|
||||
}
|
||||
};
|
||||
|
||||
resolve.exports(pkg, '.');
|
||||
// Conditions: ["default", "import", "node"]
|
||||
//=> ["./$import.mjs"]
|
||||
|
||||
resolve.exports(pkg, '.', {
|
||||
conditions: ['production']
|
||||
});
|
||||
// Conditions: ["default", "production", "import", "node"]
|
||||
//=> ["./$production.js"]
|
||||
|
||||
resolve.exports(pkg, '.', {
|
||||
conditions: ['production'],
|
||||
require: true,
|
||||
});
|
||||
// Conditions: ["default", "production", "require", "node"]
|
||||
//=> ["./$require.js"]
|
||||
|
||||
resolve.exports(pkg, '.', {
|
||||
conditions: ['production', 'worker'],
|
||||
require: true,
|
||||
});
|
||||
// Conditions: ["default", "production", "worker", "require", "node"]
|
||||
//=> ["./$worker.js"]
|
||||
|
||||
resolve.exports(pkg, '.', {
|
||||
conditions: ['production', 'worker']
|
||||
});
|
||||
// Conditions: ["default", "production", "worker", "import", "node"]
|
||||
//=> ["./$worker.js"]
|
||||
```
|
||||
|
||||
If you want to remove a condition, you can use the `!` prefix. For example, you only need `"types"`:
|
||||
|
||||
```js
|
||||
resolve.exports(pkg, '.', {
|
||||
conditions: ['!default', '!import', '!node', 'types']
|
||||
});
|
||||
// Conditions: ["types"]
|
||||
```
|
||||
|
||||
#### options.unsafe
|
||||
Type: `boolean` <br>
|
||||
Default: `false`
|
||||
|
||||
> **Important:** You probably do not want this option! <br>It will break out of Node's default resolution conditions.
|
||||
|
||||
When enabled, this option will ignore **all other options** except [`options.conditions`](#optionsconditions). This is because, when enabled, `options.unsafe` **does not** assume or provide any default conditions except the `"default"` condition.
|
||||
|
||||
```js
|
||||
resolve.exports(pkg, '.');
|
||||
//=> Conditions: ["default", "import", "node"]
|
||||
|
||||
resolve.exports(pkg, '.', { unsafe: true });
|
||||
//=> Conditions: ["default"]
|
||||
|
||||
resolve.exports(pkg, '.', { unsafe: true, require: true, browser: true });
|
||||
//=> Conditions: ["default"]
|
||||
```
|
||||
|
||||
In other words, this means that trying to use `options.require` or `options.browser` alongside `options.unsafe` will have no effect. In order to enable these conditions, you must provide them manually into the `options.conditions` list:
|
||||
|
||||
```js
|
||||
resolve.exports(pkg, '.', {
|
||||
unsafe: true,
|
||||
conditions: ["require"]
|
||||
});
|
||||
//=> Conditions: ["default", "require"]
|
||||
|
||||
resolve.exports(pkg, '.', {
|
||||
unsafe: true,
|
||||
conditions: ["browser", "require", "custom123"]
|
||||
});
|
||||
//=> Conditions: ["default", "browser", "require", "custom123"]
|
||||
```
|
||||
|
||||
## Legacy Resolver
|
||||
|
||||
Also included is a "legacy" method for resolving non-`"exports"` package fields. This may be used as a fallback method when for when no `"exports"` mapping is defined. In other words, it's completely optional (and tree-shakeable).
|
||||
|
||||
### legacy(pkg, options?)
|
||||
Returns: `string` or `undefined`
|
||||
|
||||
You may customize the field priority via [`options.fields`](#optionsfields).
|
||||
|
||||
When a field is found, its value is returned _as written_. <br>
|
||||
When no fields were found, `undefined` is returned. If you wish to mimic Node.js behavior, you can assume this means `'index.js'` – but this module does not make that assumption for you.
|
||||
|
||||
#### options.browser
|
||||
Type: `boolean` or `string` <br>
|
||||
Default: `false`
|
||||
|
||||
When truthy, ensures that the `'browser'` field is part of the acceptable `fields` list.
|
||||
|
||||
> **Important:** If your custom [`options.fields`](#optionsfields) value includes `'browser'`, then _your_ order is respected. <br>Otherwise, when truthy, `options.browser` will move `'browser'` to the front of the list, making it the top priority.
|
||||
|
||||
When `true` and `"browser"` is an object, then `legacy()` will return the the entire `"browser"` object.
|
||||
|
||||
You may also pass a string value, which will be treated as an import/file path. When this is the case and `"browser"` is an object, then `legacy()` may return:
|
||||
|
||||
* `false` – if the package author decided a file should be ignored; or
|
||||
* your `options.browser` string value – but made relative, if not already
|
||||
|
||||
> See the [`"browser" field specification](https://github.com/defunctzombie/package-browser-field-spec) for more information.
|
||||
|
||||
#### options.fields
|
||||
Type: `string[]` <br>
|
||||
Default: `['module', 'main']`
|
||||
|
||||
A list of fields to accept. The order of the array determines the priority/importance of each field, with the most important fields at the beginning of the list.
|
||||
|
||||
By default, the `legacy()` method will accept any `"module"` and/or "main" fields if they are defined. However, if both fields are defined, then "module" will be returned.
|
||||
|
||||
```js
|
||||
import { legacy } from '@es-joy/resolve.exports';
|
||||
|
||||
// package.json
|
||||
const pkg = {
|
||||
"name": "...",
|
||||
"worker": "worker.js",
|
||||
"module": "module.mjs",
|
||||
"browser": "browser.js",
|
||||
"main": "main.js",
|
||||
};
|
||||
|
||||
legacy(pkg);
|
||||
// fields = [module, main]
|
||||
//=> "module.mjs"
|
||||
|
||||
legacy(pkg, { browser: true });
|
||||
// fields = [browser, module, main]
|
||||
//=> "browser.mjs"
|
||||
|
||||
legacy(pkg, {
|
||||
fields: ['missing', 'worker', 'module', 'main']
|
||||
});
|
||||
// fields = [missing, worker, module, main]
|
||||
//=> "worker.js"
|
||||
|
||||
legacy(pkg, {
|
||||
fields: ['missing', 'worker', 'module', 'main'],
|
||||
browser: true,
|
||||
});
|
||||
// fields = [browser, missing, worker, module, main]
|
||||
//=> "browser.js"
|
||||
|
||||
legacy(pkg, {
|
||||
fields: ['module', 'browser', 'main'],
|
||||
browser: true,
|
||||
});
|
||||
// fields = [module, browser, main]
|
||||
//=> "module.mjs"
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
Loading…
Add table
Add a link
Reference in a new issue