Skip to content

Commit

Permalink
fix(core): improve generator
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Aug 28, 2024
1 parent 097b85d commit 91b43a8
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
type TargetConfiguration,
type Tree,
} from '@nx/devkit';
import { migrateProjectExecutorsToPlugin } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPlugin,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
processTargetOutputs,
toProjectRelativePath,
Expand Down Expand Up @@ -46,7 +49,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
updateNxJson,
} from '@nx/devkit';
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
import { migrateProjectExecutorsToPluginV1 } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPluginV1,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import { createNodes } from '../../plugins/plugin';
import { processBuildOptions } from './lib/process-build-options';
import { postTargetTransformer } from './lib/post-target-transformer';
Expand Down Expand Up @@ -97,7 +100,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
updateNxJson(tree, nxJson);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ class ExecutorToPluginMigrator<T> {
}
}

export class NoTargetsToMigrateError extends Error {
constructor() {
super('Could not find any targets to migrate.');
}
}

export async function migrateProjectExecutorsToPlugin<T>(
tree: Tree,
projectGraph: ProjectGraph,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
type TargetConfiguration,
type Tree,
} from '@nx/devkit';
import { migrateProjectExecutorsToPlugin } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPlugin,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import { processTargetOutputs } from '@nx/devkit/src/generators/plugin-migrations/plugin-migration-utils';
import { basename, dirname, relative } from 'node:path/posix';
import { interpolate } from 'nx/src/tasks-runner/utils';
Expand Down Expand Up @@ -40,7 +43,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
type Tree,
} from '@nx/devkit';
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
import { migrateProjectExecutorsToPluginV1 } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPluginV1,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import { createNodes } from '../../../plugins/plugin';
import { processBuildOptions } from './lib/process-build-options';
import { postTargetTransformer } from './lib/post-target-transformer';
Expand Down Expand Up @@ -140,7 +143,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
type TargetConfiguration,
type Tree,
} from '@nx/devkit';
import { migrateProjectExecutorsToPlugin } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPlugin,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
processTargetOutputs,
toProjectRelativePath,
Expand Down Expand Up @@ -40,7 +43,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createProjectGraphAsync, formatFiles, Tree } from '@nx/devkit';
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
import { migrateProjectExecutorsToPluginV1 } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPluginV1,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import { createNodes } from '../../plugins/plugin';
import { buildPostTargetTransformer } from './lib/build-post-target-transformer';
import { servePosTargetTransformer } from './lib/serve-post-target-tranformer';
Expand Down Expand Up @@ -45,7 +48,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate');
throw new NoTargetsToMigrateError();
}

if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
type Tree,
} from '@nx/devkit';
import { createNodesV2, PlaywrightPluginOptions } from '../../plugins/plugin';
import { migrateProjectExecutorsToPlugin } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPlugin,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';

interface Schema {
project?: string;
Expand Down Expand Up @@ -34,7 +37,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createProjectGraphAsync, formatFiles, type Tree } from '@nx/devkit';
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
import { migrateProjectExecutorsToPluginV1 } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPluginV1,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import { createNodes } from '../../../plugins/plugin';
import { postTargetTransformer } from './lib/post-target-transformer';
import { processStartOptions } from './lib/process-start-options';
Expand Down Expand Up @@ -123,7 +126,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createProjectGraphAsync, formatFiles, type Tree } from '@nx/devkit';
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
import { migrateProjectExecutorsToPluginV1 } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPluginV1,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import { createNodes } from '../../plugins/plugin';
import { buildPostTargetTransformer } from './lib/build-post-target-transformer';
import { servePostTargetTransformer } from './lib/serve-post-target-transformer';
Expand Down Expand Up @@ -45,7 +48,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { RollupExecutorOptions } from '../../executors/rollup/schema';
import type { RollupPluginOptions } from '../../plugins/plugin';
import { extractRollupConfigFromExecutorOptions } from './lib/extract-rollup-config-from-executor-options';
import { addPluginRegistrations } from './lib/add-plugin-registrations';
import { NoTargetsToMigrateError } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';

interface Schema {
project?: string;
Expand Down Expand Up @@ -100,7 +101,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

projects = getProjects(tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
type Tree,
} from '@nx/devkit';
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
import { migrateProjectExecutorsToPluginV1 } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPluginV1,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import { buildPostTargetTransformer } from './lib/build-post-target-transformer';
import { servePostTargetTransformer } from './lib/serve-post-target-transformer';
import { createNodes } from '../../plugins/plugin';
Expand Down Expand Up @@ -51,7 +54,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { createProjectGraphAsync, formatFiles, type Tree } from '@nx/devkit';
import { migrateProjectExecutorsToPlugin } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPlugin,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import { createNodesV2, VitePluginOptions } from '../../plugins/plugin';
import { buildPostTargetTransformer } from './lib/build-post-target-transformer';
import { servePostTargetTransformer } from './lib/serve-post-target-transformer';
Expand Down Expand Up @@ -55,7 +58,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

if (!options.skipFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
type Tree,
} from '@nx/devkit';
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
import { migrateProjectExecutorsToPlugin } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
migrateProjectExecutorsToPlugin,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import { tsquery } from '@phenomnomnominal/tsquery';
import * as ts from 'typescript';
import { createNodesV2, type WebpackPluginOptions } from '../../plugins/plugin';
Expand Down Expand Up @@ -63,7 +66,7 @@ export async function convertToInferred(tree: Tree, options: Schema) {
);

if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
throw new NoTargetsToMigrateError();
}

const installCallback = addDependenciesToPackageJson(
Expand Down
Loading

0 comments on commit 91b43a8

Please sign in to comment.