[build] Set file times to build time (#18742) (#18830)

This commit is contained in:
Jonathan Budzenski 2018-05-08 09:56:52 -05:00 committed by GitHub
parent cbbb4dc221
commit 928d3ead27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 4 deletions

View file

@ -250,6 +250,22 @@ describe('dev/build/lib/fs', () => {
expect(await read(resolve(destination, 'foo_dir/bar.txt'))).to.be('bar\n');
expect(await read(resolve(destination, 'foo_dir/.bar'))).to.be('dotfile\n');
});
it('supports atime and mtime', async () => {
const destination = resolve(TMP, 'a/b/c/d/e');
const time = new Date(1425298511000);
await copyAll(FIXTURES, destination, {
time
});
const barTxt = statSync(resolve(destination, 'foo_dir/bar.txt'));
const fooDir = statSync(resolve(destination, 'foo_dir'));
// precision is platform specific
const oneDay = 86400000;
expect(Math.abs(barTxt.atimeMs - time.getTime())).to.be.below(oneDay);
expect(Math.abs(fooDir.atimeMs - time.getTime())).to.be.below(oneDay);
expect(Math.abs(barTxt.mtimeMs - time.getTime())).to.be.below(oneDay);
});
});
describe('getFileHash()', () => {

View file

@ -6,7 +6,7 @@ import { createGunzip } from 'zlib';
import vfs from 'vinyl-fs';
import { promisify } from 'bluebird';
import mkdirpCb from 'mkdirp';
import { createPromiseFromStreams } from '../../../utils';
import { createPromiseFromStreams, createMapStream } from '../../../utils';
import { Extract } from 'tar';
@ -16,6 +16,7 @@ const chmodAsync = promisify(fs.chmod);
const writeFileAsync = promisify(fs.writeFile);
const readFileAsync = promisify(fs.readFile);
const readdirAsync = promisify(fs.readdir);
const utimesAsync = promisify(fs.utimes);
function assertAbsolute(path) {
if (!isAbsolute(path)) {
@ -70,6 +71,7 @@ export async function copyAll(sourceDir, destination, options = {}) {
const {
select = ['**/*'],
dot = false,
time,
} = options;
assertAbsolute(sourceDir);
@ -82,8 +84,8 @@ export async function copyAll(sourceDir, destination, options = {}) {
base: sourceDir,
dot,
}),
vfs.dest(destination)
vfs.dest(destination),
...(Boolean(time) ? [createMapStream(file => utimesAsync(file.path, time, time))] : []),
]);
}

View file

@ -9,7 +9,23 @@ export const CreateArchivesSourcesTask = {
await copyAll(
build.resolvePath('.'),
build.resolvePathForPlatform(platform, '.'),
{ dot: true },
{
select: [
'**/*',
'!node_modules/**',
],
dot: true,
},
);
const currentTime = new Date();
await copyAll(
build.resolvePath('node_modules'),
build.resolvePathForPlatform(platform, 'node_modules'),
{
dot: true,
time: currentTime
},
);
log.debug('Generic build source copied into', platform.getName(), 'specific build directory');