@astryxdesign/cli 0.7.0-canary.4ec1f4e → 0.7.0-canary.5777977
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -61
- package/api/build/build.mjs +9 -0
- package/api/component/_adapter.d.mts +2 -0
- package/api/component/_adapter.mjs +3 -1
- package/api/component/component.doc.mjs +5 -1
- package/api/docs/compiled-topics.test.mjs +16 -0
- package/api/integration/pack-check.test.mjs +8 -0
- package/api/template/list/list.mjs +23 -2
- package/api/template/list/list.test.mjs +52 -0
- package/api/template/template.doc.mjs +5 -4
- package/api/template/template.type.mjs +1 -1
- package/api/theme/build/build.d.mts +0 -1
- package/api/theme/build/build.mjs +4 -29
- package/api/theme/build/family.mjs +1 -1
- package/assets/codemods/transforms/next/__tests__/validate-data-token-ownership.test.mjs +84 -0
- package/assets/codemods/transforms/next/index.mjs +8 -0
- package/assets/codemods/transforms/next/validate-data-token-ownership.mjs +102 -0
- package/assets/docs/author-a-theme.doc.mjs +4 -4
- package/assets/docs/tree/tokens-data.doc.mjs +2 -2
- package/assets/docs/tree/tokens-usage.doc.mjs +1 -1
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorDeadlinePicker.tsx +1 -1
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorShowcase.tsx +1 -1
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorTreeSearch.tsx +1 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorClearable.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +2 -2
- package/assets/templates/blocks/components/Selector/SelectorShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorWithSections.tsx +1 -1
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionBasic.tsx +1 -1
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderFormattedValue.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderRangeSlider.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderWithMarks.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +4 -4
- package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +1 -1
- package/assets/templates/pages/canvas-editor/page.tsx +2 -2
- package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
- package/assets/templates/pages/payment-form/page.tsx +1 -1
- package/assets/templates/pages/table-filter/page.tsx +3 -3
- package/assets/templates/pages/theme-showcase/page.tsx +2 -2
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +10 -9
- package/clients/cli/commands/build-theme.color-scheme.test.mjs +10 -6
- package/clients/cli/commands/build-theme.data-tokens.test.mjs +23 -75
- package/clients/cli/commands/build.doc.mjs +1 -1
- package/clients/cli/commands/build.mjs +1 -1
- package/clients/cli/commands/component-ownership.test.mjs +2 -2
- package/clients/cli/commands/integration.mjs +2 -1
- package/clients/cli/commands/silent-success-refusals.test.mjs +15 -0
- package/clients/cli/commands/template.doc.mjs +1 -1
- package/foundation/discovery/template-needs.mjs +93 -11
- package/foundation/discovery/template-needs.test.mjs +106 -3
- package/foundation/env/package-manager.d.mts +13 -0
- package/foundation/env/package-manager.mjs +106 -63
- package/foundation/response/response-types.doc.mjs +1 -2
- package/package.json +9 -9
|
@@ -231,7 +231,7 @@ export default function ToolbarTableFilter() {
|
|
|
231
231
|
hasClear
|
|
232
232
|
options={field.options}
|
|
233
233
|
value={clauses[field.key] ?? null}
|
|
234
|
-
|
|
234
|
+
controlXstyle={clauses[field.key] != null ? styles.filterFill : undefined}
|
|
235
235
|
onChange={value => setClauses(prev => ({...prev, [field.key]: value}))}
|
|
236
236
|
renderValue={option =>
|
|
237
237
|
`${field.label} is ${option.label ?? option.value}`
|
|
@@ -1153,7 +1153,7 @@ function FilterRow({
|
|
|
1153
1153
|
value={value}
|
|
1154
1154
|
onChange={onChange}
|
|
1155
1155
|
isWheelEnabled={false}
|
|
1156
|
-
|
|
1156
|
+
controlXstyle={styles.filterValue}
|
|
1157
1157
|
/>
|
|
1158
1158
|
</InspectorRow>
|
|
1159
1159
|
);
|
|
@@ -2329,7 +2329,7 @@ export default function CanvasEditor() {
|
|
|
2329
2329
|
// enough for the longest option
|
|
2330
2330
|
// ("100%") to avoid truncation.
|
|
2331
2331
|
width={92}
|
|
2332
|
-
|
|
2332
|
+
controlXstyle={[
|
|
2333
2333
|
styles.toolBarControl,
|
|
2334
2334
|
styles.toolBarTrailing,
|
|
2335
2335
|
]}
|
|
@@ -871,7 +871,7 @@ export default function FormWizardVerticalPage() {
|
|
|
871
871
|
ref={fieldRefs.cover}
|
|
872
872
|
label="Cover image"
|
|
873
873
|
isLabelHidden
|
|
874
|
-
|
|
874
|
+
controlStyle={hasCover ? dropzoneFill : undefined}
|
|
875
875
|
mode="dropzone"
|
|
876
876
|
accept="image/png,image/jpeg"
|
|
877
877
|
maxSize={5 * 1024 * 1024}
|
|
@@ -3249,7 +3249,7 @@ export default function TableFilterTemplate() {
|
|
|
3249
3249
|
renderValue={option =>
|
|
3250
3250
|
`${field.label} ${field.operatorLabel} ${option.label ?? option.value}`
|
|
3251
3251
|
}
|
|
3252
|
-
|
|
3252
|
+
controlXstyle={active ? styles.filterFill : undefined}
|
|
3253
3253
|
onChange={next =>
|
|
3254
3254
|
setFieldFilter(
|
|
3255
3255
|
field.key,
|
|
@@ -3318,7 +3318,7 @@ export default function TableFilterTemplate() {
|
|
|
3318
3318
|
}
|
|
3319
3319
|
options={[...field.options]}
|
|
3320
3320
|
value={multiValues[field.key]}
|
|
3321
|
-
|
|
3321
|
+
controlXstyle={
|
|
3322
3322
|
multiValues[field.key].length > 0 ? styles.filterFill : undefined
|
|
3323
3323
|
}
|
|
3324
3324
|
onChange={next => setMultiValues(field.key, next)}
|
|
@@ -3341,7 +3341,7 @@ export default function TableFilterTemplate() {
|
|
|
3341
3341
|
value={quoteDraft}
|
|
3342
3342
|
onChange={commitQuote}
|
|
3343
3343
|
contentXstyle={styles.quotePopover}
|
|
3344
|
-
|
|
3344
|
+
controlXstyle={hasQuoteFilter ? styles.filterFill : undefined}>
|
|
3345
3345
|
{(range, onChange, close) => (
|
|
3346
3346
|
<VStack gap={4}>
|
|
3347
3347
|
<VStack gap={0}>
|
|
@@ -500,7 +500,7 @@ function StorePreview({
|
|
|
500
500
|
max={99}
|
|
501
501
|
size="sm"
|
|
502
502
|
width={72}
|
|
503
|
-
|
|
503
|
+
controlStyle={styles.quantityInput}
|
|
504
504
|
/>
|
|
505
505
|
<Button
|
|
506
506
|
label="Add to cart"
|
|
@@ -1143,7 +1143,7 @@ function InventoryCard({
|
|
|
1143
1143
|
value=""
|
|
1144
1144
|
onChange={() => {}}
|
|
1145
1145
|
startIcon={<Search size={16} />}
|
|
1146
|
-
|
|
1146
|
+
controlStyle={styles.searchInput}
|
|
1147
1147
|
/>
|
|
1148
1148
|
<OverflowList
|
|
1149
1149
|
gap={2}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
|
-
// Generated from
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// Generated from the committed full palette for the stops used by Neutral's
|
|
4
|
+
// theme source. Regenerate with `pnpm generate:neutral-palette-refs`.
|
|
5
|
+
// Keep the complete palette available for authoring and audits without
|
|
6
|
+
// making consumers pay for unused palette stops.
|
|
6
7
|
// prettier-ignore
|
|
7
8
|
export const neutralPaletteRefs = {
|
|
8
9
|
purple: {
|
|
@@ -10,11 +11,11 @@ export const neutralPaletteRefs = {
|
|
|
10
11
|
dark: {25: '#4a2f51', 80: '#eaacf8'},
|
|
11
12
|
},
|
|
12
13
|
green: {
|
|
13
|
-
light: {25: '#00490b', 30: '#0b5615',
|
|
14
|
+
light: {25: '#00490b', 30: '#0b5615', 45: '#2f7d33', 65: '#6ab26b', 75: '#90ca90', 80: '#a4d6a3'},
|
|
14
15
|
dark: {25: '#2b422b', 80: '#aad4a9', 85: '#bce0bb'},
|
|
15
16
|
},
|
|
16
17
|
neutral: {
|
|
17
|
-
light: {0: '#000000', 5: '#111111', 10: '#1b1b1b',
|
|
18
|
+
light: {0: '#000000', 5: '#111111', 10: '#1b1b1b', 30: '#474747', 45: '#6a6a6a', 60: '#919191', 85: '#d4d4d4', 90: '#e2e2e2', 95: '#f1f1f1', 100: '#ffffff'},
|
|
18
19
|
dark: {0: '#000000', 5: '#111111', 10: '#1b1b1b', 15: '#262626', 20: '#303030', 35: '#525252', 65: '#9e9e9e', 85: '#d4d4d4', 90: '#e2e2e2', 95: '#f1f1f1', 100: '#ffffff'},
|
|
19
20
|
},
|
|
20
21
|
orange: {
|
|
@@ -26,11 +27,11 @@ export const neutralPaletteRefs = {
|
|
|
26
27
|
dark: {25: '#253c5a', 65: '#5aa0f8', 75: '#88bcff', 80: '#a1caff'},
|
|
27
28
|
},
|
|
28
29
|
red: {
|
|
29
|
-
light: {25: '#76000c', 30: '#8a0011',
|
|
30
|
+
light: {25: '#76000c', 30: '#8a0011', 55: '#de4745', 65: '#fa6762', 70: '#ff7f77', 80: '#ffaea7', 85: '#ffc4be'},
|
|
30
31
|
dark: {25: '#5b2b28', 65: '#ee736c', 75: '#ff9890', 80: '#ffaea7', 85: '#ffc4be'},
|
|
31
32
|
},
|
|
32
33
|
yellow: {
|
|
33
|
-
light: {25: '#4b3900', 30: '#584400',
|
|
34
|
+
light: {25: '#4b3900', 30: '#584400', 65: '#c29900', 75: '#e2b623', 80: '#eec448', 85: '#f8d36a'},
|
|
34
35
|
dark: {25: '#453a1c', 80: '#e3c36c', 90: '#fae19e'},
|
|
35
36
|
},
|
|
36
37
|
teal: {
|
|
@@ -39,10 +40,10 @@ export const neutralPaletteRefs = {
|
|
|
39
40
|
},
|
|
40
41
|
cyan: {
|
|
41
42
|
dark: {25: '#274046', 65: '#49adc4', 75: '#71c7dd', 80: '#85d5e9', 85: '#9ae2f4'},
|
|
42
|
-
light: {25: '#004351'
|
|
43
|
+
light: {25: '#004351'},
|
|
43
44
|
},
|
|
44
45
|
pink: {
|
|
45
|
-
light: {25: '#70003f',
|
|
46
|
+
light: {25: '#70003f', 70: '#fc78b1', 85: '#ffc0d7'},
|
|
46
47
|
dark: {25: '#572b3d', 75: '#fd92bd', 80: '#ffa9ca'},
|
|
47
48
|
},
|
|
48
49
|
} as const;
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* html[data-theme="dark"] { color-scheme: dark; }
|
|
18
18
|
*
|
|
19
19
|
* Themes that never use `light-dark()` have no `color-scheme` ambiguity to
|
|
20
|
-
* resolve, so none of the three rules should be emitted for them
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* resolve, so none of the three rules should be emitted for them. Canonical data
|
|
21
|
+
* defaults come from StyleX rather than theme output, so this decision continues
|
|
22
|
+
* to read only the theme's authored values.
|
|
23
23
|
*
|
|
24
24
|
* Building `astryx theme build` requires a compiled @astryxdesign/core (there is no in-CLI
|
|
25
25
|
* fallback generator), so this suite builds core once in beforeAll via the
|
|
@@ -35,8 +35,10 @@ import {ensureCoreBuilt} from './ensure-core-built.mjs';
|
|
|
35
35
|
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
36
36
|
|
|
37
37
|
const COLOR_SCHEME_ROOT_DECL = ':root { color-scheme: light dark; }';
|
|
38
|
-
const COLOR_SCHEME_LIGHT_DECL =
|
|
39
|
-
|
|
38
|
+
const COLOR_SCHEME_LIGHT_DECL =
|
|
39
|
+
'html[data-theme="light"] { color-scheme: light; }';
|
|
40
|
+
const COLOR_SCHEME_DARK_DECL =
|
|
41
|
+
'html[data-theme="dark"] { color-scheme: dark; }';
|
|
40
42
|
|
|
41
43
|
function writeTheme(dir, name, tokens) {
|
|
42
44
|
fs.mkdirSync(dir, {recursive: true});
|
|
@@ -58,7 +60,9 @@ beforeAll(() => {
|
|
|
58
60
|
|
|
59
61
|
let tmpDir;
|
|
60
62
|
beforeEach(() => {
|
|
61
|
-
tmpDir = fs.mkdtempSync(
|
|
63
|
+
tmpDir = fs.mkdtempSync(
|
|
64
|
+
path.join(os.tmpdir(), 'astryx-build-theme-color-scheme-'),
|
|
65
|
+
);
|
|
62
66
|
});
|
|
63
67
|
afterEach(() => {
|
|
64
68
|
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
@@ -1,32 +1,17 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* no other token family does. Layer order is fixed by first declaration, so
|
|
10
|
-
* the base block also has to sit after `@layer reset` and before
|
|
11
|
-
* `@layer astryx-theme` for a consumer who imports this stylesheet alone.
|
|
12
|
-
*
|
|
13
|
-
* Building requires a compiled @astryxdesign/core, so this suite builds core
|
|
14
|
-
* once in beforeAll via the shared ensureCoreBuilt() helper.
|
|
15
|
-
*
|
|
16
|
-
* The build formats the defaults block itself, from the public
|
|
17
|
-
* `dataTokenDefaults` export; core formats it for the runtime. This suite is
|
|
18
|
-
* what keeps those two independent formattings byte-identical.
|
|
4
|
+
* @file Verifies `astryx theme build` emits sparse data overrides and no
|
|
5
|
+
* canonical root defaults while preserving explicit cascade-layer order.
|
|
6
|
+
* @input Temporary standalone theme modules compiled through the public CLI
|
|
7
|
+
* @output Structural assertions for AST-066 data-token ownership
|
|
8
|
+
* @position Regression suite for theme-build CSS ownership
|
|
19
9
|
*/
|
|
20
10
|
|
|
21
11
|
import {describe, it, expect, beforeAll, beforeEach, afterEach} from 'vitest';
|
|
22
12
|
import * as fs from 'node:fs';
|
|
23
13
|
import * as path from 'node:path';
|
|
24
14
|
import * as os from 'node:os';
|
|
25
|
-
// Core's own generator, imported from source rather than from the package: it
|
|
26
|
-
// is deliberately not part of `@astryxdesign/core/theme`'s public surface, and
|
|
27
|
-
// this suite is the guard that the build's independent formatting matches it.
|
|
28
|
-
import {generateDataTokenDefaultsCSS} from '../../../../core/src/theme/generateThemeRules';
|
|
29
|
-
import {dataTokenDefaults as sourceDataTokenDefaults} from '../../../../core/src/theme/domainTokens/dataTokens';
|
|
30
15
|
import {ensureCoreBuilt} from './ensure-core-built.mjs';
|
|
31
16
|
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
32
17
|
|
|
@@ -67,78 +52,41 @@ afterEach(() => {
|
|
|
67
52
|
});
|
|
68
53
|
|
|
69
54
|
describe('theme build data token output', () => {
|
|
70
|
-
it('emits
|
|
55
|
+
it('emits no canonical data defaults or raw root data block', async () => {
|
|
71
56
|
const css = await buildTheme(tmpDir, 'charts-untouched', {
|
|
72
57
|
tokens: {'--color-accent': '#0077B6'},
|
|
73
58
|
});
|
|
74
59
|
|
|
75
|
-
|
|
76
|
-
expect(
|
|
77
|
-
|
|
78
|
-
const baseBlock = css.slice(baseStart, css.indexOf('@layer astryx-theme'));
|
|
79
|
-
expect(baseBlock).toContain(':root {');
|
|
80
|
-
expect(baseBlock).toContain('--color-data-categorical-blue:');
|
|
81
|
-
expect(baseBlock).toContain('--color-data-gray-1:');
|
|
82
|
-
expect(css.match(/--color-data-categorical-blue:/g)).toHaveLength(1);
|
|
83
|
-
expect(css.match(/@layer astryx-base/g)).toHaveLength(1);
|
|
60
|
+
expect(css).not.toContain('--color-data-');
|
|
61
|
+
expect(css).not.toMatch(/:root\s*\{[^}]*--color-data-/s);
|
|
62
|
+
expect(css).not.toContain('@layer astryx-base {\n:root {');
|
|
84
63
|
});
|
|
85
64
|
|
|
86
|
-
it('
|
|
65
|
+
it('registers layer order before every emitted layer block', async () => {
|
|
87
66
|
const css = await buildTheme(tmpDir, 'charts-order', {
|
|
88
67
|
tokens: {'--color-accent': '#0077B6'},
|
|
89
68
|
});
|
|
90
69
|
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const theme = css.indexOf('@layer astryx-theme');
|
|
70
|
+
const order = css.indexOf('@layer reset, astryx-base, astryx-theme;');
|
|
71
|
+
const reset = css.indexOf('@layer reset {');
|
|
72
|
+
const theme = css.indexOf('@layer astryx-theme {');
|
|
94
73
|
|
|
95
|
-
expect(
|
|
96
|
-
expect(
|
|
97
|
-
expect(theme).toBeGreaterThan(
|
|
74
|
+
expect(order).toBeGreaterThanOrEqual(0);
|
|
75
|
+
expect(reset).toBeGreaterThan(order);
|
|
76
|
+
expect(theme).toBeGreaterThan(order);
|
|
98
77
|
});
|
|
99
78
|
|
|
100
|
-
it("puts only the theme's
|
|
79
|
+
it("puts only the theme's authored data token in its donut", async () => {
|
|
101
80
|
const css = await buildTheme(tmpDir, 'charts-override', {
|
|
102
81
|
tokens: {'--color-data-categorical-blue': '#00A3FF'},
|
|
103
82
|
});
|
|
104
83
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
expect(themeBlock).not.toContain('--color-data-categorical-orange');
|
|
108
|
-
expect(themeBlock).not.toContain('--color-data-gray-1');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('emits the bytes the runtime generator emits', async () => {
|
|
112
|
-
const css = await buildTheme(tmpDir, 'charts-parity', {
|
|
113
|
-
tokens: {'--color-accent': '#0077B6'},
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
// The expectation below comes from core's SOURCE; the stylesheet came from
|
|
117
|
-
// core's dist. ensureCoreBuilt() only checks that dist exists, never that
|
|
118
|
-
// it is current, so a dist older than the source would fail the byte
|
|
119
|
-
// comparison with a colour mismatch that reads as formatter drift. Name
|
|
120
|
-
// that case first.
|
|
121
|
-
const {dataTokenDefaults: builtDataTokenDefaults} = await import(
|
|
122
|
-
'@astryxdesign/core/theme'
|
|
123
|
-
);
|
|
124
|
-
expect(
|
|
125
|
-
builtDataTokenDefaults,
|
|
126
|
-
'packages/core/dist is stale — run `pnpm -F @astryxdesign/core build`',
|
|
127
|
-
).toEqual(sourceDataTokenDefaults);
|
|
128
|
-
|
|
129
|
-
// The build formats this block itself, from the public `dataTokenDefaults`
|
|
130
|
-
// export; the runtime formats it in core. Nothing else holds the two
|
|
131
|
-
// together, so compare the bytes — a changed indent or separator in either
|
|
132
|
-
// one fails here.
|
|
133
|
-
const runtimeBase = generateDataTokenDefaultsCSS();
|
|
134
|
-
const marker = '@layer astryx-base {\n';
|
|
135
|
-
const start = css.indexOf(marker);
|
|
136
|
-
expect(start).toBeGreaterThanOrEqual(0);
|
|
137
|
-
|
|
138
|
-
const bodyStart = start + marker.length;
|
|
139
|
-
expect(css.slice(bodyStart, bodyStart + runtimeBase.length)).toBe(
|
|
140
|
-
runtimeBase,
|
|
84
|
+
expect(css).toContain(
|
|
85
|
+
'@scope ([data-astryx-theme="charts-override"]) to ([data-astryx-theme])',
|
|
141
86
|
);
|
|
142
|
-
expect(css.
|
|
87
|
+
expect(css).toContain('--color-data-categorical-blue: #00A3FF;');
|
|
88
|
+
expect(css.match(/--color-data-/g)).toHaveLength(1);
|
|
89
|
+
expect(css).not.toContain('--color-data-categorical-orange');
|
|
90
|
+
expect(css).not.toContain('--color-data-gray-1');
|
|
143
91
|
});
|
|
144
92
|
});
|
|
@@ -51,7 +51,7 @@ export const doc = {
|
|
|
51
51
|
{code: 0, when: 'success (including zero matches)'},
|
|
52
52
|
{
|
|
53
53
|
code: 1,
|
|
54
|
-
when: 'invalid --type, a
|
|
54
|
+
when: 'invalid --type, a --limit that is not a positive integer, or a query when @astryxdesign/core cannot be found (the playbook needs no core)',
|
|
55
55
|
},
|
|
56
56
|
],
|
|
57
57
|
related: ['search', 'template', 'component', 'hook', 'init'],
|
|
@@ -101,7 +101,7 @@ export function registerBuild(program) {
|
|
|
101
101
|
// throws ERR_INVALID_ARGUMENT, so we pass NaN through rather than
|
|
102
102
|
// pre-rejecting with a generic code here (parity with `search`).
|
|
103
103
|
const limit =
|
|
104
|
-
options.limit != null ? Number
|
|
104
|
+
options.limit != null ? Number(options.limit) : 60;
|
|
105
105
|
|
|
106
106
|
/** @type {import('../../../api/build/build.type.mjs').BuildKitResponse} */
|
|
107
107
|
let result;
|
|
@@ -223,7 +223,7 @@ describe('component() — integration ownership via config', () => {
|
|
|
223
223
|
caught = e;
|
|
224
224
|
}
|
|
225
225
|
expect(caught).toBeTruthy();
|
|
226
|
-
expect(caught.code).toBe('
|
|
226
|
+
expect(caught.code).toBe('ERR_AMBIGUOUS_COMPONENT');
|
|
227
227
|
const pkgs = (caught.suggestions ?? []).map(s => s.name);
|
|
228
228
|
expect(pkgs).toContain(CORE_PACKAGE);
|
|
229
229
|
expect(pkgs).toContain(INTEGRATION_NAME);
|
|
@@ -288,7 +288,7 @@ describe('component() — integration ownership via config', () => {
|
|
|
288
288
|
expect(result.data.results[1]).toMatchObject({
|
|
289
289
|
selector: 'AppShell',
|
|
290
290
|
status: 'ambiguous',
|
|
291
|
-
code: '
|
|
291
|
+
code: 'ERR_AMBIGUOUS_COMPONENT',
|
|
292
292
|
});
|
|
293
293
|
expect(result.data.results[1].candidates).toEqual(
|
|
294
294
|
expect.arrayContaining([
|
|
@@ -101,7 +101,7 @@ export function registerIntegration(program) {
|
|
|
101
101
|
// still parses its own options.
|
|
102
102
|
integration.allowUnknownOption(true);
|
|
103
103
|
|
|
104
|
-
defineCommand(integration, integrationAddCommand, {
|
|
104
|
+
const addCmd = defineCommand(integration, integrationAddCommand, {
|
|
105
105
|
fn: integrationAddFn,
|
|
106
106
|
action: async (kind, name, options) => {
|
|
107
107
|
const json = program.opts().json || false;
|
|
@@ -157,6 +157,7 @@ export function registerIntegration(program) {
|
|
|
157
157
|
return NO_RESULT_SET;
|
|
158
158
|
},
|
|
159
159
|
});
|
|
160
|
+
addCmd.allowExcessArguments(false);
|
|
160
161
|
|
|
161
162
|
defineCommand(integration, integrationVerifyCommand, {
|
|
162
163
|
fn: integrationPackCheckFn,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
3
|
+
import * as fs from 'node:fs'; import * as os from 'node:os'; import * as path from 'node:path';
|
|
4
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
5
|
+
let dir;
|
|
6
|
+
beforeEach(() => { dir = fs.mkdtempSync(path.join(os.tmpdir(),'astryx-ss-')); fs.writeFileSync(path.join(dir,'package.json'),JSON.stringify({name:'s',version:'1.0.0',dependencies:{'@astryxdesign/core':'0.6.3'}})); const c=path.join(dir,'node_modules','@astryxdesign','core'); fs.mkdirSync(c,{recursive:true}); fs.writeFileSync(path.join(c,'package.json'),JSON.stringify({name:'@astryxdesign/core',version:'0.6.3'})); });
|
|
7
|
+
afterEach(() => fs.rmSync(dir, {recursive:true,force:true}));
|
|
8
|
+
const json = async a => { const {status,stdout}=await runCli(['--json',...a],{cwd:dir}); return {status,body:JSON.parse(stdout)}; };
|
|
9
|
+
describe('refuse invalid input (IFIX-0007)', () => {
|
|
10
|
+
it('template --type bogus', async () => { const {status,body}=await json(['template','--list','--type','bogus']); expect(status).toBe(1); expect(body.code).toBe('ERR_INVALID_ARGUMENT'); });
|
|
11
|
+
it('template --package @nope/x', async () => { const {status,body}=await json(['template','--list','--package','@nope/x']); expect(status).toBe(1); expect(body.code).toBe('ERR_INVALID_ARGUMENT'); });
|
|
12
|
+
it('template valid type+package filter keeps the matching templates', async () => { const {status,body}=await json(['template','--list','--type','block','--package','@astryxdesign/core']); expect(status).toBe(0); expect(body.type).toBe('template.list'); expect(body.data.length).toBeGreaterThan(0); expect(body.data.every(t => t.type === 'block')).toBe(true); });
|
|
13
|
+
it('build --limit 2.5', async () => { const {status,body}=await json(['build','pricing','--limit','2.5']); expect(status).toBe(1); expect(body.code).toBe('ERR_INVALID_ARGUMENT'); });
|
|
14
|
+
it('integration add excess args', async () => { fs.writeFileSync(path.join(dir,'package.json'),JSON.stringify({name:'@t/p',version:'1.0.0'})); const {status}=await json(['integration','add','agent-doc','Run','acme','verify']); expect(status).toBe(1); });
|
|
15
|
+
});
|
|
@@ -109,7 +109,7 @@ export const doc = {
|
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
111
|
code: 1,
|
|
112
|
-
when: 'unknown or ambiguous template, no source, a path escape,
|
|
112
|
+
when: 'unknown or ambiguous template, no source, a path escape, an existing target without --overwrite, or --list with a type outside page or block or a package that provides no templates',
|
|
113
113
|
},
|
|
114
114
|
],
|
|
115
115
|
related: ['component', 'search', 'discover', 'init'],
|
|
@@ -20,6 +20,7 @@ import * as path from 'node:path';
|
|
|
20
20
|
import module from 'node:module';
|
|
21
21
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
22
22
|
import {detectStylingSystem} from '../agent-docs/agent-docs.mjs';
|
|
23
|
+
import {decidePackageManagerIn} from '../env/package-manager.mjs';
|
|
23
24
|
|
|
24
25
|
// ── Known packages that a template may import without the user installing them.
|
|
25
26
|
// react and react-dom are the framework; @astryxdesign/* is the design system
|
|
@@ -59,16 +60,86 @@ export function extractImportedPackages(source) {
|
|
|
59
60
|
return pkgs;
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
/** @type {Record<string, string>} */
|
|
64
|
+
const ADD_VERB = {
|
|
65
|
+
pnpm: 'pnpm add',
|
|
66
|
+
yarn: 'yarn add',
|
|
67
|
+
bun: 'bun add',
|
|
68
|
+
npm: 'npm install',
|
|
69
|
+
};
|
|
70
|
+
|
|
62
71
|
/**
|
|
63
|
-
*
|
|
64
|
-
* @param {string}
|
|
65
|
-
* @returns {
|
|
72
|
+
* Whether a package.json declares a workspace (`workspaces` field).
|
|
73
|
+
* @param {string} dir
|
|
74
|
+
* @returns {{exists: boolean, declaresWorkspace: boolean}}
|
|
66
75
|
*/
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
if (fs.existsSync(
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
function readPackageJson(dir) {
|
|
77
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
78
|
+
if (!fs.existsSync(pkgPath)) return {exists: false, declaresWorkspace: false};
|
|
79
|
+
try {
|
|
80
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
81
|
+
return {exists: true, declaresWorkspace: pkg.workspaces != null};
|
|
82
|
+
} catch {
|
|
83
|
+
return {exists: true, declaresWorkspace: false};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The workspace root (AST-048 FR15): the nearest directory at or above the
|
|
89
|
+
* target that declares a workspace, by `pnpm-workspace.yaml` or a package.json
|
|
90
|
+
* `workspaces` field; outside a workspace, the nearest package.json's
|
|
91
|
+
* directory; with no package.json, the target itself.
|
|
92
|
+
* @param {string} target
|
|
93
|
+
* @returns {string}
|
|
94
|
+
*/
|
|
95
|
+
function findWorkspaceRoot(target) {
|
|
96
|
+
let dir = path.resolve(target);
|
|
97
|
+
/** @type {string | null} */
|
|
98
|
+
let nearestPackage = null;
|
|
99
|
+
for (;;) {
|
|
100
|
+
const pkg = readPackageJson(dir);
|
|
101
|
+
if (
|
|
102
|
+
fs.existsSync(path.join(dir, 'pnpm-workspace.yaml')) ||
|
|
103
|
+
pkg.declaresWorkspace
|
|
104
|
+
) {
|
|
105
|
+
return dir;
|
|
106
|
+
}
|
|
107
|
+
if (pkg.exists && nearestPackage == null) nearestPackage = dir;
|
|
108
|
+
const parent = path.dirname(dir);
|
|
109
|
+
if (parent === dir) return nearestPackage ?? path.resolve(target);
|
|
110
|
+
dir = parent;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The project's package manager for an install command (AST-048 FR17, FR19):
|
|
116
|
+
* the nearest directory from the target up to the workspace root that has a
|
|
117
|
+
* `packageManager` field or a lockfile decides, by the CLI's shared
|
|
118
|
+
* per-directory rule; with none, npm. Ambiguous when that directory's
|
|
119
|
+
* lockfiles disagree and nothing it commits picks one.
|
|
120
|
+
* @param {string} target
|
|
121
|
+
* @returns {{verb: string} | {verb: null, dir: string, lockfiles: string[]}}
|
|
122
|
+
*/
|
|
123
|
+
function resolveInstallVerb(target) {
|
|
124
|
+
const root = findWorkspaceRoot(target);
|
|
125
|
+
let dir = path.resolve(target);
|
|
126
|
+
for (;;) {
|
|
127
|
+
const decision = decidePackageManagerIn(dir);
|
|
128
|
+
if (decision) {
|
|
129
|
+
if (decision.ambiguous) {
|
|
130
|
+
return {
|
|
131
|
+
verb: null,
|
|
132
|
+
dir,
|
|
133
|
+
lockfiles: decision.lockfiles.map(lock => lock.file),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return {verb: ADD_VERB[decision.pm] ?? ADD_VERB.npm};
|
|
137
|
+
}
|
|
138
|
+
const parent = path.dirname(dir);
|
|
139
|
+
if (dir === root || parent === dir) break;
|
|
140
|
+
dir = parent;
|
|
141
|
+
}
|
|
142
|
+
return {verb: ADD_VERB.npm};
|
|
72
143
|
}
|
|
73
144
|
|
|
74
145
|
/**
|
|
@@ -128,11 +199,18 @@ export function analyzeTemplateNeeds(source, cwd) {
|
|
|
128
199
|
|
|
129
200
|
// Build the install command with version ranges from the CLI workspace.
|
|
130
201
|
let installCommand = null;
|
|
202
|
+
/** @type {string | null} */
|
|
203
|
+
let noCommandReason = null;
|
|
131
204
|
if (missing.length > 0) {
|
|
132
|
-
const
|
|
205
|
+
const resolved = resolveInstallVerb(cwd);
|
|
133
206
|
const ranges = cliPackageRanges();
|
|
134
207
|
const specs = missing.map(p => (ranges[p] ? `${p}@"${ranges[p]}"` : p));
|
|
135
|
-
|
|
208
|
+
if (resolved.verb !== null) {
|
|
209
|
+
installCommand = `${resolved.verb} ${specs.join(' ')}`;
|
|
210
|
+
} else {
|
|
211
|
+
const where = path.relative(cwd, resolved.dir) || '.';
|
|
212
|
+
noCommandReason = `Install missing dependencies: ${specs.join(' ')}. No install command: ${where} has ${resolved.lockfiles.join(' and ')}, and nothing there says which package manager to use.`;
|
|
213
|
+
}
|
|
136
214
|
}
|
|
137
215
|
|
|
138
216
|
// ── StyleX compiler ────────────────────────────────────────────────────
|
|
@@ -144,7 +222,11 @@ export function analyzeTemplateNeeds(source, cwd) {
|
|
|
144
222
|
/** @type {string[]} */
|
|
145
223
|
const notes = [];
|
|
146
224
|
if (missing.length > 0) {
|
|
147
|
-
notes.push(
|
|
225
|
+
notes.push(
|
|
226
|
+
installCommand
|
|
227
|
+
? `Install missing dependencies: ${installCommand}`
|
|
228
|
+
: (noCommandReason ?? ''),
|
|
229
|
+
);
|
|
148
230
|
}
|
|
149
231
|
if (stylexCompilerNeeded) {
|
|
150
232
|
notes.push(
|