nx 19.8.0-canary.20240917-5b34ea5 → 19.8.0-canary.20240919-7f4a877

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. package/bin/nx-cloud.js +0 -0
  2. package/package.json +17 -17
  3. package/schemas/nx-schema.json +2 -2
  4. package/src/command-line/activate-powerpack/activate-powerpack.d.ts +2 -0
  5. package/src/command-line/activate-powerpack/activate-powerpack.js +32 -0
  6. package/src/command-line/activate-powerpack/command-object.d.ts +6 -0
  7. package/src/command-line/activate-powerpack/command-object.js +26 -0
  8. package/src/command-line/add/command-object.d.ts +1 -1
  9. package/src/command-line/format/format.js +24 -7
  10. package/src/command-line/import/import.js +9 -4
  11. package/src/command-line/import/utils/prepare-source-repo.js +7 -35
  12. package/src/command-line/init/init-v2.d.ts +1 -1
  13. package/src/command-line/init/init-v2.js +10 -4
  14. package/src/command-line/list/list.js +2 -0
  15. package/src/command-line/nx-commands.d.ts +1 -1
  16. package/src/command-line/nx-commands.js +77 -57
  17. package/src/command-line/release/command-object.d.ts +2 -2
  18. package/src/command-line/release/config/config.js +8 -2
  19. package/src/command-line/release/utils/git.d.ts +2 -2
  20. package/src/command-line/release/utils/git.js +12 -2
  21. package/src/command-line/release/utils/shared.d.ts +1 -1
  22. package/src/command-line/release/version.js +4 -0
  23. package/src/command-line/report/report.d.ts +3 -0
  24. package/src/command-line/report/report.js +27 -1
  25. package/src/config/nx-json.d.ts +13 -5
  26. package/src/core/graph/main.js +1 -1
  27. package/src/native/index.d.ts +2 -1
  28. package/src/native/nx.wasm32-wasi.wasm +0 -0
  29. package/src/tasks-runner/cache.d.ts +5 -1
  30. package/src/tasks-runner/cache.js +51 -5
  31. package/src/tasks-runner/init-tasks-runner.d.ts +1 -1
  32. package/src/tasks-runner/init-tasks-runner.js +5 -3
  33. package/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.d.ts +0 -2
  34. package/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.js +0 -5
  35. package/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.d.ts +2 -6
  36. package/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts +2 -6
  37. package/src/tasks-runner/life-cycles/store-run-information-life-cycle.d.ts +2 -7
  38. package/src/tasks-runner/life-cycles/task-profiling-life-cycle.d.ts +2 -7
  39. package/src/tasks-runner/life-cycles/task-results-life-cycle.d.ts +6 -0
  40. package/src/tasks-runner/life-cycles/task-results-life-cycle.js +17 -0
  41. package/src/tasks-runner/life-cycles/task-timings-life-cycle.d.ts +2 -7
  42. package/src/tasks-runner/run-command.d.ts +12 -2
  43. package/src/tasks-runner/run-command.js +52 -59
  44. package/src/tasks-runner/task-orchestrator.d.ts +0 -1
  45. package/src/tasks-runner/task-orchestrator.js +5 -7
  46. package/src/utils/db-connection.d.ts +4 -1
  47. package/src/utils/db-connection.js +15 -4
  48. package/src/utils/git-utils.d.ts +4 -2
  49. package/src/utils/git-utils.index-filter.d.ts +0 -0
  50. package/src/utils/git-utils.index-filter.js +20 -0
  51. package/src/utils/git-utils.js +48 -13
  52. package/src/utils/git-utils.tree-filter.d.ts +11 -0
  53. package/src/utils/git-utils.tree-filter.js +43 -0
  54. package/src/utils/plugins/output.d.ts +1 -0
  55. package/src/utils/plugins/output.js +7 -0
  56. package/src/utils/powerpack.d.ts +5 -0
  57. package/src/utils/powerpack.js +38 -0
@@ -0,0 +1,20 @@
1
+ /**
2
+ * This is meant to be used with `git filter-branch --index-filter` to rewrite
3
+ * history such that only commits related to the subdirectory is kept.
4
+ *
5
+ * Example:
6
+ * NX_IMPORT_SOURCE=<source> git filter-branch --index-filter 'node git-utils.index-filter.js' --prune-empty -- --all
7
+ */
8
+ try {
9
+ const { execSync } = require('child_process');
10
+ // NOTE: Using env vars because Windows PowerShell has its own handling of quotes (") messes up quotes in args, even if escaped.
11
+ const src = process.env.NX_IMPORT_SOURCE;
12
+ execSync('git read-tree --empty', { stdio: 'inherit' });
13
+ execSync(`git reset ${process.env.GIT_COMMIT} -- "${src}"`, {
14
+ stdio: 'inherit',
15
+ });
16
+ }
17
+ catch (error) {
18
+ console.error(`Error executing Git commands: ${error}`);
19
+ process.exit(1);
20
+ }
@@ -40,6 +40,10 @@ class GitRepository {
40
40
  .toString()
41
41
  .trim();
42
42
  }
43
+ async hasUncommittedChanges() {
44
+ const data = await this.execAsync(`git status --porcelain`);
45
+ return data.trim() !== '';
46
+ }
43
47
  async addFetchRemote(remoteName, branch) {
44
48
  return await this.execAsync(`git config --add remote.${remoteName}.fetch "+refs/heads/${branch}:refs/remotes/${remoteName}/${branch}"`);
45
49
  }
@@ -105,32 +109,63 @@ class GitRepository {
105
109
  }
106
110
  // git-filter-repo is much faster than filter-branch, but needs to be installed by user
107
111
  // Use `hasFilterRepoInstalled` to check if it's installed
108
- async filterRepo(subdirectory) {
109
- // filter-repo requires POSIX path to work
110
- const posixPath = subdirectory.split(path_1.sep).join(path_1.posix.sep);
111
- return await this.execAsync(`git filter-repo -f --subdirectory-filter ${this.quotePath(posixPath)}`);
112
- }
113
- async filterBranch(subdirectory, branchName) {
114
- // filter-repo requires POSIX path to work
115
- const posixPath = subdirectory.split(path_1.sep).join(path_1.posix.sep);
112
+ async filterRepo(source, destination) {
113
+ // NOTE: filter-repo requires POSIX path to work
114
+ const sourcePosixPath = source.split(path_1.sep).join(path_1.posix.sep);
115
+ const destinationPosixPath = destination.split(path_1.sep).join(path_1.posix.sep);
116
+ await this.execAsync(`git filter-repo -f ${source !== '' ? `--path ${this.quotePath(sourcePosixPath)}` : ''} ${source !== destination
117
+ ? `--path-rename ${this.quotePath(sourcePosixPath, true)}:${this.quotePath(destinationPosixPath, true)}`
118
+ : ''}`);
119
+ }
120
+ async filterBranch(source, destination, branchName) {
116
121
  // We need non-ASCII file names to not be quoted, or else filter-branch will exclude them.
117
122
  await this.execAsync(`git config core.quotepath false`);
118
- return await this.execAsync(`git filter-branch --subdirectory-filter ${this.quotePath(posixPath)} -- ${branchName}`);
123
+ // NOTE: filter-repo requires POSIX path to work
124
+ const sourcePosixPath = source.split(path_1.sep).join(path_1.posix.sep);
125
+ const destinationPosixPath = destination.split(path_1.sep).join(path_1.posix.sep);
126
+ // First, if the source is not a root project, then only include commits relevant to the subdirectory.
127
+ if (source !== '') {
128
+ const indexFilterCommand = this.quoteArg(`node ${(0, path_1.join)(__dirname, 'git-utils.index-filter.js')}`);
129
+ await this.execAsync(`git filter-branch -f --index-filter ${indexFilterCommand} --prune-empty -- ${branchName}`, {
130
+ NX_IMPORT_SOURCE: sourcePosixPath,
131
+ NX_IMPORT_DESTINATION: destinationPosixPath,
132
+ });
133
+ }
134
+ // Then, move files to their new location if necessary.
135
+ if (source === '' || source !== destination) {
136
+ const treeFilterCommand = this.quoteArg(`node ${(0, path_1.join)(__dirname, 'git-utils.tree-filter.js')}`);
137
+ await this.execAsync(`git filter-branch -f --tree-filter ${treeFilterCommand} -- ${branchName}`, {
138
+ NX_IMPORT_SOURCE: sourcePosixPath,
139
+ NX_IMPORT_DESTINATION: destinationPosixPath,
140
+ });
141
+ }
119
142
  }
120
- execAsync(command) {
143
+ execAsync(command, env) {
121
144
  return execAsync(command, {
122
145
  cwd: this.root,
123
146
  maxBuffer: 10 * 1024 * 1024,
147
+ env: {
148
+ ...process.env,
149
+ ...env,
150
+ },
124
151
  });
125
152
  }
126
- quotePath(path) {
153
+ quotePath(path, ensureTrailingSlash) {
154
+ return this.quoteArg(ensureTrailingSlash && path !== '' && !path.endsWith('/')
155
+ ? `${path}/`
156
+ : path);
157
+ }
158
+ quoteArg(arg) {
127
159
  return process.platform === 'win32'
128
160
  ? // Windows/CMD only understands double-quotes, single-quotes are treated as part of the file name
129
161
  // Bash and other shells will substitute `$` in file names with a variable value.
130
- `"${path}"`
162
+ `"${arg
163
+ // Need to keep two slashes for Windows or else the path will be invalid.
164
+ // e.g. 'C:\Users\bob\projects\repo' is invalid, but 'C:\\Users\\bob\\projects\\repo' is valid
165
+ .replaceAll('\\', '\\\\')}"`
131
166
  : // e.g. `git mv "$$file.txt" "libs/a/$$file.txt"` will not work since `$$` is swapped with the PID of the last process.
132
167
  // Using single-quotes prevents this substitution.
133
- `'${path}'`;
168
+ `'${arg}'`;
134
169
  }
135
170
  }
136
171
  exports.GitRepository = GitRepository;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * This is meant to be used with `git filter-branch --tree-filter` to rewrite
3
+ * history to only include commits related to the source project folder. If the
4
+ * destination folder is different, this script also moves the files over.
5
+ *
6
+ * Example:
7
+ * NX_IMPORT_SOURCE=<source> NX_IMPORT_DESTINATION=<destination> git filter-branch --tree-filter 'node git-utils.tree-filter.js' --prune-empty -- --all
8
+ */
9
+ declare const execSync: any;
10
+ declare const existsSync: any, mkdirSync: any, renameSync: any, rmSync: any;
11
+ declare const posix: any;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * This is meant to be used with `git filter-branch --tree-filter` to rewrite
3
+ * history to only include commits related to the source project folder. If the
4
+ * destination folder is different, this script also moves the files over.
5
+ *
6
+ * Example:
7
+ * NX_IMPORT_SOURCE=<source> NX_IMPORT_DESTINATION=<destination> git filter-branch --tree-filter 'node git-utils.tree-filter.js' --prune-empty -- --all
8
+ */
9
+ const { execSync } = require('child_process');
10
+ const { existsSync, mkdirSync, renameSync, rmSync } = require('fs');
11
+ // NOTE: The path passed to `git filter-branch` is POSIX, so we need to use the `posix` module.
12
+ const { posix } = require('path');
13
+ try {
14
+ // NOTE: Using env vars because Windows PowerShell has its own handling of quotes (") messes up quotes in args, even if escaped.
15
+ const src = process.env.NX_IMPORT_SOURCE;
16
+ const dest = process.env.NX_IMPORT_DESTINATION;
17
+ const files = execSync(`git ls-files -z ${src}`)
18
+ .toString()
19
+ .trim()
20
+ .split('\x00')
21
+ .map((s) => s.trim())
22
+ .filter(Boolean);
23
+ for (const file of files) {
24
+ if (src === '' || file.startsWith(src)) {
25
+ // If source and destination are the same, then keep the file as is.
26
+ if (src === dest)
27
+ continue;
28
+ const destFile = posix.join(dest, file.replace(src, ''));
29
+ const dir = posix.dirname(destFile);
30
+ if (!existsSync(dir))
31
+ mkdirSync(dir, { recursive: true });
32
+ renameSync(file, destFile);
33
+ }
34
+ else {
35
+ // If not matching the source we are filtering, remove it.
36
+ rmSync(file);
37
+ }
38
+ }
39
+ }
40
+ catch (error) {
41
+ console.error(`Error executing Git commands: ${error}`);
42
+ process.exit(1);
43
+ }
@@ -2,4 +2,5 @@ import { ProjectConfiguration } from '../../config/workspace-json-project-json';
2
2
  import { PluginCapabilities } from './plugin-capabilities';
3
3
  export declare function listPlugins(plugins: Map<string, PluginCapabilities>, title: string): void;
4
4
  export declare function listAlsoAvailableCorePlugins(installedPlugins: Map<string, PluginCapabilities>): void;
5
+ export declare function listPowerpackPlugins(): void;
5
6
  export declare function listPluginCapabilities(pluginName: string, projects: Record<string, ProjectConfiguration>): Promise<void>;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listPlugins = listPlugins;
4
4
  exports.listAlsoAvailableCorePlugins = listAlsoAvailableCorePlugins;
5
+ exports.listPowerpackPlugins = listPowerpackPlugins;
5
6
  exports.listPluginCapabilities = listPluginCapabilities;
6
7
  const chalk = require("chalk");
7
8
  const output_1 = require("../output");
@@ -45,6 +46,12 @@ function listAlsoAvailableCorePlugins(installedPlugins) {
45
46
  });
46
47
  }
47
48
  }
49
+ function listPowerpackPlugins() {
50
+ const powerpackLink = 'https://nx.dev/plugin-registry';
51
+ output_1.output.log({
52
+ title: `Available Powerpack Plugins: ${powerpackLink}`,
53
+ });
54
+ }
48
55
  async function listPluginCapabilities(pluginName, projects) {
49
56
  const plugin = await (0, plugin_capabilities_1.getPluginCapabilities)(workspace_root_1.workspaceRoot, pluginName, projects);
50
57
  if (!plugin) {
@@ -0,0 +1,5 @@
1
+ export declare function printPowerpackLicense(): Promise<void>;
2
+ export declare function getPowerpackLicenseInformation(): Promise<any>;
3
+ export declare class NxPowerpackNotInstalledError extends Error {
4
+ constructor(e: Error);
5
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NxPowerpackNotInstalledError = void 0;
4
+ exports.printPowerpackLicense = printPowerpackLicense;
5
+ exports.getPowerpackLicenseInformation = getPowerpackLicenseInformation;
6
+ const logger_1 = require("./logger");
7
+ const package_manager_1 = require("./package-manager");
8
+ const workspace_root_1 = require("./workspace-root");
9
+ async function printPowerpackLicense() {
10
+ try {
11
+ const { organizationName, seatCount, workspaceCount } = await getPowerpackLicenseInformation();
12
+ logger_1.logger.log(`Nx Powerpack Licensed to ${organizationName} for ${seatCount} user${seatCount > 1 ? '' : 's'} in ${workspaceCount} workspace${workspaceCount > 1 ? '' : 's'}`);
13
+ }
14
+ catch { }
15
+ }
16
+ async function getPowerpackLicenseInformation() {
17
+ try {
18
+ const { getPowerpackLicenseInformation } = (await Promise.resolve().then(() => require(
19
+ // @ts-ignore
20
+ '@nx/powerpack-license'
21
+ // TODO(@FrozenPandaz): Provide the right type here.
22
+ )));
23
+ // )) as typeof import('@nx/powerpack-license');
24
+ return getPowerpackLicenseInformation(workspace_root_1.workspaceRoot);
25
+ }
26
+ catch (e) {
27
+ if ('code' in e && e.code === 'ERR_MODULE_NOT_FOUND') {
28
+ throw new NxPowerpackNotInstalledError(e);
29
+ }
30
+ throw e;
31
+ }
32
+ }
33
+ class NxPowerpackNotInstalledError extends Error {
34
+ constructor(e) {
35
+ super(`The "@nx/powerpack-license" package is needed to use Nx Powerpack enabled features. Please install the @nx/powerpack-license with ${(0, package_manager_1.getPackageManagerCommand)().addDev} @nx/powerpack-license`, { cause: e });
36
+ }
37
+ }
38
+ exports.NxPowerpackNotInstalledError = NxPowerpackNotInstalledError;