@nx/workspace 21.3.0-beta.2 → 21.3.0-beta.3

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": "21.3.0-beta.2",
3
+ "version": "21.3.0-beta.3",
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": {
@@ -38,14 +38,14 @@
38
38
  }
39
39
  },
40
40
  "dependencies": {
41
- "@nx/devkit": "21.3.0-beta.2",
41
+ "@nx/devkit": "21.3.0-beta.3",
42
42
  "@zkochan/js-yaml": "0.0.7",
43
43
  "chalk": "^4.1.0",
44
44
  "enquirer": "~2.3.6",
45
45
  "picomatch": "4.0.2",
46
46
  "tslib": "^2.3.0",
47
47
  "yargs-parser": "21.1.1",
48
- "nx": "21.3.0-beta.2"
48
+ "nx": "21.3.0-beta.3"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"
@@ -1,6 +1,11 @@
1
1
  import { Tree } from '@nx/devkit';
2
+ export type Command = {
3
+ command?: string;
4
+ comments?: string[];
5
+ };
2
6
  export interface Schema {
3
7
  name: string;
4
8
  ci: 'github' | 'azure' | 'circleci' | 'bitbucket-pipelines' | 'gitlab';
9
+ useRunMany?: boolean;
5
10
  }
6
11
  export declare function ciWorkflowGenerator(tree: Tree, schema: Schema): Promise<void>;
@@ -6,6 +6,97 @@ const default_base_1 = require("../../utilities/default-base");
6
6
  const path_1 = require("path");
7
7
  const nx_cloud_utils_1 = require("nx/src/utils/nx-cloud-utils");
8
8
  const ts_solution_setup_1 = require("../../utilities/typescript/ts-solution-setup");
9
+ function getCiCommands(ci, packageManagerPrefix, mainBranch, hasTypecheck, hasE2E, useRunMany = false) {
10
+ // Build task list
11
+ const tasks = `lint test build${hasTypecheck ? ' typecheck' : ''}${hasE2E ? ' e2e' : ''}`;
12
+ // Create nx-cloud record example comment with CI-specific prefix
13
+ const baseCommand = `${packageManagerPrefix} nx-cloud record -- echo Hello World`;
14
+ const prefix = getCiPrefix(ci);
15
+ const exampleComment = `${prefix}${baseCommand}`;
16
+ // Build nx-cloud record comments
17
+ const nxCloudComments = [
18
+ `Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud`,
19
+ exampleComment,
20
+ ];
21
+ // Build nx command comments and command
22
+ const commandType = useRunMany ? 'run-many' : 'affected';
23
+ const nxCommandComments = useRunMany
24
+ ? [
25
+ `As your workspace grows, you can change this to use Nx Affected to run only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected`,
26
+ ]
27
+ : [
28
+ `Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected`,
29
+ ];
30
+ if (hasE2E) {
31
+ nxCommandComments.push(`When you enable task distribution, run the e2e-ci task instead of e2e`);
32
+ }
33
+ // Build nx command with CI-specific args
34
+ const args = getCiArgs(ci, mainBranch, useRunMany);
35
+ const nxCommand = `${packageManagerPrefix} nx ${commandType} ${args}-t ${tasks}`;
36
+ return [
37
+ {
38
+ comments: nxCloudComments,
39
+ },
40
+ {
41
+ comments: nxCommandComments,
42
+ command: nxCommand,
43
+ },
44
+ ];
45
+ }
46
+ function getCiPrefix(ci) {
47
+ if (ci === 'github' || ci === 'circleci') {
48
+ return '- run: ';
49
+ }
50
+ else if (ci === 'azure') {
51
+ return '- script: ';
52
+ }
53
+ else if (ci === 'gitlab') {
54
+ return '- ';
55
+ }
56
+ // Bitbucket expects just the command without prefix for pull requests
57
+ return '';
58
+ }
59
+ function getCiArgs(ci, mainBranch, useRunMany = false) {
60
+ // When using run-many, we don't need base/head SHA args
61
+ if (useRunMany) {
62
+ return '';
63
+ }
64
+ if (ci === 'azure') {
65
+ return '--base=$(BASE_SHA) --head=$(HEAD_SHA) ';
66
+ }
67
+ else if (ci === 'bitbucket-pipelines') {
68
+ return `--base=origin/${mainBranch} `;
69
+ }
70
+ return '';
71
+ }
72
+ function getBitbucketBranchCommands(packageManagerPrefix, hasTypecheck, hasE2E, useRunMany = false) {
73
+ const tasks = `lint test build${hasTypecheck ? ' typecheck' : ''}${hasE2E ? ' e2e-ci' : ''}`;
74
+ const nxCloudComments = [
75
+ `Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud`,
76
+ `- ${packageManagerPrefix} nx-cloud record -- echo Hello World`,
77
+ ];
78
+ // Build nx command comments and command
79
+ const commandType = useRunMany ? 'run-many' : 'affected';
80
+ const nxCommandComments = useRunMany
81
+ ? [
82
+ `As your workspace grows, you can change this to use Nx Affected to run only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected`,
83
+ ]
84
+ : [
85
+ `Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected`,
86
+ ];
87
+ // Build command with conditional base arg
88
+ const baseArg = useRunMany ? '' : ' --base=HEAD~1';
89
+ const command = `${packageManagerPrefix} nx ${commandType} -t ${tasks}${baseArg}`;
90
+ return [
91
+ {
92
+ comments: nxCloudComments,
93
+ },
94
+ {
95
+ comments: nxCommandComments,
96
+ command,
97
+ },
98
+ ];
99
+ }
9
100
  async function ciWorkflowGenerator(tree, schema) {
10
101
  const ci = schema.ci;
11
102
  const options = normalizeOptions(schema, tree);
@@ -38,6 +129,11 @@ function normalizeOptions(options, tree) {
38
129
  const hasE2E = hasCypress || hasPlaywright;
39
130
  const hasTypecheck = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
40
131
  const connectedToCloud = (0, nx_cloud_utils_1.isNxCloudUsed)((0, devkit_1.readJson)(tree, 'nx.json'));
132
+ const mainBranch = (0, default_base_1.deduceDefaultBase)();
133
+ const commands = getCiCommands(options.ci, packageManagerPrefix, mainBranch, hasTypecheck, hasE2E, options.useRunMany ?? false);
134
+ const branchCommands = options.ci === 'bitbucket-pipelines'
135
+ ? getBitbucketBranchCommands(packageManagerPrefix, hasTypecheck, hasE2E, options.useRunMany ?? false)
136
+ : undefined;
41
137
  return {
42
138
  workflowName,
43
139
  workflowFileName,
@@ -45,7 +141,7 @@ function normalizeOptions(options, tree) {
45
141
  packageManagerInstall,
46
142
  packageManagerPrefix,
47
143
  packageManagerPreInstallPrefix,
48
- mainBranch: (0, default_base_1.deduceDefaultBase)(),
144
+ mainBranch,
49
145
  packageManagerVersion: packageJson?.packageManager?.split('@')[1],
50
146
  hasCypress,
51
147
  hasE2E,
@@ -54,6 +150,9 @@ function normalizeOptions(options, tree) {
54
150
  nxCloudHost,
55
151
  tmpl: '',
56
152
  connectedToCloud,
153
+ useRunMany: options.useRunMany ?? false,
154
+ commands,
155
+ branchCommands,
57
156
  };
58
157
  }
59
158
  function defaultBranchNeedsOriginPrefix(nxJson) {
@@ -8,13 +8,13 @@ pr:
8
8
  variables:
9
9
  CI: 'true'
10
10
  ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
11
- NX_BRANCH: $(System.PullRequest.PullRequestNumber)
11
+ NX_BRANCH: $(System.PullRequest.PullRequestNumber)<% if(!useRunMany){ %>
12
12
  TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')]
13
- BASE_SHA: $(git merge-base $(TARGET_BRANCH) HEAD)
13
+ BASE_SHA: $(git merge-base $(TARGET_BRANCH) HEAD)<% } %>
14
14
  ${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
15
- NX_BRANCH: $(Build.SourceBranchName)
15
+ NX_BRANCH: $(Build.SourceBranchName)<% if(!useRunMany){ %>
16
16
  BASE_SHA: $(git rev-parse HEAD~1)
17
- HEAD_SHA: $(git rev-parse HEAD)
17
+ HEAD_SHA: $(git rev-parse HEAD)<% } %>
18
18
 
19
19
  jobs:
20
20
  - job: main
@@ -23,7 +23,7 @@ jobs:
23
23
  steps:
24
24
  - checkout: self
25
25
  fetchDepth: 0
26
- fetchFilter: tree:0
26
+ fetchFilter: tree:0<% if(!useRunMany){ %>
27
27
  # Set Azure Devops CLI default settings
28
28
  - bash: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project=$(System.TeamProject)
29
29
  displayName: 'Set default Azure DevOps organization and project'
@@ -40,7 +40,7 @@ jobs:
40
40
  displayName: 'Get last successful commit SHA'
41
41
  condition: ne(variables['Build.Reason'], 'PullRequest')
42
42
  env:
43
- AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
43
+ AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)<% } %>
44
44
 
45
45
  <% if(packageManager == 'pnpm'){ %>
46
46
  - script: npm install --prefix=$HOME/.local -g pnpm@8
@@ -61,12 +61,10 @@ jobs:
61
61
 
62
62
  - script: <%= packageManagerInstall %><% if(hasCypress){ %>
63
63
  - script: <%= packageManagerPrefix %> cypress install<% } %><% if(hasPlaywright){ %>
64
- - script: <%= packageManagerPrefix %> playwright install --with-deps<% } %>
64
+ - script: <%= packageManagerPrefix %> playwright install --with-deps<% } %><% if(!useRunMany){ %>
65
65
  - script: git branch --track <%= mainBranch %> origin/<%= mainBranch %>
66
- condition: eq(variables['Build.Reason'], 'PullRequest')
66
+ condition: eq(variables['Build.Reason'], 'PullRequest')<% } %>
67
67
 
68
- # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
69
- # - script: <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
70
- # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected<% if(hasE2E){ %>
71
- # When you enable task distribution, run the e2e-ci task instead of e2e<% } %>
72
- - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e<% } %>
68
+ <% for (const command of commands) { %><% if (command.comments) { %><% for (const comment of command.comments) { %>
69
+ # <%- comment %><% } %><% } %><% if (command.command) { %>
70
+ - script: <%= command.command %><% } %><% } %>
@@ -29,11 +29,9 @@ pipelines:
29
29
  - <%= packageManagerPrefix %> cypress install<% } %><% if(hasPlaywright){ %>
30
30
  - <%= packageManagerPrefix %> playwright install --with-deps<% } %>
31
31
 
32
- # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
33
- # <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
34
- # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected<% if(hasE2E){ %>
35
- # When you enable task distribution, run the e2e-ci task instead of e2e<% } %>
36
- - <%= packageManagerPrefix %> nx affected --base=origin/<%= mainBranch %> -t lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e<% } %>
32
+ <% for (const command of commands) { %><% if (command.comments) { %><% for (const comment of command.comments) { %>
33
+ # <%- comment %><% } %><% } %><% if (command.command) { %>
34
+ - <%= command.command %><% } %><% } %>
37
35
 
38
36
  branches:
39
37
  main:
@@ -56,7 +54,6 @@ pipelines:
56
54
  <% } %>
57
55
  - <%= packageManagerInstall %>
58
56
 
59
- # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
60
- # - <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
61
- # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
62
- - <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e-ci<% } %> --base=HEAD~1
57
+ <% for (const command of branchCommands) { %><% if (command.comments) { %><% for (const comment of command.comments) { %>
58
+ # <%- comment %><% } %><% } %><% if (command.command) { %>
59
+ - <%= command.command %><% } %><% } %>
@@ -29,15 +29,13 @@ jobs:
29
29
 
30
30
  - run: <%= packageManagerInstall %><% if(hasCypress){ %>
31
31
  - run: <%= packageManagerPrefix %> cypress install<% } %><% if(hasPlaywright){ %>
32
- - run: <%= packageManagerPrefix %> playwright install --with-deps<% } %>
32
+ - run: <%= packageManagerPrefix %> playwright install --with-deps<% } %><% if(!useRunMany){ %>
33
33
  - nx/set-shas:
34
- main-branch-name: '<%= mainBranch %>'
34
+ main-branch-name: '<%= mainBranch %>'<% } %>
35
35
 
36
- # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
37
- # - run: <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
38
- # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected<% if(hasE2E){ %>
39
- # When you enable task distribution, run the e2e-ci task instead of e2e<% } %>
40
- - run: <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e<% } %>
36
+ <% for (const command of commands) { %><% if (command.comments) { %><% for (const comment of command.comments) { %>
37
+ # <%- comment %><% } %><% } %><% if (command.command) { %>
38
+ - run: <%= command.command %><% } %><% } %>
41
39
 
42
40
  workflows:
43
41
  version: 2
@@ -47,11 +47,9 @@ jobs:
47
47
  <% } %>
48
48
  - run: <%= packageManagerInstall %><% if(hasCypress){ %>
49
49
  - run: <%= packageManagerPrefix %> cypress install<% } %><% if(hasPlaywright){ %>
50
- - run: <%= packageManagerPrefix %> playwright install --with-deps<% } %>
51
- - uses: nrwl/nx-set-shas@v4
50
+ - run: <%= packageManagerPrefix %> playwright install --with-deps<% } %><% if(!useRunMany){ %>
51
+ - uses: nrwl/nx-set-shas@v4<% } %>
52
52
 
53
- # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
54
- # - run: <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
55
- # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected<% if(hasE2E){ %>
56
- # When you enable task distribution, run the e2e-ci task instead of e2e<% } %>
57
- - run: <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e<% } %>
53
+ <% for (const command of commands) { %><% if (command.comments) { %><% for (const comment of command.comments) { %>
54
+ # <%- comment %><% } %><% } %><% if (command.command) { %>
55
+ - run: <%= command.command %><% } %><% } %>
@@ -23,12 +23,10 @@ variables:
23
23
 
24
24
  - <%= packageManagerInstall %><% if(hasCypress){ %>
25
25
  - <%= packageManagerPrefix %> cypress install<% } %><% if(hasPlaywright){ %>
26
- - <%= packageManagerPrefix %> playwright install --with-deps<% } %>
26
+ - <%= packageManagerPrefix %> playwright install --with-deps<% } %><% if(!useRunMany){ %>
27
27
  - NX_HEAD=$CI_COMMIT_SHA
28
- - NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA}
28
+ - NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA}<% } %>
29
29
 
30
- # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
31
- # - <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
32
- # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected<% if(hasE2E){ %>
33
- # When you enable task distribution, run the e2e-ci task instead of e2e<% } %>
34
- - <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasTypecheck){ %> typecheck<% } %><% if(hasE2E){ %> e2e<% } %>
30
+ <% for (const command of commands) { %><% if (command.comments) { %><% for (const comment of command.comments) { %>
31
+ # <%- comment %><% } %><% } %><% if (command.command) { %>
32
+ - <%= command.command %><% } %><% } %>
@@ -32,6 +32,12 @@
32
32
  "default": "CI",
33
33
  "x-prompt": "How should we name your workflow?",
34
34
  "pattern": "^[a-zA-Z].*$"
35
+ },
36
+ "useRunMany": {
37
+ "type": "boolean",
38
+ "description": "Use 'nx run-many' instead of 'nx affected' in the generated CI workflow.",
39
+ "default": false,
40
+ "hidden": true
35
41
  }
36
42
  },
37
43
  "required": ["ci", "name"]