@astryxdesign/cli 0.7.0-canary.e3c1cfd → 0.7.0-canary.e48e2ef
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/integration/pack-check.test.mjs +8 -0
- package/api/template/template.doc.mjs +1 -1
- 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__/migrate-field-input-styling.test.mjs +108 -0
- package/assets/codemods/transforms/next/__tests__/preserve-bottom-sheet-content-padding.test.mjs +178 -0
- package/assets/codemods/transforms/next/__tests__/validate-data-token-ownership.test.mjs +84 -0
- package/assets/codemods/transforms/next/index.mjs +24 -0
- package/assets/codemods/transforms/next/migrate-field-input-styling.mjs +198 -0
- package/assets/codemods/transforms/next/preserve-bottom-sheet-content-padding.mjs +242 -0
- package/assets/codemods/transforms/next/validate-data-token-ownership.mjs +102 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/spacing.doc.mjs +2 -2
- package/assets/docs/tree/tokens-data.doc.mjs +2 -2
- package/assets/docs/tree/tokens-spacing.doc.mjs +15 -15
- package/assets/docs/tree/tokens-usage.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetHeights.tsx +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetMobileKeyboard.tsx +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetNoScrim.tsx +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.tsx +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/Dialog/DialogAdaptivePresentation.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 +11 -6
- package/assets/templates/pages/table-inbox/page.tsx +3 -1
- package/assets/templates/pages/theme-showcase/page.tsx +2 -2
- package/assets/templates/themes/butter/butterTheme.ts +12 -0
- package/assets/templates/themes/chocolate/chocolateTheme.ts +12 -0
- package/assets/templates/themes/matcha/matchaTheme.ts +14 -14
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +10 -9
- package/assets/templates/themes/neutral/neutralTheme.ts +12 -0
- package/assets/templates/themes/stone/stoneTheme.ts +12 -0
- package/assets/templates/themes/y2k/y2kTheme.ts +10 -10
- package/assets/theme.template.ts +1 -1
- 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/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
|
@@ -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
|
});
|
|
@@ -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(
|
|
@@ -93,15 +93,23 @@ describe('extractImportedPackages', () => {
|
|
|
93
93
|
|
|
94
94
|
describe('analyzeTemplateNeeds', () => {
|
|
95
95
|
let dir;
|
|
96
|
+
let userAgent;
|
|
96
97
|
beforeEach(() => {
|
|
97
98
|
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpl-needs-'));
|
|
99
|
+
userAgent = process.env.npm_config_user_agent;
|
|
100
|
+
});
|
|
101
|
+
afterEach(() => {
|
|
102
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
103
|
+
if (userAgent === undefined) delete process.env.npm_config_user_agent;
|
|
104
|
+
else process.env.npm_config_user_agent = userAgent;
|
|
98
105
|
});
|
|
99
|
-
afterEach(() => fs.rmSync(dir, {recursive: true, force: true}));
|
|
100
106
|
|
|
101
107
|
it('reports missing external packages with an install command', () => {
|
|
102
108
|
fs.writeFileSync(
|
|
103
109
|
path.join(dir, 'package.json'),
|
|
104
|
-
JSON.stringify({
|
|
110
|
+
JSON.stringify({
|
|
111
|
+
dependencies: {react: '^19.0.0', '@astryxdesign/core': '^0.6.0'},
|
|
112
|
+
}),
|
|
105
113
|
);
|
|
106
114
|
const source = `
|
|
107
115
|
import {Button} from '@astryxdesign/core';
|
|
@@ -120,7 +128,7 @@ describe('analyzeTemplateNeeds', () => {
|
|
|
120
128
|
path.join(dir, 'package.json'),
|
|
121
129
|
JSON.stringify({
|
|
122
130
|
dependencies: {
|
|
123
|
-
|
|
131
|
+
react: '^19.0.0',
|
|
124
132
|
'@astryxdesign/core': '^0.6.0',
|
|
125
133
|
'@heroicons/react': '^2.2.0',
|
|
126
134
|
},
|
|
@@ -183,6 +191,101 @@ describe('analyzeTemplateNeeds', () => {
|
|
|
183
191
|
expect(result.installCommand).toMatch(/^yarn add /);
|
|
184
192
|
});
|
|
185
193
|
|
|
194
|
+
describe('package manager for the install command (AST-048 FR17, FR19)', () => {
|
|
195
|
+
const source = `import {Chart} from 'recharts';`;
|
|
196
|
+
const write = (rel, body = '') => {
|
|
197
|
+
fs.mkdirSync(path.dirname(path.join(dir, rel)), {recursive: true});
|
|
198
|
+
fs.writeFileSync(path.join(dir, rel), body);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
it('uses npm when no directory up to the workspace root has a field or lockfile, whatever runs the CLI', () => {
|
|
202
|
+
write('package.json', '{}');
|
|
203
|
+
process.env.npm_config_user_agent = 'pnpm/11.10.0 npm/? node/v22.0.0';
|
|
204
|
+
expect(analyzeTemplateNeeds(source, dir).installCommand).toMatch(
|
|
205
|
+
/^npm install recharts/,
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('reads a lockfile that sits only at the workspace root', () => {
|
|
210
|
+
write('package.json', JSON.stringify({workspaces: ['apps/*']}));
|
|
211
|
+
write('yarn.lock');
|
|
212
|
+
write('apps/web/package.json', '{}');
|
|
213
|
+
const result = analyzeTemplateNeeds(source, path.join(dir, 'apps/web'));
|
|
214
|
+
expect(result.installCommand).toMatch(/^yarn add recharts/);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('ignores a lockfile above the workspace root of a standalone project', () => {
|
|
218
|
+
write('yarn.lock');
|
|
219
|
+
write('app/package.json', '{}');
|
|
220
|
+
const result = analyzeTemplateNeeds(source, path.join(dir, 'app'));
|
|
221
|
+
expect(result.installCommand).toMatch(/^npm install recharts/);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('follows a declared packageManager over another lockfile', () => {
|
|
225
|
+
write('package.json', JSON.stringify({packageManager: 'pnpm@11.10.0'}));
|
|
226
|
+
write('pnpm-lock.yaml');
|
|
227
|
+
write('yarn.lock');
|
|
228
|
+
expect(analyzeTemplateNeeds(source, dir).installCommand).toMatch(
|
|
229
|
+
/^pnpm add recharts/,
|
|
230
|
+
);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('lets a file only one package manager reads decide between tied lockfiles', () => {
|
|
234
|
+
write('package.json', '{}');
|
|
235
|
+
write('pnpm-lock.yaml');
|
|
236
|
+
write('yarn.lock');
|
|
237
|
+
write('pnpm-workspace.yaml', "packages: ['.']\n");
|
|
238
|
+
expect(analyzeTemplateNeeds(source, dir).installCommand).toMatch(
|
|
239
|
+
/^pnpm add recharts/,
|
|
240
|
+
);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it.each([
|
|
244
|
+
['no other file', []],
|
|
245
|
+
[
|
|
246
|
+
'config files for two package managers',
|
|
247
|
+
['pnpm-workspace.yaml', '.yarnrc.yml'],
|
|
248
|
+
],
|
|
249
|
+
])(
|
|
250
|
+
'omits the command and names the directory and lockfiles when lockfiles tie with %s',
|
|
251
|
+
(_label, extras) => {
|
|
252
|
+
write('package.json', '{}');
|
|
253
|
+
write('pnpm-lock.yaml');
|
|
254
|
+
write('yarn.lock');
|
|
255
|
+
for (const file of extras) write(file);
|
|
256
|
+
const result = analyzeTemplateNeeds(source, dir);
|
|
257
|
+
expect(result.missingPackages).toEqual(['recharts']);
|
|
258
|
+
expect(result.installCommand).toBeNull();
|
|
259
|
+
const note = result.notes[0];
|
|
260
|
+
expect(note).toContain('recharts');
|
|
261
|
+
expect(note).toContain('No install command: . has');
|
|
262
|
+
expect(note).toMatch(
|
|
263
|
+
/yarn\.lock and pnpm-lock\.yaml|pnpm-lock\.yaml and yarn\.lock/,
|
|
264
|
+
);
|
|
265
|
+
expect(note).not.toMatch(/npm install|pnpm add|yarn add/);
|
|
266
|
+
},
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
it('names the deciding directory relative to the target, not the process', () => {
|
|
270
|
+
write('package.json', JSON.stringify({workspaces: ['apps/*']}));
|
|
271
|
+
write('package-lock.json');
|
|
272
|
+
write('yarn.lock');
|
|
273
|
+
write('apps/web/package.json', '{}');
|
|
274
|
+
const result = analyzeTemplateNeeds(source, path.join(dir, 'apps/web'));
|
|
275
|
+
expect(result.installCommand).toBeNull();
|
|
276
|
+
expect(result.notes[0]).toContain(
|
|
277
|
+
`No install command: ${path.join('..', '..')} has`,
|
|
278
|
+
);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('stays ambiguous with only a package.json workspaces field beside tied lockfiles', () => {
|
|
282
|
+
write('package.json', JSON.stringify({workspaces: ['apps/*']}));
|
|
283
|
+
write('package-lock.json');
|
|
284
|
+
write('yarn.lock');
|
|
285
|
+
expect(analyzeTemplateNeeds(source, dir).installCommand).toBeNull();
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
186
289
|
it('excludes @stylexjs/stylex from missing packages (it is a Core peer)', () => {
|
|
187
290
|
fs.writeFileSync(path.join(dir, 'package.json'), '{}');
|
|
188
291
|
const source = `import * as stylex from '@stylexjs/stylex';`;
|
|
@@ -19,6 +19,19 @@
|
|
|
19
19
|
* declared field contradicts. Detection ignores them; `astryx doctor` reports
|
|
20
20
|
* them, because a tool that trusts the lockfile instead will disagree with us.
|
|
21
21
|
*/
|
|
22
|
+
/**
|
|
23
|
+
* What one directory's own files say about its package manager, by the rules
|
|
24
|
+
* {@link explainPackageManager} applies within a directory (declared field,
|
|
25
|
+
* then a single lockfile, then committed config when lockfiles tie). Returns
|
|
26
|
+
* null when the directory has neither a declaration nor a lockfile, so a caller
|
|
27
|
+
* walking up keeps looking. An ambiguous directory reports `ambiguous: true`
|
|
28
|
+
* with the lockfiles that disagree, so a caller can name them.
|
|
29
|
+
* @param {string} dir
|
|
30
|
+
* @returns {(Omit<PackageManagerResolution, 'dir'> & {lockfiles: FoundLockfile[]}) | null}
|
|
31
|
+
*/
|
|
32
|
+
export function decidePackageManagerIn(dir: string): (Omit<PackageManagerResolution, "dir"> & {
|
|
33
|
+
lockfiles: FoundLockfile[];
|
|
34
|
+
}) | null;
|
|
22
35
|
/**
|
|
23
36
|
* Detect the project's package manager, with the reasoning attached.
|
|
24
37
|
* Walks up from targetDir, taking the first directory that answers.
|
|
@@ -144,6 +144,76 @@ function evidenceIn(dir) {
|
|
|
144
144
|
* them, because a tool that trusts the lockfile instead will disagree with us.
|
|
145
145
|
*/
|
|
146
146
|
|
|
147
|
+
/**
|
|
148
|
+
* What one directory's own files say about its package manager, by the rules
|
|
149
|
+
* {@link explainPackageManager} applies within a directory (declared field,
|
|
150
|
+
* then a single lockfile, then committed config when lockfiles tie). Returns
|
|
151
|
+
* null when the directory has neither a declaration nor a lockfile, so a caller
|
|
152
|
+
* walking up keeps looking. An ambiguous directory reports `ambiguous: true`
|
|
153
|
+
* with the lockfiles that disagree, so a caller can name them.
|
|
154
|
+
* @param {string} dir
|
|
155
|
+
* @returns {(Omit<PackageManagerResolution, 'dir'> & {lockfiles: FoundLockfile[]}) | null}
|
|
156
|
+
*/
|
|
157
|
+
export function decidePackageManagerIn(dir) {
|
|
158
|
+
const locks = lockfilesIn(dir);
|
|
159
|
+
const candidates = locks.map(lock => lock.pm);
|
|
160
|
+
const declared = declaredPackageManager(dir);
|
|
161
|
+
|
|
162
|
+
// The project declared one. Nothing on the filesystem outranks that.
|
|
163
|
+
if (declared) {
|
|
164
|
+
return {
|
|
165
|
+
pm: declared,
|
|
166
|
+
ambiguous: false,
|
|
167
|
+
candidates,
|
|
168
|
+
declared,
|
|
169
|
+
source: 'declared',
|
|
170
|
+
lockfiles: locks,
|
|
171
|
+
strayLockfiles: locks.filter(lock => lock.pm !== declared),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// One lockfile is unambiguous.
|
|
176
|
+
if (locks.length === 1) {
|
|
177
|
+
return {
|
|
178
|
+
pm: locks[0].pm,
|
|
179
|
+
ambiguous: false,
|
|
180
|
+
candidates,
|
|
181
|
+
declared: null,
|
|
182
|
+
source: 'lockfile',
|
|
183
|
+
lockfiles: locks,
|
|
184
|
+
strayLockfiles: [],
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Several lockfiles and no declaration: the filesystem cannot say. Only a
|
|
189
|
+
// file the project committed on purpose can.
|
|
190
|
+
if (locks.length > 1) {
|
|
191
|
+
const evidence = evidenceIn(dir).filter(pm => candidates.includes(pm));
|
|
192
|
+
if (evidence.length === 1) {
|
|
193
|
+
return {
|
|
194
|
+
pm: evidence[0],
|
|
195
|
+
ambiguous: false,
|
|
196
|
+
candidates,
|
|
197
|
+
declared: null,
|
|
198
|
+
source: 'evidence',
|
|
199
|
+
lockfiles: locks,
|
|
200
|
+
strayLockfiles: [],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
pm: 'npx',
|
|
205
|
+
ambiguous: true,
|
|
206
|
+
candidates,
|
|
207
|
+
declared: null,
|
|
208
|
+
source: 'none',
|
|
209
|
+
lockfiles: locks,
|
|
210
|
+
strayLockfiles: [],
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
|
|
147
217
|
/**
|
|
148
218
|
* Detect the project's package manager, with the reasoning attached.
|
|
149
219
|
* Walks up from targetDir, taking the first directory that answers.
|
|
@@ -182,59 +252,16 @@ export function explainPackageManager(targetDir = process.cwd()) {
|
|
|
182
252
|
const root = path.parse(dir).root;
|
|
183
253
|
|
|
184
254
|
while (dir !== root) {
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
const declared = declaredPackageManager(dir);
|
|
188
|
-
|
|
189
|
-
// 1. The project declared one. Nothing on the filesystem outranks that.
|
|
190
|
-
if (declared) {
|
|
255
|
+
const decision = decidePackageManagerIn(dir);
|
|
256
|
+
if (decision) {
|
|
191
257
|
return {
|
|
192
|
-
pm:
|
|
193
|
-
ambiguous:
|
|
194
|
-
dir,
|
|
195
|
-
candidates,
|
|
196
|
-
declared,
|
|
197
|
-
source: 'declared',
|
|
198
|
-
strayLockfiles: locks.filter(lock => lock.pm !== declared),
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// 2. One lockfile is unambiguous.
|
|
203
|
-
if (locks.length === 1) {
|
|
204
|
-
return {
|
|
205
|
-
pm: locks[0].pm,
|
|
206
|
-
ambiguous: false,
|
|
258
|
+
pm: decision.pm,
|
|
259
|
+
ambiguous: decision.ambiguous,
|
|
207
260
|
dir,
|
|
208
|
-
candidates,
|
|
209
|
-
declared:
|
|
210
|
-
source:
|
|
211
|
-
strayLockfiles:
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// 3. Several lockfiles and no declaration: the filesystem cannot say.
|
|
216
|
-
// Only a file the project committed on purpose can.
|
|
217
|
-
if (locks.length > 1) {
|
|
218
|
-
const evidence = evidenceIn(dir).filter(pm => candidates.includes(pm));
|
|
219
|
-
if (evidence.length === 1) {
|
|
220
|
-
return {
|
|
221
|
-
pm: evidence[0],
|
|
222
|
-
ambiguous: false,
|
|
223
|
-
dir,
|
|
224
|
-
candidates,
|
|
225
|
-
declared: null,
|
|
226
|
-
source: 'evidence',
|
|
227
|
-
strayLockfiles: [],
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
pm: 'npx',
|
|
232
|
-
ambiguous: true,
|
|
233
|
-
dir,
|
|
234
|
-
candidates,
|
|
235
|
-
declared: null,
|
|
236
|
-
source: 'none',
|
|
237
|
-
strayLockfiles: [],
|
|
261
|
+
candidates: decision.candidates,
|
|
262
|
+
declared: decision.declared,
|
|
263
|
+
source: decision.source,
|
|
264
|
+
strayLockfiles: decision.strayLockfiles,
|
|
238
265
|
};
|
|
239
266
|
}
|
|
240
267
|
|
|
@@ -279,11 +306,15 @@ export function detectPackageManager(targetDir = process.cwd()) {
|
|
|
279
306
|
export function getRunPrefix(targetDir) {
|
|
280
307
|
const pm = detectPackageManager(targetDir);
|
|
281
308
|
switch (pm) {
|
|
282
|
-
case 'yarn':
|
|
283
|
-
|
|
284
|
-
case '
|
|
309
|
+
case 'yarn':
|
|
310
|
+
return 'yarn';
|
|
311
|
+
case 'pnpm':
|
|
312
|
+
return 'pnpm exec';
|
|
313
|
+
case 'bun':
|
|
314
|
+
return 'bunx';
|
|
285
315
|
case 'npm':
|
|
286
|
-
default:
|
|
316
|
+
default:
|
|
317
|
+
return 'npx';
|
|
287
318
|
}
|
|
288
319
|
}
|
|
289
320
|
|
|
@@ -310,11 +341,15 @@ export const CLI_BIN = 'astryx';
|
|
|
310
341
|
export function getDlxPrefix(targetDir) {
|
|
311
342
|
const resolution = explainPackageManager(targetDir);
|
|
312
343
|
switch (resolution.pm) {
|
|
313
|
-
case 'yarn':
|
|
314
|
-
|
|
315
|
-
case '
|
|
344
|
+
case 'yarn':
|
|
345
|
+
return isYarnClassic(resolution) ? 'npx' : 'yarn dlx';
|
|
346
|
+
case 'pnpm':
|
|
347
|
+
return 'pnpm dlx';
|
|
348
|
+
case 'bun':
|
|
349
|
+
return 'bunx';
|
|
316
350
|
case 'npm':
|
|
317
|
-
default:
|
|
351
|
+
default:
|
|
352
|
+
return 'npx';
|
|
318
353
|
}
|
|
319
354
|
}
|
|
320
355
|
|
|
@@ -343,7 +378,9 @@ function isYarnClassic({dir}) {
|
|
|
343
378
|
if (fs.existsSync(path.join(dir, '.yarnrc.yml'))) return false;
|
|
344
379
|
if (fs.existsSync(path.join(dir, '.yarnrc'))) return true;
|
|
345
380
|
}
|
|
346
|
-
const agent = /^yarn\/(\d+)\./.exec(
|
|
381
|
+
const agent = /^yarn\/(\d+)\./.exec(
|
|
382
|
+
String(process.env.npm_config_user_agent ?? ''),
|
|
383
|
+
);
|
|
347
384
|
return agent ? agent[1] === '1' : false;
|
|
348
385
|
}
|
|
349
386
|
|
|
@@ -354,8 +391,12 @@ function isYarnClassic({dir}) {
|
|
|
354
391
|
*/
|
|
355
392
|
function declaredYarnMajor(dir) {
|
|
356
393
|
try {
|
|
357
|
-
const pkg = JSON.parse(
|
|
358
|
-
|
|
394
|
+
const pkg = JSON.parse(
|
|
395
|
+
fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'),
|
|
396
|
+
);
|
|
397
|
+
const match = /^yarn@(\d+)(?:[.+]|$)/.exec(
|
|
398
|
+
String(pkg.packageManager ?? ''),
|
|
399
|
+
);
|
|
359
400
|
return match ? Number(match[1]) : null;
|
|
360
401
|
} catch {
|
|
361
402
|
// Best-effort: no package.json, or an unreadable one.
|
|
@@ -465,7 +506,9 @@ export function getCliInvocation(targetDir) {
|
|
|
465
506
|
* @returns {string}
|
|
466
507
|
*/
|
|
467
508
|
export function formatCliCommand(command, targetDir) {
|
|
468
|
-
const sub = String(command)
|
|
509
|
+
const sub = String(command)
|
|
510
|
+
.replace(/^\s*astryx\b\s*/, '')
|
|
511
|
+
.trim();
|
|
469
512
|
const stem = getCliInvocation(targetDir);
|
|
470
513
|
return sub ? `${stem} ${sub}` : stem;
|
|
471
514
|
}
|
|
@@ -196,7 +196,7 @@ export const doc = {
|
|
|
196
196
|
{
|
|
197
197
|
value: 'template.copy',
|
|
198
198
|
description:
|
|
199
|
-
"A scaffold receipt: template id, output directory, written file name, file count, demoMediaReplaced (how many Astryx demo media references were replaced with placeholders), notes (setup notes naming what the template needs that the project lacks — missing packages, missing StyleX compiler; empty when satisfied), missingPackages (external package names the template imports that are not in the project), and installCommand (a ready-to-run install command with the detected package manager and workspace version ranges; null when nothing is missing). The envelope's package names the npm package that owns the template.",
|
|
199
|
+
"A scaffold receipt: template id, output directory, written file name, file count, demoMediaReplaced (how many Astryx demo media references were replaced with placeholders), notes (setup notes naming what the template needs that the project lacks — missing packages, missing StyleX compiler; empty when satisfied), missingPackages (external package names the template imports that are not in the project), and installCommand (a ready-to-run install command with the detected package manager and workspace version ranges; null when nothing is missing, or when several lockfiles leave the package manager undetermined). The envelope's package names the npm package that owns the template.",
|
|
200
200
|
},
|
|
201
201
|
|
|
202
202
|
{
|
|
@@ -349,6 +349,5 @@ export const doc = {
|
|
|
349
349
|
description:
|
|
350
350
|
'validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and Core doc overlaps. Each finding includes `severity` (`info` | `error`) and `relationship` (`replaces` | `extends` | `accidental`).',
|
|
351
351
|
},
|
|
352
|
-
|
|
353
352
|
],
|
|
354
353
|
};
|