Repository navigation
feat(source-resolution): a package declared "resolve": "dist" carries no source condition - #77
Merged
Conversation
… no source condition
A package.json may declare "gritlint": { "resolve": "dist" } so its workspace consumers resolve its built dist/
instead of its src/. Three rules check that its export map agrees:
- dist-resolve-no-source-condition: a declared package carries the condition on no exports subpath.
- tsdown-source-condition-required: in a package with a bundler config and no declaration, every export entry that
points into ./dist/ is an object that carries the condition, so leaving devExports out is not an undeclared way
to drop it.
- gritlint-resolve-value: a top-level "gritlint" key is exactly { "resolve": "dist" }.
tsdown-exports accepts a bundler config that leaves devExports out; a devExports it sets must still be the
condition string. publishConfig.exports stays with publish-config-exports, and only the top-level "gritlint" key
counts as a declaration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A workspace package can now resolve to its built
dist/for its workspace consumers, instead of to itssrc/through the source condition. It does that by declaring"gritlint": { "resolve": "dist" }in itspackage.json. The declaration alone decides; the rules check that the export map agrees with it.Rules
dist-resolve-no-source-condition(new)exportssubpathtsdown-source-condition-required(new)./dist/is an object that carries the conditiongritlint-resolve-value(new)"gritlint"key is exactly{ "resolve": "dist" }tsdown-exports(changed)devExportsmay be left out; adevExportsthat is set must still be the condition stringtsdown-exportsis a JavaScript rule, so it can't read the siblingpackage.json. That's why the rule that stops an undeclared package from dropping the condition lives onpackage.json, intsdown-source-condition-required.publishConfig.exportsstays withpublish-config-exports. Only a top-level"gritlint"key counts as a declaration, so abinentry namedgritlintisn't one.Evidence
cargo test -p gritlint_corepasses, 137 of 137. That includes every fixture case and the committed bundled-rule listing.publishConfig.exports).tsdown-exportsgains good cases for an omitteddevExports.gritlint checkwith 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.src/string exports,publishConfig.exportsdouble reports, and contradictory findings on an invalid declaration.exportsfield at all. The bundler writesexportson build.