From 090d7173e932e21a72bbfbbcb5dae5a934e37428 Mon Sep 17 00:00:00 2001 From: shilal Date: Sat, 6 Feb 2021 18:59:16 +0000 Subject: [PATCH] Give consistent sources to each plugin when migrating Currently, the list of sources in a project is recalculated after each plugin is run. Some plugins, like "explicitAny" and "declareMissingClasProperties", expand the scope of a project by pulling dependencies of the file they're modifying into the project. This means that the order in which plugins run impacts the files that ts-migrate touches. This commit finds sources for a pronect once, before any plugins are run, and re-uses them for each plugin. This prevents files from being pulled in, which is particularly surprising if the '--sources' flag is in use. --- packages/ts-migrate-server/src/migrate/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/ts-migrate-server/src/migrate/index.ts b/packages/ts-migrate-server/src/migrate/index.ts index 947b7e6..1348bf4 100644 --- a/packages/ts-migrate-server/src/migrate/index.ts +++ b/packages/ts-migrate-server/src/migrate/index.ts @@ -50,6 +50,9 @@ export default async function migrate({ log.info('Start...'); const pluginsTimer = new PerfTimer(); const updatedSourceFiles = new Set(); + const sourceFiles = project + .getSourceFiles() + .filter(({ fileName }) => !/(\.d\.ts|\.json)$|node_modules/.test(fileName)); for (let i = 0; i < config.plugins.length; i += 1) { const { plugin, options: pluginOptions } = config.plugins[i]; @@ -58,10 +61,6 @@ export default async function migrate({ const pluginTimer = new PerfTimer(); log.info(`${pluginLogPrefix} Plugin ${i + 1} of ${config.plugins.length}. Start...`); - const sourceFiles = project - .getSourceFiles() - .filter(({ fileName }) => !/(\.d\.ts|\.json)$|node_modules/.test(fileName)); - // eslint-disable-next-line no-restricted-syntax for (const sourceFile of sourceFiles) { const { fileName } = sourceFile;