Skip to content

Commit 2889a48

Browse files
committed
fix: fix format
1 parent cad0753 commit 2889a48

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

packages/plugin-rsc/src/plugins/validate-import.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function validateImportPlugin(): Plugin {
5151
if (this.environment.mode === 'dev') {
5252
if (id.startsWith(`\0virtual:vite-rsc/validate-imports/invalid/`)) {
5353
const chain = getImportChainDev(this.environment, id)
54-
const error = formatError(chain, this.environment.name)
54+
const error = formatError(chain)
5555
if (error) {
5656
this.error({
5757
id: chain[1],
@@ -68,15 +68,15 @@ export function validateImportPlugin(): Plugin {
6868
this,
6969
'\0virtual:vite-rsc/validate-imports/invalid/server-only',
7070
)
71-
const serverOnlyError = formatError(serverOnly, this.environment.name)
71+
const serverOnlyError = formatError(serverOnly)
7272
if (serverOnlyError) {
7373
throw new Error(serverOnlyError)
7474
}
7575
const clientOnly = getImportChainBuild(
7676
this,
7777
'\0virtual:vite-rsc/validate-imports/invalid/client-only',
7878
)
79-
const clientOnlyError = formatError(clientOnly, this.environment.name)
79+
const clientOnlyError = formatError(clientOnly)
8080
if (clientOnlyError) {
8181
throw new Error(clientOnlyError)
8282
}
@@ -117,14 +117,12 @@ function getImportChainBuild(ctx: Rollup.PluginContext, id: string): string[] {
117117
return chain
118118
}
119119

120-
function formatError(
121-
chain: string[],
122-
environmentName: string,
123-
): string | undefined {
120+
function formatError(chain: string[]): string | undefined {
124121
if (chain.length === 0) return
125122
const id = chain[0]!
126123
const source = id.slice(id.lastIndexOf('/') + 1)
127-
let result = `'${source}' cannot be imported in '${environmentName}' environment:\n`
124+
const buildName = source === 'server-only' ? 'client' : 'server'
125+
let result = `'${source}' cannot be imported in ${buildName} build:\n`
128126
result += chain
129127
.slice(1, 6)
130128
.map(

0 commit comments

Comments
 (0)