mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-30 01:07:01 +08:00
This updates karma to 5.2.3, karma-coverage to the officially published version 2.0.3 (we were previously relying on a git commit) and karma-sourcemap-loader to 0.3.8. DISABLE_THIRD_PARTY_CHECK=Update Karma R=aerotwist@chromium.org Change-Id: Iaa365379d7c2c6eb9145b1507be1a0a3ae812359 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2527043 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Paul Lewis <aerotwist@chromium.org> Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Paul Lewis <aerotwist@chromium.org>
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
const debug = require('debug')('streamroller:moveAndMaybeCompressFile');
|
|
const fs = require('fs-extra');
|
|
const zlib = require('zlib');
|
|
|
|
const moveAndMaybeCompressFile = async (
|
|
sourceFilePath,
|
|
targetFilePath,
|
|
needCompress
|
|
) => {
|
|
if (sourceFilePath === targetFilePath) {
|
|
debug(
|
|
`moveAndMaybeCompressFile: source and target are the same, not doing anything`
|
|
);
|
|
return;
|
|
}
|
|
if (await fs.pathExists(sourceFilePath)) {
|
|
|
|
debug(
|
|
`moveAndMaybeCompressFile: moving file from ${sourceFilePath} to ${targetFilePath} ${
|
|
needCompress ? "with" : "without"
|
|
} compress`
|
|
);
|
|
if (needCompress) {
|
|
await new Promise((resolve, reject) => {
|
|
fs.createReadStream(sourceFilePath)
|
|
.pipe(zlib.createGzip())
|
|
.pipe(fs.createWriteStream(targetFilePath))
|
|
.on("finish", () => {
|
|
debug(
|
|
`moveAndMaybeCompressFile: finished compressing ${targetFilePath}, deleting ${sourceFilePath}`
|
|
);
|
|
fs.unlink(sourceFilePath)
|
|
.then(resolve)
|
|
.catch(() => {
|
|
debug(`Deleting ${sourceFilePath} failed, truncating instead`);
|
|
fs.truncate(sourceFilePath).then(resolve).catch(reject)
|
|
});
|
|
});
|
|
});
|
|
} else {
|
|
debug(
|
|
`moveAndMaybeCompressFile: deleting file=${targetFilePath}, renaming ${sourceFilePath} to ${targetFilePath}`
|
|
);
|
|
try {
|
|
await fs.move(sourceFilePath, targetFilePath, { overwrite: true });
|
|
} catch (e) {
|
|
debug(
|
|
`moveAndMaybeCompressFile: error moving ${sourceFilePath} to ${targetFilePath}`, e
|
|
);
|
|
debug(`Trying copy+truncate instead`);
|
|
await fs.copy(sourceFilePath, targetFilePath, { overwrite: true });
|
|
await fs.truncate(sourceFilePath);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = moveAndMaybeCompressFile;
|