Skip to content

Commit 789e359

Browse files
authored
refactor(rsc): organize plugin utils (#779)
1 parent 1a07a8a commit 789e359

File tree

4 files changed

+12
-19
lines changed

4 files changed

+12
-19
lines changed

packages/plugin-rsc/src/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ import { generateEncryptionKey, toBase64 } from './utils/encryption-utils'
3434
import { createRpcServer } from './utils/rpc'
3535
import {
3636
cleanUrl,
37+
evalValue,
3738
normalizeViteImportAnalysisUrl,
3839
prepareError,
39-
} from './vite-utils'
40+
} from './plugins/vite-utils'
4041
import { cjsModuleRunnerPlugin } from './plugins/cjs'
4142
import {
4243
createVirtualPlugin,
43-
evalValue,
4444
getEntrySource,
4545
hashString,
4646
normalizeRelativePath,

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,6 @@ import {
77
type Rollup,
88
} from 'vite'
99

10-
// https://github.com/vitejs/vite/blob/ea9aed7ebcb7f4be542bd2a384cbcb5a1e7b31bd/packages/vite/src/node/utils.ts#L1469-L1475
11-
export function evalValue<T = any>(rawValue: string): T {
12-
const fn = new Function(`
13-
var console, exports, global, module, process, require
14-
return (\n${rawValue}\n)
15-
`)
16-
return fn()
17-
}
18-
19-
// https://github.com/vitejs/vite/blob/946831f986cb797009b8178659d2b31f570c44ff/packages/vite/src/shared/utils.ts#L31-L34
20-
const postfixRE = /[?#].*$/
21-
export function cleanUrl(url: string): string {
22-
return url.replace(postfixRE, '')
23-
}
24-
2510
export function sortObject<T extends object>(o: T) {
2611
return Object.fromEntries(
2712
Object.entries(o).sort(([a], [b]) => a.localeCompare(b)),

packages/plugin-rsc/src/vite-utils.ts renamed to packages/plugin-rsc/src/plugins/vite-utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// import analysis logic copied from vite
1+
// misc utilities copied from vite
22

33
import fs from 'node:fs'
44
import path from 'node:path'
@@ -152,3 +152,12 @@ function cleanStack(stack: string) {
152152
.filter((l) => /^\s*at/.test(l))
153153
.join('\n')
154154
}
155+
156+
// https://github.com/vitejs/vite/blob/ea9aed7ebcb7f4be542bd2a384cbcb5a1e7b31bd/packages/vite/src/node/utils.ts#L1469-L1475
157+
export function evalValue<T = any>(rawValue: string): T {
158+
const fn = new Function(`
159+
var console, exports, global, module, process, require
160+
return (\n${rawValue}\n)
161+
`)
162+
return fn()
163+
}

packages/plugin-rsc/tsdown.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export default defineConfig({
88
'src/browser.ts',
99
'src/ssr.tsx',
1010
'src/rsc.tsx',
11-
'src/vite-utils.ts',
1211
'src/core/browser.ts',
1312
'src/core/ssr.ts',
1413
'src/core/rsc.ts',

0 commit comments

Comments
 (0)