Skip to content

Commit 06f84b3

Browse files
authored
feat(react): migrate @nrwl/web schematics to devkit (nrwl#4666)
1 parent a500088 commit 06f84b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+626
-569
lines changed

.prettierignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ packages/workspace/src/generators/**/files/**/*.json
77
packages/workspace/src/core/dep-graph/vendor.js
88
packages/angular/src/schematics/**/files/**/*.json
99
packages/angular/src/migrations/**/files/**/*.json
10-
packages/web/src/schematics/**/files/**/*.json
10+
packages/web/src/generators/**/files/**/*.json
1111
packages/node/src/schematics/**/files/**/*.json
1212
packages/express/src/schematics/**/files/**/*.json
1313
packages/nest/src/schematics/**/files/**/*.json
1414
packages/react/src/schematics/**/files/**/*.json
1515
packages/jest/src/schematics/**/files/**/*.json
1616
packages/**/schematics/**/files/**/*.html
17+
packages/**/generators/**/files/**/*.html
1718
/.vscode
1819
/.idea
1920
/.github

packages/cypress/collection.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1",
44
"schematics": {
55
"init": {
6-
"factory": "./src/generators/init/init#initSchematic",
6+
"factory": "./src/generators/init/init#cypressInitSchematic",
77
"schema": "./src/generators/init/schema.json",
88
"description": "Initialize the @nrwl/cypress plugin",
99
"aliases": ["ng-add"],
@@ -18,7 +18,7 @@
1818
},
1919
"generators": {
2020
"init": {
21-
"factory": "./src/generators/init/init#initGenerator",
21+
"factory": "./src/generators/init/init#cypressInitGenerator",
2222
"schema": "./src/generators/init/schema.json",
2323
"description": "Initialize the @nrwl/cypress plugin",
2424
"aliases": ["ng-add"],

packages/cypress/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { cypressProjectGenerator } from './src/generators/cypress-project/cypress-project';
2+
export { cypressInitGenerator } from './src/generators/init/init';

packages/cypress/src/generators/cypress-project/cypress-project.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async function addLinter(host: Tree, options: CypressProjectSchema) {
7676
],
7777
});
7878

79-
if (options.linter !== Linter.EsLint) {
79+
if (!options.linter || options.linter !== Linter.EsLint) {
8080
return installTask;
8181
}
8282

@@ -127,6 +127,8 @@ function normalizeOptions(host: Tree, options: Schema): CypressProjectSchema {
127127
options.name
128128
)
129129
: joinPathFragments(appsDir, options.name);
130+
131+
options.linter = options.linter || Linter.EsLint;
130132
return {
131133
...options,
132134
projectName,

packages/cypress/src/generators/cypress-project/schema.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface Schema {
44
project?: string;
55
name: string;
66
directory?: string;
7-
linter: Linter;
7+
linter?: Linter;
88
js?: boolean;
99
skipFormat?: boolean;
1010
}

packages/cypress/src/generators/init/init.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { readJson, Tree, updateJson } from '@nrwl/devkit';
22
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
33

44
import { cypressVersion } from '../../utils/versions';
5-
import initGenerator from './init';
5+
import { cypressInitGenerator } from './init';
66

77
describe('init', () => {
88
let tree: Tree;
@@ -21,7 +21,7 @@ describe('init', () => {
2121
json.devDependencies[existing] = existingVersion;
2222
return json;
2323
});
24-
initGenerator(tree);
24+
cypressInitGenerator(tree);
2525
const packageJson = readJson(tree, 'package.json');
2626

2727
expect(packageJson.devDependencies.cypress).toBeDefined();

packages/cypress/src/generators/init/init.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ function updateDependencies(host: Tree) {
2424
);
2525
}
2626

27-
export function initGenerator(host: Tree) {
27+
export function cypressInitGenerator(host: Tree) {
2828
return updateDependencies(host);
2929
}
3030

31-
export default initGenerator;
32-
export const initSchematic = convertNxGenerator(initGenerator);
31+
export default cypressInitGenerator;
32+
export const cypressInitSchematic = convertNxGenerator(cypressInitGenerator);

packages/jest/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export {
44
} from './src/utils/config/update-config';
55
export { jestConfigObjectAst } from './src/utils/config/functions';
66
export { jestProjectGenerator } from './src/generators/jest-project/jest-project';
7+
export { jestInitGenerator } from './src/generators/init/init';

packages/jest/src/generators/jest-project/jest-project.ts

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ function normalizeOptions(options: JestProjectSchema) {
2323
options.testEnvironment = '';
2424
}
2525

26+
if (!options.hasOwnProperty('supportTsx')) {
27+
options.supportTsx = false;
28+
}
29+
2630
// if we support TSX or babelJest we don't support angular(html templates)
2731
if (options.supportTsx || options.babelJest) {
2832
options.skipSerializers = true;
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
export interface JestProjectSchema {
22
project: string;
3-
supportTsx: boolean;
3+
supportTsx?: boolean;
44
/**
55
* @deprecated
66
*/
7-
skipSetupFile: boolean;
8-
setupFile: 'angular' | 'web-components' | 'none';
9-
skipSerializers: boolean;
7+
skipSetupFile?: boolean;
8+
setupFile?: 'angular' | 'web-components' | 'none';
9+
skipSerializers?: boolean;
1010
testEnvironment?: 'node' | 'jsdom' | '';
11-
babelJest: boolean;
12-
skipFormat: boolean;
11+
babelJest?: boolean;
12+
skipFormat?: boolean;
1313
}

packages/linter/src/generators/init/init.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { Linter } from '../utils/linter';
1616

1717
export interface LinterInitOptions {
18-
linter: Linter;
18+
linter?: Linter;
1919
}
2020

2121
const globalTsLintConfiguration = {
@@ -197,9 +197,9 @@ function initEsLint(tree: Tree) {
197197
}
198198

199199
export function lintInitGenerator(tree: Tree, options: LinterInitOptions) {
200-
if (options.linter === Linter.TsLint) {
201-
return initTsLint(tree);
202-
} else if (options.linter === Linter.EsLint) {
200+
if (!options.linter || options.linter === Linter.EsLint) {
203201
return initEsLint(tree);
202+
} else if (options.linter === Linter.TsLint) {
203+
return initTsLint(tree);
204204
}
205205
}

packages/linter/src/generators/lint-project/lint-project.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { lintInitGenerator } from '../init/init';
1313

1414
interface LintProjectOptions {
1515
project: string;
16-
linter: Linter;
16+
linter?: Linter;
1717
eslintFilePatterns?: string[];
1818
tsConfigPaths?: string[];
1919
skipFormat: boolean;

packages/react/src/schematics/library/library.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ import {
4646
} from '../../utils/versions';
4747
import { Schema } from './schema';
4848
import { libsDir } from '@nrwl/workspace/src/utils/ast-utils';
49-
import { initRootBabelConfig } from '@nrwl/web/src/utils/rules';
5049
import { updateBabelJestConfig } from '../../rules/update-babel-jest-config';
5150
import { names, offsetFromRoot } from '@nrwl/devkit';
5251
import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter';
52+
import init from '../init/init';
5353

5454
export interface NormalizedSchema extends Schema {
5555
name: string;
@@ -76,6 +76,11 @@ export default function (schema: Schema): Rule {
7676
options.style = 'none';
7777
}
7878
return chain([
79+
init({
80+
...options,
81+
e2eTestRunner: 'none',
82+
skipFormat: true,
83+
}),
7984
addLintFiles(options.projectRoot, options.linter, {
8085
localConfig: reactEslintJson,
8186
extraPackageDeps: extraEslintDependencies,
@@ -125,7 +130,6 @@ export default function (schema: Schema): Rule {
125130
{}
126131
),
127132
updateAppRoutes(options, context),
128-
initRootBabelConfig(),
129133
formatFiles(options),
130134
])(host, context);
131135
};

packages/tao/src/shared/workspace.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export interface WorkspaceConfiguration {
4444
/**
4545
* Default generator collection. It is used when no collection is provided.
4646
*/
47-
cli?: { defaultCollection: string };
47+
cli?: {
48+
packageManager?: 'npm' | 'yarn' | 'pnpm';
49+
defaultCollection?: string;
50+
};
4851
}
4952

5053
/**

packages/web/collection.json

+19-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@
44
"extends": ["@nrwl/workspace"],
55
"schematics": {
66
"init": {
7-
"factory": "./src/schematics/init/init",
8-
"schema": "./src/schematics/init/schema.json",
7+
"factory": "./src/generators/init/init#webInitSchematic",
8+
"schema": "./src/generators/init/schema.json",
99
"description": "Add @nrwl/web to a project",
1010
"hidden": true
1111
},
1212

1313
"application": {
14-
"factory": "./src/schematics/application/application",
15-
"schema": "./src/schematics/application/schema.json",
14+
"factory": "./src/generators/application/application#applicationSchematic",
15+
"schema": "./src/generators/application/schema.json",
16+
"aliases": ["app"],
17+
"description": "Create an application"
18+
}
19+
},
20+
"generators": {
21+
"init": {
22+
"factory": "./src/generators/init/init#webInitGenerator",
23+
"schema": "./src/generators/init/schema.json",
24+
"description": "Add @nrwl/web to a project",
25+
"hidden": true
26+
},
27+
28+
"application": {
29+
"factory": "./src/generators/application/application#applicationGenerator",
30+
"schema": "./src/generators/application/schema.json",
1631
"aliases": ["app"],
1732
"description": "Create an application"
1833
}

packages/web/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { applicationGenerator } from './src/schematics/application/application';
1+
export { applicationGenerator } from './src/generators/application/application';

packages/web/src/builders/build/build.impl.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ import { ExtraEntryPoint } from '../../utils/third-party/browser/schema';
3333

3434
export interface WebBuildBuilderOptions extends BuildBuilderOptions {
3535
index: string;
36-
budgets: any[];
37-
baseHref: string;
38-
deployUrl: string;
36+
budgets?: any[];
37+
baseHref?: string;
38+
deployUrl?: string;
3939

4040
extractCss?: boolean;
4141
crossOrigin?: CrossOriginValue;
@@ -49,6 +49,8 @@ export interface WebBuildBuilderOptions extends BuildBuilderOptions {
4949
vendorChunk?: boolean;
5050
commonChunk?: boolean;
5151

52+
namedChunks?: boolean;
53+
5254
stylePreprocessingOptions?: any;
5355
subresourceIntegrity?: boolean;
5456

0 commit comments

Comments
 (0)