@astryxdesign/cli 0.6.5-canary.f261d2f → 0.6.5-canary.f27f749
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 +14 -13
- package/api/error.d.mts +22 -0
- package/api/error.mjs +42 -0
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-theme.mjs +243 -22
- package/api/integration/add-theme.test.mjs +213 -0
- package/api/integration/authoring-checks.mjs +10 -7
- package/api/integration/authoring-checks.type.d.mts +8 -0
- package/api/integration/authoring-checks.type.mjs +7 -3
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/validate-integration.d.mts +4 -2
- package/api/integration/validate-integration.mjs +7 -2
- package/api/integration/validate-integration.test.mjs +55 -0
- package/api/integration/validate-integration.type.d.mts +5 -0
- package/api/integration/validate-integration.type.mjs +5 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/swizzle/copy/copy.mjs +66 -3
- package/api/swizzle/swizzle.doc.mjs +4 -0
- package/api/template/copy/copy.mjs +14 -8
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/show/show.mjs +15 -4
- package/api/template/show/show.test.mjs +76 -0
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +6 -2
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +2 -0
- package/api/template/template.type.mjs +2 -0
- package/api/theme/build/build.d.mts +24 -0
- package/api/theme/build/build.mjs +235 -8
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/upgrade/run/run.mjs +20 -3
- package/api/upgrade/run/run.test.mjs +45 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +1 -0
- package/api/upgrade/upgrade.type.mjs +1 -0
- package/assets/docs/icons.doc.mjs +1 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-expand.doc.mjs +3 -1
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +16 -0
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +19 -5
- package/clients/cli/commands/template.show-media.test.mjs +62 -0
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
- package/clients/cli/commands/write-failure.test.mjs +175 -0
- package/clients/cli/lib/manifest.mjs +44 -165
- package/clients/cli/lib/manifest.test.mjs +98 -7
- package/foundation/discovery/template-adapter.d.mts +13 -0
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
- package/foundation/discovery/template-adapter.mjs +16 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +13 -13
- package/package.json +9 -9
|
@@ -45,7 +45,11 @@ import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
|
45
45
|
import {parse} from '@babel/parser';
|
|
46
46
|
import {createJiti} from 'jiti';
|
|
47
47
|
import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
|
|
48
|
-
import {
|
|
48
|
+
import {
|
|
49
|
+
CLI_ROOT,
|
|
50
|
+
findCoreDir,
|
|
51
|
+
findInstalledPackage,
|
|
52
|
+
} from '../../../foundation/fs/paths.mjs';
|
|
49
53
|
import {
|
|
50
54
|
assertWithin,
|
|
51
55
|
sanitizeName,
|
|
@@ -125,6 +129,232 @@ try {
|
|
|
125
129
|
_coreImportError = e;
|
|
126
130
|
}
|
|
127
131
|
|
|
132
|
+
/**
|
|
133
|
+
* The bindings one Core provides: the namespaces interception spreads, the
|
|
134
|
+
* functions the build calls, and why the import failed, if it did.
|
|
135
|
+
* @typedef {{
|
|
136
|
+
* themeModule: any,
|
|
137
|
+
* rootModule: any,
|
|
138
|
+
* importError: any,
|
|
139
|
+
* defineTheme: any,
|
|
140
|
+
* generateThemeRulesSplit: any,
|
|
141
|
+
* generateOnMediaCSS: any,
|
|
142
|
+
* generateAdaptationCSS: any,
|
|
143
|
+
* dataTokenDefaults: any,
|
|
144
|
+
* }} CoreBindings
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The bindings exactly as the CLI's own import left them, kept so each build
|
|
149
|
+
* can choose between them and the project's installed Core.
|
|
150
|
+
* @type {CoreBindings}
|
|
151
|
+
*/
|
|
152
|
+
const _cliCore = {
|
|
153
|
+
themeModule: _coreThemeModule,
|
|
154
|
+
rootModule: _coreRootModule,
|
|
155
|
+
importError: _coreImportError,
|
|
156
|
+
defineTheme: _defineTheme,
|
|
157
|
+
generateThemeRulesSplit: _generateThemeRulesSplit,
|
|
158
|
+
generateOnMediaCSS: _generateOnMediaCSS,
|
|
159
|
+
generateAdaptationCSS: _generateAdaptationCSS,
|
|
160
|
+
dataTokenDefaults: _dataTokenDefaults,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Point the build at one Core: the module-level bindings every step reads.
|
|
165
|
+
* @param {CoreBindings} core
|
|
166
|
+
*/
|
|
167
|
+
function setCore(core) {
|
|
168
|
+
_coreThemeModule = core.themeModule;
|
|
169
|
+
_coreRootModule = core.rootModule;
|
|
170
|
+
_coreImportError = core.importError;
|
|
171
|
+
_defineTheme = core.defineTheme;
|
|
172
|
+
_generateThemeRulesSplit = core.generateThemeRulesSplit;
|
|
173
|
+
_generateOnMediaCSS = core.generateOnMediaCSS;
|
|
174
|
+
_generateAdaptationCSS = core.generateAdaptationCSS;
|
|
175
|
+
_dataTokenDefaults = core.dataTokenDefaults;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* The file an `import` of `subpath` reaches through a package's `exports` map,
|
|
180
|
+
* or null when the map has no entry for it. Conditions are taken in the map's
|
|
181
|
+
* own order, as Node does, accepting the ones an import matches here: `node`,
|
|
182
|
+
* `import`, and `default` (so `source` and `types` are skipped).
|
|
183
|
+
*
|
|
184
|
+
* @param {string} dir - The package directory.
|
|
185
|
+
* @param {string} subpath - `'.'` or a subpath such as `'./theme'`.
|
|
186
|
+
* @returns {string|null}
|
|
187
|
+
*/
|
|
188
|
+
function importTarget(dir, subpath) {
|
|
189
|
+
let pkg;
|
|
190
|
+
try {
|
|
191
|
+
pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'));
|
|
192
|
+
} catch {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
const map = pkg?.exports;
|
|
196
|
+
const bySubpath =
|
|
197
|
+
map &&
|
|
198
|
+
typeof map === 'object' &&
|
|
199
|
+
!Array.isArray(map) &&
|
|
200
|
+
Object.keys(map).some(key => key.startsWith('.'));
|
|
201
|
+
const entry = bySubpath ? map[subpath] : subpath === '.' ? map : undefined;
|
|
202
|
+
/** @param {any} value @returns {string|null} */
|
|
203
|
+
const pick = value => {
|
|
204
|
+
if (typeof value === 'string') return value;
|
|
205
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
206
|
+
return null;
|
|
207
|
+
for (const [condition, target] of Object.entries(value)) {
|
|
208
|
+
if (
|
|
209
|
+
condition !== 'node' &&
|
|
210
|
+
condition !== 'import' &&
|
|
211
|
+
condition !== 'default'
|
|
212
|
+
)
|
|
213
|
+
continue;
|
|
214
|
+
const picked = pick(target);
|
|
215
|
+
if (picked) return picked;
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
};
|
|
219
|
+
const target = pick(entry);
|
|
220
|
+
return target ? path.resolve(dir, target) : null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** @param {string} file @returns {string} its real path, or itself */
|
|
224
|
+
function realOrSelf(file) {
|
|
225
|
+
try {
|
|
226
|
+
return fs.realpathSync(file);
|
|
227
|
+
} catch {
|
|
228
|
+
return file;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The Core the project at `cwd` installed, when it differs from the one the
|
|
234
|
+
* CLI's own import found and loads. The app's `<Theme>` runs on the app's
|
|
235
|
+
* Core, so building with it keeps the CSS identical; and a CLI run one-off
|
|
236
|
+
* (`npx @astryxdesign/cli`) has no Core beside it at all. Null when there is
|
|
237
|
+
* nothing better than the CLI's own import: no installed Core (the Astryx
|
|
238
|
+
* repository, a bare directory), the same Core, or one that does not load.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} cwd
|
|
241
|
+
* @returns {Promise<CoreBindings | null>}
|
|
242
|
+
*/
|
|
243
|
+
async function loadProjectCore(cwd) {
|
|
244
|
+
const dir = findInstalledPackage(cwd, '@astryxdesign/core');
|
|
245
|
+
const themeFile = dir ? importTarget(dir, './theme') : null;
|
|
246
|
+
if (!dir || !themeFile) return null;
|
|
247
|
+
if (_cliCore.themeModule) {
|
|
248
|
+
try {
|
|
249
|
+
const own = fileURLToPath(
|
|
250
|
+
import.meta.resolve('@astryxdesign/core/theme'),
|
|
251
|
+
);
|
|
252
|
+
if (realOrSelf(own) === realOrSelf(themeFile)) return null;
|
|
253
|
+
} catch {
|
|
254
|
+
// The CLI's own Core cannot be located; load the project's.
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
let themeModule;
|
|
258
|
+
try {
|
|
259
|
+
themeModule = await import(pathToFileURL(themeFile).href);
|
|
260
|
+
} catch {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
if (!themeModule.defineTheme || !themeModule.generateThemeRulesSplit)
|
|
264
|
+
return null;
|
|
265
|
+
let rootModule = null;
|
|
266
|
+
const rootFile = importTarget(dir, '.');
|
|
267
|
+
if (rootFile) {
|
|
268
|
+
try {
|
|
269
|
+
rootModule = await import(pathToFileURL(rootFile).href);
|
|
270
|
+
} catch {
|
|
271
|
+
// As with the CLI's own import, the theme namespace stands in for it.
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
themeModule,
|
|
276
|
+
rootModule,
|
|
277
|
+
importError: null,
|
|
278
|
+
defineTheme: themeModule.defineTheme,
|
|
279
|
+
generateThemeRulesSplit: themeModule.generateThemeRulesSplit,
|
|
280
|
+
generateOnMediaCSS: themeModule.generateOnMediaCSS,
|
|
281
|
+
generateAdaptationCSS: themeModule.generateAdaptationCSS,
|
|
282
|
+
dataTokenDefaults: themeModule.dataTokenDefaults,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** @type {Map<string, Awaited<ReturnType<typeof loadProjectCore>>>} */
|
|
287
|
+
const _projectCores = new Map();
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Choose the Core this build generates with: the project's installed one when
|
|
291
|
+
* {@link loadProjectCore} finds it, else the CLI's own.
|
|
292
|
+
* @param {string} cwd
|
|
293
|
+
*/
|
|
294
|
+
async function selectCore(cwd) {
|
|
295
|
+
if (!_projectCores.has(cwd))
|
|
296
|
+
_projectCores.set(cwd, await loadProjectCore(cwd));
|
|
297
|
+
setCore(_projectCores.get(cwd) ?? _cliCore);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Whether `cwd` sits in the Astryx repository, where Core is built from
|
|
302
|
+
* source rather than installed.
|
|
303
|
+
* @param {string} cwd
|
|
304
|
+
*/
|
|
305
|
+
function inAstryxRepository(cwd) {
|
|
306
|
+
let dir = cwd;
|
|
307
|
+
for (let i = 0; i < 6; i++) {
|
|
308
|
+
try {
|
|
309
|
+
const pkg = JSON.parse(
|
|
310
|
+
fs.readFileSync(
|
|
311
|
+
path.join(dir, 'packages', 'core', 'package.json'),
|
|
312
|
+
'utf-8',
|
|
313
|
+
),
|
|
314
|
+
);
|
|
315
|
+
if (pkg?.name === '@astryxdesign/core') return true;
|
|
316
|
+
} catch {
|
|
317
|
+
// Not here; keep walking up.
|
|
318
|
+
}
|
|
319
|
+
const parent = path.dirname(dir);
|
|
320
|
+
if (parent === dir) break;
|
|
321
|
+
dir = parent;
|
|
322
|
+
}
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Why `theme build` has no Core to generate with, and the fix for where it
|
|
328
|
+
* ran: the Astryx repository builds Core, an app installs it, and an installed
|
|
329
|
+
* Core that will not load is named.
|
|
330
|
+
*
|
|
331
|
+
* @param {string} cwd
|
|
332
|
+
* @param {any} importError - Why the import failed, when it threw.
|
|
333
|
+
* @returns {string}
|
|
334
|
+
*/
|
|
335
|
+
export function coreUnavailableMessage(cwd, importError) {
|
|
336
|
+
const why =
|
|
337
|
+
'`astryx theme build` generates CSS with @astryxdesign/core, the same code the runtime <Theme> uses';
|
|
338
|
+
const detail = importError ? `\n Import error: ${importError.message}` : '';
|
|
339
|
+
if (inAstryxRepository(cwd)) {
|
|
340
|
+
return (
|
|
341
|
+
`Could not load @astryxdesign/core/theme: ${why}. Build @astryxdesign/core ` +
|
|
342
|
+
`first (e.g. \`pnpm -F @astryxdesign/core build\`).${detail}`
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
const installed = findInstalledPackage(cwd, '@astryxdesign/core');
|
|
346
|
+
if (installed) {
|
|
347
|
+
return (
|
|
348
|
+
`Could not load the @astryxdesign/core installed at ` +
|
|
349
|
+
`${path.relative(cwd, installed) || '.'}: ${why}. Reinstall it.${detail}`
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
return (
|
|
353
|
+
`This project does not have @astryxdesign/core installed: ${why}. Install ` +
|
|
354
|
+
`it: \`npm install @astryxdesign/core\` (or yarn/pnpm/bun).${detail}`
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
128
358
|
/**
|
|
129
359
|
* Read a package's `version` from a resolved directory. Returns `'unknown'`
|
|
130
360
|
* when it can't be read so the header always has a value.
|
|
@@ -2107,6 +2337,8 @@ async function themeBuildInternal(
|
|
|
2107
2337
|
|
|
2108
2338
|
logger.log(`\nBuilding theme from ${path.relative(cwd, filePath)}...`);
|
|
2109
2339
|
|
|
2340
|
+
await selectCore(cwd);
|
|
2341
|
+
|
|
2110
2342
|
// Standalone builds only need interception when an older Core could erase
|
|
2111
2343
|
// adaptations. Family preparation always supplies the same recorder as its
|
|
2112
2344
|
// shared loader so exact authored parent identity stays CLI-private instead
|
|
@@ -2233,13 +2465,7 @@ async function themeBuildInternal(
|
|
|
2233
2465
|
// capability exports are checked against what the theme actually asks for.
|
|
2234
2466
|
if (!_defineTheme || !_generateThemeRulesSplit) {
|
|
2235
2467
|
throw new AstryxError(
|
|
2236
|
-
|
|
2237
|
-
'built, resolvable @astryxdesign/core so it emits the same CSS as the ' +
|
|
2238
|
-
'runtime <Theme>. Build @astryxdesign/core first (e.g. `pnpm -F @astryxdesign/core ' +
|
|
2239
|
-
'build`)' +
|
|
2240
|
-
(_coreImportError
|
|
2241
|
-
? `.\n Import error: ${_coreImportError.message}`
|
|
2242
|
-
: '.'),
|
|
2468
|
+
coreUnavailableMessage(cwd, _coreImportError),
|
|
2243
2469
|
undefined,
|
|
2244
2470
|
ERROR_CODES.ERR_CORE_NOT_FOUND,
|
|
2245
2471
|
);
|
|
@@ -2807,6 +3033,7 @@ export async function themeBuildFamily(
|
|
|
2807
3033
|
error instanceof Error ? error.message : 'Invalid family key.';
|
|
2808
3034
|
throw new AstryxError(message, undefined, ERROR_CODES.ERR_THEME_INVALID);
|
|
2809
3035
|
}
|
|
3036
|
+
await selectCore(cwd);
|
|
2810
3037
|
const familyInterception = interceptCore(_coreThemeModule, _coreRootModule);
|
|
2811
3038
|
// prettier-ignore
|
|
2812
3039
|
const familyLoader = createJiti(import.meta.url, {moduleCache: true, interopDefault: false, jsx: true, extensions: THEME_MODULE_EXTENSIONS, virtualModules: familyInterception.modules});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `theme build` in an app generates with the Core the app installed.
|
|
5
|
+
*
|
|
6
|
+
* A CLI run one-off (`npx @astryxdesign/cli`) has no Core beside it, and the
|
|
7
|
+
* app's `<Theme>` runs on the app's Core either way, so the build loads the
|
|
8
|
+
* project's installed `@astryxdesign/core` when it differs from the CLI's own.
|
|
9
|
+
* When there is no Core to use, the error names the fix for where it ran:
|
|
10
|
+
* install it in an app, build it in the Astryx repository.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
14
|
+
import * as fs from 'node:fs';
|
|
15
|
+
import * as os from 'node:os';
|
|
16
|
+
import * as path from 'node:path';
|
|
17
|
+
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
18
|
+
import {coreUnavailableMessage, themeBuild} from './build.mjs';
|
|
19
|
+
|
|
20
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const REPO_ROOT = path.resolve(HERE, '../../../../..');
|
|
22
|
+
const CORE_DIST = path.join(REPO_ROOT, 'packages/core/dist');
|
|
23
|
+
|
|
24
|
+
/** @type {string[]} */
|
|
25
|
+
const tmpDirs = [];
|
|
26
|
+
const makeDir = () => {
|
|
27
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-project-core-'));
|
|
28
|
+
tmpDirs.push(dir);
|
|
29
|
+
fs.writeFileSync(
|
|
30
|
+
path.join(dir, 'package.json'),
|
|
31
|
+
'{"name":"app","type":"module"}',
|
|
32
|
+
);
|
|
33
|
+
// A plain theme object: the file itself never imports Core, so only the
|
|
34
|
+
// build's own Core loading can set the marker below.
|
|
35
|
+
fs.writeFileSync(
|
|
36
|
+
path.join(dir, 'ocean.mjs'),
|
|
37
|
+
"export default {name: 'ocean', tokens: {'--color-bg': '#0a0a0a'}};\n",
|
|
38
|
+
);
|
|
39
|
+
return dir;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
delete globalThis.__astryxProjectCoreLoads;
|
|
44
|
+
});
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
delete globalThis.__astryxProjectCoreLoads;
|
|
47
|
+
for (const dir of tmpDirs.splice(0))
|
|
48
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Install a Core in `dir` that is the built one, re-exported, and records each
|
|
53
|
+
* entry as it is imported. Its `exports` map lists `source` first, as Core's
|
|
54
|
+
* own does, so the build must skip that condition to find the runtime file.
|
|
55
|
+
* @param {string} dir
|
|
56
|
+
* @param {{broken?: boolean}} [options]
|
|
57
|
+
*/
|
|
58
|
+
function installCore(dir, {broken = false} = {}) {
|
|
59
|
+
const core = path.join(dir, 'node_modules', '@astryxdesign', 'core');
|
|
60
|
+
fs.mkdirSync(core, {recursive: true});
|
|
61
|
+
fs.writeFileSync(
|
|
62
|
+
path.join(core, 'package.json'),
|
|
63
|
+
JSON.stringify({
|
|
64
|
+
name: '@astryxdesign/core',
|
|
65
|
+
version: '0.6.5',
|
|
66
|
+
type: 'module',
|
|
67
|
+
exports: {
|
|
68
|
+
'.': {types: './root.d.ts', default: './root.mjs'},
|
|
69
|
+
'./theme': {
|
|
70
|
+
source: './src/theme/index.ts',
|
|
71
|
+
types: './theme.d.ts',
|
|
72
|
+
default: './theme.mjs',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
/** @param {string} entry @param {string} target */
|
|
78
|
+
const module = (entry, target) =>
|
|
79
|
+
broken
|
|
80
|
+
? "throw new Error('this Core is broken');\n"
|
|
81
|
+
: `export * from ${JSON.stringify(pathToFileURL(path.join(CORE_DIST, target)).href)};\n` +
|
|
82
|
+
`globalThis.__astryxProjectCoreLoads = [...(globalThis.__astryxProjectCoreLoads ?? []), '${entry}'];\n`;
|
|
83
|
+
fs.writeFileSync(
|
|
84
|
+
path.join(core, 'theme.mjs'),
|
|
85
|
+
module('theme', 'theme/index.js'),
|
|
86
|
+
);
|
|
87
|
+
fs.writeFileSync(path.join(core, 'root.mjs'), module('root', 'index.js'));
|
|
88
|
+
return core;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
describe('theme build generates with the Core the project installed', () => {
|
|
92
|
+
it('loads the app’s installed Core when it differs from the CLI’s own', async () => {
|
|
93
|
+
const app = makeDir();
|
|
94
|
+
installCore(app);
|
|
95
|
+
await themeBuild('ocean.mjs', {}, {cwd: app});
|
|
96
|
+
expect(globalThis.__astryxProjectCoreLoads).toEqual(['theme', 'root']);
|
|
97
|
+
// The same Core, re-exported, emits the same CSS as the CLI's own. The
|
|
98
|
+
// generated header differs only in the Core version it records.
|
|
99
|
+
const bare = makeDir();
|
|
100
|
+
await themeBuild('ocean.mjs', {}, {cwd: bare});
|
|
101
|
+
/** @param {string} dir */
|
|
102
|
+
const rules = dir =>
|
|
103
|
+
fs
|
|
104
|
+
.readFileSync(path.join(dir, 'ocean.css'), 'utf-8')
|
|
105
|
+
.replace(/^\/\*[\s\S]*?\*\/\n/, '');
|
|
106
|
+
expect(rules(app)).toBe(rules(bare));
|
|
107
|
+
expect(rules(app)).toContain('#0a0a0a');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('keeps the CLI’s own Core when the project has none', async () => {
|
|
111
|
+
const bare = makeDir();
|
|
112
|
+
await themeBuild('ocean.mjs', {}, {cwd: bare});
|
|
113
|
+
expect(globalThis.__astryxProjectCoreLoads).toBeUndefined();
|
|
114
|
+
expect(fs.existsSync(path.join(bare, 'ocean.css'))).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('keeps the CLI’s own Core when the installed one does not load', async () => {
|
|
118
|
+
const app = makeDir();
|
|
119
|
+
installCore(app, {broken: true});
|
|
120
|
+
await themeBuild('ocean.mjs', {}, {cwd: app});
|
|
121
|
+
expect(fs.existsSync(path.join(app, 'ocean.css'))).toBe(true);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('the error when there is no Core to generate with', () => {
|
|
126
|
+
it('tells an app to install Core, not to build it', () => {
|
|
127
|
+
const app = makeDir();
|
|
128
|
+
const message = coreUnavailableMessage(
|
|
129
|
+
app,
|
|
130
|
+
new Error("Cannot find package '@astryxdesign/core'"),
|
|
131
|
+
);
|
|
132
|
+
expect(message).toContain(
|
|
133
|
+
'This project does not have @astryxdesign/core installed',
|
|
134
|
+
);
|
|
135
|
+
expect(message).toContain('`npm install @astryxdesign/core`');
|
|
136
|
+
expect(message).not.toContain('pnpm -F');
|
|
137
|
+
expect(message).toContain(
|
|
138
|
+
"Import error: Cannot find package '@astryxdesign/core'",
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('names an installed Core that does not load', () => {
|
|
143
|
+
const app = makeDir();
|
|
144
|
+
installCore(app, {broken: true});
|
|
145
|
+
const message = coreUnavailableMessage(
|
|
146
|
+
app,
|
|
147
|
+
new Error('this Core is broken'),
|
|
148
|
+
);
|
|
149
|
+
expect(message).toContain(
|
|
150
|
+
`Could not load the @astryxdesign/core installed at ${path.join('node_modules', '@astryxdesign', 'core')}`,
|
|
151
|
+
);
|
|
152
|
+
expect(message).toContain('Reinstall it.');
|
|
153
|
+
expect(message).not.toContain('pnpm -F');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('keeps the build instruction in the Astryx repository', () => {
|
|
157
|
+
const message = coreUnavailableMessage(
|
|
158
|
+
path.join(REPO_ROOT, 'packages', 'cli'),
|
|
159
|
+
undefined,
|
|
160
|
+
);
|
|
161
|
+
expect(message).toContain('Build @astryxdesign/core first');
|
|
162
|
+
expect(message).toContain('`pnpm -F @astryxdesign/core build`');
|
|
163
|
+
expect(message).not.toContain('Import error');
|
|
164
|
+
});
|
|
165
|
+
});
|
package/api/upgrade/run/run.mjs
CHANGED
|
@@ -137,6 +137,12 @@ export async function run(options = {}, {cwd = process.cwd()} = {}) {
|
|
|
137
137
|
}
|
|
138
138
|
const apply = options.apply ?? false;
|
|
139
139
|
|
|
140
|
+
// One fact about the resolved source directory, captured before anything
|
|
141
|
+
// runs. `--path` defaults to `./src`, so a project laid out as `app/` (or a
|
|
142
|
+
// typo) skips every code codemod; without this the receipt is byte-identical
|
|
143
|
+
// to a clean, fully migrated project.
|
|
144
|
+
const sourcePathFound = fs.existsSync(path_);
|
|
145
|
+
|
|
140
146
|
const currentVersion = /** @type {string} */ (options.from);
|
|
141
147
|
const installed = detectInstalledTargetVersion(cwd);
|
|
142
148
|
if (!installed) {
|
|
@@ -282,6 +288,7 @@ export async function run(options = {}, {cwd = process.cwd()} = {}) {
|
|
|
282
288
|
refreshed: false,
|
|
283
289
|
action: 'none',
|
|
284
290
|
},
|
|
291
|
+
sourcePathFound,
|
|
285
292
|
filesChanged: coreResult?.totalFilesChanged ?? 0,
|
|
286
293
|
transformsApplied: coreResult?.totalTransformsApplied ?? 0,
|
|
287
294
|
modifiedFiles: uniqueFiles(coreResult?.changedFiles).map(file =>
|
|
@@ -407,6 +414,12 @@ export async function run(options = {}, {cwd = process.cwd()} = {}) {
|
|
|
407
414
|
refreshed: false,
|
|
408
415
|
action: 'none',
|
|
409
416
|
}),
|
|
417
|
+
// A missing source directory is the one way this command can migrate
|
|
418
|
+
// nothing and still look complete: every codemod is skipped, filesChanged
|
|
419
|
+
// stays 0, and errors stays empty. The receipt carries the fact so a
|
|
420
|
+
// machine consumer can tell "nothing needed changing" from "nothing was
|
|
421
|
+
// ever read" — the human text says so via the runner's own error line.
|
|
422
|
+
sourcePathFound,
|
|
410
423
|
};
|
|
411
424
|
|
|
412
425
|
let integrationResult = null;
|
|
@@ -642,12 +655,16 @@ export async function run(options = {}, {cwd = process.cwd()} = {}) {
|
|
|
642
655
|
}
|
|
643
656
|
|
|
644
657
|
const registryOk = receipt.registryCompositions?.ok ?? true;
|
|
658
|
+
const done = apply ? 'Upgrade complete' : 'Dry run complete';
|
|
645
659
|
logger.log(
|
|
646
660
|
protectedFiles.length > 0
|
|
647
661
|
? 'Upgrade incomplete: protected changes remain\n'
|
|
648
|
-
: registryOk
|
|
649
|
-
?
|
|
650
|
-
:
|
|
662
|
+
: !registryOk
|
|
663
|
+
? 'Upgrade finished with unresolved registry items\n'
|
|
664
|
+
: sourcePathFound
|
|
665
|
+
? done + '\n'
|
|
666
|
+
: `${done}, but ${path.relative(cwd, path_) || '.'} does not exist, so no source files were scanned. ` +
|
|
667
|
+
`Pass --path <your source directory> if your code does not live in ./src.\n`,
|
|
651
668
|
);
|
|
652
669
|
return {
|
|
653
670
|
type: 'upgrade.run',
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @file Colocated tests for the upgrade.run leaf — the --path scan dir must be
|
|
5
5
|
* confined to cwd (upgrade rewrites source in place with --apply, so an escaping
|
|
6
|
-
* or out-of-tree path must be rejected)
|
|
6
|
+
* or out-of-tree path must be rejected), and the receipt must say whether that
|
|
7
|
+
* dir existed at all.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
@@ -51,3 +52,46 @@ describe('upgrade.run — --path confinement', () => {
|
|
|
51
52
|
).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
|
|
52
53
|
}, SLOW);
|
|
53
54
|
});
|
|
55
|
+
|
|
56
|
+
describe('upgrade.run — sourcePathFound', () => {
|
|
57
|
+
let dir;
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'upg-srcpath-'));
|
|
60
|
+
seedProject(dir);
|
|
61
|
+
});
|
|
62
|
+
afterEach(() => fs.rmSync(dir, {recursive: true, force: true}));
|
|
63
|
+
|
|
64
|
+
// The receipt for a project whose source lives somewhere other than ./src was
|
|
65
|
+
// byte-identical to a fully migrated one: exit 0, filesChanged 0, errors [].
|
|
66
|
+
// The only signal was a human log line --json suppresses by design.
|
|
67
|
+
it('reports false when the resolved source directory is missing, and still counts nothing', async () => {
|
|
68
|
+
fs.rmSync(path.join(dir, 'src'), {recursive: true, force: true});
|
|
69
|
+
fs.mkdirSync(path.join(dir, 'app'), {recursive: true});
|
|
70
|
+
fs.writeFileSync(path.join(dir, 'app', 'index.ts'), 'const x = 1;\n');
|
|
71
|
+
|
|
72
|
+
const res = await upgrade({from: '0.0.1', apply: true}, {cwd: dir});
|
|
73
|
+
|
|
74
|
+
expect(res.type).toBe('upgrade.run');
|
|
75
|
+
expect(res.data.sourcePathFound).toBe(false);
|
|
76
|
+
expect(res.data.filesChanged).toBe(0);
|
|
77
|
+
expect(res.data.errors).toEqual([]);
|
|
78
|
+
}, SLOW);
|
|
79
|
+
|
|
80
|
+
it('reports true for a source directory that exists', async () => {
|
|
81
|
+
const res = await upgrade({from: '0.0.1', apply: true}, {cwd: dir});
|
|
82
|
+
|
|
83
|
+
expect(res.type).toBe('upgrade.run');
|
|
84
|
+
expect(res.data.sourcePathFound).toBe(true);
|
|
85
|
+
}, SLOW);
|
|
86
|
+
|
|
87
|
+
it('follows --path, so the right directory under another name reports true', async () => {
|
|
88
|
+
fs.rmSync(path.join(dir, 'src'), {recursive: true, force: true});
|
|
89
|
+
fs.mkdirSync(path.join(dir, 'app'), {recursive: true});
|
|
90
|
+
fs.writeFileSync(path.join(dir, 'app', 'index.ts'), 'const x = 1;\n');
|
|
91
|
+
|
|
92
|
+
const res = await upgrade({from: '0.0.1', path: 'app'}, {cwd: dir});
|
|
93
|
+
|
|
94
|
+
expect(res.type).toBe('upgrade.run');
|
|
95
|
+
expect(res.data.sourcePathFound).toBe(true);
|
|
96
|
+
}, SLOW);
|
|
97
|
+
});
|
|
@@ -123,7 +123,7 @@ export const doc = {
|
|
|
123
123
|
{
|
|
124
124
|
type: 'upgrade.run',
|
|
125
125
|
description:
|
|
126
|
-
'The terminal run receipt: from, to, codemods (count), integrations, agentDocs, agentDocsRefreshed, registryCompositions (when receipts are found), filesChanged, transformsApplied, modifiedFiles, protectedFiles, declinedCandidates, errors, and complete. When a protected file still requires a change, complete is false and errorCode is ERR_CODEMOD_PROTECTED; the CLI exits nonzero while preserving the structured receipt.',
|
|
126
|
+
'The terminal run receipt: from, to, codemods (count), integrations, agentDocs, agentDocsRefreshed, registryCompositions (when receipts are found), sourcePathFound (false when the resolved `path` does not exist, so nothing was scanned), filesChanged, transformsApplied, modifiedFiles, protectedFiles, declinedCandidates, errors, and complete. When a protected file still requires a change, complete is false and errorCode is ERR_CODEMOD_PROTECTED; the CLI exits nonzero while preserving the structured receipt.',
|
|
127
127
|
},
|
|
128
128
|
],
|
|
129
129
|
throws: [
|
|
@@ -168,6 +168,7 @@ export type UpgradeRunResponse = {
|
|
|
168
168
|
integrations: string[];
|
|
169
169
|
agentDocsRefreshed: boolean;
|
|
170
170
|
agentDocs: AgentDocsSummary;
|
|
171
|
+
sourcePathFound: boolean;
|
|
171
172
|
registryCompositions?: RegistryCompositionSummary | undefined;
|
|
172
173
|
complete?: boolean | undefined;
|
|
173
174
|
errorCode?: "ERR_CODEMOD_PROTECTED" | undefined;
|
|
@@ -116,6 +116,7 @@
|
|
|
116
116
|
* @property {string[]} data.integrations Integration packages processed in this upgrade (by name/spec).
|
|
117
117
|
* @property {boolean} data.agentDocsRefreshed
|
|
118
118
|
* @property {AgentDocsSummary} data.agentDocs
|
|
119
|
+
* @property {boolean} data.sourcePathFound Whether the resolved source directory (`path`, default `./src`) exists. False means no source file was read, so a zero `filesChanged` says nothing about the project being migrated.
|
|
119
120
|
* @property {RegistryCompositionSummary} [data.registryCompositions]
|
|
120
121
|
* @property {boolean} [data.complete] False when protected required changes remain.
|
|
121
122
|
* @property {'ERR_CODEMOD_PROTECTED'} [data.errorCode] Stable incomplete-result code when complete is false.
|
|
@@ -42,6 +42,7 @@ export const docs = {
|
|
|
42
42
|
['menu', 'Hamburger menu, navigation toggle'],
|
|
43
43
|
['moreHorizontal', 'Overflow menu, additional actions'],
|
|
44
44
|
['search', 'Search inputs, find'],
|
|
45
|
+
['upload', 'Upload files or content'],
|
|
45
46
|
['arrowUp', 'Sort ascending, move up'],
|
|
46
47
|
['arrowDown', 'Sort descending, move down'],
|
|
47
48
|
['arrowsUpDown', 'Sortable column indicator'],
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
Menu,
|
|
32
32
|
MoreHorizontal,
|
|
33
33
|
Search,
|
|
34
|
+
Upload,
|
|
34
35
|
ArrowUp,
|
|
35
36
|
ArrowDown,
|
|
36
37
|
ArrowUpDown,
|
|
@@ -67,6 +68,7 @@ export const butterIconRegistry: IconRegistry = {
|
|
|
67
68
|
menu: <Menu {...iconProps} />,
|
|
68
69
|
moreHorizontal: <MoreHorizontal {...iconProps} />,
|
|
69
70
|
search: <Search {...iconProps} />,
|
|
71
|
+
upload: <Upload {...iconProps} />,
|
|
70
72
|
arrowUp: <ArrowUp {...iconProps} />,
|
|
71
73
|
arrowDown: <ArrowDown {...iconProps} />,
|
|
72
74
|
arrowsUpDown: <ArrowUpDown {...iconProps} />,
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
Menu,
|
|
32
32
|
MoreHorizontal,
|
|
33
33
|
Search,
|
|
34
|
+
Upload,
|
|
34
35
|
ArrowUp,
|
|
35
36
|
ArrowDown,
|
|
36
37
|
ArrowUpDown,
|
|
@@ -67,6 +68,7 @@ export const chocolateIconRegistry: IconRegistry = {
|
|
|
67
68
|
menu: <Menu {...iconProps} />,
|
|
68
69
|
moreHorizontal: <MoreHorizontal {...iconProps} />,
|
|
69
70
|
search: <Search {...iconProps} />,
|
|
71
|
+
upload: <Upload {...iconProps} />,
|
|
70
72
|
arrowUp: <ArrowUp {...iconProps} />,
|
|
71
73
|
arrowDown: <ArrowDown {...iconProps} />,
|
|
72
74
|
arrowsUpDown: <ArrowUpDown {...iconProps} />,
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
Menu,
|
|
32
32
|
MoreHorizontal,
|
|
33
33
|
Search,
|
|
34
|
+
Upload,
|
|
34
35
|
ArrowUp,
|
|
35
36
|
ArrowDown,
|
|
36
37
|
ArrowUpDown,
|
|
@@ -67,6 +68,7 @@ export const gothicIconRegistry: IconRegistry = {
|
|
|
67
68
|
menu: <Menu {...iconProps} />,
|
|
68
69
|
moreHorizontal: <MoreHorizontal {...iconProps} />,
|
|
69
70
|
search: <Search {...iconProps} />,
|
|
71
|
+
upload: <Upload {...iconProps} />,
|
|
70
72
|
arrowUp: <ArrowUp {...iconProps} />,
|
|
71
73
|
arrowDown: <ArrowDown {...iconProps} />,
|
|
72
74
|
arrowsUpDown: <ArrowUpDown {...iconProps} />,
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
Menu,
|
|
22
22
|
MoreHorizontal,
|
|
23
23
|
Search,
|
|
24
|
+
Upload,
|
|
24
25
|
ArrowUp,
|
|
25
26
|
ArrowDown,
|
|
26
27
|
ArrowUpDown,
|
|
@@ -57,6 +58,7 @@ export const matchaIconRegistry: IconRegistry = {
|
|
|
57
58
|
menu: <Menu {...iconProps} />,
|
|
58
59
|
moreHorizontal: <MoreHorizontal {...iconProps} />,
|
|
59
60
|
search: <Search {...iconProps} />,
|
|
61
|
+
upload: <Upload {...iconProps} />,
|
|
60
62
|
arrowUp: <ArrowUp {...iconProps} />,
|
|
61
63
|
arrowDown: <ArrowDown {...iconProps} />,
|
|
62
64
|
arrowsUpDown: <ArrowUpDown {...iconProps} />,
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
Menu,
|
|
32
32
|
MoreHorizontal,
|
|
33
33
|
Search,
|
|
34
|
+
Upload,
|
|
34
35
|
ArrowUp,
|
|
35
36
|
ArrowDown,
|
|
36
37
|
ArrowUpDown,
|
|
@@ -67,6 +68,7 @@ export const neutralIconRegistry: IconRegistry = {
|
|
|
67
68
|
menu: <Menu {...iconProps} />,
|
|
68
69
|
moreHorizontal: <MoreHorizontal {...iconProps} />,
|
|
69
70
|
search: <Search {...iconProps} />,
|
|
71
|
+
upload: <Upload {...iconProps} />,
|
|
70
72
|
arrowUp: <ArrowUp {...iconProps} />,
|
|
71
73
|
arrowDown: <ArrowDown {...iconProps} />,
|
|
72
74
|
arrowsUpDown: <ArrowUpDown {...iconProps} />,
|