@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,430 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Colocated tests for autolink — loading an installed integration the
|
|
5
|
+
* config does not name.
|
|
6
|
+
*
|
|
7
|
+
* The fixtures are the shapes that actually exist in the projects this
|
|
8
|
+
* targets: a scaffold that added the dependency and wrote no config, an npm
|
|
9
|
+
* alias, a package mid-rename declared under both spellings, and a hoisted
|
|
10
|
+
* install. Temp dirs are repo-local because the loader dynamically imports the
|
|
11
|
+
* manifest and Vite refuses to import out of the OS temp dir.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
15
|
+
import * as fs from 'node:fs';
|
|
16
|
+
import * as path from 'node:path';
|
|
17
|
+
import {
|
|
18
|
+
DEPENDENCY_FIELDS,
|
|
19
|
+
autolinkIntegrations,
|
|
20
|
+
findAutolinkCandidates,
|
|
21
|
+
readDeclaredDependencies,
|
|
22
|
+
resolveInstalledPackageDir,
|
|
23
|
+
} from './autolink.mjs';
|
|
24
|
+
import {Project} from '../config/project.mjs';
|
|
25
|
+
|
|
26
|
+
let tmpDir;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-autolink-test-'));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Write a project package.json.
|
|
38
|
+
* @param {string} dir
|
|
39
|
+
* @param {object} fields
|
|
40
|
+
*/
|
|
41
|
+
function writeProject(dir, fields = {}) {
|
|
42
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
43
|
+
fs.writeFileSync(
|
|
44
|
+
path.join(dir, 'package.json'),
|
|
45
|
+
JSON.stringify({name: 'consumer', ...fields}),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Install a package under `<hostDir>/node_modules/<installAs>`.
|
|
51
|
+
*
|
|
52
|
+
* `installAs` is the directory (what an npm alias controls); `name` is the
|
|
53
|
+
* package's own identity, which is a different string exactly when the
|
|
54
|
+
* dependency is aliased.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} hostDir
|
|
57
|
+
* @param {object} options
|
|
58
|
+
* @returns {string} the installed package directory
|
|
59
|
+
*/
|
|
60
|
+
function installPackage(
|
|
61
|
+
hostDir,
|
|
62
|
+
{
|
|
63
|
+
installAs,
|
|
64
|
+
name = installAs,
|
|
65
|
+
version = '1.0.0',
|
|
66
|
+
manifest = {components: './components'},
|
|
67
|
+
manifestBasenames = ['astryx.integration.mjs'],
|
|
68
|
+
componentName = 'Widget',
|
|
69
|
+
} = {},
|
|
70
|
+
) {
|
|
71
|
+
const pkgDir = path.join(hostDir, 'node_modules', ...installAs.split('/'));
|
|
72
|
+
fs.mkdirSync(pkgDir, {recursive: true});
|
|
73
|
+
fs.writeFileSync(
|
|
74
|
+
path.join(pkgDir, 'package.json'),
|
|
75
|
+
JSON.stringify({name, version}),
|
|
76
|
+
);
|
|
77
|
+
for (const basename of manifestBasenames) {
|
|
78
|
+
fs.writeFileSync(
|
|
79
|
+
path.join(pkgDir, basename),
|
|
80
|
+
typeof manifest === 'string'
|
|
81
|
+
? manifest
|
|
82
|
+
: `export default ${JSON.stringify(manifest)};\n`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (manifest && typeof manifest === 'object' && manifest.components) {
|
|
86
|
+
const componentsDir = path.join(pkgDir, 'components');
|
|
87
|
+
fs.mkdirSync(componentsDir, {recursive: true});
|
|
88
|
+
fs.writeFileSync(
|
|
89
|
+
path.join(componentsDir, `${componentName}.doc.mjs`),
|
|
90
|
+
`export const docs = {name: '${componentName}', usage: {description: 'A widget'}};\n`,
|
|
91
|
+
);
|
|
92
|
+
fs.writeFileSync(
|
|
93
|
+
path.join(componentsDir, `${componentName}.tsx`),
|
|
94
|
+
`export function ${componentName}() { return null; }\n`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return pkgDir;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** @param {string} dir @param {string[]} integrations */
|
|
101
|
+
function writeConfig(dir, integrations) {
|
|
102
|
+
fs.writeFileSync(
|
|
103
|
+
path.join(dir, 'astryx.config.mjs'),
|
|
104
|
+
`export default ${JSON.stringify({integrations})};\n`,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
describe('readDeclaredDependencies', () => {
|
|
109
|
+
it('reads dependencies, devDependencies and optionalDependencies — not peerDependencies', () => {
|
|
110
|
+
writeProject(tmpDir, {
|
|
111
|
+
dependencies: {a: '1'},
|
|
112
|
+
devDependencies: {b: '1'},
|
|
113
|
+
optionalDependencies: {c: '1'},
|
|
114
|
+
peerDependencies: {d: '1'},
|
|
115
|
+
});
|
|
116
|
+
const declared = readDeclaredDependencies(tmpDir);
|
|
117
|
+
expect(declared.map(entry => entry.name)).toEqual(['a', 'b', 'c']);
|
|
118
|
+
expect(declared.map(entry => entry.field)).toEqual(DEPENDENCY_FIELDS);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('keeps the first field a name is declared in', () => {
|
|
122
|
+
writeProject(tmpDir, {
|
|
123
|
+
dependencies: {a: '1'},
|
|
124
|
+
devDependencies: {a: '2'},
|
|
125
|
+
});
|
|
126
|
+
expect(readDeclaredDependencies(tmpDir)).toEqual([
|
|
127
|
+
{name: 'a', field: 'dependencies'},
|
|
128
|
+
]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('refuses a key that is not a bare package name', () => {
|
|
132
|
+
writeProject(tmpDir, {
|
|
133
|
+
dependencies: {'../evil': '1', '/abs': '1', './rel': '1', ok: '1'},
|
|
134
|
+
});
|
|
135
|
+
expect(readDeclaredDependencies(tmpDir).map(e => e.name)).toEqual(['ok']);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('is empty when there is no readable package.json', () => {
|
|
139
|
+
expect(readDeclaredDependencies(tmpDir)).toEqual([]);
|
|
140
|
+
fs.writeFileSync(path.join(tmpDir, 'package.json'), '{not json');
|
|
141
|
+
expect(readDeclaredDependencies(tmpDir)).toEqual([]);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('resolveInstalledPackageDir', () => {
|
|
146
|
+
it('finds a package hoisted to a parent node_modules', () => {
|
|
147
|
+
const appDir = path.join(tmpDir, 'apps', 'web');
|
|
148
|
+
writeProject(appDir);
|
|
149
|
+
installPackage(tmpDir, {installAs: '@acme/widgets'});
|
|
150
|
+
const resolved = resolveInstalledPackageDir('@acme/widgets', appDir);
|
|
151
|
+
expect(resolved?.hostDir).toBe(tmpDir);
|
|
152
|
+
expect(resolved?.packageDir).toBe(
|
|
153
|
+
path.join(tmpDir, 'node_modules', '@acme', 'widgets'),
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('prefers the nearest node_modules', () => {
|
|
158
|
+
const appDir = path.join(tmpDir, 'apps', 'web');
|
|
159
|
+
writeProject(appDir);
|
|
160
|
+
installPackage(tmpDir, {installAs: '@acme/widgets'});
|
|
161
|
+
installPackage(appDir, {installAs: '@acme/widgets'});
|
|
162
|
+
expect(resolveInstalledPackageDir('@acme/widgets', appDir)?.hostDir).toBe(
|
|
163
|
+
appDir,
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('is null for a directory with no package.json', () => {
|
|
168
|
+
writeProject(tmpDir);
|
|
169
|
+
fs.mkdirSync(path.join(tmpDir, 'node_modules', 'empty'), {recursive: true});
|
|
170
|
+
expect(resolveInstalledPackageDir('empty', tmpDir)).toBeNull();
|
|
171
|
+
expect(resolveInstalledPackageDir('../escape', tmpDir)).toBeNull();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe('findAutolinkCandidates', () => {
|
|
176
|
+
it('probes declared dependencies only — never walks node_modules', () => {
|
|
177
|
+
writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
|
|
178
|
+
installPackage(tmpDir, {installAs: '@acme/widgets'});
|
|
179
|
+
installPackage(tmpDir, {installAs: '@acme/undeclared'});
|
|
180
|
+
|
|
181
|
+
const candidates = findAutolinkCandidates(tmpDir);
|
|
182
|
+
expect(candidates.map(candidate => candidate.spec)).toEqual([
|
|
183
|
+
'@acme/widgets',
|
|
184
|
+
]);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('ignores a transitive dependency that ships a manifest', () => {
|
|
188
|
+
writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
|
|
189
|
+
const pkgDir = installPackage(tmpDir, {installAs: '@acme/widgets'});
|
|
190
|
+
// @acme/widgets depends on @acme/inner; the project does not.
|
|
191
|
+
fs.writeFileSync(
|
|
192
|
+
path.join(pkgDir, 'package.json'),
|
|
193
|
+
JSON.stringify({
|
|
194
|
+
name: '@acme/widgets',
|
|
195
|
+
version: '1.0.0',
|
|
196
|
+
dependencies: {'@acme/inner': '^1.0.0'},
|
|
197
|
+
}),
|
|
198
|
+
);
|
|
199
|
+
installPackage(tmpDir, {installAs: '@acme/inner'});
|
|
200
|
+
|
|
201
|
+
expect(findAutolinkCandidates(tmpDir).map(c => c.spec)).toEqual([
|
|
202
|
+
'@acme/widgets',
|
|
203
|
+
]);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('skips a declared dependency with no manifest', () => {
|
|
207
|
+
writeProject(tmpDir, {dependencies: {react: '^19.0.0'}});
|
|
208
|
+
installPackage(tmpDir, {installAs: 'react', manifestBasenames: []});
|
|
209
|
+
expect(findAutolinkCandidates(tmpDir)).toEqual([]);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('skips a package with more than one root manifest instead of failing', () => {
|
|
213
|
+
writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
|
|
214
|
+
installPackage(tmpDir, {
|
|
215
|
+
installAs: '@acme/widgets',
|
|
216
|
+
manifestBasenames: ['astryx.integration.mjs', 'astryx.integration.js'],
|
|
217
|
+
});
|
|
218
|
+
expect(findAutolinkCandidates(tmpDir)).toEqual([]);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('collapses two dependency keys that link to one package directory', () => {
|
|
222
|
+
// pnpm links every dependency from one store entry, so the two spellings of
|
|
223
|
+
// a package mid-rename share a real path.
|
|
224
|
+
writeProject(tmpDir, {
|
|
225
|
+
dependencies: {'@acme/legacy-ui': '^0.5.0', '@acme/ui': '^0.1.0'},
|
|
226
|
+
});
|
|
227
|
+
const real = installPackage(tmpDir, {
|
|
228
|
+
installAs: '@acme/ui',
|
|
229
|
+
name: '@acme/ui',
|
|
230
|
+
version: '0.1.22',
|
|
231
|
+
});
|
|
232
|
+
const linkDir = path.join(tmpDir, 'node_modules', '@acme');
|
|
233
|
+
fs.mkdirSync(linkDir, {recursive: true});
|
|
234
|
+
fs.symlinkSync(real, path.join(linkDir, 'legacy-ui'), 'dir');
|
|
235
|
+
|
|
236
|
+
const candidates = findAutolinkCandidates(tmpDir);
|
|
237
|
+
expect(candidates).toHaveLength(1);
|
|
238
|
+
expect(candidates[0].spec).toBe('@acme/legacy-ui');
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('excludes package directories already loaded', () => {
|
|
242
|
+
writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
|
|
243
|
+
const pkgDir = installPackage(tmpDir, {installAs: '@acme/widgets'});
|
|
244
|
+
expect(findAutolinkCandidates(tmpDir, {exclude: [pkgDir]})).toEqual([]);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe('autolinkIntegrations', () => {
|
|
249
|
+
it('loads a declared dependency that ships a manifest, and marks it', async () => {
|
|
250
|
+
writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
|
|
251
|
+
installPackage(tmpDir, {installAs: '@acme/widgets'});
|
|
252
|
+
|
|
253
|
+
const [integration, ...rest] = await autolinkIntegrations({
|
|
254
|
+
projectDir: tmpDir,
|
|
255
|
+
});
|
|
256
|
+
expect(rest).toEqual([]);
|
|
257
|
+
expect(integration.name).toBe('@acme/widgets');
|
|
258
|
+
expect(integration.__autolinked).toBe(true);
|
|
259
|
+
expect(integration.__dependencyField).toBe('dependencies');
|
|
260
|
+
expect(integration.components).toBe(
|
|
261
|
+
path.join(tmpDir, 'node_modules', '@acme', 'widgets', 'components'),
|
|
262
|
+
);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('reads the dependency KEY, never the value', async () => {
|
|
266
|
+
// Every one of these is a real installed shape and none is a semver range.
|
|
267
|
+
writeProject(tmpDir, {
|
|
268
|
+
dependencies: {
|
|
269
|
+
'@acme/legacy-ui': 'npm:@acme/ui@0.1.22',
|
|
270
|
+
'@acme/linked': 'link:../linked',
|
|
271
|
+
'@acme/filed': 'file:../filed',
|
|
272
|
+
},
|
|
273
|
+
devDependencies: {
|
|
274
|
+
'@acme/workspaced': 'workspace:*',
|
|
275
|
+
'@acme/cataloged': 'catalog:',
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
// The aliased key installs a package whose own name is the aliased one.
|
|
279
|
+
installPackage(tmpDir, {
|
|
280
|
+
installAs: '@acme/legacy-ui',
|
|
281
|
+
name: '@acme/ui',
|
|
282
|
+
version: '0.1.22',
|
|
283
|
+
});
|
|
284
|
+
for (const installAs of [
|
|
285
|
+
'@acme/linked',
|
|
286
|
+
'@acme/filed',
|
|
287
|
+
'@acme/workspaced',
|
|
288
|
+
'@acme/cataloged',
|
|
289
|
+
]) {
|
|
290
|
+
installPackage(tmpDir, {installAs});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const loaded = await autolinkIntegrations({projectDir: tmpDir});
|
|
294
|
+
expect(loaded.map(i => i.name)).toEqual([
|
|
295
|
+
// Identity is the resolved package's own name, not the key it is under.
|
|
296
|
+
'@acme/ui',
|
|
297
|
+
'@acme/linked',
|
|
298
|
+
'@acme/filed',
|
|
299
|
+
'@acme/workspaced',
|
|
300
|
+
'@acme/cataloged',
|
|
301
|
+
]);
|
|
302
|
+
const aliased = loaded[0];
|
|
303
|
+
expect(aliased.__spec).toBe('@acme/legacy-ui');
|
|
304
|
+
expect(aliased.version).toBe('0.1.22');
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('loads one integration when both spellings of a rename are installed', async () => {
|
|
308
|
+
// Mid-rename, with two directories on disk rather than one linked store
|
|
309
|
+
// entry: the package name is the identity that collapses them.
|
|
310
|
+
writeProject(tmpDir, {
|
|
311
|
+
dependencies: {'@acme/legacy-ui': '^0.5.0', '@acme/ui': '^0.1.0'},
|
|
312
|
+
});
|
|
313
|
+
installPackage(tmpDir, {
|
|
314
|
+
installAs: '@acme/legacy-ui',
|
|
315
|
+
name: '@acme/ui',
|
|
316
|
+
version: '0.1.22',
|
|
317
|
+
});
|
|
318
|
+
installPackage(tmpDir, {
|
|
319
|
+
installAs: '@acme/ui',
|
|
320
|
+
name: '@acme/ui',
|
|
321
|
+
version: '0.1.22',
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
const loaded = await autolinkIntegrations({projectDir: tmpDir});
|
|
325
|
+
expect(loaded).toHaveLength(1);
|
|
326
|
+
expect(loaded[0].name).toBe('@acme/ui');
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('does not load one already loaded from config', async () => {
|
|
330
|
+
writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
|
|
331
|
+
const pkgDir = installPackage(tmpDir, {installAs: '@acme/widgets'});
|
|
332
|
+
const loaded = await autolinkIntegrations({
|
|
333
|
+
projectDir: tmpDir,
|
|
334
|
+
loaded: [
|
|
335
|
+
/** @type {any} */ ({name: '@acme/widgets', __packageDir: pkgDir}),
|
|
336
|
+
],
|
|
337
|
+
});
|
|
338
|
+
expect(loaded).toEqual([]);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('drops a dependency whose manifest is broken, and raises no issue for it', async () => {
|
|
342
|
+
// The project cannot fix a dependency's packaging bug, so autolink must not
|
|
343
|
+
// hand it one to look at. Both failure modes: a manifest that throws on
|
|
344
|
+
// import, and one that loads but fails schema validation.
|
|
345
|
+
writeProject(tmpDir, {
|
|
346
|
+
dependencies: {
|
|
347
|
+
'@acme/throws': '^1.0.0',
|
|
348
|
+
'@acme/invalid': '^1.0.0',
|
|
349
|
+
'@acme/widgets': '^1.0.0',
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
installPackage(tmpDir, {
|
|
353
|
+
installAs: '@acme/throws',
|
|
354
|
+
manifest: 'throw new Error("boom");\n',
|
|
355
|
+
});
|
|
356
|
+
installPackage(tmpDir, {
|
|
357
|
+
installAs: '@acme/invalid',
|
|
358
|
+
manifest: {components: 42},
|
|
359
|
+
});
|
|
360
|
+
installPackage(tmpDir, {installAs: '@acme/widgets'});
|
|
361
|
+
|
|
362
|
+
const loaded = await autolinkIntegrations({projectDir: tmpDir});
|
|
363
|
+
expect(loaded.map(i => i.name)).toEqual(['@acme/widgets']);
|
|
364
|
+
|
|
365
|
+
const project = await Project.load(tmpDir);
|
|
366
|
+
expect(await project.issues()).toEqual([]);
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
describe('Project.load with autolink', () => {
|
|
371
|
+
it('discovers components from an installed integration with no config at all', async () => {
|
|
372
|
+
// The population this exists for: the scaffold added the dependency and
|
|
373
|
+
// wrote no astryx.config, so the CLI used to report the component missing.
|
|
374
|
+
writeProject(tmpDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
|
|
375
|
+
installPackage(tmpDir, {
|
|
376
|
+
installAs: '@acme/widgets',
|
|
377
|
+
componentName: 'MetaOncall',
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
const project = await Project.load(tmpDir);
|
|
381
|
+
expect(project.configPath).toBeNull();
|
|
382
|
+
expect(project.integrations).toEqual([]);
|
|
383
|
+
expect(project.loadedIntegrations.map(i => i.name)).toEqual([
|
|
384
|
+
'@acme/widgets',
|
|
385
|
+
]);
|
|
386
|
+
const components = await project.components();
|
|
387
|
+
expect(components.map(component => component.name)).toContain('MetaOncall');
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it('keeps a configured integration explicit and puts autolinked ones after it', async () => {
|
|
391
|
+
writeProject(tmpDir, {
|
|
392
|
+
dependencies: {'@acme/widgets': '^1.0.0', '@acme/extras': '^1.0.0'},
|
|
393
|
+
});
|
|
394
|
+
writeConfig(tmpDir, ['@acme/widgets']);
|
|
395
|
+
installPackage(tmpDir, {installAs: '@acme/widgets'});
|
|
396
|
+
installPackage(tmpDir, {
|
|
397
|
+
installAs: '@acme/extras',
|
|
398
|
+
componentName: 'Extra',
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
const project = await Project.load(tmpDir);
|
|
402
|
+
expect(project.integrations).toEqual(['@acme/widgets']);
|
|
403
|
+
expect(
|
|
404
|
+
project.loadedIntegrations.map(i => [i.name, i.__autolinked ?? false]),
|
|
405
|
+
).toEqual([
|
|
406
|
+
['@acme/widgets', false],
|
|
407
|
+
['@acme/extras', true],
|
|
408
|
+
]);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it('resolves a dependency hoisted to a workspace root', async () => {
|
|
412
|
+
const appDir = path.join(tmpDir, 'apps', 'web');
|
|
413
|
+
writeProject(appDir, {dependencies: {'@acme/widgets': '^1.0.0'}});
|
|
414
|
+
installPackage(tmpDir, {installAs: '@acme/widgets'});
|
|
415
|
+
|
|
416
|
+
const project = await Project.load(appDir);
|
|
417
|
+
expect(project.loadedIntegrations.map(i => i.name)).toEqual([
|
|
418
|
+
'@acme/widgets',
|
|
419
|
+
]);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it('leaves a project with no astryx dependencies untouched', async () => {
|
|
423
|
+
writeProject(tmpDir, {dependencies: {react: '^19.0.0'}});
|
|
424
|
+
installPackage(tmpDir, {installAs: 'react', manifestBasenames: []});
|
|
425
|
+
|
|
426
|
+
const project = await Project.load(tmpDir);
|
|
427
|
+
expect(project.loadedIntegrations).toEqual([]);
|
|
428
|
+
expect(await project.issues()).toEqual([]);
|
|
429
|
+
});
|
|
430
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
* @typedef {object} FileInventoryRoot
|
|
6
|
+
* @property {'themes'|'components'|'templates'|'codemods'|'docs'} kind
|
|
7
|
+
* @property {string} path — project-relative root path
|
|
8
|
+
* @property {string[]} files — project-relative required file paths
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {object} FileInventory
|
|
12
|
+
* @property {string} manifest — project-relative manifest path
|
|
13
|
+
* @property {FileInventoryRoot[]} roots
|
|
14
|
+
* @property {string[]} allFiles — deduplicated flat list
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Compute the files the tarball must contain for an integration's
|
|
18
|
+
* contributions to be visible. Reads catalogs and walks directories;
|
|
19
|
+
* never imports or executes authored modules.
|
|
20
|
+
*
|
|
21
|
+
* @param {import('./integrations.mjs').LoadedIntegration} loaded
|
|
22
|
+
* @returns {FileInventory}
|
|
23
|
+
*/
|
|
24
|
+
export function computeRequiredFiles(loaded: import("./integrations.mjs").LoadedIntegration): FileInventory;
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {object} ContributionIdentities
|
|
27
|
+
* @property {{slug: string, exportName: string}[]} themes
|
|
28
|
+
* @property {string[]} components
|
|
29
|
+
* @property {{id: string, type: string, name: string}[]} templates
|
|
30
|
+
* @property {{version: string, id: string}[]} codemods
|
|
31
|
+
* @property {string[]} docs
|
|
32
|
+
* @property {string[]} agentDocsAppend
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* The resolved fields needed to discover contribution identities.
|
|
36
|
+
* @typedef {object} IdentitySource
|
|
37
|
+
* @property {string} name
|
|
38
|
+
* @property {string} [themes]
|
|
39
|
+
* @property {string} [components]
|
|
40
|
+
* @property {string} [templates]
|
|
41
|
+
* @property {string} [codemods]
|
|
42
|
+
* @property {string} [docs]
|
|
43
|
+
* @property {{append?: readonly string[]}} [agentDocs]
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* Run the same discovery functions a consumer uses to collect every
|
|
47
|
+
* contribution identity from a loaded integration.
|
|
48
|
+
*
|
|
49
|
+
* @param {IdentitySource} loaded
|
|
50
|
+
* @returns {Promise<{identities: ContributionIdentities, errors: Array<{kind: string, message: string}>}>}
|
|
51
|
+
*/
|
|
52
|
+
export function collectIdentities(loaded: IdentitySource): Promise<{
|
|
53
|
+
identities: ContributionIdentities;
|
|
54
|
+
errors: Array<{
|
|
55
|
+
kind: string;
|
|
56
|
+
message: string;
|
|
57
|
+
}>;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Prove that one contribution is visible through the same inventory seam the
|
|
61
|
+
* packed-package checker uses. This is the shared postcondition for every add
|
|
62
|
+
* handler, not a second set of per-writer rules.
|
|
63
|
+
*
|
|
64
|
+
* @param {IdentitySource} loaded
|
|
65
|
+
* @param {'theme'|'component'|'template'|'codemod'|'doc'|'agent-doc'} kind
|
|
66
|
+
* @param {string} name
|
|
67
|
+
* @param {{version?: string}} [options]
|
|
68
|
+
* @returns {Promise<void>}
|
|
69
|
+
*/
|
|
70
|
+
export function assertContributionVisible(loaded: IdentitySource, kind: "theme" | "component" | "template" | "codemod" | "doc" | "agent-doc", name: string, { version }?: {
|
|
71
|
+
version?: string;
|
|
72
|
+
}): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* @typedef {import('./issue').AstryxIntegrationIssue} Issue
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* Compare local and packed identities. Anything discoverable locally but
|
|
78
|
+
* missing from the packed tarball is an error.
|
|
79
|
+
*
|
|
80
|
+
* @param {ContributionIdentities} local
|
|
81
|
+
* @param {ContributionIdentities} packed
|
|
82
|
+
* @returns {Issue[]}
|
|
83
|
+
*/
|
|
84
|
+
export function compareIdentities(local: ContributionIdentities, packed: ContributionIdentities): Issue[];
|
|
85
|
+
/**
|
|
86
|
+
* Find top-level PascalCase `.tsx` files under a components root that are
|
|
87
|
+
* NOT registered as integration components. These are candidates that
|
|
88
|
+
* Astryx will ignore — surfaced as a warning so the author knows.
|
|
89
|
+
*
|
|
90
|
+
* Scans only direct children of the root (not recursive) and never
|
|
91
|
+
* enters node_modules.
|
|
92
|
+
*
|
|
93
|
+
* @param {string|undefined} componentsRoot absolute path
|
|
94
|
+
* @param {string[]} registeredNames names already returned by discovery
|
|
95
|
+
* @returns {string[]} unregistered PascalCase names
|
|
96
|
+
*/
|
|
97
|
+
export function findSourceOnlyCandidates(componentsRoot: string | undefined, registeredNames: string[]): string[];
|
|
98
|
+
export type FileInventoryRoot = {
|
|
99
|
+
kind: "themes" | "components" | "templates" | "codemods" | "docs";
|
|
100
|
+
/**
|
|
101
|
+
* — project-relative root path
|
|
102
|
+
*/
|
|
103
|
+
path: string;
|
|
104
|
+
/**
|
|
105
|
+
* — project-relative required file paths
|
|
106
|
+
*/
|
|
107
|
+
files: string[];
|
|
108
|
+
};
|
|
109
|
+
export type FileInventory = {
|
|
110
|
+
/**
|
|
111
|
+
* — project-relative manifest path
|
|
112
|
+
*/
|
|
113
|
+
manifest: string;
|
|
114
|
+
roots: FileInventoryRoot[];
|
|
115
|
+
/**
|
|
116
|
+
* — deduplicated flat list
|
|
117
|
+
*/
|
|
118
|
+
allFiles: string[];
|
|
119
|
+
};
|
|
120
|
+
export type ContributionIdentities = {
|
|
121
|
+
themes: {
|
|
122
|
+
slug: string;
|
|
123
|
+
exportName: string;
|
|
124
|
+
}[];
|
|
125
|
+
components: string[];
|
|
126
|
+
templates: {
|
|
127
|
+
id: string;
|
|
128
|
+
type: string;
|
|
129
|
+
name: string;
|
|
130
|
+
}[];
|
|
131
|
+
codemods: {
|
|
132
|
+
version: string;
|
|
133
|
+
id: string;
|
|
134
|
+
}[];
|
|
135
|
+
docs: string[];
|
|
136
|
+
agentDocsAppend: string[];
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* The resolved fields needed to discover contribution identities.
|
|
140
|
+
*/
|
|
141
|
+
export type IdentitySource = {
|
|
142
|
+
name: string;
|
|
143
|
+
themes?: string | undefined;
|
|
144
|
+
components?: string | undefined;
|
|
145
|
+
templates?: string | undefined;
|
|
146
|
+
codemods?: string | undefined;
|
|
147
|
+
docs?: string | undefined;
|
|
148
|
+
agentDocs?: {
|
|
149
|
+
append?: readonly string[];
|
|
150
|
+
} | undefined;
|
|
151
|
+
};
|
|
152
|
+
export type Issue = import("./issue").AstryxIntegrationIssue;
|