fix: resolve plugin source entry before dist to prevent workspace destruction#537
Merged
ascorbic merged 3 commits intoemdash-cms:mainfrom Apr 13, 2026
Merged
fix: resolve plugin source entry before dist to prevent workspace destruction#537ascorbic merged 3 commits intoemdash-cms:mainfrom
ascorbic merged 3 commits intoemdash-cms:mainfrom
Conversation
…truction
resolveSourceEntry() checked the direct dist path (e.g. dist/index.mjs)
before trying to resolve back to source (src/index.ts). After a full
`pnpm build`, the dist path exists and short-circuits the lookup —
returning a .mjs path that downstream code cannot handle:
1. TS_EXT_RE (/\.tsx?$/) fails to strip the .mjs extension, so
findBuildOutput searches for index.mjs.mjs (never exists).
2. tsdown receives the .mjs entry with config:false but still reads
tsconfig.json from CWD. Under certain timing conditions this
triggers a clean cycle that recursively deletes source files across
the entire packages/ directory (observed: 73k+ files wiped).
The fix reorders resolveSourceEntry() to try src/ paths first and fall
back to the direct path only when no source equivalent exists. This
matches the function's documented intent ("dist/foo.mjs → src/foo.ts").
Reproduction: clean install → pnpm build → pnpm test:unit (repeat 2-3
times). Without the fix, marketplace publish-e2e tests fail on every
run and source files are intermittently destroyed.
🦋 Changeset detectedLatest commit: c806f29 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
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 |
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
ascorbic
approved these changes
Apr 13, 2026
Collaborator
ascorbic
left a comment
There was a problem hiding this comment.
Yikes. Good find. Thanks
Collaborator
|
Can you add a changeset and sign the CLA |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Contributor
Author
|
Sorry about that — I wasn't familiar with the changeset workflow. I've added one now (f96bcdb). Thanks for the heads-up! |
Collaborator
|
Great, thanks! |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
Merged
fmhall
pushed a commit
to fmhall/emdash
that referenced
this pull request
Apr 13, 2026
…truction (emdash-cms#537) * fix: resolve plugin source entry before dist to prevent workspace destruction resolveSourceEntry() checked the direct dist path (e.g. dist/index.mjs) before trying to resolve back to source (src/index.ts). After a full `pnpm build`, the dist path exists and short-circuits the lookup — returning a .mjs path that downstream code cannot handle: 1. TS_EXT_RE (/\.tsx?$/) fails to strip the .mjs extension, so findBuildOutput searches for index.mjs.mjs (never exists). 2. tsdown receives the .mjs entry with config:false but still reads tsconfig.json from CWD. Under certain timing conditions this triggers a clean cycle that recursively deletes source files across the entire packages/ directory (observed: 73k+ files wiped). The fix reorders resolveSourceEntry() to try src/ paths first and fall back to the direct path only when no source equivalent exists. This matches the function's documented intent ("dist/foo.mjs → src/foo.ts"). Reproduction: clean install → pnpm build → pnpm test:unit (repeat 2-3 times). Without the fix, marketplace publish-e2e tests fail on every run and source files are intermittently destroyed. * chore: add changeset for bundle source entry fix --------- Co-authored-by: Matt Kane <mkane@cloudflare.com>
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.
What does this PR do?
resolveSourceEntry()checked the direct dist path (e.g.dist/index.mjs) before trying to resolve back to source (src/index.ts). After a fullpnpm build, the dist path exists and short-circuits the lookup, causing two problems:plugin bundlealways fails —TS_EXT_RE(/\.tsx?$/) cannot strip the.mjsextension, sofindBuildOutputsearches forindex.mjs.mjswhich never exists..mjsentry and under certain timing conditions triggers a recursive clean that wipes source files across the entirepackages/directory (observed: all of admin, auth, blocks, core, etc. deleted).The fix reorders
resolveSourceEntry()to trysrc/paths first and fall back to the direct path only when no source equivalent exists. This matches the function's documented intent (dist/foo.mjs → src/foo.ts).Why CI didn't catch this: The test job uses
--filter emdash... buildwhich only builds core and its dependencies — not the plugins. Sodist/index.mjsnever exists in CI, and the bug never triggers.Reproduction:
find . -type d \( -name dist -o -name node_modules \) -exec rm -rf {} +→pnpm install→pnpm build→pnpm test:unit(repeat 2–3 times). Without the fix, marketplace tests fail every run and source files are intermittently destroyed.Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runpnpm locale:extracthas been run (if applicable)AI-generated code disclosure
Screenshots / test output
Without fix (after
pnpm build→pnpm test:unit, 2–3 rounds):With fix (3 rounds of
pnpm build→pnpm test:unit):