diff --git a/packages/plugin-rsc/e2e/basic.test.ts b/packages/plugin-rsc/e2e/basic.test.ts index 68097556..5cf1c21f 100644 --- a/packages/plugin-rsc/e2e/basic.test.ts +++ b/packages/plugin-rsc/e2e/basic.test.ts @@ -58,12 +58,20 @@ test.describe('dev-non-optimized-cjs', () => { ) }) - const f = useFixture({ root: 'examples/basic', mode: 'dev' }) + const f = useFixture({ + root: 'examples/basic', + mode: 'dev', + cliOptions: { + env: { + DEBUG: 'vite-rsc:cjs', + }, + }, + }) test('show warning', async ({ page }) => { await page.goto(f.url()) - expect(f.proc().stderr()).toContain( - `Found non-optimized CJS dependency in 'ssr' environment.`, + expect(f.proc().stderr()).toMatch( + /non-optimized CJS dependency in 'ssr' environment.*@vitejs\/test-dep-cjs\/index.js/, ) }) }) diff --git a/packages/plugin-rsc/examples/react-router/cf/vite.config.ts b/packages/plugin-rsc/examples/react-router/cf/vite.config.ts index 8cf7a02f..6895d0c1 100644 --- a/packages/plugin-rsc/examples/react-router/cf/vite.config.ts +++ b/packages/plugin-rsc/examples/react-router/cf/vite.config.ts @@ -45,13 +45,11 @@ export default defineConfig({ }, ssr: { optimizeDeps: { - include: ['react-router > cookie', 'react-router > set-cookie-parser'], exclude: ['react-router'], }, }, rsc: { optimizeDeps: { - include: ['react-router > cookie', 'react-router > set-cookie-parser'], exclude: ['react-router'], }, }, diff --git a/packages/plugin-rsc/src/plugins/cjs.ts b/packages/plugin-rsc/src/plugins/cjs.ts index a232f69c..a501bbe0 100644 --- a/packages/plugin-rsc/src/plugins/cjs.ts +++ b/packages/plugin-rsc/src/plugins/cjs.ts @@ -5,10 +5,12 @@ import path from 'node:path' import fs from 'node:fs' import * as esModuleLexer from 'es-module-lexer' import { transformCjsToEsm } from '../transforms/cjs' +import { createDebug } from '@hiogawa/utils' + +const debug = createDebug('vite-rsc:cjs') export function cjsModuleRunnerPlugin(): Plugin[] { - // use-sync-external-store is known to work fine so don't show warning - const warnedPackages = new Set(['use-sync-external-store']) + const warnedPackages = new Set() return [ { @@ -43,9 +45,8 @@ export function cjsModuleRunnerPlugin(): Plugin[] { // warning once per package const packageKey = extractPackageKey(id) if (!warnedPackages.has(packageKey)) { - this.warn( - `Found non-optimized CJS dependency in '${this.environment.name}' environment. ` + - `It is recommended to add the dependency to 'environments.${this.environment.name}.optimizeDeps.include'.`, + debug( + `non-optimized CJS dependency in '${this.environment.name}' environment: ${id}`, ) warnedPackages.add(packageKey) }