@astryxdesign/cli 0.7.3-canary.cb489ff → 0.7.3-canary.cde6233
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 +68 -68
- package/api/build/blocks/blocks.d.mts +6 -4
- package/api/build/blocks/blocks.mjs +103 -20
- package/api/build/blocks/blocks.test.mjs +126 -13
- package/api/build/blocks/blocks.weights.json +1 -1
- package/api/build/kit/answer.d.mts +5 -4
- package/api/build/kit/answer.mjs +114 -12
- package/api/build/kit/answer.test.mjs +73 -3
- package/api/build/kit/signals.d.mts +8 -0
- package/api/build/kit/signals.mjs +10 -0
- package/api/build/tree.test.mjs +19 -11
- package/api/component/component-replacement.test.mjs +1 -0
- package/api/component/component.mjs +17 -3
- package/api/component/component.test.mjs +15 -0
- package/api/component/doc-links.test.mjs +2 -2
- package/api/docs/_adapter.d.mts +2 -2
- package/api/docs/_adapter.mjs +61 -18
- package/api/docs/docs-homes.test.mjs +127 -0
- package/api/docs/docs.doc.mjs +3 -3
- package/api/docs/docs.test.mjs +28 -18
- package/api/docs/integration-tree.test.mjs +20 -20
- package/api/docs/integrationDocs.test.mjs +1 -1
- package/api/docs/namespace-section.test.mjs +6 -6
- package/api/docs/reference-blocks.test.mjs +2 -2
- package/api/doctor/doctor.mjs +16 -12
- package/api/doctor/doctor.test.mjs +9 -9
- package/api/hook/hook.mjs +1 -1
- package/api/integration/_adapter.d.mts +8 -0
- package/api/integration/_adapter.mjs +21 -1
- package/api/integration/authoring-checks.test.mjs +220 -0
- package/api/integration/validate-integration-fixes.test.mjs +6 -5
- package/api/integration/validate-integration-gaps.test.mjs +9 -1
- package/api/integration/validate-integration.d.mts +4 -0
- package/api/integration/validate-integration.mjs +72 -7
- package/api/integration/validate-integration.type.d.mts +36 -4
- package/api/integration/validate-integration.type.mjs +27 -5
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/_adapter.d.mts +16 -0
- package/api/search/_adapter.mjs +39 -0
- package/api/search/_adapter.test.mjs +173 -0
- package/api/search/_candidate-score.mjs +1 -1
- package/api/search/_entries.d.mts +11 -0
- package/api/search/_entries.mjs +77 -3
- package/api/search/_entries.test.mjs +48 -0
- package/api/search/_gather-docs.mjs +3 -3
- package/api/search/search.doc.mjs +1 -1
- package/api/search/search.mjs +6 -2
- package/api/search/search.test.mjs +14 -14
- package/assets/docs/author-a-theme.doc.mjs +2 -2
- package/assets/docs/tree/add-a-component.doc.mjs +1 -1
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +2 -2
- package/assets/docs/tree/agent-guidance.doc.mjs +1 -1
- package/assets/docs/tree/{integrations.doc.mjs → authoring.doc.mjs} +15 -6
- package/assets/docs/tree/block-template.doc.mjs +1 -1
- package/assets/docs/tree/build-the-template.doc.mjs +1 -1
- package/assets/docs/tree/building-blocks.doc.mjs +2 -2
- package/assets/docs/tree/check-the-props.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +3 -3
- package/assets/docs/tree/cli-command.doc.mjs +1 -1
- package/assets/docs/tree/cli.doc.mjs +1 -1
- package/assets/docs/tree/codemods.doc.mjs +1 -1
- package/assets/docs/tree/component-family.doc.mjs +1 -1
- package/assets/docs/tree/component-imports.doc.mjs +1 -1
- package/assets/docs/tree/components.doc.mjs +1 -1
- package/assets/docs/tree/configuration.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -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 +1 -1
- package/assets/docs/tree/document-the-template.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
- package/assets/docs/tree/extend-or-replace.doc.mjs +1 -1
- package/assets/docs/{authoring.doc.mjs → tree/field-reference.doc.mjs} +4 -3
- package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
- package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
- package/assets/docs/tree/global-integrations.doc.mjs +2 -2
- package/assets/docs/tree/grade-template-with-agent.doc.mjs +4 -4
- package/assets/docs/tree/help.doc.mjs +2 -2
- package/assets/docs/tree/links.doc.mjs +1 -1
- package/assets/docs/tree/package-and-test.doc.mjs +1 -1
- package/assets/docs/tree/page-template.doc.mjs +1 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -1
- package/assets/docs/tree/quick-start.doc.mjs +1 -1
- package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
- package/assets/docs/tree/replace-a-core-template.doc.mjs +1 -1
- package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/see-it-in-an-app.doc.mjs +1 -1
- package/assets/docs/tree/ship.doc.mjs +2 -2
- package/assets/docs/tree/short-and-findable.doc.mjs +1 -1
- package/assets/docs/tree/single-component.doc.mjs +1 -1
- package/assets/docs/tree/start-a-template.doc.mjs +1 -1
- package/assets/docs/tree/subcomponent.doc.mjs +1 -1
- package/assets/docs/tree/template-assets.doc.mjs +1 -1
- package/assets/docs/tree/template-doc-overview.doc.mjs +2 -2
- package/assets/docs/tree/template-fonts.doc.mjs +1 -1
- package/assets/docs/tree/template-grading-rubric.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +1 -1
- package/assets/docs/tree/template-images-media.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +1 -1
- package/assets/docs/tree/templates.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
- package/assets/docs/tree/themes.doc.mjs +1 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +1 -1
- package/assets/docs/tree/upgrading.doc.mjs +1 -1
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
- package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
- package/assets/docs/tree/versioning.doc.mjs +5 -1
- package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
- package/assets/docs/tree/write-the-template-file.doc.mjs +1 -1
- package/assets/docs/use-integrations.doc.mjs +120 -0
- package/assets/templates/themes/butter/butterTheme.ts +4 -2
- package/assets/templates/themes/stone/stoneTheme.ts +4 -2
- package/assets/templates/themes/y2k/y2kTheme.ts +4 -2
- package/authoring/doctypes/schema/schema.doc.mjs +1 -1
- package/authoring/integration/integration.doc.mjs +1 -1
- package/authoring/integration/type.ts +1 -1
- package/clients/cli/command-result-coverage.test.mjs +6 -5
- package/clients/cli/commands/build-theme.color-scheme.test.mjs +1 -1
- package/clients/cli/commands/{component/index.mjs → component.mjs} +37 -37
- package/clients/cli/commands/component.test.mjs +6 -6
- package/clients/cli/commands/docs.doc.mjs +2 -2
- package/clients/cli/commands/docs.mjs +1 -1
- package/clients/cli/commands/docs.test.mjs +14 -14
- package/clients/cli/commands/doctor-integration.test.mjs +49 -1
- package/clients/cli/commands/doctor.mjs +10 -0
- package/clients/cli/commands/{hook/index.mjs → hook.mjs} +22 -22
- package/clients/cli/commands/import-hint-correctness.test.mjs +1 -1
- package/clients/cli/commands/integration-check.test.mjs +48 -0
- package/clients/cli/commands/integration.doc.mjs +1 -1
- package/clients/cli/commands/manifest.doc.mjs +1 -1
- package/clients/cli/commands/manifest.mjs +67 -0
- package/clients/cli/commands/postinstall.doc.mjs +23 -0
- package/clients/cli/commands/postinstall.mjs +31 -0
- package/clients/cli/commands/{build-theme.mjs → theme.mjs} +1 -1
- package/clients/cli/index.mjs +10 -85
- package/clients/cli/lib/component-format.mjs +1 -1
- package/clients/cli/lib/define-command.mjs +12 -7
- package/clients/cli/lib/exit-codes.test.mjs +5 -0
- package/clients/cli/lib/manifest.test.mjs +12 -0
- package/clients/cli/lib/welcome-box.mjs +50 -0
- package/foundation/agent-docs/agent-docs.mjs +2 -1
- package/foundation/agent-docs/agent-docs.test.mjs +5 -4
- package/foundation/discovery/authoring-self-docs.d.mts +7 -0
- package/foundation/discovery/authoring-self-docs.mjs +16 -4
- package/foundation/discovery/authoring-self-docs.test.mjs +15 -3
- package/foundation/discovery/authoring-surface.d.mts +1 -1
- package/foundation/discovery/authoring-surface.mjs +2 -2
- package/foundation/discovery/authoring-surface.test.mjs +1 -1
- package/foundation/discovery/cli-self-docs.d.mts +2 -1
- package/foundation/discovery/cli-self-docs.mjs +4 -3
- package/foundation/discovery/cli-self-docs.test.mjs +2 -2
- package/foundation/discovery/runner-allowlist.d.mts +2 -4
- package/foundation/discovery/runner-allowlist.mjs +2 -4
- package/foundation/discovery/runner-commands.d.mts +77 -0
- package/foundation/discovery/runner-commands.mjs +294 -0
- package/foundation/discovery/runner-commands.test.mjs +128 -0
- package/foundation/discovery/stray-pointers.test.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +25 -9
- package/foundation/doc-compiler/split-topic-keywords.test.mjs +3 -2
- package/foundation/doc-compiler/tree.d.mts +32 -6
- package/foundation/doc-compiler/tree.mjs +77 -43
- package/foundation/doc-compiler/tree.test.mjs +7 -7
- package/foundation/fs/read-record.d.mts +18 -0
- package/foundation/fs/read-record.mjs +131 -0
- package/foundation/fs/read-record.test.mjs +77 -0
- package/foundation/integrations/cli-peer-version.d.mts +36 -0
- package/foundation/integrations/cli-peer-version.mjs +132 -0
- package/foundation/integrations/cli-peer-version.test.mjs +354 -0
- package/foundation/integrations/exports-subpaths.d.mts +57 -0
- package/foundation/integrations/exports-subpaths.mjs +113 -0
- package/foundation/integrations/public-imports.d.mts +81 -0
- package/foundation/integrations/public-imports.mjs +976 -0
- package/foundation/integrations/public-imports.test.mjs +868 -0
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Tests for the CLI peer version warning.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {describe, it, expect, beforeAll, afterAll} from 'vitest';
|
|
8
|
+
import * as fs from 'node:fs';
|
|
9
|
+
import * as os from 'node:os';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import {cliPeerVersionProblem, cliVersion} from './cli-peer-version.mjs';
|
|
12
|
+
import {runCli} from '../../test-utils/run-cli.mjs';
|
|
13
|
+
|
|
14
|
+
/** @type {string} */
|
|
15
|
+
let tmpDir;
|
|
16
|
+
|
|
17
|
+
beforeAll(() => {
|
|
18
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-cli-peer-'));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterAll(() => {
|
|
22
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} name
|
|
27
|
+
* @param {Record<string, unknown>} pkgJson
|
|
28
|
+
*/
|
|
29
|
+
function makeIntegration(name, pkgJson) {
|
|
30
|
+
const dir = path.join(tmpDir, name.replace(/[/@]/g, '_'));
|
|
31
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
32
|
+
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(pkgJson));
|
|
33
|
+
return {name, version: String(pkgJson.version ?? '1.0.0'), __packageDir: dir};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('cliPeerVersionProblem', () => {
|
|
37
|
+
it('returns null when no @astryxdesign/cli peer is declared', () => {
|
|
38
|
+
const integration = makeIntegration('@test/no-peer', {
|
|
39
|
+
name: '@test/no-peer',
|
|
40
|
+
version: '1.0.0',
|
|
41
|
+
});
|
|
42
|
+
expect(cliPeerVersionProblem(integration, '0.6.5', tmpDir)).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('returns null when the CLI satisfies the peer range', () => {
|
|
46
|
+
const integration = makeIntegration('@test/satisfied', {
|
|
47
|
+
name: '@test/satisfied',
|
|
48
|
+
version: '1.0.0',
|
|
49
|
+
peerDependencies: {'@astryxdesign/cli': '>=0.6.0'},
|
|
50
|
+
});
|
|
51
|
+
expect(cliPeerVersionProblem(integration, '0.6.5', tmpDir)).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('warns when the CLI is below the peer range', () => {
|
|
55
|
+
const integration = makeIntegration('@test/needs-newer', {
|
|
56
|
+
name: '@test/needs-newer',
|
|
57
|
+
version: '2.0.0',
|
|
58
|
+
peerDependencies: {'@astryxdesign/cli': '>=0.8.0'},
|
|
59
|
+
});
|
|
60
|
+
const project = path.join(tmpDir, 'npm-project');
|
|
61
|
+
fs.mkdirSync(project, {recursive: true});
|
|
62
|
+
fs.writeFileSync(path.join(project, 'package-lock.json'), '{}\n');
|
|
63
|
+
expect(cliPeerVersionProblem(integration, '0.6.5', project)).toBe(
|
|
64
|
+
'@test/needs-newer needs @astryxdesign/cli >=0.8.0, but this CLI is 0.6.5, so some of what it ships may not load. Upgrade Core and the CLI together: `npm install @astryxdesign/core@latest @astryxdesign/cli@latest`, then `npx astryx upgrade --from 0.6.5 --apply`.',
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("names the project's own package manager in the upgrade command", () => {
|
|
69
|
+
const project = path.join(tmpDir, 'pnpm-project');
|
|
70
|
+
fs.mkdirSync(project, {recursive: true});
|
|
71
|
+
fs.writeFileSync(path.join(project, 'pnpm-lock.yaml'), "lockfileVersion: '9.0'\n");
|
|
72
|
+
const integration = makeIntegration('@test/pnpm', {
|
|
73
|
+
name: '@test/pnpm',
|
|
74
|
+
version: '1.0.0',
|
|
75
|
+
peerDependencies: {'@astryxdesign/cli': '>=0.8.0'},
|
|
76
|
+
});
|
|
77
|
+
expect(cliPeerVersionProblem(integration, '0.6.5', project)).toContain(
|
|
78
|
+
'`pnpm add @astryxdesign/core@latest @astryxdesign/cli@latest`, then `pnpm exec astryx upgrade --from 0.6.5 --apply`',
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('starts the upgrade from the version it is given, such as a Core-only project\'s Core', () => {
|
|
83
|
+
const project = path.join(tmpDir, 'from-npm-project');
|
|
84
|
+
fs.mkdirSync(project, {recursive: true});
|
|
85
|
+
fs.writeFileSync(path.join(project, 'package-lock.json'), '{}\n');
|
|
86
|
+
const integration = makeIntegration('@test/from', {
|
|
87
|
+
name: '@test/from',
|
|
88
|
+
version: '1.0.0',
|
|
89
|
+
peerDependencies: {'@astryxdesign/cli': '>=0.8.0'},
|
|
90
|
+
});
|
|
91
|
+
expect(
|
|
92
|
+
cliPeerVersionProblem(integration, '0.7.3', project, {from: '0.6.0'}),
|
|
93
|
+
).toContain('upgrade --from 0.6.0 --apply');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('installs them as dev dependencies in the package being authored', () => {
|
|
97
|
+
const project = path.join(tmpDir, 'own-npm-project');
|
|
98
|
+
fs.mkdirSync(project, {recursive: true});
|
|
99
|
+
fs.writeFileSync(path.join(project, 'package-lock.json'), '{}\n');
|
|
100
|
+
const integration = makeIntegration('@test/own-below', {
|
|
101
|
+
name: '@test/own-below',
|
|
102
|
+
version: '1.0.0',
|
|
103
|
+
peerDependencies: {'@astryxdesign/cli': '>=0.8.0'},
|
|
104
|
+
});
|
|
105
|
+
expect(
|
|
106
|
+
cliPeerVersionProblem(integration, '0.6.5', project, {own: true}),
|
|
107
|
+
).toContain(
|
|
108
|
+
'`npm install -D @astryxdesign/core@latest @astryxdesign/cli@latest`, then `npx astryx upgrade --from 0.6.5 --apply`',
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('does not ask for an upgrade when the CLI is newer than the range', () => {
|
|
113
|
+
const integration = makeIntegration('@test/older', {
|
|
114
|
+
name: '@test/older',
|
|
115
|
+
version: '1.0.0',
|
|
116
|
+
peerDependencies: {'@astryxdesign/cli': '^0.6.0'},
|
|
117
|
+
});
|
|
118
|
+
expect(cliPeerVersionProblem(integration, '0.7.3', tmpDir)).toBe(
|
|
119
|
+
'@test/older supports @astryxdesign/cli ^0.6.0, but this CLI is 0.7.3, outside that range, so some of what it ships may not work as its author tested. Look for a release of @test/older that supports 0.7.3.',
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('handles a caret range that excludes the running CLI', () => {
|
|
124
|
+
const integration = makeIntegration('@test/caret', {
|
|
125
|
+
name: '@test/caret',
|
|
126
|
+
version: '1.0.0',
|
|
127
|
+
peerDependencies: {'@astryxdesign/cli': '^1.0.0'},
|
|
128
|
+
});
|
|
129
|
+
expect(cliPeerVersionProblem(integration, '0.6.5', tmpDir)).toContain(
|
|
130
|
+
'^1.0.0',
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('returns null for a caret range the CLI satisfies', () => {
|
|
135
|
+
const integration = makeIntegration('@test/caret-ok', {
|
|
136
|
+
name: '@test/caret-ok',
|
|
137
|
+
version: '1.0.0',
|
|
138
|
+
peerDependencies: {'@astryxdesign/cli': '^0.6.0'},
|
|
139
|
+
});
|
|
140
|
+
expect(cliPeerVersionProblem(integration, '0.6.5', tmpDir)).toBeNull();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('tells the author to test and widen the range when the package is their own', () => {
|
|
144
|
+
const integration = makeIntegration('@test/own', {
|
|
145
|
+
name: '@test/own',
|
|
146
|
+
version: '1.0.0',
|
|
147
|
+
peerDependencies: {'@astryxdesign/cli': '^0.6.0'},
|
|
148
|
+
});
|
|
149
|
+
expect(cliPeerVersionProblem(integration, '0.7.3', tmpDir, {own: true})).toBe(
|
|
150
|
+
'@test/own declares @astryxdesign/cli ^0.6.0, but this CLI is 0.7.3, outside that range. Test the package with this CLI, and if it works, widen the @astryxdesign/cli range in its peerDependencies.',
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('warns for an optional peer the CLI does not satisfy', () => {
|
|
155
|
+
// Optional peers are still peers: the integration needs a newer CLI to
|
|
156
|
+
// work fully. The warning is about the CLI version, not about whether
|
|
157
|
+
// the peer is required for install.
|
|
158
|
+
const integration = makeIntegration('@test/optional', {
|
|
159
|
+
name: '@test/optional',
|
|
160
|
+
version: '1.0.0',
|
|
161
|
+
peerDependencies: {'@astryxdesign/cli': '>=0.9.0'},
|
|
162
|
+
peerDependenciesMeta: {'@astryxdesign/cli': {optional: true}},
|
|
163
|
+
});
|
|
164
|
+
expect(cliPeerVersionProblem(integration, '0.6.5', tmpDir)).not.toBeNull();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('handles a prerelease CLI version gracefully', () => {
|
|
168
|
+
const integration = makeIntegration('@test/prerelease', {
|
|
169
|
+
name: '@test/prerelease',
|
|
170
|
+
version: '1.0.0',
|
|
171
|
+
peerDependencies: {'@astryxdesign/cli': '>=0.7.0'},
|
|
172
|
+
});
|
|
173
|
+
// A canary like 0.7.0-canary.abc123 should satisfy >=0.7.0
|
|
174
|
+
expect(cliPeerVersionProblem(integration, '0.7.0-canary.abc123', tmpDir)).toBeNull();
|
|
175
|
+
// A canary below the floor should warn
|
|
176
|
+
expect(
|
|
177
|
+
cliPeerVersionProblem(integration, '0.6.5-canary.xyz', tmpDir),
|
|
178
|
+
).not.toBeNull();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('returns null when __packageDir is missing', () => {
|
|
182
|
+
const integration = {name: '@test/no-dir', version: '1.0.0'};
|
|
183
|
+
expect(cliPeerVersionProblem(integration, '0.6.5', tmpDir)).toBeNull();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('returns null when package.json cannot be read', () => {
|
|
187
|
+
const integration = {
|
|
188
|
+
name: '@test/bad-dir',
|
|
189
|
+
version: '1.0.0',
|
|
190
|
+
__packageDir: path.join(tmpDir, 'nonexistent'),
|
|
191
|
+
};
|
|
192
|
+
expect(cliPeerVersionProblem(integration, '0.6.5', tmpDir)).toBeNull();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('cliVersion', () => {
|
|
197
|
+
it('returns a valid semver string', () => {
|
|
198
|
+
const ver = cliVersion();
|
|
199
|
+
expect(ver).toMatch(/^\d+\.\d+\.\d+/);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('as a note that fails nothing', () => {
|
|
204
|
+
/**
|
|
205
|
+
* An integration package at `dir` whose CLI peer range is `range`.
|
|
206
|
+
* @param {string} dir
|
|
207
|
+
* @param {string} range
|
|
208
|
+
*/
|
|
209
|
+
function writeIntegration(dir, range) {
|
|
210
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
211
|
+
fs.writeFileSync(
|
|
212
|
+
path.join(dir, 'package.json'),
|
|
213
|
+
JSON.stringify({
|
|
214
|
+
name: '@acme/widgets',
|
|
215
|
+
version: '1.0.0',
|
|
216
|
+
peerDependencies: {'@astryxdesign/cli': range},
|
|
217
|
+
}),
|
|
218
|
+
);
|
|
219
|
+
fs.writeFileSync(path.join(dir, 'astryx.integration.mjs'), 'export default {};\n');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* A project with a lockfile that installs @acme/widgets.
|
|
224
|
+
* @param {string} range
|
|
225
|
+
*/
|
|
226
|
+
function project(range) {
|
|
227
|
+
const root = fs.mkdtempSync(path.join(tmpDir, 'project-'));
|
|
228
|
+
fs.writeFileSync(
|
|
229
|
+
path.join(root, 'package.json'),
|
|
230
|
+
JSON.stringify({
|
|
231
|
+
name: 'app',
|
|
232
|
+
version: '1.0.0',
|
|
233
|
+
dependencies: {'@acme/widgets': '^1.0.0'},
|
|
234
|
+
}),
|
|
235
|
+
);
|
|
236
|
+
fs.writeFileSync(path.join(root, 'package-lock.json'), '{}\n');
|
|
237
|
+
writeIntegration(path.join(root, 'node_modules', '@acme', 'widgets'), range);
|
|
238
|
+
return root;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** @param {string} [dev] */
|
|
242
|
+
const below = (dev = '') =>
|
|
243
|
+
`@acme/widgets needs @astryxdesign/cli >=99.0.0, but this CLI is ${cliVersion()}, so some of what it ships may not load. Upgrade Core and the CLI together: \`npm install${dev} @astryxdesign/core@latest @astryxdesign/cli@latest\`, then \`npx astryx upgrade --from ${cliVersion()} --apply\`.`;
|
|
244
|
+
|
|
245
|
+
it('doctor integration validate lists it in data.notes, never in data.issues, and exits 0', async () => {
|
|
246
|
+
const cwd = project('>=99.0.0');
|
|
247
|
+
const {status, stdout} = await runCli(
|
|
248
|
+
['doctor', 'integration', 'validate', '@acme/widgets', '--json'],
|
|
249
|
+
{cwd},
|
|
250
|
+
);
|
|
251
|
+
const {data} = JSON.parse(stdout);
|
|
252
|
+
expect(status).toBe(0);
|
|
253
|
+
expect(data.notes).toContainEqual({code: 'cli_peer_version', message: below()});
|
|
254
|
+
expect(data.issues.map((/** @type {{code: string}} */ i) => i.code)).not.toContain(
|
|
255
|
+
'cli_peer_version',
|
|
256
|
+
);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('integration check --strict carries the note and still exits 0', async () => {
|
|
260
|
+
const pkg = fs.mkdtempSync(path.join(tmpDir, 'package-'));
|
|
261
|
+
writeIntegration(pkg, '>=99.0.0');
|
|
262
|
+
fs.writeFileSync(path.join(pkg, 'package-lock.json'), '{}\n');
|
|
263
|
+
const {status, stdout} = await runCli(
|
|
264
|
+
['--json', 'integration', 'check', '--strict'],
|
|
265
|
+
{cwd: pkg},
|
|
266
|
+
);
|
|
267
|
+
const envelope = JSON.parse(stdout);
|
|
268
|
+
const validate = envelope.data.checks[0].response.data;
|
|
269
|
+
expect(validate.notes).toContainEqual({
|
|
270
|
+
code: 'cli_peer_version',
|
|
271
|
+
message: below(' -D'),
|
|
272
|
+
});
|
|
273
|
+
expect(validate.issues.map((/** @type {{code: string}} */ i) => i.code)).not.toContain(
|
|
274
|
+
'cli_peer_version',
|
|
275
|
+
);
|
|
276
|
+
expect(envelope.data.failed).toBe(false);
|
|
277
|
+
expect(status).toBe(0);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('starts the upgrade from the Core of a project with no CLI of its own', async () => {
|
|
281
|
+
const cwd = project('>=99.0.0');
|
|
282
|
+
const pkgJson = path.join(cwd, 'package.json');
|
|
283
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJson, 'utf8'));
|
|
284
|
+
pkg.dependencies['@astryxdesign/core'] = '0.6.0';
|
|
285
|
+
fs.writeFileSync(pkgJson, JSON.stringify(pkg));
|
|
286
|
+
const core = path.join(cwd, 'node_modules', '@astryxdesign', 'core');
|
|
287
|
+
fs.mkdirSync(core, {recursive: true});
|
|
288
|
+
fs.writeFileSync(
|
|
289
|
+
path.join(core, 'package.json'),
|
|
290
|
+
JSON.stringify({name: '@astryxdesign/core', version: '0.6.0'}),
|
|
291
|
+
);
|
|
292
|
+
const {status, stdout} = await runCli(
|
|
293
|
+
['doctor', 'integration', 'validate', '@acme/widgets', '--json'],
|
|
294
|
+
{cwd},
|
|
295
|
+
);
|
|
296
|
+
expect(status).toBe(0);
|
|
297
|
+
const note = JSON.parse(stdout).data.notes.find(
|
|
298
|
+
(/** @type {{code: string}} */ n) => n.code === 'cli_peer_version',
|
|
299
|
+
);
|
|
300
|
+
expect(note.message).toContain('upgrade --from 0.6.0 --apply');
|
|
301
|
+
expect(note.message).not.toContain(`--from ${cliVersion()}`);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('asks for a release of an installed package that supports a CLI above its range', async () => {
|
|
305
|
+
const cwd = project('^0.6.0');
|
|
306
|
+
const {stdout} = await runCli(
|
|
307
|
+
['doctor', 'integration', 'validate', '@acme/widgets', '--json'],
|
|
308
|
+
{cwd},
|
|
309
|
+
);
|
|
310
|
+
expect(JSON.parse(stdout).data.notes).toContainEqual({
|
|
311
|
+
code: 'cli_peer_version',
|
|
312
|
+
message: `@acme/widgets supports @astryxdesign/cli ^0.6.0, but this CLI is ${cliVersion()}, outside that range, so some of what it ships may not work as its author tested. Look for a release of @acme/widgets that supports ${cliVersion()}.`,
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('tells the author of the package in the current folder to test and widen a range below this CLI', async () => {
|
|
317
|
+
const pkg = fs.mkdtempSync(path.join(tmpDir, 'package-'));
|
|
318
|
+
writeIntegration(pkg, '^0.6.0');
|
|
319
|
+
const {status, stdout} = await runCli(
|
|
320
|
+
['--json', 'integration', 'check', '--strict'],
|
|
321
|
+
{cwd: pkg},
|
|
322
|
+
);
|
|
323
|
+
const envelope = JSON.parse(stdout);
|
|
324
|
+
expect(envelope.data.checks[0].response.data.notes).toContainEqual({
|
|
325
|
+
code: 'cli_peer_version',
|
|
326
|
+
message: `@acme/widgets declares @astryxdesign/cli ^0.6.0, but this CLI is ${cliVersion()}, outside that range. Test the package with this CLI, and if it works, widen the @astryxdesign/cli range in its peerDependencies.`,
|
|
327
|
+
});
|
|
328
|
+
expect(envelope.data.failed).toBe(false);
|
|
329
|
+
expect(status).toBe(0);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('leaves integration verify as it was: no warning, no issue', async () => {
|
|
333
|
+
const pkg = fs.mkdtempSync(path.join(tmpDir, 'package-'));
|
|
334
|
+
writeIntegration(pkg, '>=99.0.0');
|
|
335
|
+
const {stdout} = await runCli(['--json', 'integration', 'verify'], {
|
|
336
|
+
cwd: pkg,
|
|
337
|
+
});
|
|
338
|
+
expect(stdout).not.toContain('cli_peer_version');
|
|
339
|
+
const text = await runCli(['integration', 'verify'], {cwd: pkg});
|
|
340
|
+
expect(text.stdout + text.stderr).not.toContain('needs @astryxdesign/cli');
|
|
341
|
+
}, 120_000);
|
|
342
|
+
|
|
343
|
+
it('says nothing when the CLI is in the range', async () => {
|
|
344
|
+
const cwd = project(`>=${cliVersion()}`);
|
|
345
|
+
const {stdout} = await runCli(
|
|
346
|
+
['doctor', 'integration', 'validate', '@acme/widgets', '--json'],
|
|
347
|
+
{cwd},
|
|
348
|
+
);
|
|
349
|
+
const {data} = JSON.parse(stdout);
|
|
350
|
+
expect(
|
|
351
|
+
(data.notes ?? []).map((/** @type {{code: string}} */ n) => n.code),
|
|
352
|
+
).not.toContain('cli_peer_version');
|
|
353
|
+
});
|
|
354
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
* @file How a package.json `exports` field declares a subpath, read without
|
|
6
|
+
* touching the targets (which may be build output that does not exist yet).
|
|
7
|
+
*
|
|
8
|
+
* @input A package.json `exports` value and a `.`/`./…` subpath.
|
|
9
|
+
* @output Whether the subpath is declared for an ES module importer, and why
|
|
10
|
+
* not when it is not.
|
|
11
|
+
* @position foundation/integrations; read by the public-import checks.
|
|
12
|
+
*/
|
|
13
|
+
/** @param {unknown} value @returns {value is Record<string, unknown>} */
|
|
14
|
+
export function isRecord(value: unknown): value is Record<string, unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* Whether an export value gives an ES module importer something: a string,
|
|
17
|
+
* or a condition object / fallback array with a target under a condition
|
|
18
|
+
* other than `require` and `types`.
|
|
19
|
+
* @param {unknown} value
|
|
20
|
+
* @returns {boolean}
|
|
21
|
+
*/
|
|
22
|
+
export function importable(value: unknown): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Every string target an export value names, any condition.
|
|
25
|
+
* @param {unknown} value
|
|
26
|
+
* @param {string[]} [out]
|
|
27
|
+
* @returns {string[]}
|
|
28
|
+
*/
|
|
29
|
+
export function allTargets(value: unknown, out?: string[]): string[];
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {object} SubpathDeclaration
|
|
32
|
+
* @property {'declared'|'no_exports'|'root_only'|'missing'|'blocked'|'not_importable'} state
|
|
33
|
+
* @property {unknown} [value] the matched export value
|
|
34
|
+
* @property {string} [wildcard] what a `*` key matched
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* How a package's `exports` field declares one subpath, without touching the
|
|
38
|
+
* targets: a missing key, a key with only a `require` condition, an `exports`
|
|
39
|
+
* that is a bare string or a condition object (so only `.`), a wildcard that
|
|
40
|
+
* does not match, or a `null` that blocks it. An `exports` of `null` is no
|
|
41
|
+
* `exports` field, as Node reads it.
|
|
42
|
+
* @param {unknown} exportsField
|
|
43
|
+
* @param {string} subpath `.` or `./…`
|
|
44
|
+
* @returns {SubpathDeclaration}
|
|
45
|
+
*/
|
|
46
|
+
export function subpathDeclaration(exportsField: unknown, subpath: string): SubpathDeclaration;
|
|
47
|
+
export type SubpathDeclaration = {
|
|
48
|
+
state: "declared" | "no_exports" | "root_only" | "missing" | "blocked" | "not_importable";
|
|
49
|
+
/**
|
|
50
|
+
* the matched export value
|
|
51
|
+
*/
|
|
52
|
+
value?: unknown;
|
|
53
|
+
/**
|
|
54
|
+
* what a `*` key matched
|
|
55
|
+
*/
|
|
56
|
+
wildcard?: string | undefined;
|
|
57
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file How a package.json `exports` field declares a subpath, read without
|
|
5
|
+
* touching the targets (which may be build output that does not exist yet).
|
|
6
|
+
*
|
|
7
|
+
* @input A package.json `exports` value and a `.`/`./…` subpath.
|
|
8
|
+
* @output Whether the subpath is declared for an ES module importer, and why
|
|
9
|
+
* not when it is not.
|
|
10
|
+
* @position foundation/integrations; read by the public-import checks.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** @param {unknown} value @returns {value is Record<string, unknown>} */
|
|
14
|
+
export function isRecord(value) {
|
|
15
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether an export value gives an ES module importer something: a string,
|
|
20
|
+
* or a condition object / fallback array with a target under a condition
|
|
21
|
+
* other than `require` and `types`.
|
|
22
|
+
* @param {unknown} value
|
|
23
|
+
* @returns {boolean}
|
|
24
|
+
*/
|
|
25
|
+
export function importable(value) {
|
|
26
|
+
if (typeof value === 'string') return true;
|
|
27
|
+
if (Array.isArray(value)) return value.some(importable);
|
|
28
|
+
if (!isRecord(value)) return false;
|
|
29
|
+
return Object.entries(value).some(
|
|
30
|
+
([condition, target]) =>
|
|
31
|
+
condition !== 'require' && condition !== 'types' && importable(target),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Every string target an export value names, any condition.
|
|
37
|
+
* @param {unknown} value
|
|
38
|
+
* @param {string[]} [out]
|
|
39
|
+
* @returns {string[]}
|
|
40
|
+
*/
|
|
41
|
+
export function allTargets(value, out = []) {
|
|
42
|
+
if (typeof value === 'string') out.push(value);
|
|
43
|
+
else if (Array.isArray(value)) for (const v of value) allTargets(v, out);
|
|
44
|
+
else if (isRecord(value))
|
|
45
|
+
for (const v of Object.values(value)) allTargets(v, out);
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {object} SubpathDeclaration
|
|
51
|
+
* @property {'declared'|'no_exports'|'root_only'|'missing'|'blocked'|'not_importable'} state
|
|
52
|
+
* @property {unknown} [value] the matched export value
|
|
53
|
+
* @property {string} [wildcard] what a `*` key matched
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* How a package's `exports` field declares one subpath, without touching the
|
|
58
|
+
* targets: a missing key, a key with only a `require` condition, an `exports`
|
|
59
|
+
* that is a bare string or a condition object (so only `.`), a wildcard that
|
|
60
|
+
* does not match, or a `null` that blocks it. An `exports` of `null` is no
|
|
61
|
+
* `exports` field, as Node reads it.
|
|
62
|
+
* @param {unknown} exportsField
|
|
63
|
+
* @param {string} subpath `.` or `./…`
|
|
64
|
+
* @returns {SubpathDeclaration}
|
|
65
|
+
*/
|
|
66
|
+
export function subpathDeclaration(exportsField, subpath) {
|
|
67
|
+
if (exportsField == null) return {state: 'no_exports'};
|
|
68
|
+
const keys = isRecord(exportsField) ? Object.keys(exportsField) : [];
|
|
69
|
+
// An empty object is a subpath map with no keys: it exports nothing, so
|
|
70
|
+
// every subpath (the root too) is missing from it.
|
|
71
|
+
const isMap =
|
|
72
|
+
isRecord(exportsField) && keys.every(key => key.startsWith('.'));
|
|
73
|
+
if (!isMap) {
|
|
74
|
+
if (subpath !== '.') return {state: 'root_only'};
|
|
75
|
+
return importable(exportsField)
|
|
76
|
+
? {state: 'declared', value: exportsField}
|
|
77
|
+
: {state: 'not_importable', value: exportsField};
|
|
78
|
+
}
|
|
79
|
+
const map = /** @type {Record<string, unknown>} */ (exportsField);
|
|
80
|
+
/** @type {{value: unknown, wildcard: string} | null} */
|
|
81
|
+
let hit = null;
|
|
82
|
+
if (Object.hasOwn(map, subpath)) {
|
|
83
|
+
hit = {value: map[subpath], wildcard: ''};
|
|
84
|
+
} else {
|
|
85
|
+
const patterns = keys
|
|
86
|
+
.filter(key => key.split('*').length === 2)
|
|
87
|
+
.sort((a, b) => b.indexOf('*') - a.indexOf('*') || b.length - a.length);
|
|
88
|
+
for (const pattern of patterns) {
|
|
89
|
+
const star = pattern.indexOf('*');
|
|
90
|
+
const prefix = pattern.slice(0, star);
|
|
91
|
+
const suffix = pattern.slice(star + 1);
|
|
92
|
+
if (
|
|
93
|
+
subpath.length >= prefix.length + suffix.length &&
|
|
94
|
+
subpath.startsWith(prefix) &&
|
|
95
|
+
subpath.endsWith(suffix)
|
|
96
|
+
) {
|
|
97
|
+
hit = {
|
|
98
|
+
value: map[pattern],
|
|
99
|
+
wildcard: subpath.slice(
|
|
100
|
+
prefix.length,
|
|
101
|
+
subpath.length - suffix.length,
|
|
102
|
+
),
|
|
103
|
+
};
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (!hit) return {state: 'missing'};
|
|
109
|
+
if (hit.value == null) return {state: 'blocked'};
|
|
110
|
+
if (!importable(hit.value))
|
|
111
|
+
return {state: 'not_importable', value: hit.value, wildcard: hit.wildcard};
|
|
112
|
+
return {state: 'declared', value: hit.value, wildcard: hit.wildcard};
|
|
113
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
* Split a bare specifier into its package name and `./`-prefixed subpath.
|
|
6
|
+
* @param {string} specifier
|
|
7
|
+
* @returns {{pkg: string, subpath: string} | null}
|
|
8
|
+
*/
|
|
9
|
+
export function splitSpecifier(specifier: string): {
|
|
10
|
+
pkg: string;
|
|
11
|
+
subpath: string;
|
|
12
|
+
} | null;
|
|
13
|
+
/**
|
|
14
|
+
* Read the import statements of a module or a snippet: named, default,
|
|
15
|
+
* aliased, namespace and type-only. A snippet that does not parse (an example
|
|
16
|
+
* with elisions, say) falls back to reading `import … from '…'` lines.
|
|
17
|
+
* @param {string} text
|
|
18
|
+
* @returns {ImportStatement[]}
|
|
19
|
+
*/
|
|
20
|
+
export function readImports(text: string): ImportStatement[];
|
|
21
|
+
/**
|
|
22
|
+
* Every public-import finding for one package, as notes, and the report of
|
|
23
|
+
* what could not be judged. It returns no issues: the notes are listed
|
|
24
|
+
* only, and fail `--strict` from the next minor release.
|
|
25
|
+
* @param {string} packageDir
|
|
26
|
+
* @param {any} integration the loaded integration record
|
|
27
|
+
* @returns {Promise<{issues: Issue[], notes: PublicImportNote[], report: PublicImportsReport}>}
|
|
28
|
+
* `issues` is always empty: kept so validate's call site stays one shape
|
|
29
|
+
*/
|
|
30
|
+
export function publicImportIssues(packageDir: string, integration: any): Promise<{
|
|
31
|
+
issues: Issue[];
|
|
32
|
+
notes: PublicImportNote[];
|
|
33
|
+
report: PublicImportsReport;
|
|
34
|
+
}>;
|
|
35
|
+
export type SubpathDeclaration = import("./exports-subpaths.mjs").SubpathDeclaration;
|
|
36
|
+
export type PublicImportUnchecked = import("../../api/integration/validate-integration.type.mjs").PublicImportUnchecked;
|
|
37
|
+
export type PublicImportsReport = import("../../api/integration/validate-integration.type.mjs").PublicImportsReport;
|
|
38
|
+
export type PublicImportNote = {
|
|
39
|
+
code: string;
|
|
40
|
+
message: string;
|
|
41
|
+
};
|
|
42
|
+
export type Issue = import("./issue").AstryxIntegrationIssue;
|
|
43
|
+
export type ImportBinding = {
|
|
44
|
+
/**
|
|
45
|
+
* the exported name (`default` for a default import)
|
|
46
|
+
*/
|
|
47
|
+
imported: string;
|
|
48
|
+
typeOnly: boolean;
|
|
49
|
+
};
|
|
50
|
+
export type ImportStatement = {
|
|
51
|
+
source: string;
|
|
52
|
+
names: ImportBinding[];
|
|
53
|
+
namespace: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* the whole statement is `import type`
|
|
56
|
+
*/
|
|
57
|
+
typeOnly?: boolean | undefined;
|
|
58
|
+
};
|
|
59
|
+
export type Context = {
|
|
60
|
+
packageDir: string;
|
|
61
|
+
/**
|
|
62
|
+
* the package name; null when package.json has
|
|
63
|
+
* none, and then no import of the package's own name is judged
|
|
64
|
+
*/
|
|
65
|
+
name: string | null;
|
|
66
|
+
exportsField: unknown;
|
|
67
|
+
coreDir: string | null;
|
|
68
|
+
corePkg: any;
|
|
69
|
+
/**
|
|
70
|
+
* what could not be judged
|
|
71
|
+
*/
|
|
72
|
+
unchecked: PublicImportUnchecked[];
|
|
73
|
+
/**
|
|
74
|
+
* the package.json `files` entries, normalized
|
|
75
|
+
*/
|
|
76
|
+
files: string[];
|
|
77
|
+
/**
|
|
78
|
+
* the integration's contribution roots, absolute
|
|
79
|
+
*/
|
|
80
|
+
roots: string[];
|
|
81
|
+
};
|