Skip to content

Commit 3e04458

Browse files
committed
tweak
1 parent d6cc3db commit 3e04458

File tree

1 file changed

+10
-6
lines changed
  • packages/plugin-rsc/src/plugins

1 file changed

+10
-6
lines changed

packages/plugin-rsc/src/plugins/cjs.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ export function cjsModuleRunnerPlugin(): Plugin[] {
1919
applyToEnvironment: (env) => env.config.dev.moduleRunnerTransform,
2020
async transform(code, id) {
2121
if (
22-
(id.includes('/node_modules/') ||
23-
// it's not inside node_modules when developing rsc plugin inside pnpm workspace.
24-
id.includes(
25-
'/packages/plugin-rsc/dist/vendor/react-server-dom/',
26-
)) &&
22+
(id.includes('/node_modules/') || isDevCjs(id)) &&
2723
!id.startsWith(this.environment.config.cacheDir) &&
2824
/\b(require|exports)\b/.test(code)
2925
) {
@@ -76,7 +72,7 @@ export default module.exports;
7672
}
7773

7874
function extractPackageKey(id: string): string {
79-
if (id.includes('/packages/plugin-rsc/dist/vendor/react-server-dom/')) {
75+
if (isDevCjs(id)) {
8076
return '@vitejs/plugin-rsc'
8177
}
8278

@@ -97,3 +93,11 @@ function extractPackageKey(id: string): string {
9793
}
9894
return id
9995
}
96+
97+
// this is needed only when developing package itself within pnpm workspace
98+
function isDevCjs(id: string): boolean {
99+
return (
100+
!import.meta.url.includes('/node_modules/') &&
101+
id.includes('/vendor/react-server-dom/')
102+
)
103+
}

0 commit comments

Comments
 (0)