Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(angular): ensure all targets are generated for application and libraries #21826

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
"buildTarget": "my-dir-my-app:build",
},
},
"lint": {
"executor": "@nx/eslint:lint",
},
"serve": {
"configurations": {
"development": {
Expand All @@ -287,6 +290,15 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
"staticFilePath": "dist/apps/my-dir/my-app/browser",
},
},
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/my-dir/my-app/jest.config.ts",
},
"outputs": [
"{workspaceRoot}/coverage/{projectRoot}",
],
},
},
}
`;
Expand Down Expand Up @@ -319,6 +331,9 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
"testingType": "e2e",
},
},
"lint": {
"executor": "@nx/eslint:lint",
},
},
}
`;
Expand Down Expand Up @@ -472,6 +487,9 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
"buildTarget": "my-app:build",
},
},
"lint": {
"executor": "@nx/eslint:lint",
},
"serve": {
"configurations": {
"development": {
Expand All @@ -491,6 +509,15 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
"staticFilePath": "dist/apps/my-app/browser",
},
},
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/my-app/jest.config.ts",
},
"outputs": [
"{workspaceRoot}/coverage/{projectRoot}",
],
},
},
}
`;
Expand Down Expand Up @@ -523,6 +550,9 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
"testingType": "e2e",
},
},
"lint": {
"executor": "@nx/eslint:lint",
},
},
}
`;
Expand Down Expand Up @@ -971,6 +1001,9 @@ exports[`app nested should create project configs 1`] = `
"buildTarget": "my-app:build",
},
},
"lint": {
"executor": "@nx/eslint:lint",
},
"serve": {
"configurations": {
"development": {
Expand All @@ -990,6 +1023,15 @@ exports[`app nested should create project configs 1`] = `
"staticFilePath": "dist/my-dir/my-app/browser",
},
},
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "my-dir/my-app/jest.config.ts",
},
"outputs": [
"{workspaceRoot}/coverage/{projectRoot}",
],
},
},
}
`;
Expand Down Expand Up @@ -1022,6 +1064,9 @@ exports[`app nested should create project configs 2`] = `
"testingType": "e2e",
},
},
"lint": {
"executor": "@nx/eslint:lint",
},
},
}
`;
Expand Down Expand Up @@ -1088,6 +1133,9 @@ exports[`app not nested should create project configs 1`] = `
"buildTarget": "my-app:build",
},
},
"lint": {
"executor": "@nx/eslint:lint",
},
"serve": {
"configurations": {
"development": {
Expand All @@ -1107,6 +1155,15 @@ exports[`app not nested should create project configs 1`] = `
"staticFilePath": "dist/my-app/browser",
},
},
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "my-app/jest.config.ts",
},
"outputs": [
"{workspaceRoot}/coverage/{projectRoot}",
],
},
},
}
`;
Expand Down Expand Up @@ -1139,6 +1196,9 @@ exports[`app not nested should create project configs 2`] = `
"testingType": "e2e",
},
},
"lint": {
"executor": "@nx/eslint:lint",
},
},
}
`;
Expand Down
20 changes: 13 additions & 7 deletions packages/angular/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,18 @@ describe('app', () => {
describe('eslint', () => {
it('should add lint target', async () => {
await generateApp(appTree, 'my-app', { linter: Linter.EsLint });
expect(
readProjectConfiguration(appTree, 'my-app').targets.lint
).toMatchInlineSnapshot(`undefined`);
expect(
readProjectConfiguration(appTree, 'my-app-e2e').targets.lint
).toMatchInlineSnapshot(`undefined`);
expect(readProjectConfiguration(appTree, 'my-app').targets.lint)
.toMatchInlineSnapshot(`
{
"executor": "@nx/eslint:lint",
}
`);
expect(readProjectConfiguration(appTree, 'my-app-e2e').targets.lint)
.toMatchInlineSnapshot(`
{
"executor": "@nx/eslint:lint",
}
`);
});

it('should add valid eslint JSON configuration which extends from Nx presets', async () => {
Expand Down Expand Up @@ -1256,7 +1262,7 @@ async function generateApp(
unitTestRunner: UnitTestRunner.Jest,
linter: Linter.EsLint,
standalone: false,
addPlugin: true,
addPlugin: false,
...options,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function normalizeOptions(
});
options.rootProject = appProjectRoot === '.';
options.projectNameAndRootFormat = projectNameAndRootFormat;
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
options.addPlugin ??= process.env.NX_ADD_PLUGINS === 'true';

const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export async function normalizeOptions(
standaloneComponentName: `${
names(projectNames.projectSimpleName).className
}Component`,
addPlugin: options.addPlugin ?? process.env.NX_ADD_PLUGINS === 'true',
};

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface NormalizedSchema {
parsedTags: string[];
ngCliSchematicLibRoot: string;
standaloneComponentName: string;
addPlugin?: boolean;
};
componentOptions: {
name: string;
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ describe('lib', () => {
const json = readProjectConfiguration(tree, 'my-lib');
expect(json.root).toEqual('my-lib');
expect(json.targets.build).toBeDefined();
expect(json.targets.test).toBeDefined();
});

it('should not generate a module file and index.ts should be empty', async () => {
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ async function addUnitTestRunner(
projectRoot: options.projectRoot,
skipPackageJson: options.skipPackageJson,
strict: options.strict,
addPlugin: options.addPlugin,
});
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/generators/library/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ export interface Schema {
skipTests?: boolean;
selector?: string;
skipSelector?: boolean;
addPlugin?: boolean;
}