@astryxdesign/cli 0.6.5 → 0.6.6
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/CHANGELOG.md +87 -0
- package/README.md +16 -15
- package/api/build/_adapter.d.mts +50 -2
- package/api/build/_adapter.mjs +98 -10
- package/api/build/build.doc.mjs +2 -2
- package/api/build/build.test.mjs +111 -2
- package/api/build/kit/kit.mjs +98 -22
- package/api/build/kit/rank.d.mts +32 -8
- package/api/build/kit/rank.mjs +291 -97
- package/api/build/kit/rank.test.mjs +231 -48
- package/api/build/kit/weights.d.mts +82 -0
- package/api/build/kit/weights.json +1 -0
- package/api/build/kit/weights.mjs +305 -0
- package/api/build/kit/weights.test.mjs +190 -0
- package/api/docs/docs.d.mts +6 -0
- package/api/docs/docs.depth.test.mjs +132 -0
- package/api/docs/docs.doc.mjs +31 -2
- package/api/docs/docs.mjs +44 -1
- package/api/docs/docs.test.mjs +279 -0
- package/api/docs/docs.type.d.mts +38 -1
- package/api/docs/docs.type.mjs +18 -1
- package/api/docs/integration-tree.test.mjs +572 -0
- package/api/docs/integrationDocs.test.mjs +336 -0
- package/api/docs/node/node.d.mts +28 -3
- package/api/docs/node/node.mjs +146 -23
- package/api/error.d.mts +22 -0
- package/api/error.mjs +42 -0
- package/api/gap-report/gap-report.d.mts +3 -1
- package/api/gap-report/gap-report.mjs +12 -2
- package/api/gap-report/gap-report.test.mjs +106 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-contribution.test.mjs +3 -3
- package/api/integration/add-theme.mjs +338 -26
- package/api/integration/add-theme.test.mjs +314 -1
- package/api/integration/authoring-checks.mjs +10 -7
- package/api/integration/authoring-checks.type.d.mts +8 -0
- package/api/integration/authoring-checks.type.mjs +7 -3
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/pack-check.mjs +12 -3
- package/api/integration/pack-check.test.mjs +52 -3
- package/api/integration/validate-integration.d.mts +4 -2
- package/api/integration/validate-integration.mjs +7 -2
- package/api/integration/validate-integration.test.mjs +55 -0
- package/api/integration/validate-integration.type.d.mts +5 -0
- package/api/integration/validate-integration.type.mjs +5 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/search/search.d.mts +36 -5
- package/api/search/search.doc.mjs +4 -4
- package/api/search/search.mjs +194 -54
- package/api/search/search.test.mjs +825 -0
- package/api/search/search.type.d.mts +5 -5
- package/api/search/search.type.mjs +5 -5
- package/api/swizzle/copy/copy.mjs +66 -3
- package/api/swizzle/swizzle.doc.mjs +4 -0
- package/api/template/copy/copy.mjs +14 -8
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/show/show.mjs +15 -4
- package/api/template/show/show.test.mjs +76 -0
- package/api/template/template-integration.test.mjs +14 -0
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +6 -2
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +2 -0
- package/api/template/template.type.mjs +2 -0
- package/api/theme/build/build.d.mts +24 -0
- package/api/theme/build/build.icon-lineage.test.mjs +117 -0
- package/api/theme/build/build.icon-preservation.test.mjs +639 -0
- package/api/theme/build/build.mjs +381 -77
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/theme/build/build.test.mjs +190 -1
- package/api/theme/build/icon-imports.d.mts +47 -0
- package/api/theme/build/icon-imports.mjs +691 -0
- package/api/theme/themeBuild.doc.d.mts +4 -1
- package/api/theme/themeBuild.doc.mjs +14 -3
- package/api/upgrade/run/run.mjs +20 -3
- package/api/upgrade/run/run.test.mjs +45 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +1 -0
- package/api/upgrade/upgrade.type.mjs +1 -0
- package/assets/docs/icons.doc.mjs +1 -0
- package/assets/docs/theme.doc.mjs +3 -2
- package/assets/docs/tokens.doc.mjs +3 -3
- package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
- package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.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/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +9 -5
- package/assets/docs/tree/versioning.doc.mjs +7 -6
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
- package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
- package/assets/templates/pages/blank/template.doc.mjs +3 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
- package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
- package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
- package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
- package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
- package/assets/templates/pages/documentation/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
- package/assets/templates/pages/editor/template.doc.mjs +9 -1
- package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
- package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
- package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
- package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
- package/assets/templates/pages/ide/template.doc.mjs +9 -1
- package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
- package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
- package/assets/templates/pages/library/template.doc.mjs +15 -1
- package/assets/templates/pages/login/template.doc.mjs +10 -1
- package/assets/templates/pages/login-card/template.doc.mjs +11 -1
- package/assets/templates/pages/login-split/template.doc.mjs +10 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
- package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
- package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/settings/template.doc.mjs +3 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/table/template.doc.mjs +11 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
- package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
- package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
- package/assets/templates/pages/table-page/template.doc.mjs +20 -1
- package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
- package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
- package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/authoring/doctypes/template/parse.d.mts +2 -0
- package/authoring/doctypes/template/parse.mjs +1 -0
- package/authoring/doctypes/template/parse.test.mjs +21 -0
- package/authoring/doctypes/template/template.doc.mjs +6 -0
- package/authoring/doctypes/template/type.ts +10 -0
- package/clients/cli/commands/build-theme.mjs +8 -2
- package/clients/cli/commands/discover.mjs +29 -1
- package/clients/cli/commands/discover.no-source.test.mjs +75 -0
- package/clients/cli/commands/docs.depth.test.mjs +219 -0
- package/clients/cli/commands/docs.doc.mjs +15 -2
- package/clients/cli/commands/docs.mjs +222 -5
- package/clients/cli/commands/docs.test.mjs +383 -0
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/gap-report.mjs +12 -0
- package/clients/cli/commands/gap-report.test.mjs +63 -0
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-expand.doc.mjs +3 -1
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +16 -0
- package/clients/cli/commands/search.doc.mjs +5 -4
- package/clients/cli/commands/search.mjs +30 -6
- package/clients/cli/commands/search.test.mjs +60 -16
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +19 -5
- package/clients/cli/commands/template.show-media.test.mjs +62 -0
- package/clients/cli/commands/theme-list.behavior.test.mjs +41 -0
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
- package/clients/cli/commands/write-failure.test.mjs +175 -0
- package/clients/cli/lib/manifest.mjs +44 -165
- package/clients/cli/lib/manifest.test.mjs +98 -7
- package/foundation/agent-docs/agent-docs.mjs +2 -1
- package/foundation/agent-docs/agent-docs.test.mjs +1168 -0
- package/foundation/discovery/template-adapter.d.mts +14 -0
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
- package/foundation/discovery/template-adapter.mjs +21 -1
- package/foundation/discovery/theme-discovery.d.mts +6 -0
- package/foundation/discovery/theme-discovery.mjs +9 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +3 -3
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- package/foundation/doc-compiler/tree.test.mjs +649 -0
- package/foundation/integrations/cli-requirement.d.mts +57 -13
- package/foundation/integrations/cli-requirement.mjs +84 -22
- package/foundation/integrations/cli-requirement.test.mjs +135 -8
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +13 -13
- package/package.json +1 -1
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file End-to-end tests for integration-contributed doc topics: a scaffolded
|
|
5
|
+
* consumer project whose configured integration ships a `docs` root, read back
|
|
6
|
+
* through the public surfaces — `docs()`, `search()`, and the agent-docs block.
|
|
7
|
+
*
|
|
8
|
+
* The unit-level rules (what a docs root contributes, what the catalog does
|
|
9
|
+
* with `replaces`/`extends`) are covered in
|
|
10
|
+
* foundation/discovery/docs-discovery.test.mjs. What is pinned here is that a
|
|
11
|
+
* contributed topic is indistinguishable from a built-in one at the surfaces
|
|
12
|
+
* an agent actually reads.
|
|
13
|
+
*
|
|
14
|
+
* Fixtures live under a repo-local temp dir, not /tmp, because Vite refuses to
|
|
15
|
+
* dynamically import a module from outside the project root.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
19
|
+
import * as fs from 'node:fs';
|
|
20
|
+
import * as path from 'node:path';
|
|
21
|
+
import {docs} from './docs.mjs';
|
|
22
|
+
import {search} from '../search/search.mjs';
|
|
23
|
+
import {loadDocsCatalog} from './_adapter.mjs';
|
|
24
|
+
import {AstryxError} from '../error.mjs';
|
|
25
|
+
|
|
26
|
+
const SLOW = 30_000;
|
|
27
|
+
|
|
28
|
+
let tmpDir;
|
|
29
|
+
|
|
30
|
+
/** A minimal, valid topic. */
|
|
31
|
+
function topic(fields) {
|
|
32
|
+
return {
|
|
33
|
+
type: 'generic',
|
|
34
|
+
name: 'deploying',
|
|
35
|
+
title: 'Deploying',
|
|
36
|
+
description: 'How to ship an app built with Acme widgets.',
|
|
37
|
+
category: 'guide',
|
|
38
|
+
sections: [
|
|
39
|
+
{title: 'Overview', content: [{type: 'prose', text: 'Push the button.'}]},
|
|
40
|
+
],
|
|
41
|
+
...fields,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A consumer project that configures one integration, optionally with a docs
|
|
47
|
+
* root holding the given topics.
|
|
48
|
+
* @param {Record<string, object|string>} [topics] file name → doc
|
|
49
|
+
* @param {{config?: string}} [options]
|
|
50
|
+
*/
|
|
51
|
+
function scaffold(topics, {config} = {}) {
|
|
52
|
+
fs.writeFileSync(path.join(tmpDir, 'package.json'), JSON.stringify({name: 'consumer'}));
|
|
53
|
+
fs.writeFileSync(
|
|
54
|
+
path.join(tmpDir, 'astryx.config.mjs'),
|
|
55
|
+
config ?? "export default {integrations: ['@acme/widgets']};\n",
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const pkgDir = path.join(tmpDir, 'node_modules', '@acme', 'widgets');
|
|
59
|
+
fs.mkdirSync(pkgDir, {recursive: true});
|
|
60
|
+
fs.writeFileSync(
|
|
61
|
+
path.join(pkgDir, 'package.json'),
|
|
62
|
+
JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
|
|
63
|
+
);
|
|
64
|
+
fs.writeFileSync(
|
|
65
|
+
path.join(pkgDir, 'astryx.integration.mjs'),
|
|
66
|
+
`export default ${JSON.stringify(topics ? {docs: './docs'} : {})};\n`,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (topics) {
|
|
70
|
+
const docsDir = path.join(pkgDir, 'docs');
|
|
71
|
+
fs.mkdirSync(docsDir, {recursive: true});
|
|
72
|
+
for (const [file, doc] of Object.entries(topics)) {
|
|
73
|
+
fs.writeFileSync(
|
|
74
|
+
path.join(docsDir, file),
|
|
75
|
+
typeof doc === 'string'
|
|
76
|
+
? doc
|
|
77
|
+
: `export const docs = ${JSON.stringify(doc, null, 2)};\n`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
beforeEach(() => {
|
|
84
|
+
tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-integration-docs-test-'));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
afterEach(() => {
|
|
88
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('integration-contributed topics', () => {
|
|
92
|
+
it('lists and reads like a built-in topic, naming its owner', async () => {
|
|
93
|
+
scaffold({'deploying.doc.mjs': topic()});
|
|
94
|
+
|
|
95
|
+
const listed = await docs(undefined, undefined, {cwd: tmpDir});
|
|
96
|
+
const entry = listed.data.find(t => t.topic === 'deploying');
|
|
97
|
+
expect(entry).toMatchObject({
|
|
98
|
+
topic: 'deploying',
|
|
99
|
+
description: 'How to ship an app built with Acme widgets.',
|
|
100
|
+
package: '@acme/widgets',
|
|
101
|
+
});
|
|
102
|
+
// The built-in topics keep their own owner.
|
|
103
|
+
expect(listed.data.find(t => t.topic === 'tokens').package).toBe('@astryxdesign/cli');
|
|
104
|
+
|
|
105
|
+
const detail = await docs('deploying', undefined, {cwd: tmpDir, full: true});
|
|
106
|
+
expect(detail.type).toBe('docs.detail');
|
|
107
|
+
expect(detail.data.sections[0].content[0].text).toBe('Push the button.');
|
|
108
|
+
|
|
109
|
+
const section = await docs('deploying', 'overview', {cwd: tmpDir});
|
|
110
|
+
expect(section.data.title).toBe('Overview');
|
|
111
|
+
}, SLOW);
|
|
112
|
+
|
|
113
|
+
it('is invisible to a project that does not configure the integration', async () => {
|
|
114
|
+
scaffold({'deploying.doc.mjs': topic()}, {config: 'export default {};\n'});
|
|
115
|
+
const listed = await docs(undefined, undefined, {cwd: tmpDir});
|
|
116
|
+
expect(listed.data.some(t => t.topic === 'deploying')).toBe(false);
|
|
117
|
+
}, SLOW);
|
|
118
|
+
|
|
119
|
+
it('serves the replacement of a built-in topic, and says what it replaced', async () => {
|
|
120
|
+
scaffold({
|
|
121
|
+
'getting-started.doc.mjs': topic({
|
|
122
|
+
name: 'getting-started',
|
|
123
|
+
replaces: 'getting-started',
|
|
124
|
+
title: 'Getting started',
|
|
125
|
+
description: 'Install Acme widgets.',
|
|
126
|
+
sections: [
|
|
127
|
+
{title: 'Install', content: [{type: 'prose', text: 'yarn add @acme/widgets'}]},
|
|
128
|
+
],
|
|
129
|
+
}),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const detail = await docs('getting-started', undefined, {cwd: tmpDir, full: true});
|
|
133
|
+
expect(detail.data.sections.map(s => s.title)).toEqual(['Install']);
|
|
134
|
+
expect(detail.data.sections[0].content[0].text).toBe('yarn add @acme/widgets');
|
|
135
|
+
|
|
136
|
+
const listed = await docs(undefined, undefined, {cwd: tmpDir});
|
|
137
|
+
const entries = listed.data.filter(t => t.topic === 'getting-started');
|
|
138
|
+
expect(entries).toHaveLength(1);
|
|
139
|
+
expect(entries[0]).toMatchObject({
|
|
140
|
+
package: '@acme/widgets',
|
|
141
|
+
replaces: 'getting-started',
|
|
142
|
+
});
|
|
143
|
+
}, SLOW);
|
|
144
|
+
|
|
145
|
+
it('keeps the replaced name resolving when the replacement renames it', async () => {
|
|
146
|
+
scaffold({
|
|
147
|
+
'setup.doc.mjs': topic({name: 'setup', replaces: 'getting-started'}),
|
|
148
|
+
});
|
|
149
|
+
const byOldName = await docs('getting-started', undefined, {cwd: tmpDir, full: true});
|
|
150
|
+
const byNewName = await docs('setup', undefined, {cwd: tmpDir, full: true});
|
|
151
|
+
expect(byOldName.data.name).toBe('setup');
|
|
152
|
+
expect(byNewName.data.name).toBe('setup');
|
|
153
|
+
}, SLOW);
|
|
154
|
+
|
|
155
|
+
it('merges an extension into the topic it extends', async () => {
|
|
156
|
+
const builtin = await docs('theme', undefined, {full: true});
|
|
157
|
+
const baseSectionTitle = builtin.data.sections[0].title;
|
|
158
|
+
scaffold({
|
|
159
|
+
'theme-internal.doc.mjs': topic({
|
|
160
|
+
name: 'theme-internal',
|
|
161
|
+
extends: 'theme',
|
|
162
|
+
sections: [
|
|
163
|
+
{title: baseSectionTitle, content: [{type: 'prose', text: 'Use the Acme theme.'}]},
|
|
164
|
+
{title: 'Acme themes', content: [{type: 'prose', text: 'Three of them.'}]},
|
|
165
|
+
],
|
|
166
|
+
}),
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const extended = await docs('theme', undefined, {cwd: tmpDir, full: true});
|
|
170
|
+
// The extension is not a topic of its own.
|
|
171
|
+
expect((await docs(undefined, undefined, {cwd: tmpDir})).data.some(
|
|
172
|
+
t => t.topic === 'theme-internal',
|
|
173
|
+
)).toBe(false);
|
|
174
|
+
expect(extended.data.sections[0].content[0].text).toBe('Use the Acme theme.');
|
|
175
|
+
expect(extended.data.sections.at(-1).title).toBe('Acme themes');
|
|
176
|
+
// Everything the extension did not name is still the base doc's.
|
|
177
|
+
expect(extended.data.sections.length).toBe(builtin.data.sections.length + 1);
|
|
178
|
+
}, SLOW);
|
|
179
|
+
|
|
180
|
+
it('migrates a real built-in section to a stable ID without duplicating it', async () => {
|
|
181
|
+
const builtin = await docs('theme', undefined, {full: true});
|
|
182
|
+
// Readers see a key on every section; the migration case is one whose
|
|
183
|
+
// source authors no id.
|
|
184
|
+
const {docs: authored} = await import('../../assets/docs/theme.doc.mjs');
|
|
185
|
+
const target = authored.sections.find(section => section.id == null);
|
|
186
|
+
expect(target).toBeDefined();
|
|
187
|
+
scaffold({
|
|
188
|
+
'theme-internal.doc.mjs': topic({
|
|
189
|
+
name: 'theme-internal',
|
|
190
|
+
extends: 'theme',
|
|
191
|
+
sections: [
|
|
192
|
+
{
|
|
193
|
+
id: 'acme-theme-setup',
|
|
194
|
+
title: target.title,
|
|
195
|
+
content: [{type: 'prose', text: 'Use the Acme theme.'}],
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
}),
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const extended = await docs('theme', undefined, {cwd: tmpDir, full: true});
|
|
202
|
+
expect(extended.data.sections).toHaveLength(builtin.data.sections.length);
|
|
203
|
+
const matches = extended.data.sections.filter(
|
|
204
|
+
section => section.title === target.title,
|
|
205
|
+
);
|
|
206
|
+
expect(matches).toEqual([
|
|
207
|
+
expect.objectContaining({
|
|
208
|
+
id: 'acme-theme-setup',
|
|
209
|
+
content: [{type: 'prose', text: 'Use the Acme theme.'}],
|
|
210
|
+
}),
|
|
211
|
+
]);
|
|
212
|
+
}, SLOW);
|
|
213
|
+
|
|
214
|
+
it('replaces a real built-in section by the key its index shows', async () => {
|
|
215
|
+
const index = await docs('theme', undefined, {index: true});
|
|
216
|
+
const target = index.data.sections[0];
|
|
217
|
+
scaffold({
|
|
218
|
+
'theme-internal.doc.mjs': topic({
|
|
219
|
+
name: 'theme-internal',
|
|
220
|
+
extends: 'theme',
|
|
221
|
+
sections: [
|
|
222
|
+
{
|
|
223
|
+
id: target.id,
|
|
224
|
+
title: `${target.title} with Acme`,
|
|
225
|
+
content: [{type: 'prose', text: 'Acme first.'}],
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
}),
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const extended = await docs('theme', undefined, {cwd: tmpDir, full: true});
|
|
232
|
+
expect(extended.data.sections).toHaveLength(index.data.sections.length);
|
|
233
|
+
expect(extended.data.sections.filter(s => s.id === target.id)).toEqual([
|
|
234
|
+
expect.objectContaining({content: [{type: 'prose', text: 'Acme first.'}]}),
|
|
235
|
+
]);
|
|
236
|
+
const read = await docs('theme', target.id, {cwd: tmpDir});
|
|
237
|
+
expect(read.data.title).toBe(`${target.title} with Acme`);
|
|
238
|
+
}, SLOW);
|
|
239
|
+
|
|
240
|
+
it.each(['zh', 'dense'])(
|
|
241
|
+
'replaces translated real sections by their authored titles under --%s',
|
|
242
|
+
async lang => {
|
|
243
|
+
const english = await docs('theme', undefined, {full: true});
|
|
244
|
+
const englishTitles = english.data.sections.map(section => section.title);
|
|
245
|
+
expect(englishTitles).toEqual(
|
|
246
|
+
expect.arrayContaining(['Available Themes', 'Theme Props']),
|
|
247
|
+
);
|
|
248
|
+
scaffold({
|
|
249
|
+
'theme-internal.doc.mjs': topic({
|
|
250
|
+
name: 'theme-internal',
|
|
251
|
+
extends: 'theme',
|
|
252
|
+
sections: [
|
|
253
|
+
{
|
|
254
|
+
id: 'acme-available-themes',
|
|
255
|
+
title: 'Available Themes',
|
|
256
|
+
content: [{type: 'prose', text: 'Acme themes.'}],
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
title: 'Theme Props',
|
|
260
|
+
content: [{type: 'prose', text: 'Acme props.'}],
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
}),
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const base = await docs('theme', undefined, {lang, full: true});
|
|
267
|
+
expect(base.data.sections.map(section => section.title)).not.toEqual(
|
|
268
|
+
englishTitles,
|
|
269
|
+
);
|
|
270
|
+
const extended = await docs('theme', undefined, {cwd: tmpDir, lang, full: true});
|
|
271
|
+
expect(extended.data.sections).toHaveLength(base.data.sections.length);
|
|
272
|
+
expect(
|
|
273
|
+
extended.data.sections.filter(
|
|
274
|
+
section => section.id === 'acme-available-themes',
|
|
275
|
+
),
|
|
276
|
+
).toHaveLength(1);
|
|
277
|
+
expect(
|
|
278
|
+
extended.data.sections.filter(
|
|
279
|
+
section => section.content[0]?.text === 'Acme props.',
|
|
280
|
+
),
|
|
281
|
+
).toHaveLength(1);
|
|
282
|
+
},
|
|
283
|
+
SLOW,
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
it('offers the contributed topics as suggestions on an unknown one', async () => {
|
|
287
|
+
scaffold({'deploying.doc.mjs': topic()});
|
|
288
|
+
await expect(docs('nope-not-a-topic', undefined, {cwd: tmpDir, full: true})).rejects.toBeInstanceOf(
|
|
289
|
+
AstryxError,
|
|
290
|
+
);
|
|
291
|
+
try {
|
|
292
|
+
await docs('nope-not-a-topic', undefined, {cwd: tmpDir, full: true});
|
|
293
|
+
} catch (err) {
|
|
294
|
+
expect(err.suggestions.map(s => s.name)).toContain('deploying');
|
|
295
|
+
}
|
|
296
|
+
}, SLOW);
|
|
297
|
+
|
|
298
|
+
it('indexes a contributed topic in search', async () => {
|
|
299
|
+
scaffold({'deploying.doc.mjs': topic()});
|
|
300
|
+
const {data} = await search('deploying', {cwd: tmpDir, type: 'doc'});
|
|
301
|
+
expect(data.results[0]).toMatchObject({
|
|
302
|
+
domain: 'doc',
|
|
303
|
+
name: 'deploying',
|
|
304
|
+
command: 'astryx docs deploying',
|
|
305
|
+
});
|
|
306
|
+
}, SLOW);
|
|
307
|
+
|
|
308
|
+
it('ranks the topics that match every word of the query first', async () => {
|
|
309
|
+
// Dozens of CLI docs match `integration` alone, by name or in a code
|
|
310
|
+
// tick; the topics that hold both words, this one and the CLI's own
|
|
311
|
+
// troubleshooting guide, must still come first.
|
|
312
|
+
scaffold({
|
|
313
|
+
'troubleshooting.doc.mjs': topic({
|
|
314
|
+
name: 'troubleshooting',
|
|
315
|
+
title: 'Troubleshooting',
|
|
316
|
+
description: 'What to check when an integration does not load.',
|
|
317
|
+
}),
|
|
318
|
+
});
|
|
319
|
+
const {data} = await search('troubleshoot integration', {cwd: tmpDir, type: 'doc'});
|
|
320
|
+
const top = data.results.slice(0, 2).map(result => result.name);
|
|
321
|
+
// This topic, and the CLI's own troubleshooting guide wherever the tree
|
|
322
|
+
// places it.
|
|
323
|
+
expect(top).toContain('troubleshooting');
|
|
324
|
+
expect(
|
|
325
|
+
top.some(name => /^cli\/integrations\/(?:.+\/)?troubleshooting$/.test(name)),
|
|
326
|
+
top.join(', '),
|
|
327
|
+
).toBe(true);
|
|
328
|
+
}, SLOW);
|
|
329
|
+
|
|
330
|
+
it("falls back to the CLI's own topics when the project config is unreadable", async () => {
|
|
331
|
+
scaffold({'deploying.doc.mjs': topic()}, {config: 'export default {integrations: 42};\n'});
|
|
332
|
+
const catalog = await loadDocsCatalog(tmpDir);
|
|
333
|
+
expect(catalog.resolve('tokens')).toBeTruthy();
|
|
334
|
+
expect(catalog.resolve('deploying')).toBeUndefined();
|
|
335
|
+
}, SLOW);
|
|
336
|
+
});
|
package/api/docs/node/node.d.mts
CHANGED
|
@@ -4,15 +4,28 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {import('../../../foundation/doc-compiler/tree.mjs').DocsTree} DocsTree
|
|
6
6
|
* @typedef {import('../../../foundation/doc-compiler/tree.mjs').TreeNode} TreeNode
|
|
7
|
+
* @typedef {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} DocsCatalog
|
|
7
8
|
*/
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* How far a read goes below the node it names, and how much of each doc below
|
|
11
|
+
* it shows: `depth` levels (Infinity for every level), and `detail` brief (its
|
|
12
|
+
* identity), or compact or full (with its text: a namespace's intro, a guide's
|
|
13
|
+
* sections, a typed doc's content). `lang` selects the guides' language.
|
|
14
|
+
* @typedef {object} DepthRead
|
|
15
|
+
* @property {number} depth
|
|
16
|
+
* @property {'brief' | 'compact' | 'full'} detail
|
|
17
|
+
* @property {string | null} lang
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The docs.node view of one tree node. Without a depth read, a namespace lists
|
|
21
|
+
* its children one level down.
|
|
22
|
+
* @param {DocsCatalog} catalog
|
|
11
23
|
* @param {DocsTree} tree
|
|
12
24
|
* @param {TreeNode} node
|
|
25
|
+
* @param {DepthRead} [read] how far down to go, and how much of each doc below
|
|
13
26
|
* @returns {Promise<import('../docs.type.mjs').DocsNode>}
|
|
14
27
|
*/
|
|
15
|
-
export function nodeView(catalog:
|
|
28
|
+
export function nodeView(catalog: DocsCatalog, tree: DocsTree, node: TreeNode, read?: DepthRead): Promise<import("../docs.type.mjs").DocsNode>;
|
|
16
29
|
/**
|
|
17
30
|
* The typed edges a doc declares (spec:AST-047 FR5), resolved to routes: a
|
|
18
31
|
* function doc's `command` and `related`, and a command doc's `fn` and
|
|
@@ -41,3 +54,15 @@ export function node(route: string, options?: {
|
|
|
41
54
|
}): Promise<import("../docs.type.mjs").DocsNodeResponse>;
|
|
42
55
|
export type DocsTree = import("../../../foundation/doc-compiler/tree.mjs").DocsTree;
|
|
43
56
|
export type TreeNode = import("../../../foundation/doc-compiler/tree.mjs").TreeNode;
|
|
57
|
+
export type DocsCatalog = import("../../../foundation/discovery/docs-discovery.mjs").DocsCatalog;
|
|
58
|
+
/**
|
|
59
|
+
* How far a read goes below the node it names, and how much of each doc below
|
|
60
|
+
* it shows: `depth` levels (Infinity for every level), and `detail` brief (its
|
|
61
|
+
* identity), or compact or full (with its text: a namespace's intro, a guide's
|
|
62
|
+
* sections, a typed doc's content). `lang` selects the guides' language.
|
|
63
|
+
*/
|
|
64
|
+
export type DepthRead = {
|
|
65
|
+
depth: number;
|
|
66
|
+
detail: "brief" | "compact" | "full";
|
|
67
|
+
lang: string | null;
|
|
68
|
+
};
|
package/api/docs/node/node.mjs
CHANGED
|
@@ -7,14 +7,18 @@
|
|
|
7
7
|
* typed doc such as `cli/api/functions/search`, plus {cwd}.
|
|
8
8
|
* @output { type: 'docs.node', data: DocsNode } — the node's identity, title
|
|
9
9
|
* and summary, the namespaces above it, and either its slots with their
|
|
10
|
-
* children (a namespace) or its content (a typed doc).
|
|
11
|
-
* lists its
|
|
12
|
-
*
|
|
10
|
+
* children (a namespace) or its content (a typed doc). By default a
|
|
11
|
+
* namespace lists its children one level down; a depth read goes as far
|
|
12
|
+
* down as asked, with each doc below as its identity (brief) or with its
|
|
13
|
+
* text (compact, full). Matches `astryx --json docs <route> [--depth <n>]`.
|
|
13
14
|
* @position Leaf under api/docs, beside the topic leaves. A guide the tree
|
|
14
15
|
* places is a topic: the detail leaf reads it by its route.
|
|
15
16
|
*/
|
|
16
17
|
|
|
18
|
+
import {detailView} from '../../../foundation/doc-compiler/lenses.mjs';
|
|
17
19
|
import {
|
|
20
|
+
compileTopic,
|
|
21
|
+
guideEntry,
|
|
18
22
|
nodeContent,
|
|
19
23
|
placeLinks,
|
|
20
24
|
resolveDocsArgument,
|
|
@@ -24,18 +28,34 @@ import {
|
|
|
24
28
|
/**
|
|
25
29
|
* @typedef {import('../../../foundation/doc-compiler/tree.mjs').DocsTree} DocsTree
|
|
26
30
|
* @typedef {import('../../../foundation/doc-compiler/tree.mjs').TreeNode} TreeNode
|
|
31
|
+
* @typedef {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} DocsCatalog
|
|
27
32
|
*/
|
|
28
33
|
|
|
29
34
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
35
|
+
* How far a read goes below the node it names, and how much of each doc below
|
|
36
|
+
* it shows: `depth` levels (Infinity for every level), and `detail` brief (its
|
|
37
|
+
* identity), or compact or full (with its text: a namespace's intro, a guide's
|
|
38
|
+
* sections, a typed doc's content). `lang` selects the guides' language.
|
|
39
|
+
* @typedef {object} DepthRead
|
|
40
|
+
* @property {number} depth
|
|
41
|
+
* @property {'brief' | 'compact' | 'full'} detail
|
|
42
|
+
* @property {string | null} lang
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The docs.node view of one tree node. Without a depth read, a namespace lists
|
|
47
|
+
* its children one level down.
|
|
48
|
+
* @param {DocsCatalog} catalog
|
|
32
49
|
* @param {DocsTree} tree
|
|
33
50
|
* @param {TreeNode} node
|
|
51
|
+
* @param {DepthRead} [read] how far down to go, and how much of each doc below
|
|
34
52
|
* @returns {Promise<import('../docs.type.mjs').DocsNode>}
|
|
35
53
|
*/
|
|
36
|
-
export async function nodeView(catalog, tree, node) {
|
|
54
|
+
export async function nodeView(catalog, tree, node, read) {
|
|
37
55
|
const {content} = await nodeContent(catalog, tree, node);
|
|
38
|
-
|
|
56
|
+
const slots = node.slots.filter(slot => slot.children.length > 0);
|
|
57
|
+
/** @type {import('../docs.type.mjs').DocsNode} */
|
|
58
|
+
const view = {
|
|
39
59
|
id: node.id,
|
|
40
60
|
route: node.route,
|
|
41
61
|
kind: node.kind,
|
|
@@ -45,25 +65,128 @@ export async function nodeView(catalog, tree, node) {
|
|
|
45
65
|
breadcrumb: tree
|
|
46
66
|
.ancestors(node)
|
|
47
67
|
.map(ancestor => ({route: ancestor.route, title: ancestor.title})),
|
|
48
|
-
slots:
|
|
49
|
-
.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
title: child.title,
|
|
60
|
-
summary: child.summary,
|
|
61
|
-
};
|
|
62
|
-
}),
|
|
63
|
-
})),
|
|
68
|
+
slots: !read
|
|
69
|
+
? slots.map(slot => ({
|
|
70
|
+
name: slot.name,
|
|
71
|
+
title: slot.title,
|
|
72
|
+
children: slot.children.map(route =>
|
|
73
|
+
childIdentity(/** @type {TreeNode} */ (tree.get(route))),
|
|
74
|
+
),
|
|
75
|
+
}))
|
|
76
|
+
: read.depth >= 1
|
|
77
|
+
? await slotsBelow(catalog, tree, slots, 1, read)
|
|
78
|
+
: [],
|
|
64
79
|
content,
|
|
65
80
|
links: nodeLinks(tree, node),
|
|
66
81
|
};
|
|
82
|
+
if (read && read.depth < 1 && slots.length > 0) {
|
|
83
|
+
view.childCount = countChildren(slots);
|
|
84
|
+
}
|
|
85
|
+
return view;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The fields every child carries: what it is, and the route that opens it.
|
|
90
|
+
* @param {TreeNode} child
|
|
91
|
+
* @returns {import('../docs.type.mjs').DocsNodeChild}
|
|
92
|
+
*/
|
|
93
|
+
function childIdentity(child) {
|
|
94
|
+
return {
|
|
95
|
+
route: child.route,
|
|
96
|
+
name: child.route.slice(child.route.lastIndexOf('/') + 1),
|
|
97
|
+
kind: child.kind,
|
|
98
|
+
title: child.title,
|
|
99
|
+
summary: child.summary,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param {TreeNode['slots']} slots
|
|
105
|
+
* @returns {number}
|
|
106
|
+
*/
|
|
107
|
+
function countChildren(slots) {
|
|
108
|
+
return slots.reduce((count, slot) => count + slot.children.length, 0);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Slots read `level` levels below the named node: each child at the read's
|
|
113
|
+
* detail, and its own slots while the read goes deeper.
|
|
114
|
+
* @param {DocsCatalog} catalog
|
|
115
|
+
* @param {DocsTree} tree
|
|
116
|
+
* @param {TreeNode['slots']} slots
|
|
117
|
+
* @param {number} level
|
|
118
|
+
* @param {DepthRead} read
|
|
119
|
+
* @returns {Promise<import('../docs.type.mjs').DocsNodeSlot[]>}
|
|
120
|
+
*/
|
|
121
|
+
async function slotsBelow(catalog, tree, slots, level, read) {
|
|
122
|
+
return Promise.all(
|
|
123
|
+
slots.map(async slot => ({
|
|
124
|
+
name: slot.name,
|
|
125
|
+
title: slot.title,
|
|
126
|
+
children: await Promise.all(
|
|
127
|
+
slot.children.map(route =>
|
|
128
|
+
childBelow(
|
|
129
|
+
catalog,
|
|
130
|
+
tree,
|
|
131
|
+
/** @type {TreeNode} */ (tree.get(route)),
|
|
132
|
+
level,
|
|
133
|
+
read,
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
),
|
|
137
|
+
})),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* One child of a depth read. Where the read stops, a child with docs below it
|
|
143
|
+
* says how many, so a reader knows to go deeper.
|
|
144
|
+
* @param {DocsCatalog} catalog
|
|
145
|
+
* @param {DocsTree} tree
|
|
146
|
+
* @param {TreeNode} child
|
|
147
|
+
* @param {number} level
|
|
148
|
+
* @param {DepthRead} read
|
|
149
|
+
* @returns {Promise<import('../docs.type.mjs').DocsNodeChild>}
|
|
150
|
+
*/
|
|
151
|
+
async function childBelow(catalog, tree, child, level, read) {
|
|
152
|
+
const view = childIdentity(child);
|
|
153
|
+
if (read.detail !== 'brief') {
|
|
154
|
+
Object.assign(view, await childText(catalog, tree, child, read.lang));
|
|
155
|
+
}
|
|
156
|
+
const slots = child.slots.filter(slot => slot.children.length > 0);
|
|
157
|
+
if (slots.length > 0) {
|
|
158
|
+
if (level < read.depth) {
|
|
159
|
+
view.slots = await slotsBelow(catalog, tree, slots, level + 1, read);
|
|
160
|
+
} else {
|
|
161
|
+
view.childCount = countChildren(slots);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return view;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A child's text: a guide's compiled sections, or the content of a namespace
|
|
169
|
+
* or typed doc.
|
|
170
|
+
* @param {DocsCatalog} catalog
|
|
171
|
+
* @param {DocsTree} tree
|
|
172
|
+
* @param {TreeNode} child
|
|
173
|
+
* @param {string | null} lang
|
|
174
|
+
* @returns {Promise<{content?: any[], sections?: any[]}>}
|
|
175
|
+
*/
|
|
176
|
+
async function childText(catalog, tree, child, lang) {
|
|
177
|
+
if (child.kind === 'generic') {
|
|
178
|
+
const entry = child.ref?.topicFile
|
|
179
|
+
? guideEntry(child)
|
|
180
|
+
: child.ref?.flatTopic
|
|
181
|
+
? catalog.resolve(child.ref.flatTopic)
|
|
182
|
+
: null;
|
|
183
|
+
if (!entry) return {};
|
|
184
|
+
return {
|
|
185
|
+
sections: detailView(await compileTopic(catalog, entry, lang)).sections,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const {content} = await nodeContent(catalog, tree, child);
|
|
189
|
+
return {content};
|
|
67
190
|
}
|
|
68
191
|
|
|
69
192
|
/**
|
package/api/error.d.mts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The error for a write that failed on the filesystem: no permission, a
|
|
6
|
+
* read-only mount, a full disk, a path component that is not a directory.
|
|
7
|
+
*
|
|
8
|
+
* A raw Node errno error reached the envelope as
|
|
9
|
+
* `{"error": "EACCES: permission denied, open '/home/you/p/readonly/x.tsx'",
|
|
10
|
+
* "code": "ERR_UNKNOWN"}` — the wrong code (ERR_WRITE_FAILED is in the frozen
|
|
11
|
+
* registry for exactly this) and an absolute host path in the message. This
|
|
12
|
+
* keeps the errno, which is the part that tells you what to fix, and reports
|
|
13
|
+
* the target the way every other Astryx message does: relative to the project.
|
|
14
|
+
*
|
|
15
|
+
* A caller that wrote files before the failure must undo them first and pass
|
|
16
|
+
* the ones it could not restore as `unrestored`, so the message never says
|
|
17
|
+
* nothing was written when something was.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} target absolute path the write was aimed at
|
|
20
|
+
* @param {string} cwd project root, for the relative form
|
|
21
|
+
* @param {unknown} cause the error the filesystem call threw
|
|
22
|
+
* @param {string[]} [unrestored] absolute paths an undo could not put back
|
|
23
|
+
* @returns {AstryxError}
|
|
24
|
+
*/
|
|
25
|
+
export function writeFailed(target: string, cwd: string, cause: unknown, unrestored?: string[]): AstryxError;
|
|
4
26
|
export class AstryxError extends Error {
|
|
5
27
|
/**
|
|
6
28
|
* @param {string} message
|
package/api/error.mjs
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import {ERROR_CODES} from '../foundation/response/error-codes.mjs';
|
|
15
|
+
import * as path from 'node:path';
|
|
15
16
|
|
|
16
17
|
export class AstryxError extends Error {
|
|
17
18
|
/** @type {import('../foundation/response/base').Suggestion[] | undefined} */
|
|
@@ -36,3 +37,44 @@ export class AstryxError extends Error {
|
|
|
36
37
|
if (Array.isArray(suggestions) && suggestions.length) this.suggestions = suggestions;
|
|
37
38
|
}
|
|
38
39
|
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The error for a write that failed on the filesystem: no permission, a
|
|
43
|
+
* read-only mount, a full disk, a path component that is not a directory.
|
|
44
|
+
*
|
|
45
|
+
* A raw Node errno error reached the envelope as
|
|
46
|
+
* `{"error": "EACCES: permission denied, open '/home/you/p/readonly/x.tsx'",
|
|
47
|
+
* "code": "ERR_UNKNOWN"}` — the wrong code (ERR_WRITE_FAILED is in the frozen
|
|
48
|
+
* registry for exactly this) and an absolute host path in the message. This
|
|
49
|
+
* keeps the errno, which is the part that tells you what to fix, and reports
|
|
50
|
+
* the target the way every other Astryx message does: relative to the project.
|
|
51
|
+
*
|
|
52
|
+
* A caller that wrote files before the failure must undo them first and pass
|
|
53
|
+
* the ones it could not restore as `unrestored`, so the message never says
|
|
54
|
+
* nothing was written when something was.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} target absolute path the write was aimed at
|
|
57
|
+
* @param {string} cwd project root, for the relative form
|
|
58
|
+
* @param {unknown} cause the error the filesystem call threw
|
|
59
|
+
* @param {string[]} [unrestored] absolute paths an undo could not put back
|
|
60
|
+
* @returns {AstryxError}
|
|
61
|
+
*/
|
|
62
|
+
export function writeFailed(target, cwd, cause, unrestored = []) {
|
|
63
|
+
const rel = path.relative(cwd, target) || target;
|
|
64
|
+
const errno =
|
|
65
|
+
typeof (/** @type {any} */ (cause)?.code) === 'string'
|
|
66
|
+
? /** @type {any} */ (cause).code
|
|
67
|
+
: null;
|
|
68
|
+
const why = errno === 'EACCES' || errno === 'EPERM' ? ' (no permission)' : '';
|
|
69
|
+
const outcome =
|
|
70
|
+
unrestored.length === 0
|
|
71
|
+
? 'Nothing was written.'
|
|
72
|
+
: `Earlier writes could not all be undone: ${unrestored
|
|
73
|
+
.map(file => path.relative(cwd, file) || file)
|
|
74
|
+
.join(', ')}.`;
|
|
75
|
+
return new AstryxError(
|
|
76
|
+
`Could not write ${rel}${errno ? `: ${errno}` : ''}${why}. ${outcome}`,
|
|
77
|
+
undefined,
|
|
78
|
+
ERROR_CODES.ERR_WRITE_FAILED,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* Collect the effective handler set in delivery order: project config first,
|
|
6
6
|
* then integrations in config order. Valid handlers dedupe by handle identity;
|
|
7
|
-
* malformed integration exports
|
|
7
|
+
* malformed integration exports and integrations that failed to load retain
|
|
8
|
+
* their position as failed deliveries. An unloadable integration may export a
|
|
9
|
+
* handler, so it never counts as an empty set that enables the fallback.
|
|
8
10
|
*
|
|
9
11
|
* @param {Project} project
|
|
10
12
|
* @returns {HandlerEntry[]}
|