export async function pacmak()

in packages/jsii-pacmak/lib/index.ts [22:159]


export async function pacmak({
  argv = {},
  clean = true,
  codeOnly = false,
  fingerprint = true,
  force = false,
  forceSubdirectory = true,
  forceTarget = false,
  inputDirectories,
  outputDirectory,
  parallel = true,
  recurse = false,
  rosettaTablet,
  rosettaUnknownSnippets = undefined,
  runtimeTypeChecking = true,
  targets = Object.values(TargetName),
  timers = new Timers(),
  updateNpmIgnoreFiles = false,
  validateAssemblies = false,
}: PacmakOptions): Promise<void> {
  const rosetta = new RosettaTabletReader({
    unknownSnippets: rosettaUnknownSnippets,
    prefixDisclaimer: true,
  });
  if (rosettaTablet) {
    await rosetta.loadTabletFromFile(rosettaTablet);
  }

  const modulesToPackageSorted = await findJsiiModules(
    inputDirectories,
    recurse,
  );
  const modulesToPackageFlat = flatten(modulesToPackageSorted);

  logging.info(`Found ${modulesToPackageFlat.length} modules to package`);
  if (modulesToPackageFlat.length === 0) {
    logging.warn('Nothing to do');
    return;
  }

  if (outputDirectory) {
    // Ensure this is consistently interpreted as relative to cwd(). This is transparent for absolute
    // paths, as those would be returned unmodified.
    const absoluteOutputDirectory = resolve(cwd(), outputDirectory);
    for (const mod of modulesToPackageFlat) {
      mod.outputDirectory = absoluteOutputDirectory;
    }
  } else if (updateNpmIgnoreFiles) {
    // if outdir is coming from package.json, verify it is excluded by .npmignore. if it is explicitly
    // defined via --out, don't perform this verification.
    await updateAllNpmIgnores(modulesToPackageFlat);
  }

  const packCommand = argv['pack-command'];
  await timers.recordAsync(packCommand, () => {
    logging.info('Packaging NPM bundles');
    return Promise.all(modulesToPackageFlat.map((m) => m.npmPack(packCommand)));
  });

  await timers.recordAsync('load jsii', () => {
    logging.info('Loading jsii assemblies and translations');
    const system = new TypeSystem();
    return Promise.all(
      modulesToPackageFlat.map(async (m) => {
        await m.load(system, validateAssemblies);
        return rosetta.addAssembly(m.assembly.spec, m.moduleDirectory);
      }),
    );
  });

  try {
    const targetSets = sliceTargets(
      modulesToPackageSorted,
      targets,
      forceTarget,
    );
    if (targetSets.every((s) => s.modulesSorted.length === 0)) {
      throw new Error(
        `None of the requested packages had any targets to build for '${targets.join(
          ', ',
        )}' (use --force-target to force)`,
      );
    }

    const perLanguageDirectory = targetSets.length > 1 || forceSubdirectory;

    // We run all target sets in parallel for minimal wall clock time
    await Promise.all(
      mapParallelOrSerial(
        targetSets,
        async (targetSet) => {
          logging.info(
            `Packaging '${targetSet.targetType}' for ${describePackages(
              targetSet,
            )}`,
          );
          return timers
            .recordAsync(targetSet.targetType, () =>
              buildTargetsForLanguage(
                targetSet.targetType,
                targetSet.modulesSorted,
                {
                  argv,
                  clean,
                  codeOnly,
                  fingerprint,
                  force,
                  perLanguageDirectory,
                  rosetta,
                  runtimeTypeChecking,
                },
              ),
            )
            .then(
              () => logging.info(`${targetSet.targetType} finished`),
              (err) => {
                logging.warn(`${targetSet.targetType} failed`);
                // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
                return Promise.reject(err);
              },
            );
        },
        { parallel },
      ),
    );
  } finally {
    if (clean) {
      logging.debug('Cleaning up');
      await timers.recordAsync('cleanup', () =>
        Promise.all(modulesToPackageFlat.map((m) => m.cleanup())),
      );
    } else {
      logging.info('Temporary directories retained (--no-clean)');
    }
  }

  logging.info(`Packaged. ${timers.display()}`);
}