Skip to content

refactor(core): let Node decide the config module format - #71

Merged
Hebilicious merged 2 commits into
mainfrom
fix/loader-node-format
Sep 24, 2026
Merged

Hebilicious merged 2 commits into
mainfrom
fix/loader-node-format

Conversation

@Hebilicious

Copy link
Copy Markdown
Owner

Cleans up the loader change in #69, which worked but did more than it needed to.

packages/cssforge/src/loader.ts no longer walks package.json files, parses them, or guesses the module system from source text. It asks Node for the format Node chose and overrides only commonjs-typescript:

const loaded = nextLoad(url, context);
if (loaded.format !== "commonjs-typescript") return loaded;

return {
	format: "module-typescript",
	source: loaded.source ?? readFileSync(fileURLToPath(parsed), "utf8"),
	shortCircuit: true,
};

That drops packageTypeOf, its cache, and the usesEsmSyntax regex, whose false positive silently switched a CommonJS-authored file to ESM, so 67 lines become 15 and the rule reads as one sentence: TypeScript in the config graph loads as ESM when Node would read it as CommonJS.

Behavior change: a CommonJS-authored .ts module inside a CommonJS package now loads as ESM, matching the documented export default config shape. That is the trade for removing the heuristic, and the changeset says so.

Also adds the review rule to AGENTS.md: a pull request is never merged without an explicit instruction for that pull request, release pull requests included.

Verification: the loader test now covers "type": "commonjs", "type": "module", and an absent type field, and fails when the load hook is removed; cssforge:test, typecheck, format, readme-check, and jsr-dry-run pass; the JSR smoke passes with --require-deno; the example browser suite passes 5/5; and a Vite project built against locally packed 0.8.1 plus the plugin emits the tokens under all three type fields.

The loader asked Node for the format it chose and overrode only
`commonjs-typescript`, instead of walking package.json files and checking the
source text for ESM syntax. That removes a duplicated resolution rule, a cache,
and a heuristic whose false positive silently switched a CommonJS-authored file
to ESM.

The rule is now one sentence: TypeScript in the config graph loads as ESM when
Node would read it as CommonJS. The loader test covers the commonjs, module, and
absent type fields.
Merging needs an explicit instruction from the user for that pull request.
Opening one, green checks, and finished-looking work are not instructions.
Release pull requests are included.
@changeset-bot

changeset-bot Bot commented Sep 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5082eda

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hebilicious/cssforge Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Hebilicious
Hebilicious merged commit 1ef8e09 into main Sep 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant