Repository navigation
feat(cjs): warn when platform is ignored for the CJS format - #1111
Merged
Merged
Conversation
β Deploy Preview for tsdown-main ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
tsdown
create-tsdown
@tsdown/css
@tsdown/exe
tsdown-migrate
commit: |
Contributor
There was a problem hiding this comment.
π’ Approval recommended
No active review issues remain for the change clarifying CJS platform behavior and warnings.
No open issues π
What changed in this PR
Makes tsdownβs Node.js platform default for CJS builds explicit, addressing the unexpected dependency resolution reported in #758 without changing platform selection.
Changes:
- Warns when CJS ignores a non-Node platform setting, after merging user
inputOptions. - Adds tests for warning and suppression cases.
- Documents the platform override and its effect on
import.metarewriting.
| File | Description |
|---|---|
src/βfeatures/βrolldown.ts |
Runs the warning check after input options resolve, skipping declaration-only passes. |
src/βfeatures/βcjs.ts |
Adds the platform warning with configuration guidance. |
src/βfeatures/βcjs.test.ts |
Tests when the warning is emitted or suppressed. |
skills/βtsdown/βreferences/βoption-platform.md |
Documents the warning and CJS platform override. |
docs/βzh-CN/βoptions/βplatform.md |
Updates Chinese platform documentation. |
docs/βoptions/βplatform.md |
Updates English platform documentation. |
Review effort: Balanced
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.
AI usage
Description
The
cjsformat is always built for thenodeplatform, soplatform: 'browser'is silently ignored for it. That includes resolving dependencies with thenodeexport condition. tsdown now warns about this and suggestsplatform: 'neutral', orinputOptions: { platform: 'browser' }to build CJS for the browser anyway.platform: 'neutral'doesn't warn, since it makes no runtime assumptions (e.g.--format cjs,esm --platform neutral).Shims are now applied by a plugin that decides in its
optionshook, from the final platform after the user'sinputOptionsare merged:shims:__dirname/__filenameinject (or define + banner forunbundle), as before.import.meta.url/filename/dirnameare rewritten the same way Rolldown does on node.So forcing the platform via
inputOptionsno longer loses theimport.metarewrite, and the warning check also runs on the merged options.Linked Issues
Closes #758
Additional context
Projects that build CJS with
platform: 'browser'will see the new warning, which fails the build underfailOnWarnuntil they switch toneutralor overrideinputOptions.platform.