Skip to content

Commit 8b81f2d

Browse files
feat(source-resolution): a package declared "resolve": "dist" carries no source condition (#77)
A workspace package can now resolve to its built `dist/` for its workspace consumers, instead of to its `src/` through the source condition. It does that by declaring `"gritlint": { "resolve": "dist" }` in its `package.json`. The declaration alone decides; the rules check that the export map agrees with it. ## Rules | Rule | Check | |---|---| | `dist-resolve-no-source-condition` (new) | a declared package carries the condition on no `exports` subpath | | `tsdown-source-condition-required` (new) | in a package with a bundler config and no declaration, every export entry pointing into `./dist/` is an object that carries the condition | | `gritlint-resolve-value` (new) | a top-level `"gritlint"` key is exactly `{ "resolve": "dist" }` | | `tsdown-exports` (changed) | `devExports` may be left out; a `devExports` that is set must still be the condition string | `tsdown-exports` is a JavaScript rule, so it can't read the sibling `package.json`. That's why the rule that stops an undeclared package from dropping the condition lives on `package.json`, in `tsdown-source-condition-required`. `publishConfig.exports` stays with `publish-config-exports`. Only a top-level `"gritlint"` key counts as a declaration, so a `bin` entry named `gritlint` isn't one. ## Evidence - `cargo test -p gritlint_core` passes, 137 of 137. That includes every fixture case and the committed bundled-rule listing. - **New fixtures:** - For each new rule: bad cases at their exact locations, good cases, and decoys (a nested key, a key in another package, a bundler config in another directory, a stylesheet subpath, `publishConfig.exports`). - `tsdown-exports` gains good cases for an omitted `devExports`. - **No new findings on real trees:** `gritlint check` with the new rules finds nothing on gritlint's own repo or on a 6,807-file monorepo whose 52 libraries all use the source condition. So the rules enable at error severity with no baseline. - **Adversarial review:** a written review in a fresh context found several escapes, each reproduced as a failing fixture before the fix: string-valued and wildcard export entries, root conditions maps, `src/` string exports, `publishConfig.exports` double reports, and contradictory findings on an invalid declaration. - Left out on purpose: a bundled package with no `exports` field at all. The bundler writes `exports` on build. Co-authored-by: systemfsoftware-bot <318394648+systemfsoftware-bot@users.noreply.github.com>
1 parent 034617c commit 8b81f2d

106 files changed

Lines changed: 810 additions & 11 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 11 additions & 0 deletions

‎crates/gritlint_core/tests/fixtures/export/expected/bundled-listing.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ npm-provenance/provenance refused export-multifile: keep this rule in `gritlint
33
npm-provenance/public-access refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
44
npm-provenance/repository-url refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
55
source-resolution/api-extractor-tsconfig refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
6+
source-resolution/dist-resolve-no-source-condition refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
67
source-resolution/export-map-order refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
8+
source-resolution/gritlint-resolve-value refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
79
source-resolution/internals-export-map refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
810
source-resolution/publish-config-exports refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
911
source-resolution/shared-vitest-config refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
1012
source-resolution/tsconfig-condition refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
1113
source-resolution/tsconfig-paths refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
1214
source-resolution/tsconfig-preset-module-mode refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
1315
source-resolution/tsdown-exports refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
16+
source-resolution/tsdown-source-condition-required refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
1417
source-resolution/vitest-conditions refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.
1518
typecheck-build-mode/typecheck-build-mode refused export-multifile: keep this rule in `gritlint check`; only a single-file rule exports.

‎packs/source-resolution/README.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source-resolution/dist-resolve-no-source-condition packages/app/package.json:6:7-6:50

packs/source-resolution/fixtures/tsdown-exports/bad/missing-dev-exports/gritlint.json renamed to packs/source-resolution/fixtures/dist-resolve-no-source-condition/bad/declared-keeps-condition/gritlint.json

File renamed without changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@acme/app",
3+
"gritlint": { "resolve": "dist" },
4+
"exports": {
5+
".": {
6+
"@systemfsoftware/source": "./src/index.ts",
7+
"types": "./dist/index.d.ts",
8+
"default": "./dist/index.mjs"
9+
}
10+
}
11+
}

packs/source-resolution/fixtures/tsdown-exports/bad/missing-dev-exports/packages/app/tsdown.config.ts renamed to packs/source-resolution/fixtures/dist-resolve-no-source-condition/bad/declared-keeps-condition/packages/app/tsdown.config.ts

File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source-resolution/dist-resolve-no-source-condition package.json:6:7-6:50

packs/source-resolution/fixtures/tsdown-exports/bad/root-missing-dev-exports/gritlint.json renamed to packs/source-resolution/fixtures/dist-resolve-no-source-condition/bad/root-declared-keeps-condition-no-bundler/gritlint.json

File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@acme/app",
3+
"gritlint": { "resolve": "dist" },
4+
"exports": {
5+
"./tools": {
6+
"@systemfsoftware/source": "./src/index.ts",
7+
"types": "./dist/tools.d.ts",
8+
"default": "./dist/tools.mjs"
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)