Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0 #24

Merged
merged 35 commits into from
Jan 16, 2023
Merged

2.0 #24

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ae975b7
rename file
lukeed Jan 11, 2023
2f6ca63
chore: convert to typescript
lukeed Jan 12, 2023
1b567ed
chore: strict types
lukeed Jan 12, 2023
7937282
fix: remove node 10 (bcuz tsm,bundt)
lukeed Jan 12, 2023
ce32f0f
fix(ci): compile in 18.x only
lukeed Jan 12, 2023
2af9516
feat: export Package/Exports/Imports types
lukeed Jan 12, 2023
db4139f
chore: extract `utils` file w/ tests & revamp
lukeed Jan 13, 2023
f6a2760
chore: move `loop` to utils file
lukeed Jan 13, 2023
a8faf8a
chore: more `toEntry` tests
lukeed Jan 13, 2023
8751b0e
chore: invert `toEntry` boolean default
lukeed Jan 13, 2023
c658ad5
chore: add `utils.loop` tests
lukeed Jan 13, 2023
8304506
break: possible return `string[]` output;
lukeed Jan 13, 2023
c53b0c0
chore: extract `conditions` to utils
lukeed Jan 13, 2023
5093256
chore: rewrite for shared walker logic
lukeed Jan 15, 2023
707843b
chore: shuffle internal file exports
lukeed Jan 15, 2023
293fe34
chore: add `imports` and `exports` to dts file
lukeed Jan 15, 2023
62c782d
chore: move tests to `describe` syntax;
lukeed Jan 15, 2023
f4774c7
fix(alt): add `resolve` export
lukeed Jan 15, 2023
8b2b9e7
chore: move alt -> index
lukeed Jan 15, 2023
38980a8
chore: add `imports` tests
lukeed Jan 15, 2023
4c3af1f
chore: improve test coverage
lukeed Jan 15, 2023
93b8215
chore: rename test file
lukeed Jan 15, 2023
03c14c5
chore: more tests
lukeed Jan 15, 2023
7fb205e
chore: error message "entry" -> "specifier"
lukeed Jan 15, 2023
ccaf9ff
chore: update docs
lukeed Jan 15, 2023
5d7a613
chore: fix typos
lukeed Jan 15, 2023
1390ab6
chore: pkg desc
lukeed Jan 15, 2023
168ba52
2.0.0-next.0
lukeed Jan 15, 2023
282863d
fix(types): loosen entry input types
lukeed Jan 15, 2023
1bbfd69
chore: update readme
lukeed Jan 16, 2023
2067a5e
chore: readme spacing
lukeed Jan 16, 2023
e75e741
break: only return `string[]` or `undefined` outputs
lukeed Jan 16, 2023
584334a
chore: update module size
lukeed Jan 16, 2023
a9255fd
chore: shave 11b
lukeed Jan 16, 2023
23b6e2d
chore: add tests for clarity & shave 7b
lukeed Jan 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
nodejs: [10, 12, 14, 16, 18]
# Node 10.x not supported by tsm & bundt
nodejs: [12, 14, 16, 18]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand All @@ -34,9 +35,16 @@ jobs:
npm install
npm install -g nyc

- name: Type Check
run: npm run types

- name: Test w/ Coverage
run: nyc --include=src npm test

- name: Compile
if: matrix.nodejs >= 18
run: npm run build

- name: Report
if: matrix.nodejs >= 18
run: |
Expand Down
103 changes: 91 additions & 12 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,100 @@
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;
unsafe?: false;
} | {
conditions?: readonly string[];
unsafe?: true;
/**
* 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=any>(pkg: T, entry: string, options?: Options): string | void;

export type BrowserFiles = Record<string, string | false>;
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=any>(pkg: T, options: { browser: true, fields?: readonly string[] }): BrowserFiles | string | void;
export function legacy<T=any>(pkg: T, options: { browser: string, fields?: readonly string[] }): string | false | void;
export function legacy<T=any>(pkg: T, options: { browser: false, fields?: readonly string[] }): string | void;
export function legacy<T=any>(pkg: T, options?: {
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[];
}): BrowserFiles | string | false | void;
}): Browser | string;

// ---

/**
* 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;
}
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"version": "1.1.1",
"version": "2.0.0-next.0",
"name": "resolve.exports",
"repository": "lukeed/resolve.exports",
"description": "A tiny (813b), correct, general-purpose, and configurable \"exports\" resolver without file-system reliance",
"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",
Expand All @@ -16,8 +16,9 @@
"node": ">=10"
},
"scripts": {
"build": "bundt",
"test": "uvu -r esm test"
"build": "bundt -m",
"types": "tsc --noEmit",
"test": "uvu -r tsm test"
},
"files": [
"*.d.ts",
Expand All @@ -41,8 +42,9 @@
"resolve"
],
"devDependencies": {
"bundt": "1.1.2",
"esm": "3.2.25",
"uvu": "0.5.1"
"bundt": "next",
"tsm": "2.3.0",
"typescript": "4.9.4",
"uvu": "0.5.4"
}
}
Loading