Skip to content

Commit

Permalink
Set asset stats when writing file to theme-fs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmengo committed Sep 18, 2024
1 parent 1dce161 commit 60f895a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/theme/src/cli/utilities/theme-fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ describe('theme-fs', () => {
key: 'assets/new_file.css',
checksum: '1010',
value: 'content',
stats: {size: 7, mtime: expect.any(Number)},
attachment: '',
})
})

Expand All @@ -203,6 +205,8 @@ describe('theme-fs', () => {
key: 'assets/new_image.gif',
checksum: '1010',
attachment,
value: '',
stats: {size: 6, mtime: expect.any(Number)},
})
})

Expand All @@ -216,7 +220,13 @@ describe('theme-fs', () => {

let filesUpdated = false
vi.mocked(writeFile).mockImplementationOnce(() => {
filesUpdated = themeFileSystem.files.get(newAsset.key) === newAsset
expect(themeFileSystem.files.get(newAsset.key)).toEqual({
...newAsset,
attachment: '',
stats: {size: 7, mtime: expect.any(Number)},
})
filesUpdated = true

return Promise.resolve()
})

Expand Down
10 changes: 9 additions & 1 deletion packages/theme/src/cli/utilities/theme-fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,15 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti
await removeThemeFile(root, fileKey)
},
write: async (asset: ThemeAsset) => {
files.set(asset.key, asset)
files.set(
asset.key,
buildThemeAsset({
key: asset.key,
checksum: asset.checksum,
value: asset.value ?? '',
attachment: asset.attachment ?? '',
}),
)
await writeThemeFile(root, asset)
},
read,
Expand Down

0 comments on commit 60f895a

Please sign in to comment.