@astryxdesign/cli 0.7.2-canary.081ccea → 0.7.2-canary.0d5d64e
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 +104 -84
- package/api/build/_adapter.d.mts +8 -0
- package/api/build/_adapter.mjs +12 -1
- package/api/build/build.doc.mjs +4 -0
- package/api/build/kit/kit.mjs +3 -11
- package/api/component/_adapter.mjs +3 -11
- package/api/component/component.doc.mjs +6 -1
- package/api/discover/_adapter.d.mts +13 -0
- package/api/discover/_adapter.mjs +39 -17
- package/api/discover/discover.doc.mjs +3 -2
- package/api/discover/discover.mjs +22 -8
- package/api/discover/discover.type.d.mts +5 -3
- package/api/discover/discover.type.mjs +5 -3
- package/api/docs/_adapter.mjs +3 -2
- package/api/docs/docs.doc.mjs +2 -1
- package/api/docs/docs.mjs +2 -1
- package/api/docs/docs.test.mjs +5 -2
- package/api/docs/reference-blocks.test.mjs +1 -3
- package/api/doctor/_adapter.d.mts +108 -0
- package/api/doctor/_adapter.mjs +223 -4
- package/api/doctor/doctor.d.mts +199 -0
- package/api/doctor/doctor.doc.mjs +3 -2
- package/api/doctor/doctor.mjs +503 -31
- package/api/doctor/doctor.test.mjs +137 -14
- package/api/doctor/release-checks.test.mjs +156 -0
- package/api/doctor/theme-checks.mjs +16 -3
- package/api/doctor/theme-checks.test.mjs +87 -7
- package/api/error.d.mts +10 -0
- package/api/error.mjs +25 -0
- package/api/hook/_adapter.mjs +3 -11
- package/api/hook/hook.doc.mjs +4 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/init/_adapter.d.mts +22 -0
- package/api/init/_adapter.mjs +59 -0
- package/api/init/init.d.mts +7 -5
- package/api/init/init.doc.mjs +28 -7
- package/api/init/init.mjs +28 -4
- package/api/init/init.type.d.mts +48 -3
- package/api/init/init.type.mjs +37 -3
- package/api/init/run/run.d.mts +1 -1
- package/api/init/run/run.mjs +15 -4
- package/api/init/user/user.d.mts +14 -0
- package/api/init/user/user.mjs +87 -0
- package/api/init/user/user.test.mjs +232 -0
- package/api/integration/authoring-checks.mjs +2 -2
- package/api/integration/integrationCheck.doc.mjs +1 -1
- package/api/integration/pack-check.mjs +10 -9
- package/api/integration/pack-check.test.mjs +9 -15
- package/api/integration/validate-integration.d.mts +8 -0
- package/api/integration/validate-integration.mjs +27 -6
- package/api/integration/validate-integration.type.d.mts +8 -0
- package/api/integration/validate-integration.type.mjs +3 -1
- package/api/integration/validate-unread-theme-folders.test.mjs +3 -2
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/_adapter.d.mts +11 -0
- package/api/search/_adapter.mjs +25 -0
- package/api/search/search.d.mts +1 -1
- package/api/search/search.doc.mjs +8 -3
- package/api/search/search.mjs +38 -14
- package/api/search/search.test.mjs +4 -1
- package/api/search/search.type.d.mts +14 -1
- package/api/search/search.type.mjs +6 -1
- package/api/swizzle/_adapter.mjs +2 -2
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/template/template-integration.test.mjs +1 -1
- package/api/theme/_adapter.d.mts +16 -0
- package/api/theme/_adapter.mjs +32 -5
- package/api/theme/build/build.d.mts +2 -1
- package/api/theme/build/build.mjs +70 -14
- package/api/theme/build/build.packed-old-core.test.mjs +20 -3
- package/api/theme/build/font-warning.mjs +5 -3
- package/api/theme/build/font-warning.test.mjs +2 -1
- package/api/theme/remove/remove.test.mjs +2 -2
- package/api/theme/targets/targets.mjs +3 -10
- package/api/theme/themeTargets.doc.mjs +4 -0
- package/api/theme/use/use.test.mjs +1 -1
- package/api/upgrade/_adapter.mjs +1 -1
- package/api/upgrade/run/run.mjs +5 -1
- package/api/upgrade/upgrade.doc.mjs +2 -1
- package/api/upgrade/upgrade.mjs +5 -1
- package/assets/docs/getting-started.doc.mjs +23 -3
- package/assets/docs/tree/add-a-component.doc.mjs +11 -1
- package/assets/docs/tree/add-a-theme.doc.mjs +12 -2
- package/assets/docs/tree/add-a-topic.doc.mjs +43 -1
- package/assets/docs/tree/agent-guidance.doc.mjs +18 -4
- package/assets/docs/tree/building-blocks.doc.mjs +4 -0
- package/assets/docs/tree/check-the-props.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +5 -5
- package/assets/docs/tree/checks.doc.mjs +9 -9
- package/assets/docs/tree/ci-and-containers.doc.mjs +88 -0
- package/assets/docs/tree/cli-command.doc.mjs +142 -0
- package/assets/docs/tree/cli.doc.mjs +6 -0
- package/assets/docs/tree/codemods.doc.mjs +13 -3
- package/assets/docs/tree/commands.doc.mjs +7 -1
- package/assets/docs/tree/component-imports.doc.mjs +11 -1
- package/assets/docs/tree/components.doc.mjs +6 -0
- package/assets/docs/tree/computer-agent-guide.doc.mjs +160 -0
- package/assets/docs/tree/computer-integrations.doc.mjs +93 -0
- package/assets/docs/tree/configuration.doc.mjs +7 -3
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +11 -1
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
- package/assets/docs/tree/docs.doc.mjs +6 -0
- package/assets/docs/tree/extend-or-replace.doc.mjs +13 -3
- package/assets/docs/tree/generate-a-palette.doc.mjs +2 -2
- package/assets/docs/tree/global-integrations.doc.mjs +124 -0
- package/assets/docs/tree/global.doc.mjs +131 -0
- package/assets/docs/tree/grade-template-with-agent.doc.mjs +4 -4
- package/assets/docs/tree/install-once.doc.mjs +105 -0
- package/assets/docs/tree/integrations.doc.mjs +5 -1
- package/assets/docs/tree/layout.doc.mjs +1 -1
- package/assets/docs/tree/links.doc.mjs +1 -1
- package/assets/docs/tree/monorepos.doc.mjs +84 -0
- package/assets/docs/tree/problems.doc.mjs +205 -0
- package/assets/docs/tree/project-global-or-both.doc.mjs +131 -0
- package/assets/docs/tree/publishing.doc.mjs +2 -2
- package/assets/docs/tree/quick-start.doc.mjs +15 -5
- package/assets/docs/tree/reference.doc.mjs +192 -0
- package/assets/docs/tree/replace-a-core-component.doc.mjs +11 -1
- package/assets/docs/tree/replace-a-core-template.doc.mjs +4 -4
- package/assets/docs/tree/scaffold.doc.mjs +1 -1
- package/assets/docs/tree/sections-and-placement.doc.mjs +3 -3
- package/assets/docs/tree/see-it-in-an-app.doc.mjs +13 -3
- package/assets/docs/tree/short-and-findable.doc.mjs +3 -3
- package/assets/docs/tree/single-component.doc.mjs +3 -3
- package/assets/docs/tree/start-a-template.doc.mjs +15 -5
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/templates.doc.mjs +6 -0
- package/assets/docs/tree/test-in-an-app.doc.mjs +4 -4
- package/assets/docs/tree/test-template-in-app.doc.mjs +4 -4
- package/assets/docs/tree/themes.doc.mjs +4 -0
- package/assets/docs/tree/troubleshooting.doc.mjs +15 -7
- package/assets/docs/tree/uninstall.doc.mjs +109 -0
- package/assets/docs/tree/updates.doc.mjs +92 -0
- package/assets/docs/tree/upgrading.doc.mjs +2 -2
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +11 -1
- package/assets/docs/tree/verify-packed-template.doc.mjs +2 -2
- package/assets/docs/tree/versioning.doc.mjs +3 -3
- package/assets/docs/tree/who-answers.doc.mjs +119 -0
- package/assets/docs/tree/write-the-template-file.doc.mjs +3 -3
- package/assets/docs/working-with-ai.doc.mjs +23 -9
- package/authoring/debug/parse.d.mts +5 -5
- package/authoring/discover/discover.doc.mjs +6 -0
- package/authoring/doctypes/_schema.d.mts +8 -3
- package/authoring/doctypes/_schema.mjs +1 -0
- package/authoring/doctypes/command/command.doc.mjs +6 -0
- package/authoring/doctypes/command/type.ts +14 -0
- package/authoring/doctypes/reference/reference.doc.mjs +1 -1
- package/authoring/index.d.ts +1 -0
- package/authoring/integration/integration.doc.mjs +18 -2
- package/authoring/integration/parse.test.mjs +11 -0
- package/authoring/integration/schema.d.mts +14 -3
- package/authoring/integration/schema.mjs +33 -2
- package/authoring/integration/type.ts +8 -0
- package/clients/cli/bin/astryx.mjs +20 -3
- package/clients/cli/cli-command.test.mjs +166 -0
- package/clients/cli/commands/blog.doc.mjs +1 -0
- package/clients/cli/commands/build-theme.batch-report.test.mjs +14 -2
- package/clients/cli/commands/build-theme.font-warning.test.mjs +3 -3
- package/clients/cli/commands/build-theme.mjs +25 -12
- package/clients/cli/commands/build.doc.mjs +1 -0
- package/clients/cli/commands/build.exit-codes-doc.test.mjs +4 -0
- package/clients/cli/commands/component.doc.mjs +1 -0
- package/clients/cli/commands/discover.broken-integration.test.mjs +7 -6
- package/clients/cli/commands/discover.doc.mjs +8 -0
- package/clients/cli/commands/discover.no-source.test.mjs +1 -0
- package/clients/cli/commands/docs.doc.mjs +1 -0
- package/clients/cli/commands/docs.mjs +49 -19
- package/clients/cli/commands/docs.test.mjs +2 -2
- package/clients/cli/commands/doctor-integration-components.doc.mjs +1 -0
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -0
- package/clients/cli/commands/doctor-integration-templates.doc.mjs +1 -0
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +10 -1
- package/clients/cli/commands/doctor-integration.test.mjs +4 -3
- package/clients/cli/commands/doctor.doc.mjs +12 -2
- package/clients/cli/commands/doctor.mjs +12 -3
- package/clients/cli/commands/doctor.test.mjs +10 -4
- package/clients/cli/commands/gap-report.doc.mjs +1 -0
- package/clients/cli/commands/hook.doc.mjs +1 -0
- package/clients/cli/commands/init.behavior.test.mjs +5 -0
- package/clients/cli/commands/init.doc.mjs +29 -3
- package/clients/cli/commands/integration-add.doc.mjs +7 -0
- package/clients/cli/commands/integration-authoring.test.mjs +3 -3
- package/clients/cli/commands/integration-check.doc.mjs +10 -2
- package/clients/cli/commands/integration-check.test.mjs +31 -1
- package/clients/cli/commands/integration-pack.doc.mjs +8 -1
- package/clients/cli/commands/integration-verify.doc.mjs +8 -1
- package/clients/cli/commands/integration.mjs +3 -2
- package/clients/cli/commands/json-contract.test.mjs +6 -1
- package/clients/cli/commands/manifest.doc.mjs +1 -0
- package/clients/cli/commands/outside-project.test.mjs +774 -0
- package/clients/cli/commands/search.doc.mjs +1 -0
- package/clients/cli/commands/search.mjs +16 -11
- package/clients/cli/commands/search.test.mjs +429 -296
- package/clients/cli/commands/setup-nudge.test.mjs +26 -4
- package/clients/cli/commands/swizzle.doc.mjs +7 -0
- package/clients/cli/commands/swizzle.routing.test.mjs +1 -1
- package/clients/cli/commands/template.doc.mjs +1 -0
- package/clients/cli/commands/theme-add-lifecycle.test.mjs +3 -3
- package/clients/cli/commands/theme-add.doc.mjs +8 -1
- package/clients/cli/commands/theme-build.doc.mjs +1 -0
- package/clients/cli/commands/theme-eject.doc.mjs +1 -0
- package/clients/cli/commands/theme-list.behavior.test.mjs +6 -0
- package/clients/cli/commands/theme-list.doc.mjs +1 -0
- package/clients/cli/commands/theme-palette-generate.doc.mjs +1 -0
- package/clients/cli/commands/theme-remove.doc.mjs +7 -0
- package/clients/cli/commands/theme-targets.doc.mjs +1 -0
- package/clients/cli/commands/theme-template.doc.mjs +1 -0
- package/clients/cli/commands/theme-use.doc.mjs +7 -0
- package/clients/cli/commands/upgrade.config-ordering.test.mjs +2 -1
- package/clients/cli/commands/upgrade.doc.mjs +8 -1
- package/clients/cli/commands/upgrade.file-protection.test.mjs +3 -2
- package/clients/cli/commands/upgrade.hook-output.test.mjs +2 -1
- package/clients/cli/index.mjs +84 -13
- package/clients/cli/lib/cli-error.mjs +4 -1
- package/clients/cli/lib/component-format.test.mjs +1 -1
- package/clients/cli/lib/define-command.mjs +2 -2
- package/clients/cli/lib/json-shim.mjs +3 -1
- package/clients/cli/lib/manifest.d.ts +9 -0
- package/clients/cli/lib/manifest.mjs +17 -1
- package/clients/cli/lib/manifest.test.mjs +25 -0
- package/foundation/agent-docs/agent-doc-state.d.mts +21 -6
- package/foundation/agent-docs/agent-doc-state.mjs +29 -7
- package/foundation/agent-docs/agent-docs.d.mts +2 -2
- package/foundation/agent-docs/agent-docs.mjs +3 -3
- package/foundation/agent-docs/computer-agent-text.d.mts +133 -0
- package/foundation/agent-docs/computer-agent-text.mjs +623 -0
- package/foundation/agent-docs/computer-agent-text.test.mjs +602 -0
- package/foundation/config/project.d.mts +35 -3
- package/foundation/config/project.mjs +145 -8
- package/foundation/config/project.test.mjs +66 -0
- package/foundation/config/theme-state.mjs +5 -4
- package/foundation/discovery/cli-self-docs.mjs +20 -3
- package/foundation/discovery/cli-self-docs.test.mjs +3 -2
- package/foundation/discovery/component-replacement.mjs +2 -1
- package/foundation/discovery/runner-allowlist.d.mts +40 -0
- package/foundation/discovery/runner-allowlist.mjs +53 -0
- package/foundation/discovery/template-needs.mjs +5 -2
- package/foundation/discovery/theme-imports.mjs +8 -4
- package/foundation/discovery/theme-imports.test.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +20 -0
- package/foundation/doc-compiler/inputs.mjs +4 -1
- package/foundation/doc-compiler/read.d.mts +1 -1
- package/foundation/doc-compiler/tree.test.mjs +1 -1
- package/foundation/env/cli-command.d.mts +83 -0
- package/foundation/env/cli-command.mjs +152 -0
- package/foundation/env/cli-command.test.mjs +129 -0
- package/foundation/env/node-version.test.mjs +15 -3
- package/foundation/env/package-manager.d.mts +61 -9
- package/foundation/env/package-manager.global.test.mjs +66 -0
- package/foundation/env/package-manager.mjs +137 -13
- package/foundation/env/package-manager.test.mjs +148 -9
- package/foundation/env/project-scope.d.mts +9 -0
- package/foundation/env/project-scope.mjs +33 -0
- package/foundation/env/search-path.d.mts +42 -0
- package/foundation/env/search-path.mjs +205 -0
- package/foundation/env/search-path.test.mjs +122 -0
- package/foundation/env/user-dirs.d.mts +39 -0
- package/foundation/env/user-dirs.mjs +93 -0
- package/foundation/env/user-dirs.test.mjs +72 -0
- package/foundation/env/user-settings.d.mts +46 -0
- package/foundation/env/user-settings.mjs +106 -0
- package/foundation/env/user-settings.test.mjs +64 -0
- package/foundation/fs/file-protection.mjs +15 -1
- package/foundation/fs/module-loader.stdout.test.mjs +3 -2
- package/foundation/fs/path-compare.d.mts +33 -0
- package/foundation/fs/path-compare.mjs +73 -0
- package/foundation/fs/paths.d.mts +57 -1
- package/foundation/fs/paths.mjs +131 -3
- package/foundation/fs/paths.test.mjs +10 -1
- package/foundation/integrations/computer-integrations.d.mts +78 -0
- package/foundation/integrations/computer-integrations.mjs +316 -0
- package/foundation/integrations/computer-integrations.test.mjs +292 -0
- package/foundation/integrations/integration-warnings.mjs +3 -2
- package/foundation/integrations/integration-warnings.test.mjs +8 -9
- package/foundation/integrations/integrations.d.mts +25 -1
- package/foundation/integrations/integrations.mjs +46 -3
- package/foundation/integrations/validate-contributions.d.mts +2 -0
- package/foundation/integrations/validate-contributions.mjs +11 -0
- package/foundation/release/agent-text-worker.d.mts +4 -0
- package/foundation/release/agent-text-worker.mjs +52 -0
- package/foundation/release/cache.d.mts +310 -0
- package/foundation/release/cache.mjs +1216 -0
- package/foundation/release/cache.test.mjs +920 -0
- package/foundation/release/choose.d.mts +207 -0
- package/foundation/release/choose.mjs +677 -0
- package/foundation/release/choose.test.mjs +427 -0
- package/foundation/release/core-worker.d.mts +4 -0
- package/foundation/release/core-worker.mjs +38 -0
- package/foundation/release/global-state.d.mts +259 -0
- package/foundation/release/global-state.mjs +472 -0
- package/foundation/release/global-state.test.mjs +381 -0
- package/foundation/release/handoff.d.mts +60 -0
- package/foundation/release/handoff.e2e.test.mjs +278 -0
- package/foundation/release/handoff.mjs +357 -0
- package/foundation/release/lock-lease.d.mts +23 -0
- package/foundation/release/lock-lease.mjs +80 -0
- package/foundation/release/notices.d.mts +253 -0
- package/foundation/release/notices.mjs +596 -0
- package/foundation/release/notices.test.mjs +565 -0
- package/foundation/release/npm-guard.d.mts +4 -0
- package/foundation/release/npm-guard.mjs +126 -0
- package/foundation/release/project.d.mts +141 -0
- package/foundation/release/project.mjs +466 -0
- package/foundation/release/project.test.mjs +288 -0
- package/foundation/release/refresh-worker.d.mts +4 -0
- package/foundation/release/refresh-worker.mjs +27 -0
- package/foundation/release/run-context.d.mts +47 -0
- package/foundation/release/run-context.mjs +149 -0
- package/foundation/release/update-notice-env.d.mts +28 -0
- package/foundation/release/update-notice-env.mjs +39 -0
- package/foundation/response/base.d.ts +26 -3
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.doc.mjs +12 -0
- package/foundation/response/error-codes.mjs +17 -0
- package/foundation/response/error-codes.test.mjs +2 -0
- package/foundation/response/json-contract.test.mjs +7 -2
- package/foundation/response/json.mjs +4 -1
- package/foundation/response/response-types.doc.mjs +8 -3
- package/foundation/response/response-types.doc.test.mjs +46 -0
- package/foundation/response/response.doc.mjs +3 -3
- package/foundation/xle/browser-imports.test.mjs +74 -0
- package/package.json +9 -9
- package/scripts/postinstall.mjs +21 -2
|
@@ -8,11 +8,17 @@
|
|
|
8
8
|
* the runner that launched us. Returns the correct command prefix for running
|
|
9
9
|
* package binaries (e.g. 'npx astryx', 'yarn astryx', 'pnpm exec astryx'), and
|
|
10
10
|
* the scoped one-off form ('npx @astryxdesign/cli') when the `astryx` bin does
|
|
11
|
-
* not resolve from the project.
|
|
11
|
+
* not resolve from the project. An integration's declared `cliCommand`, then
|
|
12
|
+
* a host's door name, come first (see cli-command.mjs).
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
import * as fs from 'node:fs';
|
|
15
16
|
import * as path from 'node:path';
|
|
17
|
+
import {cliDoor, declaredCliCommand} from './cli-command.mjs';
|
|
18
|
+
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
19
|
+
import {cliVersion, runChoice} from '../release/run-context.mjs';
|
|
20
|
+
import {isGlobalCopy} from '../release/choose.mjs';
|
|
21
|
+
import {isInReleaseCache} from '../release/cache.mjs';
|
|
16
22
|
|
|
17
23
|
/**
|
|
18
24
|
* A package manager we can install with and run binaries through.
|
|
@@ -473,25 +479,73 @@ export function cliBinResolves(targetDir = process.cwd()) {
|
|
|
473
479
|
}
|
|
474
480
|
|
|
475
481
|
/**
|
|
476
|
-
* The
|
|
482
|
+
* The CLI invocation stem every printed command starts with. The one picker:
|
|
483
|
+
* every hint, error, Doctor fix and doc line that names a command goes through
|
|
484
|
+
* it (directly, or through {@link formatCliCommand} and
|
|
485
|
+
* {@link formatCliCommandsIn}). JSON fields that carry a command stay bare.
|
|
477
486
|
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
* -
|
|
481
|
-
* `
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
487
|
+
* In order:
|
|
488
|
+
*
|
|
489
|
+
* - The `cliCommand` an integration loaded in this project declares, e.g.
|
|
490
|
+
* `acme astryx`. When two integrations declare different commands,
|
|
491
|
+
* neither is used, the guess below is (even when a host set a door), and
|
|
492
|
+
* `astryx doctor` warns.
|
|
493
|
+
* - The door a host ran this call through (see cli-command.mjs). Empty in a
|
|
494
|
+
* plain run.
|
|
495
|
+
* - Otherwise the guess below.
|
|
496
|
+
*
|
|
497
|
+
* The guess names a command that, run from `targetDir`, reaches the release
|
|
498
|
+
* that answered (spec AST-081 FR5):
|
|
499
|
+
*
|
|
500
|
+
* - The project's own CLI answered and its `astryx` bin resolves from
|
|
501
|
+
* `targetDir`: `<run-prefix> astryx` (e.g. `pnpm exec astryx`).
|
|
502
|
+
* - Outside a project, the CLI installed for the computer (or the release it
|
|
503
|
+
* keeps) answered: `astryx`.
|
|
504
|
+
* - Otherwise: `<dlx-prefix> @astryxdesign/cli@<answering version>`, pinned so
|
|
505
|
+
* the package runner starts the same release. The bare `astryx` name would
|
|
506
|
+
* make npm fetch an unrelated registry package, and the unpinned scoped
|
|
507
|
+
* package the newest release.
|
|
508
|
+
*
|
|
509
|
+
* With `installed`, the line follows a step that installs the project's own
|
|
510
|
+
* CLI (an update notice, the hint that matches a project's CLI to its Core),
|
|
511
|
+
* so the guess is that CLI: `<run-prefix> astryx`. A declared `cliCommand`
|
|
512
|
+
* and a host's door still come first.
|
|
485
513
|
*
|
|
486
514
|
* @param {string} [targetDir] the project the printed command runs in;
|
|
487
515
|
* defaults to the working directory
|
|
516
|
+
* @param {{installed?: boolean}} [options]
|
|
488
517
|
* @returns {string}
|
|
489
518
|
*/
|
|
490
|
-
export function getCliInvocation(targetDir) {
|
|
491
|
-
|
|
492
|
-
|
|
519
|
+
export function getCliInvocation(targetDir, {installed = false} = {}) {
|
|
520
|
+
const declared = declaredCliCommand(targetDir);
|
|
521
|
+
if (declared.command) return declared.command;
|
|
522
|
+
const guess = () =>
|
|
523
|
+
installed
|
|
524
|
+
? `${getRunPrefix(targetDir)} ${CLI_BIN}`
|
|
525
|
+
: guessCliInvocation(targetDir);
|
|
526
|
+
if (declared.conflict) return guess();
|
|
527
|
+
return cliDoor() ?? guess();
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* The package-manager guess alone, without any integration's `cliCommand` or
|
|
532
|
+
* a host's door. The picker falls back to it when declared commands conflict,
|
|
533
|
+
* and Doctor names it then.
|
|
534
|
+
*
|
|
535
|
+
* @param {string} [targetDir]
|
|
536
|
+
* @returns {string}
|
|
537
|
+
*/
|
|
538
|
+
export function guessCliInvocation(targetDir) {
|
|
539
|
+
// Who answered this run decides the stem, so every command one run prints
|
|
540
|
+
// reaches the same release, whichever folder a line names.
|
|
541
|
+
const choice = runChoice(process.cwd());
|
|
542
|
+
if (choice.copy === 'project' && !isCliOneOff() && cliBinResolves(targetDir)) {
|
|
543
|
+
return `${getRunPrefix(targetDir)} ${CLI_BIN}`;
|
|
544
|
+
}
|
|
545
|
+
if (!choice.inProject && (isGlobalCopy(CLI_ROOT) || isInReleaseCache(CLI_ROOT))) {
|
|
546
|
+
return CLI_BIN;
|
|
493
547
|
}
|
|
494
|
-
return `${
|
|
548
|
+
return `${getDlxPrefix(targetDir)} ${CLI_PACKAGE}@${cliVersion()}`;
|
|
495
549
|
}
|
|
496
550
|
|
|
497
551
|
/**
|
|
@@ -513,6 +567,76 @@ export function formatCliCommand(command, targetDir) {
|
|
|
513
567
|
return sub ? `${stem} ${sub}` : stem;
|
|
514
568
|
}
|
|
515
569
|
|
|
570
|
+
/** Code-fence languages whose lines are shell commands. */
|
|
571
|
+
const SHELL_FENCES = new Set(['', 'bash', 'sh', 'shell', 'zsh', 'console']);
|
|
572
|
+
|
|
573
|
+
/** Code-fence languages that hold prose, such as a prompt to paste. */
|
|
574
|
+
const PROSE_FENCES = new Set(['text', 'txt', 'markdown', 'md']);
|
|
575
|
+
|
|
576
|
+
/** `astryx` where a shell line starts a command: line start, `$ `, `&&`, `||`, `;`, `|`. */
|
|
577
|
+
const SHELL_COMMAND = /(^\s*(?:\$\s+)?|(?:&&|\|\||;|\|)\s*)astryx(?=\s|$)/g;
|
|
578
|
+
|
|
579
|
+
/** `astryx` opening an inline code span: `` `astryx docs` `` or `` `astryx` ``. */
|
|
580
|
+
const INLINE_COMMAND = /`astryx(?=[\s`])/g;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Prefix the CLI commands in one line.
|
|
584
|
+
* @param {string} line
|
|
585
|
+
* @param {string} stem
|
|
586
|
+
* @param {string | null} lang the fence the line sits in; null for prose
|
|
587
|
+
* @returns {string}
|
|
588
|
+
*/
|
|
589
|
+
function prefixLine(line, stem, lang) {
|
|
590
|
+
if (lang == null) return line.replace(INLINE_COMMAND, `\`${stem}`);
|
|
591
|
+
if (SHELL_FENCES.has(lang)) return line.replace(SHELL_COMMAND, `$1${stem}`);
|
|
592
|
+
if (PROSE_FENCES.has(lang)) {
|
|
593
|
+
return line
|
|
594
|
+
.replace(INLINE_COMMAND, `\`${stem}`)
|
|
595
|
+
.replace(SHELL_COMMAND, `$1${stem}`);
|
|
596
|
+
}
|
|
597
|
+
return line;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Prefix every CLI command in doc text with `stem`, the invocation from
|
|
602
|
+
* {@link getCliInvocation}.
|
|
603
|
+
*
|
|
604
|
+
* Docs, including an integration's, are written with bare `astryx ...`
|
|
605
|
+
* commands; this rewrites them when they are shown. In prose, an inline code
|
|
606
|
+
* span that starts with `astryx`. In a shell code fence (no language, `bash`,
|
|
607
|
+
* `sh`, `shell`, `zsh`, `console`), each `astryx` that starts a command. In a
|
|
608
|
+
* `text` or `markdown` fence, both. Other fences, and plain words, are left
|
|
609
|
+
* alone. JSON output keeps the authored text.
|
|
610
|
+
*
|
|
611
|
+
* @param {string} text Markdown-style doc text, or the body of one code block.
|
|
612
|
+
* @param {string} stem e.g. `pnpm exec astryx`
|
|
613
|
+
* @param {string | null} [lang] the code block's language when `text` is one
|
|
614
|
+
* block's body; omit for Markdown, whose fences are followed
|
|
615
|
+
* @returns {string}
|
|
616
|
+
*/
|
|
617
|
+
export function prefixCliCommands(text, stem, lang = null) {
|
|
618
|
+
if (stem === CLI_BIN) return String(text);
|
|
619
|
+
const blockLang = lang == null ? null : lang.toLowerCase();
|
|
620
|
+
/** @type {{marker: string, lang: string} | null} */
|
|
621
|
+
let fence = null;
|
|
622
|
+
return String(text)
|
|
623
|
+
.split('\n')
|
|
624
|
+
.map(line => {
|
|
625
|
+
if (blockLang != null) return prefixLine(line, stem, blockLang);
|
|
626
|
+
const marker = /^\s*(`{3,}|~{3,})\s*([\w-]*)/.exec(line);
|
|
627
|
+
if (marker) {
|
|
628
|
+
if (fence == null) {
|
|
629
|
+
fence = {marker: marker[1], lang: marker[2].toLowerCase()};
|
|
630
|
+
} else if (marker[1].startsWith(fence.marker)) {
|
|
631
|
+
fence = null;
|
|
632
|
+
}
|
|
633
|
+
return line;
|
|
634
|
+
}
|
|
635
|
+
return prefixLine(line, stem, fence?.lang ?? null);
|
|
636
|
+
})
|
|
637
|
+
.join('\n');
|
|
638
|
+
}
|
|
639
|
+
|
|
516
640
|
/**
|
|
517
641
|
* Quote one argument of a printed command so the shell it is pasted into
|
|
518
642
|
* passes it on unchanged. Printed commands target a POSIX shell (sh, bash,
|
|
@@ -12,10 +12,14 @@ import {
|
|
|
12
12
|
isCliOneOff,
|
|
13
13
|
cliBinResolves,
|
|
14
14
|
getCliInvocation,
|
|
15
|
+
guessCliInvocation,
|
|
15
16
|
formatCliCommand,
|
|
17
|
+
prefixCliCommands,
|
|
16
18
|
quoteCommandArgument,
|
|
17
19
|
commandInFolder,
|
|
18
20
|
} from './package-manager.mjs';
|
|
21
|
+
import {recordDeclaredCliCommands, runWithCliDoor} from './cli-command.mjs';
|
|
22
|
+
import {CLI_VERSION} from '../../test-utils/release-fixtures.mjs';
|
|
19
23
|
|
|
20
24
|
let tmpDir;
|
|
21
25
|
const ORIGINAL_ARGV1 = process.argv[1];
|
|
@@ -59,8 +63,16 @@ function linkCliBin(dir, name = 'astryx') {
|
|
|
59
63
|
const binDir = path.join(dir, 'node_modules', '.bin');
|
|
60
64
|
fs.mkdirSync(binDir, {recursive: true});
|
|
61
65
|
fs.writeFileSync(path.join(binDir, name), '');
|
|
66
|
+
// The installed package the bin belongs to: this copy, so the project's own
|
|
67
|
+
// CLI is the one answering (spec AST-081 FR5's run-prefix case).
|
|
68
|
+
const pkg = path.join(dir, 'node_modules', '@astryxdesign', 'cli');
|
|
69
|
+
fs.mkdirSync(path.dirname(pkg), {recursive: true});
|
|
70
|
+
if (!fs.existsSync(pkg)) fs.symlinkSync(THIS_CLI, pkg, 'dir');
|
|
62
71
|
}
|
|
63
72
|
|
|
73
|
+
/** This CLI package's folder. */
|
|
74
|
+
const THIS_CLI = path.resolve(import.meta.dirname, '..', '..');
|
|
75
|
+
|
|
64
76
|
/** The header a classic Yarn (1.x) lockfile starts with. */
|
|
65
77
|
const YARN_V1_LOCK =
|
|
66
78
|
'# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n# yarn lockfile v1\n\n';
|
|
@@ -534,11 +546,11 @@ describe('getCliInvocation', () => {
|
|
|
534
546
|
// fresh package), the CLI used to print `npx astryx` for a project where that
|
|
535
547
|
// bin does not resolve, so following the hint fetched someone else's package.
|
|
536
548
|
it.each([
|
|
537
|
-
['package-lock.json', '{}',
|
|
538
|
-
['pnpm-lock.yaml', '',
|
|
539
|
-
['yarn.lock', YARN_BERRY_LOCK,
|
|
540
|
-
['yarn.lock', YARN_V1_LOCK,
|
|
541
|
-
['bun.lockb', '',
|
|
549
|
+
['package-lock.json', '{}', `npx @astryxdesign/cli@${CLI_VERSION}`],
|
|
550
|
+
['pnpm-lock.yaml', '', `pnpm dlx @astryxdesign/cli@${CLI_VERSION}`],
|
|
551
|
+
['yarn.lock', YARN_BERRY_LOCK, `yarn dlx @astryxdesign/cli@${CLI_VERSION}`],
|
|
552
|
+
['yarn.lock', YARN_V1_LOCK, `npx @astryxdesign/cli@${CLI_VERSION}`],
|
|
553
|
+
['bun.lockb', '', `bunx @astryxdesign/cli@${CLI_VERSION}`],
|
|
542
554
|
])(
|
|
543
555
|
'prints the scoped package for a project with no local CLI (%s), launched from an installed path',
|
|
544
556
|
(lockfile, contents, expected) => {
|
|
@@ -555,14 +567,14 @@ describe('getCliInvocation', () => {
|
|
|
555
567
|
const dir = makeTmpDir();
|
|
556
568
|
delete process.env.npm_config_user_agent;
|
|
557
569
|
fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"fresh"}');
|
|
558
|
-
expect(getCliInvocation(dir)).toBe(
|
|
570
|
+
expect(getCliInvocation(dir)).toBe(`npx @astryxdesign/cli@${CLI_VERSION}`);
|
|
559
571
|
});
|
|
560
572
|
|
|
561
573
|
it('uses the dlx runner + scoped package when run one-off', () => {
|
|
562
574
|
process.argv[1] = '/home/u/.npm/_npx/a1b2/node_modules/.bin/astryx';
|
|
563
575
|
const dir = makeTmpDir();
|
|
564
576
|
delete process.env.npm_config_user_agent;
|
|
565
|
-
expect(getCliInvocation(dir)).toBe(
|
|
577
|
+
expect(getCliInvocation(dir)).toBe(`npx @astryxdesign/cli@${CLI_VERSION}`);
|
|
566
578
|
});
|
|
567
579
|
|
|
568
580
|
it('pairs the dlx runner with the scoped package for pnpm one-off', () => {
|
|
@@ -570,7 +582,9 @@ describe('getCliInvocation', () => {
|
|
|
570
582
|
'/home/u/.cache/pnpm/dlx/9f/node_modules/@astryxdesign/cli/bin/astryx.mjs';
|
|
571
583
|
const dir = makeTmpDir();
|
|
572
584
|
fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
|
|
573
|
-
expect(getCliInvocation(dir)).toBe(
|
|
585
|
+
expect(getCliInvocation(dir)).toBe(
|
|
586
|
+
`pnpm dlx @astryxdesign/cli@${CLI_VERSION}`,
|
|
587
|
+
);
|
|
574
588
|
});
|
|
575
589
|
});
|
|
576
590
|
|
|
@@ -598,9 +612,134 @@ describe('formatCliCommand', () => {
|
|
|
598
612
|
const dir = makeTmpDir();
|
|
599
613
|
fs.writeFileSync(path.join(dir, 'package-lock.json'), '{}');
|
|
600
614
|
expect(formatCliCommand('astryx component Button', dir)).toBe(
|
|
601
|
-
|
|
615
|
+
`npx @astryxdesign/cli@${CLI_VERSION} component Button`,
|
|
616
|
+
);
|
|
617
|
+
});
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
describe('the picker: declared cliCommand, then the door, then the guess', () => {
|
|
621
|
+
/** A pnpm project with the CLI installed: the guess is `pnpm exec astryx`. */
|
|
622
|
+
function pnpmProject() {
|
|
623
|
+
process.argv[1] = INSTALLED_ENTRY;
|
|
624
|
+
const dir = makeTmpDir();
|
|
625
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"app"}');
|
|
626
|
+
fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
|
|
627
|
+
linkCliBin(dir);
|
|
628
|
+
return dir;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
it('guesses when nothing is declared', () => {
|
|
632
|
+
const dir = pnpmProject();
|
|
633
|
+
recordDeclaredCliCommands(dir, [{name: '@acme/a'}]);
|
|
634
|
+
expect(getCliInvocation(dir)).toBe('pnpm exec astryx');
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
it("uses an integration's cliCommand over the guess", () => {
|
|
638
|
+
const dir = pnpmProject();
|
|
639
|
+
recordDeclaredCliCommands(dir, [
|
|
640
|
+
{name: '@acme/a', cliCommand: 'acme astryx'},
|
|
641
|
+
{name: '@acme/b', cliCommand: 'acme astryx'},
|
|
642
|
+
]);
|
|
643
|
+
expect(getCliInvocation(dir)).toBe('acme astryx');
|
|
644
|
+
expect(formatCliCommand('astryx docs tokens', dir)).toBe(
|
|
645
|
+
'acme astryx docs tokens',
|
|
646
|
+
);
|
|
647
|
+
expect(guessCliInvocation(dir)).toBe('pnpm exec astryx');
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
it('falls back to the guess when integrations declare different commands', () => {
|
|
651
|
+
const dir = pnpmProject();
|
|
652
|
+
recordDeclaredCliCommands(dir, [
|
|
653
|
+
{name: '@acme/a', cliCommand: 'acme astryx'},
|
|
654
|
+
{name: '@acme/b', cliCommand: 'other astryx'},
|
|
655
|
+
]);
|
|
656
|
+
expect(getCliInvocation(dir)).toBe('pnpm exec astryx');
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it("puts a declared command ahead of a host's door", () => {
|
|
660
|
+
const dir = pnpmProject();
|
|
661
|
+
recordDeclaredCliCommands(dir, [
|
|
662
|
+
{name: '@acme/a', cliCommand: 'acme astryx'},
|
|
663
|
+
]);
|
|
664
|
+
expect(runWithCliDoor('astryx', () => getCliInvocation(dir))).toBe(
|
|
665
|
+
'acme astryx',
|
|
602
666
|
);
|
|
603
667
|
});
|
|
668
|
+
|
|
669
|
+
it("uses a host's door when nothing is declared", () => {
|
|
670
|
+
const dir = pnpmProject();
|
|
671
|
+
recordDeclaredCliCommands(dir, []);
|
|
672
|
+
expect(runWithCliDoor('astryx', () => getCliInvocation(dir))).toBe(
|
|
673
|
+
'astryx',
|
|
674
|
+
);
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
it('guesses on a conflict even when a host set a door', () => {
|
|
678
|
+
const dir = pnpmProject();
|
|
679
|
+
recordDeclaredCliCommands(dir, [
|
|
680
|
+
{name: '@acme/a', cliCommand: 'acme astryx'},
|
|
681
|
+
{name: '@acme/b', cliCommand: 'other astryx'},
|
|
682
|
+
]);
|
|
683
|
+
expect(runWithCliDoor('astryx', () => getCliInvocation(dir))).toBe(
|
|
684
|
+
'pnpm exec astryx',
|
|
685
|
+
);
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
describe('prefixCliCommands', () => {
|
|
690
|
+
/** @param {string} text @param {string | null} [lang] */
|
|
691
|
+
const shown = (text, lang) => prefixCliCommands(text, 'acme astryx', lang);
|
|
692
|
+
|
|
693
|
+
it('prefixes inline code spans that run the CLI', () => {
|
|
694
|
+
expect(
|
|
695
|
+
shown('Run `astryx docs theme`, then `astryx`. Not `astryx.config.ts`.'),
|
|
696
|
+
).toBe(
|
|
697
|
+
'Run `acme astryx docs theme`, then `acme astryx`. Not `astryx.config.ts`.',
|
|
698
|
+
);
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
it('prefixes commands in shell fences and leaves code fences alone', () => {
|
|
702
|
+
const text = [
|
|
703
|
+
'```bash',
|
|
704
|
+
'# astryx in a comment stays',
|
|
705
|
+
'astryx doctor && astryx integration verify',
|
|
706
|
+
'$ astryx docs',
|
|
707
|
+
'npm install @astryxdesign/cli',
|
|
708
|
+
'```',
|
|
709
|
+
'```tsx',
|
|
710
|
+
'astryx docs',
|
|
711
|
+
'```',
|
|
712
|
+
].join('\n');
|
|
713
|
+
expect(shown(text).split('\n')).toEqual([
|
|
714
|
+
'```bash',
|
|
715
|
+
'# astryx in a comment stays',
|
|
716
|
+
'acme astryx doctor && acme astryx integration verify',
|
|
717
|
+
'$ acme astryx docs',
|
|
718
|
+
'npm install @astryxdesign/cli',
|
|
719
|
+
'```',
|
|
720
|
+
'```tsx',
|
|
721
|
+
'astryx docs',
|
|
722
|
+
'```',
|
|
723
|
+
]);
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
it("follows one code block's language", () => {
|
|
727
|
+
expect(shown('astryx docs', 'bash')).toBe('acme astryx docs');
|
|
728
|
+
expect(shown('1. Read `astryx docs cli`.', 'text')).toBe(
|
|
729
|
+
'1. Read `acme astryx docs cli`.',
|
|
730
|
+
);
|
|
731
|
+
expect(shown("const run = 'astryx docs';", 'ts')).toBe(
|
|
732
|
+
"const run = 'astryx docs';",
|
|
733
|
+
);
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
it('leaves plain prose alone', () => {
|
|
737
|
+
expect(shown('Astryx and astryx themes')).toBe('Astryx and astryx themes');
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
it('changes nothing when the stem is the bare bin', () => {
|
|
741
|
+
expect(prefixCliCommands('`astryx docs`', 'astryx')).toBe('`astryx docs`');
|
|
742
|
+
});
|
|
604
743
|
});
|
|
605
744
|
|
|
606
745
|
describe('quoteCommandArgument', () => {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* True when `cwd` is outside any project.
|
|
6
|
+
* @param {string} [cwd]
|
|
7
|
+
* @returns {boolean}
|
|
8
|
+
*/
|
|
9
|
+
export function isOutsideProject(cwd?: string): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Whether a folder is outside a project (spec AST-081 FR3).
|
|
5
|
+
*
|
|
6
|
+
* A folder is inside a project when the CLI finds a Core or a CLI installed
|
|
7
|
+
* there or above it, or a package.json above it that declares either one; the
|
|
8
|
+
* release choice already worked that out (foundation/release/run-context.mjs).
|
|
9
|
+
* Outside a project, output never gives advice that works only inside one, such
|
|
10
|
+
* as the setup reminder, the getting-started steps, or a step that adds a theme
|
|
11
|
+
* to an app; each surface that prints such a step asks here first.
|
|
12
|
+
*
|
|
13
|
+
* @input a folder
|
|
14
|
+
* @output whether it is outside a project
|
|
15
|
+
* @position foundation/env — read by the setup reminder, init, doctor, upgrade,
|
|
16
|
+
* and the theme, search, discover, and integration-check surfaces.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import {runChoice} from '../release/run-context.mjs';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* True when `cwd` is outside any project.
|
|
23
|
+
* @param {string} [cwd]
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*/
|
|
26
|
+
export function isOutsideProject(cwd = process.cwd()) {
|
|
27
|
+
try {
|
|
28
|
+
return !runChoice(cwd).inProject;
|
|
29
|
+
} catch {
|
|
30
|
+
// A folder the release choice cannot read keeps its in-project output.
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The Astryx CLI package an executable starts, or null.
|
|
6
|
+
* @param {string} file
|
|
7
|
+
* @returns {string | null}
|
|
8
|
+
*/
|
|
9
|
+
export function astryxCliRootOf(file: string): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Every `astryx` command on the search path, in the order a shell tries
|
|
12
|
+
* them. The first row is the one that runs.
|
|
13
|
+
* @param {{searchPath?: string, platform?: NodeJS.Platform}} [options]
|
|
14
|
+
* @returns {SearchPathCommand[]}
|
|
15
|
+
*/
|
|
16
|
+
export function astryxCommandsOnSearchPath({ searchPath, platform, }?: {
|
|
17
|
+
searchPath?: string;
|
|
18
|
+
platform?: NodeJS.Platform;
|
|
19
|
+
}): SearchPathCommand[];
|
|
20
|
+
export type SearchPathCommand = {
|
|
21
|
+
/**
|
|
22
|
+
* the command as the shell finds it
|
|
23
|
+
*/
|
|
24
|
+
file: string;
|
|
25
|
+
/**
|
|
26
|
+
* whether it starts the Astryx CLI
|
|
27
|
+
*/
|
|
28
|
+
astryx: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* the CLI package it starts, when known
|
|
31
|
+
*/
|
|
32
|
+
cliRoot: string | null;
|
|
33
|
+
/**
|
|
34
|
+
* that package's version, when known
|
|
35
|
+
*/
|
|
36
|
+
version: string | null;
|
|
37
|
+
/**
|
|
38
|
+
* whether that release hands a project's
|
|
39
|
+
* run to the project's release (spec AST-081 FR9); `null` when unknown
|
|
40
|
+
*/
|
|
41
|
+
handsOff: boolean | null;
|
|
42
|
+
};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The `astryx` commands on the computer's search path (spec AST-081
|
|
5
|
+
* FR10, FR11): which program each one starts, in the order a shell tries
|
|
6
|
+
* them, so `doctor`, `init --user`, and the update notices can tell the Astryx CLI
|
|
7
|
+
* apart from another program and a release that predates the hand-off from
|
|
8
|
+
* one that hands a project's run to the project's release.
|
|
9
|
+
*
|
|
10
|
+
* A command belongs to the Astryx CLI when its real file sits in the CLI
|
|
11
|
+
* package (npm and Bun link it), or when it is a package manager's small shim
|
|
12
|
+
* script that starts the CLI package's bin (npm on Windows, pnpm, Yarn); the
|
|
13
|
+
* package folder is read from the shim's text.
|
|
14
|
+
*
|
|
15
|
+
* @input the search path and, on Windows, its executable names
|
|
16
|
+
* @output one row per `astryx` command found
|
|
17
|
+
* @position packages/cli/foundation/env — read by doctor, init --user, and
|
|
18
|
+
* the update notices.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import * as fs from 'node:fs';
|
|
22
|
+
import * as path from 'node:path';
|
|
23
|
+
|
|
24
|
+
/** The CLI package whose bin the `astryx` command starts. */
|
|
25
|
+
const CLI_PACKAGE = '@astryxdesign/cli';
|
|
26
|
+
|
|
27
|
+
/** The bare command name. */
|
|
28
|
+
const COMMAND = 'astryx';
|
|
29
|
+
|
|
30
|
+
/** Shims are small; anything larger is a program, not a shim. */
|
|
31
|
+
const MAX_SHIM_BYTES = 64 * 1024;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A CLI package folder named in a shim's text, with the shim's own folder
|
|
35
|
+
* written as `$basedir` (sh), `%~dp0` or `%dp0%` (cmd), or `$PSScriptRoot`
|
|
36
|
+
* (PowerShell).
|
|
37
|
+
*/
|
|
38
|
+
const SHIM_PACKAGE =
|
|
39
|
+
/((?:\$basedir(?:_abs|_win)?|%~dp0|%dp0%|\$PSScriptRoot)?[^"'\s:;$%]*node_modules[\\/]@astryxdesign[\\/]cli)(?=[\\/"'])/gu;
|
|
40
|
+
|
|
41
|
+
/** The shim folder written in a shim's text, in each shell's spelling. */
|
|
42
|
+
const SHIM_BASE =
|
|
43
|
+
/^(?:\$basedir(?:_abs|_win)?|%~dp0|%dp0%|\$PSScriptRoot)[\\/]?/u;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The absolute target some package managers record in a shim's comment
|
|
47
|
+
* (`# cmd-shim-target=<file>`).
|
|
48
|
+
*/
|
|
49
|
+
const SHIM_TARGET_LINE = /^\s*(?:#|@?rem|::)\s*cmd-shim-target=(.+?)\s*$/imu;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @typedef {object} SearchPathCommand
|
|
53
|
+
* @property {string} file the command as the shell finds it
|
|
54
|
+
* @property {boolean} astryx whether it starts the Astryx CLI
|
|
55
|
+
* @property {string | null} cliRoot the CLI package it starts, when known
|
|
56
|
+
* @property {string | null} version that package's version, when known
|
|
57
|
+
* @property {boolean | null} handsOff whether that release hands a project's
|
|
58
|
+
* run to the project's release (spec AST-081 FR9); `null` when unknown
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The CLI package's version, when `dir` is the Astryx CLI package.
|
|
63
|
+
* @param {string} dir
|
|
64
|
+
* @returns {string | null}
|
|
65
|
+
*/
|
|
66
|
+
function cliVersionAt(dir) {
|
|
67
|
+
try {
|
|
68
|
+
const pkg = JSON.parse(
|
|
69
|
+
fs.readFileSync(path.join(dir, 'package.json'), 'utf8'),
|
|
70
|
+
);
|
|
71
|
+
return pkg?.name === CLI_PACKAGE ? String(pkg.version ?? '') : null;
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Releases that hand off carry the release-choice module.
|
|
79
|
+
* @param {string} dir
|
|
80
|
+
* @returns {boolean}
|
|
81
|
+
*/
|
|
82
|
+
function handsOffAt(dir) {
|
|
83
|
+
return fs.existsSync(path.join(dir, 'foundation', 'release', 'choose.mjs'));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The Astryx CLI package an executable starts, or null.
|
|
88
|
+
* @param {string} file
|
|
89
|
+
* @returns {string | null}
|
|
90
|
+
*/
|
|
91
|
+
export function astryxCliRootOf(file) {
|
|
92
|
+
let real;
|
|
93
|
+
try {
|
|
94
|
+
real = fs.realpathSync(file);
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
for (let dir = path.dirname(real); ;) {
|
|
99
|
+
if (cliVersionAt(dir) !== null) return dir;
|
|
100
|
+
const parent = path.dirname(dir);
|
|
101
|
+
if (parent === dir) break;
|
|
102
|
+
dir = parent;
|
|
103
|
+
}
|
|
104
|
+
let text;
|
|
105
|
+
try {
|
|
106
|
+
if (fs.statSync(real).size > MAX_SHIM_BYTES) return null;
|
|
107
|
+
text = fs.readFileSync(real, 'utf8');
|
|
108
|
+
} catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const base = path.dirname(file);
|
|
112
|
+
const target = SHIM_TARGET_LINE.exec(text)?.[1];
|
|
113
|
+
if (target && path.isAbsolute(target)) {
|
|
114
|
+
for (let dir = path.dirname(target); ;) {
|
|
115
|
+
if (cliVersionAt(dir) !== null) return dir;
|
|
116
|
+
const parent = path.dirname(dir);
|
|
117
|
+
if (parent === dir) break;
|
|
118
|
+
dir = parent;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (const match of text.matchAll(SHIM_PACKAGE)) {
|
|
122
|
+
const named = match[1]
|
|
123
|
+
.replace(SHIM_BASE, `${base}${path.sep}`)
|
|
124
|
+
.replace(/[\\/]/gu, path.sep);
|
|
125
|
+
const dir = path.resolve(base, named);
|
|
126
|
+
if (cliVersionAt(dir) !== null) return dir;
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Whether a small script names the CLI package's files, even when that
|
|
133
|
+
* package cannot be read from here.
|
|
134
|
+
* @param {string} file
|
|
135
|
+
* @returns {boolean}
|
|
136
|
+
*/
|
|
137
|
+
function namesCliPackage(file) {
|
|
138
|
+
try {
|
|
139
|
+
const real = fs.realpathSync(file);
|
|
140
|
+
if (fs.statSync(real).size > MAX_SHIM_BYTES) return false;
|
|
141
|
+
return /node_modules[\\/]@astryxdesign[\\/]cli[\\/]/u.test(
|
|
142
|
+
fs.readFileSync(real, 'utf8'),
|
|
143
|
+
);
|
|
144
|
+
} catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Every `astryx` command on the search path, in the order a shell tries
|
|
151
|
+
* them. The first row is the one that runs.
|
|
152
|
+
* @param {{searchPath?: string, platform?: NodeJS.Platform}} [options]
|
|
153
|
+
* @returns {SearchPathCommand[]}
|
|
154
|
+
*/
|
|
155
|
+
export function astryxCommandsOnSearchPath({
|
|
156
|
+
searchPath = process.env.PATH ?? process.env.Path ?? '',
|
|
157
|
+
platform = process.platform,
|
|
158
|
+
} = {}) {
|
|
159
|
+
const windows = platform === 'win32';
|
|
160
|
+
const names = windows
|
|
161
|
+
? ['astryx.cmd', 'astryx.exe', 'astryx.ps1', 'astryx']
|
|
162
|
+
: [COMMAND];
|
|
163
|
+
/** @type {SearchPathCommand[]} */
|
|
164
|
+
const rows = [];
|
|
165
|
+
const seen = new Set();
|
|
166
|
+
for (const dir of searchPath.split(windows ? ';' : path.delimiter)) {
|
|
167
|
+
if (!dir) continue;
|
|
168
|
+
for (const name of names) {
|
|
169
|
+
const file = path.join(dir, name);
|
|
170
|
+
let stat;
|
|
171
|
+
try {
|
|
172
|
+
stat = fs.statSync(file);
|
|
173
|
+
} catch {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (!stat.isFile()) continue;
|
|
177
|
+
if (!windows) {
|
|
178
|
+
try {
|
|
179
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
180
|
+
} catch {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
let key = file;
|
|
185
|
+
try {
|
|
186
|
+
key = fs.realpathSync(file);
|
|
187
|
+
} catch {
|
|
188
|
+
// Keep the path as found.
|
|
189
|
+
}
|
|
190
|
+
if (seen.has(key)) break;
|
|
191
|
+
seen.add(key);
|
|
192
|
+
const cliRoot = astryxCliRootOf(file);
|
|
193
|
+
rows.push({
|
|
194
|
+
file,
|
|
195
|
+
astryx: cliRoot !== null || namesCliPackage(file),
|
|
196
|
+
cliRoot,
|
|
197
|
+
version: cliRoot ? cliVersionAt(cliRoot) : null,
|
|
198
|
+
handsOff: cliRoot ? handsOffAt(cliRoot) : null,
|
|
199
|
+
});
|
|
200
|
+
// One command per folder: the shell runs the first name it finds.
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return rows;
|
|
205
|
+
}
|