@nrwl/angular 13.10.0-beta.7 → 13.10.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/esm2020/mfe/index.mjs +2 -2
  2. package/fesm2015/nrwl-angular-mfe.mjs +1 -1
  3. package/fesm2015/nrwl-angular-testing.mjs.map +1 -1
  4. package/fesm2015/nrwl-angular.mjs.map +1 -1
  5. package/fesm2020/nrwl-angular-mfe.mjs +1 -1
  6. package/fesm2020/nrwl-angular-testing.mjs.map +1 -1
  7. package/fesm2020/nrwl-angular.mjs.map +1 -1
  8. package/mfe/index.d.ts +1 -1
  9. package/mfe/index.js +2 -1
  10. package/mfe/index.js.map +1 -1
  11. package/package.json +6 -6
  12. package/src/builders/webpack-browser/schema.json +0 -15
  13. package/src/generators/application/lib/add-mfe.js +1 -0
  14. package/src/generators/application/lib/add-mfe.js.map +1 -1
  15. package/src/generators/application/schema.d.ts +1 -0
  16. package/src/generators/application/schema.json +6 -0
  17. package/src/generators/mfe-host/mfe-host.js +1 -0
  18. package/src/generators/mfe-host/mfe-host.js.map +1 -1
  19. package/src/generators/mfe-host/schema.d.ts +1 -0
  20. package/src/generators/mfe-host/schema.json +5 -0
  21. package/src/generators/ng-add/compat.d.ts +1 -1
  22. package/src/generators/ng-add/files/{root → root-karma}/karma.conf.js__tmpl__ +0 -0
  23. package/src/generators/ng-add/migrate-from-angular-cli.d.ts +2 -2
  24. package/src/generators/ng-add/migrate-from-angular-cli.js +38 -607
  25. package/src/generators/ng-add/migrate-from-angular-cli.js.map +1 -1
  26. package/src/generators/ng-add/ng-add.d.ts +3 -3
  27. package/src/generators/ng-add/ng-add.js +2 -2
  28. package/src/generators/ng-add/ng-add.js.map +1 -1
  29. package/src/generators/ng-add/schema.d.ts +1 -1
  30. package/src/generators/ng-add/utilities/app.migrator.d.ts +18 -0
  31. package/src/generators/ng-add/utilities/app.migrator.js +182 -0
  32. package/src/generators/ng-add/utilities/app.migrator.js.map +1 -0
  33. package/src/generators/ng-add/utilities/e2e-project.migrator.d.ts +19 -0
  34. package/src/generators/ng-add/utilities/e2e-project.migrator.js +186 -0
  35. package/src/generators/ng-add/utilities/e2e-project.migrator.js.map +1 -0
  36. package/src/generators/ng-add/utilities/e2e-utils.d.ts +7 -0
  37. package/src/generators/ng-add/utilities/e2e-utils.js +46 -0
  38. package/src/generators/ng-add/utilities/e2e-utils.js.map +1 -0
  39. package/src/generators/ng-add/utilities/get-all-projects.d.ts +3 -0
  40. package/src/generators/ng-add/utilities/get-all-projects.js +26 -0
  41. package/src/generators/ng-add/utilities/get-all-projects.js.map +1 -0
  42. package/src/generators/ng-add/utilities/normalize-options.d.ts +3 -0
  43. package/src/generators/ng-add/utilities/normalize-options.js +24 -0
  44. package/src/generators/ng-add/utilities/normalize-options.js.map +1 -0
  45. package/src/generators/ng-add/utilities/project.migrator.d.ts +21 -0
  46. package/src/generators/ng-add/utilities/project.migrator.js +53 -0
  47. package/src/generators/ng-add/utilities/project.migrator.js.map +1 -0
  48. package/src/generators/ng-add/utilities/types.d.ts +10 -0
  49. package/src/generators/ng-add/utilities/types.js +3 -0
  50. package/src/generators/ng-add/utilities/types.js.map +1 -0
  51. package/src/generators/ng-add/utilities/workspace.d.ts +12 -0
  52. package/src/generators/ng-add/utilities/workspace.js +258 -0
  53. package/src/generators/ng-add/utilities/workspace.js.map +1 -0
  54. package/src/generators/setup-mfe/lib/add-remote-to-host.d.ts +2 -2
  55. package/src/generators/setup-mfe/lib/add-remote-to-host.js +49 -23
  56. package/src/generators/setup-mfe/lib/add-remote-to-host.js.map +1 -1
  57. package/src/generators/setup-mfe/lib/fix-bootstrap.d.ts +2 -1
  58. package/src/generators/setup-mfe/lib/fix-bootstrap.js +13 -4
  59. package/src/generators/setup-mfe/lib/fix-bootstrap.js.map +1 -1
  60. package/src/generators/setup-mfe/lib/index.d.ts +1 -0
  61. package/src/generators/setup-mfe/lib/index.js +1 -0
  62. package/src/generators/setup-mfe/lib/index.js.map +1 -1
  63. package/src/generators/setup-mfe/lib/setup-host-if-dynamic.d.ts +3 -0
  64. package/src/generators/setup-mfe/lib/setup-host-if-dynamic.js +15 -0
  65. package/src/generators/setup-mfe/lib/setup-host-if-dynamic.js.map +1 -0
  66. package/src/generators/setup-mfe/schema.d.ts +1 -0
  67. package/src/generators/setup-mfe/schema.json +6 -0
  68. package/src/generators/setup-mfe/setup-mfe.d.ts +1 -1
  69. package/src/generators/setup-mfe/setup-mfe.js +16 -13
  70. package/src/generators/setup-mfe/setup-mfe.js.map +1 -1
  71. package/src/utils/versions.js +1 -1
  72. package/src/generators/ng-add/files/decorate-angular-cli/decorate-angular-cli.js__tmpl__ +0 -69
  73. package/src/generators/ng-add/files/root/nx.json__tmpl__ +0 -29
@@ -3,620 +3,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.migrateFromAngularCli = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nrwl/devkit");
6
- const workspace_1 = require("@nrwl/workspace/src/generators/workspace/workspace");
7
- const default_base_1 = require("@nrwl/workspace/src/utilities/default-base");
8
- const prettier_1 = require("@nrwl/workspace/src/utilities/prettier");
9
- const typescript_1 = require("@nrwl/workspace/src/utilities/typescript");
10
- const versions_1 = require("@nrwl/workspace/src/utils/versions");
11
- const path_1 = require("path");
12
- const versions_2 = require("../../utils/versions");
13
- function updatePackageJson(tree) {
14
- (0, devkit_1.updateJson)(tree, 'package.json', (packageJson) => {
15
- var _a, _b;
16
- packageJson.scripts = packageJson.scripts || {};
17
- packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { nx: 'nx', 'affected:apps': 'nx affected:apps', 'affected:libs': 'nx affected:libs', 'affected:build': 'nx affected:build', 'affected:e2e': 'nx affected:e2e', 'affected:test': 'nx affected:test', 'affected:lint': 'nx affected:lint', 'affected:graph': 'nx affected:graph', affected: 'nx affected', format: 'nx format:write', 'format:write': 'nx format:write', 'format:check': 'nx format:check', update: 'ng update @nrwl/workspace', 'update:check': 'ng update', lint: 'nx workspace-lint && ng lint', graph: 'nx graph', 'workspace-generator': 'nx workspace-generator', help: 'nx help' });
18
- packageJson.devDependencies = (_a = packageJson.devDependencies) !== null && _a !== void 0 ? _a : {};
19
- packageJson.dependencies = (_b = packageJson.dependencies) !== null && _b !== void 0 ? _b : {};
20
- if (!packageJson.dependencies['@nrwl/angular']) {
21
- packageJson.dependencies['@nrwl/angular'] = versions_2.nxVersion;
22
- }
23
- if (!packageJson.devDependencies['@angular/cli']) {
24
- packageJson.devDependencies['@angular/cli'] = versions_2.angularDevkitVersion;
25
- }
26
- if (!packageJson.devDependencies['@nrwl/workspace']) {
27
- packageJson.devDependencies['@nrwl/workspace'] = versions_2.nxVersion;
28
- }
29
- if (!packageJson.devDependencies['nx']) {
30
- packageJson.devDependencies['nx'] = versions_2.nxVersion;
31
- }
32
- if (!packageJson.devDependencies['prettier']) {
33
- packageJson.devDependencies['prettier'] = versions_1.prettierVersion;
34
- }
35
- return packageJson;
36
- });
37
- }
38
- function convertPath(name, originalPath) {
39
- return `apps/${name}/${originalPath}`;
40
- }
41
- function updateAngularCLIJson(host, options) {
42
- var _a;
43
- const workspaceConfig = (0, devkit_1.readWorkspaceConfiguration)(host);
44
- const appName = workspaceConfig.defaultProject;
45
- const e2eName = `${appName}-e2e`;
46
- const e2eRoot = (0, devkit_1.joinPathFragments)('apps', e2eName);
47
- delete workspaceConfig.newProjectRoot;
48
- const defaultProject = (0, devkit_1.readProjectConfiguration)(host, appName);
49
- const oldSourceRoot = defaultProject.sourceRoot;
50
- const newRoot = (0, devkit_1.joinPathFragments)('apps', appName);
51
- defaultProject.root = newRoot;
52
- defaultProject.sourceRoot = (0, devkit_1.joinPathFragments)(newRoot, 'src');
53
- function convertBuildOptions(buildOptions) {
54
- buildOptions.outputPath =
55
- buildOptions.outputPath &&
56
- (0, devkit_1.joinPathFragments)((0, devkit_1.normalizePath)('dist'), 'apps', appName);
57
- buildOptions.index =
58
- buildOptions.index && convertAsset(buildOptions.index);
59
- buildOptions.main =
60
- buildOptions.main && convertAsset(buildOptions.main);
61
- buildOptions.polyfills =
62
- buildOptions.polyfills && convertAsset(buildOptions.polyfills);
63
- buildOptions.tsConfig =
64
- buildOptions.tsConfig && (0, devkit_1.joinPathFragments)(newRoot, 'tsconfig.app.json');
65
- buildOptions.assets =
66
- buildOptions.assets && buildOptions.assets.map(convertAsset);
67
- buildOptions.styles =
68
- buildOptions.styles && buildOptions.styles.map(convertAsset);
69
- buildOptions.scripts =
70
- buildOptions.scripts && buildOptions.scripts.map(convertAsset);
71
- buildOptions.fileReplacements =
72
- buildOptions.fileReplacements &&
73
- buildOptions.fileReplacements.map((replacement) => ({
74
- replace: convertAsset(replacement.replace),
75
- with: convertAsset(replacement.with),
76
- }));
77
- }
78
- convertBuildOptions(defaultProject.targets.build.options);
79
- Object.values(defaultProject.targets.build.configurations).forEach((config) => convertBuildOptions(config));
80
- if (defaultProject.targets.test) {
81
- const testOptions = defaultProject.targets.test.options;
82
- testOptions.main = testOptions.main && convertAsset(testOptions.main);
83
- testOptions.polyfills =
84
- testOptions.polyfills && convertAsset(testOptions.polyfills);
85
- testOptions.tsConfig = (0, devkit_1.joinPathFragments)(newRoot, 'tsconfig.spec.json');
86
- testOptions.karmaConfig = (0, devkit_1.joinPathFragments)(newRoot, 'karma.conf.js');
87
- testOptions.assets =
88
- testOptions.assets && testOptions.assets.map(convertAsset);
89
- testOptions.styles =
90
- testOptions.styles && testOptions.styles.map(convertAsset);
91
- testOptions.scripts =
92
- testOptions.scripts && testOptions.scripts.map(convertAsset);
93
- }
94
- const lintTarget = defaultProject.targets.lint;
95
- if (lintTarget) {
96
- lintTarget.options.tsConfig = [
97
- (0, devkit_1.joinPathFragments)(newRoot, 'tsconfig.app.json'),
98
- (0, devkit_1.joinPathFragments)(newRoot, 'tsconfig.spec.json'),
99
- ];
100
- }
101
- function convertServerOptions(serverOptions) {
102
- serverOptions.outputPath =
103
- serverOptions.outputPath &&
104
- (0, devkit_1.joinPathFragments)((0, devkit_1.normalizePath)('dist'), 'apps', `${options.name}-server`);
105
- serverOptions.main = serverOptions.main && convertAsset(serverOptions.main);
106
- serverOptions.tsConfig =
107
- serverOptions.tsConfig &&
108
- (0, devkit_1.joinPathFragments)((0, devkit_1.normalizePath)('apps'), appName, 'tsconfig.server.json');
109
- serverOptions.fileReplacements =
110
- serverOptions.fileReplacements &&
111
- serverOptions.fileReplacements.map((replacement) => ({
112
- replace: convertAsset(replacement.replace),
113
- with: convertAsset(replacement.with),
114
- }));
115
- }
116
- if (defaultProject.targets.server) {
117
- const serverOptions = defaultProject.targets.server.options;
118
- convertServerOptions(serverOptions);
119
- Object.values(defaultProject.targets.server.configurations).forEach((config) => convertServerOptions(config));
120
- }
121
- if (defaultProject.targets.e2e) {
122
- const lintTargetOptions = lintTarget ? lintTarget.options : {};
123
- if (isProtractorE2eProject(defaultProject)) {
124
- (0, devkit_1.addProjectConfiguration)(host, e2eName, {
125
- root: e2eRoot,
126
- projectType: 'application',
127
- targets: {
128
- e2e: Object.assign(Object.assign({}, defaultProject.targets.e2e), { options: Object.assign(Object.assign({}, defaultProject.targets.e2e.options), { protractorConfig: (0, devkit_1.joinPathFragments)(e2eRoot, 'protractor.conf.js') }) }),
129
- lint: {
130
- executor: '@angular-devkit/build-angular:tslint',
131
- options: Object.assign(Object.assign({}, lintTargetOptions), { tsConfig: (0, devkit_1.joinPathFragments)(e2eRoot, 'tsconfig.json') }),
132
- },
133
- },
134
- implicitDependencies: [appName],
135
- tags: [],
136
- });
137
- }
138
- else if (isCypressE2eProject(defaultProject)) {
139
- const cypressConfig = (0, devkit_1.joinPathFragments)(e2eRoot, (0, path_1.basename)((_a = getCypressConfigFile(defaultProject)) !== null && _a !== void 0 ? _a : 'cypress.json'));
140
- const e2eProjectConfig = {
141
- root: e2eRoot,
142
- sourceRoot: (0, devkit_1.joinPathFragments)(e2eRoot, 'src'),
143
- projectType: 'application',
144
- targets: {
145
- e2e: updateE2eCypressTarget(defaultProject.targets.e2e, cypressConfig),
146
- },
147
- implicitDependencies: [appName],
148
- tags: [],
149
- };
150
- if (defaultProject.targets['cypress-run']) {
151
- e2eProjectConfig.targets['cypress-run'] = updateE2eCypressTarget(defaultProject.targets['cypress-run'], cypressConfig);
152
- }
153
- if (defaultProject.targets['cypress-open']) {
154
- e2eProjectConfig.targets['cypress-open'] = updateE2eCypressTarget(defaultProject.targets['cypress-open'], cypressConfig);
155
- }
156
- (0, devkit_1.addProjectConfiguration)(host, e2eName, e2eProjectConfig);
157
- delete defaultProject.targets['cypress-run'];
158
- delete defaultProject.targets['cypress-open'];
159
- }
160
- delete defaultProject.targets.e2e;
161
- }
162
- (0, devkit_1.updateProjectConfiguration)(host, appName, defaultProject);
163
- workspaceConfig.cli = workspaceConfig.cli || {};
164
- if (!workspaceConfig.cli.defaultCollection) {
165
- workspaceConfig.cli.defaultCollection = '@nrwl/angular';
166
- }
167
- (0, devkit_1.updateWorkspaceConfiguration)(host, workspaceConfig);
168
- function convertAsset(asset) {
169
- if (typeof asset === 'string') {
170
- return asset.startsWith(oldSourceRoot)
171
- ? convertPath(appName, asset.replace(oldSourceRoot, 'src'))
172
- : asset;
173
- }
174
- else {
175
- return Object.assign(Object.assign({}, asset), { input: asset.input && asset.input.startsWith(oldSourceRoot)
176
- ? convertPath(appName, asset.input.replace(oldSourceRoot, 'src'))
177
- : asset.input });
178
- }
179
- }
180
- }
181
- function getCypressConfigFile(e2eProject) {
182
- let cypressConfig = 'cypress.json';
183
- const configFileOption = e2eProject.targets.e2e.options.configFile;
184
- if (configFileOption === false) {
185
- cypressConfig = undefined;
186
- }
187
- else if (typeof configFileOption === 'string') {
188
- cypressConfig = (0, path_1.basename)(configFileOption);
189
- }
190
- return cypressConfig;
191
- }
192
- function updateE2eCypressTarget(target, cypressConfig) {
193
- const updatedTarget = Object.assign(Object.assign({}, target), { executor: '@nrwl/cypress:cypress', options: Object.assign(Object.assign({}, target.options), { cypressConfig }) });
194
- delete updatedTarget.options.configFile;
195
- delete updatedTarget.options.tsConfig;
196
- if (updatedTarget.options.headless && updatedTarget.options.watch) {
197
- updatedTarget.options.headed = false;
198
- }
199
- else if (updatedTarget.options.headless === false &&
200
- !updatedTarget.options.watch) {
201
- updatedTarget.options.headed = true;
202
- }
203
- delete updatedTarget.options.headless;
204
- return updatedTarget;
205
- }
206
- function updateTsConfig(host) {
207
- (0, devkit_1.writeJson)(host, 'tsconfig.base.json', setUpCompilerOptions((0, devkit_1.readJson)(host, (0, typescript_1.getRootTsConfigPathInTree)(host))));
208
- if (host.exists('tsconfig.json')) {
209
- host.delete('tsconfig.json');
210
- }
211
- }
212
- function updateTsConfigsJson(host, options) {
213
- const app = (0, devkit_1.readProjectConfiguration)(host, options.name);
214
- const e2eProject = getE2eProject(host);
215
- const tsConfigPath = (0, typescript_1.getRootTsConfigPathInTree)(host);
216
- const appOffset = (0, devkit_1.offsetFromRoot)(app.root);
217
- (0, devkit_1.updateJson)(host, app.targets.build.options.tsConfig, (json) => {
218
- json.extends = `${appOffset}${tsConfigPath}`;
219
- json.compilerOptions = json.compilerOptions || {};
220
- json.compilerOptions.outDir = `${appOffset}dist/out-tsc`;
221
- return json;
222
- });
223
- if (app.targets.test) {
224
- (0, devkit_1.updateJson)(host, app.targets.test.options.tsConfig, (json) => {
225
- json.extends = `${appOffset}${tsConfigPath}`;
226
- json.compilerOptions = json.compilerOptions || {};
227
- json.compilerOptions.outDir = `${appOffset}dist/out-tsc`;
228
- return json;
229
- });
230
- }
231
- if (app.targets.server) {
232
- (0, devkit_1.updateJson)(host, app.targets.server.options.tsConfig, (json) => {
233
- json.extends = `${appOffset}${tsConfigPath}`;
234
- json.compilerOptions = json.compilerOptions || {};
235
- json.compilerOptions.outDir = `${appOffset}dist/out-tsc`;
236
- return json;
237
- });
238
- }
239
- if (!!e2eProject) {
240
- const tsConfig = isProtractorE2eProject(e2eProject)
241
- ? e2eProject.targets.lint.options.tsConfig
242
- : (0, devkit_1.joinPathFragments)(e2eProject.root, 'tsconfig.json');
243
- (0, devkit_1.updateJson)(host, tsConfig, (json) => {
244
- json.extends = `${(0, devkit_1.offsetFromRoot)(e2eProject.root)}${tsConfigPath}`;
245
- json.compilerOptions = Object.assign(Object.assign({}, json.compilerOptions), { outDir: `${(0, devkit_1.offsetFromRoot)(e2eProject.root)}dist/out-tsc` });
246
- return json;
247
- });
248
- }
249
- }
250
- function updateTsLint(host) {
251
- if (host.exists(`tslint.json`)) {
252
- (0, devkit_1.updateJson)(host, 'tslint.json', (tslintJson) => {
253
- [
254
- 'no-trailing-whitespace',
255
- 'one-line',
256
- 'quotemark',
257
- 'typedef-whitespace',
258
- 'whitespace',
259
- ].forEach((key) => {
260
- tslintJson[key] = undefined;
261
- });
262
- tslintJson.rulesDirectory = tslintJson.rulesDirectory || [];
263
- tslintJson.rulesDirectory.push('node_modules/@nrwl/workspace/src/tslint');
264
- tslintJson.rules['nx-enforce-module-boundaries'] = [
265
- true,
266
- {
267
- allow: [],
268
- depConstraints: [{ sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }],
269
- },
270
- ];
271
- return tslintJson;
272
- });
273
- }
274
- }
275
- function updateProjectTsLint(host, options) {
276
- const workspaceJson = (0, devkit_1.readJson)(host, (0, devkit_1.getWorkspacePath)(host));
277
- const app = workspaceJson.projects[options.name];
278
- const offset = '../../';
279
- if (host.exists(`${app.root}/tslint.json`)) {
280
- (0, devkit_1.updateJson)(host, `${app.root}/tslint.json`, (json) => {
281
- json.extends = `${offset}tslint.json`;
282
- return json;
283
- });
284
- }
285
- }
286
- function setUpCompilerOptions(tsconfig) {
287
- if (!tsconfig.compilerOptions.paths) {
288
- tsconfig.compilerOptions.paths = {};
289
- }
290
- tsconfig.compilerOptions.baseUrl = '.';
291
- tsconfig.compilerOptions.rootDir = '.';
292
- return tsconfig;
293
- }
294
- function moveOutOfSrc(tree, appName, filePath, required = true) {
295
- if (!filePath) {
296
- return;
297
- }
298
- const filename = !!filePath ? (0, path_1.basename)(filePath) : '';
299
- const from = filePath;
300
- const to = filename
301
- ? (0, devkit_1.joinPathFragments)('apps', appName, filename)
302
- : (0, devkit_1.joinPathFragments)('apps', appName);
303
- renameSyncInTree(tree, from, to, required);
304
- }
305
- function getE2eKey(host) {
306
- const projects = (0, devkit_1.getProjects)(host);
307
- for (const [projectName, project] of projects) {
308
- if (project.targets.e2e) {
309
- return projectName;
310
- }
311
- }
312
- }
313
- function getE2eProject(host) {
314
- const key = getE2eKey(host);
315
- if (key) {
316
- return (0, devkit_1.readProjectConfiguration)(host, key);
317
- }
318
- else {
319
- return null;
320
- }
321
- }
322
- function isCypressE2eProject(e2eProject) {
323
- return e2eProject.targets.e2e.executor === '@cypress/schematic:cypress';
324
- }
325
- function isProtractorE2eProject(e2eProject) {
326
- return (e2eProject.targets.e2e.executor ===
327
- '@angular-devkit/build-angular:protractor');
328
- }
329
- function moveExistingFiles(host, options) {
330
- const app = (0, devkit_1.readProjectConfiguration)(host, options.name);
331
- // it is not required to have a browserslist
332
- moveOutOfSrc(host, options.name, 'browserslist', false);
333
- moveOutOfSrc(host, options.name, '.browserslistrc', false);
334
- moveOutOfSrc(host, options.name, app.targets.build.options.tsConfig);
335
- if (app.targets.test) {
336
- moveOutOfSrc(host, options.name, app.targets.test.options.karmaConfig);
337
- moveOutOfSrc(host, options.name, app.targets.test.options.tsConfig);
338
- }
339
- else {
340
- // there could still be a karma.conf.js file in the root
341
- // so move to new location
342
- if (host.exists('karma.conf.js')) {
343
- console.info('No test configuration, but root Karma config file found');
344
- moveOutOfSrc(host, options.name, 'karma.conf.js');
345
- }
346
- }
347
- if (app.targets.server) {
348
- moveOutOfSrc(host, options.name, app.targets.server.options.tsConfig);
349
- }
350
- const oldAppSourceRoot = app.sourceRoot;
351
- const newAppSourceRoot = (0, devkit_1.joinPathFragments)('apps', options.name, 'src');
352
- renameDirSyncInTree(host, oldAppSourceRoot, newAppSourceRoot);
353
- moveE2eProjectFiles(host, app, options);
354
- }
355
- function moveE2eProjectFiles(tree, app, options) {
356
- const e2eProject = getE2eProject(tree);
357
- if (!e2eProject) {
358
- console.warn('No e2e project was migrated because there was none declared in angular.json.');
359
- return;
360
- }
361
- if (isProtractorE2eProject(e2eProject)) {
362
- const oldE2eRoot = (0, devkit_1.joinPathFragments)(app.root || '', 'e2e');
363
- const newE2eRoot = (0, devkit_1.joinPathFragments)('apps', `${getE2eKey(tree)}-e2e`);
364
- renameDirSyncInTree(tree, oldE2eRoot, newE2eRoot);
365
- }
366
- else if (isCypressE2eProject(e2eProject)) {
367
- const e2eProjectName = `${options.name}-e2e`;
368
- const configFile = getCypressConfigFile(e2eProject);
369
- const oldE2eRoot = 'cypress';
370
- const newE2eRoot = (0, devkit_1.joinPathFragments)('apps', e2eProjectName);
371
- if (configFile) {
372
- updateCypressConfigFilePaths(tree, configFile, oldE2eRoot, newE2eRoot);
373
- moveOutOfSrc(tree, e2eProjectName, configFile);
374
- }
375
- else {
376
- tree.write((0, devkit_1.joinPathFragments)('apps', e2eProjectName, 'cypress.json'), JSON.stringify({
377
- fileServerFolder: '.',
378
- fixturesFolder: './src/fixtures',
379
- integrationFolder: './src/integration',
380
- modifyObstructiveCode: false,
381
- supportFile: './src/support/index.ts',
382
- pluginsFile: './src/plugins/index.ts',
383
- video: true,
384
- videosFolder: `../../dist/cypress/${newE2eRoot}/videos`,
385
- screenshotsFolder: `../../dist/cypress/${newE2eRoot}/screenshots`,
386
- chromeWebSecurity: false,
387
- }));
388
- }
389
- moveOutOfSrc(tree, e2eProjectName, `${oldE2eRoot}/tsconfig.json`);
390
- renameDirSyncInTree(tree, oldE2eRoot, (0, devkit_1.joinPathFragments)('apps', e2eProjectName, 'src'));
391
- }
392
- }
393
- function updateCypressConfigFilePaths(tree, configFile, oldE2eRoot, newE2eRoot) {
394
- const srcFoldersAndFiles = [
395
- 'integrationFolder',
396
- 'supportFile',
397
- 'pluginsFile',
398
- 'fixturesFolder',
399
- ];
400
- const distFolders = ['videosFolder', 'screenshotsFolder'];
401
- const stringOrArrayGlobs = ['ignoreTestFiles', 'testFiles'];
402
- const cypressConfig = (0, devkit_1.readJson)(tree, configFile);
403
- cypressConfig.fileServerFolder = '.';
404
- srcFoldersAndFiles.forEach((folderOrFile) => {
405
- if (cypressConfig[folderOrFile]) {
406
- cypressConfig[folderOrFile] = `./src/${(0, path_1.relative)(oldE2eRoot, cypressConfig[folderOrFile])}`;
407
- }
408
- });
409
- distFolders.forEach((folder) => {
410
- if (cypressConfig[folder]) {
411
- cypressConfig[folder] = `../../dist/cypress/${newE2eRoot}/${(0, path_1.relative)(oldE2eRoot, cypressConfig[folder])}`;
412
- }
413
- });
414
- stringOrArrayGlobs.forEach((stringOrArrayGlob) => {
415
- if (!cypressConfig[stringOrArrayGlob]) {
416
- return;
417
- }
418
- if (Array.isArray(cypressConfig[stringOrArrayGlob])) {
419
- cypressConfig[stringOrArrayGlob] = cypressConfig[stringOrArrayGlob].map((glob) => replaceCypressGlobConfig(glob, oldE2eRoot));
420
- }
421
- else {
422
- cypressConfig[stringOrArrayGlob] = replaceCypressGlobConfig(cypressConfig[stringOrArrayGlob], oldE2eRoot);
423
- }
424
- });
425
- (0, devkit_1.writeJson)(tree, configFile, cypressConfig);
426
- }
427
- function replaceCypressGlobConfig(globPattern, oldE2eRoot) {
428
- return globPattern.replace(new RegExp(`^(\\.\\/|\\/)?${oldE2eRoot}\\/`), './src/');
429
- }
430
- function createAdditionalFiles(host) {
6
+ const versions_1 = require("../../utils/versions");
7
+ const app_migrator_1 = require("./utilities/app.migrator");
8
+ const get_all_projects_1 = require("./utilities/get-all-projects");
9
+ const normalize_options_1 = require("./utilities/normalize-options");
10
+ const workspace_1 = require("./utilities/workspace");
11
+ function migrateFromAngularCli(tree, rawOptions) {
431
12
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
432
- const recommendations = [
433
- 'nrwl.angular-console',
434
- 'angular.ng-template',
435
- 'dbaeumer.vscode-eslint',
436
- 'esbenp.prettier-vscode',
437
- ];
438
- if (host.exists('.vscode/extensions.json')) {
439
- (0, devkit_1.updateJson)(host, '.vscode/extensions.json', (json) => {
440
- json.recommendations = json.recommendations || [];
441
- recommendations.forEach((extension) => {
442
- if (!json.recommendations.includes(extension)) {
443
- json.recommendations.push(extension);
444
- }
445
- });
446
- return json;
447
- });
448
- }
449
- else {
450
- (0, devkit_1.writeJson)(host, '.vscode/extensions.json', {
451
- recommendations,
452
- });
453
- }
454
- // if the user does not already have a prettier configuration
455
- // of any kind, create one
456
- const existingPrettierConfig = yield (0, prettier_1.resolveUserExistingPrettierConfig)();
457
- if (!existingPrettierConfig) {
458
- (0, devkit_1.writeJson)(host, '.prettierrc', workspace_1.DEFAULT_NRWL_PRETTIER_CONFIG);
459
- }
460
- });
461
- }
462
- function checkCanConvertToWorkspace(host) {
463
- try {
464
- if (!host.exists('package.json')) {
465
- throw new Error('Cannot find package.json');
466
- }
467
- if (!host.exists('angular.json')) {
468
- throw new Error('Cannot find angular.json');
469
- }
470
- // TODO: This restriction should be lited
471
- const workspaceJson = (0, devkit_1.readJson)(host, 'angular.json');
472
- const hasLibraries = Object.keys(workspaceJson.projects).find((project) => workspaceJson.projects[project].projectType &&
473
- workspaceJson.projects[project].projectType !== 'application');
474
- if (Object.keys(workspaceJson.projects).length > 2 || hasLibraries) {
475
- throw new Error('Can only convert projects with one app');
476
- }
477
- const e2eKey = getE2eKey(host);
478
- const e2eApp = getE2eProject(host);
479
- if (!e2eApp) {
480
- return;
481
- }
482
- if (isProtractorE2eProject(e2eApp)) {
483
- if (host.exists(e2eApp.targets.e2e.options.protractorConfig)) {
484
- return;
485
- }
486
- console.info(`Make sure the "${e2eKey}.architect.e2e.options.protractorConfig" is valid or the "${e2eKey}" project is removed from "angular.json".`);
487
- throw new Error(`An e2e project with Protractor was found but "${e2eApp.targets.e2e.options.protractorConfig}" could not be found.`);
488
- }
489
- if (isCypressE2eProject(e2eApp)) {
490
- const configFile = getCypressConfigFile(e2eApp);
491
- if (configFile && !host.exists(configFile)) {
492
- throw new Error(`An e2e project with Cypress was found but "${configFile}" could not be found.`);
493
- }
494
- if (!host.exists('cypress')) {
495
- throw new Error(`An e2e project with Cypress was found but the "cypress" directory could not be found.`);
496
- }
497
- return;
498
- }
499
- throw new Error(`An e2e project was found but it's using an unsupported executor "${e2eApp.targets.e2e.executor}".`);
500
- }
501
- catch (e) {
502
- console.error(e.message);
503
- console.error('Your workspace could not be converted into an Nx Workspace because of the above error.');
504
- throw e;
505
- }
506
- }
507
- function createNxJson(host) {
508
- const { projects = {}, newProjectRoot = '' } = (0, devkit_1.readJson)(host, 'angular.json');
509
- const hasLibraries = Object.keys(projects).find((project) => projects[project].projectType &&
510
- projects[project].projectType !== 'application');
511
- if (Object.keys(projects).length !== 1 || hasLibraries) {
512
- throw new Error(`The schematic can only be used with Angular CLI workspaces with a single application.`);
513
- }
514
- const name = Object.keys(projects)[0];
515
- (0, devkit_1.writeJson)(host, 'nx.json', {
516
- npmScope: name,
517
- implicitDependencies: {
518
- 'package.json': {
519
- dependencies: '*',
520
- devDependencies: '*',
521
- },
522
- '.eslintrc.json': '*',
523
- },
524
- tasksRunnerOptions: {
525
- default: {
526
- runner: 'nx/tasks-runners/default',
527
- options: {
528
- cacheableOperations: ['build', 'lint', 'test', 'e2e'],
529
- },
530
- },
531
- },
532
- workspaceLayout: { appsDir: newProjectRoot, libsDir: newProjectRoot },
533
- });
534
- }
535
- function decorateAngularCli(host) {
536
- (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'decorate-angular-cli'), '.', { tmpl: '' });
537
- (0, devkit_1.updateJson)(host, 'package.json', (json) => {
538
- if (json.scripts &&
539
- json.scripts.postinstall &&
540
- !json.scripts.postinstall.includes('decorate-angular-cli.js')) {
541
- // if exists, add execution of this script
542
- json.scripts.postinstall += ' && node ./decorate-angular-cli.js';
543
- }
544
- else {
545
- if (!json.scripts)
546
- json.scripts = {};
547
- // if doesn't exist, set to execute this script
548
- json.scripts.postinstall = 'node ./decorate-angular-cli.js';
549
- }
550
- if (json.scripts.ng) {
551
- json.scripts.ng = 'nx';
552
- }
553
- return json;
554
- });
555
- }
556
- function addFiles(host, options) {
557
- var _a;
558
- (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/root'), '.', {
559
- tmpl: '',
560
- dot: '.',
561
- rootTsConfigPath: (0, typescript_1.getRootTsConfigPathInTree)(host),
562
- npmScope: options.npmScope,
563
- defaultBase: (_a = options.defaultBase) !== null && _a !== void 0 ? _a : (0, default_base_1.deduceDefaultBase)(),
564
- });
565
- if (!host.exists('.prettierignore')) {
566
- (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/prettier'), '.', {
567
- tmpl: '',
568
- dot: '.',
569
- });
570
- }
571
- }
572
- function renameSyncInTree(tree, from, to, required) {
573
- if (!tree.exists(from)) {
574
- if (required) {
575
- console.warn(`Path: ${from} does not exist`);
576
- }
577
- }
578
- else if (tree.exists(to)) {
579
- if (required) {
580
- console.warn(`Path: ${to} already exists`);
581
- }
582
- }
583
- else {
584
- const contents = tree.read(from);
585
- tree.write(to, contents);
586
- tree.delete(from);
587
- }
588
- }
589
- function renameDirSyncInTree(tree, from, to) {
590
- (0, devkit_1.visitNotIgnoredFiles)(tree, from, (file) => {
591
- renameSyncInTree(tree, file, file.replace(from, to), true);
592
- });
593
- }
594
- function migrateFromAngularCli(tree, schema) {
595
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
596
- if (schema.preserveAngularCliLayout) {
13
+ const projects = (0, get_all_projects_1.getAllProjects)(tree);
14
+ const options = (0, normalize_options_1.normalizeOptions)(rawOptions, projects);
15
+ if (options.preserveAngularCliLayout) {
597
16
  (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
598
- nx: versions_2.nxVersion,
599
- '@nrwl/workspace': versions_2.nxVersion,
17
+ nx: versions_1.nxVersion,
18
+ '@nrwl/workspace': versions_1.nxVersion,
600
19
  });
601
- createNxJson(tree);
602
- decorateAngularCli(tree);
20
+ (0, workspace_1.createNxJson)(tree, options, true);
21
+ (0, workspace_1.decorateAngularCli)(tree);
603
22
  }
604
23
  else {
605
- const options = Object.assign(Object.assign({}, schema), { npmScope: (0, devkit_1.names)(schema.npmScope || schema.name).fileName });
606
- checkCanConvertToWorkspace(tree);
607
- moveExistingFiles(tree, options);
608
- addFiles(tree, options);
609
- yield createAdditionalFiles(tree);
610
- updatePackageJson(tree);
611
- updateAngularCLIJson(tree, options);
612
- updateTsLint(tree);
613
- updateProjectTsLint(tree, options);
614
- updateTsConfig(tree);
615
- updateTsConfigsJson(tree, options);
616
- decorateAngularCli(tree);
24
+ (0, workspace_1.validateWorkspace)(tree, projects);
25
+ const migrators = [
26
+ ...projects.apps.map((app) => new app_migrator_1.AppMigrator(tree, options, app)),
27
+ // TODO: add libraries migrator when support for libs is added
28
+ ];
29
+ // TODO: validate all projects and collect errors before migrating when
30
+ // multiple projects are supported
31
+ // create and update root files and configurations
32
+ (0, workspace_1.createNxJson)(tree, options);
33
+ (0, workspace_1.updateWorkspaceConfigDefaults)(tree);
34
+ (0, workspace_1.updateRootTsConfig)(tree);
35
+ (0, workspace_1.updatePackageJson)(tree);
36
+ (0, workspace_1.decorateAngularCli)(tree);
37
+ // TODO: check later if it's still needed
38
+ (0, workspace_1.updateTsLint)(tree);
39
+ yield (0, workspace_1.createWorkspaceFiles)(tree);
40
+ // migrate all projects
41
+ for (const migrator of migrators) {
42
+ yield migrator.migrate();
43
+ }
44
+ // needs to be done last because the Angular CLI workspace can have one
45
+ // in the root for the root application, so we wait until that root Karma
46
+ // config is moved when the projects are migrated before creating this one
47
+ (0, workspace_1.createRootKarmaConfig)(tree);
617
48
  yield (0, devkit_1.formatFiles)(tree);
618
49
  }
619
- if (!schema.skipInstall) {
50
+ if (!options.skipInstall) {
620
51
  return () => {
621
52
  (0, devkit_1.installPackagesTask)(tree);
622
53
  };