Skip to content

Commit d0e4592

Browse files
committed
fix: use rm -f for single-file deletes in cleanupFiles
Single-file rm calls without -f would fail if the file is missing, e.g. if the upstream template changes between tags. Added -f to all single-file deletes for idempotent cleanup. Directory deletes already use -rf.
1 parent c8dc7fb commit d0e4592

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

source/__tests__/operations/cleanupFiles.test.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('cleanupFiles', () => {
127127
const commands = getExecFileCommands()
128128
const homeFolder = 'src/components/pageComponents/home'
129129
expect(commands).toContain(`rm -rf ${homeFolder}/Examples/demos/subgraphs`)
130-
expect(commands).toContain(`rm ${homeFolder}/Examples/index.tsx`)
130+
expect(commands).toContain(`rm -f ${homeFolder}/Examples/index.tsx`)
131131
expect(commands).toContain(
132132
`cp .install-files/home/Examples/index.tsx ${homeFolder}/Examples/index.tsx`,
133133
)
@@ -155,7 +155,7 @@ describe('cleanupFiles', () => {
155155
await cleanupFiles('/project/my_app', 'custom', ['demo', 'subgraph', 'vocs', 'husky'])
156156

157157
const commands = getExecFileCommands()
158-
expect(commands).toContain('rm typedoc.json')
158+
expect(commands).toContain('rm -f typedoc.json')
159159
})
160160

161161
it('removes typedoc:build from package.json scripts', async () => {
@@ -172,7 +172,7 @@ describe('cleanupFiles', () => {
172172
await cleanupFiles('/project/my_app', 'custom', ['demo', 'subgraph', 'typedoc', 'husky'])
173173

174174
const commands = getExecFileCommands()
175-
expect(commands).toContain('rm vocs.config.ts')
175+
expect(commands).toContain('rm -f vocs.config.ts')
176176
expect(commands).toContain('rm -rf docs')
177177
})
178178

@@ -193,8 +193,8 @@ describe('cleanupFiles', () => {
193193

194194
const commands = getExecFileCommands()
195195
expect(commands).toContain('rm -rf .husky')
196-
expect(commands).toContain('rm .lintstagedrc.mjs')
197-
expect(commands).toContain('rm commitlint.config.js')
196+
expect(commands).toContain('rm -f .lintstagedrc.mjs')
197+
expect(commands).toContain('rm -f commitlint.config.js')
198198
})
199199

200200
it('removes prepare from package.json scripts', async () => {
@@ -213,8 +213,8 @@ describe('cleanupFiles', () => {
213213
const commands = getExecFileCommands()
214214
expect(commands).toContain('rm -rf src/components/pageComponents/home')
215215
expect(commands).toContain('rm -rf src/subgraphs')
216-
expect(commands).toContain('rm typedoc.json')
217-
expect(commands).toContain('rm vocs.config.ts')
216+
expect(commands).toContain('rm -f typedoc.json')
217+
expect(commands).toContain('rm -f vocs.config.ts')
218218
expect(commands).toContain('rm -rf .husky')
219219
expect(commands).toContain('rm -rf .install-files')
220220
})
@@ -243,6 +243,16 @@ describe('cleanupFiles', () => {
243243
expect(commands.at(-1)).toBe('rm -rf .install-files')
244244
})
245245

246+
it('uses -f flag on all single-file rm calls for idempotent cleanup', async () => {
247+
await cleanupFiles('/project/my_app', 'custom', [])
248+
249+
const commands = getExecFileCommands()
250+
const rmCommands = commands.filter((cmd) => cmd.startsWith('rm '))
251+
for (const cmd of rmCommands) {
252+
expect(cmd).toMatch(/^rm -[rf]/)
253+
}
254+
})
255+
246256
describe('onProgress callback', () => {
247257
it('reports only Install script for full mode', async () => {
248258
const steps: string[] = []

source/operations/cleanupFiles.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function cleanupSubgraph(projectFolder: string, features: FeatureName[]):
4747
await execFile('rm', ['-rf', `${homeFolder}/Examples/demos/subgraphs`], {
4848
cwd: projectFolder,
4949
})
50-
await execFile('rm', [`${homeFolder}/Examples/index.tsx`], { cwd: projectFolder })
50+
await execFile('rm', ['-f', `${homeFolder}/Examples/index.tsx`], { cwd: projectFolder })
5151
await execFile(
5252
'cp',
5353
['.install-files/home/Examples/index.tsx', `${homeFolder}/Examples/index.tsx`],
@@ -57,18 +57,18 @@ async function cleanupSubgraph(projectFolder: string, features: FeatureName[]):
5757
}
5858

5959
async function cleanupTypedoc(projectFolder: string): Promise<void> {
60-
await execFile('rm', ['typedoc.json'], { cwd: projectFolder })
60+
await execFile('rm', ['-f', 'typedoc.json'], { cwd: projectFolder })
6161
}
6262

6363
async function cleanupVocs(projectFolder: string): Promise<void> {
64-
await execFile('rm', ['vocs.config.ts'], { cwd: projectFolder })
64+
await execFile('rm', ['-f', 'vocs.config.ts'], { cwd: projectFolder })
6565
await execFile('rm', ['-rf', 'docs'], { cwd: projectFolder })
6666
}
6767

6868
async function cleanupHusky(projectFolder: string): Promise<void> {
6969
await execFile('rm', ['-rf', '.husky'], { cwd: projectFolder })
70-
await execFile('rm', ['.lintstagedrc.mjs'], { cwd: projectFolder })
71-
await execFile('rm', ['commitlint.config.js'], { cwd: projectFolder })
70+
await execFile('rm', ['-f', '.lintstagedrc.mjs'], { cwd: projectFolder })
71+
await execFile('rm', ['-f', 'commitlint.config.js'], { cwd: projectFolder })
7272
}
7373

7474
export async function cleanupFiles(

0 commit comments

Comments
 (0)