@nx/workspace 17.0.4 → 17.0.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.
Files changed (47) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -9
  3. package/migrations.json +0 -37
  4. package/package.json +4 -4
  5. package/src/generators/ci-workflow/ci-workflow.d.ts +1 -1
  6. package/src/generators/ci-workflow/ci-workflow.js +18 -30
  7. package/src/generators/ci-workflow/files/azure/azure-pipelines.yml__tmpl__ +33 -31
  8. package/src/generators/ci-workflow/files/bitbucket-pipelines/bitbucket-pipelines.yml__tmpl__ +29 -34
  9. package/src/generators/ci-workflow/files/circleci/.circleci/config.yml__tmpl__ +53 -17
  10. package/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml__tmpl__ +19 -26
  11. package/src/generators/ci-workflow/files/gitlab/.gitlab-ci.yml__tmpl__ +35 -12
  12. package/src/generators/ci-workflow/schema.json +1 -1
  13. package/src/generators/convert-to-monorepo/convert-to-monorepo.js +2 -6
  14. package/src/generators/convert-to-monorepo/schema.json +1 -1
  15. package/src/generators/convert-to-nx-project/schema.json +1 -1
  16. package/src/generators/move/lib/create-project-configuration-in-new-destination.js +2 -7
  17. package/src/generators/move/lib/extract-base-configs.d.ts +1 -1
  18. package/src/generators/move/lib/extract-base-configs.js +10 -4
  19. package/src/generators/move/lib/move-project-files.js +4 -4
  20. package/src/generators/move/lib/normalize-schema.d.ts +1 -1
  21. package/src/generators/move/lib/normalize-schema.js +79 -86
  22. package/src/generators/move/lib/update-imports.js +1 -1
  23. package/src/generators/move/lib/update-jest-config.js +3 -5
  24. package/src/generators/move/lib/update-project-root-files.js +2 -2
  25. package/src/generators/move/move.js +1 -4
  26. package/src/generators/move/schema.json +1 -1
  27. package/src/generators/new/files-readme/README.md.template +23 -49
  28. package/src/generators/new/files-root-app/package.json__tmpl__ +0 -3
  29. package/src/generators/new/generate-preset.js +0 -16
  30. package/src/generators/new/generate-workspace-files.js +23 -36
  31. package/src/generators/new/new.d.ts +0 -3
  32. package/src/generators/new/new.js +7 -9
  33. package/src/generators/new/schema.json +1 -15
  34. package/src/generators/npm-package/schema.json +1 -1
  35. package/src/generators/preset/preset.js +0 -84
  36. package/src/generators/preset/schema.d.ts +0 -3
  37. package/src/generators/preset/schema.json +3 -17
  38. package/src/generators/remove/lib/update-jest-config.js +6 -18
  39. package/src/generators/remove/schema.json +1 -1
  40. package/src/generators/run-commands/schema.json +1 -1
  41. package/src/generators/utils/presets.d.ts +0 -4
  42. package/src/generators/utils/presets.js +1 -5
  43. package/src/utils/output.js +1 -1
  44. package/src/utils/versions.d.ts +2 -2
  45. package/src/utils/versions.js +2 -2
  46. package/src/generators/utils/jest-config.d.ts +0 -2
  47. package/src/generators/utils/jest-config.js +0 -13
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2024 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2023 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -1,9 +1,4 @@
1
- <p style="text-align: center;">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
4
- <img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
5
- </picture>
6
- </p>
1
+ <p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
7
2
 
8
3
  <div style="text-align: center;">
9
4
 
@@ -20,9 +15,9 @@
20
15
 
21
16
  <hr>
22
17
 
23
- # Nx: Smart Monorepos · Fast CI
18
+ # Nx: Smart, Fast and Extensible Build System
24
19
 
25
- Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
20
+ Nx is a next generation build system with first class monorepo support and powerful integrations.
26
21
 
27
22
  ## Getting Started
28
23
 
@@ -62,5 +57,5 @@ npx nx@latest init
62
57
  - [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
63
58
 
64
59
  <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
65
- width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
60
+ width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
66
61
 
package/migrations.json CHANGED
@@ -61,43 +61,6 @@
61
61
  "version": "~5.1.3"
62
62
  }
63
63
  }
64
- },
65
- "17.1.0": {
66
- "version": "17.1.0-beta.4",
67
- "x-prompt": "Do you want to update to TypeScript v5.2?",
68
- "requires": {
69
- "typescript": ">=5.1.0 <5.2.0"
70
- },
71
- "packages": {
72
- "typescript": {
73
- "version": "~5.2.2"
74
- }
75
- }
76
- },
77
- "17.3.0": {
78
- "version": "17.3.0-beta.10",
79
- "x-prompt": "Do you want to update to TypeScript v5.3?",
80
- "requires": {
81
- "typescript": ">=5.2.0 <5.3.0"
82
- },
83
- "packages": {
84
- "typescript": {
85
- "version": "~5.3.2"
86
- }
87
- }
88
- },
89
- "18.2.0": {
90
- "version": "18.2.0-beta.0",
91
- "x-prompt": "Do you want to update to TypeScript v5.4?",
92
- "requires": {
93
- "typescript": ">=5.3.0 <5.4.0"
94
- },
95
- "packages": {
96
- "typescript": {
97
- "version": "~5.4.2",
98
- "alwaysAddToPackageJson": false
99
- }
100
- }
101
64
  }
102
65
  }
103
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/workspace",
3
- "version": "17.0.4",
3
+ "version": "v17.0.6",
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": "17.0.4",
64
+ "@nx/devkit": "v17.0.6",
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": "17.0.4",
70
- "@nrwl/workspace": "17.0.4"
69
+ "nx": "v17.0.6",
70
+ "@nrwl/workspace": "v17.0.6"
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(tree: Tree, schema: Schema): Promise<void>;
6
+ export declare function ciWorkflowGenerator(host: Tree, schema: Schema): Promise<void>;
@@ -4,57 +4,45 @@ 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
- const nx_cloud_utils_1 = require("nx/src/utils/nx-cloud-utils");
8
- async function ciWorkflowGenerator(tree, schema) {
7
+ async function ciWorkflowGenerator(host, schema) {
9
8
  const ci = schema.ci;
10
- const nxJson = (0, devkit_1.readJson)(tree, 'nx.json');
9
+ const options = normalizeOptions(schema);
10
+ const nxJson = (0, devkit_1.readJson)(host, '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)(tree, 'nx.json', appendOriginPrefix(nxJson));
17
+ (0, devkit_1.writeJson)(host, 'nx.json', appendOriginPrefix(nxJson));
18
18
  }
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);
19
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, 'files', ci), '', options);
20
+ await (0, devkit_1.formatFiles)(host);
22
21
  }
23
22
  exports.ciWorkflowGenerator = ciWorkflowGenerator;
24
- function normalizeOptions(options, tree) {
23
+ function normalizeOptions(options) {
25
24
  const { name: workflowName, fileName: workflowFileName } = (0, devkit_1.names)(options.name);
26
- const packageManager = (0, devkit_1.detectPackageManager)();
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'];
25
+ const { exec: packageManagerPrefix, ciInstall: packageManagerInstall } = (0, devkit_1.getPackageManagerCommand)();
36
26
  return {
37
27
  workflowName,
38
28
  workflowFileName,
39
- packageManager,
40
29
  packageManagerInstall,
41
30
  packageManagerPrefix,
42
31
  mainBranch: (0, default_base_1.deduceDefaultBase)(),
43
- hasE2E,
44
- nxCloudHost,
45
32
  tmpl: '',
46
33
  };
47
34
  }
48
35
  function defaultBranchNeedsOriginPrefix(nxJson) {
49
- const base = nxJson.defaultBase ?? nxJson.affected?.defaultBase;
50
- return !base?.startsWith('origin/');
36
+ return !nxJson.affected?.defaultBase?.startsWith('origin/');
51
37
  }
52
38
  function appendOriginPrefix(nxJson) {
53
- if (nxJson?.affected?.defaultBase) {
54
- nxJson.affected.defaultBase = `origin/${nxJson.affected.defaultBase}`;
55
- }
56
- if (nxJson.defaultBase || !nxJson.affected) {
57
- nxJson.defaultBase = `origin/${nxJson.defaultBase ?? (0, default_base_1.deduceDefaultBase)()}`;
58
- }
59
- return nxJson;
39
+ return {
40
+ ...nxJson,
41
+ affected: {
42
+ ...(nxJson.affected ?? {}),
43
+ defaultBase: nxJson.affected?.defaultBase
44
+ ? `origin/${nxJson.affected.defaultBase}`
45
+ : 'origin/main',
46
+ },
47
+ };
60
48
  }
@@ -7,6 +7,7 @@ pr:
7
7
 
8
8
  variables:
9
9
  CI: 'true'
10
+ NX_CLOUD_DISTRIBUTED_EXECUTION: 'true'
10
11
  ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
11
12
  NX_BRANCH: $(System.PullRequest.PullRequestNumber)
12
13
  TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')]
@@ -17,40 +18,41 @@ variables:
17
18
  HEAD_SHA: $(git rev-parse HEAD)
18
19
 
19
20
  jobs:
20
- - job: main
21
+ - job: agents
22
+ strategy:
23
+ parallel: 3
24
+ displayName: Nx Cloud Agent
21
25
  pool:
22
26
  vmImage: 'ubuntu-latest'
23
27
  steps:
24
- - checkout: self
25
- fetchDepth: 0
26
- # Set Azure Devops CLI default settings
27
- - bash: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project=$(System.TeamProject)
28
- displayName: 'Set default Azure DevOps organization and project'
29
- # Get last successfull commit from Azure Devops CLI
30
- - displayName: 'Get last successful commit SHA'
31
- condition: ne(variables['Build.Reason'], 'PullRequest')
32
- env:
33
- AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
34
- bash: |
35
- LAST_SHA=$(az pipelines build list --branch $(Build.SourceBranchName) --definition-ids $(System.DefinitionId) --result succeeded --top 1 --query "[0].triggerInfo.\"ci.sourceSha\"")
36
- if [ -z "$LAST_SHA" ]
37
- then
38
- echo "Last successful commit not found. Using fallback 'HEAD~1': $BASE_SHA"
39
- else
40
- echo "Last successful commit SHA: $LAST_SHA"
41
- echo "##vso[task.setvariable variable=BASE_SHA]$LAST_SHA"
42
- fi
43
-
44
- # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
45
- # 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
46
- # - script: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
47
-
48
- <% if(packageManager == 'pnpm'){ %>
49
- - script: npm install --prefix=$HOME/.local -g pnpm@8
28
+ <% if(packageManagerPrefix == 'pnpm exec'){ %>
29
+ - script: npm install --prefix=$HOME/.local -g pnpm@8.2.0
50
30
  displayName: Install PNPM
51
31
  <% } %>- script: <%= packageManagerInstall %>
52
- - script: git branch --track main origin/main
53
- condition: eq(variables['Build.Reason'], 'PullRequest')
32
+ displayName: NPM Install Dependencies
33
+ - script: npx nx-cloud start-agent
34
+ displayName: Start Nx-Cloud agent
54
35
 
55
- - script: <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
56
- - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
36
+ - job: main
37
+ displayName: Nx Cloud Main
38
+ pool:
39
+ vmImage: 'ubuntu-latest'
40
+ steps:
41
+ <% if(packageManagerPrefix == 'pnpm exec'){ %>
42
+ - script: npm install --prefix=$HOME/.local -g pnpm@8.2.0
43
+ displayName: Install PNPM
44
+ <% } %>- script: <%= packageManagerInstall %>
45
+ displayName: NPM Install Dependencies
46
+ - script: <%= packageManagerPrefix %> nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3
47
+ displayName: Start CI run
48
+ - script: <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
49
+ displayName: Check format
50
+ - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=lint --parallel=3
51
+ displayName: Run lint
52
+ - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=test --parallel=3 --ci --code-coverage
53
+ displayName: Run test
54
+ - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=build --parallel=3
55
+ displayName: Run build
56
+ - script: <%= packageManagerPrefix %> nx-cloud stop-all-agents
57
+ condition: always()
58
+ displayName: Stop all Nx-Cloud agents
@@ -1,41 +1,36 @@
1
- image: node:20
1
+ image: node:16.18
2
2
 
3
3
  clone:
4
4
  depth: full
5
5
 
6
+ definitions:
7
+ steps:
8
+ - step: &agent
9
+ name: Agent
10
+ script:
11
+ - export NX_BRANCH=$BITBUCKET_PR_ID
12
+ <% if(packageManagerPrefix == 'pnpm exec'){ %>
13
+ - npm install --prefix=$HOME/.local -g pnpm@8.2.0
14
+ <% } %>
15
+ - <%= packageManagerInstall %>
16
+ - <%= packageManagerPrefix %> nx-cloud start-agent
17
+
6
18
  pipelines:
7
19
  pull-requests:
8
20
  '**':
9
- - step:
10
- name: 'Build and test affected apps on Pull Requests'
11
- script:
12
- - export NX_BRANCH=$BITBUCKET_PR_ID
13
-
14
- # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
15
- # 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
16
- # - <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
17
-
18
- <% if(packageManager == 'pnpm'){ %>
19
- - npm install --prefix=$HOME/.local -g pnpm@8
20
- <% } %>
21
- - <%= packageManagerInstall %>
22
-
23
- - <%= packageManagerPrefix %> nx-cloud record -- nx format:check
24
- - <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e-ci<% } %> --base=origin/<%= mainBranch %>
25
-
26
- branches:
27
- main:
28
- - step:
29
- name: 'Build and test affected apps on "<%= mainBranch %>" branch changes'
30
- script:
31
- # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
32
- # 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
33
- # - <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
34
-
35
- <% if(packageManager == 'pnpm'){ %>
36
- - npm install --prefix=$HOME/.local -g pnpm@8
37
- <% } %>
38
- - <%= packageManagerInstall %>
39
-
40
- - <%= packageManagerPrefix %> nx-cloud record -- nx format:check
41
- - <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e-ci<% } %> --base=HEAD~1
21
+ - parallel:
22
+ - step:
23
+ name: <%= workflowName %>
24
+ script:
25
+ - export NX_BRANCH=$BITBUCKET_PR_ID
26
+ <% if(packageManagerPrefix == 'pnpm exec'){ %>
27
+ - npm install --prefix=$HOME/.local -g pnpm@8.2.0
28
+ <% } %>
29
+ - <%= packageManagerInstall %>
30
+ - <%= packageManagerPrefix %> nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3
31
+ - <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check
32
+ - <%= packageManagerPrefix %> nx affected --target=lint & <%= packageManagerPrefix %> nx affected --target=test & <%= packageManagerPrefix %> nx affected --target=build
33
+ - <%= packageManagerPrefix %> nx-cloud stop-all-agents
34
+ - step: *agent
35
+ - step: *agent
36
+ - step: *agent
@@ -1,37 +1,73 @@
1
1
  version: 2.1
2
2
 
3
3
  orbs:
4
- nx: nrwl/nx@1.6.2
4
+ nx: nrwl/nx@1.6.1
5
5
 
6
6
  jobs:
7
+ agent:
8
+ docker:
9
+ - image: cimg/node:lts-browsers
10
+ parameters:
11
+ ordinal:
12
+ type: integer
13
+ steps:
14
+ - checkout
15
+ <% if(packageManagerPrefix == 'pnpm exec'){ %>
16
+ - run:
17
+ name: Install PNPM
18
+ command: npm install --prefix=$HOME/.local -g pnpm@8.2.0
19
+ <% } %>- run:
20
+ name: Install dependencies
21
+ command: <%= packageManagerInstall %>
22
+ - run:
23
+ name: Start the agent << parameters.ordinal >>
24
+ command: <%= packageManagerPrefix %> nx-cloud start-agent
25
+ no_output_timeout: 60m
7
26
  main:
8
27
  docker:
9
28
  - image: cimg/node:lts-browsers
29
+ environment:
30
+ NX_CLOUD_DISTRIBUTED_EXECUTION: 'true'
10
31
  steps:
11
32
  - 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
-
17
- <% if(packageManager == 'pnpm'){ %>
33
+ <% if(packageManagerPrefix == 'pnpm exec'){ %>
18
34
  - run:
19
35
  name: Install PNPM
20
- command: npm install --prefix=$HOME/.local -g pnpm@8
21
- <% } %>- run: <%= packageManagerInstall %>
36
+ command: npm install --prefix=$HOME/.local -g pnpm@8.2.0
37
+ <% } %>- run:
38
+ name: Install dependencies
39
+ command: <%= packageManagerInstall %>
22
40
  - nx/set-shas:
23
41
  main-branch-name: '<%= mainBranch %>'
24
-
25
- # Required for nx affected if we're on a branch
26
- - run: git branch --track main origin/main
27
- condition: eq(variables['Build.Reason'], 'PullRequest')
28
-
29
- - run: <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
30
- - run: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
42
+ - run:
43
+ name: Initialize the Nx Cloud distributed CI run
44
+ command: <%= packageManagerPrefix %> nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3
45
+ - run:
46
+ name: Check format
47
+ command: <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check --base=$NX_BASE --head=$NX_HEAD
48
+ - run:
49
+ name: Run lint
50
+ command: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3
51
+ - run:
52
+ name: Run test
53
+ command: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage
54
+ - run:
55
+ name: Run build
56
+ command: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3
57
+ - run:
58
+ name: Stop all agents
59
+ command: <%= packageManagerPrefix %> nx-cloud stop-all-agents
60
+ when: always
31
61
 
32
62
  workflows:
33
63
  version: 2
34
64
 
35
65
  <%= workflowFileName %>:
36
66
  jobs:
37
- - main
67
+ - agent:
68
+ name: Nx Cloud Agent << matrix.ordinal >>
69
+ matrix:
70
+ parameters:
71
+ ordinal: [1, 2, 3]
72
+ - main:
73
+ name: Nx Cloud Main
@@ -6,36 +6,29 @@ on:
6
6
  - <%= mainBranch %>
7
7
  pull_request:
8
8
 
9
+ # Needed for nx-set-shas within nx-cloud-main.yml, when run on the <%= mainBranch %> branch
9
10
  permissions:
10
11
  actions: read
11
12
  contents: read
12
13
 
13
14
  jobs:
14
15
  main:
15
- runs-on: ubuntu-latest
16
- steps:
17
- - uses: actions/checkout@v4
18
- with:
19
- fetch-depth: 0
16
+ name: Nx Cloud - Main Job
17
+ uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.13.1
18
+ with:
19
+ main-branch-name: <%= mainBranch %>
20
+ number-of-agents: 3
21
+ init-commands: |
22
+ <%= packageManagerPrefix %> nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3
23
+ parallel-commands: |
24
+ <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check
25
+ parallel-commands-on-agents: |
26
+ <%= packageManagerPrefix %> nx affected --target=lint --parallel=3
27
+ <%= packageManagerPrefix %> nx affected --target=test --parallel=3 --ci --code-coverage
28
+ <%= packageManagerPrefix %> nx affected --target=build --parallel=3
20
29
 
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
-
25
- <% if(packageManager == 'pnpm'){ %>
26
- - uses: pnpm/action-setup@v2
27
- with:
28
- version: 8
29
- <% } %># Cache node_modules
30
- - uses: actions/setup-node@v3
31
- with:
32
- node-version: 20
33
- cache: '<%= packageManager %>'
34
- - run: <%= packageManagerInstall %>
35
- - uses: nrwl/nx-set-shas@v4
36
-
37
- - run: git branch --track main origin/main
38
- if: ${{ github.event_name == 'pull_request' }}
39
-
40
- - run: <%= packageManagerPrefix %> nx-cloud record -- nx format:check
41
- - run: <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
30
+ agents:
31
+ name: Nx Cloud - Agents
32
+ uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.13.1
33
+ with:
34
+ number-of-agents: 3
@@ -1,24 +1,47 @@
1
- image: node:20
1
+ image: node:18
2
2
  variables:
3
3
  CI: 'true'
4
4
 
5
- # Main job
6
- <%= workflowName %>:
5
+ # Creating template for DTE agents
6
+ .dte-agent:
7
+ interruptible: true
8
+ script:
9
+ <% if(packageManagerPrefix == 'pnpm exec'){ %>
10
+ - npm install --prefix=$HOME/.local -g pnpm@8.2.0
11
+ <% } %>
12
+ - <%= packageManagerInstall %>
13
+ - <%= packageManagerPrefix %> nx-cloud start-agent
14
+
15
+ # Creating template for a job running DTE (orchestrator)
16
+ .base-pipeline:
7
17
  interruptible: true
8
18
  only:
9
19
  - main
10
20
  - merge_requests
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
-
16
- <% if(packageManager == 'pnpm'){ %>
17
- - npm install --prefix=$HOME/.local -g pnpm@8
21
+ before_script:
22
+ <% if(packageManagerPrefix == 'pnpm exec'){ %>
23
+ - npm install --prefix=$HOME/.local -g pnpm@8.2.0
18
24
  <% } %>
19
25
  - <%= packageManagerInstall %>
20
26
  - NX_HEAD=$CI_COMMIT_SHA
21
27
  - NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA}
22
28
 
23
- - <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
24
- - <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
29
+ # Main job running DTE
30
+ <%= workflowName %>:
31
+ stage: affected
32
+ extends: .base-pipeline
33
+ script:
34
+ - <%= packageManagerPrefix %> nx-cloud start-ci-run --stop-agents-after="build"
35
+ - <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check --base=$NX_BASE --head=$NX_HEAD
36
+ - <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3 & <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage & <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=e2e --parallel=3 --ci --code-coverage & <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3
37
+
38
+ # Create as many agents as you want
39
+ nx-dte-agent1:
40
+ extends: .dte-agent
41
+ stage: affected
42
+ nx-dte-agent2:
43
+ extends: .dte-agent
44
+ stage: affected
45
+ nx-dte-agent3:
46
+ extends: .dte-agent
47
+ stage: affected
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "$id": "NxWorkspaceCIWorkflow",
4
4
  "title": "Generate a CI workflow.",
5
5
  "description": "Generate a CI workflow.",
@@ -11,14 +11,10 @@ async function monorepoGenerator(tree, options) {
11
11
  const projectsToMove = [];
12
12
  // Need to determine libs vs packages directory base on the type of root project.
13
13
  for (const [, project] of projects) {
14
- if (project.root === '.') {
14
+ if (project.root === '.')
15
15
  rootProject = project;
16
- }
17
- else {
18
- projectsToMove.push(project);
19
- }
16
+ projectsToMove.unshift(project); // move the root project 1st
20
17
  }
21
- projectsToMove.unshift(rootProject); // move the root project 1st
22
18
  // Currently, Nx only handles apps+libs or packages. You cannot mix and match them.
23
19
  // If the standalone project is an app (React, Angular, etc), then use apps+libs.
24
20
  // Otherwise, for TS standalone (lib), use packages.
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "$id": "NxWorkspaceConvertToMonorepo",
4
4
  "cli": "nx",
5
5
  "title": "Nx Convert to Monorepo",
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "$id": "SchematicsConvertToNxProject",
4
4
  "title": "@nx/workspace:fix-configuration",
5
5
  "description": "Migrates v1 config to v2 standalone configuration.",
@@ -5,7 +5,7 @@ const devkit_1 = require("@nx/devkit");
5
5
  function createProjectConfigurationInNewDestination(tree, schema, projectConfig) {
6
6
  projectConfig.name = schema.newProjectName;
7
7
  const isRootProject = projectConfig.root === '.';
8
- // Subtle bug if project name === path, where the updated name was being overridden.
8
+ // Subtle bug if project name === path, where the updated name was being overrideen.
9
9
  const { name, ...rest } = projectConfig;
10
10
  // replace old root path with new one
11
11
  let newProjectString = JSON.stringify(rest);
@@ -17,12 +17,7 @@ function createProjectConfigurationInNewDestination(tree, schema, projectConfig)
17
17
  newProjectString = newProjectString.replace(/"(\.\/)?src\/(.*?)"/g, `"${schema.relativeToRootDestination}/src/$2"`);
18
18
  }
19
19
  else {
20
- // There's another issue if project name === path, where the target
21
- // string (my-app:build:production) was being replaced
22
- // and resulting in my-destination/my-new-name:build:production
23
- // Change anything but target strings (my-app:build:production).
24
- // Target string are going to be updated in the updateBuildTargets function
25
- newProjectString = newProjectString.replace(new RegExp(projectConfig.root + '(?!:)', 'g'), schema.relativeToRootDestination);
20
+ newProjectString = newProjectString.replace(new RegExp(projectConfig.root, 'g'), schema.relativeToRootDestination);
26
21
  }
27
22
  const newProject = {
28
23
  name,
@@ -1,4 +1,4 @@
1
1
  import { ProjectConfiguration, Tree } from '@nx/devkit';
2
2
  export declare function maybeExtractTsConfigBase(tree: Tree): void;
3
3
  export declare function maybeExtractJestConfigBase(tree: Tree): Promise<void>;
4
- export declare function maybeMigrateEslintConfigIfRootProject(tree: Tree, rootProject: ProjectConfiguration): void;
4
+ export declare function maybeExtractEslintConfigIfRootProject(tree: Tree, rootProject: ProjectConfiguration): void;