Skip to content

Commit d1e2e06

Browse files
committed
fix(create-cli): preserve write type on repeated writes
1 parent 9fbee4c commit d1e2e06

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/create-cli/src/lib/setup/virtual-fs.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ export function createTree(
3737
},
3838

3939
write: async (filePath: string, content: string): Promise<void> => {
40-
const type = (await fs.exists(resolve(filePath))) ? 'UPDATE' : 'CREATE';
41-
pending.set(filePath, { content, type });
40+
const entry = pending.get(filePath);
41+
if (entry) {
42+
pending.set(filePath, { ...entry, content });
43+
} else {
44+
const type = (await fs.exists(resolve(filePath))) ? 'UPDATE' : 'CREATE';
45+
pending.set(filePath, { content, type });
46+
}
4247
},
4348

4449
listChanges: (): FileChange[] =>

packages/create-cli/src/lib/setup/virtual-fs.unit.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ describe('createTree', () => {
9696
]);
9797
});
9898

99+
it('should preserve CREATE type when writing to the same path twice', async () => {
100+
const tree = createTree('/project', createMockFs());
101+
await tree.write('new.ts', 'first');
102+
await tree.write('new.ts', 'second');
103+
104+
expect(tree.listChanges()).toStrictEqual([
105+
{ path: 'new.ts', type: 'CREATE', content: 'second' },
106+
]);
107+
});
108+
99109
it('should mark existing files as UPDATE', async () => {
100110
const tree = createTree(
101111
'/project',

0 commit comments

Comments
 (0)