@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,795 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx integration pack --check` — verify an integration package is
|
|
5
|
+
* ready to publish by cross-referencing its declared contributions against the
|
|
6
|
+
* real npm tarball.
|
|
7
|
+
*
|
|
8
|
+
* Three phases:
|
|
9
|
+
* 1. Structure validation — reuses `validateLocalIntegration`.
|
|
10
|
+
* 2. Pack-list cross-reference — computes the static file inventory and
|
|
11
|
+
* compares it against the lifecycle-produced `npm pack --json` artifact.
|
|
12
|
+
* 3. Extracted-tarball validation — extracts the tarball into a scratch
|
|
13
|
+
* consumer under the author's node_modules and runs the same discovery
|
|
14
|
+
* functions a consumer uses, then compares identities (slugs, names,
|
|
15
|
+
* topic ids) exactly.
|
|
16
|
+
*
|
|
17
|
+
* Contract: every contribution visible in the author's package, and every
|
|
18
|
+
* file required to make it visible, must survive the real npm tarball and
|
|
19
|
+
* be equally visible from an extracted node_modules consumer view.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import * as fs from 'node:fs';
|
|
23
|
+
import * as path from 'node:path';
|
|
24
|
+
import * as os from 'node:os';
|
|
25
|
+
import {fileURLToPath} from 'node:url';
|
|
26
|
+
import {spawnSync} from 'node:child_process';
|
|
27
|
+
import jscodeshift from 'jscodeshift';
|
|
28
|
+
import {assertWithin} from '../../foundation/fs/path-safety.mjs';
|
|
29
|
+
import {resolvePackageDir} from '../../foundation/integrations/integrations.mjs';
|
|
30
|
+
import {
|
|
31
|
+
discoverIntegrationComponents,
|
|
32
|
+
resolveIntegrationImportPath,
|
|
33
|
+
} from '../../foundation/discovery/component-discovery.mjs';
|
|
34
|
+
import {loadComponentDoc} from '../../foundation/discovery/component-loader.mjs';
|
|
35
|
+
import {discoverIntegrationTemplatesForOne} from '../../foundation/discovery/template-adapter.mjs';
|
|
36
|
+
import {
|
|
37
|
+
validateLocalIntegration,
|
|
38
|
+
validateInstalledIntegration,
|
|
39
|
+
} from './validate-integration.mjs';
|
|
40
|
+
import {
|
|
41
|
+
computeRequiredFiles,
|
|
42
|
+
collectIdentities,
|
|
43
|
+
compareIdentities,
|
|
44
|
+
} from '../../foundation/integrations/contribution-inventory.mjs';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @typedef {import('../../foundation/integrations/issue').AstryxIntegrationIssue} Issue
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/** @param {string} code @param {string} message @returns {Issue} */
|
|
51
|
+
function error(code, message) {
|
|
52
|
+
return {code, severity: 'error', message};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** @param {string} code @param {string} message @returns {Issue} */
|
|
56
|
+
function warning(code, message) {
|
|
57
|
+
return {code, severity: 'warning', message};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Cleanup must never hide the check result or prevent the other temporary tree
|
|
62
|
+
* from being removed.
|
|
63
|
+
* @param {string|null} dir
|
|
64
|
+
* @param {string} label
|
|
65
|
+
* @param {Issue[]} issues
|
|
66
|
+
*/
|
|
67
|
+
function removeTreeBestEffort(dir, label, issues) {
|
|
68
|
+
if (dir == null) return;
|
|
69
|
+
try {
|
|
70
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
71
|
+
} catch (err) {
|
|
72
|
+
issues.push(
|
|
73
|
+
warning(
|
|
74
|
+
'cleanup_failed',
|
|
75
|
+
`Could not remove ${label} ${dir}: ${err instanceof Error ? err.message : String(err)}`,
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Find the nearest package.json starting from `cwd` and walking up.
|
|
83
|
+
* @param {string} cwd
|
|
84
|
+
* @returns {{packageDir: string, pkg: Record<string, unknown>}|null}
|
|
85
|
+
*/
|
|
86
|
+
function findPackage(cwd) {
|
|
87
|
+
let dir = path.resolve(cwd);
|
|
88
|
+
for (let depth = 0; depth < 50; depth++) {
|
|
89
|
+
const file = path.join(dir, 'package.json');
|
|
90
|
+
if (fs.existsSync(file)) {
|
|
91
|
+
try {
|
|
92
|
+
return {
|
|
93
|
+
packageDir: dir,
|
|
94
|
+
pkg: JSON.parse(fs.readFileSync(file, 'utf-8')),
|
|
95
|
+
};
|
|
96
|
+
} catch (err) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Could not parse ${file}: ${err instanceof Error ? err.message : String(err)}`,
|
|
99
|
+
{cause: err},
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const parent = path.dirname(dir);
|
|
104
|
+
if (parent === dir) break;
|
|
105
|
+
dir = parent;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Build the empty receipt returned when no integration manifest is found.
|
|
112
|
+
* @param {string|null} name
|
|
113
|
+
* @param {Issue[]} issues
|
|
114
|
+
* @returns {import('./pack-check.type.mjs').IntegrationPackCheckResponse}
|
|
115
|
+
*/
|
|
116
|
+
function emptyReceipt(name, issues) {
|
|
117
|
+
return {
|
|
118
|
+
type: 'integration.pack-check',
|
|
119
|
+
data: {
|
|
120
|
+
name,
|
|
121
|
+
version: null,
|
|
122
|
+
packable: !issues.some(i => i.severity === 'error'),
|
|
123
|
+
tarball: null,
|
|
124
|
+
inventory: {manifest: null, roots: [], expectedFiles: 0, packedFiles: 0},
|
|
125
|
+
contributions: {local: null, packed: null},
|
|
126
|
+
issues,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Parse npm's JSON pack result into the facts the checker needs.
|
|
133
|
+
* @param {string} output
|
|
134
|
+
* @returns {{filename: string, fileCount: number, size: number, unpackedSize: number, packedPaths: Set<string>}}
|
|
135
|
+
*/
|
|
136
|
+
export function parseNpmPackOutput(output) {
|
|
137
|
+
/** @type {Array<{filename: string, entryCount: number, size: number, unpackedSize: number, files?: Array<{path: string}>}>} */
|
|
138
|
+
let parsed;
|
|
139
|
+
try {
|
|
140
|
+
parsed = JSON.parse(output);
|
|
141
|
+
} catch {
|
|
142
|
+
throw new Error('npm pack produced unparseable JSON output.');
|
|
143
|
+
}
|
|
144
|
+
if (!Array.isArray(parsed) || parsed.length === 0) {
|
|
145
|
+
throw new Error('npm pack returned an empty result.');
|
|
146
|
+
}
|
|
147
|
+
const info = parsed[0];
|
|
148
|
+
if (!info || !Array.isArray(info.files)) {
|
|
149
|
+
throw new Error('npm pack returned a result without a files array.');
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
filename: info.filename,
|
|
153
|
+
fileCount: info.entryCount,
|
|
154
|
+
size: info.size,
|
|
155
|
+
unpackedSize: info.unpackedSize,
|
|
156
|
+
packedPaths: new Set(info.files.map(file => file.path)),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Run `npm pack --json` with output directed to `destDir` so no preexisting
|
|
162
|
+
* tgz is overwritten. This intentionally runs the package lifecycle, matching
|
|
163
|
+
* the artifact `npm publish` would produce. Uses spawnSync with an args array —
|
|
164
|
+
* no shell — so paths with metacharacters cannot inject.
|
|
165
|
+
*
|
|
166
|
+
* @param {string} packageDir
|
|
167
|
+
* @param {string} destDir
|
|
168
|
+
* @returns {{filename: string, fileCount: number, size: number, unpackedSize: number, packedPaths: Set<string>}}
|
|
169
|
+
*/
|
|
170
|
+
function runNpmPack(packageDir, destDir) {
|
|
171
|
+
const result = spawnSync(
|
|
172
|
+
'npm',
|
|
173
|
+
['pack', '--json', '--silent', `--pack-destination=${destDir}`],
|
|
174
|
+
{cwd: packageDir, encoding: 'utf-8', timeout: 60_000},
|
|
175
|
+
);
|
|
176
|
+
if (result.error) {
|
|
177
|
+
throw new Error(`Could not start npm pack: ${result.error.message}`);
|
|
178
|
+
}
|
|
179
|
+
if (result.status !== 0) {
|
|
180
|
+
const stderr = (result.stderr || '').trim();
|
|
181
|
+
throw new Error(
|
|
182
|
+
`npm pack failed (exit ${result.status})${stderr ? `: ${stderr}` : ''}.`,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
return parseNpmPackOutput(result.stdout);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Extract a tarball into `extractDir`, stripping the leading `package/`
|
|
190
|
+
* directory that npm tarballs wrap files in. Uses spawnSync with an args
|
|
191
|
+
* array — no shell.
|
|
192
|
+
*
|
|
193
|
+
* @param {string} tgzPath
|
|
194
|
+
* @param {string} extractDir
|
|
195
|
+
*/
|
|
196
|
+
function extractTarball(tgzPath, extractDir) {
|
|
197
|
+
fs.mkdirSync(extractDir, {recursive: true});
|
|
198
|
+
const result = spawnSync(
|
|
199
|
+
'tar',
|
|
200
|
+
['xzf', tgzPath, '-C', extractDir, '--strip-components=1'],
|
|
201
|
+
{encoding: 'utf-8', timeout: 30_000},
|
|
202
|
+
);
|
|
203
|
+
if (result.error) {
|
|
204
|
+
throw new Error(`Could not start tar extraction: ${result.error.message}`);
|
|
205
|
+
}
|
|
206
|
+
if (result.status !== 0) {
|
|
207
|
+
const stderr = (result.stderr || '').trim();
|
|
208
|
+
throw new Error(
|
|
209
|
+
`tar extraction failed (exit ${result.status})${stderr ? `: ${stderr}` : ''}.`,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const MODULE_EXTENSIONS = ['.mjs', '.js', '.mts', '.ts', '.tsx', '.jsx'];
|
|
215
|
+
const moduleParser = jscodeshift.withParser('tsx');
|
|
216
|
+
|
|
217
|
+
/** @param {unknown} specifier @param {string} fromFile */
|
|
218
|
+
function resolveLocalModule(specifier, fromFile) {
|
|
219
|
+
if (typeof specifier !== 'string' || !specifier.startsWith('.')) return null;
|
|
220
|
+
const base = path.resolve(path.dirname(fromFile), specifier);
|
|
221
|
+
const candidates = [
|
|
222
|
+
base,
|
|
223
|
+
...MODULE_EXTENSIONS.map(extension => `${base}${extension}`),
|
|
224
|
+
...MODULE_EXTENSIONS.map(extension => path.join(base, `index${extension}`)),
|
|
225
|
+
];
|
|
226
|
+
return candidates.find(candidate => fs.existsSync(candidate)) ?? null;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** @param {any} declaration @param {string} exportName */
|
|
230
|
+
function declarationExports(declaration, exportName) {
|
|
231
|
+
if (!declaration) return false;
|
|
232
|
+
if (['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type)) {
|
|
233
|
+
return declaration.id?.name === exportName;
|
|
234
|
+
}
|
|
235
|
+
if (declaration.type !== 'VariableDeclaration') return false;
|
|
236
|
+
return declaration.declarations.some(
|
|
237
|
+
(/** @type {any} */ item) =>
|
|
238
|
+
item.id?.type === 'Identifier' && item.id.name === exportName,
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Check one resolved module's static export surface without executing package
|
|
244
|
+
* code. Local ESM re-exports are followed recursively.
|
|
245
|
+
*
|
|
246
|
+
* @param {string} file
|
|
247
|
+
* @param {string} exportName
|
|
248
|
+
* @param {Set<string>} [seen]
|
|
249
|
+
*/
|
|
250
|
+
function moduleExportsName(file, exportName, seen = new Set()) {
|
|
251
|
+
const identity = `${file}\0${exportName}`;
|
|
252
|
+
if (seen.has(identity) || !fs.existsSync(file)) return false;
|
|
253
|
+
seen.add(identity);
|
|
254
|
+
|
|
255
|
+
let root;
|
|
256
|
+
try {
|
|
257
|
+
root = moduleParser(fs.readFileSync(file, 'utf-8'));
|
|
258
|
+
} catch {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
let found = false;
|
|
263
|
+
root
|
|
264
|
+
.find(moduleParser.ExportNamedDeclaration)
|
|
265
|
+
.forEach((/** @type {any} */ exportPath) => {
|
|
266
|
+
if (found) return;
|
|
267
|
+
const node = exportPath.node;
|
|
268
|
+
if (declarationExports(node.declaration, exportName)) {
|
|
269
|
+
found = true;
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
for (const specifier of node.specifiers ?? []) {
|
|
273
|
+
const exported = specifier.exported?.name ?? specifier.exported?.value;
|
|
274
|
+
if (exported !== exportName) continue;
|
|
275
|
+
if (!node.source) {
|
|
276
|
+
found = true;
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const target = resolveLocalModule(node.source.value, file);
|
|
280
|
+
const imported =
|
|
281
|
+
specifier.local?.name ?? specifier.local?.value ?? exportName;
|
|
282
|
+
if (target && moduleExportsName(target, imported, seen)) {
|
|
283
|
+
found = true;
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
if (found) return true;
|
|
289
|
+
if (
|
|
290
|
+
exportName === 'default' &&
|
|
291
|
+
root.find(moduleParser.ExportDefaultDeclaration).size() > 0
|
|
292
|
+
) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
root
|
|
297
|
+
.find(moduleParser.ExportAllDeclaration)
|
|
298
|
+
.forEach((/** @type {any} */ exportPath) => {
|
|
299
|
+
if (found) return;
|
|
300
|
+
const target = resolveLocalModule(exportPath.node.source?.value, file);
|
|
301
|
+
if (target && moduleExportsName(target, exportName, seen)) found = true;
|
|
302
|
+
});
|
|
303
|
+
return found;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Resolve package specifiers through Node's real ESM resolver from the scratch
|
|
308
|
+
* consumer. Resolution does not execute the target module, so source `.tsx`
|
|
309
|
+
* exports and built `.mjs` exports are both safe to inspect.
|
|
310
|
+
*
|
|
311
|
+
* @param {string[]} specifiers
|
|
312
|
+
* @param {string} scratchBase
|
|
313
|
+
* @returns {Map<string, {url?: string, error?: string}>}
|
|
314
|
+
*/
|
|
315
|
+
function resolveConsumerSpecifiers(specifiers, scratchBase) {
|
|
316
|
+
const resolver = path.join(scratchBase, '.astryx-resolve-imports.mjs');
|
|
317
|
+
const source = `const specs = JSON.parse(process.argv[2]);\nconst out = {};\nfor (const specifier of specs) {\n try { out[specifier] = {url: import.meta.resolve(specifier)}; }\n catch (error) { out[specifier] = {error: error instanceof Error ? error.message : String(error)}; }\n}\nconsole.log(JSON.stringify(out));\n`;
|
|
318
|
+
fs.writeFileSync(resolver, source, {flag: 'wx'});
|
|
319
|
+
try {
|
|
320
|
+
const result = spawnSync(
|
|
321
|
+
process.execPath,
|
|
322
|
+
[resolver, JSON.stringify([...new Set(specifiers)])],
|
|
323
|
+
{cwd: scratchBase, encoding: 'utf-8', timeout: 30_000},
|
|
324
|
+
);
|
|
325
|
+
if (result.error || result.status !== 0) {
|
|
326
|
+
const message = result.error?.message ?? result.stderr.trim();
|
|
327
|
+
return new Map(
|
|
328
|
+
specifiers.map(specifier => [
|
|
329
|
+
specifier,
|
|
330
|
+
{error: message || `resolver exited ${result.status}`},
|
|
331
|
+
]),
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
const parsed = JSON.parse(result.stdout);
|
|
335
|
+
return new Map(
|
|
336
|
+
/** @type {Array<[string, {url?: string, error?: string}]>} */ (
|
|
337
|
+
Object.entries(parsed)
|
|
338
|
+
),
|
|
339
|
+
);
|
|
340
|
+
} finally {
|
|
341
|
+
fs.rmSync(resolver, {force: true});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Verify that every packed component is reachable through the exact import
|
|
347
|
+
* specifier the component API gives consumers, and that the resolved module
|
|
348
|
+
* statically exports the component name.
|
|
349
|
+
*
|
|
350
|
+
* @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration} integration
|
|
351
|
+
* @param {string} scratchBase
|
|
352
|
+
* @returns {Promise<Issue[]>}
|
|
353
|
+
*/
|
|
354
|
+
async function validatePackedComponentExports(integration, scratchBase) {
|
|
355
|
+
const records = discoverIntegrationComponents(integration);
|
|
356
|
+
/** @type {Array<{name: string, specifier: string}>} */
|
|
357
|
+
const components = [];
|
|
358
|
+
for (const record of records) {
|
|
359
|
+
let docs;
|
|
360
|
+
try {
|
|
361
|
+
docs = await loadComponentDoc(record.docPath);
|
|
362
|
+
} catch {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
const specifier =
|
|
366
|
+
/** @type {{import?: string}} */ (docs).import ??
|
|
367
|
+
resolveIntegrationImportPath(
|
|
368
|
+
{
|
|
369
|
+
exportsMap: integration.__packageExports,
|
|
370
|
+
packageDir: integration.__packageDir,
|
|
371
|
+
docPath: record.docPath,
|
|
372
|
+
packageName: integration.name,
|
|
373
|
+
},
|
|
374
|
+
record.name,
|
|
375
|
+
);
|
|
376
|
+
components.push({name: record.name, specifier});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const resolved = resolveConsumerSpecifiers(
|
|
380
|
+
components.map(component => component.specifier),
|
|
381
|
+
scratchBase,
|
|
382
|
+
);
|
|
383
|
+
/** @type {Issue[]} */
|
|
384
|
+
const issues = [];
|
|
385
|
+
for (const {name, specifier} of components) {
|
|
386
|
+
const result = resolved.get(specifier);
|
|
387
|
+
if (!result?.url || result.error) {
|
|
388
|
+
issues.push(
|
|
389
|
+
error(
|
|
390
|
+
'component_import_unresolvable',
|
|
391
|
+
`Component "${name}" advertises import "${specifier}", but a consumer cannot resolve it${result?.error ? `: ${result.error}` : '.'}`,
|
|
392
|
+
),
|
|
393
|
+
);
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
let target;
|
|
397
|
+
try {
|
|
398
|
+
target = fileURLToPath(result.url);
|
|
399
|
+
} catch {
|
|
400
|
+
target = null;
|
|
401
|
+
}
|
|
402
|
+
if (!target || !moduleExportsName(target, name)) {
|
|
403
|
+
issues.push(
|
|
404
|
+
error(
|
|
405
|
+
'component_export_missing',
|
|
406
|
+
`Component "${name}" advertises import "${specifier}", but that packed module does not export "${name}". Add or correct the package export before publishing.`,
|
|
407
|
+
),
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return issues;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Verify that every packed template source can be imported through its exact
|
|
416
|
+
* package subpath and still has a default export.
|
|
417
|
+
*
|
|
418
|
+
* @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration} integration
|
|
419
|
+
* @param {string} scratchBase
|
|
420
|
+
* @returns {Promise<Issue[]>}
|
|
421
|
+
*/
|
|
422
|
+
async function validatePackedTemplateExports(integration, scratchBase) {
|
|
423
|
+
const {templates} = await discoverIntegrationTemplatesForOne(integration);
|
|
424
|
+
const entries = templates.map(template => ({
|
|
425
|
+
id: template.dirName,
|
|
426
|
+
specifier: `${integration.name}/${path
|
|
427
|
+
.relative(integration.__packageDir, template.filePath)
|
|
428
|
+
.split(path.sep)
|
|
429
|
+
.join('/')}`,
|
|
430
|
+
}));
|
|
431
|
+
const resolved = resolveConsumerSpecifiers(
|
|
432
|
+
entries.map(entry => entry.specifier),
|
|
433
|
+
scratchBase,
|
|
434
|
+
);
|
|
435
|
+
/** @type {Issue[]} */
|
|
436
|
+
const issues = [];
|
|
437
|
+
for (const {id, specifier} of entries) {
|
|
438
|
+
const result = resolved.get(specifier);
|
|
439
|
+
if (!result?.url || result.error) {
|
|
440
|
+
issues.push(
|
|
441
|
+
error(
|
|
442
|
+
'template_import_unresolvable',
|
|
443
|
+
`Template "${id}" source is packed but its public import "${specifier}" cannot be resolved${result?.error ? `: ${result.error}` : '.'}`,
|
|
444
|
+
),
|
|
445
|
+
);
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
let target;
|
|
449
|
+
try {
|
|
450
|
+
target = fileURLToPath(result.url);
|
|
451
|
+
} catch {
|
|
452
|
+
target = null;
|
|
453
|
+
}
|
|
454
|
+
if (!target || !moduleExportsName(target, 'default')) {
|
|
455
|
+
issues.push(
|
|
456
|
+
error(
|
|
457
|
+
'template_export_missing',
|
|
458
|
+
`Template "${id}" public import "${specifier}" does not have a default export.`,
|
|
459
|
+
),
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return issues;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Verify an integration package is ready to publish.
|
|
468
|
+
*
|
|
469
|
+
* Validates the local structure, cross-references every declared contribution
|
|
470
|
+
* file against the real `npm pack` file list, extracts the tarball into a
|
|
471
|
+
* scratch consumer, and compares local vs packed discovery results exactly.
|
|
472
|
+
*
|
|
473
|
+
* @param {import('./pack-check.type.mjs').IntegrationPackCheckOptions} [options]
|
|
474
|
+
* @returns {Promise<import('./pack-check.type.mjs').IntegrationPackCheckResponse>}
|
|
475
|
+
*/
|
|
476
|
+
export async function integrationPackCheck(options = {}) {
|
|
477
|
+
const {cwd = process.cwd()} = options;
|
|
478
|
+
|
|
479
|
+
// ── Locate the package ──
|
|
480
|
+
let found;
|
|
481
|
+
try {
|
|
482
|
+
found = findPackage(cwd);
|
|
483
|
+
} catch (err) {
|
|
484
|
+
return emptyReceipt(null, [
|
|
485
|
+
error(
|
|
486
|
+
'invalid_package_json',
|
|
487
|
+
err instanceof Error ? err.message : String(err),
|
|
488
|
+
),
|
|
489
|
+
]);
|
|
490
|
+
}
|
|
491
|
+
if (!found) {
|
|
492
|
+
return emptyReceipt(null, [
|
|
493
|
+
error(
|
|
494
|
+
'no_package',
|
|
495
|
+
'No package.json found. Run this command inside an integration package.',
|
|
496
|
+
),
|
|
497
|
+
]);
|
|
498
|
+
}
|
|
499
|
+
const {packageDir, pkg} = found;
|
|
500
|
+
const pkgName = typeof pkg.name === 'string' ? pkg.name : '(unnamed package)';
|
|
501
|
+
const pkgVersion = typeof pkg.version === 'string' ? pkg.version : null;
|
|
502
|
+
|
|
503
|
+
// ── Phase 1: structure validation ──
|
|
504
|
+
const localResult = await validateLocalIntegration(cwd);
|
|
505
|
+
/** @type {Issue[]} */
|
|
506
|
+
const issues = [...localResult.issues];
|
|
507
|
+
|
|
508
|
+
if (!localResult.found || !localResult.integration) {
|
|
509
|
+
return emptyReceipt(pkgName, [
|
|
510
|
+
...issues,
|
|
511
|
+
...(localResult.found
|
|
512
|
+
? []
|
|
513
|
+
: [
|
|
514
|
+
error(
|
|
515
|
+
'missing_manifest',
|
|
516
|
+
'No astryx.integration.{ts,mjs,js} found next to package.json.',
|
|
517
|
+
),
|
|
518
|
+
]),
|
|
519
|
+
]);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const loaded = localResult.integration;
|
|
523
|
+
|
|
524
|
+
// ── Phase 2: file inventory + npm pack ──
|
|
525
|
+
const fileInv = computeRequiredFiles(loaded);
|
|
526
|
+
const {identities: localIdentities, errors: localDiscoveryErrors} =
|
|
527
|
+
await collectIdentities(loaded);
|
|
528
|
+
for (const discoveryError of localDiscoveryErrors) {
|
|
529
|
+
issues.push(
|
|
530
|
+
error(
|
|
531
|
+
'local_discovery_failed',
|
|
532
|
+
`${discoveryError.kind}: ${discoveryError.message}`,
|
|
533
|
+
),
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
for (const root of fileInv.roots) {
|
|
537
|
+
if (root.files.length === 0) {
|
|
538
|
+
issues.push(
|
|
539
|
+
error(
|
|
540
|
+
'empty_contribution_root',
|
|
541
|
+
`Declared ${root.kind} root "${root.path}" contains no discoverable contribution files.`,
|
|
542
|
+
),
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Temp resources — always cleaned up
|
|
548
|
+
const tgzTmpDir = fs.mkdtempSync(
|
|
549
|
+
path.join(os.tmpdir(), 'astryx-pack-check-'),
|
|
550
|
+
);
|
|
551
|
+
/** @type {string|null} */
|
|
552
|
+
let scratchBase = null;
|
|
553
|
+
|
|
554
|
+
try {
|
|
555
|
+
// npm pack
|
|
556
|
+
/** @type {ReturnType<typeof runNpmPack>} */
|
|
557
|
+
let packResult;
|
|
558
|
+
try {
|
|
559
|
+
packResult = runNpmPack(packageDir, tgzTmpDir);
|
|
560
|
+
} catch (err) {
|
|
561
|
+
issues.push(error('pack_failed', /** @type {Error} */ (err).message));
|
|
562
|
+
return buildReceipt(
|
|
563
|
+
pkgName,
|
|
564
|
+
pkgVersion,
|
|
565
|
+
fileInv,
|
|
566
|
+
null,
|
|
567
|
+
localIdentities,
|
|
568
|
+
null,
|
|
569
|
+
issues,
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// Create the repo-local consumer AFTER packing, so it cannot enter the
|
|
574
|
+
// tarball. Keeping it beside the package lets packed metadata resolve the
|
|
575
|
+
// package's already-installed dependencies. The unique suffix makes
|
|
576
|
+
// concurrent checks independent.
|
|
577
|
+
scratchBase = fs.mkdtempSync(path.join(packageDir, '.astryx-pack-check-'));
|
|
578
|
+
|
|
579
|
+
// Cross-reference file inventory vs pack list
|
|
580
|
+
if (!packResult.packedPaths.has(fileInv.manifest)) {
|
|
581
|
+
issues.push(
|
|
582
|
+
error(
|
|
583
|
+
'manifest_not_packed',
|
|
584
|
+
`Integration manifest "${fileInv.manifest}" is not in the npm pack list. ` +
|
|
585
|
+
'Add it to "files" in package.json.',
|
|
586
|
+
),
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
for (const root of fileInv.roots) {
|
|
591
|
+
const missing = root.files.filter(f => !packResult.packedPaths.has(f));
|
|
592
|
+
if (missing.length === root.files.length && root.files.length > 0) {
|
|
593
|
+
issues.push(
|
|
594
|
+
error(
|
|
595
|
+
'root_not_packed',
|
|
596
|
+
`Declared ${root.kind} root "${root.path}" has 0 of ${root.files.length} expected ` +
|
|
597
|
+
`files in the pack list. Add "${root.path.replace(/^\.\//, '')}" to "files" in package.json.`,
|
|
598
|
+
),
|
|
599
|
+
);
|
|
600
|
+
} else {
|
|
601
|
+
for (const file of missing) {
|
|
602
|
+
issues.push(
|
|
603
|
+
error(
|
|
604
|
+
'file_not_packed',
|
|
605
|
+
`${root.kind} file "${file}" is not in the pack list.`,
|
|
606
|
+
),
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
let tgzPath;
|
|
613
|
+
try {
|
|
614
|
+
tgzPath = assertWithin(packResult.filename, tgzTmpDir, {
|
|
615
|
+
label: 'npm pack filename',
|
|
616
|
+
});
|
|
617
|
+
} catch (err) {
|
|
618
|
+
issues.push(
|
|
619
|
+
error(
|
|
620
|
+
'invalid_pack_result',
|
|
621
|
+
err instanceof Error ? err.message : String(err),
|
|
622
|
+
),
|
|
623
|
+
);
|
|
624
|
+
return buildReceipt(
|
|
625
|
+
pkgName,
|
|
626
|
+
pkgVersion,
|
|
627
|
+
fileInv,
|
|
628
|
+
packResult,
|
|
629
|
+
localIdentities,
|
|
630
|
+
null,
|
|
631
|
+
issues,
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// ── Phase 3: extract + identity comparison ──
|
|
636
|
+
let extractDir;
|
|
637
|
+
try {
|
|
638
|
+
extractDir = resolvePackageDir(pkgName, scratchBase);
|
|
639
|
+
} catch (err) {
|
|
640
|
+
issues.push(
|
|
641
|
+
error(
|
|
642
|
+
'invalid_package_name',
|
|
643
|
+
err instanceof Error ? err.message : String(err),
|
|
644
|
+
),
|
|
645
|
+
);
|
|
646
|
+
return buildReceipt(
|
|
647
|
+
pkgName,
|
|
648
|
+
pkgVersion,
|
|
649
|
+
fileInv,
|
|
650
|
+
packResult,
|
|
651
|
+
localIdentities,
|
|
652
|
+
null,
|
|
653
|
+
issues,
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
try {
|
|
657
|
+
extractTarball(tgzPath, extractDir);
|
|
658
|
+
} catch (err) {
|
|
659
|
+
issues.push(error('extract_failed', /** @type {Error} */ (err).message));
|
|
660
|
+
return buildReceipt(
|
|
661
|
+
pkgName,
|
|
662
|
+
pkgVersion,
|
|
663
|
+
fileInv,
|
|
664
|
+
packResult,
|
|
665
|
+
localIdentities,
|
|
666
|
+
null,
|
|
667
|
+
issues,
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// Validate the extracted tree as an installed integration
|
|
672
|
+
const packedResult = await validateInstalledIntegration(
|
|
673
|
+
pkgName,
|
|
674
|
+
scratchBase,
|
|
675
|
+
);
|
|
676
|
+
|
|
677
|
+
for (const issue of packedResult.issues) {
|
|
678
|
+
issues.push({
|
|
679
|
+
code: `packed_${issue.code}`,
|
|
680
|
+
severity: issue.severity,
|
|
681
|
+
message: `Packed: ${issue.message}`,
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
if (!packedResult.integration) {
|
|
686
|
+
return buildReceipt(
|
|
687
|
+
pkgName,
|
|
688
|
+
pkgVersion,
|
|
689
|
+
fileInv,
|
|
690
|
+
packResult,
|
|
691
|
+
localIdentities,
|
|
692
|
+
null,
|
|
693
|
+
issues,
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// Collect packed identities and compare
|
|
698
|
+
const {identities: packedIdentities, errors: discoveryErrors} =
|
|
699
|
+
await collectIdentities(packedResult.integration);
|
|
700
|
+
|
|
701
|
+
for (const de of discoveryErrors) {
|
|
702
|
+
issues.push(
|
|
703
|
+
error('packed_discovery_failed', `${de.kind}: ${de.message}`),
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
issues.push(...compareIdentities(localIdentities, packedIdentities));
|
|
708
|
+
issues.push(
|
|
709
|
+
...(await validatePackedComponentExports(
|
|
710
|
+
packedResult.integration,
|
|
711
|
+
scratchBase,
|
|
712
|
+
)),
|
|
713
|
+
...(await validatePackedTemplateExports(
|
|
714
|
+
packedResult.integration,
|
|
715
|
+
scratchBase,
|
|
716
|
+
)),
|
|
717
|
+
);
|
|
718
|
+
|
|
719
|
+
return buildReceipt(
|
|
720
|
+
pkgName,
|
|
721
|
+
pkgVersion,
|
|
722
|
+
fileInv,
|
|
723
|
+
packResult,
|
|
724
|
+
localIdentities,
|
|
725
|
+
packedIdentities,
|
|
726
|
+
issues,
|
|
727
|
+
);
|
|
728
|
+
} finally {
|
|
729
|
+
removeTreeBestEffort(tgzTmpDir, 'temporary tarball directory', issues);
|
|
730
|
+
removeTreeBestEffort(scratchBase, 'scratch consumer', issues);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Assemble the receipt.
|
|
736
|
+
* @param {string} name
|
|
737
|
+
* @param {string|null} version
|
|
738
|
+
* @param {import('../../foundation/integrations/contribution-inventory.mjs').FileInventory} fileInv
|
|
739
|
+
* @param {ReturnType<typeof runNpmPack>|null} packResult
|
|
740
|
+
* @param {import('../../foundation/integrations/contribution-inventory.mjs').ContributionIdentities|null} localIdentities
|
|
741
|
+
* @param {import('../../foundation/integrations/contribution-inventory.mjs').ContributionIdentities|null} packedIdentities
|
|
742
|
+
* @param {Issue[]} issues
|
|
743
|
+
* @returns {import('./pack-check.type.mjs').IntegrationPackCheckResponse}
|
|
744
|
+
*/
|
|
745
|
+
function buildReceipt(
|
|
746
|
+
name,
|
|
747
|
+
version,
|
|
748
|
+
fileInv,
|
|
749
|
+
packResult,
|
|
750
|
+
localIdentities,
|
|
751
|
+
packedIdentities,
|
|
752
|
+
issues,
|
|
753
|
+
) {
|
|
754
|
+
const packedPaths = packResult?.packedPaths ?? new Set();
|
|
755
|
+
|
|
756
|
+
/** @type {import('./pack-check.type.mjs').PackCheckInventoryRoot[]} */
|
|
757
|
+
const roots = fileInv.roots.map(root => {
|
|
758
|
+
const missing = root.files.filter(f => !packedPaths.has(f));
|
|
759
|
+
return {
|
|
760
|
+
kind: root.kind,
|
|
761
|
+
path: root.path,
|
|
762
|
+
expectedFiles: root.files.length,
|
|
763
|
+
missingFiles: missing,
|
|
764
|
+
complete: missing.length === 0,
|
|
765
|
+
};
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
const expectedFiles = fileInv.allFiles.length;
|
|
769
|
+
const packedFiles = fileInv.allFiles.filter(f => packedPaths.has(f)).length;
|
|
770
|
+
|
|
771
|
+
return {
|
|
772
|
+
type: 'integration.pack-check',
|
|
773
|
+
data: {
|
|
774
|
+
name,
|
|
775
|
+
version,
|
|
776
|
+
packable: !issues.some(i => i.severity === 'error'),
|
|
777
|
+
tarball: packResult
|
|
778
|
+
? {
|
|
779
|
+
filename: packResult.filename,
|
|
780
|
+
fileCount: packResult.fileCount,
|
|
781
|
+
size: packResult.size,
|
|
782
|
+
unpackedSize: packResult.unpackedSize,
|
|
783
|
+
}
|
|
784
|
+
: null,
|
|
785
|
+
inventory: {
|
|
786
|
+
manifest: fileInv.manifest,
|
|
787
|
+
roots,
|
|
788
|
+
expectedFiles,
|
|
789
|
+
packedFiles,
|
|
790
|
+
},
|
|
791
|
+
contributions: {local: localIdentities, packed: packedIdentities},
|
|
792
|
+
issues,
|
|
793
|
+
},
|
|
794
|
+
};
|
|
795
|
+
}
|