@nx/cypress 23.1.0-beta.4 → 23.1.0-beta.5

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.
@@ -5,7 +5,8 @@ exports.componentConfigurationGeneratorInternal = componentConfigurationGenerato
5
5
  exports.updateTsConfigForComponentTesting = updateTsConfigForComponentTesting;
6
6
  const tslib_1 = require("tslib");
7
7
  const devkit_1 = require("@nx/devkit");
8
- const internal_1 = require("@nx/js/internal");
8
+ const internal_1 = require("@nx/devkit/internal");
9
+ const internal_2 = require("@nx/js/internal");
9
10
  const assert_supported_cypress_version_1 = require("../../utils/assert-supported-cypress-version");
10
11
  const deprecation_1 = require("../../utils/deprecation");
11
12
  const versions_1 = require("../../utils/versions");
@@ -19,7 +20,7 @@ function componentConfigurationGenerator(tree, options) {
19
20
  }
20
21
  async function componentConfigurationGeneratorInternal(tree, options) {
21
22
  (0, assert_supported_cypress_version_1.assertSupportedCypressVersion)(tree);
22
- (0, internal_1.assertNotUsingTsSolutionSetup)(tree, 'cypress', 'component-configuration');
23
+ (0, internal_2.assertNotUsingTsSolutionSetup)(tree, 'cypress', 'component-configuration');
23
24
  const tasks = [];
24
25
  const opts = normalizeOptions(tree, options);
25
26
  if (!(0, versions_1.getInstalledCypressMajorVersion)(tree)) {
@@ -115,14 +116,24 @@ function updateNxJsonConfiguration(tree, hasPlugin) {
115
116
  !cacheableOperations.includes('component-test')) {
116
117
  cacheableOperations.push('component-test');
117
118
  }
118
- nxJson.targetDefaults ??= {};
119
- nxJson.targetDefaults['component-test'] ??= {};
120
- nxJson.targetDefaults['component-test'].cache ??= true;
121
- nxJson.targetDefaults['component-test'] ??= {};
122
- nxJson.targetDefaults['component-test'].inputs ??= [
123
- 'default',
124
- productionFileSet ? '^production' : '^default',
125
- ];
119
+ // Either a `target: 'component-test'` default or a default keyed on
120
+ // the executor we're scaffolding will apply to the new target — pick
121
+ // the more specific (target-keyed) when both are present.
122
+ const existingForTarget = (0, internal_1.findTargetDefault)(nxJson.targetDefaults, {
123
+ target: 'component-test',
124
+ });
125
+ const existingForExecutor = (0, internal_1.findTargetDefault)(nxJson.targetDefaults, {
126
+ executor: '@nx/cypress:cypress',
127
+ });
128
+ const existing = existingForTarget ?? existingForExecutor;
129
+ (0, internal_1.upsertTargetDefault)(tree, nxJson, {
130
+ target: 'component-test',
131
+ cache: existing?.cache ?? true,
132
+ inputs: existing?.inputs ?? [
133
+ 'default',
134
+ productionFileSet ? '^production' : '^default',
135
+ ],
136
+ });
126
137
  }
127
138
  (0, devkit_1.updateNxJson)(tree, nxJson);
128
139
  }
@@ -14,15 +14,33 @@ function setupE2ETargetDefaults(tree) {
14
14
  return;
15
15
  }
16
16
  // E2e targets depend on all their project's sources + production sources of dependencies
17
- nxJson.targetDefaults ??= {};
18
17
  const productionFileSet = !!nxJson.namedInputs?.production;
19
- nxJson.targetDefaults.e2e ??= {};
20
- nxJson.targetDefaults.e2e.cache ??= true;
21
- nxJson.targetDefaults.e2e.inputs ??= [
22
- 'default',
23
- productionFileSet ? '^production' : '^default',
24
- ];
25
- (0, devkit_1.updateNxJson)(tree, nxJson);
18
+ const existing = findExistingE2eDefault(nxJson.targetDefaults);
19
+ const patch = {};
20
+ if (existing?.cache === undefined)
21
+ patch.cache = true;
22
+ if (existing?.inputs === undefined) {
23
+ patch.inputs = ['default', productionFileSet ? '^production' : '^default'];
24
+ }
25
+ if (Object.keys(patch).length > 0) {
26
+ (0, internal_1.upsertTargetDefault)(tree, nxJson, { target: 'e2e', ...patch });
27
+ (0, devkit_1.updateNxJson)(tree, nxJson);
28
+ }
29
+ }
30
+ function findExistingE2eDefault(td) {
31
+ if (!td)
32
+ return undefined;
33
+ const value = td['e2e'];
34
+ if (value === undefined)
35
+ return undefined;
36
+ if (Array.isArray(value)) {
37
+ const found = value.find((e) => e.filter === undefined);
38
+ if (!found)
39
+ return undefined;
40
+ const { filter: _f, ...rest } = found;
41
+ return rest;
42
+ }
43
+ return value;
26
44
  }
27
45
  function updateDependencies(tree, options) {
28
46
  const tasks = [];
@@ -22,25 +22,42 @@ async function default_1(tree) {
22
22
  // update options from nx.json target defaults
23
23
  const nxJson = (0, devkit_1.readNxJson)(tree);
24
24
  if (nxJson.targetDefaults) {
25
- for (const [targetOrExecutor, targetConfig] of Object.entries(nxJson.targetDefaults)) {
26
- if (targetOrExecutor !== EXECUTOR_TO_MIGRATE &&
27
- targetConfig.executor !== EXECUTOR_TO_MIGRATE) {
28
- continue;
29
- }
30
- if (targetConfig.options) {
31
- updateOptions(targetConfig);
32
- }
33
- Object.keys(targetConfig.configurations ?? {}).forEach((config) => {
34
- updateConfiguration(targetConfig, config);
25
+ const targetDefaults = nxJson.targetDefaults;
26
+ for (const key of Object.keys(targetDefaults)) {
27
+ const value = targetDefaults[key];
28
+ const entries = Array.isArray(value)
29
+ ? value
30
+ : [value];
31
+ const usesExecutor = (entry) => key === EXECUTOR_TO_MIGRATE ||
32
+ entry.executor === EXECUTOR_TO_MIGRATE ||
33
+ entry.filter?.executor === EXECUTOR_TO_MIGRATE;
34
+ const kept = entries.filter((entry) => {
35
+ if (usesExecutor(entry)) {
36
+ if (entry.options) {
37
+ updateOptions(entry);
38
+ }
39
+ Object.keys(entry.configurations ?? {}).forEach((config) => {
40
+ updateConfiguration(entry, config);
41
+ });
42
+ }
43
+ // Drop entries left with nothing but their `filter`/`executor` locator.
44
+ return Object.keys(entry).some((k) => k !== 'filter' && k !== 'executor');
35
45
  });
36
- if (!Object.keys(targetConfig).length ||
37
- (Object.keys(targetConfig).length === 1 &&
38
- Object.keys(targetConfig)[0] === 'executor')) {
39
- delete nxJson.targetDefaults[targetOrExecutor];
46
+ if (kept.length === 0) {
47
+ delete targetDefaults[key];
40
48
  }
41
- if (!Object.keys(nxJson.targetDefaults).length) {
42
- delete nxJson.targetDefaults;
49
+ else if (kept.length === 1 && kept[0].filter === undefined) {
50
+ // A lone unfiltered entry is stored as the plain object form (which
51
+ // omits `filter`).
52
+ const { filter: _filter, ...config } = kept[0];
53
+ targetDefaults[key] = config;
43
54
  }
55
+ else {
56
+ targetDefaults[key] = kept;
57
+ }
58
+ }
59
+ if (Object.keys(targetDefaults).length === 0) {
60
+ delete nxJson.targetDefaults;
44
61
  }
45
62
  (0, devkit_1.updateNxJson)(tree, nxJson);
46
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/cypress",
3
- "version": "23.1.0-beta.4",
3
+ "version": "23.1.0-beta.5",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -89,12 +89,12 @@
89
89
  "semver": "^7.6.3",
90
90
  "tree-kill": "^1.2.2",
91
91
  "tslib": "^2.3.0",
92
- "@nx/devkit": "23.1.0-beta.4",
93
- "@nx/eslint": "23.1.0-beta.4",
94
- "@nx/js": "23.1.0-beta.4"
92
+ "@nx/devkit": "23.1.0-beta.5",
93
+ "@nx/eslint": "23.1.0-beta.5",
94
+ "@nx/js": "23.1.0-beta.5"
95
95
  },
96
96
  "devDependencies": {
97
- "nx": "23.1.0-beta.4"
97
+ "nx": "23.1.0-beta.5"
98
98
  },
99
99
  "peerDependencies": {
100
100
  "cypress": ">= 13 < 16"