Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function closeWatcher() {
// Wait for one second before closing, giving time for file changes to propagate
await delay(1000);
if (changedFilesOutsideScope.length > 0) {
logger.warn(sideEffectWarningString);
changedFilesOutsideScope.forEach(file => logger.warn(`- ${file}`));
logger.warn(sideEffectCallToActionString);
} else {
logger.info(noSideEffectString);
}
watcher.close();
}
export async function closeWatcher() {
// Wait for one second before closing, giving time for file changes to propagate
await delay(1000);
if (changedFilesOutsideScope.length > 0) {
logger.warn(sideEffectWarningString);
changedFilesOutsideScope.forEach(file => logger.warn(`- ${file}`));
logger.warn(sideEffectCallToActionString);
} else {
logger.info(noSideEffectString);
}
watcher.close();
}
export async function closeWatcher() {
// Wait for one second before closing, giving time for file changes to propagate
await delay(1000);
if (changedFilesOutsideScope.length > 0) {
logger.warn(sideEffectWarningString);
changedFilesOutsideScope.forEach(file => logger.warn(`- ${file}`));
logger.warn(sideEffectCallToActionString);
} else {
logger.info(noSideEffectString);
}
watcher.close();
}
export function initializeWatcher(
packageRoot: string,
internalCacheFolder: string,
logFolder: string,
outputFolder: string | string[],
hashGlobs: string[]
) {
// Trying to find the git root and using it as an approximation of code boundary
const repositoryRoot = getGitRepositoryRoot(packageRoot);
// Empty the arrays
changedFilesOutsideScope = [];
changedFilesInsideScope = [];
logger.info("Running in AUDIT mode");
logger.info(`[audit] Watching file changes in: ${repositoryRoot}`);
logger.info(`[audit] Backfill will cache folder: ${outputFolder}`);
// Define globs
const ignoreGlobs = addGlobstars([
".git",
".cache",
logFolder,
internalCacheFolder
]);
const cacheFolderGlob = outputFolderAsArray(outputFolder).map(folder =>
path.posix.join("**", folder, "**")
);
watcher = chokidar
export function initializeWatcher(
packageRoot: string,
internalCacheFolder: string,
logFolder: string,
outputFolder: string | string[],
hashGlobs: string[]
) {
// Trying to find the git root and using it as an approximation of code boundary
const repositoryRoot = getGitRepositoryRoot(packageRoot);
// Empty the arrays
changedFilesOutsideScope = [];
changedFilesInsideScope = [];
logger.info("Running in AUDIT mode");
logger.info(`[audit] Watching file changes in: ${repositoryRoot}`);
logger.info(`[audit] Backfill will cache folder: ${outputFolder}`);
// Define globs
const ignoreGlobs = addGlobstars([
".git",
".cache",
logFolder,
internalCacheFolder
]);
const cacheFolderGlob = outputFolderAsArray(outputFolder).map(folder =>
path.posix.join("**", folder, "**")
);
watcher = chokidar
.watch(hashGlobs, {
const hashOfBuildCommand = createHash(this.buildCommandSignature).then(
hash => {
logger.verbose(`hashOfBuildCommand: ${hash}`);
return hash;
}
);
const hashOfOwnFiles = this.getHashOfOwnFiles().then(hash => {
logger.verbose(`hashOfOwnFiles: ${hash}`);
return hash;
});
const hashOfLockFile = this.getHashOfLockFile().then(hash => {
logger.verbose(`hashOfLockFile: ${hash}`);
return hash;
});
logger.profile("hasher:calculateHash");
// 1. Create hash to be used when fetching cache from cache storage
const packageHash = await Promise.all([
...hashOfDependencies,
hashOfBuildCommand,
hashOfOwnFiles,
hashOfLockFile
])
.then(hashes => hashes.filter(notEmpty))
.then(hashes => createHash(hashes));
logger.profile("hasher:calculateHash");
// 2. Create hash to be stored in the package. Used to communicate the state
// of the package to dependent packages (parents)
await Promise.all([...hashOfDependencies, hashOfOwnFiles, hashOfLockFile])
return async (): Promise => {
const parsedBuildCommand = buildCommand.join(" ");
if (!parsedBuildCommand) {
throw new Error("Command not provided");
}
// Clear outputFolder to guarantee a deterministic cache
if (clearOutputFolder) {
await Promise.all(
outputFolderAsArray(outputFolder).map(folder => fs.remove(folder))
);
}
// Set up runner
logger.profile("buildCommand:run");
const runner = execa(parsedBuildCommand, {
shell: true,
...(process.env.NODE_ENV !== "test" ? { stdio: "inherit" } : {})
});
return (
runner
// Add build time to the performance logger
.then(() => {
logger.setTime("buildTime", "buildCommand:run");
})
// Catch to pretty-print the command that failed and re-throw
.catch(err => {
if (process.env.NODE_ENV !== "test") {
logger.error(`Failed while running: "${parsedBuildCommand}"`);
}
hashOfOwnFiles,
hashOfLockFile
])
.then(hashes => hashes.filter(notEmpty))
.then(hashes => createHash(hashes));
logger.profile("hasher:calculateHash");
// 2. Create hash to be stored in the package. Used to communicate the state
// of the package to dependent packages (parents)
await Promise.all([...hashOfDependencies, hashOfOwnFiles, hashOfLockFile])
.then(hashes => hashes.filter(notEmpty))
.then(hashes => createHash(hashes))
.then(hash => this.writeHashToDisk(hash));
logger.setHash(packageHash);
return packageHash;
}
}
.then(() => {
logger.setTime("buildTime", "buildCommand:run");
})
// Catch to pretty-print the command that failed and re-throw
initializeWatcher(
packageRoot,
internalCacheFolder,
logFolder,
outputFolder,
hashGlobs
);
}
await backfill(config, cacheStorage, buildCommand, hasher);
if (argv["audit"]) {
await closeWatcher();
}
} catch (err) {
logger.error(err);
process.exit(1);
}
}