Skip to content

Commit 0f6004b

Browse files
feat(init-worktree): copy .infisical.json into new worktrees to ensure Infisical config is present. This prevents missing config when bootstrapping a new worktree.
🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 8d580b1 commit 0f6004b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scripts/init-worktree.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bun
22

33
import { spawn } from 'child_process'
4-
import { existsSync, mkdirSync, writeFileSync } from 'fs'
4+
import { existsSync, mkdirSync, writeFileSync, copyFileSync } from 'fs'
55
import { join, resolve } from 'path'
66
import { createInterface } from 'readline'
77

@@ -218,6 +218,20 @@ NEXT_PUBLIC_WEB_PORT=${args.webPort}
218218
console.log('Created .env.worktree with port configurations')
219219
}
220220

221+
function copyInfisicalConfig(worktreePath: string): void {
222+
const sourceInfisicalPath = '.infisical.json'
223+
const targetInfisicalPath = join(worktreePath, '.infisical.json')
224+
225+
if (existsSync(sourceInfisicalPath)) {
226+
copyFileSync(sourceInfisicalPath, targetInfisicalPath)
227+
console.log('Copied .infisical.json to worktree')
228+
} else {
229+
console.warn(
230+
'Warning: .infisical.json not found in project root, make sure to run `infisical init` in your new worktree!',
231+
)
232+
}
233+
}
234+
221235
// Wrapper script no longer needed - .bin/bun handles .env.worktree loading
222236
// function createWrapperScript(worktreePath: string): void {
223237
// // This function is deprecated - the .bin/bun wrapper now handles .env.worktree loading
@@ -294,6 +308,7 @@ async function main(): Promise<void> {
294308

295309
// Create configuration files
296310
createEnvWorktreeFile(worktreePath, args)
311+
copyInfisicalConfig(worktreePath)
297312
// Note: .bin/bun wrapper now automatically loads .env.worktree
298313

299314
// Run direnv allow

0 commit comments

Comments
 (0)