Repository navigation
Commit 8b81f2d
authored
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
- .changeset
- crates/gritlint_core/tests/fixtures/export/expected
- packs/source-resolution
- fixtures
- dist-resolve-no-source-condition
- bad
- declared-keeps-condition
- packages/app
- root-declared-keeps-condition-no-bundler
- good
- declared-dist-map
- packages/app
- nested-declaration-is-not-one
- other-package-declares
- packages
- app
- lib
- publish-map-owned-elsewhere
- undeclared-keeps-condition
- packages/app
- gritlint-resolve-value
- bad
- boolean-value
- extra-key
- misspelled-key
- not-an-object
- other-value
- good
- declared
- nested-bin-key
- other-file-named-like-it
- undeclared
- tsdown-exports
- bad
- missing-dev-exports
- root-missing-dev-exports
- good
- omits-dev-exports
- packages/app
- root-omits-dev-exports
- tsdown-source-condition-required
- bad
- nested-declaration-is-not-one
- root-conditions-map
- root-undeclared-default-only
- string-subpath
- undeclared-drops-condition
- packages/app
- undeclared-string-exports
- wildcard-string-beside-condition
- good
- bundler-in-another-package
- packages
- app
- lib
- declared-dist
- packages/app
- invalid-declaration-reported-elsewhere
- no-bundler
- packages/app
- publish-config-map
- root-conditions-map-with-condition
- source-and-stylesheet
- packages/app
- string-exports-to-src
- rules
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
0 commit comments