nx 23.2.0-beta.0 → 23.2.0-beta.10
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/dist/bin/init-local.js +3 -5
- package/dist/bin/nx.js +3 -1
- package/dist/release/changelog-renderer/index.js +4 -5
- package/dist/release/index.d.ts +1 -1
- package/dist/src/adapter/ngcli-adapter.js +60 -1
- package/dist/src/ai/set-up-ai-agents/set-up-ai-agents.js +35 -15
- package/dist/src/analytics/analytics.d.ts +6 -0
- package/dist/src/analytics/analytics.js +16 -10
- package/dist/src/analytics/index.d.ts +1 -1
- package/dist/src/analytics/index.js +2 -1
- package/dist/src/command-line/add/add.js +5 -0
- package/dist/src/command-line/affected/affected.js +1 -0
- package/dist/src/command-line/completion/command-object.js +7 -12
- package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +19 -25
- 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/graph/graph.d.ts +1 -0
- package/dist/src/command-line/graph/graph.js +15 -6
- package/dist/src/command-line/import/import.js +30 -40
- package/dist/src/command-line/init/ai-agent-prompts.d.ts +1 -1
- package/dist/src/command-line/init/ai-agent-prompts.js +12 -17
- package/dist/src/command-line/init/command-object.js +14 -4
- 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/integrated-workspace.js +2 -5
- package/dist/src/command-line/init/implementation/angular/legacy-angular-versions.js +5 -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 +9 -1
- 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 -0
- package/dist/src/command-line/init/init-v1.js +15 -18
- package/dist/src/command-line/init/init-v2.js +40 -57
- 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 +91 -0
- package/dist/src/command-line/migrate/execute-migration.js +474 -0
- 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 +33 -19
- package/dist/src/command-line/migrate/migrate.d.ts +29 -113
- package/dist/src/command-line/migrate/migrate.js +666 -664
- 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 +17 -21
- package/dist/src/command-line/nx-cloud/connect/view-logs.js +2 -0
- 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 +11 -17
- package/dist/src/command-line/release/index.d.ts +1 -1
- 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/git.js +1 -1
- package/dist/src/command-line/release/utils/release-graph.d.ts +20 -2
- package/dist/src/command-line/release/utils/release-graph.js +81 -21
- package/dist/src/command-line/release/utils/remote-release-clients/github.js +17 -23
- package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +14 -23
- package/dist/src/command-line/release/utils/resolve-semver-specifier.js +19 -41
- package/dist/src/command-line/release/utils/shared.d.ts +2 -2
- package/dist/src/command-line/release/version/release-group-processor.d.ts +24 -0
- package/dist/src/command-line/release/version/release-group-processor.js +80 -6
- package/dist/src/command-line/release/version/resolve-current-version.js +7 -10
- package/dist/src/command-line/release/version/version-actions.d.ts +27 -2
- package/dist/src/command-line/release/version/version-actions.js +9 -1
- package/dist/src/command-line/release/version.js +10 -6
- package/dist/src/command-line/reset/reset.js +6 -1
- package/dist/src/command-line/run/run-one.js +1 -0
- package/dist/src/command-line/run-many/run-many.js +1 -0
- package/dist/src/command-line/show/show-target/inputs.js +50 -153
- package/dist/src/command-line/show/show-target/outputs.js +48 -173
- package/dist/src/command-line/show/show-target/utils.d.ts +28 -0
- package/dist/src/command-line/show/show-target/utils.js +83 -3
- package/dist/src/command-line/watch/watch.js +13 -0
- package/dist/src/command-line/yargs-utils/shared-options.d.ts +2 -2
- package/dist/src/command-line/yargs-utils/shared-options.js +3 -1
- package/dist/src/commands-runner/create-command-graph.js +5 -0
- package/dist/src/config/misc-interfaces.d.ts +19 -7
- package/dist/src/config/nx-json.d.ts +5 -3
- 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 +52 -1
- package/dist/src/daemon/client/client.js +160 -36
- package/dist/src/daemon/client/daemon-environment.d.ts +17 -0
- package/dist/src/daemon/client/daemon-environment.js +110 -2
- package/dist/src/daemon/client/daemon-socket-messenger.js +4 -0
- package/dist/src/daemon/message-types/daemon-message.d.ts +32 -0
- package/dist/src/daemon/message-types/daemon-message.js +25 -0
- package/dist/src/daemon/server/file-watching/file-watcher-sockets.d.ts +5 -0
- package/dist/src/daemon/server/file-watching/file-watcher-sockets.js +16 -0
- package/dist/src/daemon/server/handle-tasks-execution-hooks.d.ts +1 -1
- package/dist/src/daemon/server/latest-nx.js +5 -2
- package/dist/src/daemon/server/server.js +31 -4
- package/dist/src/daemon/server/shutdown-utils.d.ts +5 -0
- package/dist/src/daemon/server/shutdown-utils.js +11 -4
- package/dist/src/daemon/socket-utils.d.ts +1 -0
- package/dist/src/daemon/socket-utils.js +24 -3
- package/dist/src/daemon/tmp-dir.d.ts +43 -3
- package/dist/src/daemon/tmp-dir.js +437 -15
- package/dist/src/devkit-internals.d.ts +105 -8
- package/dist/src/devkit-internals.js +223 -7
- package/dist/src/executors/run-commands/running-tasks.js +46 -29
- package/dist/src/generators/internal-utils/format-changed-files.d.ts +24 -0
- 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/generators/tree.d.ts +4 -2
- package/dist/src/generators/utils/nx-json.js +13 -3
- package/dist/src/hasher/check-task-files.d.ts +86 -0
- package/dist/src/hasher/check-task-files.js +378 -0
- 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.d.ts +12 -0
- package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +250 -0
- package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +50 -0
- package/dist/src/native/index.d.ts +37 -4
- package/dist/src/native/index.js +71 -28
- package/dist/src/native/native-bindings.js +3 -0
- package/dist/src/native/native-file-cache-location.d.ts +17 -1
- package/dist/src/native/native-file-cache-location.js +86 -12
- 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/get-cloud-options.js +5 -2
- package/dist/src/nx-cloud/utilities/onboarding.js +5 -2
- 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/bun-parser.js +43 -10
- 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/pnpm-parser.js +420 -64
- 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 +92 -12
- 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 +9 -5
- package/dist/src/plugins/js/project-graph/affected/npm-packages.js +51 -20
- package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +14 -4
- package/dist/src/project-graph/affected/affected-project-graph-models.d.ts +1 -1
- package/dist/src/project-graph/affected/affected-project-graph.d.ts +1 -1
- package/dist/src/project-graph/affected/affected-project-graph.js +2 -2
- package/dist/src/project-graph/affected/locators/project-glob-changes.js +5 -2
- package/dist/src/project-graph/build-project-graph.js +7 -1
- package/dist/src/project-graph/error-types.d.ts +12 -1
- package/dist/src/project-graph/error-types.js +27 -2
- package/dist/src/project-graph/file-utils.js +6 -1
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +1 -0
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +18 -1
- package/dist/src/project-graph/plugins/isolation/messaging.d.ts +16 -3
- package/dist/src/project-graph/plugins/isolation/messaging.js +3 -0
- package/dist/src/project-graph/plugins/isolation/plugin-worker.js +58 -8
- package/dist/src/project-graph/plugins/loaded-nx-plugin.js +1 -0
- package/dist/src/project-graph/project-graph.js +23 -0
- package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.d.ts +1 -0
- package/dist/src/project-graph/utils/project-configuration/name-substitution-manager.js +16 -2
- package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.d.ts +12 -8
- package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.js +30 -21
- package/dist/src/project-graph/utils/project-configuration/source-maps.d.ts +12 -5
- package/dist/src/project-graph/utils/project-configuration/source-maps.js +21 -7
- package/dist/src/project-graph/utils/project-configuration/target-defaults.d.ts +1 -1
- package/dist/src/project-graph/utils/project-configuration/target-defaults.js +26 -27
- package/dist/src/project-graph/utils/project-configuration/target-merging.js +50 -8
- package/dist/src/project-graph/utils/project-configuration/target-normalization.js +149 -6
- package/dist/src/project-graph/utils/project-configuration/utils.d.ts +15 -0
- package/dist/src/project-graph/utils/project-configuration/utils.js +42 -6
- package/dist/src/project-graph/utils/project-configuration-utils.d.ts +15 -12
- package/dist/src/project-graph/utils/project-configuration-utils.js +79 -99
- 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-analysis.d.ts +9 -4
- package/dist/src/tasks-runner/life-cycles/performance-life-cycle.js +5 -4
- package/dist/src/tasks-runner/life-cycles/performance-report.d.ts +28 -8
- package/dist/src/tasks-runner/life-cycles/performance-report.js +117 -30
- 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-terminal.d.ts +17 -3
- package/dist/src/tasks-runner/pseudo-terminal.js +22 -10
- package/dist/src/tasks-runner/run-command.js +28 -35
- 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 +9 -0
- package/dist/src/tasks-runner/task-env.js +31 -4
- package/dist/src/tasks-runner/task-orchestrator.d.ts +72 -1
- package/dist/src/tasks-runner/task-orchestrator.js +182 -18
- package/dist/src/tasks-runner/utils.js +2 -6
- package/dist/src/utils/acknowledge-build-scripts.js +7 -5
- 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.d.ts +0 -6
- package/dist/src/utils/analytics-prompt.js +4 -58
- package/dist/src/utils/assert-workspace-validity.js +7 -2
- 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/command-line-utils.js +30 -20
- package/dist/src/utils/exit-codes.d.ts +9 -0
- package/dist/src/utils/exit-codes.js +19 -0
- package/dist/src/utils/fileutils.d.ts +5 -0
- package/dist/src/utils/fileutils.js +7 -2
- 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-revision.d.ts +12 -0
- package/dist/src/utils/git-revision.js +25 -0
- package/dist/src/utils/git-utils.d.ts +48 -2
- package/dist/src/utils/git-utils.js +220 -14
- package/dist/src/utils/git-worktrees.d.ts +30 -0
- package/dist/src/utils/git-worktrees.js +212 -0
- package/dist/src/utils/ignore.d.ts +170 -1
- package/dist/src/utils/ignore.js +263 -11
- package/dist/src/utils/long-running-target.d.ts +10 -0
- package/dist/src/utils/long-running-target.js +19 -0
- package/dist/src/utils/min-release-age/behavior/bun.js +7 -11
- package/dist/src/utils/min-release-age/behavior/npm.js +5 -2
- package/dist/src/utils/min-release-age/packument.js +1 -1
- package/dist/src/utils/nx-console-prompt.js +3 -6
- package/dist/src/utils/nx-tmp-dir.d.ts +18 -0
- package/dist/src/utils/nx-tmp-dir.js +40 -0
- 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 +132 -0
- package/dist/src/utils/owned-private-dir.js +323 -0
- package/dist/src/utils/package-json.d.ts +2 -0
- package/dist/src/utils/package-json.js +11 -7
- package/dist/src/utils/package-manager-config/bunfig.d.ts +14 -0
- package/dist/src/utils/package-manager-config/bunfig.js +49 -0
- package/dist/src/utils/package-manager-config/npmrc.d.ts +23 -0
- package/dist/src/utils/package-manager-config/npmrc.js +124 -0
- package/dist/src/utils/package-manager-config/pnpm-config.d.ts +17 -0
- package/dist/src/utils/package-manager-config/pnpm-config.js +60 -0
- package/dist/src/utils/package-manager.d.ts +23 -2
- package/dist/src/utils/package-manager.js +268 -44
- package/dist/src/utils/params.d.ts +7 -1
- package/dist/src/utils/params.js +64 -6
- 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/provenance.js +6 -14
- package/dist/src/utils/registry-config/bun.d.ts +2 -0
- package/dist/src/utils/registry-config/bun.js +257 -0
- package/dist/src/utils/registry-config/index.d.ts +13 -0
- package/dist/src/utils/registry-config/index.js +102 -0
- package/dist/src/utils/registry-config/pnpm.d.ts +2 -0
- package/dist/src/utils/registry-config/pnpm.js +1551 -0
- package/dist/src/utils/registry-config/utils.d.ts +195 -0
- package/dist/src/utils/registry-config/utils.js +496 -0
- package/dist/src/utils/registry-config/yarn-berry.d.ts +2 -0
- package/dist/src/utils/registry-config/yarn-berry.js +612 -0
- package/dist/src/utils/registry-config/yarn-classic.d.ts +2 -0
- package/dist/src/utils/registry-config/yarn-classic.js +1001 -0
- package/dist/src/utils/safe-spawn.d.ts +24 -0
- package/dist/src/utils/safe-spawn.js +104 -0
- package/dist/src/utils/shell-quoting.d.ts +15 -0
- package/dist/src/utils/shell-quoting.js +35 -0
- package/dist/src/utils/wait-for-socket-connection.d.ts +11 -0
- package/dist/src/utils/wait-for-socket-connection.js +14 -8
- package/dist/src/utils/workspace-id.d.ts +20 -0
- package/dist/src/utils/workspace-id.js +54 -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/migrations.json +6 -0
- package/package.json +29 -19
- package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.d.ts +0 -19
- package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +0 -81
- package/dist/src/utils/is-using-prettier.d.ts +0 -3
- package/dist/src/utils/is-using-prettier.js +0 -62
- package/dist/src/utils/min-release-age/npmrc.d.ts +0 -15
- package/dist/src/utils/min-release-age/npmrc.js +0 -45
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Tree } from '../../generators/tree';
|
|
2
|
+
/**
|
|
3
|
+
* Config filenames prettier discovers. Exported because generator setup must
|
|
4
|
+
* agree with detection - a format missing from one side gets a second,
|
|
5
|
+
* redundant config written next to it.
|
|
6
|
+
* https://prettier.io/docs/configuration
|
|
7
|
+
*/
|
|
8
|
+
export declare const prettierConfigFiles: string[];
|
|
9
|
+
export declare function isUsingPrettier(root: string): boolean;
|
|
10
|
+
export declare function isUsingPrettierInTree(tree: Tree): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Keeps only the files prettier can format. oxfmt needs no equivalent - it
|
|
13
|
+
* silently skips file types it does not handle.
|
|
14
|
+
*/
|
|
15
|
+
export declare function filterToPrettierSupportedFiles(files: string[]): Promise<string[]>;
|
|
16
|
+
export declare function writeWithPrettier(patterns: string[], cwd?: string): void;
|
|
17
|
+
export declare function checkWithPrettier(patterns: string[]): Promise<string[]>;
|
|
18
|
+
export declare function getPrettierPath(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Quote a pattern for prettier's shell-based exec calls; oxfmt uses execFile
|
|
21
|
+
* and takes raw paths.
|
|
22
|
+
*
|
|
23
|
+
* Exported so `nx format` can size its chunks against the quoted length -
|
|
24
|
+
* patterns are chunked before they get here, and quoting grows each one.
|
|
25
|
+
*/
|
|
26
|
+
export declare function quoteForShell(pattern: string): string;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prettierConfigFiles = void 0;
|
|
4
|
+
exports.isUsingPrettier = isUsingPrettier;
|
|
5
|
+
exports.isUsingPrettierInTree = isUsingPrettierInTree;
|
|
6
|
+
exports.filterToPrettierSupportedFiles = filterToPrettierSupportedFiles;
|
|
7
|
+
exports.writeWithPrettier = writeWithPrettier;
|
|
8
|
+
exports.checkWithPrettier = checkWithPrettier;
|
|
9
|
+
exports.getPrettierPath = getPrettierPath;
|
|
10
|
+
exports.quoteForShell = quoteForShell;
|
|
11
|
+
const node_child_process_1 = require("node:child_process");
|
|
12
|
+
const node_fs_1 = require("node:fs");
|
|
13
|
+
const node_path_1 = require("node:path");
|
|
14
|
+
const semver_1 = require("semver");
|
|
15
|
+
const json_1 = require("../../generators/utils/json");
|
|
16
|
+
const fileutils_1 = require("../fileutils");
|
|
17
|
+
const handle_import_1 = require("../handle-import");
|
|
18
|
+
const package_json_1 = require("../package-json");
|
|
19
|
+
const shared_1 = require("./shared");
|
|
20
|
+
/**
|
|
21
|
+
* Config filenames prettier discovers. Exported because generator setup must
|
|
22
|
+
* agree with detection - a format missing from one side gets a second,
|
|
23
|
+
* redundant config written next to it.
|
|
24
|
+
* https://prettier.io/docs/configuration
|
|
25
|
+
*/
|
|
26
|
+
exports.prettierConfigFiles = [
|
|
27
|
+
'.prettierrc',
|
|
28
|
+
'.prettierrc.json',
|
|
29
|
+
'.prettierrc.yml',
|
|
30
|
+
'.prettierrc.yaml',
|
|
31
|
+
'.prettierrc.json5',
|
|
32
|
+
'.prettierrc.js',
|
|
33
|
+
'prettier.config.js',
|
|
34
|
+
'.prettierrc.ts',
|
|
35
|
+
'prettier.config.ts',
|
|
36
|
+
'.prettierrc.mjs',
|
|
37
|
+
'prettier.config.mjs',
|
|
38
|
+
'.prettierrc.mts',
|
|
39
|
+
'prettier.config.mts',
|
|
40
|
+
'.prettierrc.cjs',
|
|
41
|
+
'prettier.config.cjs',
|
|
42
|
+
'.prettierrc.cts',
|
|
43
|
+
'prettier.config.cts',
|
|
44
|
+
'.prettierrc.toml',
|
|
45
|
+
];
|
|
46
|
+
function isUsingPrettier(root) {
|
|
47
|
+
for (const file of exports.prettierConfigFiles) {
|
|
48
|
+
if ((0, node_fs_1.existsSync)((0, node_path_1.join)(root, file))) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Even if no file is present, it is possible the user is configuring prettier via their package.json
|
|
53
|
+
const packageJsonPath = (0, node_path_1.join)(root, 'package.json');
|
|
54
|
+
if ((0, node_fs_1.existsSync)(packageJsonPath)) {
|
|
55
|
+
const packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
|
|
56
|
+
if (packageJson.prettier) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
function isUsingPrettierInTree(tree) {
|
|
63
|
+
for (const file of exports.prettierConfigFiles) {
|
|
64
|
+
if (tree.exists(file)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Even if no file is present, it is possible the user is configuring prettier via their package.json
|
|
69
|
+
if (tree.exists('package.json')) {
|
|
70
|
+
const packageJson = (0, json_1.readJson)(tree, 'package.json');
|
|
71
|
+
if (packageJson.prettier) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Keeps only the files prettier can format. oxfmt needs no equivalent - it
|
|
79
|
+
* silently skips file types it does not handle.
|
|
80
|
+
*/
|
|
81
|
+
async function filterToPrettierSupportedFiles(files) {
|
|
82
|
+
const prettier = await (0, handle_import_1.handleImport)('prettier');
|
|
83
|
+
const supportInfo = await prettier.getSupportInfo();
|
|
84
|
+
const supportedExtensions = new Set(supportInfo.languages
|
|
85
|
+
.flatMap((language) => language.extensions)
|
|
86
|
+
.filter((extension) => !!extension));
|
|
87
|
+
// Prettier matches ~30 files by *name* rather than extension (`.swcrc`,
|
|
88
|
+
// `Jakefile`). It publishes that list next to the extensions, so read it
|
|
89
|
+
// rather than hardcoding.
|
|
90
|
+
const supportedFilenames = new Set(supportInfo.languages.flatMap((language) => language.filenames ?? []));
|
|
91
|
+
return files.filter((file) => supportedExtensions.has((0, node_path_1.extname)(file)) ||
|
|
92
|
+
supportedFilenames.has((0, node_path_1.basename)(file)));
|
|
93
|
+
}
|
|
94
|
+
function writeWithPrettier(patterns,
|
|
95
|
+
// Defaults to the caller's cwd. `nx init` sets it so it can pass paths
|
|
96
|
+
// relative to the repo root rather than absolute ones the user has to read.
|
|
97
|
+
cwd) {
|
|
98
|
+
if (patterns.length === 0) {
|
|
99
|
+
// Prettier with no file arguments reads stdin, and `stdio: [0, 1, 2]` hands
|
|
100
|
+
// it nx's own - from a terminal it blocks forever with nothing on screen. At
|
|
101
|
+
// EOF it exits 0 under `--list-different` and 2 (which `execSync` throws on)
|
|
102
|
+
// without it, so which failure you get depends on `shouldUseListDifferent`.
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const prettierPath = getPrettierPath();
|
|
106
|
+
const listDifferentArg = shouldUseListDifferent() ? '--list-different ' : '';
|
|
107
|
+
// No `--parser json` special case for `.swcrc`: prettier's own language table
|
|
108
|
+
// maps it to the json parser, so it formats correctly on its own (measured).
|
|
109
|
+
// Splitting the batch also meant one of the two spawns could receive zero
|
|
110
|
+
// files, which is the error above.
|
|
111
|
+
(0, node_child_process_1.execSync)(`node ${quoteForShell(prettierPath)} --write ${listDifferentArg}-- ${patterns
|
|
112
|
+
.map(quoteForShell)
|
|
113
|
+
.join(' ')}`, {
|
|
114
|
+
cwd,
|
|
115
|
+
stdio: [0, 1, 2],
|
|
116
|
+
windowsHide: true,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function checkWithPrettier(patterns) {
|
|
120
|
+
const prettierPath = getPrettierPath();
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
(0, node_child_process_1.exec)(`node ${quoteForShell(prettierPath)} --list-different -- ${patterns
|
|
123
|
+
.map(quoteForShell)
|
|
124
|
+
.join(' ')}`, { encoding: 'utf-8', windowsHide: true, maxBuffer: shared_1.FORMATTER_MAX_BUFFER }, (error, stdout) => {
|
|
125
|
+
if (error) {
|
|
126
|
+
// As the oxfmt sibling: a spawn failure, kill or maxBuffer overrun reports a
|
|
127
|
+
// string `code` or none. Prettier signals "files differ" numerically, so
|
|
128
|
+
// treating these as a file list would pass `format:check` on a formatter
|
|
129
|
+
// that never ran.
|
|
130
|
+
if (typeof error['code'] !== 'number') {
|
|
131
|
+
reject(new Error(`prettier could not be run to completion (${error['code'] ?? error.signal ?? 'unknown'}): ${error.message}`));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
// Only `Mismatch` means "files differ", as in `checkWithOxfmt`. `Failure`
|
|
135
|
+
// still prints the files prettier got through - measured, one differing plus
|
|
136
|
+
// one unparseable exits 2 with the differing file on stdout - so reading
|
|
137
|
+
// stdout there would swallow the syntax error.
|
|
138
|
+
if (error['code'] !== 1 /* PrettierExitCode.Mismatch */ ||
|
|
139
|
+
stdout.length === 0) {
|
|
140
|
+
reject(error);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
resolve(stdout.trim().split('\n'));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
resolve([]);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
let prettierPath;
|
|
152
|
+
function getPrettierPath() {
|
|
153
|
+
if (prettierPath) {
|
|
154
|
+
return prettierPath;
|
|
155
|
+
}
|
|
156
|
+
const { packageJson, path: packageJsonPath } = (0, package_json_1.readModulePackageJson)('prettier');
|
|
157
|
+
const bin = packageJson.bin;
|
|
158
|
+
const binPath = typeof bin === 'string' ? bin : bin?.['prettier'];
|
|
159
|
+
if (!binPath) {
|
|
160
|
+
throw new Error(`Could not find prettier binary in ${packageJsonPath}`);
|
|
161
|
+
}
|
|
162
|
+
prettierPath = (0, node_path_1.resolve)((0, node_path_1.dirname)(packageJsonPath), binPath);
|
|
163
|
+
return prettierPath;
|
|
164
|
+
}
|
|
165
|
+
let useListDifferent;
|
|
166
|
+
/**
|
|
167
|
+
* Determines if --list-different should be used with --write.
|
|
168
|
+
* Prettier 4+ and 3.6.x with experimental CLI don't support combining these flags.
|
|
169
|
+
*/
|
|
170
|
+
function shouldUseListDifferent() {
|
|
171
|
+
if (useListDifferent !== undefined) {
|
|
172
|
+
return useListDifferent;
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
const { packageJson } = (0, package_json_1.readModulePackageJson)('prettier');
|
|
176
|
+
const prettierMajor = (0, semver_1.major)(packageJson.version);
|
|
177
|
+
const isExperimentalCli = process.env.PRETTIER_EXPERIMENTAL_CLI === '1';
|
|
178
|
+
useListDifferent = prettierMajor < 4 && !isExperimentalCli;
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
useListDifferent = false;
|
|
182
|
+
}
|
|
183
|
+
return useListDifferent;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Quote a pattern for prettier's shell-based exec calls; oxfmt uses execFile
|
|
187
|
+
* and takes raw paths.
|
|
188
|
+
*
|
|
189
|
+
* Exported so `nx format` can size its chunks against the quoted length -
|
|
190
|
+
* patterns are chunked before they get here, and quoting grows each one.
|
|
191
|
+
*/
|
|
192
|
+
function quoteForShell(pattern) {
|
|
193
|
+
// Interpolated into a command string, so every character special *inside
|
|
194
|
+
// double quotes* needs escaping, not just `$`: a backtick substitutes, `"`
|
|
195
|
+
// closes the quoting, `\` escapes what follows. One pass over the original,
|
|
196
|
+
// since `String.replace` never re-scans what it inserted.
|
|
197
|
+
const escaped = process.platform !== 'win32'
|
|
198
|
+
? pattern.replace(/([\\"`$])/g, '\\$1')
|
|
199
|
+
: pattern;
|
|
200
|
+
return `"${escaped}"`;
|
|
201
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FORMATTER_MAX_BUFFER = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Formatters list every mismatching path on stdout, which overruns Node's 1MB
|
|
6
|
+
* default on a large workspace.
|
|
7
|
+
*/
|
|
8
|
+
exports.FORMATTER_MAX_BUFFER = 50 * 1024 * 1024;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git parses any argument beginning with `-` as an option rather than a
|
|
3
|
+
* revision, so a flag-shaped revision could smuggle options such as
|
|
4
|
+
* `--upload-pack` into the git commands Nx runs.
|
|
5
|
+
*/
|
|
6
|
+
export declare function assertValidGitRevision(revision: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* For refs Nx itself recorded from `git rev-parse` and later read back off
|
|
9
|
+
* disk, where anything other than a commit sha means the value was tampered
|
|
10
|
+
* with rather than that the user picked an unusual revision.
|
|
11
|
+
*/
|
|
12
|
+
export declare function assertValidGitSha(sha: string): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertValidGitRevision = assertValidGitRevision;
|
|
4
|
+
exports.assertValidGitSha = assertValidGitSha;
|
|
5
|
+
/**
|
|
6
|
+
* Git parses any argument beginning with `-` as an option rather than a
|
|
7
|
+
* revision, so a flag-shaped revision could smuggle options such as
|
|
8
|
+
* `--upload-pack` into the git commands Nx runs.
|
|
9
|
+
*/
|
|
10
|
+
function assertValidGitRevision(revision) {
|
|
11
|
+
if (revision.startsWith('-')) {
|
|
12
|
+
throw new Error(`Invalid git revision: "${revision}". Git revisions cannot start with "-".`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const COMMIT_SHA = /^[0-9a-f]{7,40}$/i;
|
|
16
|
+
/**
|
|
17
|
+
* For refs Nx itself recorded from `git rev-parse` and later read back off
|
|
18
|
+
* disk, where anything other than a commit sha means the value was tampered
|
|
19
|
+
* with rather than that the user picked an unusual revision.
|
|
20
|
+
*/
|
|
21
|
+
function assertValidGitSha(sha) {
|
|
22
|
+
if (!COMMIT_SHA.test(sha)) {
|
|
23
|
+
throw new Error(`Invalid git commit sha: "${sha}". Expected a hexadecimal commit sha.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -36,9 +36,37 @@ export interface VcsRemoteInfo {
|
|
|
36
36
|
}
|
|
37
37
|
export declare function parseVcsRemoteUrl(url: string): VcsRemoteInfo | null;
|
|
38
38
|
export declare function getVcsRemoteInfo(directory?: string): VcsRemoteInfo | null;
|
|
39
|
+
export declare function getGitRootPath(cwd?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Path of `directory` relative to its git root, posix-separated so it is
|
|
42
|
+
* identical on every OS, and '' when the directory is the git root itself.
|
|
43
|
+
* Null outside a git repository.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getGitRootRelativePath(directory: string): string | null;
|
|
46
|
+
/** A shallow clone's truncated history has no stable root commit. */
|
|
47
|
+
export declare function isShallowRepository(directory?: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* SHA of the repository's first commit. Merged unrelated histories leave
|
|
50
|
+
* several root commits — the sorted-first one is picked so every clone
|
|
51
|
+
* agrees. Null when there are no commits, or outside a git repository.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getFirstCommitSha(directory?: string): string | null;
|
|
39
54
|
export declare function isGitRepository(directory?: string): boolean;
|
|
55
|
+
export type GitRepositoryStatus = 'git' | 'not-git' | 'unknown';
|
|
56
|
+
/**
|
|
57
|
+
* Like `isGitRepository`, but separates "this is not a git repository" from
|
|
58
|
+
* "the probe itself failed" (git not installed, permissions). Callers gating
|
|
59
|
+
* destructive or unverifiable behavior on the answer must fail closed on
|
|
60
|
+
* 'unknown' instead of reading a broken probe as a missing repository.
|
|
61
|
+
*/
|
|
62
|
+
export declare function getGitRepositoryStatus(directory?: string): GitRepositoryStatus;
|
|
40
63
|
export declare function getGitCurrentBranch(directory?: string): string | null;
|
|
41
|
-
export declare function
|
|
64
|
+
export declare function getGitRemoteNames(directory?: string): string[];
|
|
65
|
+
export type WorkingTreeStatus = 'dirty' | 'clean' | 'unknown';
|
|
66
|
+
export declare function getWorkingTreeStatus(directory?: string, excludePaths?: string[]): WorkingTreeStatus;
|
|
67
|
+
export declare function hasUncommittedChanges(directory?: string, excludePaths?: string[]): boolean;
|
|
68
|
+
export type PathCommitExposure = 'ignored' | 'tracked' | 'unignored' | 'unknown';
|
|
69
|
+
export declare function getPathCommitExposure(dirPath: string, directory?: string): PathCommitExposure;
|
|
42
70
|
export declare function getUncommittedChangesSnapshot(directory?: string): string;
|
|
43
71
|
export declare function commitChanges(commitMessage: string, directory?: string): string | null;
|
|
44
72
|
/**
|
|
@@ -51,6 +79,24 @@ export declare function commitChanges(commitMessage: string, directory?: string)
|
|
|
51
79
|
* Returns `null` (rather than throwing) when the commit itself succeeded
|
|
52
80
|
* but `git rev-parse HEAD` failed transiently — by contract the diff is
|
|
53
81
|
* no longer in the working tree, so callers must NOT report it as such.
|
|
82
|
+
*
|
|
83
|
+
* `excludePaths` are `directory`-relative paths the commit must not capture,
|
|
84
|
+
* whatever the ignore rules say. Their working-tree files are left intact;
|
|
85
|
+
* only their index entries are put back to HEAD's state. Paths come from
|
|
86
|
+
* callers' own constants, never from user input.
|
|
54
87
|
*/
|
|
55
|
-
export declare function tryCommitChanges(commitMessage: string, directory: string): string | null;
|
|
88
|
+
export declare function tryCommitChanges(commitMessage: string, directory: string, excludePaths?: string[]): string | null;
|
|
56
89
|
export declare function getLatestCommitSha(directory?: string): string | null;
|
|
90
|
+
/**
|
|
91
|
+
* The shape of a recorded `git rev-parse` output: 40 hex chars, or 64 in a
|
|
92
|
+
* sha256 repository. Anything a caller persists and later interpolates into a
|
|
93
|
+
* command line has to be checked against this first.
|
|
94
|
+
*/
|
|
95
|
+
export declare const GIT_SHA: RegExp;
|
|
96
|
+
/**
|
|
97
|
+
* Whether `ancestor` is reachable from `descendant`, i.e. resetting to
|
|
98
|
+
* `descendant` keeps `ancestor` in history. Returns false when the answer
|
|
99
|
+
* cannot be established (invalid input, not a repository, unknown commits),
|
|
100
|
+
* so callers treat an unverifiable commit as not preserved.
|
|
101
|
+
*/
|
|
102
|
+
export declare function isAncestorCommit(ancestor: string, descendant: string, directory?: string): boolean;
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GitRepository = void 0;
|
|
3
|
+
exports.GIT_SHA = exports.GitRepository = void 0;
|
|
4
4
|
exports.cloneFromUpstream = cloneFromUpstream;
|
|
5
5
|
exports.parseVcsRemoteUrl = parseVcsRemoteUrl;
|
|
6
6
|
exports.getVcsRemoteInfo = getVcsRemoteInfo;
|
|
7
|
+
exports.getGitRootPath = getGitRootPath;
|
|
8
|
+
exports.getGitRootRelativePath = getGitRootRelativePath;
|
|
9
|
+
exports.isShallowRepository = isShallowRepository;
|
|
10
|
+
exports.getFirstCommitSha = getFirstCommitSha;
|
|
7
11
|
exports.isGitRepository = isGitRepository;
|
|
12
|
+
exports.getGitRepositoryStatus = getGitRepositoryStatus;
|
|
8
13
|
exports.getGitCurrentBranch = getGitCurrentBranch;
|
|
14
|
+
exports.getGitRemoteNames = getGitRemoteNames;
|
|
15
|
+
exports.getWorkingTreeStatus = getWorkingTreeStatus;
|
|
9
16
|
exports.hasUncommittedChanges = hasUncommittedChanges;
|
|
17
|
+
exports.getPathCommitExposure = getPathCommitExposure;
|
|
10
18
|
exports.getUncommittedChangesSnapshot = getUncommittedChangesSnapshot;
|
|
11
19
|
exports.commitChanges = commitChanges;
|
|
12
20
|
exports.tryCommitChanges = tryCommitChanges;
|
|
13
21
|
exports.getLatestCommitSha = getLatestCommitSha;
|
|
22
|
+
exports.isAncestorCommit = isAncestorCommit;
|
|
14
23
|
const tslib_1 = require("tslib");
|
|
15
24
|
const child_process_1 = require("child_process");
|
|
16
25
|
const crypto = tslib_1.__importStar(require("crypto"));
|
|
@@ -49,12 +58,7 @@ class GitRepository {
|
|
|
49
58
|
this.root = this.getGitRootPath(this.directory);
|
|
50
59
|
}
|
|
51
60
|
getGitRootPath(cwd) {
|
|
52
|
-
return (
|
|
53
|
-
cwd,
|
|
54
|
-
windowsHide: true,
|
|
55
|
-
})
|
|
56
|
-
.toString()
|
|
57
|
-
.trim();
|
|
61
|
+
return getGitRootPath(cwd);
|
|
58
62
|
}
|
|
59
63
|
async hasUncommittedChanges() {
|
|
60
64
|
const data = await this.execGit(['status', '--porcelain']);
|
|
@@ -297,6 +301,65 @@ function getVcsRemoteInfo(directory) {
|
|
|
297
301
|
return null;
|
|
298
302
|
}
|
|
299
303
|
}
|
|
304
|
+
function getGitRootPath(cwd) {
|
|
305
|
+
return (0, child_process_1.execFileSync)('git', ['rev-parse', '--show-toplevel'], {
|
|
306
|
+
cwd,
|
|
307
|
+
windowsHide: true,
|
|
308
|
+
})
|
|
309
|
+
.toString()
|
|
310
|
+
.trim();
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Path of `directory` relative to its git root, posix-separated so it is
|
|
314
|
+
* identical on every OS, and '' when the directory is the git root itself.
|
|
315
|
+
* Null outside a git repository.
|
|
316
|
+
*/
|
|
317
|
+
function getGitRootRelativePath(directory) {
|
|
318
|
+
try {
|
|
319
|
+
return (0, path_1.relative)(getGitRootPath(directory), directory)
|
|
320
|
+
.split(path_1.sep)
|
|
321
|
+
.join(path_1.posix.sep);
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/** A shallow clone's truncated history has no stable root commit. */
|
|
328
|
+
function isShallowRepository(directory) {
|
|
329
|
+
try {
|
|
330
|
+
return ((0, child_process_1.execFileSync)('git', ['rev-parse', '--is-shallow-repository'], {
|
|
331
|
+
encoding: 'utf8',
|
|
332
|
+
stdio: 'pipe',
|
|
333
|
+
cwd: directory,
|
|
334
|
+
windowsHide: true,
|
|
335
|
+
}).trim() === 'true');
|
|
336
|
+
}
|
|
337
|
+
catch {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* SHA of the repository's first commit. Merged unrelated histories leave
|
|
343
|
+
* several root commits — the sorted-first one is picked so every clone
|
|
344
|
+
* agrees. Null when there are no commits, or outside a git repository.
|
|
345
|
+
*/
|
|
346
|
+
function getFirstCommitSha(directory) {
|
|
347
|
+
try {
|
|
348
|
+
const roots = (0, child_process_1.execFileSync)('git', ['rev-list', '--max-parents=0', 'HEAD'], {
|
|
349
|
+
encoding: 'utf8',
|
|
350
|
+
stdio: 'pipe',
|
|
351
|
+
cwd: directory,
|
|
352
|
+
windowsHide: true,
|
|
353
|
+
})
|
|
354
|
+
.trim()
|
|
355
|
+
.split(/\r?\n/)
|
|
356
|
+
.filter(Boolean);
|
|
357
|
+
return roots.sort()[0] ?? null;
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
300
363
|
function isGitRepository(directory) {
|
|
301
364
|
try {
|
|
302
365
|
(0, child_process_1.execSync)('git rev-parse --is-inside-work-tree', {
|
|
@@ -310,6 +373,29 @@ function isGitRepository(directory) {
|
|
|
310
373
|
return false;
|
|
311
374
|
}
|
|
312
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* Like `isGitRepository`, but separates "this is not a git repository" from
|
|
378
|
+
* "the probe itself failed" (git not installed, permissions). Callers gating
|
|
379
|
+
* destructive or unverifiable behavior on the answer must fail closed on
|
|
380
|
+
* 'unknown' instead of reading a broken probe as a missing repository.
|
|
381
|
+
*/
|
|
382
|
+
function getGitRepositoryStatus(directory) {
|
|
383
|
+
try {
|
|
384
|
+
(0, child_process_1.execSync)('git rev-parse --is-inside-work-tree', {
|
|
385
|
+
stdio: 'pipe',
|
|
386
|
+
cwd: directory,
|
|
387
|
+
windowsHide: true,
|
|
388
|
+
// Force untranslated messages; the classification matches on the
|
|
389
|
+
// English "not a git repository".
|
|
390
|
+
env: { ...process.env, LC_ALL: 'C' },
|
|
391
|
+
});
|
|
392
|
+
return 'git';
|
|
393
|
+
}
|
|
394
|
+
catch (err) {
|
|
395
|
+
const stderr = err?.stderr?.toString() ?? '';
|
|
396
|
+
return /not a git repository/i.test(stderr) ? 'not-git' : 'unknown';
|
|
397
|
+
}
|
|
398
|
+
}
|
|
313
399
|
// Checked-out branch name, or null when there isn't one to act on: a detached
|
|
314
400
|
// HEAD reports the literal "HEAD" (treated as no branch), and any git error
|
|
315
401
|
// (not a repo, no commits yet) also yields null.
|
|
@@ -327,21 +413,94 @@ function getGitCurrentBranch(directory) {
|
|
|
327
413
|
return null;
|
|
328
414
|
}
|
|
329
415
|
}
|
|
416
|
+
// Names of the remotes configured in the repository, empty when there are
|
|
417
|
+
// none or the probe itself failed.
|
|
418
|
+
function getGitRemoteNames(directory) {
|
|
419
|
+
try {
|
|
420
|
+
return (0, child_process_1.execSync)('git remote', {
|
|
421
|
+
encoding: 'utf8',
|
|
422
|
+
cwd: directory,
|
|
423
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
424
|
+
windowsHide: true,
|
|
425
|
+
})
|
|
426
|
+
.split('\n')
|
|
427
|
+
.map((name) => name.trim())
|
|
428
|
+
.filter(Boolean);
|
|
429
|
+
}
|
|
430
|
+
catch {
|
|
431
|
+
return [];
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
// Tri-state working-tree probe: 'unknown' means the probe itself failed (git
|
|
435
|
+
// missing, spawn failure, permissions), not that the tree is clean. Callers
|
|
436
|
+
// that gate destructive actions on tree cleanliness must treat 'unknown' as
|
|
437
|
+
// unsafe rather than clean.
|
|
438
|
+
// `excludePaths` are left out of the probe the way `tryCommitChanges` leaves
|
|
439
|
+
// them out of the commit, so a tree dirty only under them reads as clean. An
|
|
440
|
+
// exclude-only pathspec still covers the whole tree, matching `git add -A`.
|
|
441
|
+
function getWorkingTreeStatus(directory, excludePaths = []) {
|
|
442
|
+
const pathspecs = excludePaths
|
|
443
|
+
.map((excludePath) => ` ":(exclude)${excludePath}"`)
|
|
444
|
+
.join('');
|
|
445
|
+
try {
|
|
446
|
+
const out = (0, child_process_1.execSync)(`git status --porcelain${pathspecs ? ` --${pathspecs}` : ''}`, {
|
|
447
|
+
encoding: 'utf8',
|
|
448
|
+
cwd: directory,
|
|
449
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
450
|
+
windowsHide: true,
|
|
451
|
+
});
|
|
452
|
+
return out.trim() === '' ? 'clean' : 'dirty';
|
|
453
|
+
}
|
|
454
|
+
catch {
|
|
455
|
+
return 'unknown';
|
|
456
|
+
}
|
|
457
|
+
}
|
|
330
458
|
// Sync companion to `GitRepository.hasUncommittedChanges` for callers that
|
|
331
|
-
// can't drop into the async class
|
|
332
|
-
//
|
|
333
|
-
function hasUncommittedChanges(directory) {
|
|
459
|
+
// can't drop into the async class. A failed probe reads as false; callers for
|
|
460
|
+
// whom that tolerance is unsafe use `getWorkingTreeStatus` instead.
|
|
461
|
+
function hasUncommittedChanges(directory, excludePaths = []) {
|
|
462
|
+
return getWorkingTreeStatus(directory, excludePaths) === 'dirty';
|
|
463
|
+
}
|
|
464
|
+
// Classifies whether `git add -A` commits made in `directory` can sweep in
|
|
465
|
+
// the directory at `dirPath`. Tracked files stay committable no matter what
|
|
466
|
+
// the ignore rules say (ignore rules never apply to tracked files), so
|
|
467
|
+
// `git ls-files` decides 'tracked' first; `git check-ignore` then splits the
|
|
468
|
+
// untracked remainder into 'ignored' (covered) vs 'unignored' (no
|
|
469
|
+
// coverage). 'unknown' means the probe itself failed (not a git repository,
|
|
470
|
+
// git missing); callers gating destructive behavior on the result must
|
|
471
|
+
// treat it as unsafe.
|
|
472
|
+
function getPathCommitExposure(dirPath, directory) {
|
|
334
473
|
try {
|
|
335
|
-
const
|
|
474
|
+
const tracked = (0, child_process_1.execSync)(`git ls-files -- ${dirPath}`, {
|
|
336
475
|
encoding: 'utf8',
|
|
337
476
|
cwd: directory,
|
|
338
477
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
339
478
|
windowsHide: true,
|
|
340
479
|
});
|
|
341
|
-
|
|
480
|
+
if (tracked.trim() !== '') {
|
|
481
|
+
return 'tracked';
|
|
482
|
+
}
|
|
342
483
|
}
|
|
343
484
|
catch {
|
|
344
|
-
return
|
|
485
|
+
return 'unknown';
|
|
486
|
+
}
|
|
487
|
+
// Query with a trailing slash so git treats the path as a directory even
|
|
488
|
+
// when it does not exist on disk yet: a directory-only ignore rule (a
|
|
489
|
+
// trailing-slash .gitignore entry) does not match a bare query for an
|
|
490
|
+
// absent path, which would misreport covered workspaces as unignored.
|
|
491
|
+
const asDir = dirPath.endsWith('/') ? dirPath : `${dirPath}/`;
|
|
492
|
+
try {
|
|
493
|
+
(0, child_process_1.execSync)(`git check-ignore -q -- ${asDir}`, {
|
|
494
|
+
cwd: directory,
|
|
495
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
496
|
+
windowsHide: true,
|
|
497
|
+
});
|
|
498
|
+
return 'ignored';
|
|
499
|
+
}
|
|
500
|
+
catch (e) {
|
|
501
|
+
// check-ignore exits 1 for "not ignored"; anything else is a probe
|
|
502
|
+
// failure.
|
|
503
|
+
return e?.status === 1 ? 'unignored' : 'unknown';
|
|
345
504
|
}
|
|
346
505
|
}
|
|
347
506
|
// Returns a content-sensitive sha1 snapshot of the working tree state for
|
|
@@ -445,8 +604,13 @@ function commitChanges(commitMessage, directory) {
|
|
|
445
604
|
* Returns `null` (rather than throwing) when the commit itself succeeded
|
|
446
605
|
* but `git rev-parse HEAD` failed transiently — by contract the diff is
|
|
447
606
|
* no longer in the working tree, so callers must NOT report it as such.
|
|
607
|
+
*
|
|
608
|
+
* `excludePaths` are `directory`-relative paths the commit must not capture,
|
|
609
|
+
* whatever the ignore rules say. Their working-tree files are left intact;
|
|
610
|
+
* only their index entries are put back to HEAD's state. Paths come from
|
|
611
|
+
* callers' own constants, never from user input.
|
|
448
612
|
*/
|
|
449
|
-
function tryCommitChanges(commitMessage, directory) {
|
|
613
|
+
function tryCommitChanges(commitMessage, directory, excludePaths = []) {
|
|
450
614
|
try {
|
|
451
615
|
(0, child_process_1.execSync)('git add -A', {
|
|
452
616
|
encoding: 'utf8',
|
|
@@ -454,6 +618,20 @@ function tryCommitChanges(commitMessage, directory) {
|
|
|
454
618
|
cwd: directory,
|
|
455
619
|
windowsHide: true,
|
|
456
620
|
});
|
|
621
|
+
// Exclusion happens as an unstage rather than an add-time pathspec:
|
|
622
|
+
// `git add` refuses a pathspec naming an ignored directory (exit 1) even
|
|
623
|
+
// as an exclusion, and an add-time pathspec cannot cover entries that
|
|
624
|
+
// were already staged before this call. The reset is relative to cwd, so
|
|
625
|
+
// a workspace nested inside a larger repo excludes its own path; a path
|
|
626
|
+
// with no index entry is a quiet no-op, unborn HEAD included.
|
|
627
|
+
for (const excludePath of excludePaths) {
|
|
628
|
+
(0, child_process_1.execSync)(`git reset -q -- "${excludePath}"`, {
|
|
629
|
+
encoding: 'utf8',
|
|
630
|
+
stdio: 'pipe',
|
|
631
|
+
cwd: directory,
|
|
632
|
+
windowsHide: true,
|
|
633
|
+
});
|
|
634
|
+
}
|
|
457
635
|
(0, child_process_1.execSync)('git commit --no-verify -F -', {
|
|
458
636
|
encoding: 'utf8',
|
|
459
637
|
stdio: 'pipe',
|
|
@@ -488,3 +666,31 @@ function getLatestCommitSha(directory) {
|
|
|
488
666
|
return null;
|
|
489
667
|
}
|
|
490
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* The shape of a recorded `git rev-parse` output: 40 hex chars, or 64 in a
|
|
671
|
+
* sha256 repository. Anything a caller persists and later interpolates into a
|
|
672
|
+
* command line has to be checked against this first.
|
|
673
|
+
*/
|
|
674
|
+
exports.GIT_SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i;
|
|
675
|
+
/**
|
|
676
|
+
* Whether `ancestor` is reachable from `descendant`, i.e. resetting to
|
|
677
|
+
* `descendant` keeps `ancestor` in history. Returns false when the answer
|
|
678
|
+
* cannot be established (invalid input, not a repository, unknown commits),
|
|
679
|
+
* so callers treat an unverifiable commit as not preserved.
|
|
680
|
+
*/
|
|
681
|
+
function isAncestorCommit(ancestor, descendant, directory) {
|
|
682
|
+
if (!exports.GIT_SHA.test(ancestor) || !exports.GIT_SHA.test(descendant)) {
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
try {
|
|
686
|
+
(0, child_process_1.execSync)(`git merge-base --is-ancestor ${ancestor} ${descendant}`, {
|
|
687
|
+
stdio: 'pipe',
|
|
688
|
+
windowsHide: true,
|
|
689
|
+
cwd: directory,
|
|
690
|
+
});
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
catch {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
}
|