How to use backfill-logger - 10 common examples

To help you get started, we’ve selected a few backfill-logger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / backfill / packages / backfill / src / audit.ts View on Github external
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();
}
github microsoft / backfill / packages / backfill / src / audit.ts View on Github external
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();
}
github microsoft / backfill / packages / backfill / src / audit.ts View on Github external
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();
}
github microsoft / backfill / packages / backfill / src / audit.ts View on Github external
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
github microsoft / backfill / packages / backfill / src / audit.ts View on Github external
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, {
github microsoft / backfill / packages / backfill / src / hasher.ts View on Github external
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])
github microsoft / backfill / packages / backfill / src / commandRunner.ts View on Github external
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}"`);
          }
github microsoft / backfill / packages / backfill / src / hasher.ts View on Github external
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;
  }
}
github microsoft / backfill / packages / backfill / src / commandRunner.ts View on Github external
.then(() => {
          logger.setTime("buildTime", "buildCommand:run");
        })
        // Catch to pretty-print the command that failed and re-throw
github microsoft / backfill / packages / backfill / src / index.ts View on Github external
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);
  }
}