From 2d860044352aab70cec6a6416f06ea9fd49ec36b Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Thu, 21 Jan 2021 10:32:27 -0600 Subject: [PATCH] [build/fs] Fix copyAll default atime and mtime (#88921) --- src/dev/build/lib/fs.ts | 4 ++-- src/dev/build/lib/integration_tests/fs.test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/dev/build/lib/fs.ts b/src/dev/build/lib/fs.ts index 451462d0cb14e6..f01fbc6283ec5a 100644 --- a/src/dev/build/lib/fs.ts +++ b/src/dev/build/lib/fs.ts @@ -153,7 +153,7 @@ export async function copy(source: string, destination: string, options: CopyOpt interface CopyAllOptions { select?: string[]; dot?: boolean; - time?: string | number | Date; + time?: Date; } export async function copyAll( @@ -161,7 +161,7 @@ export async function copyAll( destination: string, options: CopyAllOptions = {} ) { - const { select = ['**/*'], dot = false, time = Date.now() } = options; + const { select = ['**/*'], dot = false, time = new Date() } = options; assertAbsolute(sourceDir); assertAbsolute(destination); diff --git a/src/dev/build/lib/integration_tests/fs.test.ts b/src/dev/build/lib/integration_tests/fs.test.ts index 6052924f34921e..fa8a534d6e6b56 100644 --- a/src/dev/build/lib/integration_tests/fs.test.ts +++ b/src/dev/build/lib/integration_tests/fs.test.ts @@ -244,6 +244,20 @@ describe('copyAll()', () => { expect(Math.abs(fooDir.atimeMs - time.getTime())).toBeLessThan(oneDay); expect(Math.abs(barTxt.mtimeMs - time.getTime())).toBeLessThan(oneDay); }); + + it('defaults atime and mtime to now', async () => { + const destination = resolve(TMP, 'a/b/c/d/e/f'); + await copyAll(FIXTURES, destination); + const barTxt = statSync(resolve(destination, 'foo_dir/bar.txt')); + const fooDir = statSync(resolve(destination, 'foo_dir')); + + // precision is platform specific + const now = new Date(); + const oneDay = 86400000; + expect(Math.abs(barTxt.atimeMs - now.getTime())).toBeLessThan(oneDay); + expect(Math.abs(fooDir.atimeMs - now.getTime())).toBeLessThan(oneDay); + expect(Math.abs(barTxt.mtimeMs - now.getTime())).toBeLessThan(oneDay); + }); }); describe('getFileHash()', () => {