Skip to content

Commit

Permalink
feat(angular): force explicit targets when NX_ADD_PLUGINS is not expl…
Browse files Browse the repository at this point in the history
…icitly true
  • Loading branch information
leosvelperez committed Feb 16, 2024
1 parent f29383d commit 219ba8b
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/angular/src/generators/add-linting/add-linting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export async function addLintingGenerator(
skipFormat: true,
rootProject: rootProject,
addPlugin: options.addPlugin,
addExplicitTargets: !options.addPlugin,
});
tasks.push(lintTask);

Expand Down
7 changes: 5 additions & 2 deletions packages/angular/src/generators/application/lib/add-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
import type { NormalizedSchema } from './normalized-schema';

export async function addE2e(tree: Tree, options: NormalizedSchema) {
// check for explicit false, separate e2e projects infer targets by default
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false';

if (options.e2eTestRunner === 'cypress') {
// TODO: This can call `@nx/web:static-config` generator when ready
addFileServerTarget(tree, options, 'serve-static');
Expand All @@ -34,7 +37,7 @@ export async function addE2e(tree: Tree, options: NormalizedSchema) {
devServerTarget: `${options.name}:serve:development`,
baseUrl: 'http://localhost:4200',
rootProject: options.rootProject,
addPlugin: options.addPlugin,
addPlugin: addPlugin,
});
} else if (options.e2eTestRunner === 'playwright') {
const { configurationGenerator: playwrightConfigurationGenerator } =
Expand Down Expand Up @@ -62,7 +65,7 @@ export async function addE2e(tree: Tree, options: NormalizedSchema) {
}`,
webServerAddress: `http://localhost:${options.port ?? 4200}`,
rootProject: options.rootProject,
addPlugin: options.addPlugin,
addPlugin: addPlugin,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ export async function cypressComponentConfigurationInternal(
tree: Tree,
options: CypressComponentConfigSchema
) {
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
options.addPlugin ??= process.env.NX_ADD_PLUGINS === 'true';

const projectConfig = readProjectConfiguration(tree, options.project);
const installTask = await baseCyCTConfig(tree, {
project: options.project,
skipFormat: true,
addPlugin: options.addPlugin,
addExplicitTargets: !options.addPlugin,
});

await configureCypressCT(tree, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export async function updateRootEsLintConfig(
unitTestRunner?: string
): Promise<void> {
await lintInitGenerator(tree, {
addPlugin: process.env.NX_ADD_PLUGINS !== 'false',
addPlugin: process.env.NX_ADD_PLUGINS === 'true',
});

if (!existingEsLintConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export async function generateStorybookConfiguration(
tree: Tree,
options: StorybookConfigurationOptions
): Promise<GeneratorCallback> {
const { configurationGenerator } = ensurePackage('@nx/storybook', nxVersion);
const addPlugin = process.env.NX_ADD_PLUGINS === 'true';

const { configurationGenerator } = ensurePackage<
typeof import('@nx/storybook')
>('@nx/storybook', nxVersion);
return await configurationGenerator(tree, {
project: options.project,
uiFramework: '@storybook/angular',
Expand All @@ -17,5 +21,7 @@ export async function generateStorybookConfiguration(
interactionTests: options.interactionTests,
configureStaticServe: options.configureStaticServe,
skipFormat: true,
addPlugin: addPlugin,
addExplicitTargets: !addPlugin,
});
}
1 change: 1 addition & 0 deletions packages/angular/src/generators/utils/add-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export async function addJest(
skipPackageJson: options.skipPackageJson,
skipFormat: true,
addPlugin: options.addPlugin,
addExplicitTargets: !options.addPlugin,
});

const setupFile = joinPathFragments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function componentConfigurationGeneratorInternal(
tasks.push(updateDeps(tree, opts));

addProjectFiles(tree, projectConfig, opts);
if (!hasPlugin) {
if (!hasPlugin || opts.addExplicitTargets) {
addTargetToProject(tree, projectConfig, opts);
}
updateNxJsonConfiguration(tree, hasPlugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ export interface CypressComponentConfigurationSchema {
bundler?: 'webpack' | 'vite';
jsx?: boolean;
addPlugin?: boolean;

/**
* @internal
*/
addExplicitTargets?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export async function configurationGeneratorInternal(
const linterTask = await addLinterToCyProject(tree, {
...opts,
cypressDir: opts.directory,
addPlugin: opts.addPlugin,
});
tasks.push(linterTask);

Expand Down
2 changes: 2 additions & 0 deletions packages/cypress/src/utils/add-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface CyLinterOptions {
* This is useful when adding linting to a brand new project vs an existing one
**/
overwriteExisting?: boolean;
addPlugin?: boolean;
}

export async function addLinterToCyProject(
Expand All @@ -63,6 +64,7 @@ export async function addLinterToCyProject(
setParserOptionsProject: options.setParserOptionsProject,
skipPackageJson: options.skipPackageJson,
rootProject: options.rootProject,
addPlugin: options.addPlugin,
})
);
}
Expand Down
7 changes: 6 additions & 1 deletion packages/eslint/src/generators/lint-project/lint-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ interface LintProjectOptions {
rootProject?: boolean;
keepExistingVersions?: boolean;
addPlugin?: boolean;

/**
* @internal
*/
addExplicitTargets?: boolean;
}

export function lintProjectGenerator(tree: Tree, options: LintProjectOptions) {
Expand Down Expand Up @@ -91,7 +96,7 @@ export async function lintProjectGeneratorInternal(
}

const hasPlugin = hasEslintPlugin(tree);
if (hasPlugin) {
if (hasPlugin && !options.addExplicitTargets) {
if (
lintFilePatterns &&
lintFilePatterns.length &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export async function configurationGeneratorInternal(
);
}
});
if (!hasPlugin) {
if (!hasPlugin || options.addExplicitTargets) {
updateWorkspace(tree, options);
}

Expand Down
5 changes: 5 additions & 0 deletions packages/jest/src/generators/configuration/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export interface JestProjectSchema {
compiler?: 'tsc' | 'babel' | 'swc';
skipPackageJson?: boolean;
js?: boolean;

/**
* @internal
*/
addExplicitTargets?: boolean;
}

export type NormalizedJestProjectSchema = JestProjectSchema & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export async function configurationGeneratorInternal(

let devDeps = {};

if (!hasPlugin) {
if (!hasPlugin || schema.addExplicitTargets) {
if (schema.uiFramework === '@storybook/angular') {
addAngularStorybookTarget(tree, schema.project, schema.interactionTests);
} else {
Expand Down
5 changes: 5 additions & 0 deletions packages/storybook/src/generators/configuration/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ export interface StorybookConfigureSchema {
*/
cypressDirectory?: string;
addPlugin?: boolean;

/**
* @internal
*/
addExplicitTargets?: boolean;
}
2 changes: 0 additions & 2 deletions packages/workspace/src/generators/preset/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ async function createPreset(tree: Tree, options: Schema) {
e2eTestRunner: options.e2eTestRunner ?? 'cypress',
bundler: options.bundler,
ssr: options.ssr,
addPlugin,
});
} else if (options.preset === Preset.AngularStandalone) {
const {
Expand All @@ -53,7 +52,6 @@ async function createPreset(tree: Tree, options: Schema) {
e2eTestRunner: options.e2eTestRunner ?? 'cypress',
bundler: options.bundler,
ssr: options.ssr,
addPlugin,
});
} else if (options.preset === Preset.ReactMonorepo) {
const { applicationGenerator: reactApplicationGenerator } = require('@nx' +
Expand Down

0 comments on commit 219ba8b

Please sign in to comment.