Skip to content

Commit d1e2e06

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

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎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-
consttype=(awaitfs.exists(resolve(filePath))) ? 'UPDATE' : 'CREATE';
41-
pending.set(filePath,{ content, type });
40+
constentry=pending.get(filePath);
41+
if(entry){
42+
pending.set(filePath,{ ...entry, content });
43+
}else{
44+
consttype=(awaitfs.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+
consttree=createTree('/project',createMockFs());
101+
awaittree.write('new.ts','first');
102+
awaittree.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
consttree=createTree(
101111
'/project',

0 commit comments

Comments
 (0)