Skip to content

Commit

Permalink
Give consistent sources to each plugin when migrating
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shilal committed Feb 6, 2021
1 parent f882598 commit 090d717
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/ts-migrate-server/src/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export default async function migrate({
log.info('Start...');
const pluginsTimer = new PerfTimer();
const updatedSourceFiles = new Set<string>();
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];
Expand All @@ -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;
Expand Down

0 comments on commit 090d717

Please sign in to comment.