@astryxdesign/cli 0.6.0 → 0.6.1
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 +48 -1
- package/README.md +76 -67
- package/api/build/build.test.mjs +37 -0
- package/api/build/build.type.mjs +1 -1
- package/api/build/kit/kit.mjs +31 -1
- package/api/component/_adapter.mjs +14 -28
- package/api/component/integration-import-agreement.test.mjs +318 -0
- package/api/doctor/doctor.d.mts +32 -3
- package/api/doctor/doctor.doc.mjs +2 -1
- package/api/doctor/doctor.mjs +97 -4
- package/api/doctor/doctor.test.mjs +90 -1
- package/api/gap-report/gap-report-worker.d.mts +4 -0
- package/api/gap-report/gap-report-worker.mjs +73 -0
- package/api/gap-report/gap-report.d.mts +81 -0
- package/api/gap-report/gap-report.doc.d.mts +9 -0
- package/api/gap-report/gap-report.doc.mjs +127 -0
- package/api/gap-report/gap-report.mjs +707 -0
- package/api/gap-report/gap-report.test.mjs +1210 -0
- package/api/gap-report/gap-report.type.d.mts +88 -0
- package/api/gap-report/gap-report.type.mjs +69 -0
- package/api/index.d.mts +8 -1
- package/api/index.mjs +24 -1
- package/api/integration/add-contribution.d.mts +44 -0
- package/api/integration/add-contribution.mjs +1160 -0
- package/api/integration/add-contribution.test.mjs +733 -0
- package/api/integration/add-helpers.d.mts +80 -0
- package/api/integration/add-helpers.mjs +333 -0
- package/api/integration/add-helpers.test.mjs +161 -0
- package/api/integration/add-theme.d.mts +10 -0
- package/api/integration/add-theme.mjs +332 -0
- package/api/integration/add-theme.test.mjs +194 -0
- package/api/integration/integration-authoring.type.d.mts +55 -0
- package/api/integration/integration-authoring.type.mjs +76 -0
- package/api/integration/integration-block-exports.test.mjs +4 -0
- package/api/integration/integrationAdd.doc.d.mts +5 -0
- package/api/integration/integrationAdd.doc.mjs +100 -0
- package/api/integration/integrationAddAgentDoc.doc.d.mts +5 -0
- package/api/integration/integrationAddAgentDoc.doc.mjs +49 -0
- package/api/integration/integrationAddCodemod.doc.d.mts +5 -0
- package/api/integration/integrationAddCodemod.doc.mjs +55 -0
- package/api/integration/integrationAddComponent.doc.d.mts +5 -0
- package/api/integration/integrationAddComponent.doc.mjs +49 -0
- package/api/integration/integrationAddDoc.doc.d.mts +5 -0
- package/api/integration/integrationAddDoc.doc.mjs +59 -0
- package/api/integration/integrationAddTemplate.doc.d.mts +5 -0
- package/api/integration/integrationAddTemplate.doc.mjs +55 -0
- package/api/integration/integrationAddTheme.doc.d.mts +5 -0
- package/api/integration/integrationAddTheme.doc.mjs +85 -0
- package/api/integration/integrationPackCheck.doc.d.mts +5 -0
- package/api/integration/integrationPackCheck.doc.mjs +35 -0
- package/api/integration/pack-check.d.mts +27 -0
- package/api/integration/pack-check.mjs +795 -0
- package/api/integration/pack-check.test.mjs +569 -0
- package/api/integration/pack-check.type.d.mts +45 -0
- package/api/integration/pack-check.type.mjs +56 -0
- package/api/integration/public-api.test.mjs +21 -0
- package/api/integration/validate-integration.mjs +221 -11
- package/api/integration/validate-integration.test.mjs +189 -5
- package/api/integration/validateIntegration.doc.mjs +2 -2
- package/api/json/index.ts +1 -0
- package/api/search/search.mjs +19 -1
- package/api/theme/_adapter.d.mts +26 -28
- package/api/theme/_adapter.mjs +101 -38
- package/api/theme/add/add.d.mts +2 -1
- package/api/theme/add/add.mjs +56 -20
- package/api/theme/add/add.test.mjs +1 -0
- package/api/theme/build/build.d.mts +25 -0
- package/api/theme/build/build.mjs +101 -70
- package/api/theme/build/build.test.mjs +77 -44
- package/api/theme/integration-themes.test.mjs +183 -0
- package/api/theme/list/list.d.mts +10 -2
- package/api/theme/list/list.mjs +31 -10
- package/api/theme/list/list.test.mjs +102 -23
- package/api/theme/listThemes.doc.d.mts +1 -5
- package/api/theme/listThemes.doc.mjs +6 -13
- package/api/theme/targets/targets.test.mjs +22 -8
- package/api/theme/theme.d.mts +1 -1
- package/api/theme/theme.mjs +1 -1
- package/api/theme/theme.type.d.mts +9 -0
- package/api/theme/theme.type.mjs +3 -1
- package/api/theme/themeAdd.doc.d.mts +1 -4
- package/api/theme/themeAdd.doc.mjs +31 -31
- package/api/theme/themeBuild.doc.mjs +1 -1
- package/api/theme/themeList.doc.d.mts +1 -4
- package/api/theme/themeList.doc.mjs +7 -15
- package/api/theme/themeListAvailable.doc.d.mts +8 -0
- package/api/theme/themeListAvailable.doc.mjs +57 -0
- package/api/theme/themeTargets.doc.mjs +21 -7
- package/api/upgrade/_adapter.d.mts +2 -0
- package/api/upgrade/_adapter.mjs +1 -0
- package/api/upgrade/registry/registry.d.mts +40 -0
- package/api/upgrade/registry/registry.mjs +1154 -0
- package/api/upgrade/registry/registry.test.mjs +826 -0
- package/api/upgrade/run/run.mjs +49 -8
- package/api/upgrade/status/status.d.mts +6 -4
- package/api/upgrade/status/status.mjs +26 -8
- package/api/upgrade/upgrade.d.mts +2 -2
- package/api/upgrade/upgrade.doc.mjs +33 -9
- package/api/upgrade/upgrade.mjs +34 -7
- package/api/upgrade/upgrade.test.mjs +198 -8
- package/api/upgrade/upgrade.type.d.mts +90 -1
- package/api/upgrade/upgrade.type.mjs +51 -2
- package/assets/docs/cli-integrations.doc.mjs +152 -28
- package/assets/docs/getting-started.doc.mjs +1 -1
- package/assets/docs/{shadcn-compatibility.doc.mjs → shadcn-compatibility.doc.draft.mjs} +23 -13
- package/assets/docs/styling.doc.mjs +3 -3
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +23 -13
- package/assets/docs/theme.doc.zh.mjs +1 -1
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +2 -1
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +38 -12
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.tsx +87 -0
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +23 -0
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +75 -0
- package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.tsx +5 -19
- package/assets/templates/blocks/components/Center/CenterHorizontal.doc.mjs +3 -2
- package/assets/templates/blocks/components/Center/CenterHorizontal.tsx +4 -5
- package/assets/templates/blocks/components/Toast/ToastAction.tsx +2 -1
- package/assets/templates/blocks/components/Toast/ToastDeduplication.tsx +2 -1
- package/assets/templates/blocks/components/Toast/ToastDismiss.tsx +2 -1
- package/assets/templates/blocks/components/Toast/ToastShowcase.tsx +2 -1
- package/assets/templates/blocks/components/Toast/ToastStacking.tsx +2 -1
- package/assets/templates/blocks/components/Toast/ToastTypes.tsx +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +2 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +3 -3
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -2
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +2 -2
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -2
- package/assets/templates/themes/butter/butterTheme.ts +3 -3
- package/assets/templates/themes/neutral/neutralTheme.ts +2 -2
- package/assets/templates/themes/stone/stoneTheme.ts +3 -3
- package/assets/theme.template.ts +4 -7
- package/authoring/config/config.doc.mjs +9 -1
- package/authoring/config/parse.d.mts +2 -0
- package/authoring/config/parse.mjs +28 -3
- package/authoring/config/parse.test.mjs +25 -3
- package/authoring/config/type.ts +3 -0
- package/authoring/doctypes/_schema.d.mts +3 -0
- package/authoring/doctypes/_schema.mjs +6 -1
- package/authoring/doctypes/base/type.ts +6 -6
- package/authoring/doctypes/component/component.doc.mjs +6 -0
- package/authoring/doctypes/component/type.ts +2 -0
- package/authoring/gap-report/parse.d.mts +63 -0
- package/authoring/gap-report/parse.mjs +121 -0
- package/authoring/gap-report/parse.test.mjs +172 -0
- package/authoring/gap-report/type.ts +107 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +12 -0
- package/authoring/index.mjs +4 -0
- package/authoring/integration/integration.doc.mjs +14 -2
- package/authoring/integration/parse.test.mjs +9 -4
- package/authoring/integration/schema.d.mts +2 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +23 -6
- package/authoring/shadcn/receipt.d.mts +219 -0
- package/authoring/shadcn/receipt.mjs +248 -0
- package/authoring/shadcn/receipt.test.mjs +187 -0
- package/authoring/shadcn/source-variants.d.mts +28 -0
- package/authoring/shadcn/source-variants.mjs +176 -0
- package/authoring/shadcn/source-variants.test.mjs +120 -0
- package/clients/cli/commands/build-theme.mjs +54 -19
- package/clients/cli/commands/build-theme.variants.test.mjs +15 -12
- package/clients/cli/commands/component/index.mjs +1 -1
- package/clients/cli/commands/docs.test.mjs +1 -0
- package/clients/cli/commands/doctor-integration.doc.mjs +1 -1
- package/clients/cli/commands/gap-report.doc.mjs +73 -0
- package/clients/cli/commands/gap-report.mjs +114 -0
- package/clients/cli/commands/gap-report.test.mjs +198 -0
- package/clients/cli/commands/import-hint-correctness.test.mjs +88 -0
- package/clients/cli/commands/integration-add.doc.mjs +88 -0
- package/clients/cli/commands/integration-authoring.test.mjs +177 -0
- package/clients/cli/commands/integration-pack.doc.mjs +34 -0
- package/clients/cli/commands/integration-real-world.test.mjs +618 -0
- package/clients/cli/commands/integration.doc.mjs +28 -0
- package/clients/cli/commands/integration.mjs +153 -0
- package/clients/cli/commands/theme-add.doc.mjs +11 -6
- package/clients/cli/commands/theme-list.doc.mjs +21 -5
- package/clients/cli/commands/theme-targets.behavior.test.mjs +19 -2
- package/clients/cli/commands/theme.doc.mjs +2 -2
- package/clients/cli/commands/upgrade.doc.mjs +17 -4
- package/clients/cli/commands/upgrade.mjs +12 -1
- package/clients/cli/commands/upgrade.test.mjs +41 -0
- package/clients/cli/index.mjs +5 -0
- package/clients/cli/lib/component-format.mjs +42 -26
- package/clients/cli/lib/component-format.test.mjs +34 -3
- package/clients/cli/lib/manifest.mjs +12 -0
- package/foundation/config/project-themes.test.mjs +127 -0
- package/foundation/config/project.d.mts +23 -4
- package/foundation/config/project.mjs +96 -9
- package/foundation/config/project.test.mjs +132 -6
- package/foundation/discovery/component-discovery.d.mts +36 -0
- package/foundation/discovery/component-discovery.mjs +96 -0
- package/foundation/discovery/theme-discovery.d.mts +39 -0
- package/foundation/discovery/theme-discovery.mjs +650 -0
- package/foundation/discovery/theme-discovery.test.mjs +375 -0
- package/foundation/discovery/theming-targets.d.mts +16 -0
- package/foundation/discovery/theming-targets.mjs +39 -3
- package/foundation/discovery/theming-targets.test.mjs +139 -0
- package/foundation/integrations/autolink.d.mts +96 -0
- package/foundation/integrations/autolink.mjs +265 -0
- package/foundation/integrations/autolink.test.mjs +430 -0
- package/foundation/integrations/contribution-inventory.d.mts +152 -0
- package/foundation/integrations/contribution-inventory.mjs +497 -0
- package/foundation/integrations/contribution-inventory.test.mjs +361 -0
- package/foundation/integrations/integrations.d.mts +73 -9
- package/foundation/integrations/integrations.mjs +158 -8
- package/foundation/integrations/integrations.test.mjs +152 -29
- package/foundation/integrations/manifest-writer.d.mts +56 -0
- package/foundation/integrations/manifest-writer.mjs +328 -0
- package/foundation/integrations/manifest-writer.test.mjs +229 -0
- package/foundation/integrations/validate-contributions.mjs +81 -6
- package/foundation/response/error-codes.d.mts +4 -1
- package/foundation/response/error-codes.doc.mjs +16 -1
- package/foundation/response/error-codes.mjs +10 -1
- package/foundation/response/response-types.doc.mjs +23 -2
- package/package.json +8 -1
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Contribution inventory for integration pack-check.
|
|
5
|
+
*
|
|
6
|
+
* Enumerates the files and contribution identities an integration package
|
|
7
|
+
* declares, for cross-referencing against the npm tarball. The file inventory
|
|
8
|
+
* is computed statically (no module imports); the identity inventory runs
|
|
9
|
+
* the same discovery functions a consumer uses.
|
|
10
|
+
*
|
|
11
|
+
* @position packages/cli/foundation/integrations — shared contribution inventory
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import * as fs from 'node:fs';
|
|
15
|
+
import * as path from 'node:path';
|
|
16
|
+
import {isDeepStrictEqual} from 'node:util';
|
|
17
|
+
import {THEME_MANIFEST_BASENAME} from '../discovery/theme-discovery.mjs';
|
|
18
|
+
import {discoverIntegrationThemes} from '../discovery/theme-discovery.mjs';
|
|
19
|
+
import {discoverIntegrationComponents} from '../discovery/component-discovery.mjs';
|
|
20
|
+
import {loadComponentDoc} from '../discovery/component-loader.mjs';
|
|
21
|
+
import {discoverIntegrationTemplatesForOne} from '../discovery/template-adapter.mjs';
|
|
22
|
+
import {discoverIntegrationCodemods} from '../../assets/codemods/integration-discovery.mjs';
|
|
23
|
+
import {discoverIntegrationDocs} from '../discovery/docs-discovery.mjs';
|
|
24
|
+
|
|
25
|
+
// ── File-walk helpers (no module imports, no execution) ──────────
|
|
26
|
+
|
|
27
|
+
const TEMPLATE_RE = /\.(?:template|doc)\.(?:ts|mjs|js)$/u;
|
|
28
|
+
const COMPONENT_DOC_RE = /\.doc\.(?:ts|mjs|js)$/u;
|
|
29
|
+
const CODEMOD_RE = /\.(?:ts|mjs|js)$/u;
|
|
30
|
+
const CODEMOD_TEST_RE = /\.(?:test|spec|fixture)\.(?:ts|mjs|js)$/u;
|
|
31
|
+
const DOC_RE = /\.doc\.(?:ts|mjs|js)$/u;
|
|
32
|
+
const SKIP_DIRS = new Set([
|
|
33
|
+
'node_modules',
|
|
34
|
+
'.git',
|
|
35
|
+
'__tests__',
|
|
36
|
+
'__fixtures__',
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Recursively collect files under `dir` that satisfy `filter`, excluding
|
|
41
|
+
* `node_modules` and `.git`. Returns sorted absolute paths.
|
|
42
|
+
* @param {string} dir
|
|
43
|
+
* @param {(name: string) => boolean} filter
|
|
44
|
+
* @returns {string[]}
|
|
45
|
+
*/
|
|
46
|
+
function walkDir(dir, filter) {
|
|
47
|
+
if (!dir || !fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) return [];
|
|
48
|
+
/** @type {string[]} */
|
|
49
|
+
const out = [];
|
|
50
|
+
for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
|
|
51
|
+
if (SKIP_DIRS.has(entry.name)) continue;
|
|
52
|
+
const full = path.join(dir, entry.name);
|
|
53
|
+
if (entry.isDirectory()) out.push(...walkDir(full, filter));
|
|
54
|
+
else if (filter(entry.name)) out.push(full);
|
|
55
|
+
}
|
|
56
|
+
return out.sort();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @param {string} packageDir @param {string} file */
|
|
60
|
+
function rel(packageDir, file) {
|
|
61
|
+
return path.relative(packageDir, file).split(path.sep).join('/');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ── Per-kind file enumeration ────────────────────────────────────
|
|
65
|
+
|
|
66
|
+
/** @param {string} root @param {string} pkgDir */
|
|
67
|
+
function enumerateThemeFiles(root, pkgDir) {
|
|
68
|
+
/** @type {string[]} */
|
|
69
|
+
const files = [];
|
|
70
|
+
const catalog = path.join(root, THEME_MANIFEST_BASENAME);
|
|
71
|
+
if (!fs.existsSync(catalog)) return files;
|
|
72
|
+
files.push(rel(pkgDir, catalog));
|
|
73
|
+
try {
|
|
74
|
+
const data = JSON.parse(fs.readFileSync(catalog, 'utf-8'));
|
|
75
|
+
if (data?.version !== 1 || !Array.isArray(data.themes)) return files;
|
|
76
|
+
for (const theme of data.themes) {
|
|
77
|
+
if (typeof theme.slug !== 'string' || !Array.isArray(theme.files))
|
|
78
|
+
continue;
|
|
79
|
+
for (const f of theme.files) {
|
|
80
|
+
if (typeof f === 'string') {
|
|
81
|
+
files.push(rel(pkgDir, path.join(root, theme.slug, f)));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} catch {
|
|
86
|
+
/* Phase 1 catches structural issues */
|
|
87
|
+
}
|
|
88
|
+
return files;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @param {string} root @param {string} pkgDir */
|
|
92
|
+
function enumerateComponentFiles(root, pkgDir) {
|
|
93
|
+
const files = [];
|
|
94
|
+
for (const doc of walkDir(root, name => COMPONENT_DOC_RE.test(name))) {
|
|
95
|
+
files.push(rel(pkgDir, doc));
|
|
96
|
+
const source = `${doc.replace(COMPONENT_DOC_RE, '')}.tsx`;
|
|
97
|
+
if (fs.existsSync(source)) files.push(rel(pkgDir, source));
|
|
98
|
+
}
|
|
99
|
+
return files;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** @param {string} root @param {string} pkgDir */
|
|
103
|
+
function enumerateTemplateFiles(root, pkgDir) {
|
|
104
|
+
const files = [];
|
|
105
|
+
for (const tmpl of walkDir(root, n => TEMPLATE_RE.test(n))) {
|
|
106
|
+
files.push(rel(pkgDir, tmpl));
|
|
107
|
+
const stem = tmpl.replace(TEMPLATE_RE, '');
|
|
108
|
+
const source = `${stem}.tsx`;
|
|
109
|
+
if (fs.existsSync(source)) files.push(rel(pkgDir, source));
|
|
110
|
+
}
|
|
111
|
+
return files;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** @param {string} root @param {string} pkgDir */
|
|
115
|
+
function enumerateCodemodFiles(root, pkgDir) {
|
|
116
|
+
return walkDir(
|
|
117
|
+
root,
|
|
118
|
+
name => CODEMOD_RE.test(name) && !CODEMOD_TEST_RE.test(name),
|
|
119
|
+
).map(file => rel(pkgDir, file));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** @param {string} root @param {string} pkgDir */
|
|
123
|
+
function enumerateDocFiles(root, pkgDir) {
|
|
124
|
+
return walkDir(root, n => DOC_RE.test(n)).map(f => rel(pkgDir, f));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** @type {Record<FileInventoryRoot['kind'], (root: string, pkgDir: string) => string[]>} */
|
|
128
|
+
const ENUMERATORS = {
|
|
129
|
+
themes: enumerateThemeFiles,
|
|
130
|
+
components: enumerateComponentFiles,
|
|
131
|
+
templates: enumerateTemplateFiles,
|
|
132
|
+
codemods: enumerateCodemodFiles,
|
|
133
|
+
docs: enumerateDocFiles,
|
|
134
|
+
};
|
|
135
|
+
const ROOT_KINDS = /** @type {const} */ ([
|
|
136
|
+
'themes',
|
|
137
|
+
'components',
|
|
138
|
+
'templates',
|
|
139
|
+
'codemods',
|
|
140
|
+
'docs',
|
|
141
|
+
]);
|
|
142
|
+
|
|
143
|
+
// ── Public: static file inventory ────────────────────────────────
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @typedef {object} FileInventoryRoot
|
|
147
|
+
* @property {'themes'|'components'|'templates'|'codemods'|'docs'} kind
|
|
148
|
+
* @property {string} path — project-relative root path
|
|
149
|
+
* @property {string[]} files — project-relative required file paths
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @typedef {object} FileInventory
|
|
154
|
+
* @property {string} manifest — project-relative manifest path
|
|
155
|
+
* @property {FileInventoryRoot[]} roots
|
|
156
|
+
* @property {string[]} allFiles — deduplicated flat list
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Compute the files the tarball must contain for an integration's
|
|
161
|
+
* contributions to be visible. Reads catalogs and walks directories;
|
|
162
|
+
* never imports or executes authored modules.
|
|
163
|
+
*
|
|
164
|
+
* @param {import('./integrations.mjs').LoadedIntegration} loaded
|
|
165
|
+
* @returns {FileInventory}
|
|
166
|
+
*/
|
|
167
|
+
export function computeRequiredFiles(loaded) {
|
|
168
|
+
const pkgDir = loaded.__packageDir;
|
|
169
|
+
const manifestRel = rel(pkgDir, loaded.__manifestFile);
|
|
170
|
+
/** @type {FileInventoryRoot[]} */
|
|
171
|
+
const roots = [];
|
|
172
|
+
const allFiles = [manifestRel];
|
|
173
|
+
|
|
174
|
+
for (const kind of ROOT_KINDS) {
|
|
175
|
+
const root = loaded[kind];
|
|
176
|
+
if (!root) continue;
|
|
177
|
+
const files = ENUMERATORS[kind](root, pkgDir);
|
|
178
|
+
roots.push({
|
|
179
|
+
kind,
|
|
180
|
+
path: rel(pkgDir, root),
|
|
181
|
+
files,
|
|
182
|
+
});
|
|
183
|
+
allFiles.push(...files);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return {manifest: manifestRel, roots, allFiles: [...new Set(allFiles)]};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ── Public: identity collection ──────────────────────────────────
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @typedef {object} ContributionIdentities
|
|
193
|
+
* @property {{slug: string, exportName: string}[]} themes
|
|
194
|
+
* @property {string[]} components
|
|
195
|
+
* @property {{id: string, type: string, name: string}[]} templates
|
|
196
|
+
* @property {{version: string, id: string}[]} codemods
|
|
197
|
+
* @property {string[]} docs
|
|
198
|
+
* @property {string[]} agentDocsAppend
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The resolved fields needed to discover contribution identities.
|
|
203
|
+
* @typedef {object} IdentitySource
|
|
204
|
+
* @property {string} name
|
|
205
|
+
* @property {string} [themes]
|
|
206
|
+
* @property {string} [components]
|
|
207
|
+
* @property {string} [templates]
|
|
208
|
+
* @property {string} [codemods]
|
|
209
|
+
* @property {string} [docs]
|
|
210
|
+
* @property {{append?: readonly string[]}} [agentDocs]
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Run the same discovery functions a consumer uses to collect every
|
|
215
|
+
* contribution identity from a loaded integration.
|
|
216
|
+
*
|
|
217
|
+
* @param {IdentitySource} loaded
|
|
218
|
+
* @returns {Promise<{identities: ContributionIdentities, errors: Array<{kind: string, message: string}>}>}
|
|
219
|
+
*/
|
|
220
|
+
export async function collectIdentities(loaded) {
|
|
221
|
+
/** @type {ContributionIdentities} */
|
|
222
|
+
const identities = {
|
|
223
|
+
themes: [],
|
|
224
|
+
components: [],
|
|
225
|
+
templates: [],
|
|
226
|
+
codemods: [],
|
|
227
|
+
docs: [],
|
|
228
|
+
agentDocsAppend: loaded.agentDocs?.append
|
|
229
|
+
? [...loaded.agentDocs.append]
|
|
230
|
+
: [],
|
|
231
|
+
};
|
|
232
|
+
/** @type {Array<{kind: string, message: string}>} */
|
|
233
|
+
const errors = [];
|
|
234
|
+
|
|
235
|
+
if (loaded.themes && fs.existsSync(loaded.themes)) {
|
|
236
|
+
try {
|
|
237
|
+
const themes = await discoverIntegrationThemes(
|
|
238
|
+
/** @type {import('./integrations.mjs').LoadedIntegration} */ (loaded),
|
|
239
|
+
);
|
|
240
|
+
identities.themes = themes
|
|
241
|
+
.map(t => ({slug: t.slug, exportName: t.exportName}))
|
|
242
|
+
.sort((a, b) => a.slug.localeCompare(b.slug));
|
|
243
|
+
} catch (err) {
|
|
244
|
+
errors.push({
|
|
245
|
+
kind: 'themes',
|
|
246
|
+
message: /** @type {Error} */ (err).message,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (loaded.components && fs.existsSync(loaded.components)) {
|
|
252
|
+
try {
|
|
253
|
+
const records = discoverIntegrationComponents(loaded) ?? [];
|
|
254
|
+
for (const record of records) {
|
|
255
|
+
try {
|
|
256
|
+
await loadComponentDoc(record.docPath);
|
|
257
|
+
identities.components.push(record.name);
|
|
258
|
+
} catch (err) {
|
|
259
|
+
errors.push({
|
|
260
|
+
kind: 'components',
|
|
261
|
+
message: `${path.relative(loaded.components, record.docPath)}: ${
|
|
262
|
+
/** @type {Error} */ (err).message
|
|
263
|
+
}`,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
identities.components.sort();
|
|
268
|
+
} catch (err) {
|
|
269
|
+
errors.push({
|
|
270
|
+
kind: 'components',
|
|
271
|
+
message: /** @type {Error} */ (err).message,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (loaded.templates && fs.existsSync(loaded.templates)) {
|
|
277
|
+
try {
|
|
278
|
+
const {templates, errors: templateErrors} =
|
|
279
|
+
await discoverIntegrationTemplatesForOne(loaded);
|
|
280
|
+
for (const templateError of templateErrors) {
|
|
281
|
+
errors.push({kind: 'templates', message: templateError.message});
|
|
282
|
+
}
|
|
283
|
+
identities.templates = templates
|
|
284
|
+
.map(t => ({id: t.dirName, type: t.type, name: t.name}))
|
|
285
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
286
|
+
} catch (err) {
|
|
287
|
+
errors.push({
|
|
288
|
+
kind: 'templates',
|
|
289
|
+
message: /** @type {Error} */ (err).message,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (loaded.codemods && fs.existsSync(loaded.codemods)) {
|
|
295
|
+
try {
|
|
296
|
+
const byVersion = await discoverIntegrationCodemods([loaded]);
|
|
297
|
+
/** @type {{version: string, id: string}[]} */
|
|
298
|
+
const entries = [];
|
|
299
|
+
for (const [version, codemods] of byVersion) {
|
|
300
|
+
for (const cm of codemods) entries.push({version, id: cm.id});
|
|
301
|
+
}
|
|
302
|
+
identities.codemods = entries.sort((a, b) =>
|
|
303
|
+
`${a.version}/${a.id}`.localeCompare(`${b.version}/${b.id}`),
|
|
304
|
+
);
|
|
305
|
+
} catch (err) {
|
|
306
|
+
errors.push({
|
|
307
|
+
kind: 'codemods',
|
|
308
|
+
message: /** @type {Error} */ (err).message,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (loaded.docs && fs.existsSync(loaded.docs)) {
|
|
314
|
+
try {
|
|
315
|
+
const {records, errors: docErrors} =
|
|
316
|
+
await discoverIntegrationDocs(loaded);
|
|
317
|
+
for (const docError of docErrors) {
|
|
318
|
+
errors.push({kind: 'docs', message: docError.message});
|
|
319
|
+
}
|
|
320
|
+
identities.docs = records.map(r => r.name).sort();
|
|
321
|
+
} catch (err) {
|
|
322
|
+
errors.push({kind: 'docs', message: /** @type {Error} */ (err).message});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return {identities, errors};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Prove that one contribution is visible through the same inventory seam the
|
|
331
|
+
* packed-package checker uses. This is the shared postcondition for every add
|
|
332
|
+
* handler, not a second set of per-writer rules.
|
|
333
|
+
*
|
|
334
|
+
* @param {IdentitySource} loaded
|
|
335
|
+
* @param {'theme'|'component'|'template'|'codemod'|'doc'|'agent-doc'} kind
|
|
336
|
+
* @param {string} name
|
|
337
|
+
* @param {{version?: string}} [options]
|
|
338
|
+
* @returns {Promise<void>}
|
|
339
|
+
*/
|
|
340
|
+
export async function assertContributionVisible(
|
|
341
|
+
loaded,
|
|
342
|
+
kind,
|
|
343
|
+
name,
|
|
344
|
+
{version} = {},
|
|
345
|
+
) {
|
|
346
|
+
const {identities, errors} = await collectIdentities(loaded);
|
|
347
|
+
const errorKind =
|
|
348
|
+
kind === 'theme'
|
|
349
|
+
? 'themes'
|
|
350
|
+
: kind === 'component'
|
|
351
|
+
? 'components'
|
|
352
|
+
: kind === 'template'
|
|
353
|
+
? 'templates'
|
|
354
|
+
: kind === 'codemod'
|
|
355
|
+
? 'codemods'
|
|
356
|
+
: kind === 'doc'
|
|
357
|
+
? 'docs'
|
|
358
|
+
: 'agentDocs';
|
|
359
|
+
const relevantError = errors.find(error => error.kind === errorKind);
|
|
360
|
+
if (relevantError) throw new Error(relevantError.message);
|
|
361
|
+
|
|
362
|
+
const visible =
|
|
363
|
+
kind === 'theme'
|
|
364
|
+
? identities.themes.some(theme => theme.slug === name)
|
|
365
|
+
: kind === 'component'
|
|
366
|
+
? identities.components.includes(name)
|
|
367
|
+
: kind === 'template'
|
|
368
|
+
? identities.templates.some(template => template.id === name)
|
|
369
|
+
: kind === 'codemod'
|
|
370
|
+
? identities.codemods.some(
|
|
371
|
+
codemod => codemod.id === name && codemod.version === version,
|
|
372
|
+
)
|
|
373
|
+
: kind === 'doc'
|
|
374
|
+
? identities.docs.includes(name)
|
|
375
|
+
: identities.agentDocsAppend.includes(name);
|
|
376
|
+
if (!visible) {
|
|
377
|
+
const qualifier = version == null ? '' : ` under version ${version}`;
|
|
378
|
+
throw new Error(
|
|
379
|
+
`${kind} contribution "${name}" was not visible${qualifier} after writing.`,
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// ── Public: identity comparison ──────────────────────────────────
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* @typedef {import('./issue').AstryxIntegrationIssue} Issue
|
|
388
|
+
*/
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Compare local and packed identities. Anything discoverable locally but
|
|
392
|
+
* missing from the packed tarball is an error.
|
|
393
|
+
*
|
|
394
|
+
* @param {ContributionIdentities} local
|
|
395
|
+
* @param {ContributionIdentities} packed
|
|
396
|
+
* @returns {Issue[]}
|
|
397
|
+
*/
|
|
398
|
+
export function compareIdentities(local, packed) {
|
|
399
|
+
/** @type {Issue[]} */
|
|
400
|
+
const issues = [];
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Compare one identity list in both directions, then compare the complete
|
|
404
|
+
* record for matching keys. A packed-only identity is just as suspicious as a
|
|
405
|
+
* missing one: npm shipped bytes the local authoring view did not expose.
|
|
406
|
+
* @param {string} kind
|
|
407
|
+
* @param {unknown[]} localItems
|
|
408
|
+
* @param {unknown[]} packedItems
|
|
409
|
+
* @param {(item: any) => string} keyOf
|
|
410
|
+
*/
|
|
411
|
+
function compareKind(kind, localItems, packedItems, keyOf) {
|
|
412
|
+
const localByKey = new Map(localItems.map(item => [keyOf(item), item]));
|
|
413
|
+
const packedByKey = new Map(packedItems.map(item => [keyOf(item), item]));
|
|
414
|
+
for (const [key, item] of localByKey) {
|
|
415
|
+
if (!packedByKey.has(key)) {
|
|
416
|
+
issues.push({
|
|
417
|
+
code: 'identity_not_packed',
|
|
418
|
+
severity: 'error',
|
|
419
|
+
message: `${kind} "${key}" is discoverable locally but missing from the packed tarball.`,
|
|
420
|
+
});
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
const packedItem = packedByKey.get(key);
|
|
424
|
+
if (!isDeepStrictEqual(item, packedItem)) {
|
|
425
|
+
issues.push({
|
|
426
|
+
code: 'identity_mismatch',
|
|
427
|
+
severity: 'error',
|
|
428
|
+
message: `${kind} "${key}" resolves differently from the packed tarball.`,
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
for (const key of packedByKey.keys()) {
|
|
433
|
+
if (!localByKey.has(key)) {
|
|
434
|
+
issues.push({
|
|
435
|
+
code: 'packed_identity_unexpected',
|
|
436
|
+
severity: 'error',
|
|
437
|
+
message: `${kind} "${key}" exists only in the packed tarball.`,
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
compareKind('Theme', local.themes, packed.themes, item => item.slug);
|
|
444
|
+
compareKind('Component', local.components, packed.components, item => item);
|
|
445
|
+
compareKind('Template', local.templates, packed.templates, item => item.id);
|
|
446
|
+
compareKind(
|
|
447
|
+
'Codemod',
|
|
448
|
+
local.codemods,
|
|
449
|
+
packed.codemods,
|
|
450
|
+
item => `${item.version}/${item.id}`,
|
|
451
|
+
);
|
|
452
|
+
compareKind('Doc topic', local.docs, packed.docs, item => item);
|
|
453
|
+
|
|
454
|
+
if (
|
|
455
|
+
JSON.stringify(local.agentDocsAppend) !==
|
|
456
|
+
JSON.stringify(packed.agentDocsAppend)
|
|
457
|
+
) {
|
|
458
|
+
issues.push({
|
|
459
|
+
code: 'agent_docs_mismatch',
|
|
460
|
+
severity: 'error',
|
|
461
|
+
message:
|
|
462
|
+
'agentDocs.append lines differ between local and packed manifests.',
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return issues;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// ── Public: source-only candidate detection ──────────────────────
|
|
470
|
+
|
|
471
|
+
const PASCAL_CASE_TSX = /^([A-Z][A-Za-z0-9]+)\.tsx$/u;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Find top-level PascalCase `.tsx` files under a components root that are
|
|
475
|
+
* NOT registered as integration components. These are candidates that
|
|
476
|
+
* Astryx will ignore — surfaced as a warning so the author knows.
|
|
477
|
+
*
|
|
478
|
+
* Scans only direct children of the root (not recursive) and never
|
|
479
|
+
* enters node_modules.
|
|
480
|
+
*
|
|
481
|
+
* @param {string|undefined} componentsRoot absolute path
|
|
482
|
+
* @param {string[]} registeredNames names already returned by discovery
|
|
483
|
+
* @returns {string[]} unregistered PascalCase names
|
|
484
|
+
*/
|
|
485
|
+
export function findSourceOnlyCandidates(componentsRoot, registeredNames) {
|
|
486
|
+
if (!componentsRoot || !fs.existsSync(componentsRoot)) return [];
|
|
487
|
+
const known = new Set(registeredNames);
|
|
488
|
+
/** @type {string[]} */
|
|
489
|
+
const candidates = [];
|
|
490
|
+
for (const entry of fs.readdirSync(componentsRoot, {withFileTypes: true})) {
|
|
491
|
+
if (!entry.isFile() && !entry.isSymbolicLink()) continue;
|
|
492
|
+
const match = entry.name.match(PASCAL_CASE_TSX);
|
|
493
|
+
if (!match) continue;
|
|
494
|
+
if (!known.has(match[1])) candidates.push(match[1]);
|
|
495
|
+
}
|
|
496
|
+
return candidates.sort();
|
|
497
|
+
}
|