Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/plugin-rsc/e2e/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/,
)
})
})
Expand Down
2 changes: 0 additions & 2 deletions packages/plugin-rsc/examples/react-router/cf/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
},
Expand Down
11 changes: 6 additions & 5 deletions packages/plugin-rsc/src/plugins/cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(['use-sync-external-store'])
const warnedPackages = new Set<string>()

return [
{
Expand Down Expand Up @@ -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)
}
Expand Down
Loading