xref: /expo/tools/src/vendoring/common.ts (revision 1a8a11e6)
1import chalk from 'chalk';
2
3import logger from '../Logger';
4import { CopyFileOptions, FileTransform, copyFileWithTransformsAsync } from '../Transforms';
5
6/**
7 * Copies vendored files from source directory to target directory
8 * with transforms applied to their content and relative path.
9 */
10export async function copyVendoredFilesAsync(
11  files: Set<string>,
12  options: Omit<CopyFileOptions, 'sourceFile'>
13): Promise<void> {
14  const unusedTransforms = new Set<FileTransform>(options.transforms.content);
15  for (const sourceFile of files) {
16    const { targetFile, transformsUsed } = await copyFileWithTransformsAsync({
17      sourceFile,
18      ...options,
19    });
20    transformsUsed.forEach((transform) => unusedTransforms.delete(transform));
21
22    if (sourceFile !== targetFile) {
23      logger.log('�� Renamed %s to %s', chalk.magenta(sourceFile), chalk.magenta(targetFile));
24    }
25  }
26  for (const unusedTransform of unusedTransforms) {
27    logger.warn(
28      '⚠️ A transform was never applied to vendored code.\nThis can indicate outdated transforms or bugs in the vendored package.\nPath(s): %s',
29      chalk.magenta(String(unusedTransform.paths ?? ''))
30    );
31  }
32}
33