From 232ceeea5f449487dc368a92d026677a9bbc73c1 Mon Sep 17 00:00:00 2001 From: Hamed Rabah <26891088+hamedrabah@users.noreply.github.com> Date: Mon, 31 Aug 2026 00:10:48 -0700 Subject: [PATCH] fix(cli): ignore string braces when editing targets --- packages/cli/src/commands/ship.test.ts | 23 +++++++++ packages/cli/src/commands/ship.ts | 65 ++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/ship.test.ts b/packages/cli/src/commands/ship.test.ts index 6d624b9f..0209e967 100644 --- a/packages/cli/src/commands/ship.test.ts +++ b/packages/cli/src/commands/ship.test.ts @@ -82,6 +82,29 @@ export default defineConfig({ expect(config).toContain('"deploy-vercel": { use: "deploy-vercel", config: {} },'); }); + it('adds a target after entries whose config strings contain braces', async () => { + const dir = await mkdtemp(join(tmpdir(), 'sh1pt-target-add-braces-')); + const file = join(dir, 'sh1pt.config.ts'); + await writeFile(file, `export default { + name: 'demo', + version: '0.0.0', + targets: { + "deploy-netlify": { + use: "deploy-netlify", + config: { successMessage: "deployed }" }, + }, + }, +}; +`); + + addTargetToConfig(file, 'deploy-vercel'); + + const config = await readFile(file, 'utf8'); + const manifest = await loadManifest(file); + expect(config).toContain('"deploy-vercel": { use: "deploy-vercel", config: {} },'); + expect(manifest.targets).toHaveProperty('deploy-vercel'); + }); + it('removes target entries that were added by the CLI', async () => { const dir = await mkdtemp(join(tmpdir(), 'sh1pt-target-remove-')); const file = join(dir, 'sh1pt.config.ts'); diff --git a/packages/cli/src/commands/ship.ts b/packages/cli/src/commands/ship.ts index 083bf199..c82d65f9 100644 --- a/packages/cli/src/commands/ship.ts +++ b/packages/cli/src/commands/ship.ts @@ -216,12 +216,13 @@ function targetEntriesFromSource(source: string, configPath: string): Record= 0 && source[i] === '\\'; i--) slashCount++; + return slashCount % 2 === 1; +} + function targetPropertyPattern(id: string): RegExp { const escaped = id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); return new RegExp(`^\\s*['"]?${escaped}['"]?\\s*:\\s*\\{\\s*use:\\s*['"][^'"]+['"]\\s*,\\s*config:\\s*\\{\\s*\\}\\s*\\},?\\r?\\n`, 'm');