Skip to content
This repository was archived by the owner on Jun 15, 2025. It is now read-only.

Commit 036f24b

Browse files
committed
avoid dups in the case of create-vite process being skipped (when rewriting existing dir)
1 parent bfaf96e commit 036f24b

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

index.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,14 @@ viteProcess.on('close', (code) => {
113113

114114
const tsconfigNodeJSONPath = resolve(cwd, 'tsconfig.node.json')
115115
const tsconfigNodeJSON = readFileSync(tsconfigNodeJSONPath, 'utf-8')
116-
const modifiedTsconfigNodeJSON = tsconfigNodeJSON.replace(
117-
'"compilerOptions": {',
118-
'"compilerOptions": {\n "lib": ["ESNext"],'
119-
)
120-
writeFileSync(tsconfigNodeJSONPath, modifiedTsconfigNodeJSON, 'utf8')
116+
117+
if (!tsconfigNodeJSON.includes('"lib": ["ESNext"],')) {
118+
const modifiedTsconfigNodeJSON = tsconfigNodeJSON.replace(
119+
'"compilerOptions": {',
120+
'"compilerOptions": {\n "lib": ["ESNext"],'
121+
)
122+
writeFileSync(tsconfigNodeJSONPath, modifiedTsconfigNodeJSON, 'utf8')
123+
}
121124
}
122125

123126
// patching the vite.config.ts to make socket:* modules external
@@ -126,11 +129,14 @@ viteProcess.on('close', (code) => {
126129

127130
const viteConfigTSPath = resolve(cwd, 'vite.config.ts')
128131
const viteConfigTS = readFileSync(viteConfigTSPath, 'utf-8')
129-
const modifiedViteConfigTS = viteConfigTS.replace(
130-
'defineConfig({',
131-
'defineConfig({\n build: {\n rollupOptions: {\n external(id) {\n return id.startsWith(\'socket:\')\n }\n }\n },'
132-
)
133-
writeFileSync(viteConfigTSPath, modifiedViteConfigTS, 'utf8')
132+
133+
if (!viteConfigTS.includes('external(id)')) {
134+
const modifiedViteConfigTS = viteConfigTS.replace(
135+
'defineConfig({',
136+
'defineConfig({\n build: {\n rollupOptions: {\n external(id) {\n return id.startsWith(\'socket:\')\n }\n }\n },'
137+
)
138+
writeFileSync(viteConfigTSPath, modifiedViteConfigTS, 'utf8')
139+
}
134140
}
135141

136142
process.stdout.write(`\nDone!\n\nBuild and run your app with:\nssc build -r ${projectName}`)

0 commit comments

Comments
 (0)