@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
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Integrations are PACKAGE NAMES listed in astryx.config.{ts,mjs,js}. Each
|
|
7
7
|
* package declares a single conventional root manifest sibling to its
|
|
8
8
|
* package.json — astryx.integration.{ts,mjs,js} — which contributes
|
|
9
|
-
* components/templates/codemods/docs roots and an optional issuesUrl. Identity
|
|
9
|
+
* components/templates/codemods/docs/themes roots and an optional issuesUrl. Identity
|
|
10
10
|
* (name, version) comes from the package's package.json, not the manifest.
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -22,11 +22,12 @@ import {
|
|
|
22
22
|
unknownIntegrationKeys,
|
|
23
23
|
} from '../../authoring/integration/schema.mjs';
|
|
24
24
|
import {importUserModule, findPresentFiles} from '../fs/module-loader.mjs';
|
|
25
|
+
import {parseGapReportHandler} from '../../authoring/gap-report/parse.mjs';
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* A fully-resolved, loaded integration. Identity (`name`, `version`) comes from
|
|
28
|
-
* the package's package.json; the `components`/`templates`/`codemods`/`docs
|
|
29
|
-
* roots are absolute paths resolved from the manifest. The `__`-prefixed fields
|
|
29
|
+
* the package's package.json; the `components`/`templates`/`codemods`/`docs`/
|
|
30
|
+
* `themes` roots are absolute paths resolved from the manifest. The `__`-prefixed fields
|
|
30
31
|
* are internal bookkeeping used by Doctor integration validation and Project.
|
|
31
32
|
* @typedef {object} LoadedIntegration
|
|
32
33
|
* @property {string} name
|
|
@@ -35,20 +36,35 @@ import {importUserModule, findPresentFiles} from '../fs/module-loader.mjs';
|
|
|
35
36
|
* @property {string} [templates]
|
|
36
37
|
* @property {string} [codemods]
|
|
37
38
|
* @property {string} [docs]
|
|
39
|
+
* @property {string} [themes]
|
|
38
40
|
* @property {string} [issuesUrl]
|
|
39
41
|
* @property {{append?: readonly string[]}} [agentDocs]
|
|
40
42
|
* @property {string} [__agentDocsError] contribution-specific validation
|
|
41
43
|
* failure; other manifest contributions remain available
|
|
42
44
|
* @property {string} __spec
|
|
43
45
|
* @property {string} __packageDir
|
|
46
|
+
* @property {Record<string, unknown>|null} [__packageExports] the owning
|
|
47
|
+
* package's `exports` map, kept from the package.json this loader already
|
|
48
|
+
* parsed so import resolution does not read it a second time
|
|
44
49
|
* @property {string} __manifestFile
|
|
45
50
|
* @property {string} [__loadError] set when the manifest failed to load/validate;
|
|
46
51
|
* such an integration contributes nothing and is surfaced via Project.issues()
|
|
47
52
|
* @property {string[]} [__unknownKeys] manifest keys this CLI does not know —
|
|
48
53
|
* surfaced as a warning; the rest of the manifest still contributes
|
|
54
|
+
* @property {boolean} [__autolinked] loaded because the project declares the
|
|
55
|
+
* package as a dependency and it ships a manifest, with no astryx.config
|
|
56
|
+
* entry naming it — see foundation/integrations/autolink.mjs
|
|
57
|
+
* @property {boolean} [__local] loaded from the package containing the current
|
|
58
|
+
* working directory, so an author sees the exact bytes they are editing
|
|
59
|
+
* @property {string} [__dependencyField] for an autolinked integration, the
|
|
60
|
+
* package.json field that declared it (`dependencies`, `devDependencies`,
|
|
61
|
+
* `optionalDependencies`)
|
|
49
62
|
* @property {import('../../authoring/debug/type').DebugEventHandler} [__debug]
|
|
50
63
|
* the manifest module's `debug` NAMED export, when it exported a function.
|
|
51
|
-
*
|
|
64
|
+
* @property {import('../../authoring/gap-report/type').GapReportHandler} [__gapReport]
|
|
65
|
+
* validated package-owned handler from the `gapReport` NAMED export.
|
|
66
|
+
* @property {string} [__gapReportError] isolated named-handler validation error.
|
|
67
|
+
* Named exports are not manifest keys — see {@link loadManifest}.
|
|
52
68
|
*/
|
|
53
69
|
|
|
54
70
|
/** Conventional manifest basenames, in load-precedence order. */
|
|
@@ -69,6 +85,29 @@ export function findManifestPaths(dir) {
|
|
|
69
85
|
return findPresentFiles(dir, MANIFEST_BASENAMES);
|
|
70
86
|
}
|
|
71
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Parse the optional named gap-report handler without making it part of the
|
|
90
|
+
* default manifest schema. A malformed handler is isolated from every other
|
|
91
|
+
* integration contribution and represented as a failed delivery at fan-out.
|
|
92
|
+
*
|
|
93
|
+
* @param {unknown} value
|
|
94
|
+
* @param {string} label
|
|
95
|
+
* @returns {{handler?: import('../../authoring/gap-report/type').GapReportHandler, error?: string}}
|
|
96
|
+
*/
|
|
97
|
+
function parseGapReportHandlerExport(value, label) {
|
|
98
|
+
if (value === undefined) return {};
|
|
99
|
+
try {
|
|
100
|
+
return {
|
|
101
|
+
handler: parseGapReportHandler(
|
|
102
|
+
value,
|
|
103
|
+
`${label} named export "gapReport"`,
|
|
104
|
+
),
|
|
105
|
+
};
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return {error: error instanceof Error ? error.message : String(error)};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
72
111
|
/**
|
|
73
112
|
* Load and validate a manifest module's default export, while isolating the
|
|
74
113
|
* optional `agentDocs` contribution from the manifest's other fields.
|
|
@@ -79,13 +118,13 @@ export function findManifestPaths(dir) {
|
|
|
79
118
|
* The raw object is also inspected before parsing so unknown-key warnings retain
|
|
80
119
|
* forward compatibility.
|
|
81
120
|
*
|
|
82
|
-
* `debug`
|
|
83
|
-
*
|
|
121
|
+
* `debug` and `gapReport` come back separately because they are named exports,
|
|
122
|
+
* not manifest keys. A CLI that does not know them simply does not read them.
|
|
84
123
|
*
|
|
85
124
|
* @param {string} file absolute manifest path
|
|
86
125
|
* @param {string} [label] used in error messages
|
|
87
126
|
* @param {{fresh?: boolean}} [options]
|
|
88
|
-
* @returns {Promise<{manifest: import('../../authoring/integration/type').AstryxIntegration, unknownKeys: string[], debug?: import('../../authoring/debug/type').DebugEventHandler, agentDocsError?: string}>}
|
|
127
|
+
* @returns {Promise<{manifest: import('../../authoring/integration/type').AstryxIntegration, unknownKeys: string[], debug?: import('../../authoring/debug/type').DebugEventHandler, gapReport?: import('../../authoring/gap-report/type').GapReportHandler, gapReportError?: string, agentDocsError?: string}>}
|
|
89
128
|
*/
|
|
90
129
|
export async function loadManifest(
|
|
91
130
|
file,
|
|
@@ -95,6 +134,7 @@ export async function loadManifest(
|
|
|
95
134
|
const mod = await importUserModule(file, {fresh});
|
|
96
135
|
const raw = mod?.default;
|
|
97
136
|
const baseManifest = parseIntegrationBase(raw, label);
|
|
137
|
+
const gapReport = parseGapReportHandlerExport(mod?.gapReport, label);
|
|
98
138
|
const hasAgentDocs =
|
|
99
139
|
raw != null &&
|
|
100
140
|
typeof raw === 'object' &&
|
|
@@ -127,6 +167,8 @@ export async function loadManifest(
|
|
|
127
167
|
mod.debug
|
|
128
168
|
)
|
|
129
169
|
: undefined,
|
|
170
|
+
gapReport: gapReport.handler,
|
|
171
|
+
gapReportError: gapReport.error,
|
|
130
172
|
agentDocsError,
|
|
131
173
|
};
|
|
132
174
|
}
|
|
@@ -172,7 +214,9 @@ export function resolvePackageDir(packageName, cwd = process.cwd()) {
|
|
|
172
214
|
const nodeModules = path.resolve(cwd, 'node_modules');
|
|
173
215
|
const dir = path.resolve(nodeModules, ...packageName.split('/'));
|
|
174
216
|
if (dir !== nodeModules && !dir.startsWith(nodeModules + path.sep)) {
|
|
175
|
-
throw new Error(
|
|
217
|
+
throw new Error(
|
|
218
|
+
`Integration "${packageName}" resolves outside node_modules.`,
|
|
219
|
+
);
|
|
176
220
|
}
|
|
177
221
|
return dir;
|
|
178
222
|
}
|
|
@@ -201,6 +245,102 @@ function resolveManifestPath(packageDir, spec) {
|
|
|
201
245
|
return present[0];
|
|
202
246
|
}
|
|
203
247
|
|
|
248
|
+
/**
|
|
249
|
+
* Load the integration package rooted at `packageDir` directly, without first
|
|
250
|
+
* installing or publishing it. This is the self-resolution seam: an author in
|
|
251
|
+
* a package with a manifest sees the same contributions a consumer installs.
|
|
252
|
+
*
|
|
253
|
+
* A missing manifest returns null. A broken manifest returns the same load-error
|
|
254
|
+
* marker as an installed integration, so Project issues stay truthful.
|
|
255
|
+
*
|
|
256
|
+
* @param {string} packageDir
|
|
257
|
+
* @param {{fresh?: boolean}} [options]
|
|
258
|
+
* @returns {Promise<LoadedIntegration|null>}
|
|
259
|
+
*/
|
|
260
|
+
export async function loadLocalIntegration(packageDir, {fresh = false} = {}) {
|
|
261
|
+
const manifests = findManifestPaths(packageDir);
|
|
262
|
+
if (manifests.length === 0) return null;
|
|
263
|
+
|
|
264
|
+
const pkgPath = path.join(packageDir, 'package.json');
|
|
265
|
+
let pkg;
|
|
266
|
+
try {
|
|
267
|
+
pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
268
|
+
} catch {
|
|
269
|
+
throw new Error(
|
|
270
|
+
`Could not read the local integration package at ${pkgPath}.`,
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
const spec =
|
|
274
|
+
typeof pkg.name === 'string' && pkg.name.length > 0
|
|
275
|
+
? pkg.name
|
|
276
|
+
: '(local integration)';
|
|
277
|
+
const manifestFile = resolveManifestPath(packageDir, spec);
|
|
278
|
+
|
|
279
|
+
let manifest;
|
|
280
|
+
/** @type {string[]} */
|
|
281
|
+
let unknownKeys;
|
|
282
|
+
/** @type {import('../../authoring/debug/type').DebugEventHandler | undefined} */
|
|
283
|
+
let debugHandler;
|
|
284
|
+
/** @type {import('../../authoring/gap-report/type').GapReportHandler | undefined} */
|
|
285
|
+
let gapReportHandler;
|
|
286
|
+
/** @type {string | undefined} */
|
|
287
|
+
let gapReportError;
|
|
288
|
+
/** @type {string | undefined} */
|
|
289
|
+
let agentDocsError;
|
|
290
|
+
try {
|
|
291
|
+
({
|
|
292
|
+
manifest,
|
|
293
|
+
unknownKeys,
|
|
294
|
+
debug: debugHandler,
|
|
295
|
+
gapReport: gapReportHandler,
|
|
296
|
+
gapReportError,
|
|
297
|
+
agentDocsError,
|
|
298
|
+
} = await loadManifest(manifestFile, `Integration ${spec}`, {fresh}));
|
|
299
|
+
} catch (err) {
|
|
300
|
+
return {
|
|
301
|
+
name: spec,
|
|
302
|
+
version: pkg.version,
|
|
303
|
+
__spec: spec,
|
|
304
|
+
__packageDir: packageDir,
|
|
305
|
+
__manifestFile: manifestFile,
|
|
306
|
+
__loadError: err instanceof Error ? err.message : String(err),
|
|
307
|
+
__local: true,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** @param {string | null | undefined} value */
|
|
312
|
+
const resolveRoot = value => {
|
|
313
|
+
if (value == null) return undefined;
|
|
314
|
+
try {
|
|
315
|
+
return assertWithin(value, packageDir, {label: 'contribution root'});
|
|
316
|
+
} catch {
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
name: spec,
|
|
323
|
+
version: pkg.version,
|
|
324
|
+
components: resolveRoot(manifest.components),
|
|
325
|
+
templates: resolveRoot(manifest.templates),
|
|
326
|
+
codemods: resolveRoot(manifest.codemods),
|
|
327
|
+
docs: resolveRoot(manifest.docs),
|
|
328
|
+
themes: resolveRoot(manifest.themes),
|
|
329
|
+
issuesUrl: manifest.issuesUrl,
|
|
330
|
+
agentDocs: manifest.agentDocs,
|
|
331
|
+
__agentDocsError: agentDocsError,
|
|
332
|
+
__unknownKeys: unknownKeys,
|
|
333
|
+
__debug: debugHandler,
|
|
334
|
+
__gapReport: gapReportHandler,
|
|
335
|
+
__gapReportError: gapReportError,
|
|
336
|
+
__spec: spec,
|
|
337
|
+
__packageDir: packageDir,
|
|
338
|
+
__packageExports: pkg.exports ?? null,
|
|
339
|
+
__manifestFile: manifestFile,
|
|
340
|
+
__local: true,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
204
344
|
/**
|
|
205
345
|
* Load configured integrations.
|
|
206
346
|
*
|
|
@@ -237,6 +377,10 @@ export async function loadIntegrations(
|
|
|
237
377
|
let unknownKeys;
|
|
238
378
|
/** @type {import('../../authoring/debug/type').DebugEventHandler | undefined} */
|
|
239
379
|
let debugHandler;
|
|
380
|
+
/** @type {import('../../authoring/gap-report/type').GapReportHandler | undefined} */
|
|
381
|
+
let gapReportHandler;
|
|
382
|
+
/** @type {string | undefined} */
|
|
383
|
+
let gapReportError;
|
|
240
384
|
/** @type {string | undefined} */
|
|
241
385
|
let agentDocsError;
|
|
242
386
|
try {
|
|
@@ -244,6 +388,8 @@ export async function loadIntegrations(
|
|
|
244
388
|
manifest,
|
|
245
389
|
unknownKeys,
|
|
246
390
|
debug: debugHandler,
|
|
391
|
+
gapReport: gapReportHandler,
|
|
392
|
+
gapReportError,
|
|
247
393
|
agentDocsError,
|
|
248
394
|
} = await loadManifest(manifestFile, `Integration ${spec}`, {fresh}));
|
|
249
395
|
} catch (err) {
|
|
@@ -280,13 +426,17 @@ export async function loadIntegrations(
|
|
|
280
426
|
templates: resolveRoot(manifest.templates),
|
|
281
427
|
codemods: resolveRoot(manifest.codemods),
|
|
282
428
|
docs: resolveRoot(manifest.docs),
|
|
429
|
+
themes: resolveRoot(manifest.themes),
|
|
283
430
|
issuesUrl: manifest.issuesUrl,
|
|
284
431
|
agentDocs: manifest.agentDocs,
|
|
285
432
|
__agentDocsError: agentDocsError,
|
|
286
433
|
__unknownKeys: unknownKeys,
|
|
287
434
|
__debug: debugHandler,
|
|
435
|
+
__gapReport: gapReportHandler,
|
|
436
|
+
__gapReportError: gapReportError,
|
|
288
437
|
__spec: spec,
|
|
289
438
|
__packageDir: packageDir,
|
|
439
|
+
__packageExports: pkg.exports ?? null,
|
|
290
440
|
__manifestFile: manifestFile,
|
|
291
441
|
});
|
|
292
442
|
}
|
|
@@ -4,13 +4,20 @@ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
|
4
4
|
import * as fs from 'node:fs';
|
|
5
5
|
import * as path from 'node:path';
|
|
6
6
|
import {Project} from '../config/project.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
loadIntegrations,
|
|
9
|
+
loadLocalIntegration,
|
|
10
|
+
resolvePackageDir,
|
|
11
|
+
} from './integrations.mjs';
|
|
8
12
|
import {discover} from '../../api/discover/discover.mjs';
|
|
9
13
|
|
|
10
14
|
let tmpDir;
|
|
11
15
|
let originalCwd;
|
|
12
16
|
|
|
13
|
-
function writeManifestPackage(
|
|
17
|
+
function writeManifestPackage(
|
|
18
|
+
dir,
|
|
19
|
+
{basename = 'astryx.integration.mjs', body},
|
|
20
|
+
) {
|
|
14
21
|
const pkgDir = path.join(dir, 'node_modules', '@acme', 'widgets');
|
|
15
22
|
fs.mkdirSync(pkgDir, {recursive: true});
|
|
16
23
|
fs.writeFileSync(
|
|
@@ -141,26 +148,32 @@ describe('configured integrations', () => {
|
|
|
141
148
|
['wrong outer shape', []],
|
|
142
149
|
['wrong append shape', {append: 'not-an-array'}],
|
|
143
150
|
['non-string entry', {append: ['ok', 42]}],
|
|
144
|
-
[
|
|
151
|
+
[
|
|
152
|
+
'too many lines',
|
|
153
|
+
{append: Array.from({length: 9}, (_, i) => `line ${i}`)},
|
|
154
|
+
],
|
|
145
155
|
['too many code points', {append: ['😀'.repeat(241)]}],
|
|
146
156
|
['control character', {append: ['bad\u0001line']}],
|
|
147
157
|
['managed marker', {append: ['ASTRYX:START']}],
|
|
148
|
-
])(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
])(
|
|
159
|
+
'isolates invalid agentDocs (%s) from valid roots',
|
|
160
|
+
async (_label, agentDocs) => {
|
|
161
|
+
const pkgDir = writeManifestPackage(tmpDir, {
|
|
162
|
+
body: `export default ${JSON.stringify({
|
|
163
|
+
components: './components',
|
|
164
|
+
agentDocs,
|
|
165
|
+
})};\n`,
|
|
166
|
+
});
|
|
167
|
+
fs.mkdirSync(path.join(pkgDir, 'components'));
|
|
168
|
+
|
|
169
|
+
const [loaded] = await loadIntegrations(['@acme/widgets'], {cwd: tmpDir});
|
|
170
|
+
|
|
171
|
+
expect(loaded.__loadError).toBeUndefined();
|
|
172
|
+
expect(loaded.components).toBe(path.join(pkgDir, 'components'));
|
|
173
|
+
expect(loaded.agentDocs).toBeUndefined();
|
|
174
|
+
expect(loaded.__agentDocsError).toMatch(/agentDocs/i);
|
|
175
|
+
},
|
|
176
|
+
);
|
|
164
177
|
|
|
165
178
|
it('errors when the package has no conventional root manifest', async () => {
|
|
166
179
|
const pkgDir = path.join(tmpDir, 'node_modules', '@acme', 'widgets');
|
|
@@ -169,9 +182,9 @@ describe('configured integrations', () => {
|
|
|
169
182
|
path.join(pkgDir, 'package.json'),
|
|
170
183
|
JSON.stringify({name: '@acme/widgets'}),
|
|
171
184
|
);
|
|
172
|
-
await expect(
|
|
173
|
-
/
|
|
174
|
-
);
|
|
185
|
+
await expect(
|
|
186
|
+
loadIntegrations(['@acme/widgets'], {cwd: tmpDir}),
|
|
187
|
+
).rejects.toThrow(/no conventional root manifest/);
|
|
175
188
|
});
|
|
176
189
|
|
|
177
190
|
it('errors when the package has multiple root manifests', async () => {
|
|
@@ -182,15 +195,69 @@ describe('configured integrations', () => {
|
|
|
182
195
|
path.join(pkgDir, 'astryx.integration.js'),
|
|
183
196
|
`module.exports = {};\n`,
|
|
184
197
|
);
|
|
185
|
-
await expect(
|
|
186
|
-
/
|
|
187
|
-
);
|
|
198
|
+
await expect(
|
|
199
|
+
loadIntegrations(['@acme/widgets'], {cwd: tmpDir}),
|
|
200
|
+
).rejects.toThrow(/multiple root manifests/);
|
|
188
201
|
});
|
|
189
202
|
|
|
190
203
|
it('errors when the package is not installed', async () => {
|
|
191
|
-
await expect(
|
|
192
|
-
/
|
|
204
|
+
await expect(
|
|
205
|
+
loadIntegrations(['@acme/missing'], {cwd: tmpDir}),
|
|
206
|
+
).rejects.toThrow(/Could not find installed integration package/);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe('local integration self-resolution', () => {
|
|
211
|
+
it('preserves a valid gapReport named export', async () => {
|
|
212
|
+
fs.writeFileSync(
|
|
213
|
+
path.join(tmpDir, 'package.json'),
|
|
214
|
+
JSON.stringify({name: '@acme/local', version: '1.0.0'}),
|
|
215
|
+
);
|
|
216
|
+
fs.writeFileSync(
|
|
217
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
218
|
+
`export const gapReport = {
|
|
219
|
+
audience: 'internal',
|
|
220
|
+
handle(report) { return {status: 'filed', message: report.component}; },
|
|
221
|
+
};
|
|
222
|
+
export default {};
|
|
223
|
+
`,
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const loaded = await loadLocalIntegration(tmpDir, {fresh: true});
|
|
227
|
+
|
|
228
|
+
expect(loaded).toMatchObject({name: '@acme/local', __local: true});
|
|
229
|
+
expect(loaded?.__gapReport?.audience).toBe('internal');
|
|
230
|
+
expect(
|
|
231
|
+
loaded?.__gapReport?.handle(
|
|
232
|
+
/** @type {any} */ ({component: 'LocalWidget'}),
|
|
233
|
+
/** @type {any} */ ({signal: new AbortController().signal}),
|
|
234
|
+
),
|
|
235
|
+
).toEqual({status: 'filed', message: 'LocalWidget'});
|
|
236
|
+
expect(loaded?.__gapReportError).toBeUndefined();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('preserves a malformed gapReport error without dropping the manifest', async () => {
|
|
240
|
+
fs.writeFileSync(
|
|
241
|
+
path.join(tmpDir, 'package.json'),
|
|
242
|
+
JSON.stringify({name: '@acme/local', version: '1.0.0'}),
|
|
243
|
+
);
|
|
244
|
+
fs.writeFileSync(
|
|
245
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
246
|
+
`export const gapReport = {audience: 'internal', command: './report.mjs'};
|
|
247
|
+
export default {issuesUrl: 'https://example.com/issues'};
|
|
248
|
+
`,
|
|
193
249
|
);
|
|
250
|
+
|
|
251
|
+
const loaded = await loadLocalIntegration(tmpDir, {fresh: true});
|
|
252
|
+
|
|
253
|
+
expect(loaded).toMatchObject({
|
|
254
|
+
name: '@acme/local',
|
|
255
|
+
issuesUrl: 'https://example.com/issues',
|
|
256
|
+
__local: true,
|
|
257
|
+
});
|
|
258
|
+
expect(loaded?.__loadError).toBeUndefined();
|
|
259
|
+
expect(loaded?.__gapReport).toBeUndefined();
|
|
260
|
+
expect(loaded?.__gapReportError).toMatch(/gapReport.*handle/i);
|
|
194
261
|
});
|
|
195
262
|
});
|
|
196
263
|
|
|
@@ -198,7 +265,9 @@ describe('resolvePackageDir — spec must be a bare package name', () => {
|
|
|
198
265
|
it.each(['../../../etc', 'a/../../b', '/abs/evil', 'foo/..', '..'])(
|
|
199
266
|
'rejects a traversal/absolute spec %s',
|
|
200
267
|
spec => {
|
|
201
|
-
expect(() => resolvePackageDir(spec, '/proj')).toThrow(
|
|
268
|
+
expect(() => resolvePackageDir(spec, '/proj')).toThrow(
|
|
269
|
+
/Invalid|outside node_modules/i,
|
|
270
|
+
);
|
|
202
271
|
},
|
|
203
272
|
);
|
|
204
273
|
|
|
@@ -223,7 +292,10 @@ describe('a broken integration manifest degrades gracefully (skip + warn)', () =
|
|
|
223
292
|
]) {
|
|
224
293
|
const dir = path.join(tmpDir, 'node_modules', ...name.split('/'));
|
|
225
294
|
fs.mkdirSync(dir, {recursive: true});
|
|
226
|
-
fs.writeFileSync(
|
|
295
|
+
fs.writeFileSync(
|
|
296
|
+
path.join(dir, 'package.json'),
|
|
297
|
+
JSON.stringify({name, version: '1.0.0'}),
|
|
298
|
+
);
|
|
227
299
|
fs.writeFileSync(path.join(dir, 'astryx.integration.mjs'), body);
|
|
228
300
|
}
|
|
229
301
|
|
|
@@ -279,3 +351,54 @@ describe('the `debug` named export', () => {
|
|
|
279
351
|
expect(loaded.__unknownKeys).toEqual([]);
|
|
280
352
|
});
|
|
281
353
|
});
|
|
354
|
+
|
|
355
|
+
describe('the `gapReport` named export', () => {
|
|
356
|
+
it('loads a function handler without turning it into a manifest key', async () => {
|
|
357
|
+
writeManifestPackage(tmpDir, {
|
|
358
|
+
body:
|
|
359
|
+
`const handle = async report => ({status: 'filed', message: report.component});\n` +
|
|
360
|
+
`export const gapReport = {audience: 'public', handle};\n` +
|
|
361
|
+
`export default {issuesUrl: 'https://example.com/i'};\n`,
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
const [loaded] = await loadIntegrations(['@acme/widgets'], {cwd: tmpDir});
|
|
365
|
+
|
|
366
|
+
expect(loaded.__gapReport?.audience).toBe('public');
|
|
367
|
+
expect(typeof loaded.__gapReport?.handle).toBe('function');
|
|
368
|
+
await expect(
|
|
369
|
+
loaded.__gapReport?.handle(/** @type {any} */ ({component: 'Button'})),
|
|
370
|
+
).resolves.toEqual({
|
|
371
|
+
status: 'filed',
|
|
372
|
+
message: 'Button',
|
|
373
|
+
});
|
|
374
|
+
expect(loaded.__gapReportError).toBeUndefined();
|
|
375
|
+
expect(loaded.__unknownKeys).toEqual([]);
|
|
376
|
+
expect(loaded.issuesUrl).toBe('https://example.com/i');
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('isolates an invalid named handler from the default manifest', async () => {
|
|
380
|
+
writeManifestPackage(tmpDir, {
|
|
381
|
+
body:
|
|
382
|
+
`export const gapReport = {audience: 'internal', command: './report.mjs'};\n` +
|
|
383
|
+
`export default {issuesUrl: 'https://example.com/i'};\n`,
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
const [loaded] = await loadIntegrations(['@acme/widgets'], {cwd: tmpDir});
|
|
387
|
+
|
|
388
|
+
expect(loaded.__loadError).toBeUndefined();
|
|
389
|
+
expect(loaded.__gapReport).toBeUndefined();
|
|
390
|
+
expect(loaded.__gapReportError).toMatch(/gapReport/);
|
|
391
|
+
expect(loaded.issuesUrl).toBe('https://example.com/i');
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('keeps a same-named default-manifest field unknown instead of treating it as a handler', async () => {
|
|
395
|
+
writeManifestPackage(tmpDir, {
|
|
396
|
+
body: `export default {gapReport: {audience: 'public', handle: () => {}}};\n`,
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
const [loaded] = await loadIntegrations(['@acme/widgets'], {cwd: tmpDir});
|
|
400
|
+
|
|
401
|
+
expect(loaded.__gapReport).toBeUndefined();
|
|
402
|
+
expect(loaded.__unknownKeys).toEqual(['gapReport']);
|
|
403
|
+
});
|
|
404
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Find the one local integration manifest, or null when none exists.
|
|
6
|
+
* @param {string} packageDir
|
|
7
|
+
* @returns {string|null}
|
|
8
|
+
*/
|
|
9
|
+
export function findLocalIntegrationManifestOrNull(packageDir: string): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Find the one local integration manifest.
|
|
12
|
+
* @param {string} packageDir
|
|
13
|
+
* @returns {string}
|
|
14
|
+
*/
|
|
15
|
+
export function findLocalIntegrationManifest(packageDir: string): string;
|
|
16
|
+
/** @param {any} node */
|
|
17
|
+
export function unwrapManifestExpression(node: any): any;
|
|
18
|
+
/**
|
|
19
|
+
* Find the object literal an integration manifest exports.
|
|
20
|
+
* @param {ReturnType<typeof jscodeshift.withParser>} j
|
|
21
|
+
* @param {ReturnType<ReturnType<typeof jscodeshift.withParser>>} ast
|
|
22
|
+
* @returns {any|null}
|
|
23
|
+
*/
|
|
24
|
+
export function findManifestObject(j: ReturnType<typeof jscodeshift.withParser>, ast: ReturnType<ReturnType<typeof jscodeshift.withParser>>): any | null;
|
|
25
|
+
/**
|
|
26
|
+
* Add a contribution root to an integration manifest, creating the manifest
|
|
27
|
+
* when requested and none exists.
|
|
28
|
+
*
|
|
29
|
+
* If the key already has `rootPath`, this is an idempotent no-op. A different
|
|
30
|
+
* author-owned value is a typed refusal. `dryRun` performs every read and
|
|
31
|
+
* source-shape check but writes nothing. `createIfMissing` creates a minimal
|
|
32
|
+
* `.mjs` manifest as part of the same verified operation.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} packageDir
|
|
35
|
+
* @param {string} kind
|
|
36
|
+
* @param {string} rootPath
|
|
37
|
+
* @param {{dryRun?: boolean, verify?: () => void | Promise<void>, createIfMissing?: boolean}} [options]
|
|
38
|
+
* @returns {Promise<{path: string, created: boolean}>}
|
|
39
|
+
*/
|
|
40
|
+
export function patchIntegrationRoot(packageDir: string, kind: string, rootPath: string, { dryRun, verify, createIfMissing }?: {
|
|
41
|
+
dryRun?: boolean;
|
|
42
|
+
verify?: () => void | Promise<void>;
|
|
43
|
+
createIfMissing?: boolean;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
path: string;
|
|
46
|
+
created: boolean;
|
|
47
|
+
}>;
|
|
48
|
+
export class IntegrationRootConflictError extends Error {
|
|
49
|
+
/** @param {string} kind @param {string} current @param {string} requested */
|
|
50
|
+
constructor(kind: string, current: string, requested: string);
|
|
51
|
+
code: string;
|
|
52
|
+
kind: string;
|
|
53
|
+
current: string;
|
|
54
|
+
requested: string;
|
|
55
|
+
}
|
|
56
|
+
import jscodeshift from 'jscodeshift';
|