@depup/nx 23.1.2-depup.1 → 23.2.0-depup.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/README.md +7 -6
- package/changes.json +12 -8
- package/dist/bin/init-local.js +3 -5
- package/dist/bin/nx.js +1 -0
- package/dist/src/adapter/ngcli-adapter.js +60 -1
- package/dist/src/ai/constants.d.ts +15 -0
- package/dist/src/ai/constants.js +17 -1
- package/dist/src/ai/set-up-ai-agents/set-up-ai-agents.js +57 -9
- package/dist/src/ai/utils.d.ts +13 -0
- package/dist/src/ai/utils.js +29 -0
- package/dist/src/analytics/analytics.js +2 -4
- package/dist/src/command-line/completion/command-object.js +7 -12
- package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +42 -31
- package/dist/src/command-line/format/format.js +84 -101
- package/dist/src/command-line/generate/generate.js +35 -35
- package/dist/src/command-line/import/import.js +29 -38
- package/dist/src/command-line/init/ai-agent-prompts.js +5 -11
- package/dist/src/command-line/init/command-object.js +4 -2
- package/dist/src/command-line/init/configure-plugins.js +4 -1
- package/dist/src/command-line/init/implementation/add-nx-to-monorepo.js +12 -32
- package/dist/src/command-line/init/implementation/add-nx-to-nest.js +17 -21
- package/dist/src/command-line/init/implementation/add-nx-to-npm-repo.js +8 -21
- package/dist/src/command-line/init/implementation/add-nx-to-turborepo.js +3 -17
- package/dist/src/command-line/init/implementation/angular/index.js +10 -15
- package/dist/src/command-line/init/implementation/angular/legacy-angular-versions.js +2 -0
- package/dist/src/command-line/init/implementation/angular/standalone-workspace.js +8 -2
- package/dist/src/command-line/init/implementation/check-compatible-with-plugins.js +2 -0
- package/dist/src/command-line/init/implementation/dot-nx/add-nx-scripts.js +5 -0
- package/dist/src/command-line/init/implementation/format.d.ts +18 -0
- package/dist/src/command-line/init/implementation/format.js +114 -0
- package/dist/src/command-line/init/implementation/utils.js +8 -8
- package/dist/src/command-line/init/init-v1.js +15 -18
- package/dist/src/command-line/init/init-v2.js +77 -66
- package/dist/src/command-line/migrate/agentic/definitions.js +36 -9
- package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +37 -22
- package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +30 -39
- package/dist/src/command-line/migrate/agentic/handoff.d.ts +7 -7
- package/dist/src/command-line/migrate/agentic/handoff.js +13 -10
- package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.d.ts +7 -12
- package/dist/src/command-line/migrate/agentic/print-dropped-agent-context.js +7 -0
- package/dist/src/command-line/migrate/agentic/run-step.d.ts +10 -0
- package/dist/src/command-line/migrate/agentic/run-step.js +1 -0
- package/dist/src/command-line/migrate/agentic/runner.js +24 -24
- package/dist/src/command-line/migrate/agentic/select.d.ts +10 -2
- package/dist/src/command-line/migrate/agentic/select.js +30 -32
- package/dist/src/command-line/migrate/agentic/types.d.ts +33 -3
- package/dist/src/command-line/migrate/agentic/types.js +35 -0
- package/dist/src/command-line/migrate/command-object.d.ts +6 -0
- package/dist/src/command-line/migrate/command-object.js +19 -1
- package/dist/src/command-line/migrate/execute-migration.d.ts +28 -9
- package/dist/src/command-line/migrate/execute-migration.js +112 -27
- package/dist/src/command-line/migrate/migrate-analytics.d.ts +35 -0
- package/dist/src/command-line/migrate/migrate-analytics.js +64 -0
- package/dist/src/command-line/migrate/migrate-commits.d.ts +38 -8
- package/dist/src/command-line/migrate/migrate-commits.js +130 -15
- package/dist/src/command-line/migrate/migrate-config.d.ts +13 -12
- package/dist/src/command-line/migrate/migrate-config.js +22 -14
- package/dist/src/command-line/migrate/migrate-output.d.ts +45 -7
- package/dist/src/command-line/migrate/migrate-output.js +52 -8
- package/dist/src/command-line/migrate/migrate-ui-api.d.ts +2 -1
- package/dist/src/command-line/migrate/migrate-ui-api.js +16 -7
- package/dist/src/command-line/migrate/migrate.d.ts +24 -55
- package/dist/src/command-line/migrate/migrate.js +553 -226
- package/dist/src/command-line/migrate/migration-shape.d.ts +8 -0
- package/dist/src/command-line/migrate/multi-major.js +7 -10
- package/dist/src/command-line/migrate/resolve-package-version.js +4 -8
- package/dist/src/command-line/migrate/run/agent-output.d.ts +20 -0
- package/dist/src/command-line/migrate/run/agent-output.js +65 -0
- package/dist/src/command-line/migrate/run/index.d.ts +9 -0
- package/dist/src/command-line/migrate/run/index.js +23 -0
- package/dist/src/command-line/migrate/run/orchestrator.d.ts +20 -0
- package/dist/src/command-line/migrate/run/orchestrator.js +1200 -0
- package/dist/src/command-line/migrate/run/run-id.d.ts +16 -0
- package/dist/src/command-line/migrate/run/run-id.js +56 -0
- package/dist/src/command-line/migrate/run/run-state.d.ts +157 -0
- package/dist/src/command-line/migrate/run/run-state.js +438 -0
- package/dist/src/command-line/migrate/run/state-lock.d.ts +25 -0
- package/dist/src/command-line/migrate/run/state-lock.js +76 -0
- package/dist/src/command-line/migrate/run/state-machine.d.ts +84 -0
- package/dist/src/command-line/migrate/run/state-machine.js +315 -0
- package/dist/src/command-line/migrate/run/util.d.ts +59 -0
- package/dist/src/command-line/migrate/run/util.js +148 -0
- package/dist/src/command-line/migrate/run/worker.d.ts +16 -0
- package/dist/src/command-line/migrate/run/worker.js +682 -0
- package/dist/src/command-line/migrate/run-migration-process.js +6 -5
- package/dist/src/command-line/migrate/safe-prompt.d.ts +14 -26
- package/dist/src/command-line/migrate/safe-prompt.js +32 -43
- package/dist/src/command-line/migrate/sort-migrations.d.ts +16 -0
- package/dist/src/command-line/migrate/sort-migrations.js +32 -0
- package/dist/src/command-line/migrate/step-actions.d.ts +5 -0
- package/dist/src/command-line/migrate/step-actions.js +12 -0
- package/dist/src/command-line/migrate/text.d.ts +18 -0
- package/dist/src/command-line/migrate/text.js +26 -0
- package/dist/src/command-line/migrate/version-skew-guard.d.ts +60 -0
- package/dist/src/command-line/migrate/version-skew-guard.js +175 -0
- package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +16 -20
- package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.d.ts +2 -0
- package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.js +16 -0
- package/dist/src/command-line/nx-cloud/start-nx-agents/start-nx-agents.d.ts +4 -0
- package/dist/src/command-line/nx-cloud/start-nx-agents/start-nx-agents.js +13 -0
- package/dist/src/command-line/nx-commands.js +26 -24
- package/dist/src/command-line/release/changelog.js +6 -17
- package/dist/src/command-line/release/plan.js +15 -28
- package/dist/src/command-line/release/publish.js +5 -0
- package/dist/src/command-line/release/release.js +6 -17
- package/dist/src/command-line/release/utils/release-graph.d.ts +1 -0
- package/dist/src/command-line/release/utils/release-graph.js +10 -2
- package/dist/src/command-line/release/utils/remote-release-clients/github.js +10 -22
- package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +13 -22
- package/dist/src/command-line/release/utils/resolve-semver-specifier.js +19 -41
- package/dist/src/command-line/release/version/resolve-current-version.js +7 -10
- package/dist/src/command-line/release/version.js +2 -2
- package/dist/src/command-line/reset/reset.js +17 -15
- package/dist/src/command-line/yargs-utils/shared-options.d.ts +1 -1
- package/dist/src/command-line/yargs-utils/shared-options.js +3 -1
- package/dist/src/config/misc-interfaces.d.ts +19 -7
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/core/graph/styles.js +1 -1
- package/dist/src/daemon/client/client.d.ts +2 -7
- package/dist/src/daemon/client/client.js +113 -28
- package/dist/src/daemon/client/daemon-environment.d.ts +35 -0
- package/dist/src/daemon/client/daemon-environment.js +106 -6
- package/dist/src/daemon/client/daemon-socket-messenger.d.ts +1 -1
- package/dist/src/daemon/client/daemon-socket-messenger.js +8 -3
- package/dist/src/daemon/is-v8-serializer-enabled.d.ts +2 -2
- package/dist/src/daemon/is-v8-serializer-enabled.js +2 -2
- package/dist/src/daemon/message-types/daemon-message.d.ts +2 -1
- package/dist/src/daemon/message-types/daemon-message.js +25 -2
- package/dist/src/daemon/sandbox-socket-hint.d.ts +27 -0
- package/dist/src/daemon/sandbox-socket-hint.js +136 -0
- package/dist/src/daemon/server/client-socket-context.d.ts +1 -1
- package/dist/src/daemon/server/client-socket-context.js +2 -3
- package/dist/src/daemon/server/dotenv-graph-changes.d.ts +97 -0
- package/dist/src/daemon/server/dotenv-graph-changes.js +284 -0
- package/dist/src/daemon/server/handle-client-env.d.ts +8 -0
- package/dist/src/daemon/server/handle-client-env.js +92 -0
- package/dist/src/daemon/server/handle-outputs-changes.d.ts +10 -0
- package/dist/src/daemon/server/handle-outputs-changes.js +86 -0
- package/dist/src/daemon/server/project-graph-incremental-recomputation.d.ts +21 -0
- package/dist/src/daemon/server/project-graph-incremental-recomputation.js +159 -6
- package/dist/src/daemon/server/server.js +36 -72
- package/dist/src/daemon/server/shutdown-utils.d.ts +1 -1
- package/dist/src/daemon/server/shutdown-utils.js +2 -2
- package/dist/src/daemon/socket-utils.d.ts +26 -7
- package/dist/src/daemon/socket-utils.js +45 -31
- package/dist/src/daemon/tmp-dir.d.ts +10 -0
- package/dist/src/daemon/tmp-dir.js +21 -37
- package/dist/src/devkit-internals.d.ts +20 -9
- package/dist/src/devkit-internals.js +49 -6
- package/dist/src/executors/run-commands/running-tasks.js +46 -29
- package/dist/src/generators/internal-utils/{format-changed-files-with-prettier-if-available.d.ts → format-changed-files.d.ts} +6 -6
- package/dist/src/generators/internal-utils/format-changed-files.js +163 -0
- package/dist/src/generators/testing-utils/create-tree-with-empty-workspace.d.ts +15 -0
- package/dist/src/generators/testing-utils/create-tree-with-empty-workspace.js +21 -3
- package/dist/src/migrations/update-15-0-0/prefix-outputs.js +2 -2
- package/dist/src/migrations/update-16-0-0/remove-nrwl-cli.js +2 -2
- package/dist/src/migrations/update-16-0-0/update-depends-on-to-tokens.js +2 -2
- package/dist/src/migrations/update-16-0-0/update-nx-cloud-runner.js +2 -2
- package/dist/src/migrations/update-16-2-0/remove-run-commands-output-path.js +2 -2
- package/dist/src/migrations/update-17-0-0/rm-default-collection-npm-scope.js +2 -2
- package/dist/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +2 -2
- package/dist/src/migrations/update-17-2-0/move-default-base.js +2 -2
- package/dist/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.js +2 -2
- package/dist/src/migrations/update-19-2-4/set-project-name.js +2 -2
- package/dist/src/migrations/update-20-0-0/move-use-daemon-process.js +2 -2
- package/dist/src/migrations/update-20-0-1/use-legacy-cache.js +2 -2
- package/dist/src/migrations/update-21-0-0/release-changelog-config-changes.js +2 -2
- package/dist/src/migrations/update-21-0-0/release-version-config-changes.js +2 -2
- package/dist/src/migrations/update-21-0-0/remove-custom-tasks-runner.js +2 -2
- package/dist/src/migrations/update-21-0-0/remove-legacy-cache.js +2 -2
- package/dist/src/migrations/update-22-0-0/consolidate-release-tag-config.js +2 -2
- package/dist/src/migrations/update-22-0-0/release-version-config-changes.js +2 -2
- package/dist/src/migrations/update-22-2-0/add-self-healing-to-gitignore.js +2 -2
- package/dist/src/migrations/update-22-6-0/add-claude-settings-local-to-git-ignore.js +2 -2
- package/dist/src/migrations/update-22-6-0/add-claude-worktrees-to-git-ignore.js +2 -2
- package/dist/src/migrations/update-22-7-0/add-polygraph-to-git-ignore.js +2 -2
- package/dist/src/migrations/update-23-0-0/add-migrate-runs-to-git-ignore.js +2 -2
- package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +2 -2
- package/dist/src/native/index.d.ts +7 -3
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +3 -3
- package/dist/src/nx-cloud/utilities/url-shorten.d.ts +1 -4
- package/dist/src/nx-cloud/utilities/url-shorten.js +9 -8
- package/dist/src/plugins/js/lock-file/lock-file.d.ts +46 -4
- package/dist/src/plugins/js/lock-file/lock-file.js +192 -15
- package/dist/src/plugins/js/lock-file/npm-parser.js +10 -3
- package/dist/src/plugins/js/lock-file/pnpm-parser.js +356 -62
- package/dist/src/plugins/js/lock-file/project-graph-pruning.d.ts +25 -1
- package/dist/src/plugins/js/lock-file/project-graph-pruning.js +78 -4
- package/dist/src/plugins/js/lock-file/pruned-output.d.ts +330 -0
- package/dist/src/plugins/js/lock-file/pruned-output.js +1441 -0
- package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.d.ts +1 -0
- package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +6 -5
- package/dist/src/plugins/js/utils/register.d.ts +11 -0
- package/dist/src/plugins/js/utils/register.js +40 -6
- package/dist/src/project-graph/plugins/get-plugins.d.ts +27 -1
- package/dist/src/project-graph/plugins/get-plugins.js +110 -5
- package/dist/src/project-graph/plugins/isolation/enabled.js +1 -4
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +16 -0
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +69 -11
- package/dist/src/project-graph/plugins/isolation/messaging.js +1 -3
- package/dist/src/project-graph/plugins/isolation/plugin-worker.js +23 -2
- package/dist/src/project-graph/project-graph.js +27 -2
- package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.d.ts +7 -0
- package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.js +14 -6
- package/dist/src/project-graph/utils/project-configuration/target-defaults.js +47 -21
- package/dist/src/tasks-runner/is-tui-enabled.js +3 -1
- package/dist/src/tasks-runner/life-cycle.d.ts +2 -2
- package/dist/src/tasks-runner/life-cycle.js +2 -2
- package/dist/src/tasks-runner/life-cycles/performance-report.d.ts +12 -0
- package/dist/src/tasks-runner/life-cycles/performance-report.js +62 -3
- package/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.d.ts +26 -1
- package/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +99 -5
- package/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts +26 -0
- package/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +113 -17
- package/dist/src/tasks-runner/pseudo-ipc.js +14 -13
- package/dist/src/tasks-runner/pseudo-terminal.d.ts +17 -3
- package/dist/src/tasks-runner/pseudo-terminal.js +22 -10
- package/dist/src/tasks-runner/run-command.js +32 -39
- package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +55 -0
- package/dist/src/tasks-runner/running-tasks/batch-process.js +161 -8
- package/dist/src/tasks-runner/task-env.d.ts +25 -0
- package/dist/src/tasks-runner/task-env.js +39 -0
- package/dist/src/tasks-runner/task-orchestrator.d.ts +68 -0
- package/dist/src/tasks-runner/task-orchestrator.js +159 -8
- package/dist/src/utils/analytics-enabled.d.ts +7 -0
- package/dist/src/utils/analytics-enabled.js +11 -0
- package/dist/src/utils/analytics-prompt.js +4 -7
- package/dist/src/utils/cache-directory.d.ts +62 -3
- package/dist/src/utils/cache-directory.js +276 -25
- package/dist/src/utils/catalog/bun-manager-utils.d.ts +8 -0
- package/dist/src/utils/catalog/bun-manager-utils.js +174 -0
- package/dist/src/utils/catalog/bun-manager.d.ts +28 -0
- package/dist/src/utils/catalog/bun-manager.js +130 -0
- package/dist/src/utils/catalog/index.d.ts +1 -1
- package/dist/src/utils/catalog/index.js +1 -1
- package/dist/src/utils/catalog/manager-factory.js +3 -0
- package/dist/src/utils/catalog/manager-utils.d.ts +8 -1
- package/dist/src/utils/catalog/manager-utils.js +9 -4
- package/dist/src/utils/catalog/manager.d.ts +13 -1
- package/dist/src/utils/catalog/manager.js +30 -0
- package/dist/src/utils/catalog/pnpm-manager.d.ts +2 -1
- package/dist/src/utils/catalog/pnpm-manager.js +3 -0
- package/dist/src/utils/catalog/types.d.ts +4 -0
- package/dist/src/utils/catalog/yarn-manager.d.ts +6 -2
- package/dist/src/utils/catalog/yarn-manager.js +23 -32
- package/dist/src/utils/child-process.d.ts +31 -1
- package/dist/src/utils/child-process.js +103 -0
- package/dist/src/utils/chunkify.d.ts +7 -1
- package/dist/src/utils/chunkify.js +10 -3
- package/dist/src/utils/consume-messages-from-socket.d.ts +42 -7
- package/dist/src/utils/consume-messages-from-socket.js +273 -38
- package/dist/src/utils/db-connection.js +8 -16
- package/dist/src/utils/exit-codes.d.ts +9 -0
- package/dist/src/utils/exit-codes.js +19 -0
- package/dist/src/utils/formatters/index.d.ts +13 -0
- package/dist/src/utils/formatters/index.js +74 -0
- package/dist/src/utils/formatters/oxfmt.d.ts +32 -0
- package/dist/src/utils/formatters/oxfmt.js +764 -0
- package/dist/src/utils/formatters/prettier.d.ts +26 -0
- package/dist/src/utils/formatters/prettier.js +201 -0
- package/dist/src/utils/formatters/shared.d.ts +5 -0
- package/dist/src/utils/formatters/shared.js +8 -0
- package/dist/src/utils/git-utils.d.ts +38 -2
- package/dist/src/utils/git-utils.js +422 -19
- package/dist/src/utils/has-nx-js-plugin.d.ts +1 -1
- package/dist/src/utils/has-nx-js-plugin.js +1 -1
- package/dist/src/utils/ignore.d.ts +47 -5
- package/dist/src/utils/ignore.js +93 -11
- package/dist/src/utils/kill-child-on-host-exit.d.ts +7 -0
- package/dist/src/utils/kill-child-on-host-exit.js +42 -0
- package/dist/src/utils/nx-console-prompt.js +3 -6
- package/dist/src/utils/nx-tmp-dir.d.ts +5 -0
- package/dist/src/utils/nx-tmp-dir.js +7 -2
- package/dist/src/utils/output.d.ts +153 -0
- package/dist/src/utils/output.js +289 -5
- package/dist/src/utils/owned-private-dir.d.ts +13 -0
- package/dist/src/utils/owned-private-dir.js +39 -0
- package/dist/src/utils/package-json.d.ts +2 -0
- package/dist/src/utils/package-manager.js +17 -7
- package/dist/src/utils/params.d.ts +7 -1
- package/dist/src/utils/params.js +64 -6
- package/dist/src/utils/permission-errors.d.ts +11 -0
- package/dist/src/utils/permission-errors.js +17 -0
- package/dist/src/utils/plugins/core-plugins.js +4 -0
- package/dist/src/utils/prompt-helpers.d.ts +53 -0
- package/dist/src/utils/prompt-helpers.js +111 -0
- package/dist/src/utils/socket-refused-exit-code.d.ts +15 -0
- package/dist/src/utils/socket-refused-exit-code.js +18 -0
- package/dist/src/utils/write-formatted-json-file.d.ts +3 -2
- package/dist/src/utils/write-formatted-json-file.js +5 -4
- package/package.json +33 -24
- package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +0 -88
- package/dist/src/utils/is-using-prettier.d.ts +0 -3
- package/dist/src/utils/is-using-prettier.js +0 -62
|
@@ -3,22 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.chunkify = chunkify;
|
|
4
4
|
exports.getMaxArgLength = getMaxArgLength;
|
|
5
5
|
const TERMINAL_SIZE = getMaxArgLength();
|
|
6
|
-
function chunkify(target, maxChunkLength = TERMINAL_SIZE - 500
|
|
6
|
+
function chunkify(target, maxChunkLength = TERMINAL_SIZE - 500,
|
|
7
|
+
/**
|
|
8
|
+
* How long each entry will be once it reaches the command line. Callers that
|
|
9
|
+
* quote or escape afterwards pass that transformation's length here, so the
|
|
10
|
+
* chunk is sized against what is actually spawned rather than the raw string.
|
|
11
|
+
*/
|
|
12
|
+
measure = (item) => item.length) {
|
|
7
13
|
const chunks = [];
|
|
8
14
|
let currentChunk = [];
|
|
9
15
|
let currentChunkLength = 0;
|
|
10
16
|
for (const file of target) {
|
|
17
|
+
const length = measure(file);
|
|
11
18
|
if (
|
|
12
19
|
// Prevent empty chunk if first file path is longer than maxChunkLength
|
|
13
20
|
currentChunk.length &&
|
|
14
21
|
// +1 accounts for the space between file names
|
|
15
|
-
currentChunkLength +
|
|
22
|
+
currentChunkLength + length + 1 >= maxChunkLength) {
|
|
16
23
|
chunks.push(currentChunk);
|
|
17
24
|
currentChunk = [];
|
|
18
25
|
currentChunkLength = 0;
|
|
19
26
|
}
|
|
20
27
|
currentChunk.push(file);
|
|
21
|
-
currentChunkLength +=
|
|
28
|
+
currentChunkLength += length + 1;
|
|
22
29
|
}
|
|
23
30
|
chunks.push(currentChunk);
|
|
24
31
|
return chunks;
|
|
@@ -1,9 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
export declare
|
|
3
|
-
export declare function isJsonMessage(message: string): boolean;
|
|
1
|
+
import type { Socket } from 'net';
|
|
2
|
+
export declare const MESSAGE_HEADER_PREFIX = "NX_MSG_";
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Ceiling on a single message, in bytes. Payloads are buffered outside the V8
|
|
5
|
+
* heap, so `--max-old-space-size` does not bound them and a peer that declares
|
|
6
|
+
* a huge length would otherwise be allowed to stream until the machine gives
|
|
7
|
+
* out. The default is four times the ~0.5GiB string ceiling that used to cap
|
|
8
|
+
* every message, so it clears any payload that previously worked or was meant
|
|
9
|
+
* to. Set `NX_MAX_MESSAGE_SIZE` to another byte count to change it, or to 0 to
|
|
10
|
+
* remove the ceiling. The daemon reads it from the env it was spawned with —
|
|
11
|
+
* clients do not reflect it (see DAEMON_ENV_VARS_EXCLUSIONS) — so changing it
|
|
12
|
+
* needs a daemon restart (`nx reset`).
|
|
8
13
|
*/
|
|
9
|
-
export declare
|
|
14
|
+
export declare const DEFAULT_MAX_MESSAGE_SIZE: number;
|
|
15
|
+
export declare function getMaxMessageSize(): number;
|
|
16
|
+
export declare function frameHeader(payloadLength: number): Buffer;
|
|
17
|
+
/**
|
|
18
|
+
* Writes a length-prefixed message. The header and payload are written
|
|
19
|
+
* separately so a large payload is never copied to prepend its header.
|
|
20
|
+
*/
|
|
21
|
+
export declare function writeMessage(socket: Socket, payload: Buffer, callback?: (err?: Error) => void): void;
|
|
22
|
+
export declare class MessageFramingError extends Error {
|
|
23
|
+
constructor(message: string);
|
|
24
|
+
}
|
|
25
|
+
export declare function consumeMessagesFromSocket(callback: (message: Buffer) => void, onError?: (error: MessageFramingError) => void): (data: Buffer) => void;
|
|
26
|
+
/**
|
|
27
|
+
* v8-serialized payloads always begin with the 0xFF version header, which no
|
|
28
|
+
* JSON document can start with.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isJsonMessage(message: Buffer): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Render part of a message for an error message. A v8 payload is binary rather
|
|
33
|
+
* than utf8 text — its 0xFF header alone can never decode — so it is rendered
|
|
34
|
+
* as hex instead of as U+FFFD-riddled mojibake.
|
|
35
|
+
*/
|
|
36
|
+
export declare function describeMessage(message: Buffer, { maxBytes, from }?: DescribeMessageOptions): string;
|
|
37
|
+
export interface DescribeMessageOptions {
|
|
38
|
+
maxBytes?: number;
|
|
39
|
+
from?: 'start' | 'end';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse a message produced by `serialize()` in `daemon/socket-utils.ts`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseMessage<T = unknown>(message: Buffer): T;
|
|
@@ -1,56 +1,291 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MessageFramingError = exports.DEFAULT_MAX_MESSAGE_SIZE = exports.MESSAGE_HEADER_PREFIX = void 0;
|
|
4
|
+
exports.getMaxMessageSize = getMaxMessageSize;
|
|
5
|
+
exports.frameHeader = frameHeader;
|
|
6
|
+
exports.writeMessage = writeMessage;
|
|
4
7
|
exports.consumeMessagesFromSocket = consumeMessagesFromSocket;
|
|
5
8
|
exports.isJsonMessage = isJsonMessage;
|
|
9
|
+
exports.describeMessage = describeMessage;
|
|
6
10
|
exports.parseMessage = parseMessage;
|
|
7
|
-
const string_decoder_1 = require("string_decoder");
|
|
8
11
|
const v8_1 = require("v8");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
exports.MESSAGE_HEADER_PREFIX = 'NX_MSG_';
|
|
13
|
+
const MESSAGE_HEADER_TERMINATOR = ':'.charCodeAt(0);
|
|
14
|
+
const MESSAGE_HEADER_PREFIX_BYTES = Buffer.from(exports.MESSAGE_HEADER_PREFIX, 'ascii');
|
|
15
|
+
// `Number.MAX_SAFE_INTEGER` is 16 digits, so a longer run of digits than that
|
|
16
|
+
// is a desynchronized stream rather than a very large message.
|
|
17
|
+
const MAX_HEADER_LENGTH = exports.MESSAGE_HEADER_PREFIX.length + 16 + 1;
|
|
18
|
+
/**
|
|
19
|
+
* Ceiling on a single message, in bytes. Payloads are buffered outside the V8
|
|
20
|
+
* heap, so `--max-old-space-size` does not bound them and a peer that declares
|
|
21
|
+
* a huge length would otherwise be allowed to stream until the machine gives
|
|
22
|
+
* out. The default is four times the ~0.5GiB string ceiling that used to cap
|
|
23
|
+
* every message, so it clears any payload that previously worked or was meant
|
|
24
|
+
* to. Set `NX_MAX_MESSAGE_SIZE` to another byte count to change it, or to 0 to
|
|
25
|
+
* remove the ceiling. The daemon reads it from the env it was spawned with —
|
|
26
|
+
* clients do not reflect it (see DAEMON_ENV_VARS_EXCLUSIONS) — so changing it
|
|
27
|
+
* needs a daemon restart (`nx reset`).
|
|
28
|
+
*/
|
|
29
|
+
exports.DEFAULT_MAX_MESSAGE_SIZE = 2 * 1024 * 1024 * 1024;
|
|
30
|
+
function getMaxMessageSize() {
|
|
31
|
+
const configured = process.env.NX_MAX_MESSAGE_SIZE;
|
|
32
|
+
if (configured === undefined || configured === '') {
|
|
33
|
+
return exports.DEFAULT_MAX_MESSAGE_SIZE;
|
|
34
|
+
}
|
|
35
|
+
const parsed = Number(configured);
|
|
36
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
37
|
+
console.warn(`NX_MAX_MESSAGE_SIZE must be a non-negative number of bytes, but was "${configured}". Using the default of ${exports.DEFAULT_MAX_MESSAGE_SIZE}.`);
|
|
38
|
+
return exports.DEFAULT_MAX_MESSAGE_SIZE;
|
|
39
|
+
}
|
|
40
|
+
return parsed;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `nx reset` only helps while a daemon is enabled: it and its plugin workers keep the
|
|
44
|
+
* limit they were spawned with, and the var is excluded from the daemon env hash so
|
|
45
|
+
* changing it restarts nothing. Every other reader re-reads the env per invocation.
|
|
46
|
+
* Required lazily because the daemon client imports this module.
|
|
47
|
+
*/
|
|
48
|
+
function daemonHoldsItsOwnLimit() {
|
|
49
|
+
try {
|
|
50
|
+
return require('../daemon/client/client').daemonClient.enabled();
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const ZERO = '0'.charCodeAt(0);
|
|
57
|
+
const NINE = '9'.charCodeAt(0);
|
|
58
|
+
function frameHeader(payloadLength) {
|
|
59
|
+
return Buffer.from(`${exports.MESSAGE_HEADER_PREFIX}${payloadLength}:`, 'ascii');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Writes a length-prefixed message. The header and payload are written
|
|
63
|
+
* separately so a large payload is never copied to prepend its header.
|
|
64
|
+
*/
|
|
65
|
+
function writeMessage(socket, payload, callback) {
|
|
66
|
+
socket.write(frameHeader(payload.length));
|
|
67
|
+
socket.write(payload, callback);
|
|
68
|
+
}
|
|
69
|
+
class MessageFramingError extends Error {
|
|
70
|
+
constructor(message) {
|
|
71
|
+
super(message);
|
|
72
|
+
this.name = 'MessageFramingError';
|
|
73
|
+
Object.setPrototypeOf(this, MessageFramingError.prototype);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.MessageFramingError = MessageFramingError;
|
|
77
|
+
function consumeMessagesFromSocket(callback, onError = (error) => {
|
|
78
|
+
console.error(error.message);
|
|
79
|
+
}) {
|
|
80
|
+
let chunks = [];
|
|
81
|
+
let buffered = 0;
|
|
82
|
+
let expectedPayloadLength = null;
|
|
83
|
+
let broken = false;
|
|
84
|
+
// Read once per socket so a test or a caller can change it between
|
|
85
|
+
// connections without paying the lookup on every frame.
|
|
86
|
+
const maxMessageSize = getMaxMessageSize();
|
|
87
|
+
const fail = (message) => {
|
|
88
|
+
broken = true;
|
|
89
|
+
chunks = [];
|
|
90
|
+
buffered = 0;
|
|
91
|
+
expectedPayloadLength = null;
|
|
92
|
+
onError(new MessageFramingError(message));
|
|
93
|
+
};
|
|
94
|
+
// Copies at most `length` leading bytes without collapsing the chunk list.
|
|
95
|
+
const peek = (length) => {
|
|
96
|
+
const size = Math.min(length, buffered);
|
|
97
|
+
if (chunks.length === 1) {
|
|
98
|
+
return chunks[0].subarray(0, size);
|
|
99
|
+
}
|
|
100
|
+
const out = Buffer.allocUnsafe(size);
|
|
101
|
+
let offset = 0;
|
|
102
|
+
for (const chunk of chunks) {
|
|
103
|
+
if (offset >= size)
|
|
104
|
+
break;
|
|
105
|
+
offset += chunk.copy(out, offset, 0, Math.min(chunk.length, size - offset));
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
};
|
|
109
|
+
const take = (length) => {
|
|
110
|
+
if (length === 0) {
|
|
111
|
+
return Buffer.alloc(0);
|
|
112
|
+
}
|
|
113
|
+
// A socket chunk usually carries several whole messages, so slice the
|
|
114
|
+
// leading one out in place rather than allocating and copying for each.
|
|
115
|
+
// The payload is parsed by the callback before the next read, so sharing
|
|
116
|
+
// the chunk's memory does not retain it.
|
|
117
|
+
if (chunks[0].length === length) {
|
|
118
|
+
buffered -= length;
|
|
119
|
+
return chunks.shift();
|
|
120
|
+
}
|
|
121
|
+
if (chunks[0].length > length) {
|
|
122
|
+
const out = chunks[0].subarray(0, length);
|
|
123
|
+
chunks[0] = chunks[0].subarray(length);
|
|
124
|
+
buffered -= length;
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
const out = Buffer.allocUnsafe(length);
|
|
128
|
+
let offset = 0;
|
|
129
|
+
while (offset < length) {
|
|
130
|
+
const chunk = chunks[0];
|
|
131
|
+
const needed = length - offset;
|
|
132
|
+
if (chunk.length <= needed) {
|
|
133
|
+
chunk.copy(out, offset);
|
|
134
|
+
offset += chunk.length;
|
|
135
|
+
chunks.shift();
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
chunk.copy(out, offset, 0, needed);
|
|
139
|
+
chunks[0] = chunk.subarray(needed);
|
|
140
|
+
offset = length;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
buffered -= length;
|
|
144
|
+
return out;
|
|
145
|
+
};
|
|
146
|
+
const discard = (length) => {
|
|
147
|
+
let remaining = length;
|
|
148
|
+
while (remaining > 0) {
|
|
149
|
+
const chunk = chunks[0];
|
|
150
|
+
if (chunk.length <= remaining) {
|
|
151
|
+
remaining -= chunk.length;
|
|
152
|
+
chunks.shift();
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
chunks[0] = chunk.subarray(remaining);
|
|
156
|
+
remaining = 0;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
buffered -= length;
|
|
160
|
+
};
|
|
161
|
+
// Returns the payload length, or null when the header is still incomplete.
|
|
162
|
+
const readHeader = () => {
|
|
163
|
+
const head = peek(MAX_HEADER_LENGTH);
|
|
164
|
+
for (let i = 0; i < MESSAGE_HEADER_PREFIX_BYTES.length; i++) {
|
|
165
|
+
if (i >= head.length)
|
|
166
|
+
return null;
|
|
167
|
+
if (head[i] !== MESSAGE_HEADER_PREFIX_BYTES[i]) {
|
|
168
|
+
fail(`Expected a message to begin with '${exports.MESSAGE_HEADER_PREFIX}' but received ` +
|
|
169
|
+
`${JSON.stringify(head.toString('utf8', 0, 32))}. The stream is out of sync.`);
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
let digits = 0;
|
|
174
|
+
let value = 0;
|
|
175
|
+
for (let i = MESSAGE_HEADER_PREFIX_BYTES.length; i < head.length; i++) {
|
|
176
|
+
const byte = head[i];
|
|
177
|
+
if (byte === MESSAGE_HEADER_TERMINATOR) {
|
|
178
|
+
if (digits === 0) {
|
|
179
|
+
fail(`Message header carried no length.`);
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
if (maxMessageSize > 0 && value > maxMessageSize) {
|
|
183
|
+
fail(`Message of ${value} bytes exceeds the ${maxMessageSize} byte limit. ` +
|
|
184
|
+
`Set NX_MAX_MESSAGE_SIZE to raise it, or to 0 to remove it.` +
|
|
185
|
+
(daemonHoldsItsOwnLimit()
|
|
186
|
+
? ` Then run \`nx reset\`, since a running daemon and the plugin workers it spawns keep the limit they started with.`
|
|
187
|
+
: ''));
|
|
188
|
+
return null;
|
|
28
189
|
}
|
|
190
|
+
discard(i + 1);
|
|
191
|
+
return value;
|
|
29
192
|
}
|
|
30
|
-
|
|
193
|
+
if (byte < ZERO || byte > NINE) {
|
|
194
|
+
fail(`Message header contained a non-digit length. The stream is out of sync.`);
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
value = value * 10 + (byte - ZERO);
|
|
198
|
+
digits++;
|
|
199
|
+
}
|
|
200
|
+
if (head.length >= MAX_HEADER_LENGTH) {
|
|
201
|
+
fail(`Message header exceeded ${MAX_HEADER_LENGTH} bytes without a ':'.`);
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
};
|
|
205
|
+
return (data) => {
|
|
206
|
+
if (broken) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
chunks.push(data);
|
|
210
|
+
buffered += data.length;
|
|
211
|
+
while (!broken) {
|
|
212
|
+
if (expectedPayloadLength === null) {
|
|
213
|
+
const length = readHeader();
|
|
214
|
+
if (length === null)
|
|
215
|
+
break;
|
|
216
|
+
expectedPayloadLength = length;
|
|
217
|
+
}
|
|
218
|
+
if (expectedPayloadLength === 0) {
|
|
219
|
+
fail('Message header declared a zero-length payload.');
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
if (buffered < expectedPayloadLength)
|
|
223
|
+
break;
|
|
224
|
+
const payload = take(expectedPayloadLength);
|
|
225
|
+
expectedPayloadLength = null;
|
|
226
|
+
callback(payload);
|
|
31
227
|
}
|
|
32
|
-
// If message doesn't end with MESSAGE_END_SEQ, keep accumulating chunks
|
|
33
228
|
};
|
|
34
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* v8-serialized payloads always begin with the 0xFF version header, which no
|
|
232
|
+
* JSON document can start with.
|
|
233
|
+
*/
|
|
35
234
|
function isJsonMessage(message) {
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
235
|
+
return message.length === 0 || message[0] !== 0xff;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Widest slice of `window` that holds only whole utf8 characters. Cutting at an
|
|
239
|
+
* arbitrary byte leaves a partial sequence, and a partial sequence decodes to
|
|
240
|
+
* U+FFFD, which is the corruption `describeMessage` exists to avoid. A slice
|
|
241
|
+
* taken from the end can also begin mid-character, so both edges are trimmed.
|
|
242
|
+
*/
|
|
243
|
+
function trimToCharBoundary(window, from) {
|
|
244
|
+
const isContinuation = (byte) => (byte & 0xc0) === 0x80;
|
|
245
|
+
if (from === 'end') {
|
|
246
|
+
let offset = 0;
|
|
247
|
+
while (offset < window.length && isContinuation(window[offset])) {
|
|
248
|
+
offset++;
|
|
249
|
+
}
|
|
250
|
+
return window.subarray(offset);
|
|
251
|
+
}
|
|
252
|
+
let lead = window.length - 1;
|
|
253
|
+
while (lead >= 0 && isContinuation(window[lead])) {
|
|
254
|
+
lead--;
|
|
255
|
+
}
|
|
256
|
+
if (lead < 0) {
|
|
257
|
+
return window.subarray(0, 0);
|
|
258
|
+
}
|
|
259
|
+
const byte = window[lead];
|
|
260
|
+
const width = byte >= 0xf0 ? 4 : byte >= 0xe0 ? 3 : byte >= 0xc0 ? 2 : 1;
|
|
261
|
+
// Keep the trailing sequence only when the cut did not land inside it.
|
|
262
|
+
return lead + width <= window.length ? window : window.subarray(0, lead);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Render part of a message for an error message. A v8 payload is binary rather
|
|
266
|
+
* than utf8 text — its 0xFF header alone can never decode — so it is rendered
|
|
267
|
+
* as hex instead of as U+FFFD-riddled mojibake.
|
|
268
|
+
*/
|
|
269
|
+
function describeMessage(message, { maxBytes = 300, from = 'start' } = {}) {
|
|
270
|
+
const json = isJsonMessage(message);
|
|
271
|
+
const window = from === 'end'
|
|
272
|
+
? message.subarray(Math.max(0, message.length - maxBytes))
|
|
273
|
+
: message.subarray(0, maxBytes);
|
|
274
|
+
const slice = json ? trimToCharBoundary(window, from) : window;
|
|
275
|
+
const elided = message.length - slice.length;
|
|
276
|
+
return [
|
|
277
|
+
`${json ? 'json' : 'v8'}, ${message.length} bytes` +
|
|
278
|
+
(elided > 0
|
|
279
|
+
? `, ${from === 'end' ? 'last' : 'first'} ${slice.length} shown`
|
|
280
|
+
: ''),
|
|
281
|
+
json ? slice.toString('utf8') : slice.toString('hex'),
|
|
282
|
+
].join('\n');
|
|
46
283
|
}
|
|
47
284
|
/**
|
|
48
|
-
* Parse a message
|
|
49
|
-
* `daemon/socket-utils.ts`. Auto-detects JSON vs. v8-serialized payloads using
|
|
50
|
-
* `isJsonMessage()` and decodes the binary path via `v8.deserialize`.
|
|
285
|
+
* Parse a message produced by `serialize()` in `daemon/socket-utils.ts`.
|
|
51
286
|
*/
|
|
52
287
|
function parseMessage(message) {
|
|
53
288
|
return isJsonMessage(message)
|
|
54
|
-
? JSON.parse(message)
|
|
55
|
-
: (0, v8_1.deserialize)(
|
|
289
|
+
? JSON.parse(message.toString('utf8'))
|
|
290
|
+
: (0, v8_1.deserialize)(message);
|
|
56
291
|
}
|
|
@@ -7,25 +7,17 @@ const cache_directory_1 = require("./cache-directory");
|
|
|
7
7
|
const workspace_root_1 = require("./workspace-root");
|
|
8
8
|
const dbConnectionMap = new Map();
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Where the shared DB lives, resolved once per process.
|
|
11
|
+
*
|
|
12
|
+
* The DB is the only thing that uses the shared `workspace-data` directory --
|
|
13
|
+
* daemon logs and the `disabled` marker stay in the checkout's own, because
|
|
14
|
+
* they describe that checkout. Sharing is not decided here: this DB indexes the
|
|
15
|
+
* cache directory's contents, so the two have to land in the same scope or a
|
|
16
|
+
* cache hit resolves to artifacts that were never written here.
|
|
13
17
|
*/
|
|
14
18
|
let _sharedDir;
|
|
15
19
|
function sharedWorkspaceDataDirectory(root) {
|
|
16
|
-
|
|
17
|
-
return _sharedDir;
|
|
18
|
-
try {
|
|
19
|
-
const mainRoot = (0, native_1.getMainWorktreeRoot)(root);
|
|
20
|
-
if (mainRoot) {
|
|
21
|
-
_sharedDir = (0, cache_directory_1.workspaceDataDirectoryForWorkspace)(mainRoot);
|
|
22
|
-
return _sharedDir;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
// Fall back to local workspace data if worktree detection fails
|
|
27
|
-
}
|
|
28
|
-
_sharedDir = (0, cache_directory_1.workspaceDataDirectoryForWorkspace)(root);
|
|
20
|
+
_sharedDir ??= (0, cache_directory_1.sharedDataDirectory)(root, 'workspace-data');
|
|
29
21
|
return _sharedDir;
|
|
30
22
|
}
|
|
31
23
|
function getDbConnection(opts = {}) {
|
|
@@ -13,3 +13,12 @@ export declare const EXPECTED_TERMINATION_SIGNALS: Set<number>;
|
|
|
13
13
|
* Handles both Linux exact-match and macOS strsignal formats (e.g. "Terminated by Hangup: 1").
|
|
14
14
|
*/
|
|
15
15
|
export declare function messageToCode(message: string): number;
|
|
16
|
+
/**
|
|
17
|
+
* Ends the process the way an interrupted process ends: by SIGINT, not by
|
|
18
|
+
* exiting with its conventional code.
|
|
19
|
+
*
|
|
20
|
+
* A shell reports 130 either way, but a parent using waitpid sees
|
|
21
|
+
* `signal: 'SIGINT'` rather than `code: 130`, which is what tools wrapping nx
|
|
22
|
+
* check to tell "the user pressed Ctrl+C" from "the command failed".
|
|
23
|
+
*/
|
|
24
|
+
export declare function exitAsInterrupted(): never;
|
|
@@ -4,6 +4,7 @@ exports.EXPECTED_TERMINATION_SIGNALS = void 0;
|
|
|
4
4
|
exports.signalToCode = signalToCode;
|
|
5
5
|
exports.codeToSignal = codeToSignal;
|
|
6
6
|
exports.messageToCode = messageToCode;
|
|
7
|
+
exports.exitAsInterrupted = exitAsInterrupted;
|
|
7
8
|
/**
|
|
8
9
|
* Translates NodeJS signals to numeric exit code
|
|
9
10
|
* @param signal
|
|
@@ -73,3 +74,21 @@ function messageToCode(message) {
|
|
|
73
74
|
return 1;
|
|
74
75
|
}
|
|
75
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Ends the process the way an interrupted process ends: by SIGINT, not by
|
|
79
|
+
* exiting with its conventional code.
|
|
80
|
+
*
|
|
81
|
+
* A shell reports 130 either way, but a parent using waitpid sees
|
|
82
|
+
* `signal: 'SIGINT'` rather than `code: 130`, which is what tools wrapping nx
|
|
83
|
+
* check to tell "the user pressed Ctrl+C" from "the command failed".
|
|
84
|
+
*/
|
|
85
|
+
function exitAsInterrupted() {
|
|
86
|
+
// Windows has no signal disposition to inherit - `process.kill` there
|
|
87
|
+
// terminates with an arbitrary code - so keep the 128+SIGINT convention.
|
|
88
|
+
if (process.platform !== 'win32') {
|
|
89
|
+
// Any listener would swallow this; the default action is what terminates.
|
|
90
|
+
process.removeAllListeners('SIGINT');
|
|
91
|
+
process.kill(process.pid, 'SIGINT');
|
|
92
|
+
}
|
|
93
|
+
process.exit(130);
|
|
94
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Tree } from '../../generators/tree';
|
|
2
|
+
/**
|
|
3
|
+
* Adding a member here does NOT reliably break compilation: the repo builds
|
|
4
|
+
* with `strict: false`, so a `switch` that omits one is not an error. The
|
|
5
|
+
* `never` assertions and type-keyed tables that do catch it fail immediately
|
|
6
|
+
* inside `packages/nx`, but the ones in devkit and `@nx/js` read the type from
|
|
7
|
+
* its emitted declarations, so those only fail once it has been rebuilt.
|
|
8
|
+
*/
|
|
9
|
+
export type FormatterType = 'prettier' | 'oxfmt';
|
|
10
|
+
/** Test-only: the warn-once flag is module state and would leak between cases. */
|
|
11
|
+
export declare function resetFormatterWarningsForTesting(): void;
|
|
12
|
+
export declare function detectFormatter(root: string): FormatterType | null;
|
|
13
|
+
export declare function detectFormatterInTree(tree: Tree): FormatterType | null;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetFormatterWarningsForTesting = resetFormatterWarningsForTesting;
|
|
4
|
+
exports.detectFormatter = detectFormatter;
|
|
5
|
+
exports.detectFormatterInTree = detectFormatterInTree;
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const json_1 = require("../../generators/utils/json");
|
|
9
|
+
const fileutils_1 = require("../fileutils");
|
|
10
|
+
const oxfmt_1 = require("./oxfmt");
|
|
11
|
+
const prettier_1 = require("./prettier");
|
|
12
|
+
const logger_1 = require("../logger");
|
|
13
|
+
// Once per process: detection runs on every one of 200+ `formatFiles` call sites.
|
|
14
|
+
let warnedBothConfigured = false;
|
|
15
|
+
function warnBothConfigured() {
|
|
16
|
+
warnedBothConfigured = true;
|
|
17
|
+
logger_1.logger.warn('Both an oxfmt and a prettier config were found. Nx is formatting with ' +
|
|
18
|
+
'oxfmt. Delete the config you are not using to make the choice ' +
|
|
19
|
+
'explicit: https://nx.dev/docs/reference/code-formatting');
|
|
20
|
+
}
|
|
21
|
+
/** Test-only: the warn-once flag is module state and would leak between cases. */
|
|
22
|
+
function resetFormatterWarningsForTesting() {
|
|
23
|
+
warnedBothConfigured = false;
|
|
24
|
+
}
|
|
25
|
+
function detectFormatter(root) {
|
|
26
|
+
if ((0, oxfmt_1.isUsingOxfmt)(root)) {
|
|
27
|
+
// Flag first, so the lookup stops repeating once we have warned.
|
|
28
|
+
if (!warnedBothConfigured && (0, prettier_1.isUsingPrettier)(root)) {
|
|
29
|
+
warnBothConfigured();
|
|
30
|
+
}
|
|
31
|
+
return 'oxfmt';
|
|
32
|
+
}
|
|
33
|
+
if ((0, prettier_1.isUsingPrettier)(root)) {
|
|
34
|
+
return 'prettier';
|
|
35
|
+
}
|
|
36
|
+
// Neither is configured. Both formatters run on their defaults, so a
|
|
37
|
+
// dependency declared in the root package.json is the only statement of
|
|
38
|
+
// intent an unconfigured workspace gives. #30426 ruled out treating prettier
|
|
39
|
+
// as *resolvable in node_modules*, which a declared dependency is not.
|
|
40
|
+
const packageJsonPath = (0, node_path_1.join)(root, 'package.json');
|
|
41
|
+
if ((0, node_fs_1.existsSync)(packageJsonPath)) {
|
|
42
|
+
return detectFormatterFromDependencies((0, fileutils_1.readJsonFile)(packageJsonPath));
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function detectFormatterInTree(tree) {
|
|
47
|
+
if ((0, oxfmt_1.isUsingOxfmtInTree)(tree)) {
|
|
48
|
+
if (!warnedBothConfigured && (0, prettier_1.isUsingPrettierInTree)(tree)) {
|
|
49
|
+
warnBothConfigured();
|
|
50
|
+
}
|
|
51
|
+
return 'oxfmt';
|
|
52
|
+
}
|
|
53
|
+
if ((0, prettier_1.isUsingPrettierInTree)(tree)) {
|
|
54
|
+
return 'prettier';
|
|
55
|
+
}
|
|
56
|
+
// See detectFormatter: a declared dependency is the fallback for both.
|
|
57
|
+
if (tree.exists('package.json')) {
|
|
58
|
+
return detectFormatterFromDependencies((0, json_1.readJson)(tree, 'package.json'));
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
/** oxfmt first, matching the precedence the config files already have. */
|
|
63
|
+
function detectFormatterFromDependencies(packageJson) {
|
|
64
|
+
if (hasDependency(packageJson, 'oxfmt')) {
|
|
65
|
+
return 'oxfmt';
|
|
66
|
+
}
|
|
67
|
+
if (hasDependency(packageJson, 'prettier')) {
|
|
68
|
+
return 'prettier';
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function hasDependency(packageJson, name) {
|
|
73
|
+
return Boolean(packageJson.dependencies?.[name] ?? packageJson.devDependencies?.[name]);
|
|
74
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Tree } from '../../generators/tree';
|
|
2
|
+
/**
|
|
3
|
+
* Config filenames oxfmt *discovers* - narrower than the set `-c` accepts.
|
|
4
|
+
* Measured against 0.60.0: `oxfmt.config.{js,cjs,mjs,cts}` load when named
|
|
5
|
+
* but are never searched for, so treating one as config would format on
|
|
6
|
+
* options oxfmt ignores. No precedence order - oxfmt fails with
|
|
7
|
+
* "Both '<a>' and '<b>' found in <dir>" when a directory holds two.
|
|
8
|
+
*/
|
|
9
|
+
export declare const oxfmtConfigFiles: string[];
|
|
10
|
+
export declare function isUsingOxfmt(root: string): boolean;
|
|
11
|
+
export declare function isUsingOxfmtInTree(tree: Tree): boolean;
|
|
12
|
+
export declare function getOxfmtBinPath(): string;
|
|
13
|
+
export declare function writeWithOxfmt(patterns: string[], cwd?: string): void;
|
|
14
|
+
export declare function checkWithOxfmt(patterns: string[]): Promise<string[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Nothing is written to disk: staging files inside the workspace would race the
|
|
17
|
+
* daemon's watcher and the project graph mid-generator.
|
|
18
|
+
*
|
|
19
|
+
* A path is absent from the result when oxfmt has no parser for it, an ignore
|
|
20
|
+
* file covers it, or it is already formatted. One unparseable file fails only
|
|
21
|
+
* itself; the rest of the batch still applies.
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatFilesWithOxfmt(files: {
|
|
24
|
+
path: string;
|
|
25
|
+
content: string;
|
|
26
|
+
}[], workspaceRoot: string, seedConfig?: {
|
|
27
|
+
name: string;
|
|
28
|
+
content: string;
|
|
29
|
+
}, rootConfigNames?: readonly string[], read?: (relativePath: string) => string | null | undefined): Promise<{
|
|
30
|
+
formatted: Map<string, string>;
|
|
31
|
+
errors?: string[];
|
|
32
|
+
}>;
|