@nx/web 16.8.0-beta.4 → 16.8.0-beta.6

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.
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applicationSchematic = exports.applicationGeneratorInternal = exports.applicationGenerator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
7
6
  const js_1 = require("@nx/js");
@@ -10,255 +9,275 @@ const path_1 = require("path");
10
9
  const versions_2 = require("../../utils/versions");
11
10
  const init_1 = require("../init/init");
12
11
  function createApplicationFiles(tree, options) {
13
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, options.bundler === 'vite' ? './files/app-vite' : './files/app-webpack'), options.appProjectRoot, Object.assign(Object.assign(Object.assign({}, options), (0, devkit_1.names)(options.name)), { tmpl: '', offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot), rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot) }));
12
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, options.bundler === 'vite' ? './files/app-vite' : './files/app-webpack'), options.appProjectRoot, {
13
+ ...options,
14
+ ...(0, devkit_1.names)(options.name),
15
+ tmpl: '',
16
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
17
+ rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
18
+ });
14
19
  if (options.unitTestRunner === 'none') {
15
20
  tree.delete((0, path_1.join)(options.appProjectRoot, './src/app/app.element.spec.ts'));
16
21
  }
17
22
  }
18
- function setupBundler(tree, options) {
19
- var _a;
20
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
- const main = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/main.ts');
22
- const tsConfig = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json');
23
- const assets = [
24
- (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/favicon.ico'),
25
- (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/assets'),
23
+ async function setupBundler(tree, options) {
24
+ const main = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/main.ts');
25
+ const tsConfig = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json');
26
+ const assets = [
27
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/favicon.ico'),
28
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/assets'),
29
+ ];
30
+ if (options.bundler === 'webpack') {
31
+ const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_2.nxVersion);
32
+ await configurationGenerator(tree, {
33
+ project: options.projectName,
34
+ main,
35
+ tsConfig,
36
+ compiler: options.compiler ?? 'babel',
37
+ devServer: true,
38
+ webpackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'),
39
+ skipFormat: true,
40
+ });
41
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
42
+ const prodConfig = project.targets.build.configurations.production;
43
+ const buildOptions = project.targets.build.options;
44
+ buildOptions.assets = assets;
45
+ buildOptions.index = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html');
46
+ buildOptions.baseHref = '/';
47
+ buildOptions.styles = [
48
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/styles.${options.style}`),
26
49
  ];
27
- if (options.bundler === 'webpack') {
28
- const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_2.nxVersion);
29
- yield configurationGenerator(tree, {
30
- project: options.projectName,
50
+ // We can delete that, because this projest is an application
51
+ // and applications have a .babelrc file in their root dir.
52
+ // So Nx will find it and use it
53
+ delete buildOptions.babelUpwardRootMode;
54
+ buildOptions.scripts = [];
55
+ prodConfig.fileReplacements = [
56
+ {
57
+ replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/environments/environment.ts`),
58
+ with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/environments/environment.prod.ts`),
59
+ },
60
+ ];
61
+ prodConfig.optimization = true;
62
+ prodConfig.outputHashing = 'all';
63
+ prodConfig.sourceMap = false;
64
+ prodConfig.namedChunks = false;
65
+ prodConfig.extractLicenses = true;
66
+ prodConfig.vendorChunk = false;
67
+ (0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
68
+ }
69
+ else if (options.bundler === 'none') {
70
+ // TODO(jack): Flush this out... no bundler should be possible for web but the experience isn't holistic due to missing features (e.g. writing index.html).
71
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
72
+ project.targets.build = {
73
+ executor: `@nx/js:${options.compiler}`,
74
+ outputs: ['{options.outputPath}'],
75
+ options: {
31
76
  main,
77
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot),
32
78
  tsConfig,
33
- compiler: (_a = options.compiler) !== null && _a !== void 0 ? _a : 'babel',
34
- devServer: true,
35
- webpackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'),
36
- skipFormat: true,
37
- });
38
- const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
39
- const prodConfig = project.targets.build.configurations.production;
40
- const buildOptions = project.targets.build.options;
41
- buildOptions.assets = assets;
42
- buildOptions.index = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html');
43
- buildOptions.baseHref = '/';
44
- buildOptions.styles = [
45
- (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/styles.${options.style}`),
46
- ];
47
- // We can delete that, because this projest is an application
48
- // and applications have a .babelrc file in their root dir.
49
- // So Nx will find it and use it
50
- delete buildOptions.babelUpwardRootMode;
51
- buildOptions.scripts = [];
52
- prodConfig.fileReplacements = [
53
- {
54
- replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/environments/environment.ts`),
55
- with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/environments/environment.prod.ts`),
56
- },
57
- ];
58
- prodConfig.optimization = true;
59
- prodConfig.outputHashing = 'all';
60
- prodConfig.sourceMap = false;
61
- prodConfig.namedChunks = false;
62
- prodConfig.extractLicenses = true;
63
- prodConfig.vendorChunk = false;
64
- (0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
65
- }
66
- else if (options.bundler === 'none') {
67
- // TODO(jack): Flush this out... no bundler should be possible for web but the experience isn't holistic due to missing features (e.g. writing index.html).
68
- const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
69
- project.targets.build = {
70
- executor: `@nx/js:${options.compiler}`,
71
- outputs: ['{options.outputPath}'],
72
- options: {
73
- main,
74
- outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot),
75
- tsConfig,
76
- assets,
77
- },
78
- };
79
- (0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
80
- }
81
- else {
82
- throw new Error('Unsupported bundler type');
83
- }
84
- });
79
+ assets,
80
+ },
81
+ };
82
+ (0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
83
+ }
84
+ else {
85
+ throw new Error('Unsupported bundler type');
86
+ }
85
87
  }
86
- function addProject(tree, options) {
87
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
88
- const targets = {};
89
- (0, devkit_1.addProjectConfiguration)(tree, options.projectName, {
90
- projectType: 'application',
91
- root: options.appProjectRoot,
92
- sourceRoot: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src'),
93
- tags: options.parsedTags,
94
- targets,
95
- }, options.standaloneConfig);
96
- if (options.bundler !== 'vite') {
97
- yield setupBundler(tree, options);
98
- }
99
- });
88
+ async function addProject(tree, options) {
89
+ const targets = {};
90
+ (0, devkit_1.addProjectConfiguration)(tree, options.projectName, {
91
+ projectType: 'application',
92
+ root: options.appProjectRoot,
93
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src'),
94
+ tags: options.parsedTags,
95
+ targets,
96
+ }, options.standaloneConfig);
97
+ if (options.bundler !== 'vite') {
98
+ await setupBundler(tree, options);
99
+ }
100
100
  }
101
101
  function setDefaults(tree, options) {
102
102
  const nxJson = (0, devkit_1.readNxJson)(tree);
103
103
  nxJson.generators = nxJson.generators || {};
104
- nxJson.generators['@nx/web:application'] = Object.assign({ style: options.style, linter: options.linter, unitTestRunner: options.unitTestRunner, e2eTestRunner: options.e2eTestRunner }, nxJson.generators['@nx/web:application']);
104
+ nxJson.generators['@nx/web:application'] = {
105
+ style: options.style,
106
+ linter: options.linter,
107
+ unitTestRunner: options.unitTestRunner,
108
+ e2eTestRunner: options.e2eTestRunner,
109
+ ...nxJson.generators['@nx/web:application'],
110
+ };
105
111
  (0, devkit_1.updateNxJson)(tree, nxJson);
106
112
  }
107
- function applicationGenerator(host, schema) {
108
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
109
- return yield applicationGeneratorInternal(host, Object.assign({ projectNameAndRootFormat: 'derived' }, schema));
113
+ async function applicationGenerator(host, schema) {
114
+ return await applicationGeneratorInternal(host, {
115
+ projectNameAndRootFormat: 'derived',
116
+ ...schema,
110
117
  });
111
118
  }
112
119
  exports.applicationGenerator = applicationGenerator;
113
- function applicationGeneratorInternal(host, schema) {
114
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
115
- const options = yield normalizeOptions(host, schema);
116
- const tasks = [];
117
- const webTask = yield (0, init_1.webInitGenerator)(host, Object.assign(Object.assign({}, options), { skipFormat: true }));
118
- tasks.push(webTask);
119
- createApplicationFiles(host, options);
120
- yield addProject(host, options);
121
- if (options.bundler === 'vite') {
122
- const { viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_2.nxVersion);
123
- // We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
124
- // See: https://vitejs.dev/guide/env-and-mode.html
125
- if (host.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'))) {
126
- host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'));
127
- }
128
- const viteTask = yield viteConfigurationGenerator(host, {
129
- uiFramework: 'none',
130
- project: options.projectName,
131
- newProject: true,
132
- includeVitest: options.unitTestRunner === 'vitest',
133
- inSourceTests: options.inSourceTests,
134
- skipFormat: true,
135
- });
136
- tasks.push(viteTask);
137
- }
138
- if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') {
139
- const { vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_2.nxVersion);
140
- const vitestTask = yield vitestGenerator(host, {
141
- uiFramework: 'none',
142
- project: options.projectName,
143
- coverageProvider: 'c8',
144
- inSourceTests: options.inSourceTests,
145
- skipFormat: true,
146
- });
147
- tasks.push(vitestTask);
148
- }
149
- if ((options.bundler === 'vite' || options.unitTestRunner === 'vitest') &&
150
- options.inSourceTests) {
151
- host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/app/app.element.spec.ts`));
152
- }
153
- if (options.linter === 'eslint') {
154
- const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/linter', versions_2.nxVersion);
155
- const lintTask = yield lintProjectGenerator(host, {
156
- linter: options.linter,
157
- project: options.projectName,
158
- tsConfigPaths: [
159
- (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
160
- ],
161
- unitTestRunner: options.unitTestRunner,
162
- eslintFilePatterns: [`${options.appProjectRoot}/**/*.ts`],
163
- skipFormat: true,
164
- setParserOptionsProject: options.setParserOptionsProject,
165
- });
166
- tasks.push(lintTask);
167
- }
168
- if (options.e2eTestRunner === 'cypress') {
169
- const { cypressProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_2.nxVersion);
170
- const cypressTask = yield cypressProjectGenerator(host, Object.assign(Object.assign({}, options), { name: options.e2eProjectName, directory: options.e2eProjectRoot,
171
- // the name and root are already normalized, instruct the generator to use them as is
172
- projectNameAndRootFormat: 'as-provided', project: options.projectName, skipFormat: true }));
173
- tasks.push(cypressTask);
174
- }
175
- else if (options.e2eTestRunner === 'playwright') {
176
- const { configurationGenerator: playwrightConfigGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_2.nxVersion);
177
- (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
178
- root: options.e2eProjectRoot,
179
- sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
180
- projectType: 'application',
181
- targets: {},
182
- implicitDependencies: [options.projectName],
183
- });
184
- const playwrightTask = yield playwrightConfigGenerator(host, {
185
- project: options.e2eProjectName,
186
- skipFormat: true,
187
- skipPackageJson: false,
188
- directory: 'src',
189
- js: false,
190
- linter: options.linter,
191
- setParserOptionsProject: options.setParserOptionsProject,
192
- webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.name}`,
193
- webServerAddress: 'http://localhost:4200',
194
- });
195
- tasks.push(playwrightTask);
196
- }
197
- if (options.unitTestRunner === 'jest') {
198
- const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_2.nxVersion);
199
- const jestTask = yield configurationGenerator(host, {
200
- project: options.projectName,
201
- skipSerializers: true,
202
- setupFile: 'web-components',
203
- compiler: options.compiler,
204
- skipFormat: true,
205
- });
206
- tasks.push(jestTask);
120
+ async function applicationGeneratorInternal(host, schema) {
121
+ const options = await normalizeOptions(host, schema);
122
+ const tasks = [];
123
+ const webTask = await (0, init_1.webInitGenerator)(host, {
124
+ ...options,
125
+ skipFormat: true,
126
+ });
127
+ tasks.push(webTask);
128
+ createApplicationFiles(host, options);
129
+ await addProject(host, options);
130
+ if (options.bundler === 'vite') {
131
+ const { viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_2.nxVersion);
132
+ // We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
133
+ // See: https://vitejs.dev/guide/env-and-mode.html
134
+ if (host.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'))) {
135
+ host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'));
207
136
  }
208
- if (options.compiler === 'swc') {
209
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, '.swcrc'), {
210
- jsc: {
211
- parser: {
212
- syntax: 'typescript',
213
- },
214
- target: 'es2016',
137
+ const viteTask = await viteConfigurationGenerator(host, {
138
+ uiFramework: 'none',
139
+ project: options.projectName,
140
+ newProject: true,
141
+ includeVitest: options.unitTestRunner === 'vitest',
142
+ inSourceTests: options.inSourceTests,
143
+ skipFormat: true,
144
+ });
145
+ tasks.push(viteTask);
146
+ }
147
+ if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') {
148
+ const { vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_2.nxVersion);
149
+ const vitestTask = await vitestGenerator(host, {
150
+ uiFramework: 'none',
151
+ project: options.projectName,
152
+ coverageProvider: 'c8',
153
+ inSourceTests: options.inSourceTests,
154
+ skipFormat: true,
155
+ });
156
+ tasks.push(vitestTask);
157
+ }
158
+ if ((options.bundler === 'vite' || options.unitTestRunner === 'vitest') &&
159
+ options.inSourceTests) {
160
+ host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/app/app.element.spec.ts`));
161
+ }
162
+ if (options.linter === 'eslint') {
163
+ const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/linter', versions_2.nxVersion);
164
+ const lintTask = await lintProjectGenerator(host, {
165
+ linter: options.linter,
166
+ project: options.projectName,
167
+ tsConfigPaths: [
168
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
169
+ ],
170
+ unitTestRunner: options.unitTestRunner,
171
+ eslintFilePatterns: [`${options.appProjectRoot}/**/*.ts`],
172
+ skipFormat: true,
173
+ setParserOptionsProject: options.setParserOptionsProject,
174
+ });
175
+ tasks.push(lintTask);
176
+ }
177
+ if (options.e2eTestRunner === 'cypress') {
178
+ const { cypressProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_2.nxVersion);
179
+ const cypressTask = await cypressProjectGenerator(host, {
180
+ ...options,
181
+ name: options.e2eProjectName,
182
+ directory: options.e2eProjectRoot,
183
+ // the name and root are already normalized, instruct the generator to use them as is
184
+ projectNameAndRootFormat: 'as-provided',
185
+ project: options.projectName,
186
+ skipFormat: true,
187
+ });
188
+ tasks.push(cypressTask);
189
+ }
190
+ else if (options.e2eTestRunner === 'playwright') {
191
+ const { configurationGenerator: playwrightConfigGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_2.nxVersion);
192
+ (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
193
+ root: options.e2eProjectRoot,
194
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
195
+ projectType: 'application',
196
+ targets: {},
197
+ implicitDependencies: [options.projectName],
198
+ });
199
+ const playwrightTask = await playwrightConfigGenerator(host, {
200
+ project: options.e2eProjectName,
201
+ skipFormat: true,
202
+ skipPackageJson: false,
203
+ directory: 'src',
204
+ js: false,
205
+ linter: options.linter,
206
+ setParserOptionsProject: options.setParserOptionsProject,
207
+ webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.name}`,
208
+ webServerAddress: 'http://localhost:4200',
209
+ });
210
+ tasks.push(playwrightTask);
211
+ }
212
+ if (options.unitTestRunner === 'jest') {
213
+ const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_2.nxVersion);
214
+ const jestTask = await configurationGenerator(host, {
215
+ project: options.projectName,
216
+ skipSerializers: true,
217
+ setupFile: 'web-components',
218
+ compiler: options.compiler,
219
+ skipFormat: true,
220
+ });
221
+ tasks.push(jestTask);
222
+ }
223
+ if (options.compiler === 'swc') {
224
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, '.swcrc'), {
225
+ jsc: {
226
+ parser: {
227
+ syntax: 'typescript',
215
228
  },
216
- });
217
- const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, {}, { '@swc/core': versions_1.swcCoreVersion, 'swc-loader': versions_2.swcLoaderVersion });
218
- tasks.push(installTask);
219
- }
220
- else {
221
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, '.babelrc'), {
222
- presets: ['@nx/js/babel'],
223
- });
224
- }
225
- setDefaults(host, options);
226
- if (!schema.skipFormat) {
227
- yield (0, devkit_1.formatFiles)(host);
228
- }
229
- return (0, devkit_1.runTasksInSerial)(...tasks);
230
- });
229
+ target: 'es2016',
230
+ },
231
+ });
232
+ const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, {}, { '@swc/core': versions_1.swcCoreVersion, 'swc-loader': versions_2.swcLoaderVersion });
233
+ tasks.push(installTask);
234
+ }
235
+ else {
236
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, '.babelrc'), {
237
+ presets: ['@nx/js/babel'],
238
+ });
239
+ }
240
+ setDefaults(host, options);
241
+ if (!schema.skipFormat) {
242
+ await (0, devkit_1.formatFiles)(host);
243
+ }
244
+ return (0, devkit_1.runTasksInSerial)(...tasks);
231
245
  }
232
246
  exports.applicationGeneratorInternal = applicationGeneratorInternal;
233
- function normalizeOptions(host, options) {
234
- var _a, _b, _c, _d;
235
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
236
- const { projectName: appProjectName, projectRoot: appProjectRoot, projectNameAndRootFormat, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
237
- name: options.name,
238
- projectType: 'application',
239
- directory: options.directory,
240
- projectNameAndRootFormat: options.projectNameAndRootFormat,
241
- callingGenerator: '@nx/web:application',
242
- });
243
- options.projectNameAndRootFormat = projectNameAndRootFormat;
244
- const e2eProjectName = `${appProjectName}-e2e`;
245
- const e2eProjectRoot = `${appProjectRoot}-e2e`;
246
- const { npmScope } = (0, devkit_1.getWorkspaceLayout)(host);
247
- const parsedTags = options.tags
248
- ? options.tags.split(',').map((s) => s.trim())
249
- : [];
250
- if (options.bundler === 'vite' && !options.unitTestRunner) {
251
- options.unitTestRunner = 'vitest';
252
- }
253
- options.style = options.style || 'css';
254
- options.linter = options.linter || 'eslint';
255
- options.unitTestRunner = options.unitTestRunner || 'jest';
256
- options.e2eTestRunner = options.e2eTestRunner || 'cypress';
257
- return Object.assign(Object.assign({}, options), { prefix: (_b = (_a = options.prefix) !== null && _a !== void 0 ? _a : npmScope) !== null && _b !== void 0 ? _b : 'app', name: (0, devkit_1.names)(options.name).fileName, compiler: (_c = options.compiler) !== null && _c !== void 0 ? _c : 'babel', bundler: (_d = options.bundler) !== null && _d !== void 0 ? _d : 'webpack', projectName: appProjectName, appProjectRoot,
258
- e2eProjectRoot,
259
- e2eProjectName,
260
- parsedTags });
247
+ async function normalizeOptions(host, options) {
248
+ const { projectName: appProjectName, projectRoot: appProjectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
249
+ name: options.name,
250
+ projectType: 'application',
251
+ directory: options.directory,
252
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
253
+ callingGenerator: '@nx/web:application',
261
254
  });
255
+ options.projectNameAndRootFormat = projectNameAndRootFormat;
256
+ const e2eProjectName = `${appProjectName}-e2e`;
257
+ const e2eProjectRoot = `${appProjectRoot}-e2e`;
258
+ const { npmScope } = (0, devkit_1.getWorkspaceLayout)(host);
259
+ const parsedTags = options.tags
260
+ ? options.tags.split(',').map((s) => s.trim())
261
+ : [];
262
+ if (options.bundler === 'vite' && !options.unitTestRunner) {
263
+ options.unitTestRunner = 'vitest';
264
+ }
265
+ options.style = options.style || 'css';
266
+ options.linter = options.linter || 'eslint';
267
+ options.unitTestRunner = options.unitTestRunner || 'jest';
268
+ options.e2eTestRunner = options.e2eTestRunner || 'cypress';
269
+ return {
270
+ ...options,
271
+ prefix: options.prefix ?? npmScope ?? 'app',
272
+ name: (0, devkit_1.names)(options.name).fileName,
273
+ compiler: options.compiler ?? 'babel',
274
+ bundler: options.bundler ?? 'webpack',
275
+ projectName: appProjectName,
276
+ appProjectRoot,
277
+ e2eProjectRoot,
278
+ e2eProjectName,
279
+ parsedTags,
280
+ };
262
281
  }
263
282
  exports.default = applicationGenerator;
264
283
  exports.applicationSchematic = (0, devkit_1.convertNxGenerator)(applicationGenerator);
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.webInitSchematic = exports.webInitGenerator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const js_1 = require("@nx/js");
7
6
  const versions_1 = require("../../utils/versions");
@@ -15,45 +14,43 @@ function updateDependencies(tree, schema) {
15
14
  tslib: versions_1.tsLibVersion,
16
15
  }, devDependencies);
17
16
  }
18
- function webInitGenerator(tree, schema) {
19
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
20
- const tasks = [];
21
- const jsInitTask = yield (0, js_1.initGenerator)(tree, {
22
- js: false,
17
+ async function webInitGenerator(tree, schema) {
18
+ const tasks = [];
19
+ const jsInitTask = await (0, js_1.initGenerator)(tree, {
20
+ js: false,
21
+ skipFormat: true,
22
+ });
23
+ tasks.push(jsInitTask);
24
+ if (!schema.unitTestRunner || schema.unitTestRunner === 'jest') {
25
+ const { jestInitGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
26
+ const jestTask = await jestInitGenerator(tree, {
27
+ skipPackageJson: schema.skipPackageJson,
28
+ });
29
+ tasks.push(jestTask);
30
+ }
31
+ if (!schema.e2eTestRunner || schema.e2eTestRunner === 'cypress') {
32
+ const { cypressInitGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
33
+ const cypressTask = await cypressInitGenerator(tree, {
34
+ skipPackageJson: schema.skipPackageJson,
35
+ });
36
+ tasks.push(cypressTask);
37
+ }
38
+ else if (schema.e2eTestRunner === 'playwright') {
39
+ const { initGenerator: playwrightInitGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_1.nxVersion);
40
+ const playwrightConfigTask = await playwrightInitGenerator(tree, {
23
41
  skipFormat: true,
42
+ skipPackageJson: schema.skipPackageJson,
24
43
  });
25
- tasks.push(jsInitTask);
26
- if (!schema.unitTestRunner || schema.unitTestRunner === 'jest') {
27
- const { jestInitGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
28
- const jestTask = yield jestInitGenerator(tree, {
29
- skipPackageJson: schema.skipPackageJson,
30
- });
31
- tasks.push(jestTask);
32
- }
33
- if (!schema.e2eTestRunner || schema.e2eTestRunner === 'cypress') {
34
- const { cypressInitGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
35
- const cypressTask = yield cypressInitGenerator(tree, {
36
- skipPackageJson: schema.skipPackageJson,
37
- });
38
- tasks.push(cypressTask);
39
- }
40
- else if (schema.e2eTestRunner === 'playwright') {
41
- const { initGenerator: playwrightInitGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_1.nxVersion);
42
- const playwrightConfigTask = yield playwrightInitGenerator(tree, {
43
- skipFormat: true,
44
- skipPackageJson: schema.skipPackageJson,
45
- });
46
- tasks.push(playwrightConfigTask);
47
- }
48
- if (!schema.skipPackageJson) {
49
- const installTask = updateDependencies(tree, schema);
50
- tasks.push(installTask);
51
- }
52
- if (!schema.skipFormat) {
53
- yield (0, devkit_1.formatFiles)(tree);
54
- }
55
- return (0, devkit_1.runTasksInSerial)(...tasks);
56
- });
44
+ tasks.push(playwrightConfigTask);
45
+ }
46
+ if (!schema.skipPackageJson) {
47
+ const installTask = updateDependencies(tree, schema);
48
+ tasks.push(installTask);
49
+ }
50
+ if (!schema.skipFormat) {
51
+ await (0, devkit_1.formatFiles)(tree);
52
+ }
53
+ return (0, devkit_1.runTasksInSerial)(...tasks);
57
54
  }
58
55
  exports.webInitGenerator = webInitGenerator;
59
56
  exports.default = webInitGenerator;
@@ -8,11 +8,14 @@ function webStaticServeGenerator(tree, options) {
8
8
  }
9
9
  exports.webStaticServeGenerator = webStaticServeGenerator;
10
10
  function normalizeOptions(tree, options) {
11
- var _a, _b, _c, _d;
12
11
  const target = (0, devkit_1.parseTargetString)(options.buildTarget);
13
- const opts = Object.assign(Object.assign({}, options), { targetName: options.targetName || 'serve-static', projectName: target.project });
12
+ const opts = {
13
+ ...options,
14
+ targetName: options.targetName || 'serve-static',
15
+ projectName: target.project,
16
+ };
14
17
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, target.project);
15
- const buildTargetConfig = (_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.targets) === null || _a === void 0 ? void 0 : _a[target.target];
18
+ const buildTargetConfig = projectConfig?.targets?.[target.target];
16
19
  if (!buildTargetConfig) {
17
20
  throw new Error((0, devkit_1.stripIndents) `Unable to read the target configuration for the provided build target, ${opts.buildTarget}
18
21
  Are you sure this target exists?`);
@@ -23,18 +26,18 @@ Either rename or remove the existing '${opts.targetName}' target and try again.
23
26
  Optionally, you can provide a different name with the --target-name option other than '${opts.targetName}'`);
24
27
  }
25
28
  // NOTE: @nx/web:file-server only looks for the outputPath option
26
- if (!((_b = buildTargetConfig.options) === null || _b === void 0 ? void 0 : _b.outputPath) && !opts.outputPath) {
29
+ if (!buildTargetConfig.options?.outputPath && !opts.outputPath) {
27
30
  // attempt to find the suiteable path from the outputs
28
31
  let maybeOutputValue;
29
- for (const o of (buildTargetConfig === null || buildTargetConfig === void 0 ? void 0 : buildTargetConfig.outputs) || []) {
32
+ for (const o of buildTargetConfig?.outputs || []) {
30
33
  const isInterpolatedOutput = o.trim().startsWith('{options.');
31
34
  if (!isInterpolatedOutput) {
32
35
  continue;
33
36
  }
34
37
  const noBracketParts = o.replace(/[{}]/g, '').split('.');
35
- if (noBracketParts.length === 2 && (noBracketParts === null || noBracketParts === void 0 ? void 0 : noBracketParts[1])) {
38
+ if (noBracketParts.length === 2 && noBracketParts?.[1]) {
36
39
  const key = noBracketParts[1].trim();
37
- const value = (_c = buildTargetConfig.options) === null || _c === void 0 ? void 0 : _c[key];
40
+ const value = buildTargetConfig.options?.[key];
38
41
  if (value) {
39
42
  maybeOutputValue = value;
40
43
  break;
@@ -42,7 +45,7 @@ Optionally, you can provide a different name with the --target-name option other
42
45
  }
43
46
  }
44
47
  // NOTE: outputDir is the storybook option.
45
- opts.outputPath = ((_d = buildTargetConfig.options) === null || _d === void 0 ? void 0 : _d.outputDir) || maybeOutputValue;
48
+ opts.outputPath = buildTargetConfig.options?.outputDir || maybeOutputValue;
46
49
  if (opts.outputPath) {
47
50
  devkit_1.logger.warn(`Automatically detected the output path to be ${opts.outputPath}.
48
51
  If this is incorrect, the update the staticFilePath option in the ${target.project}:${opts.targetName} target configuration`);