@astryxdesign/cli 0.7.3-canary.b1e1936 → 0.7.3-canary.ca48bb7
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 +102 -24
- package/api/doctor/doctor.test.mjs +37 -12
- package/api/hook/hook.mjs +1 -1
- package/api/init/init.doc.mjs +20 -6
- package/api/init/init.test.mjs +18 -2
- package/api/init/init.type.d.mts +3 -3
- package/api/init/init.type.mjs +3 -3
- package/api/init/remove/remove.mjs +17 -4
- package/api/init/remove/remove.test.mjs +114 -2
- package/api/init/run/run.mjs +69 -6
- 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/pack-check.mjs +110 -4
- package/api/integration/pack-check.test.mjs +69 -0
- package/api/integration/validate-integration-fixes.test.mjs +6 -5
- package/api/integration/validate-integration-gaps.test.mjs +304 -1
- package/api/integration/validate-integration.d.mts +6 -1
- package/api/integration/validate-integration.mjs +82 -13
- package/api/integration/validate-integration.type.d.mts +37 -4
- package/api/integration/validate-integration.type.mjs +28 -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/api/theme/build/build.packed-old-core.test.mjs +1 -0
- package/api/upgrade/_adapter.d.mts +57 -9
- package/api/upgrade/_adapter.mjs +198 -28
- package/api/upgrade/registry/registry.d.mts +10 -4
- package/api/upgrade/registry/registry.mjs +33 -16
- package/api/upgrade/registry/registry.test.mjs +85 -0
- package/api/upgrade/run/run.d.mts +4 -2
- package/api/upgrade/run/run.mjs +13 -2
- package/api/upgrade/run/run.test.mjs +417 -3
- package/api/upgrade/upgrade.doc.mjs +10 -5
- package/api/upgrade/upgrade.mjs +13 -2
- package/api/upgrade/upgrade.test.mjs +194 -0
- package/api/upgrade/upgrade.type.d.mts +5 -3
- package/api/upgrade/upgrade.type.mjs +8 -6
- package/assets/docs/author-a-theme.doc.mjs +2 -2
- package/assets/docs/is-my-code-good.doc.mjs +287 -0
- 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 +17 -38
- 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/docs/working-with-ai.doc.mjs +6 -2
- 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/doctor.test.mjs +65 -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/init.behavior.test.mjs +230 -1
- package/clients/cli/commands/init.doc.mjs +28 -9
- package/clients/cli/commands/init.flag-help.test.mjs +1 -0
- package/clients/cli/commands/init.mjs +2 -2
- 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/outside-project.test.mjs +2 -1
- package/clients/cli/commands/postinstall.doc.mjs +23 -0
- package/clients/cli/commands/postinstall.mjs +31 -0
- package/clients/cli/commands/setup-nudge.test.mjs +61 -0
- package/clients/cli/commands/{build-theme.mjs → theme.mjs} +1 -1
- package/clients/cli/commands/upgrade.doc.mjs +4 -2
- package/clients/cli/commands/upgrade.mjs +9 -2
- package/clients/cli/commands/upgrade.subfolder-path.test.mjs +97 -0
- package/clients/cli/index.mjs +29 -86
- 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-doc-state.d.mts +20 -7
- package/foundation/agent-docs/agent-doc-state.mjs +35 -8
- package/foundation/agent-docs/agent-docs.d.mts +100 -12
- package/foundation/agent-docs/agent-docs.mjs +1012 -100
- package/foundation/agent-docs/agent-docs.path-safety.test.mjs +1239 -17
- package/foundation/agent-docs/agent-docs.test.mjs +683 -39
- package/foundation/config/project.mjs +5 -20
- package/foundation/config/project.test.mjs +56 -0
- 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/discovery/template-adapter.mjs +18 -1
- package/foundation/discovery/template-needs.mjs +1 -44
- package/foundation/discovery/theme-discovery.mjs +147 -3
- package/foundation/doc-compiler/doc-loads.test.mjs +29 -9
- package/foundation/doc-compiler/read.mjs +59 -1
- package/foundation/doc-compiler/read.test.mjs +11 -2
- 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/paths.d.mts +70 -8
- package/foundation/fs/paths.mjs +526 -35
- package/foundation/fs/paths.test.mjs +430 -54
- 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/autolink.d.mts +2 -1
- package/foundation/integrations/autolink.mjs +4 -13
- 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/integrations.d.mts +20 -1
- package/foundation/integrations/integrations.mjs +59 -2
- package/foundation/integrations/public-imports.d.mts +118 -0
- package/foundation/integrations/public-imports.mjs +1769 -0
- package/foundation/integrations/public-imports.test.mjs +1793 -0
- package/foundation/integrations/validate-contributions.d.mts +19 -0
- package/foundation/integrations/validate-contributions.mjs +172 -3
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +9 -9
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - validateLocalIntegration(cwd) — the package rooted at `cwd` (nearest
|
|
13
13
|
* package.json + sibling astryx.integration.{ts,mjs,js}).
|
|
14
14
|
* - validateInstalledIntegration(spec, cwd) — an installed package resolved
|
|
15
|
-
* from `cwd
|
|
15
|
+
* from the node_modules chain at or above `cwd`.
|
|
16
16
|
*
|
|
17
17
|
* Both return a { found, name, version, manifestFile, issues } result. `found`
|
|
18
18
|
* is false only for the no-manifest local case, which is guidance (not an
|
|
@@ -37,6 +37,7 @@ import {assertWithin} from '../../foundation/fs/path-safety.mjs';
|
|
|
37
37
|
import {normalizeProviderId} from '../../foundation/identity/provider-identity.mjs';
|
|
38
38
|
import {integrationDocTypes} from '../docs/_adapter.mjs';
|
|
39
39
|
import {integrationDocConsistency} from '../../foundation/discovery/doc-consistency.mjs';
|
|
40
|
+
import {integrationRunnerCommands} from './_adapter.mjs';
|
|
40
41
|
import {
|
|
41
42
|
THEME_SLUG_RE,
|
|
42
43
|
unreadThemeFolders,
|
|
@@ -52,7 +53,7 @@ import {
|
|
|
52
53
|
import {
|
|
53
54
|
findManifestPaths,
|
|
54
55
|
loadManifest,
|
|
55
|
-
|
|
56
|
+
resolveInstalledIntegrationDir,
|
|
56
57
|
} from '../../foundation/integrations/integrations.mjs';
|
|
57
58
|
// The on-disk contribution validators live in foundation: Project and
|
|
58
59
|
// integration-warnings need them too, and foundation must not depend on api.
|
|
@@ -69,6 +70,12 @@ import {
|
|
|
69
70
|
rootProblem,
|
|
70
71
|
} from '../../foundation/integrations/validate-contributions.mjs';
|
|
71
72
|
import {formatCliCommand} from '../../foundation/env/package-manager.mjs';
|
|
73
|
+
import {cliPeerVersionProblem} from '../../foundation/integrations/cli-peer-version.mjs';
|
|
74
|
+
import {publicImportIssues} from '../../foundation/integrations/public-imports.mjs';
|
|
75
|
+
import {runChoice} from '../../foundation/release/run-context.mjs';
|
|
76
|
+
|
|
77
|
+
/** The running CLI is outside the package's `@astryxdesign/cli` peer range. */
|
|
78
|
+
const CLI_PEER_VERSION = 'cli_peer_version';
|
|
72
79
|
|
|
73
80
|
export {validateLoadedIntegration, isListedIssue};
|
|
74
81
|
|
|
@@ -91,6 +98,8 @@ export {validateLoadedIntegration, isListedIssue};
|
|
|
91
98
|
* may not fail `--strict` until the next (architecture:cli-surface INV35);
|
|
92
99
|
* `integration verify` still fails on a package.json npm cannot pack.
|
|
93
100
|
* @property {import('../../foundation/integrations/integrations.mjs').LoadedIntegration} [integration]
|
|
101
|
+
* @property {import('./validate-integration.type.mjs').PublicImportsReport} [publicImports]
|
|
102
|
+
* what the public-import check could not judge
|
|
94
103
|
*/
|
|
95
104
|
|
|
96
105
|
/**
|
|
@@ -277,13 +286,15 @@ async function findUnreachableContributionIssues(
|
|
|
277
286
|
* Shared core for the local and installed entry points.
|
|
278
287
|
* @param {string} packageDir
|
|
279
288
|
* @param {{name: string, version?: string}} identity
|
|
280
|
-
* @param {{scanUnreachable?: boolean}} [options]
|
|
289
|
+
* @param {{scanUnreachable?: boolean, own?: boolean, cwd?: string}} [options]
|
|
290
|
+
* `own`: the package is the one being authored in the current folder;
|
|
291
|
+
* `cwd`: the folder whose package manager an install command names
|
|
281
292
|
* @returns {Promise<ValidateResult>}
|
|
282
293
|
*/
|
|
283
294
|
async function validateAtPackageDir(
|
|
284
295
|
packageDir,
|
|
285
296
|
identity,
|
|
286
|
-
{scanUnreachable = false} = {},
|
|
297
|
+
{scanUnreachable = false, own = false, cwd = packageDir} = {},
|
|
287
298
|
) {
|
|
288
299
|
/** @type {Issue[]} */
|
|
289
300
|
const issues = [];
|
|
@@ -328,12 +339,14 @@ async function validateAtPackageDir(
|
|
|
328
339
|
let manifest;
|
|
329
340
|
/** @type {string[]} */
|
|
330
341
|
let unknownKeys;
|
|
342
|
+
/** @type {string[]} */
|
|
343
|
+
let declaredKeys;
|
|
331
344
|
/** @type {string | undefined} */
|
|
332
345
|
let agentDocsError;
|
|
333
346
|
/** @type {string | undefined} */
|
|
334
347
|
let cliCommandError;
|
|
335
348
|
try {
|
|
336
|
-
({manifest, unknownKeys, agentDocsError, cliCommandError} =
|
|
349
|
+
({manifest, unknownKeys, declaredKeys, agentDocsError, cliCommandError} =
|
|
337
350
|
await loadManifest(
|
|
338
351
|
manifestFile,
|
|
339
352
|
`Integration manifest (${path.basename(manifestFile)})`,
|
|
@@ -400,6 +413,7 @@ async function validateAtPackageDir(
|
|
|
400
413
|
__cliCommandError: cliCommandError,
|
|
401
414
|
__agentDocsError: agentDocsError,
|
|
402
415
|
__unknownKeys: unknownKeys,
|
|
416
|
+
__declaredKeys: declaredKeys,
|
|
403
417
|
__spec: identity.name,
|
|
404
418
|
__declaredProviderId: manifest.providerId,
|
|
405
419
|
__packageDir: packageDir,
|
|
@@ -422,6 +436,24 @@ async function validateAtPackageDir(
|
|
|
422
436
|
issues.push(issue);
|
|
423
437
|
}
|
|
424
438
|
}
|
|
439
|
+
// The running CLI outside the package's `@astryxdesign/cli` peer range is a
|
|
440
|
+
// note for the same reason. It is built here, not among the contribution
|
|
441
|
+
// checks, so `integration verify` (which reports their layout findings)
|
|
442
|
+
// does not see it.
|
|
443
|
+
// The version an upgrade starts from is the project's: its own CLI's, or,
|
|
444
|
+
// with none, its Core's, as the project-upgrade notice takes it.
|
|
445
|
+
const choice = runChoice(cwd);
|
|
446
|
+
const from =
|
|
447
|
+
choice.inProject && choice.copy === 'starting' && choice.coreVersion
|
|
448
|
+
? choice.coreVersion
|
|
449
|
+
: undefined;
|
|
450
|
+
const peerProblem = cliPeerVersionProblem(loaded, undefined, cwd, {
|
|
451
|
+
own,
|
|
452
|
+
from,
|
|
453
|
+
});
|
|
454
|
+
if (peerProblem) {
|
|
455
|
+
(result.notes ??= []).push({code: CLI_PEER_VERSION, message: peerProblem});
|
|
456
|
+
}
|
|
425
457
|
if (loaded.themes && !rootProblem(loaded.themes))
|
|
426
458
|
issues.push(...unreadThemeFolderIssues(packageDir, loaded));
|
|
427
459
|
// What the docs say that no reader serves: a prop listed twice, an
|
|
@@ -440,6 +472,14 @@ async function validateAtPackageDir(
|
|
|
440
472
|
packageDir,
|
|
441
473
|
)),
|
|
442
474
|
);
|
|
475
|
+
// What the package tells apps to import, read from source: package.json
|
|
476
|
+
// `exports`, docs, examples and template imports.
|
|
477
|
+
const publicImports = await publicImportIssues(packageDir, loaded);
|
|
478
|
+
issues.push(...publicImports.issues);
|
|
479
|
+
// Each finding is a note until the next minor makes it a warning.
|
|
480
|
+
if (publicImports.notes.length > 0)
|
|
481
|
+
(result.notes ??= []).push(...publicImports.notes);
|
|
482
|
+
result.publicImports = publicImports.report;
|
|
443
483
|
if (scanUnreachable) {
|
|
444
484
|
issues.push(
|
|
445
485
|
...(await findUnreachableContributionIssues(
|
|
@@ -503,7 +543,7 @@ export async function validateLocalIntegration(cwd = process.cwd()) {
|
|
|
503
543
|
const result = await validateAtPackageDir(
|
|
504
544
|
packageDir,
|
|
505
545
|
{name, version: pkg.version},
|
|
506
|
-
{scanUnreachable: true},
|
|
546
|
+
{scanUnreachable: true, own: true},
|
|
507
547
|
);
|
|
508
548
|
(result.listed ??= []).unshift(
|
|
509
549
|
...fields,
|
|
@@ -592,20 +632,21 @@ function packageJsonFieldIssues(pkg, pkgJsonPath) {
|
|
|
592
632
|
}
|
|
593
633
|
|
|
594
634
|
/**
|
|
595
|
-
* Validate an INSTALLED integration package
|
|
635
|
+
* Validate an INSTALLED integration package: the nearest `node_modules/<spec>`
|
|
636
|
+
* at or above `cwd`, resolved the way the project loads it.
|
|
596
637
|
* @param {string} spec package name
|
|
597
638
|
* @param {string} [cwd]
|
|
598
639
|
* @returns {Promise<ValidateResult>}
|
|
599
640
|
*/
|
|
600
641
|
export async function validateInstalledIntegration(spec, cwd = process.cwd()) {
|
|
601
|
-
//
|
|
642
|
+
// The resolver throws (path-safety guard) on a spec with path segments,
|
|
602
643
|
// `..`, or an absolute path. Every other malformed input to this command
|
|
603
644
|
// degrades into a diagnostic — so catch it here and return an issue instead
|
|
604
645
|
// of letting the throw escape to a raw stack (human) / generic ERR_UNKNOWN
|
|
605
646
|
// (--json).
|
|
606
647
|
let packageDir;
|
|
607
648
|
try {
|
|
608
|
-
packageDir =
|
|
649
|
+
packageDir = resolveInstalledIntegrationDir(spec, cwd);
|
|
609
650
|
} catch (err) {
|
|
610
651
|
return {
|
|
611
652
|
found: true,
|
|
@@ -637,10 +678,29 @@ export async function validateInstalledIntegration(spec, cwd = process.cwd()) {
|
|
|
637
678
|
};
|
|
638
679
|
}
|
|
639
680
|
|
|
640
|
-
return validateAtPackageDir(
|
|
641
|
-
|
|
642
|
-
version: pkg.version,
|
|
643
|
-
|
|
681
|
+
return validateAtPackageDir(
|
|
682
|
+
packageDir,
|
|
683
|
+
{name: pkg.name ?? spec, version: pkg.version},
|
|
684
|
+
{cwd},
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* The runner-command notes for a package's topics: each Astryx command a topic
|
|
690
|
+
* writes with a package runner, where the doc file is, and the bare command to
|
|
691
|
+
* write.
|
|
692
|
+
* @param {any} integration a loaded integration
|
|
693
|
+
* @returns {Promise<Array<{code: string, message: string}>>}
|
|
694
|
+
*/
|
|
695
|
+
async function runnerCommandNotes(integration) {
|
|
696
|
+
const packageDir = integration.__packageDir;
|
|
697
|
+
return (await integrationRunnerCommands(integration)).map(each => ({
|
|
698
|
+
code: 'runner_command',
|
|
699
|
+
message:
|
|
700
|
+
typeof packageDir === 'string'
|
|
701
|
+
? `${path.relative(packageDir, each.file).split(path.sep).join('/')}: ${each.message}`
|
|
702
|
+
: each.message,
|
|
703
|
+
}));
|
|
644
704
|
}
|
|
645
705
|
|
|
646
706
|
/**
|
|
@@ -693,6 +753,11 @@ export async function validateIntegration(pkg, options = {}) {
|
|
|
693
753
|
...(names ?? []).flatMap(each => each.notes),
|
|
694
754
|
]
|
|
695
755
|
: [];
|
|
756
|
+
// Each Astryx command a topic writes with a package runner, as a
|
|
757
|
+
// `runner_command` note with its fix, the same way.
|
|
758
|
+
if (integration?.docs) {
|
|
759
|
+
notes.push(...(await runnerCommandNotes(integration)));
|
|
760
|
+
}
|
|
696
761
|
return {
|
|
697
762
|
type: 'integration.validate',
|
|
698
763
|
data: {
|
|
@@ -716,6 +781,10 @@ export async function validateIntegration(pkg, options = {}) {
|
|
|
716
781
|
...(docTypes ? {docTypes} : {}),
|
|
717
782
|
...(docNames ? {docNames} : {}),
|
|
718
783
|
...(blockComponents ? {blockComponents} : {}),
|
|
784
|
+
// What the public-import check could not judge: listed, never failed on.
|
|
785
|
+
...(result.found && result.publicImports
|
|
786
|
+
? {publicImports: result.publicImports}
|
|
787
|
+
: {}),
|
|
719
788
|
},
|
|
720
789
|
};
|
|
721
790
|
}
|
|
@@ -14,6 +14,7 @@ export type LoadedIntegration = {
|
|
|
14
14
|
codemods?: string | undefined;
|
|
15
15
|
docs?: string | undefined;
|
|
16
16
|
issuesUrl?: string | undefined;
|
|
17
|
+
__declaredKeys?: string[] | undefined;
|
|
17
18
|
__unknownKeys?: string[] | undefined;
|
|
18
19
|
__spec: string;
|
|
19
20
|
__packageDir: string;
|
|
@@ -36,7 +37,9 @@ export type ValidateIntegrationResponse = {
|
|
|
36
37
|
type: "integration.validate";
|
|
37
38
|
/**
|
|
38
39
|
* `notes`: information beside the issues that fails nothing, such as
|
|
39
|
-
* `invalid_cli_command`, a `cliCommand` that was ignored as malformed
|
|
40
|
+
* `invalid_cli_command`, a `cliCommand` that was ignored as malformed;
|
|
41
|
+
* `cli_peer_version`, the running CLI outside the package's
|
|
42
|
+
* `@astryxdesign/cli` peer range; and
|
|
40
43
|
* the package layout findings added after the last minor release, each with
|
|
41
44
|
* its fix in the message: two docs for one component
|
|
42
45
|
* (`duplicate_component_doc`), a root reached through a symlink
|
|
@@ -44,9 +47,11 @@ export type ValidateIntegrationResponse = {
|
|
|
44
47
|
* (`unreadable_file`), a package.json without `name` or `version`
|
|
45
48
|
* (`invalid_package_json`), no provider ID (`no_provider_id`), and a doc
|
|
46
49
|
* whose file name differs from its source only in letter case where the two
|
|
47
|
-
* still pair (`source_without_component_doc`);
|
|
48
|
-
* `unknown_block_component` (see `docNames` and `blockComponents`);
|
|
49
|
-
* become warnings in the next
|
|
50
|
+
* still pair (`source_without_component_doc`); `doc_name_mismatch` and
|
|
51
|
+
* `unknown_block_component` (see `docNames` and `blockComponents`); and
|
|
52
|
+
* since 0.7.3 each public-import finding; they become warnings in the next
|
|
53
|
+
* minor release; and `runner_command`, an Astryx command a topic writes
|
|
54
|
+
* with a package runner
|
|
50
55
|
*/
|
|
51
56
|
data: {
|
|
52
57
|
validated: boolean;
|
|
@@ -60,6 +65,7 @@ export type ValidateIntegrationResponse = {
|
|
|
60
65
|
docTypes?: DocTypesReport;
|
|
61
66
|
docNames?: DocNamesReport;
|
|
62
67
|
blockComponents?: BlockComponentsReport;
|
|
68
|
+
publicImports?: PublicImportsReport;
|
|
63
69
|
};
|
|
64
70
|
};
|
|
65
71
|
/**
|
|
@@ -113,3 +119,30 @@ export type BlockComponentsReport = {
|
|
|
113
119
|
reason: string;
|
|
114
120
|
}>;
|
|
115
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* An import the public-import check could not judge.
|
|
124
|
+
*/
|
|
125
|
+
export type PublicImportUnchecked = {
|
|
126
|
+
/**
|
|
127
|
+
* package-relative file that names it
|
|
128
|
+
*/
|
|
129
|
+
file: string;
|
|
130
|
+
/**
|
|
131
|
+
* the import specifier
|
|
132
|
+
*/
|
|
133
|
+
specifier: string;
|
|
134
|
+
/**
|
|
135
|
+
* why it was not checked
|
|
136
|
+
*/
|
|
137
|
+
reason: string;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* The public-import check's report on validate's result: `unchecked` lists
|
|
141
|
+
* what it could not judge, never counted or failed on. Its findings are
|
|
142
|
+
* notes on the result (`data.notes`), so `findings` stays empty.
|
|
143
|
+
*/
|
|
144
|
+
export type PublicImportsReport = {
|
|
145
|
+
status: "checked";
|
|
146
|
+
findings: never[];
|
|
147
|
+
unchecked: PublicImportUnchecked[];
|
|
148
|
+
};
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* @property {string} [codemods]
|
|
19
19
|
* @property {string} [docs]
|
|
20
20
|
* @property {string} [issuesUrl]
|
|
21
|
+
* @property {string[]} [__declaredKeys]
|
|
21
22
|
* @property {string[]} [__unknownKeys]
|
|
22
23
|
* @property {string} __spec
|
|
23
24
|
* @property {string} __packageDir
|
|
@@ -38,9 +39,11 @@
|
|
|
38
39
|
* "healthy" — the two are otherwise byte-identical.
|
|
39
40
|
* @typedef {object} ValidateIntegrationResponse
|
|
40
41
|
* @property {'integration.validate'} type
|
|
41
|
-
* @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
|
|
42
43
|
* `notes`: information beside the issues that fails nothing, such as
|
|
43
|
-
* `invalid_cli_command`, a `cliCommand` that was ignored as malformed
|
|
44
|
+
* `invalid_cli_command`, a `cliCommand` that was ignored as malformed;
|
|
45
|
+
* `cli_peer_version`, the running CLI outside the package's
|
|
46
|
+
* `@astryxdesign/cli` peer range; and
|
|
44
47
|
* the package layout findings added after the last minor release, each with
|
|
45
48
|
* its fix in the message: two docs for one component
|
|
46
49
|
* (`duplicate_component_doc`), a root reached through a symlink
|
|
@@ -48,9 +51,11 @@
|
|
|
48
51
|
* (`unreadable_file`), a package.json without `name` or `version`
|
|
49
52
|
* (`invalid_package_json`), no provider ID (`no_provider_id`), and a doc
|
|
50
53
|
* whose file name differs from its source only in letter case where the two
|
|
51
|
-
* still pair (`source_without_component_doc`);
|
|
52
|
-
* `unknown_block_component` (see `docNames` and `blockComponents`);
|
|
53
|
-
* become warnings in the next
|
|
54
|
+
* still pair (`source_without_component_doc`); `doc_name_mismatch` and
|
|
55
|
+
* `unknown_block_component` (see `docNames` and `blockComponents`); and
|
|
56
|
+
* since 0.7.3 each public-import finding; they become warnings in the next
|
|
57
|
+
* minor release; and `runner_command`, an Astryx command a topic writes
|
|
58
|
+
* with a package runner
|
|
54
59
|
*/
|
|
55
60
|
|
|
56
61
|
/**
|
|
@@ -97,3 +102,21 @@
|
|
|
97
102
|
*/
|
|
98
103
|
|
|
99
104
|
export {};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* An import the public-import check could not judge.
|
|
108
|
+
* @typedef {object} PublicImportUnchecked
|
|
109
|
+
* @property {string} file package-relative file that names it
|
|
110
|
+
* @property {string} specifier the import specifier
|
|
111
|
+
* @property {string} reason why it was not checked
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The public-import check's report on validate's result: `unchecked` lists
|
|
116
|
+
* what it could not judge, never counted or failed on. Its findings are
|
|
117
|
+
* notes on the result (`data.notes`), so `findings` stays empty.
|
|
118
|
+
* @typedef {object} PublicImportsReport
|
|
119
|
+
* @property {'checked'} status
|
|
120
|
+
* @property {never[]} findings
|
|
121
|
+
* @property {PublicImportUnchecked[]} unchecked
|
|
122
|
+
*/
|
|
@@ -62,7 +62,7 @@ export const doc = {
|
|
|
62
62
|
{
|
|
63
63
|
type: 'integration.validate',
|
|
64
64
|
description:
|
|
65
|
-
|
|
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 `cli_peer_version` when the running CLI is outside the `@astryxdesign/cli` peer range of the package, 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`, `component_import_missing_name`, `example_import_not_exported`, `example_import_missing_name`, `template_import_not_exported`, `template_import_outside_root`, `template_private_import`, `template_import_missing_name` and `template_no_default_export`. 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: an `exports` target not built yet; a module whose export list cannot be read in full (CommonJS, or a declaration file it cannot read); a root import in a package with no `exports` (the root module `main` names is not read); every name an import (other than a component doc's own component) names that its module does not export, while a TypeScript file in the package has a `declare module` block for a relative path or the package's own name or a subpath of it, which can add names to that module (a `declare module` in a comment, `declare global`, a wildcard such as `'*.css'`, and another package's name do not count; a file whose text has `declare module` but that cannot be parsed counts); the same for every such name when the package has more than 5,000 files to search for that block; 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
|
+
});
|
|
@@ -104,7 +104,7 @@ export function scoreCandidate(
|
|
|
104
104
|
for (const candidateName of [name, ...aliases.filter(Boolean)]) {
|
|
105
105
|
const nameLower = candidateName.toLowerCase();
|
|
106
106
|
// A placed guide's name is its route, and the route's last segment is its
|
|
107
|
-
// name too, as a flat topic's is: `codemods` is
|
|
107
|
+
// name too, as a flat topic's is: `codemods` is authoring/building-blocks/codemods.
|
|
108
108
|
const leafLower = nameLower.slice(nameLower.lastIndexOf('/') + 1);
|
|
109
109
|
|
|
110
110
|
// A plural of the name is the name: `integration` is the `integrations`
|
|
@@ -13,6 +13,16 @@ export function entryTable(all: any[], cards: Record<string, {
|
|
|
13
13
|
synonyms?: string[];
|
|
14
14
|
props?: string[];
|
|
15
15
|
}>): EntryTable;
|
|
16
|
+
/**
|
|
17
|
+
* @param {any[]} all
|
|
18
|
+
* @param {Record<string, {what?: string, synonyms?: string[], props?: string[]}>} cards
|
|
19
|
+
* @returns {EntryTable}
|
|
20
|
+
*/
|
|
21
|
+
export function buildTable(all: any[], cards: Record<string, {
|
|
22
|
+
what?: string;
|
|
23
|
+
synonyms?: string[];
|
|
24
|
+
props?: string[];
|
|
25
|
+
}>): EntryTable;
|
|
16
26
|
export function entryOf(table: {
|
|
17
27
|
index: Map<string, number>;
|
|
18
28
|
}, res: {
|
|
@@ -22,6 +32,7 @@ export function entryOf(table: {
|
|
|
22
32
|
section?: string;
|
|
23
33
|
}): number | undefined;
|
|
24
34
|
export function entryId(c: any): string;
|
|
35
|
+
export const HASHED_FIELDS: readonly string[];
|
|
25
36
|
export type EntryTable = {
|
|
26
37
|
/**
|
|
27
38
|
* every returnable `<domain>:<name>`, in code-point order
|