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(misc): add support for angular cli workspaces to nx init #13404

Merged
merged 1 commit into from
Nov 29, 2022
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
89 changes: 37 additions & 52 deletions e2e/angular-core/src/ng-add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
updateFile(
'e2e/src/app.e2e-spec.ts',
`describe('app', () => {
it('should pass', {
it('should pass', () => {
expect(true).toBe(true);
});
});`
Expand Down Expand Up @@ -148,39 +148,42 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
cli: {
packageManager: packageManager,
},
defaultProject: project,
implicitDependencies: {
'.eslintrc.json': '*',
'package.json': {
dependencies: '*',
devDependencies: '*',
},
},
npmScope: 'projscope',
targetDefaults: {
build: {
dependsOn: ['^build'],
},
},
tasksRunnerOptions: {
default: {
options: {
cacheableOperations: ['build', 'lint', 'test', 'e2e'],
cacheableOperations: ['build', 'test', 'e2e'],
},
runner: 'nx/tasks-runners/default',
},
},
});

// check angular.json
expect(readJson('angular.json')).toStrictEqual({
version: 2,
projects: {
[project]: `apps/${project}`,
[`${project}-e2e`]: `apps/${project}-e2e`,
namedInputs: {
default: ['{projectRoot}/**/*', 'sharedGlobals'],
production: [
'default',
'!{projectRoot}/tsconfig.spec.json',
'!{projectRoot}/**/*.spec.[jt]s',
'!{projectRoot}/karma.conf.js',
],
sharedGlobals: [],
},
targetDefaults: {
build: {
dependsOn: ['^build'],
inputs: ['production', '^production'],
},
e2e: {
inputs: ['default', '^production'],
},
test: {
inputs: ['default', '^production', '{workspaceRoot}/karma.conf.js'],
},
},
});

// check angular.json does not exist
checkFilesDoNotExist('angular.json');

// check project configuration
const projectConfig = readJson(`apps/${project}/project.json`);
expect(projectConfig.sourceRoot).toEqual(`apps/${project}/src`);
Expand Down Expand Up @@ -513,15 +516,8 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {

runNgAdd('@nrwl/angular', '--npm-scope projscope');

// check angular.json
expect(readJson('angular.json')).toStrictEqual({
version: 2,
projects: {
[project]: `apps/${project}`,
[lib1]: `libs/${lib1}`,
[lib2]: `libs/${lib2}`,
},
});
// check angular.json does not exist
checkFilesDoNotExist('angular.json');

// check building lib1
let output = runCLI(`build ${lib1}`);
Expand Down Expand Up @@ -563,14 +559,8 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {

runNgAdd('@nrwl/angular', '--npm-scope projscope');

// check angular.json
expect(readJson('angular.json')).toStrictEqual({
version: 2,
projects: {
[project]: `apps/${project}`,
[app1]: `apps/${app1}`,
},
});
// check angular.json does not exist
checkFilesDoNotExist('angular.json');

// check building project
let output = runCLI(`build ${project} --outputHashing none`);
Expand Down Expand Up @@ -616,18 +606,13 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {

runNgAdd('@nrwl/angular', '--preserve-angular-cli-layout');

// check config still uses Angular CLI layout
const updatedAngularJson = readJson('angular.json');
expect(updatedAngularJson.projects[project].root).toEqual('');
expect(updatedAngularJson.projects[project].sourceRoot).toEqual('src');
expect(updatedAngularJson.projects.app2.root).toEqual('projects/app2');
expect(updatedAngularJson.projects.app2.sourceRoot).toEqual(
'projects/app2/src'
);
expect(updatedAngularJson.projects.lib1.root).toEqual('projects/lib1');
expect(updatedAngularJson.projects.lib1.sourceRoot).toEqual(
'projects/lib1/src'
);
// check project configs
const projectJson = readJson('project.json');
expect(projectJson.sourceRoot).toEqual('src');
const app2ProjectJson = readJson('projects/app2/project.json');
expect(app2ProjectJson.sourceRoot).toEqual('projects/app2/src');
const lib1ProjectJson = readJson('projects/lib1/project.json');
expect(lib1ProjectJson.sourceRoot).toEqual('projects/lib1/src');

// check building an app
let output = runCLI(`build ${project} --outputHashing none`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@ Object {
"affected": Object {
"defaultBase": "main",
},
"implicitDependencies": Object {
".eslintrc.json": "*",
"package.json": Object {
"dependencies": "*",
"devDependencies": "*",
},
"namedInputs": Object {
"default": Array [
"{projectRoot}/**/*",
"sharedGlobals",
],
"production": Array [
"default",
],
"sharedGlobals": Array [],
},
"targetDefaults": Object {
"build": Object {
"dependsOn": Array [
"^build",
],
"inputs": Array [
"production",
"^production",
],
},
},
"tasksRunnerOptions": Object {
"default": Object {
"options": Object {
"cacheableOperations": Array [
"build",
"lint",
"test",
"e2e",
],
},
"runner": "nx/tasks-runners/default",
Expand All @@ -44,27 +48,48 @@ Object {
"affected": Object {
"defaultBase": "main",
},
"defaultProject": "app1",
"implicitDependencies": Object {
".eslintrc.json": "*",
"package.json": Object {
"dependencies": "*",
"devDependencies": "*",
},
"namedInputs": Object {
"default": Array [
"{projectRoot}/**/*",
"sharedGlobals",
],
"production": Array [
"default",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/**/*.spec.[jt]s",
"!{projectRoot}/karma.conf.js",
],
"sharedGlobals": Array [],
},
"targetDefaults": Object {
"build": Object {
"dependsOn": Array [
"^build",
],
"inputs": Array [
"production",
"^production",
],
},
"e2e": Object {
"inputs": Array [
"default",
"^production",
],
},
"test": Object {
"inputs": Array [
"default",
"^production",
"{workspaceRoot}/karma.conf.js",
],
},
},
"tasksRunnerOptions": Object {
"default": Object {
"options": Object {
"cacheableOperations": Array [
"build",
"lint",
"test",
"e2e",
],
Expand All @@ -79,6 +104,81 @@ Object {
}
`;

exports[`workspace --preserve-angular-cli-layout should support multiple projects 2`] = `
Object {
"name": "app1",
"sourceRoot": "src",
"targets": Object {
"build": Object {
"executor": "@angular-devkit/build-angular:browser",
"options": Object {
"tsConfig": "tsconfig.app.json",
},
},
"e2e": Object {
"executor": "@angular-devkit/build-angular:protractor",
"options": Object {
"protractorConfig": "e2e/protractor.conf.js",
},
},
"test": Object {
"executor": "@angular-devkit/build-angular:karma",
"options": Object {
"tsConfig": "tsconfig.spec.json",
},
},
},
}
`;

exports[`workspace --preserve-angular-cli-layout should support multiple projects 3`] = `
Object {
"name": "app2",
"sourceRoot": "projects/app2/src",
"targets": Object {
"build": Object {
"executor": "@angular-devkit/build-angular:browser",
"options": Object {
"tsConfig": "projects/app2/tsconfig.app.json",
},
},
"e2e": Object {
"executor": "@angular-devkit/build-angular:protractor",
"options": Object {
"protractorConfig": "projects/app2/e2e/protractor.conf.js",
},
},
"test": Object {
"executor": "@angular-devkit/build-angular:karma",
"options": Object {
"tsConfig": "projects/app2/tsconfig.spec.json",
},
},
},
}
`;

exports[`workspace --preserve-angular-cli-layout should support multiple projects 4`] = `
Object {
"name": "lib1",
"sourceRoot": "projects/lib1/src",
"targets": Object {
"build": Object {
"executor": "@angular-devkit/build-angular:ng-packagr",
"options": Object {
"tsConfig": "projects/lib1/tsconfig.lib.json",
},
},
"test": Object {
"executor": "@angular-devkit/build-angular:karma",
"options": Object {
"tsConfig": "projects/lib1/tsconfig.spec.json",
},
},
},
}
`;

exports[`workspace move to nx layout should create a root eslint config 1`] = `
Object {
"ignorePatterns": Array [
Expand Down Expand Up @@ -163,34 +263,58 @@ Object {
"defaultBase": "main",
},
"defaultProject": "myApp",
"implicitDependencies": Object {
".eslintrc.json": "*",
"package.json": Object {
"dependencies": "*",
"devDependencies": "*",
},
"namedInputs": Object {
"default": Array [
"{projectRoot}/**/*",
"sharedGlobals",
],
"production": Array [
"default",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/**/*.spec.[jt]s",
"!{projectRoot}/karma.conf.js",
"!{projectRoot}/.eslintrc.json",
],
"sharedGlobals": Array [],
},
"npmScope": "my-org",
"targetDefaults": Object {
"build": Object {
"dependsOn": Array [
"^build",
],
"inputs": Array [
"production",
"^production",
],
},
"e2e": Object {
"inputs": Array [
"default",
"^production",
],
},
"lint": Object {
"inputs": Array [
"default",
"{workspaceRoot}/.eslintrc.json",
],
},
"test": Object {
"inputs": Array [
"default",
"^production",
"{workspaceRoot}/karma.conf.js",
],
},
},
"tasksRunnerOptions": Object {
"default": Object {
"options": Object {
"cacheableOperations": Array [
"build",
"lint",
"test",
"lint",
"e2e",
],
},
Expand Down
Loading