@astryxdesign/cli 0.7.3-canary.641d08e → 0.7.3-canary.7c96b57
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 +63 -63
- package/api/component/component-replacement.test.mjs +1 -0
- package/api/component/component.mjs +1 -1
- package/api/hook/hook.mjs +1 -1
- 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 +15 -0
- package/api/integration/validate-integration.type.d.mts +33 -4
- package/api/integration/validate-integration.type.mjs +24 -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/search.mjs +6 -2
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/use-integrations.doc.mjs +120 -0
- 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/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/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/discovery/runner-commands.mjs +1 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +21 -9
- 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/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
|
@@ -64,6 +64,7 @@ function writeIntegration(name, components, peers) {
|
|
|
64
64
|
type: 'component',
|
|
65
65
|
name: componentName,
|
|
66
66
|
displayName: componentName,
|
|
67
|
+
import: `${name}/components/${componentName}`,
|
|
67
68
|
...(replaces ? {replaces} : {}),
|
|
68
69
|
keywords: ['acme'],
|
|
69
70
|
usage: {description: `${componentName} for Acme apps.`},
|
|
@@ -293,7 +293,7 @@ async function componentRead(name, options = {}) {
|
|
|
293
293
|
const selectorList = Array.isArray(name) ? name : null;
|
|
294
294
|
const noName = selectorList == null && !name;
|
|
295
295
|
|
|
296
|
-
// Default detail level mirrors the CLI (see commands/component
|
|
296
|
+
// Default detail level mirrors the CLI (see commands/component.mjs):
|
|
297
297
|
// single-component views default to 'full', list-style views (--list,
|
|
298
298
|
// --category, or no name) default to 'brief' (scannable name lists).
|
|
299
299
|
// An explicit array remains a batch even when it is empty or a caller also
|
package/api/hook/hook.mjs
CHANGED
|
@@ -43,7 +43,7 @@ export async function hook(name, options = {}) {
|
|
|
43
43
|
zh = false,
|
|
44
44
|
} = options;
|
|
45
45
|
|
|
46
|
-
// Default detail level mirrors the CLI (see commands/hook
|
|
46
|
+
// Default detail level mirrors the CLI (see commands/hook.mjs):
|
|
47
47
|
// single-hook views default to 'full', list-style views (--list,
|
|
48
48
|
// --category, or no name) default to 'brief' (scannable name lists).
|
|
49
49
|
// Keeping this in sync with the CLI is what the API↔CLI parity test checks.
|
|
@@ -37,6 +37,7 @@ const componentDoc = name =>
|
|
|
37
37
|
`export default {type: 'component', name: '${name}', displayName: '${name}', usage: {description: '${name}.'}, props: []};\n`;
|
|
38
38
|
/** @param {string} name */
|
|
39
39
|
const componentSource = name => `export function ${name}() { return null; }\n`;
|
|
40
|
+
/** @param {string} name */
|
|
40
41
|
const templateSource = name =>
|
|
41
42
|
`export default function ${name}() { return null; }\n`;
|
|
42
43
|
/** @param {string} name */
|
|
@@ -398,9 +399,9 @@ describe('unreachable_contribution fixes hold when followed', () => {
|
|
|
398
399
|
const dir = writePackage({
|
|
399
400
|
[MANIFEST]: manifest({templates: './templates'}),
|
|
400
401
|
'templates/hero.doc.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
|
|
401
|
-
'templates/hero.tsx':
|
|
402
|
+
'templates/hero.tsx': templateSource('Hero'),
|
|
402
403
|
'src/blocks/Carousel.doc.mjs': `export default {type: 'block', name: 'Carousel', displayName: 'Carousel', aspectRatio: 1};\n`,
|
|
403
|
-
'src/blocks/Carousel.tsx':
|
|
404
|
+
'src/blocks/Carousel.tsx': templateSource('Carousel'),
|
|
404
405
|
});
|
|
405
406
|
|
|
406
407
|
const message = only(await issuesOf(dir), 'unreachable_contribution');
|
|
@@ -423,7 +424,7 @@ describe('unreachable_contribution fixes hold when followed', () => {
|
|
|
423
424
|
[MANIFEST]: manifest({templates: './templates'}),
|
|
424
425
|
'templates/.keep': '',
|
|
425
426
|
'src/blocks/Carousel.doc.mjs': `export default {type: 'block', name: 'Carousel', displayName: 'Carousel', aspectRatio: 1};\n`,
|
|
426
|
-
'src/blocks/Carousel.tsx':
|
|
427
|
+
'src/blocks/Carousel.tsx': templateSource('Carousel'),
|
|
427
428
|
});
|
|
428
429
|
|
|
429
430
|
const message = only(await issuesOf(dir), 'unreachable_contribution');
|
|
@@ -687,9 +688,9 @@ describe('fixes never move a contribution onto a name its root already has', ()
|
|
|
687
688
|
const dir = writePackage({
|
|
688
689
|
[MANIFEST]: manifest({templates: './templates'}),
|
|
689
690
|
'templates/hero.doc.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
|
|
690
|
-
'templates/hero.tsx':
|
|
691
|
+
'templates/hero.tsx': templateSource('Hero'),
|
|
691
692
|
'extra/hero.doc.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
|
|
692
|
-
'extra/hero.tsx':
|
|
693
|
+
'extra/hero.tsx': templateSource('Hero'),
|
|
693
694
|
});
|
|
694
695
|
|
|
695
696
|
const message = only(await issuesOf(dir), 'unreachable_contribution');
|
|
@@ -169,6 +169,7 @@ const writeNamed = files =>
|
|
|
169
169
|
version: '1.0.0',
|
|
170
170
|
exports: {
|
|
171
171
|
'./components/*': './components/*.tsx',
|
|
172
|
+
'./templates/*': './templates/*.tsx',
|
|
172
173
|
'.': './index.ts',
|
|
173
174
|
},
|
|
174
175
|
});
|
|
@@ -534,7 +535,14 @@ describe('block component names', () => {
|
|
|
534
535
|
'export function Panel() { return null; }\nexport const UI = {};\nexport const Lib = {};\nexport function pick() { return null; }\n',
|
|
535
536
|
...files,
|
|
536
537
|
},
|
|
537
|
-
{
|
|
538
|
+
{
|
|
539
|
+
name: '@acme/kit',
|
|
540
|
+
version: '1.0.0',
|
|
541
|
+
exports: {
|
|
542
|
+
'.': './index.tsx',
|
|
543
|
+
'./templates/*': './templates/*.tsx',
|
|
544
|
+
},
|
|
545
|
+
},
|
|
538
546
|
);
|
|
539
547
|
/** @param {string} extra */
|
|
540
548
|
const block = extra =>
|
|
@@ -83,6 +83,10 @@ export type ValidateResult = {
|
|
|
83
83
|
*/
|
|
84
84
|
listed?: import("../../foundation/integrations/issue").AstryxIntegrationIssue[] | undefined;
|
|
85
85
|
integration?: import("../../foundation/integrations/integrations.mjs").LoadedIntegration | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* what the public-import check could not judge
|
|
88
|
+
*/
|
|
89
|
+
publicImports?: import("./validate-integration.type.mjs").PublicImportsReport | undefined;
|
|
86
90
|
};
|
|
87
91
|
import { validateLoadedIntegration } from '../../foundation/integrations/validate-contributions.mjs';
|
|
88
92
|
import { isListedIssue } from '../../foundation/integrations/validate-contributions.mjs';
|
|
@@ -70,6 +70,7 @@ import {
|
|
|
70
70
|
rootProblem,
|
|
71
71
|
} from '../../foundation/integrations/validate-contributions.mjs';
|
|
72
72
|
import {formatCliCommand} from '../../foundation/env/package-manager.mjs';
|
|
73
|
+
import {publicImportIssues} from '../../foundation/integrations/public-imports.mjs';
|
|
73
74
|
|
|
74
75
|
export {validateLoadedIntegration, isListedIssue};
|
|
75
76
|
|
|
@@ -92,6 +93,8 @@ export {validateLoadedIntegration, isListedIssue};
|
|
|
92
93
|
* may not fail `--strict` until the next (architecture:cli-surface INV35);
|
|
93
94
|
* `integration verify` still fails on a package.json npm cannot pack.
|
|
94
95
|
* @property {import('../../foundation/integrations/integrations.mjs').LoadedIntegration} [integration]
|
|
96
|
+
* @property {import('./validate-integration.type.mjs').PublicImportsReport} [publicImports]
|
|
97
|
+
* what the public-import check could not judge
|
|
95
98
|
*/
|
|
96
99
|
|
|
97
100
|
/**
|
|
@@ -444,6 +447,14 @@ async function validateAtPackageDir(
|
|
|
444
447
|
packageDir,
|
|
445
448
|
)),
|
|
446
449
|
);
|
|
450
|
+
// What the package tells apps to import, read from source: package.json
|
|
451
|
+
// `exports`, docs, examples and template imports.
|
|
452
|
+
const publicImports = await publicImportIssues(packageDir, loaded);
|
|
453
|
+
issues.push(...publicImports.issues);
|
|
454
|
+
// Each finding is a note until the next minor makes it a warning.
|
|
455
|
+
if (publicImports.notes.length > 0)
|
|
456
|
+
(result.notes ??= []).push(...publicImports.notes);
|
|
457
|
+
result.publicImports = publicImports.report;
|
|
447
458
|
if (scanUnreachable) {
|
|
448
459
|
issues.push(
|
|
449
460
|
...(await findUnreachableContributionIssues(
|
|
@@ -744,6 +755,10 @@ export async function validateIntegration(pkg, options = {}) {
|
|
|
744
755
|
...(docTypes ? {docTypes} : {}),
|
|
745
756
|
...(docNames ? {docNames} : {}),
|
|
746
757
|
...(blockComponents ? {blockComponents} : {}),
|
|
758
|
+
// What the public-import check could not judge: listed, never failed on.
|
|
759
|
+
...(result.found && result.publicImports
|
|
760
|
+
? {publicImports: result.publicImports}
|
|
761
|
+
: {}),
|
|
747
762
|
},
|
|
748
763
|
};
|
|
749
764
|
}
|
|
@@ -45,10 +45,11 @@ export type ValidateIntegrationResponse = {
|
|
|
45
45
|
* (`unreadable_file`), a package.json without `name` or `version`
|
|
46
46
|
* (`invalid_package_json`), no provider ID (`no_provider_id`), and a doc
|
|
47
47
|
* whose file name differs from its source only in letter case where the two
|
|
48
|
-
* still pair (`source_without_component_doc`);
|
|
49
|
-
* `unknown_block_component` (see `docNames` and `blockComponents`);
|
|
50
|
-
* become warnings in the next
|
|
51
|
-
* Astryx command a topic writes
|
|
48
|
+
* still pair (`source_without_component_doc`); `doc_name_mismatch` and
|
|
49
|
+
* `unknown_block_component` (see `docNames` and `blockComponents`); and
|
|
50
|
+
* since 0.7.3 each public-import finding; they become warnings in the next
|
|
51
|
+
* minor release; and `runner_command`, an Astryx command a topic writes
|
|
52
|
+
* with a package runner
|
|
52
53
|
*/
|
|
53
54
|
data: {
|
|
54
55
|
validated: boolean;
|
|
@@ -62,6 +63,7 @@ export type ValidateIntegrationResponse = {
|
|
|
62
63
|
docTypes?: DocTypesReport;
|
|
63
64
|
docNames?: DocNamesReport;
|
|
64
65
|
blockComponents?: BlockComponentsReport;
|
|
66
|
+
publicImports?: PublicImportsReport;
|
|
65
67
|
};
|
|
66
68
|
};
|
|
67
69
|
/**
|
|
@@ -115,3 +117,30 @@ export type BlockComponentsReport = {
|
|
|
115
117
|
reason: string;
|
|
116
118
|
}>;
|
|
117
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* An import the public-import check could not judge.
|
|
122
|
+
*/
|
|
123
|
+
export type PublicImportUnchecked = {
|
|
124
|
+
/**
|
|
125
|
+
* package-relative file that names it
|
|
126
|
+
*/
|
|
127
|
+
file: string;
|
|
128
|
+
/**
|
|
129
|
+
* the import specifier
|
|
130
|
+
*/
|
|
131
|
+
specifier: string;
|
|
132
|
+
/**
|
|
133
|
+
* why it was not checked
|
|
134
|
+
*/
|
|
135
|
+
reason: string;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* The public-import check's report on validate's result: `unchecked` lists
|
|
139
|
+
* what it could not judge, never counted or failed on. Its findings are
|
|
140
|
+
* notes on the result (`data.notes`), so `findings` stays empty.
|
|
141
|
+
*/
|
|
142
|
+
export type PublicImportsReport = {
|
|
143
|
+
status: "checked";
|
|
144
|
+
findings: never[];
|
|
145
|
+
unchecked: PublicImportUnchecked[];
|
|
146
|
+
};
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
* "healthy" — the two are otherwise byte-identical.
|
|
40
40
|
* @typedef {object} ValidateIntegrationResponse
|
|
41
41
|
* @property {'integration.validate'} type
|
|
42
|
-
* @property {{validated: boolean, name: string | null, version: string | null, issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[], notes?: Array<{code: string, message: string}>, docTypes?: DocTypesReport, docNames?: DocNamesReport, blockComponents?: BlockComponentsReport}} data
|
|
42
|
+
* @property {{validated: boolean, name: string | null, version: string | null, issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[], notes?: Array<{code: string, message: string}>, docTypes?: DocTypesReport, docNames?: DocNamesReport, blockComponents?: BlockComponentsReport, publicImports?: PublicImportsReport}} data
|
|
43
43
|
* `notes`: information beside the issues that fails nothing, such as
|
|
44
44
|
* `invalid_cli_command`, a `cliCommand` that was ignored as malformed, and
|
|
45
45
|
* the package layout findings added after the last minor release, each with
|
|
@@ -49,10 +49,11 @@
|
|
|
49
49
|
* (`unreadable_file`), a package.json without `name` or `version`
|
|
50
50
|
* (`invalid_package_json`), no provider ID (`no_provider_id`), and a doc
|
|
51
51
|
* whose file name differs from its source only in letter case where the two
|
|
52
|
-
* still pair (`source_without_component_doc`);
|
|
53
|
-
* `unknown_block_component` (see `docNames` and `blockComponents`);
|
|
54
|
-
* become warnings in the next
|
|
55
|
-
* Astryx command a topic writes
|
|
52
|
+
* still pair (`source_without_component_doc`); `doc_name_mismatch` and
|
|
53
|
+
* `unknown_block_component` (see `docNames` and `blockComponents`); and
|
|
54
|
+
* since 0.7.3 each public-import finding; they become warnings in the next
|
|
55
|
+
* minor release; and `runner_command`, an Astryx command a topic writes
|
|
56
|
+
* with a package runner
|
|
56
57
|
*/
|
|
57
58
|
|
|
58
59
|
/**
|
|
@@ -99,3 +100,21 @@
|
|
|
99
100
|
*/
|
|
100
101
|
|
|
101
102
|
export {};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* An import the public-import check could not judge.
|
|
106
|
+
* @typedef {object} PublicImportUnchecked
|
|
107
|
+
* @property {string} file package-relative file that names it
|
|
108
|
+
* @property {string} specifier the import specifier
|
|
109
|
+
* @property {string} reason why it was not checked
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The public-import check's report on validate's result: `unchecked` lists
|
|
114
|
+
* what it could not judge, never counted or failed on. Its findings are
|
|
115
|
+
* notes on the result (`data.notes`), so `findings` stays empty.
|
|
116
|
+
* @typedef {object} PublicImportsReport
|
|
117
|
+
* @property {'checked'} status
|
|
118
|
+
* @property {never[]} findings
|
|
119
|
+
* @property {PublicImportUnchecked[]} unchecked
|
|
120
|
+
*/
|
|
@@ -62,7 +62,7 @@ export const doc = {
|
|
|
62
62
|
{
|
|
63
63
|
type: 'integration.validate',
|
|
64
64
|
description:
|
|
65
|
-
'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message} information that fails nothing, such as `invalid_cli_command` for a `cliCommand` that was ignored as malformed, and the package layout findings added after the last minor release, each with its fix in the message: `duplicate_component_doc`, `symlinked_root`, `unreadable_file`, `invalid_package_json` (no `name` or `version`), `no_provider_id`, and `source_without_component_doc` for a doc whose file name differs from its source only in letter case where the two still pair; and `doc_name_mismatch` and `unknown_block_component` (see `docNames` and `blockComponents`); they become warnings in the next minor release. A `runner_command` note lists each Astryx command a topic writes with a package runner, with its file, line and the bare command to write. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked. When the manifest loads, `data.docNames` lists the component doc names it could not judge: `status` (`checked`), `findings` (always empty; a doc name the module its import names provably does not export is a `doc_name_mismatch` note, with its fix in the message) and `unchecked` ({file, name, reason}: a doc whose `name` differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, `data.blockComponents` lists the component names templates give in `exampleFor` or `componentsUsed` that could not be judged: `status` (`checked`), `findings` (always empty; a name neither the package nor Core has, and the template does not import, is an `unknown_block_component` note, with its fix in the message) and `unchecked` ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed).',
|
|
65
|
+
'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message} information that fails nothing, such as `invalid_cli_command` for a `cliCommand` that was ignored as malformed, and the package layout findings added after the last minor release, each with its fix in the message: `duplicate_component_doc`, `symlinked_root`, `unreadable_file`, `invalid_package_json` (no `name` or `version`), `no_provider_id`, and `source_without_component_doc` for a doc whose file name differs from its source only in letter case where the two still pair; and `doc_name_mismatch` and `unknown_block_component` (see `docNames` and `blockComponents`); they become warnings in the next minor release. A `runner_command` note lists each Astryx command a topic writes with a package runner, with its file, line and the bare command to write. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked. When the manifest loads, `data.docNames` lists the component doc names it could not judge: `status` (`checked`), `findings` (always empty; a doc name the module its import names provably does not export is a `doc_name_mismatch` note, with its fix in the message) and `unchecked` ({file, name, reason}: a doc whose `name` differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, `data.blockComponents` lists the component names templates give in `exampleFor` or `componentsUsed` that could not be judged: `status` (`checked`), `findings` (always empty; a name neither the package nor Core has, and the template does not import, is an `unknown_block_component` note, with its fix in the message) and `unchecked` ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed). Since 0.7.3 each import apps cannot use is a note in `data.notes`, its fix inside the message, listed only: it does not fail this command or `integration check --strict`, and fails `--strict` from the next minor release. The codes are `component_import_not_exported`, `component_import_other_package`, `example_import_not_exported`, `template_import_not_exported`, `template_import_outside_root` and `template_private_import`. When the manifest loads, `data.publicImports` is `{status: \'checked\', findings: [], unchecked}`: `unchecked` lists each import the check could not judge, as {file, specifier, reason}, the reason starting `example <label>:` for an import in a component example: a deep path into build output not built yet in a package with no `exports`; a template import of Core when `@astryxdesign/core` is not installed beside the package (a `packages/core` of the workspace under another name does not count); every import of the package\'s own name when package.json has no `name` or a `name` that is not a bare package name; one entry for the whole check when package.json cannot be read; and an import of a subpath whose `exports` entry has only a `types` target, unless it is `import type`, every binding is an inline `type`, or every name it imports is a type its types file declares: a value import of a name that file does not declare as a type, a namespace or side-effect import, or any import when the types file cannot be read (it may be build output). `integration check` counts the unchecked as not compared; they never fail it.',
|
|
66
66
|
},
|
|
67
67
|
],
|
|
68
68
|
examples: [
|
|
@@ -26,6 +26,21 @@ export function gatherCandidates(options: {
|
|
|
26
26
|
outside: boolean;
|
|
27
27
|
coreSkipped: string | null;
|
|
28
28
|
}>;
|
|
29
|
+
/**
|
|
30
|
+
* gatherCandidates, reused within one process: a later search in the same
|
|
31
|
+
* folder, for the same `type`, ranks the candidates an earlier search
|
|
32
|
+
* gathered when none of the files that gather read, and none of the folders
|
|
33
|
+
* it listed or probed, changed since (each is checked by its change time and
|
|
34
|
+
* size, so an edited doc in a linked package is seen on the next call). A
|
|
35
|
+
* long-running caller (a docs site's search, an agent harness) then pays the
|
|
36
|
+
* gather once. A one-shot `astryx search` gathers once, as before.
|
|
37
|
+
* @param {{cwd?: string, type?: string}} options
|
|
38
|
+
* @returns {Promise<Gathered>}
|
|
39
|
+
*/
|
|
40
|
+
export function gatherCandidatesReused(options: {
|
|
41
|
+
cwd?: string;
|
|
42
|
+
type?: string;
|
|
43
|
+
}): Promise<Gathered>;
|
|
29
44
|
/**
|
|
30
45
|
* The search tree's static data, read once: the entry cards and each node's
|
|
31
46
|
* weights file.
|
|
@@ -38,6 +53,7 @@ export function gatherCandidates(options: {
|
|
|
38
53
|
export function loadSearchData(): SearchData;
|
|
39
54
|
export { componentKeywords } from "./_gather-components.mjs";
|
|
40
55
|
export type Candidate = import("./_lexical.mjs").Candidate;
|
|
56
|
+
export type Gathered = Awaited<ReturnType<typeof gatherCandidates>>;
|
|
41
57
|
export type SearcherWeights = {
|
|
42
58
|
w: number[];
|
|
43
59
|
mu: number[];
|
package/api/search/_adapter.mjs
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import {readFileSync} from 'node:fs';
|
|
10
|
+
import * as path from 'node:path';
|
|
10
11
|
import {requireCoreDir} from '../../foundation/fs/paths.mjs';
|
|
12
|
+
import {recordReads, unchangedSince} from '../../foundation/fs/read-record.mjs';
|
|
11
13
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
12
14
|
import {coreDirOrThrow} from '../error.mjs';
|
|
13
15
|
import {CORELESS_DOMAINS} from './_query.mjs';
|
|
@@ -91,6 +93,43 @@ export async function gatherCandidates(options) {
|
|
|
91
93
|
};
|
|
92
94
|
}
|
|
93
95
|
|
|
96
|
+
/**
|
|
97
|
+
* @typedef {Awaited<ReturnType<typeof gatherCandidates>>} Gathered
|
|
98
|
+
* @type {Map<string, {reads: Map<string, string>, value: Promise<Gathered>}>}
|
|
99
|
+
*/
|
|
100
|
+
const gathered = new Map();
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* gatherCandidates, reused within one process: a later search in the same
|
|
104
|
+
* folder, for the same `type`, ranks the candidates an earlier search
|
|
105
|
+
* gathered when none of the files that gather read, and none of the folders
|
|
106
|
+
* it listed or probed, changed since (each is checked by its change time and
|
|
107
|
+
* size, so an edited doc in a linked package is seen on the next call). A
|
|
108
|
+
* long-running caller (a docs site's search, an agent harness) then pays the
|
|
109
|
+
* gather once. A one-shot `astryx search` gathers once, as before.
|
|
110
|
+
* @param {{cwd?: string, type?: string}} options
|
|
111
|
+
* @returns {Promise<Gathered>}
|
|
112
|
+
*/
|
|
113
|
+
export async function gatherCandidatesReused(options) {
|
|
114
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
115
|
+
const key = `${cwd}\0${options.type ?? ''}`;
|
|
116
|
+
const hit = gathered.get(key);
|
|
117
|
+
if (hit && unchangedSince(hit.reads)) return hit.value;
|
|
118
|
+
/** @type {Map<string, string>} */
|
|
119
|
+
const seen = new Map();
|
|
120
|
+
const value = recordReads(seen, () => gatherCandidates({...options, cwd}));
|
|
121
|
+
try {
|
|
122
|
+
await value;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (gathered.get(key)?.value === value) gathered.delete(key);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
// Each path's state was taken as it was first read, so an edit made while
|
|
128
|
+
// the gather ran shows as a change on the next call.
|
|
129
|
+
gathered.set(key, {reads: seen, value});
|
|
130
|
+
return value;
|
|
131
|
+
}
|
|
132
|
+
|
|
94
133
|
/**
|
|
95
134
|
* @typedef {{w: number[], mu: number[], sd: number[]}} SearcherWeights
|
|
96
135
|
* @typedef {object} SearchData
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Tests for search's adapter: a long-running caller reuses the gathered
|
|
5
|
+
* candidates while their inputs are unchanged (gatherCandidatesReused), and
|
|
6
|
+
* gathers again when an input changes or for another folder or `type`.
|
|
7
|
+
*
|
|
8
|
+
* Whether inputs changed is read-record's answer (tested in
|
|
9
|
+
* read-record.test.mjs). Other tests running at the same time change shared
|
|
10
|
+
* folders a gather reads (the temp folder, the repository root), so here the
|
|
11
|
+
* reuse case holds that answer at "unchanged", and every other case only
|
|
12
|
+
* checks that a change forces a new gather, which concurrent changes cannot
|
|
13
|
+
* undo.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import {describe, it, expect, vi} from 'vitest';
|
|
17
|
+
import * as fs from 'node:fs';
|
|
18
|
+
import * as os from 'node:os';
|
|
19
|
+
import * as path from 'node:path';
|
|
20
|
+
import * as readRecord from '../../foundation/fs/read-record.mjs';
|
|
21
|
+
import {gatherCandidates, gatherCandidatesReused} from './_adapter.mjs';
|
|
22
|
+
|
|
23
|
+
vi.mock('../../foundation/fs/read-record.mjs', async original => {
|
|
24
|
+
const real = /** @type {typeof readRecord} */ (await original());
|
|
25
|
+
return {...real, unchangedSince: vi.fn(real.unchangedSince)};
|
|
26
|
+
});
|
|
27
|
+
const unchangedSince = vi.mocked(readRecord.unchangedSince);
|
|
28
|
+
|
|
29
|
+
const SLOW = 60_000;
|
|
30
|
+
|
|
31
|
+
/** A folder with only a package.json: a docs search there reads the CLI's docs. */
|
|
32
|
+
function scratchProject() {
|
|
33
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-gather-reuse-'));
|
|
34
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"app"}');
|
|
35
|
+
return dir;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('gatherCandidatesReused', () => {
|
|
39
|
+
it(
|
|
40
|
+
'reuses the gathered candidates while the inputs are unchanged',
|
|
41
|
+
async () => {
|
|
42
|
+
const cwd = scratchProject();
|
|
43
|
+
const first = await gatherCandidatesReused({cwd, type: 'doc'});
|
|
44
|
+
unchangedSince.mockReturnValueOnce(true);
|
|
45
|
+
expect(await gatherCandidatesReused({cwd, type: 'doc'})).toBe(first);
|
|
46
|
+
expect(first.all.length).toBeGreaterThan(0);
|
|
47
|
+
// The same candidates a fresh gather finds.
|
|
48
|
+
expect(JSON.parse(JSON.stringify(first))).toEqual(
|
|
49
|
+
JSON.parse(JSON.stringify(await gatherCandidates({cwd, type: 'doc'}))),
|
|
50
|
+
);
|
|
51
|
+
},
|
|
52
|
+
SLOW,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
it(
|
|
56
|
+
'gathers again when an input file changes',
|
|
57
|
+
async () => {
|
|
58
|
+
const cwd = scratchProject();
|
|
59
|
+
const first = await gatherCandidatesReused({cwd, type: 'doc'});
|
|
60
|
+
const later = new Date(Date.now() + 5_000);
|
|
61
|
+
fs.utimesSync(path.join(cwd, 'package.json'), later, later);
|
|
62
|
+
expect(await gatherCandidatesReused({cwd, type: 'doc'})).not.toBe(first);
|
|
63
|
+
fs.writeFileSync(
|
|
64
|
+
path.join(cwd, 'astryx.config.mjs'),
|
|
65
|
+
'export default {};\n',
|
|
66
|
+
);
|
|
67
|
+
expect(await gatherCandidatesReused({cwd, type: 'doc'})).not.toBe(first);
|
|
68
|
+
},
|
|
69
|
+
SLOW,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
it(
|
|
73
|
+
'keeps one entry per folder and type',
|
|
74
|
+
async () => {
|
|
75
|
+
const cwd = scratchProject();
|
|
76
|
+
const docs = await gatherCandidatesReused({cwd, type: 'doc'});
|
|
77
|
+
const themes = await gatherCandidatesReused({cwd, type: 'theme'});
|
|
78
|
+
expect(themes).not.toBe(docs);
|
|
79
|
+
expect(themes.all.every(c => c.domain === 'theme')).toBe(true);
|
|
80
|
+
expect(
|
|
81
|
+
await gatherCandidatesReused({cwd: scratchProject(), type: 'doc'}),
|
|
82
|
+
).not.toBe(docs);
|
|
83
|
+
},
|
|
84
|
+
SLOW,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
it(
|
|
88
|
+
'gathers again when a file the gather read changes, in a linked package too',
|
|
89
|
+
async () => {
|
|
90
|
+
// A consumer whose integration is a symlink to a package folder
|
|
91
|
+
// elsewhere, as a workspace package is.
|
|
92
|
+
const dir = fs.mkdtempSync(
|
|
93
|
+
path.join(process.cwd(), '.astryx-gather-reuse-'),
|
|
94
|
+
);
|
|
95
|
+
const pkg = fs.mkdtempSync(
|
|
96
|
+
path.join(os.tmpdir(), 'astryx-linked-widgets-'),
|
|
97
|
+
);
|
|
98
|
+
try {
|
|
99
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"consumer"}');
|
|
100
|
+
fs.writeFileSync(
|
|
101
|
+
path.join(dir, 'astryx.config.mjs'),
|
|
102
|
+
"export default { integrations: ['@acme/widgets'] };\n",
|
|
103
|
+
);
|
|
104
|
+
fs.mkdirSync(
|
|
105
|
+
path.join(dir, 'node_modules', '@astryxdesign', 'core', 'src'),
|
|
106
|
+
{
|
|
107
|
+
recursive: true,
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
fs.mkdirSync(path.join(pkg, 'components'));
|
|
111
|
+
fs.writeFileSync(
|
|
112
|
+
path.join(pkg, 'package.json'),
|
|
113
|
+
'{"name":"@acme/widgets","version":"1.0.0"}',
|
|
114
|
+
);
|
|
115
|
+
fs.writeFileSync(
|
|
116
|
+
path.join(pkg, 'astryx.integration.mjs'),
|
|
117
|
+
"export default { components: './components' };\n",
|
|
118
|
+
);
|
|
119
|
+
fs.writeFileSync(
|
|
120
|
+
path.join(pkg, 'components', 'FancyGizmo.doc.mjs'),
|
|
121
|
+
`export default {
|
|
122
|
+
type: 'component',
|
|
123
|
+
name: 'FancyGizmo',
|
|
124
|
+
keywords: ['gizmo'],
|
|
125
|
+
usage: {description: 'A fancy part.'},
|
|
126
|
+
props: [],
|
|
127
|
+
};\n`,
|
|
128
|
+
);
|
|
129
|
+
fs.writeFileSync(
|
|
130
|
+
path.join(pkg, 'components', 'FancyGizmo.tsx'),
|
|
131
|
+
'export function FancyGizmo() { return null; }\n',
|
|
132
|
+
);
|
|
133
|
+
fs.mkdirSync(path.join(dir, 'node_modules', '@acme'));
|
|
134
|
+
fs.symlinkSync(
|
|
135
|
+
pkg,
|
|
136
|
+
path.join(dir, 'node_modules', '@acme', 'widgets'),
|
|
137
|
+
'dir',
|
|
138
|
+
);
|
|
139
|
+
const options = {cwd: dir, type: 'component'};
|
|
140
|
+
const first = await gatherCandidatesReused(options);
|
|
141
|
+
expect(first.all.map(c => c.name)).toContain('FancyGizmo');
|
|
142
|
+
|
|
143
|
+
// A new component in the linked package: its folder changed.
|
|
144
|
+
fs.writeFileSync(
|
|
145
|
+
path.join(pkg, 'components', 'TinySprocket.doc.mjs'),
|
|
146
|
+
`export default {
|
|
147
|
+
type: 'component',
|
|
148
|
+
name: 'TinySprocket',
|
|
149
|
+
keywords: ['sprocket'],
|
|
150
|
+
usage: {description: 'A small part.'},
|
|
151
|
+
props: [],
|
|
152
|
+
};\n`,
|
|
153
|
+
);
|
|
154
|
+
fs.writeFileSync(
|
|
155
|
+
path.join(pkg, 'components', 'TinySprocket.tsx'),
|
|
156
|
+
'export function TinySprocket() { return null; }\n',
|
|
157
|
+
);
|
|
158
|
+
const second = await gatherCandidatesReused(options);
|
|
159
|
+
expect(second).not.toBe(first);
|
|
160
|
+
expect(second.all.map(c => c.name)).toContain('TinySprocket');
|
|
161
|
+
|
|
162
|
+
// An edited file the gather read: the linked package's manifest.
|
|
163
|
+
const later = new Date(Date.now() + 5_000);
|
|
164
|
+
fs.utimesSync(path.join(pkg, 'package.json'), later, later);
|
|
165
|
+
expect(await gatherCandidatesReused(options)).not.toBe(second);
|
|
166
|
+
} finally {
|
|
167
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
168
|
+
fs.rmSync(pkg, {recursive: true, force: true});
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
SLOW,
|
|
172
|
+
);
|
|
173
|
+
});
|
package/api/search/search.mjs
CHANGED
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
gatherCandidates,
|
|
20
|
+
gatherCandidatesReused,
|
|
21
|
+
loadSearchData,
|
|
22
|
+
} from './_adapter.mjs';
|
|
19
23
|
import {rankLexical} from './_lexical.mjs';
|
|
20
24
|
import {checkSearchArgs} from './_result.mjs';
|
|
21
25
|
import {runTree} from '../../foundation/route/route.mjs';
|
|
@@ -56,7 +60,7 @@ export async function search(query, options = {}) {
|
|
|
56
60
|
await runTree(
|
|
57
61
|
SEARCH_TREE,
|
|
58
62
|
{query, options},
|
|
59
|
-
{...(await
|
|
63
|
+
{...(await gatherCandidatesReused(options)), data: loadSearchData()},
|
|
60
64
|
)
|
|
61
65
|
),
|
|
62
66
|
options.cwd ?? process.cwd(),
|
|
@@ -32,7 +32,7 @@ export const docs = {
|
|
|
32
32
|
'`astryx doctor integration validate`',
|
|
33
33
|
'The manifest loads, each root holds contributions the CLI can read, and each doc matches its authoring type. Notes, which fail nothing, list a malformed `cliCommand` and each command a topic writes with a package runner (`runner_command`)',
|
|
34
34
|
'A declared root is missing (`missing_root`), a contribution does not load (`invalid_doc`, `invalid_component`, `invalid_theme`), or two templates in the package replace one Core id (`ambiguous_template_replacement`)',
|
|
35
|
-
"The manifest has a key this CLI does not know (`unknown_manifest_key`), or a doc field does not match the doc's authoring type: a field the type does not have, a missing required field, or a value outside the field's type. It also warns on what no reader can serve: a prop listed twice (`duplicate_prop`), a `propDescriptions` key that names no documented prop (`unknown_translated_prop`), a section with no content (`empty_section`), two sections of a topic with one key (`duplicate_section_key`), or a `.doc.zh.mjs` or `.doc.dense.mjs` overlay beside no topic file (`orphan_doc_overlay`). It checks docs with your installed `typescript`, or, where that is missing or has no JavaScript compiler API (TypeScript 7), with an installed `@typescript/typescript6`; without either, it prints `[skip] Docs not type-checked`. With no `astryx.integration.mjs` it prints a hint and exits 0",
|
|
35
|
+
"The manifest has a key this CLI does not know (`unknown_manifest_key`), or a doc field does not match the doc's authoring type: a field the type does not have, a missing required field, or a value outside the field's type. It also warns on what no reader can serve: a prop listed twice (`duplicate_prop`), a `propDescriptions` key that names no documented prop (`unknown_translated_prop`), a section with no content (`empty_section`), two sections of a topic with one key (`duplicate_section_key`), or a `.doc.zh.mjs` or `.doc.dense.mjs` overlay beside no topic file (`orphan_doc_overlay`). Since 0.7.3 it also lists, from source and without failing, what the package tells apps to import that they cannot: a component's import (the doc's `import`, or the one the CLI derives) or a template's public import whose subpath package.json `exports` does not declare (`component_import_not_exported`, `template_import_not_exported`) or that names another package (`component_import_other_package`); an example that imports an undeclared subpath (`example_import_not_exported`); a template that imports a path outside the templates root (`template_import_outside_root`) or a path its package or Core does not export (`template_private_import`). Each is a note, printed with its fix, that fails `--strict` from the next minor; an import it cannot judge, such as a deep path into a `dist/` not built yet, is listed under `publicImports` as not checked. It checks docs with your installed `typescript`, or, where that is missing or has no JavaScript compiler API (TypeScript 7), with an installed `@typescript/typescript6`; without either, it prints `[skip] Docs not type-checked`. With no `astryx.integration.mjs` it prints a hint and exits 0",
|
|
36
36
|
],
|
|
37
37
|
[
|
|
38
38
|
'`astryx doctor integration components`',
|