@nx/workspace 18.0.0-canary.20240202-ea5befb → 18.0.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/workspace",
3
- "version": "18.0.0-canary.20240202-ea5befb",
3
+ "version": "18.0.0",
4
4
  "private": false,
5
5
  "description": "The Workspace plugin contains executors and generators that are useful for any Nx workspace. It should be present in every Nx workspace and other plugins build on it.",
6
6
  "repository": {
@@ -61,13 +61,13 @@
61
61
  }
62
62
  },
63
63
  "dependencies": {
64
- "@nx/devkit": "18.0.0-canary.20240202-ea5befb",
64
+ "@nx/devkit": "18.0.0",
65
65
  "chalk": "^4.1.0",
66
66
  "enquirer": "~2.3.6",
67
67
  "tslib": "^2.3.0",
68
68
  "yargs-parser": "21.1.1",
69
- "nx": "18.0.0-canary.20240202-ea5befb",
70
- "@nrwl/workspace": "18.0.0-canary.20240202-ea5befb"
69
+ "nx": "18.0.0",
70
+ "@nrwl/workspace": "18.0.0"
71
71
  },
72
72
  "publishConfig": {
73
73
  "access": "public"
@@ -3,4 +3,4 @@ export interface Schema {
3
3
  name: string;
4
4
  ci: 'github' | 'azure' | 'circleci' | 'bitbucket-pipelines' | 'gitlab';
5
5
  }
6
- export declare function ciWorkflowGenerator(host: Tree, schema: Schema): Promise<void>;
6
+ export declare function ciWorkflowGenerator(tree: Tree, schema: Schema): Promise<void>;
@@ -4,26 +4,35 @@ exports.ciWorkflowGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const default_base_1 = require("../../utilities/default-base");
6
6
  const path_1 = require("path");
7
- async function ciWorkflowGenerator(host, schema) {
7
+ const nx_cloud_utils_1 = require("nx/src/utils/nx-cloud-utils");
8
+ async function ciWorkflowGenerator(tree, schema) {
8
9
  const ci = schema.ci;
9
- const options = normalizeOptions(schema);
10
- const nxJson = (0, devkit_1.readJson)(host, 'nx.json');
10
+ const nxJson = (0, devkit_1.readJson)(tree, 'nx.json');
11
11
  const nxCloudUsed = nxJson.nxCloudAccessToken ??
12
12
  Object.values(nxJson.tasksRunnerOptions ?? {}).find((r) => r.runner == '@nrwl/nx-cloud' || r.runner == 'nx-cloud');
13
13
  if (!nxCloudUsed) {
14
14
  throw new Error('This workspace is not connected to Nx Cloud.');
15
15
  }
16
16
  if (ci === 'bitbucket-pipelines' && defaultBranchNeedsOriginPrefix(nxJson)) {
17
- (0, devkit_1.writeJson)(host, 'nx.json', appendOriginPrefix(nxJson));
17
+ (0, devkit_1.writeJson)(tree, 'nx.json', appendOriginPrefix(nxJson));
18
18
  }
19
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, 'files', ci), '', options);
20
- await (0, devkit_1.formatFiles)(host);
19
+ const options = normalizeOptions(schema, tree);
20
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files', ci), '', options);
21
+ await (0, devkit_1.formatFiles)(tree);
21
22
  }
22
23
  exports.ciWorkflowGenerator = ciWorkflowGenerator;
23
- function normalizeOptions(options) {
24
+ function normalizeOptions(options, tree) {
24
25
  const { name: workflowName, fileName: workflowFileName } = (0, devkit_1.names)(options.name);
25
26
  const packageManager = (0, devkit_1.detectPackageManager)();
26
27
  const { exec: packageManagerPrefix, ciInstall: packageManagerInstall } = (0, devkit_1.getPackageManagerCommand)(packageManager);
28
+ const nxCloudUrl = (0, nx_cloud_utils_1.getNxCloudUrl)((0, devkit_1.readJson)(tree, 'nx.json'));
29
+ const nxCloudHost = new URL(nxCloudUrl).host;
30
+ const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
31
+ const allDependencies = {
32
+ ...packageJson.dependencies,
33
+ ...packageJson.devDependencies,
34
+ };
35
+ const hasE2E = allDependencies['@nx/cypress'] || allDependencies['@nx/playwright'];
27
36
  return {
28
37
  workflowName,
29
38
  workflowFileName,
@@ -31,6 +40,8 @@ function normalizeOptions(options) {
31
40
  packageManagerInstall,
32
41
  packageManagerPrefix,
33
42
  mainBranch: (0, default_base_1.deduceDefaultBase)(),
43
+ hasE2E,
44
+ nxCloudHost,
34
45
  tmpl: '',
35
46
  };
36
47
  }
@@ -21,13 +21,14 @@ jobs:
21
21
  pool:
22
22
  vmImage: 'ubuntu-latest'
23
23
  steps:
24
+ # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
25
+ # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested
26
+ # - script: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
27
+
24
28
  <% if(packageManager == 'pnpm'){ %>
25
29
  - script: npm install --prefix=$HOME/.local -g pnpm@8
26
30
  displayName: Install PNPM
27
31
  <% } %>- script: <%= packageManagerInstall %>
28
32
 
29
- # Uncomment to enable task distribution. --stop-agents-after is optional, but allows idle agents to shut down once the "build" targets have been requested
30
- # - script: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build"
31
-
32
33
  - script: <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
33
- - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t=lint,test,build
34
+ - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
@@ -11,13 +11,15 @@ pipelines:
11
11
  name: <%= workflowName %>
12
12
  script:
13
13
  - export NX_BRANCH=$BITBUCKET_PR_ID
14
+
15
+ # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
16
+ # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested
17
+ # - <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
18
+
14
19
  <% if(packageManager == 'pnpm'){ %>
15
20
  - npm install --prefix=$HOME/.local -g pnpm@8
16
21
  <% } %>
17
22
  - <%= packageManagerInstall %>
18
23
 
19
- # Uncomment to enable task distribution. --stop-agents-after is optional, but allows idle agents to shut down once the "build" targets have been requested
20
- # - <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build"
21
-
22
24
  - <%= packageManagerPrefix %> nx-cloud record -- nx format:check
23
- - <%= packageManagerPrefix %> nx affected -t=lint,test,build
25
+ - <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
@@ -9,6 +9,11 @@ jobs:
9
9
  - image: cimg/node:lts-browsers
10
10
  steps:
11
11
  - checkout
12
+
13
+ # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
14
+ # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested
15
+ # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
16
+
12
17
  <% if(packageManager == 'pnpm'){ %>
13
18
  - run:
14
19
  name: Install PNPM
@@ -17,11 +22,8 @@ jobs:
17
22
  - nx/set-shas:
18
23
  main-branch-name: '<%= mainBranch %>'
19
24
 
20
- # Uncomment to enable task distribution. --stop-agents-after is optional, but allows idle agents to shut down once the "build" targets have been requested
21
- # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build"
22
-
23
25
  - run: <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
24
- - run: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD -t=lint,test,build
26
+ - run: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
25
27
 
26
28
  workflows:
27
29
  version: 2
@@ -17,6 +17,11 @@ jobs:
17
17
  - uses: actions/checkout@v4
18
18
  with:
19
19
  fetch-depth: 0
20
+
21
+ # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
22
+ # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested
23
+ # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
24
+
20
25
  <% if(packageManager == 'pnpm'){ %>
21
26
  - uses: pnpm/action-setup@v2
22
27
  with:
@@ -29,8 +34,5 @@ jobs:
29
34
  - run: <%= packageManagerInstall %>
30
35
  - uses: nrwl/nx-set-shas@v4
31
36
 
32
- # Uncomment to enable task distribution. --stop-agents-after is optional, but allows idle agents to shut down once the "build" targets have been requested
33
- # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build"
34
-
35
37
  - run: <%= packageManagerPrefix %> nx-cloud record -- nx format:check
36
- - run: <%= packageManagerPrefix %> nx affected -t=lint,test,build
38
+ - run: <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
@@ -9,6 +9,10 @@ variables:
9
9
  - main
10
10
  - merge_requests
11
11
  script:
12
+ # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
13
+ # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested
14
+ # - <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
15
+
12
16
  <% if(packageManager == 'pnpm'){ %>
13
17
  - npm install --prefix=$HOME/.local -g pnpm@8
14
18
  <% } %>
@@ -16,8 +20,5 @@ variables:
16
20
  - NX_HEAD=$CI_COMMIT_SHA
17
21
  - NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA}
18
22
 
19
- # Uncomment to enable task distribution. --stop-agents-after is optional, but allows idle agents to shut down once the "build" targets have been requested
20
- # - <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build"
21
-
22
23
  - <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
23
- - <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD -t=lint,test,build
24
+ - <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
@@ -48,7 +48,7 @@ function createNxJson(tree, { directory, defaultBase, preset }) {
48
48
  affected: {
49
49
  defaultBase,
50
50
  },
51
- targetDefaults: process.env.NX_PCV3 !== 'true'
51
+ targetDefaults: process.env.NX_ADD_PLUGINS === 'false'
52
52
  ? {
53
53
  build: {
54
54
  cache: true,
@@ -69,7 +69,7 @@ function createNxJson(tree, { directory, defaultBase, preset }) {
69
69
  production: ['default'],
70
70
  sharedGlobals: [],
71
71
  };
72
- if (process.env.NX_PCV3 !== 'true') {
72
+ if (process.env.NX_ADD_PLUGINS === 'false') {
73
73
  nxJson.targetDefaults.build.inputs = ['production', '^production'];
74
74
  }
75
75
  }
@@ -16,6 +16,7 @@ async function presetGenerator(tree, options) {
16
16
  exports.presetGenerator = presetGenerator;
17
17
  exports.default = presetGenerator;
18
18
  async function createPreset(tree, options) {
19
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false';
19
20
  if (options.preset === presets_1.Preset.Apps) {
20
21
  return;
21
22
  }
@@ -32,6 +33,7 @@ async function createPreset(tree, options) {
32
33
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
33
34
  bundler: options.bundler,
34
35
  ssr: options.ssr,
36
+ addPlugin,
35
37
  });
36
38
  }
37
39
  else if (options.preset === presets_1.Preset.AngularStandalone) {
@@ -48,6 +50,7 @@ async function createPreset(tree, options) {
48
50
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
49
51
  bundler: options.bundler,
50
52
  ssr: options.ssr,
53
+ addPlugin,
51
54
  });
52
55
  }
53
56
  else if (options.preset === presets_1.Preset.ReactMonorepo) {
@@ -61,6 +64,7 @@ async function createPreset(tree, options) {
61
64
  linter: options.linter,
62
65
  bundler: options.bundler ?? 'webpack',
63
66
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
67
+ addPlugin,
64
68
  });
65
69
  }
66
70
  else if (options.preset === presets_1.Preset.ReactStandalone) {
@@ -76,6 +80,7 @@ async function createPreset(tree, options) {
76
80
  bundler: options.bundler ?? 'vite',
77
81
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
78
82
  unitTestRunner: options.bundler === 'vite' ? 'vitest' : 'jest',
83
+ addPlugin,
79
84
  });
80
85
  }
81
86
  else if (options.preset === presets_1.Preset.VueMonorepo) {
@@ -88,6 +93,7 @@ async function createPreset(tree, options) {
88
93
  style: options.style,
89
94
  linter: options.linter,
90
95
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
96
+ addPlugin,
91
97
  });
92
98
  }
93
99
  else if (options.preset === presets_1.Preset.VueStandalone) {
@@ -102,6 +108,7 @@ async function createPreset(tree, options) {
102
108
  rootProject: true,
103
109
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
104
110
  unitTestRunner: 'vitest',
111
+ addPlugin,
105
112
  });
106
113
  }
107
114
  else if (options.preset === presets_1.Preset.Nuxt) {
@@ -114,6 +121,7 @@ async function createPreset(tree, options) {
114
121
  style: options.style,
115
122
  linter: options.linter,
116
123
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
124
+ addPlugin,
117
125
  });
118
126
  }
119
127
  else if (options.preset === presets_1.Preset.NuxtStandalone) {
@@ -128,6 +136,7 @@ async function createPreset(tree, options) {
128
136
  rootProject: true,
129
137
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
130
138
  unitTestRunner: 'vitest',
139
+ addPlugin,
131
140
  });
132
141
  }
133
142
  else if (options.preset === presets_1.Preset.NextJs) {
@@ -142,6 +151,7 @@ async function createPreset(tree, options) {
142
151
  appDir: options.nextAppDir,
143
152
  src: options.nextSrcDir,
144
153
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
154
+ addPlugin,
145
155
  });
146
156
  }
147
157
  else if (options.preset === presets_1.Preset.NextJsStandalone) {
@@ -157,6 +167,7 @@ async function createPreset(tree, options) {
157
167
  src: options.nextSrcDir,
158
168
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
159
169
  rootProject: true,
170
+ addPlugin,
160
171
  });
161
172
  }
162
173
  else if (options.preset === presets_1.Preset.WebComponents) {
@@ -170,6 +181,7 @@ async function createPreset(tree, options) {
170
181
  linter: options.linter,
171
182
  bundler: 'vite',
172
183
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
184
+ addPlugin,
173
185
  });
174
186
  }
175
187
  else if (options.preset === presets_1.Preset.Nest) {
@@ -181,6 +193,7 @@ async function createPreset(tree, options) {
181
193
  projectNameAndRootFormat: 'as-provided',
182
194
  linter: options.linter,
183
195
  e2eTestRunner: options.e2eTestRunner ?? 'jest',
196
+ addPlugin,
184
197
  });
185
198
  }
186
199
  else if (options.preset === presets_1.Preset.Express) {
@@ -191,6 +204,7 @@ async function createPreset(tree, options) {
191
204
  projectNameAndRootFormat: 'as-provided',
192
205
  linter: options.linter,
193
206
  e2eTestRunner: options.e2eTestRunner ?? 'jest',
207
+ addPlugin,
194
208
  });
195
209
  }
196
210
  else if (options.preset === presets_1.Preset.ReactNative) {
@@ -202,6 +216,7 @@ async function createPreset(tree, options) {
202
216
  projectNameAndRootFormat: 'as-provided',
203
217
  linter: options.linter,
204
218
  e2eTestRunner: options.e2eTestRunner ?? 'detox',
219
+ addPlugin,
205
220
  });
206
221
  }
207
222
  else if (options.preset === presets_1.Preset.Expo) {
@@ -212,6 +227,7 @@ async function createPreset(tree, options) {
212
227
  projectNameAndRootFormat: 'as-provided',
213
228
  linter: options.linter,
214
229
  e2eTestRunner: options.e2eTestRunner ?? 'detox',
230
+ addPlugin,
215
231
  });
216
232
  }
217
233
  else if (options.preset === presets_1.Preset.TS) {
@@ -229,6 +245,7 @@ async function createPreset(tree, options) {
229
245
  testEnvironment: 'node',
230
246
  js: options.js,
231
247
  rootProject: true,
248
+ addPlugin,
232
249
  });
233
250
  }
234
251
  else if (options.preset === presets_1.Preset.NodeStandalone) {
@@ -246,6 +263,7 @@ async function createPreset(tree, options) {
246
263
  docker: options.docker,
247
264
  rootProject: true,
248
265
  e2eTestRunner: options.e2eTestRunner ?? 'jest',
266
+ addPlugin,
249
267
  });
250
268
  }
251
269
  else if (options.preset === presets_1.Preset.NodeMonorepo) {
@@ -262,6 +280,7 @@ async function createPreset(tree, options) {
262
280
  docker: options.docker,
263
281
  rootProject: false,
264
282
  e2eTestRunner: options.e2eTestRunner ?? 'jest',
283
+ addPlugin,
265
284
  });
266
285
  }
267
286
  else {