@astryxdesign/cli 0.7.0-canary.e92e36f → 0.7.0-canary.eaca8eb
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/doctor/doctor.d.mts +30 -2
- package/api/doctor/doctor.doc.mjs +2 -1
- package/api/doctor/doctor.mjs +153 -3
- package/api/doctor/doctor.test.mjs +250 -4
- 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/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/clients/cli/commands/doctor.doc.mjs +1 -1
- package/clients/cli/commands/doctor.test.mjs +33 -0
- 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
|
@@ -403,3 +403,36 @@ describe('doctor — text output mirrors the JSON', () => {
|
|
|
403
403
|
}
|
|
404
404
|
}, 60_000);
|
|
405
405
|
});
|
|
406
|
+
|
|
407
|
+
describe('doctor — a configured integration that cannot load', () => {
|
|
408
|
+
it('sets exit code 1 and reports it in the JSON', async () => {
|
|
409
|
+
const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-exit-'));
|
|
410
|
+
const prevCwd = process.cwd();
|
|
411
|
+
const prevExit = process.exitCode;
|
|
412
|
+
process.exitCode = undefined;
|
|
413
|
+
try {
|
|
414
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"app"}');
|
|
415
|
+
fs.writeFileSync(
|
|
416
|
+
path.join(dir, 'astryx.config.mjs'),
|
|
417
|
+
"export default { integrations: ['@acme/missing'] };\n",
|
|
418
|
+
);
|
|
419
|
+
const coreDir = path.join(dir, 'node_modules', '@astryxdesign', 'core');
|
|
420
|
+
fs.mkdirSync(coreDir, {recursive: true});
|
|
421
|
+
fs.writeFileSync(
|
|
422
|
+
path.join(coreDir, 'package.json'),
|
|
423
|
+
JSON.stringify({name: '@astryxdesign/core', version: '0.6.3'}),
|
|
424
|
+
);
|
|
425
|
+
process.chdir(dir);
|
|
426
|
+
await createProgram().parseAsync(['node', 'astryx', '--json', 'doctor']);
|
|
427
|
+
expect(process.exitCode).toBe(1);
|
|
428
|
+
const {data} = JSON.parse(logCalls.join('\n'));
|
|
429
|
+
expect(
|
|
430
|
+
data.checks.find(c => c.id === 'configured-integrations'),
|
|
431
|
+
).toMatchObject({status: 'fail'});
|
|
432
|
+
} finally {
|
|
433
|
+
process.chdir(prevCwd);
|
|
434
|
+
process.exitCode = prevExit;
|
|
435
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
436
|
+
}
|
|
437
|
+
}, 60_000);
|
|
438
|
+
});
|
|
@@ -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
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.0-canary.
|
|
3
|
+
"version": "0.7.0-canary.eaca8eb",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -101,10 +101,10 @@
|
|
|
101
101
|
"zod": "^4.4.3"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
|
-
"@astryxdesign/charts": "0.7.0-canary.
|
|
105
|
-
"@astryxdesign/core": "0.7.0-canary.
|
|
106
|
-
"@astryxdesign/lab": "0.7.0-canary.
|
|
107
|
-
"@astryxdesign/theme-neutral": "0.7.0-canary.
|
|
104
|
+
"@astryxdesign/charts": "0.7.0-canary.eaca8eb",
|
|
105
|
+
"@astryxdesign/core": "0.7.0-canary.eaca8eb",
|
|
106
|
+
"@astryxdesign/lab": "0.7.0-canary.eaca8eb",
|
|
107
|
+
"@astryxdesign/theme-neutral": "0.7.0-canary.eaca8eb"
|
|
108
108
|
},
|
|
109
109
|
"peerDependenciesMeta": {
|
|
110
110
|
"@astryxdesign/charts": {
|
|
@@ -121,10 +121,10 @@
|
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
|
-
"@astryxdesign/charts": "0.7.0-canary.
|
|
125
|
-
"@astryxdesign/core": "0.7.0-canary.
|
|
126
|
-
"@astryxdesign/lab": "0.7.0-canary.
|
|
127
|
-
"@astryxdesign/theme-neutral": "0.7.0-canary.
|
|
124
|
+
"@astryxdesign/charts": "0.7.0-canary.eaca8eb",
|
|
125
|
+
"@astryxdesign/core": "0.7.0-canary.eaca8eb",
|
|
126
|
+
"@astryxdesign/lab": "0.7.0-canary.eaca8eb",
|
|
127
|
+
"@astryxdesign/theme-neutral": "0.7.0-canary.eaca8eb",
|
|
128
128
|
"@heroicons/react": "^2.2.0",
|
|
129
129
|
"@stylexjs/stylex": "^0.19.0",
|
|
130
130
|
"@types/babel__core": "^7.20.5",
|