@nx/angular 0.0.0-pr-27957-a99d5ea → 0.0.0-pr-28229-afe192c

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 (87) hide show
  1. package/generators.d.ts +0 -1
  2. package/generators.js +0 -1
  3. package/generators.json +7 -13
  4. package/package.json +11 -11
  5. package/plugin.d.ts +1 -0
  6. package/plugin.js +5 -0
  7. package/src/builders/utilities/webpack.js +30 -4
  8. package/src/generators/application/application.d.ts +0 -1
  9. package/src/generators/application/application.js +0 -7
  10. package/src/generators/application/lib/normalize-options.js +3 -5
  11. package/src/generators/application/schema.d.ts +2 -4
  12. package/src/generators/application/schema.json +7 -12
  13. package/src/generators/component/component.d.ts +0 -1
  14. package/src/generators/component/component.js +0 -7
  15. package/src/generators/component/lib/normalize-options.js +1 -6
  16. package/src/generators/component/schema.d.ts +2 -18
  17. package/src/generators/component/schema.json +7 -28
  18. package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +1 -2
  19. package/src/generators/cypress-component-configuration/cypress-component-configuration.js +1 -7
  20. package/src/generators/directive/lib/normalize-options.js +1 -6
  21. package/src/generators/directive/schema.d.ts +2 -15
  22. package/src/generators/directive/schema.json +8 -29
  23. package/src/generators/federate-module/lib/add-remote.js +0 -3
  24. package/src/generators/federate-module/schema.d.ts +0 -2
  25. package/src/generators/federate-module/schema.json +0 -5
  26. package/src/generators/host/host.d.ts +1 -2
  27. package/src/generators/host/host.js +8 -22
  28. package/src/generators/host/schema.d.ts +2 -4
  29. package/src/generators/host/schema.json +10 -13
  30. package/src/generators/init/init.js +12 -0
  31. package/src/generators/init/schema.d.ts +3 -0
  32. package/src/generators/library/lib/add-standalone-component.js +3 -2
  33. package/src/generators/library/lib/normalize-options.js +1 -2
  34. package/src/generators/library/lib/normalized-schema.d.ts +2 -2
  35. package/src/generators/library/library.d.ts +0 -1
  36. package/src/generators/library/library.js +0 -9
  37. package/src/generators/library/schema.d.ts +2 -4
  38. package/src/generators/library/schema.json +7 -13
  39. package/src/generators/move/move.d.ts +0 -1
  40. package/src/generators/move/move.js +1 -8
  41. package/src/generators/move/schema.d.ts +0 -3
  42. package/src/generators/move/schema.json +0 -5
  43. package/src/generators/pipe/lib/normalize-options.js +1 -6
  44. package/src/generators/pipe/schema.d.ts +2 -15
  45. package/src/generators/pipe/schema.json +7 -28
  46. package/src/generators/remote/remote.d.ts +1 -2
  47. package/src/generators/remote/remote.js +3 -12
  48. package/src/generators/remote/schema.d.ts +2 -4
  49. package/src/generators/remote/schema.json +10 -13
  50. package/src/generators/scam/lib/normalize-options.js +1 -6
  51. package/src/generators/scam/scam.js +0 -2
  52. package/src/generators/scam/schema.d.ts +3 -15
  53. package/src/generators/scam/schema.json +8 -29
  54. package/src/generators/scam-directive/lib/normalize-options.js +1 -6
  55. package/src/generators/scam-directive/scam-directive.js +0 -2
  56. package/src/generators/scam-directive/schema.d.ts +3 -15
  57. package/src/generators/scam-directive/schema.json +8 -3
  58. package/src/generators/scam-pipe/lib/normalize-options.js +1 -6
  59. package/src/generators/scam-pipe/scam-pipe.js +0 -2
  60. package/src/generators/scam-pipe/schema.d.ts +3 -15
  61. package/src/generators/scam-pipe/schema.json +8 -23
  62. package/src/generators/stories/schema.d.ts +0 -2
  63. package/src/generators/stories/schema.json +0 -10
  64. package/src/generators/stories/stories.js +0 -19
  65. package/src/generators/storybook-configuration/lib/generate-stories.js +0 -6
  66. package/src/generators/storybook-configuration/lib/generate-storybook-configuration.js +0 -2
  67. package/src/generators/storybook-configuration/schema.d.ts +0 -3
  68. package/src/generators/storybook-configuration/schema.json +0 -15
  69. package/src/generators/storybook-configuration/storybook-configuration.js +0 -3
  70. package/src/generators/utils/testing.js +14 -26
  71. package/src/plugins/plugin.d.ts +19 -0
  72. package/src/plugins/plugin.js +418 -0
  73. package/src/utils/versions.d.ts +1 -1
  74. package/src/utils/versions.js +1 -1
  75. package/src/generators/component-cypress-spec/component-cypress-spec.d.ts +0 -4
  76. package/src/generators/component-cypress-spec/component-cypress-spec.js +0 -35
  77. package/src/generators/component-cypress-spec/files/__componentFileName__.__fileExt__ +0 -17
  78. package/src/generators/component-cypress-spec/lib/get-args-default-value.d.ts +0 -2
  79. package/src/generators/component-cypress-spec/lib/get-args-default-value.js +0 -24
  80. package/src/generators/component-cypress-spec/lib/get-component-selector.d.ts +0 -2
  81. package/src/generators/component-cypress-spec/lib/get-component-selector.js +0 -23
  82. package/src/generators/component-cypress-spec/schema.d.ts +0 -10
  83. package/src/generators/component-cypress-spec/schema.json +0 -66
  84. package/src/generators/stories/lib/get-e2e-project.d.ts +0 -2
  85. package/src/generators/stories/lib/get-e2e-project.js +0 -14
  86. package/src/generators/storybook-configuration/lib/validate-options.d.ts +0 -2
  87. package/src/generators/storybook-configuration/lib/validate-options.js +0 -8
@@ -0,0 +1,418 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodesV2 = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
7
+ const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
8
+ const js_1 = require("@nx/js");
9
+ const node_fs_1 = require("node:fs");
10
+ const node_path_1 = require("node:path");
11
+ const posix = tslib_1.__importStar(require("node:path/posix"));
12
+ const devkit_internals_1 = require("nx/src/devkit-internals");
13
+ const cache_directory_1 = require("nx/src/utils/cache-directory");
14
+ const knownExecutors = {
15
+ appShell: new Set(['@angular-devkit/build-angular:app-shell']),
16
+ build: new Set([
17
+ '@angular-devkit/build-angular:application',
18
+ '@angular/build:application',
19
+ '@angular-devkit/build-angular:browser-esbuild',
20
+ '@angular-devkit/build-angular:browser',
21
+ '@angular-devkit/build-angular:ng-packagr',
22
+ ]),
23
+ devServer: new Set(['@angular-devkit/build-angular:dev-server']),
24
+ extractI18n: new Set(['@angular-devkit/build-angular:extract-i18n']),
25
+ prerender: new Set([
26
+ '@angular-devkit/build-angular:prerender',
27
+ '@nguniversal/builders:prerender',
28
+ ]),
29
+ server: new Set(['@angular-devkit/build-angular:server']),
30
+ serveSsr: new Set([
31
+ '@angular-devkit/build-angular:ssr-dev-server',
32
+ '@nguniversal/builders:ssr-dev-server',
33
+ ]),
34
+ test: new Set(['@angular-devkit/build-angular:karma']),
35
+ };
36
+ const pmc = (0, devkit_1.getPackageManagerCommand)();
37
+ function readProjectsCache(cachePath) {
38
+ return (0, node_fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
39
+ }
40
+ function writeProjectsToCache(cachePath, results) {
41
+ (0, devkit_1.writeJsonFile)(cachePath, results);
42
+ }
43
+ exports.createNodesV2 = [
44
+ '**/angular.json',
45
+ async (configFiles, options, context) => {
46
+ const optionsHash = (0, devkit_internals_1.hashObject)(options);
47
+ const cachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, `angular-${optionsHash}.hash`);
48
+ const projectsCache = readProjectsCache(cachePath);
49
+ try {
50
+ return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, projectsCache), configFiles, options, context);
51
+ }
52
+ finally {
53
+ writeProjectsToCache(cachePath, projectsCache);
54
+ }
55
+ },
56
+ ];
57
+ async function createNodesInternal(configFilePath, options, context, projectsCache) {
58
+ const angularWorkspaceRoot = (0, node_path_1.dirname)(configFilePath);
59
+ // Do not create a project if package.json isn't there
60
+ const siblingFiles = (0, node_fs_1.readdirSync)((0, node_path_1.join)(context.workspaceRoot, angularWorkspaceRoot));
61
+ if (!siblingFiles.includes('package.json')) {
62
+ return {};
63
+ }
64
+ const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(angularWorkspaceRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
65
+ projectsCache[hash] ??= await buildAngularProjects(configFilePath, options, angularWorkspaceRoot, context);
66
+ return { projects: projectsCache[hash] };
67
+ }
68
+ async function buildAngularProjects(configFilePath, options, angularWorkspaceRoot, context) {
69
+ const projects = {};
70
+ const absoluteConfigFilePath = (0, node_path_1.join)(context.workspaceRoot, configFilePath);
71
+ const angularJson = (0, devkit_1.readJsonFile)(absoluteConfigFilePath);
72
+ const appShellTargets = [];
73
+ const prerenderTargets = [];
74
+ for (const [projectName, project] of Object.entries(angularJson.projects ?? {})) {
75
+ const targets = {};
76
+ const projectTargets = getAngularJsonProjectTargets(project);
77
+ if (!projectTargets) {
78
+ continue;
79
+ }
80
+ const namedInputs = (0, get_named_inputs_1.getNamedInputs)(project.root, context);
81
+ for (const [angularTargetName, angularTarget] of Object.entries(projectTargets)) {
82
+ const nxTargetName = options?.targetNamePrefix
83
+ ? `${options.targetNamePrefix}${angularTargetName}`
84
+ : angularTargetName;
85
+ const externalDependencies = ['@angular/cli'];
86
+ targets[nxTargetName] = {
87
+ command:
88
+ // For targets that are also Angular CLI commands, infer the simplified form.
89
+ // Otherwise, use `ng run` to support non-command targets so that they will run.
90
+ angularTargetName === 'build' ||
91
+ angularTargetName === 'deploy' ||
92
+ angularTargetName === 'extract-i18n' ||
93
+ angularTargetName === 'e2e' ||
94
+ angularTargetName === 'lint' ||
95
+ angularTargetName === 'serve' ||
96
+ angularTargetName === 'test'
97
+ ? `ng ${angularTargetName}`
98
+ : `ng run ${projectName}:${angularTargetName}`,
99
+ options: { cwd: angularWorkspaceRoot },
100
+ metadata: {
101
+ technologies: ['angular'],
102
+ description: `Run the "${angularTargetName}" target for "${projectName}".`,
103
+ help: {
104
+ command: `${pmc.exec} ng run ${projectName}:${angularTargetName} --help`,
105
+ example: {},
106
+ },
107
+ },
108
+ };
109
+ if (knownExecutors.appShell.has(angularTarget.builder)) {
110
+ appShellTargets.push({ target: nxTargetName, project: projectName });
111
+ }
112
+ else if (knownExecutors.build.has(angularTarget.builder)) {
113
+ await updateBuildTarget(nxTargetName, targets[nxTargetName], angularTarget, context, angularWorkspaceRoot, project.root, namedInputs);
114
+ }
115
+ else if (knownExecutors.devServer.has(angularTarget.builder)) {
116
+ targets[nxTargetName].metadata.help.example.options = { port: 4201 };
117
+ }
118
+ else if (knownExecutors.extractI18n.has(angularTarget.builder)) {
119
+ targets[nxTargetName].metadata.help.example.options = {
120
+ format: 'json',
121
+ };
122
+ }
123
+ else if (knownExecutors.test.has(angularTarget.builder)) {
124
+ updateTestTarget(targets[nxTargetName], angularTarget, context, angularWorkspaceRoot, project.root, namedInputs, externalDependencies);
125
+ }
126
+ else if (knownExecutors.server.has(angularTarget.builder)) {
127
+ updateServerTarget(targets[nxTargetName], angularTarget, context, angularWorkspaceRoot, project.root, namedInputs);
128
+ }
129
+ else if (knownExecutors.serveSsr.has(angularTarget.builder)) {
130
+ targets[nxTargetName].metadata.help.example.options = { port: 4201 };
131
+ }
132
+ else if (knownExecutors.prerender.has(angularTarget.builder)) {
133
+ prerenderTargets.push({ target: nxTargetName, project: projectName });
134
+ }
135
+ if (targets[nxTargetName].inputs?.length) {
136
+ targets[nxTargetName].inputs.push({ externalDependencies });
137
+ }
138
+ if (angularTarget.configurations) {
139
+ for (const configurationName of Object.keys(angularTarget.configurations)) {
140
+ targets[nxTargetName].configurations = {
141
+ ...targets[nxTargetName].configurations,
142
+ [configurationName]: {
143
+ command: `ng run ${projectName}:${angularTargetName}:${configurationName}`,
144
+ },
145
+ };
146
+ }
147
+ }
148
+ if (angularTarget.defaultConfiguration) {
149
+ targets[nxTargetName].defaultConfiguration =
150
+ angularTarget.defaultConfiguration;
151
+ }
152
+ }
153
+ projects[projectName] = {
154
+ projectType: project.projectType,
155
+ root: posix.join(angularWorkspaceRoot, project.root),
156
+ sourceRoot: project.sourceRoot
157
+ ? posix.join(angularWorkspaceRoot, project.sourceRoot)
158
+ : undefined,
159
+ targets,
160
+ };
161
+ }
162
+ for (const { project, target } of appShellTargets) {
163
+ updateAppShellTarget(project, target, projects, angularJson, angularWorkspaceRoot, context);
164
+ }
165
+ for (const { project, target } of prerenderTargets) {
166
+ updatePrerenderTarget(project, target, projects, angularJson);
167
+ }
168
+ return Object.entries(projects).reduce((acc, [projectName, project]) => {
169
+ acc[project.root] = {
170
+ projectType: project.projectType,
171
+ sourceRoot: project.sourceRoot,
172
+ targets: project.targets,
173
+ };
174
+ return acc;
175
+ }, {});
176
+ }
177
+ function updateAppShellTarget(projectName, targetName, projects, angularJson, angularWorkspaceRoot, context) {
178
+ // it must exist since we collected it when processing it
179
+ const target = projects[projectName].targets[targetName];
180
+ target.metadata.help.example.options = { route: '/some/route' };
181
+ const { inputs, outputs } = getBrowserAndServerTargetInputsAndOutputs(projectName, targetName, projects, angularJson);
182
+ const outputIndexPath = getAngularJsonProjectTargets(angularJson.projects[projectName])[targetName].options?.outputIndexPath;
183
+ if (outputIndexPath) {
184
+ const fullOutputIndexPath = (0, node_path_1.join)(context.workspaceRoot, angularWorkspaceRoot, outputIndexPath);
185
+ outputs.push(getOutput(fullOutputIndexPath, context.workspaceRoot, angularWorkspaceRoot, angularJson.projects[projectName].root));
186
+ }
187
+ if (!outputs.length) {
188
+ // no outputs were identified for the build or server target, so we don't
189
+ // set any Nx cache options
190
+ return;
191
+ }
192
+ target.cache = true;
193
+ target.inputs = inputs;
194
+ target.outputs = outputs;
195
+ }
196
+ async function updateBuildTarget(targetName, target, angularTarget, context, angularWorkspaceRoot, projectRoot, namedInputs) {
197
+ target.dependsOn = [`^${targetName}`];
198
+ if (angularTarget.options?.outputPath) {
199
+ const fullOutputPath = (0, node_path_1.join)(context.workspaceRoot, angularWorkspaceRoot, angularTarget.options.outputPath);
200
+ target.outputs = [
201
+ getOutput(fullOutputPath, context.workspaceRoot, angularWorkspaceRoot, projectRoot),
202
+ ];
203
+ }
204
+ else if (angularTarget.builder === '@angular-devkit/build-angular:ng-packagr') {
205
+ const outputs = await getNgPackagrOutputs(angularTarget, angularWorkspaceRoot, projectRoot, context);
206
+ if (outputs.length) {
207
+ target.outputs = outputs;
208
+ }
209
+ }
210
+ if (target.outputs?.length) {
211
+ // make it cacheable if we were able to identify outputs
212
+ target.cache = true;
213
+ target.inputs =
214
+ 'production' in namedInputs
215
+ ? ['production', '^production']
216
+ : ['default', '^default'];
217
+ }
218
+ if (angularTarget.builder === '@angular-devkit/build-angular:ng-packagr') {
219
+ target.metadata.help.example.options = { watch: true };
220
+ }
221
+ else {
222
+ target.metadata.help.example.options = { localize: true };
223
+ }
224
+ }
225
+ function updateTestTarget(target, angularTarget, context, angularWorkspaceRoot, projectRoot, namedInputs, externalDependencies) {
226
+ target.cache = true;
227
+ target.inputs =
228
+ 'production' in namedInputs
229
+ ? ['default', '^production']
230
+ : ['default', '^default'];
231
+ target.outputs = getKarmaTargetOutputs(angularTarget, angularWorkspaceRoot, projectRoot, context);
232
+ externalDependencies.push('karma');
233
+ target.metadata.help.example.options = { codeCoverage: true };
234
+ }
235
+ function updateServerTarget(target, angularTarget, context, angularWorkspaceRoot, projectRoot, namedInputs) {
236
+ target.metadata.help.example.options = { localize: true };
237
+ if (!angularTarget.options?.outputPath) {
238
+ // only make it cacheable if we were able to identify outputs
239
+ return;
240
+ }
241
+ target.cache = true;
242
+ target.inputs =
243
+ 'production' in namedInputs
244
+ ? ['production', '^production']
245
+ : ['default', '^default'];
246
+ const fullOutputPath = (0, node_path_1.join)(context.workspaceRoot, angularWorkspaceRoot, angularTarget.options.outputPath);
247
+ target.outputs = [
248
+ getOutput(fullOutputPath, context.workspaceRoot, angularWorkspaceRoot, projectRoot),
249
+ ];
250
+ }
251
+ function updatePrerenderTarget(projectName, targetName, projects, angularJson) {
252
+ // it must exist since we collected it when processing it
253
+ const target = projects[projectName].targets[targetName];
254
+ target.metadata.help.example.options =
255
+ getAngularJsonProjectTargets(angularJson.projects[projectName])[targetName]
256
+ .builder === '@angular-devkit/build-angular:prerender'
257
+ ? { discoverRoutes: false }
258
+ : { guessRoutes: false };
259
+ const { inputs, outputs } = getBrowserAndServerTargetInputsAndOutputs(projectName, targetName, projects, angularJson);
260
+ if (!outputs.length) {
261
+ // no outputs were identified for the build or server target, so we don't
262
+ // set any Nx cache options
263
+ return;
264
+ }
265
+ target.cache = true;
266
+ target.inputs = inputs;
267
+ target.outputs = outputs;
268
+ }
269
+ async function getNgPackagrOutputs(target, angularWorkspaceRoot, projectRoot, context) {
270
+ let ngPackageJsonPath = (0, node_path_1.join)(context.workspaceRoot, angularWorkspaceRoot, target.options.project);
271
+ const readConfig = async (configPath) => {
272
+ if (!(0, node_fs_1.existsSync)(configPath)) {
273
+ return undefined;
274
+ }
275
+ try {
276
+ if (configPath.endsWith('.js')) {
277
+ const result = await import(configPath);
278
+ return result['default'] ?? result;
279
+ }
280
+ return (0, devkit_1.readJsonFile)(configPath);
281
+ }
282
+ catch { }
283
+ return undefined;
284
+ };
285
+ let ngPackageJson;
286
+ let basePath;
287
+ if ((0, node_fs_1.statSync)(ngPackageJsonPath).isDirectory()) {
288
+ basePath = ngPackageJsonPath;
289
+ ngPackageJson = await readConfig((0, node_path_1.join)(ngPackageJsonPath, 'ng-package.json'));
290
+ if (!ngPackageJson) {
291
+ ngPackageJson = await readConfig((0, node_path_1.join)(ngPackageJsonPath, 'ng-package.js'));
292
+ }
293
+ }
294
+ else {
295
+ basePath = (0, node_path_1.dirname)(ngPackageJsonPath);
296
+ ngPackageJson = await readConfig(ngPackageJsonPath);
297
+ }
298
+ if (!ngPackageJson) {
299
+ return [];
300
+ }
301
+ const destination = ngPackageJson.dest
302
+ ? (0, node_path_1.join)(basePath, ngPackageJson.dest)
303
+ : (0, node_path_1.join)(basePath, 'dist');
304
+ return [
305
+ getOutput(destination, context.workspaceRoot, angularWorkspaceRoot, projectRoot),
306
+ ];
307
+ }
308
+ function getKarmaTargetOutputs(target, angularWorkspaceRoot, projectRoot, context) {
309
+ const defaultOutput = posix.join('{workspaceRoot}', angularWorkspaceRoot, 'coverage/{projectName}');
310
+ if (!target.options?.karmaConfig) {
311
+ return [defaultOutput];
312
+ }
313
+ try {
314
+ const { parseConfig } = require('karma/lib/config');
315
+ const karmaConfigPath = (0, node_path_1.join)(context.workspaceRoot, angularWorkspaceRoot, projectRoot, target.options.karmaConfig);
316
+ const config = parseConfig(karmaConfigPath);
317
+ if (config.coverageReporter.dir) {
318
+ return [
319
+ getOutput(config.coverageReporter.dir, context.workspaceRoot, angularWorkspaceRoot, projectRoot),
320
+ ];
321
+ }
322
+ }
323
+ catch {
324
+ // we silently ignore any error here and fall back to the default output
325
+ }
326
+ return [defaultOutput];
327
+ }
328
+ function getBrowserAndServerTargetInputsAndOutputs(projectName, targetName, projects, angularJson) {
329
+ const { browserTarget, serverTarget } = extractBrowserAndServerTargets(angularJson, projectName, targetName);
330
+ if (!browserTarget || !serverTarget) {
331
+ // if any of these are missing, the target is invalid so we return empty values
332
+ return { inputs: [], outputs: [] };
333
+ }
334
+ const browserTargetInputs = projects[browserTarget.project]?.targets?.[browserTarget.target]?.inputs ??
335
+ [];
336
+ const serverTargetInputs = projects[serverTarget.project]?.targets?.[serverTarget.target]?.inputs ??
337
+ [];
338
+ const browserTargetOutputs = projects[browserTarget.project]?.targets?.[browserTarget.target]?.outputs ??
339
+ [];
340
+ const serverTargetOutputs = projects[serverTarget.project]?.targets?.[serverTarget.target]?.outputs ??
341
+ [];
342
+ return {
343
+ inputs: mergeInputs(...browserTargetInputs, ...serverTargetInputs),
344
+ outputs: Array.from(new Set([...browserTargetOutputs, ...serverTargetOutputs])),
345
+ };
346
+ }
347
+ function extractBrowserAndServerTargets(angularJson, projectName, targetName) {
348
+ let browserTarget;
349
+ let serverTarget;
350
+ try {
351
+ const targets = getAngularJsonProjectTargets(angularJson.projects[projectName]);
352
+ const target = targets[targetName];
353
+ let browserTargetSpecifier = target.options?.browserTarget;
354
+ if (!browserTargetSpecifier) {
355
+ const configuration = Object.values(target.configurations ?? {}).find((config) => !!config.browserTarget);
356
+ browserTargetSpecifier = configuration?.browserTarget;
357
+ }
358
+ if (browserTargetSpecifier) {
359
+ browserTarget = targetFromTargetString(browserTargetSpecifier, projectName, targetName);
360
+ }
361
+ let serverTargetSpecifier = target.options?.serverTarget;
362
+ if (!serverTargetSpecifier) {
363
+ serverTargetSpecifier = Object.values(target.configurations ?? {}).find((config) => !!config.serverTarget)?.serverTarget;
364
+ }
365
+ if (serverTargetSpecifier) {
366
+ serverTarget = targetFromTargetString(serverTargetSpecifier, projectName, targetName);
367
+ }
368
+ }
369
+ catch { }
370
+ return { browserTarget: browserTarget, serverTarget };
371
+ }
372
+ function mergeInputs(...inputs) {
373
+ const stringInputs = new Set();
374
+ const externalDependencies = new Set();
375
+ for (const input of inputs) {
376
+ if (typeof input === 'string') {
377
+ stringInputs.add(input);
378
+ }
379
+ else if ('externalDependencies' in input) {
380
+ // we only infer external dependencies, so we don't need to handle the other input definitions
381
+ for (const externalDependency of input.externalDependencies) {
382
+ externalDependencies.add(externalDependency);
383
+ }
384
+ }
385
+ }
386
+ return [
387
+ ...stringInputs,
388
+ ...(externalDependencies.size
389
+ ? [{ externalDependencies: Array.from(externalDependencies) }]
390
+ : []),
391
+ ];
392
+ }
393
+ // angular support abbreviated target specifiers, this is adapter from:
394
+ // https://github.com/angular/angular-cli/blob/7d9ce246a33c60ec96eb4bf99520f5475716a910/packages/angular_devkit/architect/src/api.ts#L336
395
+ function targetFromTargetString(specifier, abbreviatedProjectName, abbreviatedTargetName) {
396
+ const tuple = specifier.split(':', 3);
397
+ if (tuple.length < 2) {
398
+ // invalid target, ignore
399
+ return undefined;
400
+ }
401
+ // we only care about project and target
402
+ return {
403
+ project: tuple[0] || abbreviatedProjectName || '',
404
+ target: tuple[1] || abbreviatedTargetName || '',
405
+ };
406
+ }
407
+ function getOutput(path, workspaceRoot, angularWorkspaceRoot, projectRoot) {
408
+ const relativePath = (0, node_path_1.relative)((0, node_path_1.join)(workspaceRoot, angularWorkspaceRoot, projectRoot), path);
409
+ if (relativePath.startsWith('..')) {
410
+ return posix.join('{workspaceRoot}', (0, node_path_1.join)(angularWorkspaceRoot, projectRoot, relativePath));
411
+ }
412
+ else {
413
+ return posix.join('{projectRoot}', relativePath);
414
+ }
415
+ }
416
+ function getAngularJsonProjectTargets(project) {
417
+ return project.architect ?? project.targets;
418
+ }
@@ -13,7 +13,7 @@ export declare const expressVersion = "~4.18.2";
13
13
  export declare const typesExpressVersion = "4.17.14";
14
14
  export declare const browserSyncVersion = "^3.0.0";
15
15
  export declare const moduleFederationNodeVersion = "~2.5.0";
16
- export declare const moduleFederationEnhancedVersion = "~0.6.0";
16
+ export declare const moduleFederationEnhancedVersion = "0.6.6";
17
17
  export declare const angularEslintVersion = "^18.3.0";
18
18
  export declare const typescriptEslintVersion = "^7.16.0";
19
19
  export declare const tailwindVersion = "^3.0.2";
@@ -16,7 +16,7 @@ exports.expressVersion = '~4.18.2';
16
16
  exports.typesExpressVersion = '4.17.14';
17
17
  exports.browserSyncVersion = '^3.0.0';
18
18
  exports.moduleFederationNodeVersion = '~2.5.0';
19
- exports.moduleFederationEnhancedVersion = '~0.6.0';
19
+ exports.moduleFederationEnhancedVersion = '0.6.6';
20
20
  exports.angularEslintVersion = '^18.3.0';
21
21
  exports.typescriptEslintVersion = '^7.16.0';
22
22
  exports.tailwindVersion = '^3.0.2';
@@ -1,4 +0,0 @@
1
- import type { Tree } from '@nx/devkit';
2
- import type { ComponentCypressSpecGeneratorOptions } from './schema';
3
- export declare function componentCypressSpecGenerator(tree: Tree, options: ComponentCypressSpecGeneratorOptions): Promise<void>;
4
- export default componentCypressSpecGenerator;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.componentCypressSpecGenerator = componentCypressSpecGenerator;
4
- const devkit_1 = require("@nx/devkit");
5
- const storybook_inputs_1 = require("../utils/storybook-ast/storybook-inputs");
6
- const get_args_default_value_1 = require("./lib/get-args-default-value");
7
- const get_component_selector_1 = require("./lib/get-component-selector");
8
- async function componentCypressSpecGenerator(tree, options) {
9
- const { cypressProject, projectName, projectPath, componentPath, componentFileName, componentName, specDirectory, } = options;
10
- const e2eProjectName = cypressProject || `${projectName}-e2e`;
11
- const { sourceRoot, root } = (0, devkit_1.readProjectConfiguration)(tree, e2eProjectName);
12
- const isCypressV10 = tree.exists((0, devkit_1.joinPathFragments)(root, 'cypress.config.ts'));
13
- const e2eLibIntegrationFolderPath = (0, devkit_1.joinPathFragments)(sourceRoot, isCypressV10 ? 'e2e' : 'integration');
14
- const templatesDir = (0, devkit_1.joinPathFragments)(__dirname, 'files');
15
- const destinationDir = (0, devkit_1.joinPathFragments)(e2eLibIntegrationFolderPath, specDirectory ?? componentPath);
16
- const storyFile = (0, devkit_1.joinPathFragments)(destinationDir, `${componentFileName}.${isCypressV10 ? 'cy' : 'spec'}.ts`);
17
- if (tree.exists(storyFile)) {
18
- return;
19
- }
20
- const fullComponentPath = (0, devkit_1.joinPathFragments)(projectPath, componentPath, `${componentFileName}.ts`);
21
- const props = (0, storybook_inputs_1.getComponentProps)(tree, fullComponentPath, get_args_default_value_1.getArgsDefaultValue);
22
- const componentSelector = (0, get_component_selector_1.getComponentSelector)(tree, fullComponentPath);
23
- (0, devkit_1.generateFiles)(tree, templatesDir, destinationDir, {
24
- projectName,
25
- componentFileName,
26
- componentName,
27
- componentSelector,
28
- props,
29
- fileExt: isCypressV10 ? 'cy.ts' : 'spec.ts',
30
- });
31
- if (!options.skipFormat) {
32
- await (0, devkit_1.formatFiles)(tree);
33
- }
34
- }
35
- exports.default = componentCypressSpecGenerator;
@@ -1,17 +0,0 @@
1
- describe('<%=projectName%>', () => {
2
- beforeEach(() =>
3
- cy.visit(
4
- '/iframe.html?id=<%= componentName.toLowerCase() %>--primary<% if ( props && props.length > 0 ) { %>&args=<% } %><%
5
- for(let prop of props) {
6
- %><%=prop.name%><%
7
- if(prop.defaultValue !== undefined && (prop.defaultValue || prop.defaultValue === false)) {
8
- %>:<%=prop.defaultValue%><%
9
- } %>;<%
10
- }%>'
11
- )
12
- );
13
-
14
- it('should render the component', () => {
15
- cy.get('<%=componentSelector%>').should('exist');
16
- });
17
- });
@@ -1,2 +0,0 @@
1
- import type { PropertyDeclaration } from 'typescript';
2
- export declare function getArgsDefaultValue(property: PropertyDeclaration): string | undefined;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getArgsDefaultValue = getArgsDefaultValue;
4
- const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
5
- let tsModule;
6
- function getArgsDefaultValue(property) {
7
- if (!property.initializer) {
8
- return undefined;
9
- }
10
- if (!tsModule) {
11
- tsModule = (0, ensure_typescript_1.ensureTypescript)();
12
- }
13
- switch (property.initializer.kind) {
14
- case tsModule.SyntaxKind.StringLiteral:
15
- const returnString = property.initializer.getText().slice(1, -1);
16
- return returnString.replace(/\s/g, '+');
17
- case tsModule.SyntaxKind.NumericLiteral:
18
- case tsModule.SyntaxKind.TrueKeyword:
19
- case tsModule.SyntaxKind.FalseKeyword:
20
- return property.initializer.getText();
21
- default:
22
- return undefined;
23
- }
24
- }
@@ -1,2 +0,0 @@
1
- import type { Tree } from '@nx/devkit';
2
- export declare function getComponentSelector(tree: Tree, path: string): string;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getComponentSelector = getComponentSelector;
4
- const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
5
- const js_1 = require("@nx/js");
6
- const ast_utils_1 = require("../../../utils/nx-devkit/ast-utils");
7
- let tsModule;
8
- function getComponentSelector(tree, path) {
9
- if (!tsModule) {
10
- tsModule = (0, ensure_typescript_1.ensureTypescript)();
11
- }
12
- const file = (0, ast_utils_1.getTsSourceFile)(tree, path);
13
- const componentDecorators = (0, ast_utils_1.getDecoratorMetadata)(file, 'Component', '@angular/core');
14
- if (componentDecorators.length === 0) {
15
- throw new Error(`No @Component decorator in ${path}.`);
16
- }
17
- const componentDecorator = componentDecorators[0];
18
- const selectorNode = ((0, js_1.findNodes)(componentDecorator, tsModule.SyntaxKind.PropertyAssignment).find((node) => node.name.getText() === 'selector'));
19
- if (!selectorNode) {
20
- throw new Error(`No selector defined for the component in ${path}.`);
21
- }
22
- return selectorNode.initializer.getText().slice(1, -1);
23
- }
@@ -1,10 +0,0 @@
1
- export interface ComponentCypressSpecGeneratorOptions {
2
- projectName: string;
3
- projectPath: string;
4
- componentName: string;
5
- componentPath: string;
6
- componentFileName: string;
7
- cypressProject?: string;
8
- specDirectory?: string;
9
- skipFormat?: boolean;
10
- }
@@ -1,66 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/schema",
3
- "$id": "NxAngularComponentCypressSpecGenerator",
4
- "type": "object",
5
- "cli": "nx",
6
- "description": "Creates a Storybook Cypress spec for a UI component that has a story.",
7
- "x-deprecated": "Use interactionTests instead. This option will be removed in v20.",
8
- "properties": {
9
- "projectName": {
10
- "type": "string",
11
- "description": "The name of the project.",
12
- "$default": {
13
- "$source": "projectName"
14
- },
15
- "examples": ["ui-samples"],
16
- "x-priority": "important"
17
- },
18
- "projectPath": {
19
- "type": "string",
20
- "description": "Path to the project.",
21
- "examples": ["libs/ui-samples"],
22
- "x-priority": "important"
23
- },
24
- "componentName": {
25
- "type": "string",
26
- "description": "Class name of the component.",
27
- "examples": ["AwesomeComponent"],
28
- "x-priority": "important"
29
- },
30
- "componentPath": {
31
- "type": "string",
32
- "description": "Relative path to the component file from the project root.",
33
- "examples": ["awesome"],
34
- "x-priority": "important"
35
- },
36
- "componentFileName": {
37
- "type": "string",
38
- "description": "Component file name without the `.ts` extension.",
39
- "examples": ["awesome.component"],
40
- "x-priority": "important"
41
- },
42
- "cypressProject": {
43
- "type": "string",
44
- "description": "The Cypress project to generate the stories under. By default, inferred from `projectName`."
45
- },
46
- "specDirectory": {
47
- "type": "string",
48
- "description": "Directory where to place the generated spec file. By default matches the value of the `componentPath` option."
49
- },
50
- "skipFormat": {
51
- "description": "Skip formatting files.",
52
- "type": "boolean",
53
- "default": false,
54
- "x-priority": "internal"
55
- }
56
- },
57
- "additionalProperties": false,
58
- "required": [
59
- "projectName",
60
- "projectPath",
61
- "componentName",
62
- "componentPath",
63
- "componentFileName"
64
- ],
65
- "examplesFile": "../../../docs/component-cypress-spec-examples.md"
66
- }
@@ -1,2 +0,0 @@
1
- import type { ProjectConfiguration, Tree } from '@nx/devkit';
2
- export declare function getE2EProject(tree: Tree, e2eProjectName: string): ProjectConfiguration;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getE2EProject = getE2EProject;
4
- const devkit_1 = require("@nx/devkit");
5
- function getE2EProject(tree, e2eProjectName) {
6
- let e2eProject;
7
- try {
8
- e2eProject = (0, devkit_1.readProjectConfiguration)(tree, e2eProjectName);
9
- }
10
- catch {
11
- e2eProject = undefined;
12
- }
13
- return e2eProject;
14
- }
@@ -1,2 +0,0 @@
1
- import type { StorybookConfigurationOptions } from '../schema';
2
- export declare function validateOptions(options: StorybookConfigurationOptions): void;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateOptions = validateOptions;
4
- function validateOptions(options) {
5
- if (options.generateCypressSpecs && !options.generateStories) {
6
- throw new Error('Cannot set generateCypressSpecs to true when generateStories is set to false.');
7
- }
8
- }