fix(plugins): replace __dirname with ESM-compatible import.meta.url - #37
Merged
Merged
Conversation
The V2 upgrade (dade6fb) added "type": "module" to all packages but left `__dirname` usages in place, which throws `ReferenceError: __dirname is not defined` when the built ESM plugins are loaded (e.g. via jiti in rspress.config.ts). Derive the directory from import.meta.url instead. Affected packages: google-analytics, vercel-analytics, back-to-top, file-tree, live2d, mermaid, reading-time.
Contributor
Author
|
pls merge and release, thx |
Contributor
Author
|
@SoonIter pls release packages |
Member
done |
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.
Summary
"type": "module"to all packages but left__dirnameusages in plugin sources, causingReferenceError: __dirname is not definedwhen the built ESM plugins are loaded (e.g. via jiti when loadingrspress.config.ts):__dirnamefromimport.meta.urlviapath.dirname(fileURLToPath(import.meta.url))in the 7 affected packages:google-analytics,vercel-analytics,back-to-top,file-tree,live2d,mermaid,reading-timeTest plan
pnpm buildfor all 7 packages succeeds; dist output contains the ESM-compatible derivationrspress-plugin-google-analytics/dist/index.jsin Node ESM no longer throws andglobalUIComponentsresolves correctlyrspress devin a downstream project with the patched plugin