@astryxdesign/cli 0.7.15-canary.gf890983 → 0.7.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +353 -3
- package/api/doctor/_adapter.d.mts +2 -1
- package/api/doctor/_adapter.mjs +6 -1
- package/api/doctor/doctor.mjs +2 -2
- package/api/doctor/theme-checks.mjs +56 -21
- package/api/integration/add-helpers.mjs +5 -0
- package/api/integration/add-theme.mjs +15 -110
- package/api/theme/_adapter.d.mts +37 -5
- package/api/theme/_adapter.mjs +363 -50
- package/api/theme/_fork.d.mts +90 -0
- package/api/theme/_fork.mjs +246 -0
- package/api/theme/build/build.d.mts +25 -1
- package/api/theme/build/build.mjs +352 -41
- package/api/theme/eject/eject.mjs +36 -15
- package/api/theme/list/list.mjs +3 -6
- package/api/theme/palette/generate/generator.d.mts +13 -0
- package/api/theme/palette/generate/generator.mjs +32 -2
- package/api/theme/targets/targets.mjs +10 -3
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +2 -2
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.mjs +157 -36
- package/api/theme-edit/_catalog.d.mts +1 -6
- package/api/theme-edit/_catalog.mjs +5 -268
- package/api/theme-edit/_check.d.mts +3 -1
- package/api/theme-edit/_check.mjs +733 -308
- package/api/theme-edit/_color.d.mts +19 -0
- package/api/theme-edit/_color.mjs +277 -33
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +25 -0
- package/api/theme-edit/_context.d.mts +2 -0
- package/api/theme-edit/_context.mjs +83 -9
- package/api/theme-edit/_css.d.mts +84 -0
- package/api/theme-edit/_css.mjs +700 -0
- package/api/theme-edit/_edit.mjs +370 -85
- package/api/theme-edit/_how-commands.d.mts +5 -0
- package/api/theme-edit/_how-commands.mjs +20 -13
- package/api/theme-edit/_how-question.d.mts +29 -0
- package/api/theme-edit/_how-question.mjs +1573 -182
- package/api/theme-edit/_how.mjs +306 -22
- package/api/theme-edit/_overview.mjs +2 -7
- package/api/theme-edit/_palette.d.mts +27 -5
- package/api/theme-edit/_palette.mjs +231 -97
- package/api/theme-edit/_parts.d.mts +42 -10
- package/api/theme-edit/_parts.mjs +224 -69
- package/api/theme-edit/_preview-app.d.mts +8 -0
- package/api/theme-edit/_preview-app.mjs +549 -96
- package/api/theme-edit/_preview.d.mts +7 -16
- package/api/theme-edit/_preview.mjs +77 -84
- package/api/theme-edit/_project.d.mts +20 -1
- package/api/theme-edit/_project.mjs +43 -13
- package/api/theme-edit/_settings.d.mts +96 -20
- package/api/theme-edit/_settings.mjs +646 -141
- package/api/theme-edit/_tables.d.mts +18 -12
- package/api/theme-edit/_tables.mjs +144 -147
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +3 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
- package/api/theme-edit/themeEditSet.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -0
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/index.mjs +10 -10
- package/clients/cli/commands/experimental/theme.mjs +22 -3
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/integration.mjs +8 -0
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +325 -48
- package/clients/cli/index.mjs +18 -3
- package/clients/cli/lib/cli-error.mjs +118 -3
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/config/project.mjs +34 -8
- package/foundation/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- package/foundation/discovery/template-needs.d.mts +13 -0
- package/foundation/discovery/template-needs.mjs +30 -15
- package/foundation/discovery/theme-discovery.mjs +14 -2
- package/foundation/discovery/theme-imports.d.mts +16 -0
- package/foundation/discovery/theme-imports.mjs +30 -2
- package/foundation/doc-compiler/import.mjs +10 -4
- package/foundation/fs/gather-cache.mjs +82 -23
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +7 -2
- package/foundation/integrations/autolink.d.mts +1 -24
- package/foundation/integrations/autolink.mjs +7 -60
- package/foundation/integrations/declared-dependencies.d.mts +27 -0
- package/foundation/integrations/declared-dependencies.mjs +73 -0
- package/foundation/integrations/may-have-integrations.d.mts +8 -0
- package/foundation/integrations/may-have-integrations.mjs +47 -0
- package/foundation/release/cache.d.mts +21 -2
- package/foundation/release/cache.mjs +48 -8
- package/foundation/release/folder-lock.d.mts +7 -0
- package/foundation/release/folder-lock.mjs +60 -26
- package/foundation/release/lock-lease.d.mts +2 -1
- package/foundation/release/lock-lease.mjs +7 -2
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +4 -4
- package/package.json +6 -6
- package/api/theme-edit/_css-properties.d.mts +0 -10
- package/api/theme-edit/_css-properties.mjs +0 -556
|
@@ -67,7 +67,12 @@ import {
|
|
|
67
67
|
discoverValidIntegrationComponents,
|
|
68
68
|
} from '../discovery/component-discovery.mjs';
|
|
69
69
|
import {resolveComponentReplacements} from '../discovery/component-replacement.mjs';
|
|
70
|
-
import {
|
|
70
|
+
import {
|
|
71
|
+
CLI_ROOT,
|
|
72
|
+
findCoreDir,
|
|
73
|
+
findPackageRoot,
|
|
74
|
+
findProjectCoreDir,
|
|
75
|
+
} from '../fs/paths.mjs';
|
|
71
76
|
import {
|
|
72
77
|
applyTemplateReplacements,
|
|
73
78
|
effectiveTemplateDiscovery,
|
|
@@ -96,6 +101,8 @@ import {
|
|
|
96
101
|
selectIntegrationCodemods,
|
|
97
102
|
} from '../../assets/codemods/integration-discovery.mjs';
|
|
98
103
|
import {validateLoadedIntegration} from '../integrations/validate-contributions.mjs';
|
|
104
|
+
import {persistedGather} from '../fs/gather-cache.mjs';
|
|
105
|
+
|
|
99
106
|
import {recordDeclaredCliCommands} from '../env/cli-command.mjs';
|
|
100
107
|
import {
|
|
101
108
|
hostedRun,
|
|
@@ -107,6 +114,12 @@ import {
|
|
|
107
114
|
configContentHash,
|
|
108
115
|
} from './config-cache.mjs';
|
|
109
116
|
|
|
117
|
+
/** Issues are plain records, kept as they are. */
|
|
118
|
+
const ISSUES_CODEC = {
|
|
119
|
+
encode: (/** @type {any} */ value) => value,
|
|
120
|
+
decode: (/** @type {any} */ value) => value,
|
|
121
|
+
};
|
|
122
|
+
|
|
110
123
|
export {CONFIG_BASENAMES, findConfigPath} from './config-path.mjs';
|
|
111
124
|
|
|
112
125
|
/**
|
|
@@ -326,8 +339,7 @@ function readPackageJson(dir) {
|
|
|
326
339
|
*/
|
|
327
340
|
|
|
328
341
|
/** Default issue tracker used when neither config nor integration routes one. */
|
|
329
|
-
export const DEFAULT_ISSUES_URL =
|
|
330
|
-
'https://github.com/meta/astryx/issues/new';
|
|
342
|
+
export const DEFAULT_ISSUES_URL = 'https://github.com/meta/astryx/issues/new';
|
|
331
343
|
|
|
332
344
|
/**
|
|
333
345
|
* Whether this project accepts `debug` handlers contributed by the
|
|
@@ -475,7 +487,10 @@ export class Project {
|
|
|
475
487
|
* @param {{cache?: import('./config-cache.mjs').ConfigCache, fresh?: boolean, core?: 'any' | 'project'}} [options]
|
|
476
488
|
* @returns {Promise<Project>}
|
|
477
489
|
*/
|
|
478
|
-
static async load(
|
|
490
|
+
static async load(
|
|
491
|
+
cwd = process.cwd(),
|
|
492
|
+
{cache, fresh = false, core = 'any'} = {},
|
|
493
|
+
) {
|
|
479
494
|
const resolvedCache = fresh
|
|
480
495
|
? new InMemoryConfigCache()
|
|
481
496
|
: (cache ?? new InMemoryConfigCache());
|
|
@@ -739,10 +754,21 @@ export class Project {
|
|
|
739
754
|
try {
|
|
740
755
|
// An experimental root is checked only in a project that opts in
|
|
741
756
|
// (spec:AST-017 FR27); the package's own checks read it either way.
|
|
742
|
-
const
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
757
|
+
const checked = this.#config.experimental?.iconSet
|
|
758
|
+
? integration
|
|
759
|
+
: {...integration, iconSets: undefined};
|
|
760
|
+
// A function of the files the checks read, which the kept gather
|
|
761
|
+
// stamps: a later run with every one unchanged reads the issues back.
|
|
762
|
+
const found = await persistedGather(
|
|
763
|
+
[
|
|
764
|
+
'integration-issues',
|
|
765
|
+
this.#cwd,
|
|
766
|
+
integration.__packageDir ?? null,
|
|
767
|
+
integration.name ?? null,
|
|
768
|
+
Boolean(this.#config.experimental?.iconSet),
|
|
769
|
+
],
|
|
770
|
+
() => validateLoadedIntegration(checked),
|
|
771
|
+
ISSUES_CODEC,
|
|
746
772
|
);
|
|
747
773
|
for (const issue of found ?? []) this.#pushIssue(pkg, issue);
|
|
748
774
|
} catch (err) {
|
|
@@ -130,6 +130,22 @@ export const THEME_MODULE_BASENAME: "astryx-themes";
|
|
|
130
130
|
export const THEME_MODULE_MARKER: "@generated by `astryx theme` \u2014 do not edit manually.";
|
|
131
131
|
export const THEME_RECORD_MARKER: "@astryx-theme-record";
|
|
132
132
|
export class ThemeStateError extends Error {
|
|
133
|
+
/**
|
|
134
|
+
* @param {string} message
|
|
135
|
+
* @param {{cause?: unknown, suggestions?: Array<{name: string, reason: string}>}} [options]
|
|
136
|
+
*/
|
|
137
|
+
constructor(message: string, options?: {
|
|
138
|
+
cause?: unknown;
|
|
139
|
+
suggestions?: Array<{
|
|
140
|
+
name: string;
|
|
141
|
+
reason: string;
|
|
142
|
+
}>;
|
|
143
|
+
});
|
|
144
|
+
/** Commands that move past the refusal. */
|
|
145
|
+
suggestions: {
|
|
146
|
+
name: string;
|
|
147
|
+
reason: string;
|
|
148
|
+
}[];
|
|
133
149
|
}
|
|
134
150
|
export type ThemeState = {
|
|
135
151
|
projectDir: string;
|
|
@@ -26,7 +26,54 @@ export const THEME_RECORD_MARKER = '@astryx-theme-record';
|
|
|
26
26
|
|
|
27
27
|
const THEME_SLUG_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
|
|
28
28
|
|
|
29
|
-
export class ThemeStateError extends Error {
|
|
29
|
+
export class ThemeStateError extends Error {
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} message
|
|
32
|
+
* @param {{cause?: unknown, suggestions?: Array<{name: string, reason: string}>}} [options]
|
|
33
|
+
*/
|
|
34
|
+
constructor(message, options = {}) {
|
|
35
|
+
super(
|
|
36
|
+
message,
|
|
37
|
+
options.cause === undefined ? undefined : {cause: options.cause},
|
|
38
|
+
);
|
|
39
|
+
/** Commands that move past the refusal. */
|
|
40
|
+
this.suggestions = options.suggestions ?? [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The refusal for a generated module whose record header cannot be read. No
|
|
46
|
+
* theme command can read the record to rewrite it, so the way out is to
|
|
47
|
+
* delete the module and add its themes again, named from its `themes` export.
|
|
48
|
+
* @param {string} label the module's project path
|
|
49
|
+
* @param {string} problem what is wrong with the header
|
|
50
|
+
* @param {string} source the module text
|
|
51
|
+
*/
|
|
52
|
+
function damagedRecordError(label, problem, source) {
|
|
53
|
+
const slugs = [
|
|
54
|
+
...source.matchAll(/^\s*"([a-z][a-z0-9-]*)":\s*_astryxTheme\d+,/gmu),
|
|
55
|
+
].map(match => match[1]);
|
|
56
|
+
const adds = (slugs.length > 0 ? slugs : ['<slug>']).map(slug =>
|
|
57
|
+
formatCliCommand(`theme add ${slug}`),
|
|
58
|
+
);
|
|
59
|
+
return new ThemeStateError(
|
|
60
|
+
`${label} ${problem}, so no theme command can read or rewrite it. Delete ${label}, then add its themes again: ${adds.map(add => `\`${add}\``).join(', ')}.`,
|
|
61
|
+
{
|
|
62
|
+
suggestions:
|
|
63
|
+
slugs.length > 0
|
|
64
|
+
? adds.map((name, index) => ({
|
|
65
|
+
name,
|
|
66
|
+
reason: `add ${slugs[index]} again once ${label} is deleted`,
|
|
67
|
+
}))
|
|
68
|
+
: [
|
|
69
|
+
{
|
|
70
|
+
name: formatCliCommand('theme list'),
|
|
71
|
+
reason: `the themes you can add, once ${label} is deleted`,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
}
|
|
30
77
|
|
|
31
78
|
/** @param {unknown} value @returns {value is Record<string, unknown>} */
|
|
32
79
|
function isRecord(value) {
|
|
@@ -123,10 +170,12 @@ export function themeModuleCandidates(projectDir) {
|
|
|
123
170
|
* @param {unknown} value
|
|
124
171
|
* @param {string} label
|
|
125
172
|
*/
|
|
126
|
-
function validThemeRecord(value, label) {
|
|
173
|
+
function validThemeRecord(value, label, source = '') {
|
|
127
174
|
if (!isRecord(value) || !isRecord(value.themes)) {
|
|
128
|
-
throw
|
|
129
|
-
|
|
175
|
+
throw damagedRecordError(
|
|
176
|
+
label,
|
|
177
|
+
`has no static ${THEME_RECORD_MARKER} header`,
|
|
178
|
+
source,
|
|
130
179
|
);
|
|
131
180
|
}
|
|
132
181
|
const keys = Object.keys(value);
|
|
@@ -158,8 +207,13 @@ function validThemeRecord(value, label) {
|
|
|
158
207
|
typeof value.defaultThemeSlug !== 'string' ||
|
|
159
208
|
!THEME_SLUG_RE.test(value.defaultThemeSlug)
|
|
160
209
|
) {
|
|
210
|
+
const first = Object.keys(themes)[0];
|
|
211
|
+
const use = formatCliCommand(`theme use ${first ?? '<slug>'}`);
|
|
161
212
|
throw new ThemeStateError(
|
|
162
|
-
`${label} defaultThemeSlug must be a lowercase kebab-case slug.
|
|
213
|
+
`${label} defaultThemeSlug must be a lowercase kebab-case slug. Choose a default with \`${use}\`.`,
|
|
214
|
+
first
|
|
215
|
+
? {suggestions: [{name: use, reason: `make ${first} the default`}]}
|
|
216
|
+
: {},
|
|
163
217
|
);
|
|
164
218
|
}
|
|
165
219
|
return {themes, defaultSlug: value.defaultThemeSlug};
|
|
@@ -178,8 +232,12 @@ export function parseThemeModuleRecord(source, label = 'theme module') {
|
|
|
178
232
|
.split(/\r?\n/u)
|
|
179
233
|
.filter(line => /^\s*\*\s*@astryx-theme-record\s+/u.test(line));
|
|
180
234
|
if (recordLines.length !== 1) {
|
|
181
|
-
throw
|
|
182
|
-
|
|
235
|
+
throw damagedRecordError(
|
|
236
|
+
label,
|
|
237
|
+
recordLines.length === 0
|
|
238
|
+
? `has no static ${THEME_RECORD_MARKER} header`
|
|
239
|
+
: `has more than one ${THEME_RECORD_MARKER} header`,
|
|
240
|
+
source,
|
|
183
241
|
);
|
|
184
242
|
}
|
|
185
243
|
const payload = recordLines[0].replace(
|
|
@@ -189,13 +247,14 @@ export function parseThemeModuleRecord(source, label = 'theme module') {
|
|
|
189
247
|
let record;
|
|
190
248
|
try {
|
|
191
249
|
record = JSON.parse(payload);
|
|
192
|
-
} catch
|
|
193
|
-
throw
|
|
194
|
-
|
|
195
|
-
{
|
|
250
|
+
} catch {
|
|
251
|
+
throw damagedRecordError(
|
|
252
|
+
label,
|
|
253
|
+
`has a ${THEME_RECORD_MARKER} header that is not valid JSON`,
|
|
254
|
+
source,
|
|
196
255
|
);
|
|
197
256
|
}
|
|
198
|
-
return validThemeRecord(record, label);
|
|
257
|
+
return validThemeRecord(record, label, source);
|
|
199
258
|
}
|
|
200
259
|
|
|
201
260
|
/**
|
|
@@ -234,6 +293,11 @@ export function resolveThemeModule(projectDir, {forWrite = false} = {}) {
|
|
|
234
293
|
}
|
|
235
294
|
}
|
|
236
295
|
let expectedOriginal;
|
|
296
|
+
if (fs.existsSync(file) && fs.statSync(file).isDirectory()) {
|
|
297
|
+
throw new ThemeStateError(
|
|
298
|
+
`${projectPath(path.relative(projectDir, file))} is a folder, where the generated theme module goes. Move or delete that folder, then run the same command again.`,
|
|
299
|
+
);
|
|
300
|
+
}
|
|
237
301
|
if (fs.existsSync(file)) {
|
|
238
302
|
expectedOriginal = fs.readFileSync(file);
|
|
239
303
|
if (!expectedOriginal.toString('utf-8').includes(THEME_MODULE_MARKER)) {
|
|
@@ -337,8 +401,15 @@ export function readThemeState(cwd = process.cwd()) {
|
|
|
337
401
|
*/
|
|
338
402
|
export function renderThemeModule(themes, defaultSlug, typescript) {
|
|
339
403
|
if (!themes.some(theme => theme.slug === defaultSlug)) {
|
|
404
|
+
// The record's default names no added theme; choosing an added one as the
|
|
405
|
+
// default rewrites the record.
|
|
406
|
+
const first = themes[0]?.slug;
|
|
407
|
+
const use = formatCliCommand(`theme use ${first ?? '<slug>'}`);
|
|
340
408
|
throw new ThemeStateError(
|
|
341
|
-
`Default theme "${defaultSlug}" is not added.
|
|
409
|
+
`Default theme "${defaultSlug}" is not added. Choose an added theme as the default with \`${use}\`.`,
|
|
410
|
+
first
|
|
411
|
+
? {suggestions: [{name: use, reason: `make ${first} the default`}]}
|
|
412
|
+
: {},
|
|
342
413
|
);
|
|
343
414
|
}
|
|
344
415
|
/** @type {string[]} */
|
|
@@ -22,6 +22,19 @@ export function extractImportedPackages(source: string): Set<string>;
|
|
|
22
22
|
* @returns {string[]}
|
|
23
23
|
*/
|
|
24
24
|
export function parsedSpecifiers(source: string): string[];
|
|
25
|
+
/**
|
|
26
|
+
* The command that installs `packages` in the project at `cwd`, in its package
|
|
27
|
+
* manager and with the CLI workspace's version ranges. Null, with the reason,
|
|
28
|
+
* when several lockfiles leave the package manager undetermined; null with no
|
|
29
|
+
* reason when there is nothing to install.
|
|
30
|
+
* @param {string[]} packages
|
|
31
|
+
* @param {string} cwd
|
|
32
|
+
* @returns {{installCommand: string | null, noCommandReason: string | null}}
|
|
33
|
+
*/
|
|
34
|
+
export function installCommandFor(packages: string[], cwd: string): {
|
|
35
|
+
installCommand: string | null;
|
|
36
|
+
noCommandReason: string | null;
|
|
37
|
+
};
|
|
25
38
|
/**
|
|
26
39
|
* Analyze what a template source needs that the target project lacks.
|
|
27
40
|
*
|
|
@@ -245,6 +245,35 @@ function cliPackageRanges() {
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
/**
|
|
249
|
+
* The command that installs `packages` in the project at `cwd`, in its package
|
|
250
|
+
* manager and with the CLI workspace's version ranges. Null, with the reason,
|
|
251
|
+
* when several lockfiles leave the package manager undetermined; null with no
|
|
252
|
+
* reason when there is nothing to install.
|
|
253
|
+
* @param {string[]} packages
|
|
254
|
+
* @param {string} cwd
|
|
255
|
+
* @returns {{installCommand: string | null, noCommandReason: string | null}}
|
|
256
|
+
*/
|
|
257
|
+
export function installCommandFor(packages, cwd) {
|
|
258
|
+
if (packages.length === 0) {
|
|
259
|
+
return {installCommand: null, noCommandReason: null};
|
|
260
|
+
}
|
|
261
|
+
const resolved = resolveInstallVerb(cwd);
|
|
262
|
+
const ranges = cliPackageRanges();
|
|
263
|
+
const specs = packages.map(p => (ranges[p] ? `${p}@"${ranges[p]}"` : p));
|
|
264
|
+
if (resolved.verb !== null) {
|
|
265
|
+
return {
|
|
266
|
+
installCommand: `${resolved.verb} ${specs.join(' ')}`,
|
|
267
|
+
noCommandReason: null,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
const where = path.relative(cwd, resolved.dir) || '.';
|
|
271
|
+
return {
|
|
272
|
+
installCommand: null,
|
|
273
|
+
noCommandReason: `Install missing dependencies: ${specs.join(' ')}. No install command: ${where} has ${resolved.lockfiles.join(' and ')}, and nothing there says which package manager to use.`,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
248
277
|
/**
|
|
249
278
|
* Analyze what a template source needs that the target project lacks.
|
|
250
279
|
*
|
|
@@ -285,21 +314,7 @@ export function analyzeTemplateNeeds(source, cwd) {
|
|
|
285
314
|
|
|
286
315
|
const missing = external.filter(p => !(p in projectDeps));
|
|
287
316
|
|
|
288
|
-
|
|
289
|
-
let installCommand = null;
|
|
290
|
-
/** @type {string | null} */
|
|
291
|
-
let noCommandReason = null;
|
|
292
|
-
if (missing.length > 0) {
|
|
293
|
-
const resolved = resolveInstallVerb(cwd);
|
|
294
|
-
const ranges = cliPackageRanges();
|
|
295
|
-
const specs = missing.map(p => (ranges[p] ? `${p}@"${ranges[p]}"` : p));
|
|
296
|
-
if (resolved.verb !== null) {
|
|
297
|
-
installCommand = `${resolved.verb} ${specs.join(' ')}`;
|
|
298
|
-
} else {
|
|
299
|
-
const where = path.relative(cwd, resolved.dir) || '.';
|
|
300
|
-
noCommandReason = `Install missing dependencies: ${specs.join(' ')}. No install command: ${where} has ${resolved.lockfiles.join(' and ')}, and nothing there says which package manager to use.`;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
317
|
+
const {installCommand, noCommandReason} = installCommandFor(missing, cwd);
|
|
303
318
|
|
|
304
319
|
// ── StyleX compiler ────────────────────────────────────────────────────
|
|
305
320
|
const usesStylex = imported.has(STYLEX_RUNTIME);
|
|
@@ -1372,8 +1372,20 @@ export function discoverThemeDirectory(
|
|
|
1372
1372
|
entry => entry.isFile() && entry.name.endsWith(THEME_DOC_SUFFIX),
|
|
1373
1373
|
);
|
|
1374
1374
|
if (rootDescriptor) {
|
|
1375
|
+
const stem = rootDescriptor.name
|
|
1376
|
+
.slice(0, -THEME_DOC_SUFFIX.length)
|
|
1377
|
+
.replace(/Theme$/, '');
|
|
1378
|
+
// The folder is under the theme root on disk. The owner names that
|
|
1379
|
+
// root only for the project's own local themes; a package's root is
|
|
1380
|
+
// named by its path.
|
|
1381
|
+
const slug =
|
|
1382
|
+
stem.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase() || '<slug>';
|
|
1383
|
+
const folder =
|
|
1384
|
+
owner === LOCAL_THEME_ROOT
|
|
1385
|
+
? `${owner}/${slug}`
|
|
1386
|
+
: path.join(themeRoot, slug).split(path.sep).join('/');
|
|
1375
1387
|
throw new Error(
|
|
1376
|
-
`Theme descriptor "${rootDescriptor.name}" for ${owner} must be inside a lower-kebab theme directory
|
|
1388
|
+
`Theme descriptor "${rootDescriptor.name}" for ${owner} must be inside a lower-kebab theme directory. Move that theme's files into their own folder, such as ${folder}/.`,
|
|
1377
1389
|
);
|
|
1378
1390
|
}
|
|
1379
1391
|
const rootSymlink = rootEntries.find(entry => entry.isSymbolicLink());
|
|
@@ -1484,7 +1496,7 @@ export function discoverThemeDirectory(
|
|
|
1484
1496
|
const doc = readThemeDoc(docPath, owner);
|
|
1485
1497
|
if (doc.name !== slug) {
|
|
1486
1498
|
throw new Error(
|
|
1487
|
-
`${label} names "${doc.name}" but its directory is "${slug}".`,
|
|
1499
|
+
`${label} names "${doc.name}" but its directory is "${slug}". A theme's folder carries its name: move its files into a folder named "${doc.name}".`,
|
|
1488
1500
|
);
|
|
1489
1501
|
}
|
|
1490
1502
|
const entry = sources[0];
|
|
@@ -12,4 +12,20 @@ export function resolveThemeImports(theme: import("./theme-discovery.mjs").Disco
|
|
|
12
12
|
ownerThemeCount?: number;
|
|
13
13
|
}): import("../config/theme-state.mjs").ResolvedAppTheme;
|
|
14
14
|
export class ThemeImportError extends Error {
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} message
|
|
17
|
+
* @param {{cause?: unknown, suggestions?: Array<{name: string, reason: string}>}} [options]
|
|
18
|
+
*/
|
|
19
|
+
constructor(message: string, options?: {
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
suggestions?: Array<{
|
|
22
|
+
name: string;
|
|
23
|
+
reason: string;
|
|
24
|
+
}>;
|
|
25
|
+
});
|
|
26
|
+
/** Commands that move past the refusal. */
|
|
27
|
+
suggestions: {
|
|
28
|
+
name: string;
|
|
29
|
+
reason: string;
|
|
30
|
+
}[];
|
|
15
31
|
}
|
|
@@ -20,8 +20,22 @@ import {inspectPackageExport} from './package-exports.mjs';
|
|
|
20
20
|
import {themeImportPackage} from './theme-discovery.mjs';
|
|
21
21
|
import {isLocalThemeOwner, projectPath} from '../config/theme-state.mjs';
|
|
22
22
|
import {formatCliCommand} from '../env/package-manager.mjs';
|
|
23
|
+
import {installCommandFor} from './template-needs.mjs';
|
|
23
24
|
|
|
24
|
-
export class ThemeImportError extends Error {
|
|
25
|
+
export class ThemeImportError extends Error {
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} message
|
|
28
|
+
* @param {{cause?: unknown, suggestions?: Array<{name: string, reason: string}>}} [options]
|
|
29
|
+
*/
|
|
30
|
+
constructor(message, options = {}) {
|
|
31
|
+
super(
|
|
32
|
+
message,
|
|
33
|
+
options.cause === undefined ? undefined : {cause: options.cause},
|
|
34
|
+
);
|
|
35
|
+
/** Commands that move past the refusal. */
|
|
36
|
+
this.suggestions = options.suggestions ?? [];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
25
39
|
|
|
26
40
|
/** @param {string} file */
|
|
27
41
|
function readPackage(file) {
|
|
@@ -133,8 +147,22 @@ function resolvePackageTheme(theme, cwd, ownerThemeCount) {
|
|
|
133
147
|
/** @type {any} */ (theme).packageDir ??
|
|
134
148
|
findInstalledPackage(cwd, importPackage);
|
|
135
149
|
if (!packageDir) {
|
|
150
|
+
// The app imports a theme from its package, bundled themes included, so
|
|
151
|
+
// the package is installed in the app before the theme is added.
|
|
152
|
+
const {installCommand} = installCommandFor([importPackage], cwd);
|
|
153
|
+
const add = formatCliCommand(`theme add ${theme.slug}`, cwd);
|
|
154
|
+
const install = installCommand ?? `npm install ${importPackage}`;
|
|
136
155
|
throw new ThemeImportError(
|
|
137
|
-
`Theme package "${importPackage}" is not installed.
|
|
156
|
+
`Theme package "${importPackage}" is not installed. The app imports ${theme.slug} from it, so install it, then add the theme: \`${install}\`, then \`${add}\`.`,
|
|
157
|
+
{
|
|
158
|
+
suggestions: [
|
|
159
|
+
{
|
|
160
|
+
name: install,
|
|
161
|
+
reason: `install ${importPackage}, which the app imports`,
|
|
162
|
+
},
|
|
163
|
+
{name: add, reason: 'add the theme once it is installed'},
|
|
164
|
+
],
|
|
165
|
+
},
|
|
138
166
|
);
|
|
139
167
|
}
|
|
140
168
|
const pkg = readPackage(path.join(packageDir, 'package.json'));
|
|
@@ -28,6 +28,7 @@ import * as fs from 'node:fs';
|
|
|
28
28
|
import {pathToFileURL} from 'node:url';
|
|
29
29
|
import {createRequire} from 'node:module';
|
|
30
30
|
import {importUrl} from '../fs/import-url.mjs';
|
|
31
|
+
import {jitiCacheOptions} from '../fs/jiti-cache.mjs';
|
|
31
32
|
import {
|
|
32
33
|
importUserModule,
|
|
33
34
|
readFreshInTurn,
|
|
@@ -195,16 +196,21 @@ export function importTemplateModule(file) {
|
|
|
195
196
|
'template',
|
|
196
197
|
first => {
|
|
197
198
|
if (first.endsWith('.ts')) {
|
|
198
|
-
jsxJiti ??= createJiti(import.meta.url, {
|
|
199
|
+
jsxJiti ??= createJiti(import.meta.url, {
|
|
200
|
+
...jitiCacheOptions(),
|
|
201
|
+
jsx: true,
|
|
202
|
+
});
|
|
199
203
|
return jsxJiti.import(first);
|
|
200
204
|
}
|
|
201
205
|
return importInTurn(first, `file://${first}`);
|
|
202
206
|
},
|
|
203
207
|
changed =>
|
|
204
208
|
changed.endsWith('.ts')
|
|
205
|
-
? createJiti(import.meta.url, {
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
? createJiti(import.meta.url, {
|
|
210
|
+
...jitiCacheOptions(),
|
|
211
|
+
jsx: true,
|
|
212
|
+
moduleCache: false,
|
|
213
|
+
}).import(changed)
|
|
208
214
|
: importFresh(changed),
|
|
209
215
|
);
|
|
210
216
|
}
|
|
@@ -12,9 +12,11 @@
|
|
|
12
12
|
* and every environment variable it read are as they were; otherwise it
|
|
13
13
|
* gathers fresh and stores that.
|
|
14
14
|
* @position Used by search's adapter (api/search/_adapter.mjs) for the
|
|
15
|
-
* catalog `search` and `build` rank
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* catalog `search` and `build` rank, and by the project
|
|
16
|
+
* (foundation/config/project.mjs) for each integration's contribution-check
|
|
17
|
+
* results, which `component`, `template`, `theme`, `discover` and `search`
|
|
18
|
+
* report. Gathers are kept only once the folder exists: the first such run
|
|
19
|
+
* on a machine just makes it, so a one-off run pays nothing to store one. Only a published CLI stores anything:
|
|
18
20
|
* its build id (clients/cli/build-id.generated.json, written at `prepack`)
|
|
19
21
|
* names its exact code, so a checkout, whose code may change between runs
|
|
20
22
|
* under the same version, always gathers.
|
|
@@ -34,8 +36,10 @@ import * as path from 'node:path';
|
|
|
34
36
|
import {fileURLToPath} from 'node:url';
|
|
35
37
|
import {isDeepStrictEqual} from 'node:util';
|
|
36
38
|
import {CLI_ROOT} from './paths.mjs';
|
|
39
|
+
import {mayHaveIntegrations} from '../integrations/may-have-integrations.mjs';
|
|
37
40
|
import {currentUid, isPrivateDir} from '../env/private-dir.mjs';
|
|
38
41
|
import {userCacheDir} from '../env/user-dirs.mjs';
|
|
42
|
+
import {jitiCacheDir} from './jiti-cache.mjs';
|
|
39
43
|
import {
|
|
40
44
|
fileStamp,
|
|
41
45
|
recordReads,
|
|
@@ -44,8 +48,26 @@ import {
|
|
|
44
48
|
withoutRecording,
|
|
45
49
|
} from './read-record.mjs';
|
|
46
50
|
|
|
51
|
+
/**
|
|
52
|
+
* The kept commands whose only kept gather is their integrations' check
|
|
53
|
+
* results: a project with no integration records none of them.
|
|
54
|
+
*/
|
|
55
|
+
const INTEGRATION_COMMANDS = new Set([
|
|
56
|
+
'component',
|
|
57
|
+
'template',
|
|
58
|
+
'theme',
|
|
59
|
+
'discover',
|
|
60
|
+
]);
|
|
61
|
+
|
|
47
62
|
/** The run's commands whose gathers are kept. */
|
|
48
|
-
const KEPT_COMMANDS = new Set([
|
|
63
|
+
const KEPT_COMMANDS = new Set([
|
|
64
|
+
'search',
|
|
65
|
+
'build',
|
|
66
|
+
'component',
|
|
67
|
+
'template',
|
|
68
|
+
'theme',
|
|
69
|
+
'discover',
|
|
70
|
+
]);
|
|
49
71
|
|
|
50
72
|
/** Where `prepack` writes the id of the package's exact contents. */
|
|
51
73
|
export const BUILD_ID_FILE = path.join(
|
|
@@ -96,6 +118,9 @@ let lastOutcome = null;
|
|
|
96
118
|
*/
|
|
97
119
|
let gatherCode = null;
|
|
98
120
|
|
|
121
|
+
/** How many persistedGather calls are running, nested inside one another. */
|
|
122
|
+
let gatherDepth = 0;
|
|
123
|
+
|
|
99
124
|
/**
|
|
100
125
|
* The outcome of the last kept gather in this process: whether it was a hit,
|
|
101
126
|
* and why it missed. Null when no kept gather ran.
|
|
@@ -114,12 +139,28 @@ export function gatherCacheOutcome() {
|
|
|
114
139
|
* @returns {boolean}
|
|
115
140
|
*/
|
|
116
141
|
function inJitiCache(file) {
|
|
142
|
+
jitiRoots ??= jitiCacheRoots();
|
|
143
|
+
return jitiRoots.some(
|
|
144
|
+
root => file === root || file.startsWith(root + path.sep),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** jiti's cache folders, worked out once per process (inJitiCache). */
|
|
149
|
+
/** @type {string[] | undefined} */
|
|
150
|
+
let jitiRoots;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Where jiti may keep transpiled code: the system temp folder's `jiti`, the
|
|
154
|
+
* per-user folder (jiti-cache.mjs), and a set JITI_FS_CACHE.
|
|
155
|
+
* @returns {string[]}
|
|
156
|
+
*/
|
|
157
|
+
function jitiCacheRoots() {
|
|
117
158
|
const env = process.env.JITI_FS_CACHE;
|
|
118
|
-
const roots = [path.join(os.tmpdir(), 'jiti')];
|
|
159
|
+
const roots = [path.join(os.tmpdir(), 'jiti'), jitiCacheDir()];
|
|
119
160
|
if (env && env !== 'false' && env !== 'true' && env !== '0' && env !== '1') {
|
|
120
161
|
roots.push(path.resolve(env));
|
|
121
162
|
}
|
|
122
|
-
return roots
|
|
163
|
+
return roots;
|
|
123
164
|
}
|
|
124
165
|
|
|
125
166
|
/**
|
|
@@ -186,12 +227,17 @@ export async function recordRunFor(argv, fn) {
|
|
|
186
227
|
!KEPT_COMMANDS.has(command) ||
|
|
187
228
|
runsUnderPnp() ||
|
|
188
229
|
currentUid() == null ||
|
|
189
|
-
withoutRecording(buildId) == null
|
|
230
|
+
withoutRecording(buildId) == null ||
|
|
231
|
+
// Last, being a few file checks: those commands keep only their
|
|
232
|
+
// integrations' check results, so a project with none records nothing.
|
|
233
|
+
(INTEGRATION_COMMANDS.has(command) &&
|
|
234
|
+
!withoutRecording(() => mayHaveIntegrations(process.cwd())))
|
|
190
235
|
) {
|
|
191
236
|
return fn();
|
|
192
237
|
}
|
|
193
|
-
//
|
|
194
|
-
//
|
|
238
|
+
// Gathers are kept only once the folder exists: the first recorded run on a
|
|
239
|
+
// machine (search, build, component, template, theme or discover) just makes
|
|
240
|
+
// it, so a one-off run never pays to store one.
|
|
195
241
|
const dir = cacheDirPath();
|
|
196
242
|
if (!withoutRecording(() => fs.existsSync(dir))) {
|
|
197
243
|
try {
|
|
@@ -456,6 +502,28 @@ function staleReason(stamps, env) {
|
|
|
456
502
|
* @returns {Promise<T>}
|
|
457
503
|
*/
|
|
458
504
|
export async function persistedGather(key, load, codec, keep = () => true) {
|
|
505
|
+
// A gather inside another (an integration's checks inside search's catalog
|
|
506
|
+
// gather) leaves the run's recording to the outermost: only it disarms, so
|
|
507
|
+
// what the outer gather reads after the inner one is still stamped.
|
|
508
|
+
gatherDepth++;
|
|
509
|
+
try {
|
|
510
|
+
return await gatherAt(key, load, codec, keep);
|
|
511
|
+
} finally {
|
|
512
|
+
if (--gatherDepth === 0) run?.disarm();
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* persistedGather's body; the caller disarms the run's recording once the
|
|
518
|
+
* outermost gather is done.
|
|
519
|
+
* @template T, E
|
|
520
|
+
* @param {unknown[]} key
|
|
521
|
+
* @param {() => Promise<T>} load
|
|
522
|
+
* @param {{encode: (value: T) => E, decode: (stored: E) => T}} codec
|
|
523
|
+
* @param {(value: T) => boolean} keep
|
|
524
|
+
* @returns {Promise<T>}
|
|
525
|
+
*/
|
|
526
|
+
async function gatherAt(key, load, codec, keep) {
|
|
459
527
|
const id = withoutRecording(buildId);
|
|
460
528
|
// A run under Yarn Plug'n'Play's loader neither keeps nor reads catalogs:
|
|
461
529
|
// its modules resolve through PnP, which a catalog's stamps do not follow.
|
|
@@ -471,11 +539,7 @@ export async function persistedGather(key, load, codec, keep = () => true) {
|
|
|
471
539
|
? "a run under Yarn Plug'n'Play's loader"
|
|
472
540
|
: 'no usable cache folder',
|
|
473
541
|
};
|
|
474
|
-
|
|
475
|
-
return await load();
|
|
476
|
-
} finally {
|
|
477
|
-
run?.disarm();
|
|
478
|
-
}
|
|
542
|
+
return await load();
|
|
479
543
|
}
|
|
480
544
|
const file = entryFile(dir, key, id);
|
|
481
545
|
let reason = 'no entry';
|
|
@@ -493,7 +557,6 @@ export async function persistedGather(key, load, codec, keep = () => true) {
|
|
|
493
557
|
const value = codec.decode(stored.value);
|
|
494
558
|
recordStates(stored.stamps);
|
|
495
559
|
gatherCode = cliStates(stored.stamps);
|
|
496
|
-
run?.disarm();
|
|
497
560
|
lastOutcome = {hit: true, reason: 'unchanged'};
|
|
498
561
|
try {
|
|
499
562
|
const now = new Date();
|
|
@@ -512,15 +575,11 @@ export async function persistedGather(key, load, codec, keep = () => true) {
|
|
|
512
575
|
lastOutcome = {hit: false, reason};
|
|
513
576
|
// A later gather in the run records its modules and variables again.
|
|
514
577
|
const armed = run?.arm() ?? false;
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
withoutRecording(() => store(dir, file, entryKey(key, id), value, codec));
|
|
519
|
-
}
|
|
520
|
-
return value;
|
|
521
|
-
} finally {
|
|
522
|
-
run?.disarm();
|
|
578
|
+
const value = await load();
|
|
579
|
+
if (run && armed && keep(value)) {
|
|
580
|
+
withoutRecording(() => store(dir, file, entryKey(key, id), value, codec));
|
|
523
581
|
}
|
|
582
|
+
return value;
|
|
524
583
|
}
|
|
525
584
|
|
|
526
585
|
/**
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The per-user folder for jiti's transpiled code.
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
export function jitiCacheDir(): string;
|
|
9
|
+
/**
|
|
10
|
+
* The `fsCache` option for a jiti loader: the per-user folder, made (0700)
|
|
11
|
+
* on first use and used at once, while it is a real folder the user owns and
|
|
12
|
+
* no one else can reach (the kept catalogs' check). A folder that fails the
|
|
13
|
+
* check, or cannot be made, is not used and nothing is cached on disk. Where
|
|
14
|
+
* the system has no user ids (Windows) ownership cannot be checked, and jiti
|
|
15
|
+
* keeps its default, the user's own temp folder there. Worked out once per
|
|
16
|
+
* process.
|
|
17
|
+
* @returns {{fsCache?: string | false}}
|
|
18
|
+
*/
|
|
19
|
+
export function jitiCacheOptions(): {
|
|
20
|
+
fsCache?: string | false;
|
|
21
|
+
};
|