@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61
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 +3 -3
- package/README.md +63 -63
- package/api/build/_adapter.d.mts +4 -0
- package/api/build/_adapter.mjs +28 -2
- package/api/build/blocks/blocks.d.mts +10 -1
- package/api/build/blocks/blocks.mjs +84 -7
- package/api/build/build.mjs +6 -1
- package/api/build/tree.d.mts +4 -0
- package/api/build/tree.mjs +9 -2
- package/api/doctor/_adapter.d.mts +3 -1
- package/api/doctor/_adapter.mjs +14 -1
- package/api/doctor/_authoring-audit.d.mts +42 -0
- package/api/doctor/_authoring-audit.mjs +106 -0
- package/api/doctor/doctor.d.mts +7 -0
- package/api/doctor/doctor.mjs +24 -39
- 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/integration/validate-integration.mjs +17 -3
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/_adapter.mjs +124 -3
- package/api/search/_candidate-score.mjs +63 -9
- package/api/search/_entries.d.mts +10 -0
- package/api/search/_entries.mjs +68 -1
- package/api/search/_gather-templates.d.mts +11 -0
- package/api/search/_gather-templates.mjs +22 -2
- package/api/search/_words.mjs +26 -6
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/theme/_adapter.d.mts +37 -5
- package/api/theme/_adapter.mjs +381 -57
- package/api/theme/_fork.d.mts +90 -0
- package/api/theme/_fork.mjs +246 -0
- package/api/theme/build/build.d.mts +40 -2
- package/api/theme/build/build.mjs +477 -66
- 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.d.mts +8 -0
- package/api/theme/targets/targets.mjs +24 -4
- 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 +7 -4
- package/api/theme/themeEject.doc.mjs +3 -3
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.d.mts +46 -3
- package/api/theme-edit/_adapter.mjs +496 -112
- package/api/theme-edit/_catalog.d.mts +1 -6
- package/api/theme-edit/_catalog.mjs +5 -268
- package/api/theme-edit/_check.d.mts +9 -4
- package/api/theme-edit/_check.mjs +1232 -229
- package/api/theme-edit/_color.d.mts +19 -0
- package/api/theme-edit/_color.mjs +280 -34
- package/api/theme-edit/_compiler.d.mts +3 -1
- package/api/theme-edit/_compiler.mjs +52 -13
- package/api/theme-edit/_context.d.mts +4 -1
- package/api/theme-edit/_context.mjs +126 -13
- package/api/theme-edit/_css.d.mts +84 -0
- package/api/theme-edit/_css.mjs +700 -0
- package/api/theme-edit/_edit.d.mts +9 -3
- package/api/theme-edit/_edit.mjs +806 -103
- package/api/theme-edit/_how-commands.d.mts +38 -7
- package/api/theme-edit/_how-commands.mjs +64 -45
- package/api/theme-edit/_how-question.d.mts +33 -0
- package/api/theme-edit/_how-question.mjs +2553 -381
- package/api/theme-edit/_how.mjs +402 -31
- package/api/theme-edit/_overview.mjs +2 -7
- package/api/theme-edit/_palette.d.mts +60 -13
- package/api/theme-edit/_palette.mjs +826 -295
- package/api/theme-edit/_parts.d.mts +42 -10
- package/api/theme-edit/_parts.mjs +280 -69
- package/api/theme-edit/_png.d.mts +4 -4
- package/api/theme-edit/_png.mjs +4 -2
- package/api/theme-edit/_preview-app.d.mts +14 -0
- package/api/theme-edit/_preview-app.mjs +1675 -235
- package/api/theme-edit/_preview.d.mts +7 -16
- package/api/theme-edit/_preview.mjs +79 -86
- package/api/theme-edit/_project.d.mts +32 -2
- package/api/theme-edit/_project.mjs +80 -19
- package/api/theme-edit/_settings.d.mts +199 -52
- package/api/theme-edit/_settings.mjs +1422 -217
- package/api/theme-edit/_tables.d.mts +19 -6
- package/api/theme-edit/_tables.mjs +150 -92
- package/api/theme-edit/theme-edit.type.d.mts +20 -1
- package/api/theme-edit/theme-edit.type.mjs +6 -3
- package/api/theme-edit/themeEditHow.doc.mjs +6 -0
- 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/themeEditPreviewRemove.doc.mjs +5 -1
- package/api/theme-edit/themeEditSet.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/api/upgrade/_adapter.d.mts +1 -0
- package/assets/codemods/run-codemod.mjs +61 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
- package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
- package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
- package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
- package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
- package/assets/docs/tree/calendars.doc.mjs +1 -3
- package/assets/docs/tree/checks.doc.mjs +22 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -0
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -1
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/self-audit.generated.json +1 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
- package/assets/templates/components.generated.json +1 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +8 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +19 -15
- package/clients/cli/build-id.generated.json +1 -0
- package/clients/cli/commands/ensure-core-built.mjs +12 -5
- package/clients/cli/commands/experimental/index.mjs +10 -10
- package/clients/cli/commands/experimental/theme.mjs +200 -81
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.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/experimental-theme-preview-list.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
- package/clients/cli/commands/integration.mjs +8 -0
- package/clients/cli/commands/manifest.mjs +5 -2
- 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 +439 -66
- package/clients/cli/index.mjs +27 -6
- package/clients/cli/lib/cli-error.mjs +118 -3
- package/clients/cli/lib/manifest.mjs +37 -0
- package/clients/cli/lib/resolve-theme.mjs +2 -1
- package/clients/cli/manifest.generated.json +1 -0
- 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/module-exports.mjs +16 -2
- package/foundation/discovery/stored-self-audit.d.mts +31 -0
- package/foundation/discovery/stored-self-audit.mjs +119 -0
- package/foundation/discovery/template-adapter.d.mts +48 -2
- package/foundation/discovery/template-adapter.mjs +51 -19
- package/foundation/discovery/template-needs.d.mts +19 -0
- package/foundation/discovery/template-needs.mjs +50 -16
- package/foundation/discovery/template-source-tree.d.mts +7 -0
- package/foundation/discovery/template-source-tree.mjs +15 -0
- package/foundation/discovery/theme-discovery.d.mts +2 -1
- package/foundation/discovery/theme-discovery.mjs +16 -10
- package/foundation/discovery/theme-imports.d.mts +16 -0
- package/foundation/discovery/theme-imports.mjs +30 -2
- package/foundation/discovery/theme-module-extensions.d.mts +18 -0
- package/foundation/discovery/theme-module-extensions.mjs +30 -0
- package/foundation/doc-compiler/import.mjs +22 -15
- package/foundation/doc-compiler/stored-docs.d.mts +18 -12
- package/foundation/doc-compiler/stored-docs.mjs +52 -19
- package/foundation/env/private-dir.d.mts +17 -0
- package/foundation/env/private-dir.mjs +42 -0
- package/foundation/fs/gather-cache.d.mts +108 -0
- package/foundation/fs/gather-cache.mjs +783 -0
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +14 -3
- package/foundation/fs/read-record.d.mts +31 -1
- package/foundation/fs/read-record.mjs +100 -7
- 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/integrations.d.mts +8 -0
- package/foundation/integrations/integrations.mjs +4 -0
- package/foundation/integrations/may-have-integrations.d.mts +8 -0
- package/foundation/integrations/may-have-integrations.mjs +47 -0
- package/foundation/integrations/validate-contributions.d.mts +62 -1
- package/foundation/integrations/validate-contributions.mjs +476 -40
- package/foundation/release/cache.d.mts +32 -4
- package/foundation/release/cache.mjs +105 -16
- package/foundation/release/folder-lock.d.mts +28 -0
- package/foundation/release/folder-lock.mjs +205 -0
- 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 +5 -5
- package/package.json +8 -6
- package/api/theme-edit/_css-properties.d.mts +0 -10
- package/api/theme-edit/_css-properties.mjs +0 -556
|
@@ -18,7 +18,12 @@
|
|
|
18
18
|
import * as fs from 'node:fs';
|
|
19
19
|
import * as path from 'node:path';
|
|
20
20
|
import module from 'node:module';
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
parseTemplateSource,
|
|
23
|
+
TEMPLATE_COMPONENTS_FILE,
|
|
24
|
+
walk,
|
|
25
|
+
} from './template-source-tree.mjs';
|
|
26
|
+
import {readStore, storedKey} from '../doc-compiler/stored-docs.mjs';
|
|
22
27
|
import {CLI_ROOT, findWorkspaceRoot} from '../fs/paths.mjs';
|
|
23
28
|
import {detectStylingSystem} from '../agent-docs/agent-docs.mjs';
|
|
24
29
|
import {
|
|
@@ -81,6 +86,20 @@ export function extractImportedPackages(source) {
|
|
|
81
86
|
* @returns {string[]}
|
|
82
87
|
*/
|
|
83
88
|
function moduleSpecifiers(source) {
|
|
89
|
+
// A template Astryx ships answers from what parsing it returned at publish.
|
|
90
|
+
const stored = readStore(TEMPLATE_COMPONENTS_FILE).get(
|
|
91
|
+
`imports:${storedKey(source)}`,
|
|
92
|
+
);
|
|
93
|
+
if (Array.isArray(stored)) return [...stored];
|
|
94
|
+
return parsedSpecifiers(source);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* moduleSpecifiers, read from the source's syntax tree.
|
|
99
|
+
* @param {string} source
|
|
100
|
+
* @returns {string[]}
|
|
101
|
+
*/
|
|
102
|
+
export function parsedSpecifiers(source) {
|
|
84
103
|
let file;
|
|
85
104
|
try {
|
|
86
105
|
file = parseTemplateSource(source, {errorRecovery: true});
|
|
@@ -226,6 +245,35 @@ function cliPackageRanges() {
|
|
|
226
245
|
}
|
|
227
246
|
}
|
|
228
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
|
+
|
|
229
277
|
/**
|
|
230
278
|
* Analyze what a template source needs that the target project lacks.
|
|
231
279
|
*
|
|
@@ -266,21 +314,7 @@ export function analyzeTemplateNeeds(source, cwd) {
|
|
|
266
314
|
|
|
267
315
|
const missing = external.filter(p => !(p in projectDeps));
|
|
268
316
|
|
|
269
|
-
|
|
270
|
-
let installCommand = null;
|
|
271
|
-
/** @type {string | null} */
|
|
272
|
-
let noCommandReason = null;
|
|
273
|
-
if (missing.length > 0) {
|
|
274
|
-
const resolved = resolveInstallVerb(cwd);
|
|
275
|
-
const ranges = cliPackageRanges();
|
|
276
|
-
const specs = missing.map(p => (ranges[p] ? `${p}@"${ranges[p]}"` : p));
|
|
277
|
-
if (resolved.verb !== null) {
|
|
278
|
-
installCommand = `${resolved.verb} ${specs.join(' ')}`;
|
|
279
|
-
} else {
|
|
280
|
-
const where = path.relative(cwd, resolved.dir) || '.';
|
|
281
|
-
noCommandReason = `Install missing dependencies: ${specs.join(' ')}. No install command: ${where} has ${resolved.lockfiles.join(' and ')}, and nothing there says which package manager to use.`;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
317
|
+
const {installCommand, noCommandReason} = installCommandFor(missing, cwd);
|
|
284
318
|
|
|
285
319
|
// ── StyleX compiler ────────────────────────────────────────────────────
|
|
286
320
|
const usesStylex = imported.has(STYLEX_RUNTIME);
|
|
@@ -50,3 +50,10 @@ export function isReference(node: any, parent: any, key: string): any;
|
|
|
50
50
|
* @returns {Set<string>}
|
|
51
51
|
*/
|
|
52
52
|
export function writtenNames(file: any): Set<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Where what parsing returns for each template Astryx ships is stored at
|
|
55
|
+
* publish (scripts/generate-template-components.mjs): its component list
|
|
56
|
+
* under its source's key, and the module specifiers it imports under
|
|
57
|
+
* `imports:` and that key.
|
|
58
|
+
*/
|
|
59
|
+
export const TEMPLATE_COMPONENTS_FILE: string;
|
|
@@ -12,6 +12,21 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import {createRequire} from 'node:module';
|
|
15
|
+
import * as path from 'node:path';
|
|
16
|
+
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Where what parsing returns for each template Astryx ships is stored at
|
|
20
|
+
* publish (scripts/generate-template-components.mjs): its component list
|
|
21
|
+
* under its source's key, and the module specifiers it imports under
|
|
22
|
+
* `imports:` and that key.
|
|
23
|
+
*/
|
|
24
|
+
export const TEMPLATE_COMPONENTS_FILE = path.join(
|
|
25
|
+
CLI_ROOT,
|
|
26
|
+
'assets',
|
|
27
|
+
'templates',
|
|
28
|
+
'components.generated.json',
|
|
29
|
+
);
|
|
15
30
|
|
|
16
31
|
const require = createRequire(import.meta.url);
|
|
17
32
|
|
|
@@ -147,7 +147,7 @@ export function discoverIntegrationThemes(integration: import("../integrations/i
|
|
|
147
147
|
export const BUNDLED_THEME_PACKAGE: "@astryxdesign/cli";
|
|
148
148
|
export const THEMES_DIR: string;
|
|
149
149
|
export const THEME_DOC_SUFFIX: ".doc.mjs";
|
|
150
|
-
export
|
|
150
|
+
export { THEME_MODULE_EXTENSIONS };
|
|
151
151
|
/** A theme directory's name: lower-kebab, starting with a letter. */
|
|
152
152
|
export const THEME_SLUG_RE: RegExp;
|
|
153
153
|
export type DiscoveredTheme = {
|
|
@@ -196,3 +196,4 @@ export type UnmigratedThemeCopy = {
|
|
|
196
196
|
exportName: string;
|
|
197
197
|
descriptor: string;
|
|
198
198
|
};
|
|
199
|
+
import { THEME_MODULE_EXTENSIONS } from './theme-module-extensions.mjs';
|
|
@@ -26,6 +26,7 @@ import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
|
26
26
|
import {formatCliCommand} from '../env/package-manager.mjs';
|
|
27
27
|
import {LOCAL_THEME_ROOT} from '../config/theme-state.mjs';
|
|
28
28
|
import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
|
|
29
|
+
import {THEME_MODULE_EXTENSIONS} from './theme-module-extensions.mjs';
|
|
29
30
|
|
|
30
31
|
export const BUNDLED_THEME_PACKAGE = '@astryxdesign/cli';
|
|
31
32
|
export const THEMES_DIR = path.join(CLI_ROOT, 'assets', 'templates', 'themes');
|
|
@@ -114,14 +115,7 @@ function resolveThemePath(value, root, label) {
|
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
export
|
|
118
|
-
'.mjs',
|
|
119
|
-
'.js',
|
|
120
|
-
'.mts',
|
|
121
|
-
'.ts',
|
|
122
|
-
'.tsx',
|
|
123
|
-
'.jsx',
|
|
124
|
-
];
|
|
118
|
+
export {THEME_MODULE_EXTENSIONS};
|
|
125
119
|
|
|
126
120
|
/** A theme directory's name: lower-kebab, starting with a letter. */
|
|
127
121
|
export const THEME_SLUG_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
|
|
@@ -1378,8 +1372,20 @@ export function discoverThemeDirectory(
|
|
|
1378
1372
|
entry => entry.isFile() && entry.name.endsWith(THEME_DOC_SUFFIX),
|
|
1379
1373
|
);
|
|
1380
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('/');
|
|
1381
1387
|
throw new Error(
|
|
1382
|
-
`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}/.`,
|
|
1383
1389
|
);
|
|
1384
1390
|
}
|
|
1385
1391
|
const rootSymlink = rootEntries.find(entry => entry.isSymbolicLink());
|
|
@@ -1490,7 +1496,7 @@ export function discoverThemeDirectory(
|
|
|
1490
1496
|
const doc = readThemeDoc(docPath, owner);
|
|
1491
1497
|
if (doc.name !== slug) {
|
|
1492
1498
|
throw new Error(
|
|
1493
|
-
`${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}".`,
|
|
1494
1500
|
);
|
|
1495
1501
|
}
|
|
1496
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'));
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
* @file The file extensions a theme source module can have.
|
|
6
|
+
*
|
|
7
|
+
* @input none
|
|
8
|
+
* @output THEME_MODULE_EXTENSIONS and THEME_SOURCE_EXTENSIONS
|
|
9
|
+
* @position read by theme discovery (which theme sources it accepts) and by
|
|
10
|
+
* `theme build` (which inputs it loads), so both accept the same files
|
|
11
|
+
*/
|
|
12
|
+
/** The extensions of a discoverable theme source, `<name>Theme.<ext>`. */
|
|
13
|
+
export const THEME_MODULE_EXTENSIONS: string[];
|
|
14
|
+
/**
|
|
15
|
+
* The extensions `theme build` loads as a theme source: the discoverable ones,
|
|
16
|
+
* and their CommonJS forms, which a theme may also be written in.
|
|
17
|
+
*/
|
|
18
|
+
export const THEME_SOURCE_EXTENSIONS: string[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The file extensions a theme source module can have.
|
|
5
|
+
*
|
|
6
|
+
* @input none
|
|
7
|
+
* @output THEME_MODULE_EXTENSIONS and THEME_SOURCE_EXTENSIONS
|
|
8
|
+
* @position read by theme discovery (which theme sources it accepts) and by
|
|
9
|
+
* `theme build` (which inputs it loads), so both accept the same files
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** The extensions of a discoverable theme source, `<name>Theme.<ext>`. */
|
|
13
|
+
export const THEME_MODULE_EXTENSIONS = [
|
|
14
|
+
'.mjs',
|
|
15
|
+
'.js',
|
|
16
|
+
'.mts',
|
|
17
|
+
'.ts',
|
|
18
|
+
'.tsx',
|
|
19
|
+
'.jsx',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The extensions `theme build` loads as a theme source: the discoverable ones,
|
|
24
|
+
* and their CommonJS forms, which a theme may also be written in.
|
|
25
|
+
*/
|
|
26
|
+
export const THEME_SOURCE_EXTENSIONS = [
|
|
27
|
+
...THEME_MODULE_EXTENSIONS,
|
|
28
|
+
'.cjs',
|
|
29
|
+
'.cts',
|
|
30
|
+
];
|
|
@@ -26,20 +26,24 @@
|
|
|
26
26
|
|
|
27
27
|
import * as fs from 'node:fs';
|
|
28
28
|
import {pathToFileURL} from 'node:url';
|
|
29
|
-
import {
|
|
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,
|
|
34
35
|
readInTurn,
|
|
35
36
|
} from '../fs/module-loader.mjs';
|
|
36
37
|
import {fileStamp, recordContentRead} from '../fs/read-record.mjs';
|
|
37
|
-
import {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
import {readStore, storedKey, STORED_DOCS_FILE} from './stored-docs.mjs';
|
|
39
|
+
|
|
40
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* jiti, loaded on first use: only TypeScript doc files need it.
|
|
44
|
+
* @type {typeof import('jiti').createJiti}
|
|
45
|
+
*/
|
|
46
|
+
const createJiti = (...args) => requireFromHere('jiti').createJiti(...args);
|
|
43
47
|
|
|
44
48
|
/** @type {ReturnType<typeof createJiti> | undefined} */
|
|
45
49
|
let jsxJiti;
|
|
@@ -101,16 +105,14 @@ function loadFirst(file, load) {
|
|
|
101
105
|
const storedModules = new Map();
|
|
102
106
|
|
|
103
107
|
/**
|
|
104
|
-
* The module of a
|
|
108
|
+
* The module of a doc file whose text has stored exports: an object
|
|
105
109
|
* shaped as its namespace (no prototype, the export names in order, tagged
|
|
106
110
|
* `Module`, closed to new names). Null for any other file.
|
|
107
111
|
* @param {string} file
|
|
108
112
|
* @returns {Record<string, unknown> | null}
|
|
109
113
|
*/
|
|
110
114
|
function storedModule(file) {
|
|
111
|
-
if (!file.
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
115
|
+
if (!file.endsWith('.doc.mjs')) return null;
|
|
114
116
|
let text;
|
|
115
117
|
try {
|
|
116
118
|
text = fs.readFileSync(file, 'utf-8');
|
|
@@ -194,16 +196,21 @@ export function importTemplateModule(file) {
|
|
|
194
196
|
'template',
|
|
195
197
|
first => {
|
|
196
198
|
if (first.endsWith('.ts')) {
|
|
197
|
-
jsxJiti ??= createJiti(import.meta.url, {
|
|
199
|
+
jsxJiti ??= createJiti(import.meta.url, {
|
|
200
|
+
...jitiCacheOptions(),
|
|
201
|
+
jsx: true,
|
|
202
|
+
});
|
|
198
203
|
return jsxJiti.import(first);
|
|
199
204
|
}
|
|
200
205
|
return importInTurn(first, `file://${first}`);
|
|
201
206
|
},
|
|
202
207
|
changed =>
|
|
203
208
|
changed.endsWith('.ts')
|
|
204
|
-
? createJiti(import.meta.url, {
|
|
205
|
-
|
|
206
|
-
|
|
209
|
+
? createJiti(import.meta.url, {
|
|
210
|
+
...jitiCacheOptions(),
|
|
211
|
+
jsx: true,
|
|
212
|
+
moduleCache: false,
|
|
213
|
+
}).import(changed)
|
|
207
214
|
: importFresh(changed),
|
|
208
215
|
);
|
|
209
216
|
}
|
|
@@ -5,23 +5,29 @@
|
|
|
5
5
|
* The key of a source file's text in a store written at publish (the stored
|
|
6
6
|
* docs, the stored template component lists): a hash of the text, so an
|
|
7
7
|
* edited or unknown file is never answered from a store.
|
|
8
|
-
* @param {string} text
|
|
8
|
+
* @param {string | Buffer} text
|
|
9
9
|
* @returns {string}
|
|
10
10
|
*/
|
|
11
|
-
export function storedKey(text: string): string;
|
|
11
|
+
export function storedKey(text: string | Buffer): string;
|
|
12
12
|
/**
|
|
13
|
-
* A store written at publish, by key, read once per process. A
|
|
14
|
-
*
|
|
13
|
+
* A store written at publish, by key, read once per process. A store is
|
|
14
|
+
* either one JSON object of key to value, or (the stored docs) a first line
|
|
15
|
+
* mapping each key to its byte range, then the values: a lookup parses only
|
|
16
|
+
* the value it reads. A missing or unreadable file reads as empty, so every
|
|
17
|
+
* source is worked out as before.
|
|
15
18
|
* @param {string} file
|
|
16
|
-
* @returns {
|
|
19
|
+
* @returns {{get: (key: string) => any}}
|
|
17
20
|
*/
|
|
18
|
-
export function readStore(file: string):
|
|
21
|
+
export function readStore(file: string): {
|
|
22
|
+
get: (key: string) => any;
|
|
23
|
+
};
|
|
19
24
|
/**
|
|
20
|
-
* Where the exports of the doc files Astryx ships
|
|
21
|
-
* imports nothing,
|
|
22
|
-
* hash of its text.
|
|
23
|
-
* file
|
|
25
|
+
* Where the exports of the doc files Astryx ships (the CLI's and Core's) are
|
|
26
|
+
* stored: each doc that imports nothing, reads nothing of where it sits, and
|
|
27
|
+
* exports only plain data, by a hash of its text. Such a doc's exports depend
|
|
28
|
+
* on its text alone, so any file with that exact text reads them; an edited
|
|
29
|
+
* or unknown file is imported as before. The first line maps each key to the
|
|
30
|
+
* byte range of its exports, as JSON, in the rest of the file, so a read
|
|
31
|
+
* parses only the docs it needs.
|
|
24
32
|
*/
|
|
25
33
|
export const STORED_DOCS_FILE: string;
|
|
26
|
-
/** The folder of the files Astryx ships; only its doc files are stored. */
|
|
27
|
-
export const SHIPPED_ASSETS: string;
|
|
@@ -15,10 +15,13 @@ import * as path from 'node:path';
|
|
|
15
15
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Where the exports of the doc files Astryx ships
|
|
19
|
-
* imports nothing,
|
|
20
|
-
* hash of its text.
|
|
21
|
-
* file
|
|
18
|
+
* Where the exports of the doc files Astryx ships (the CLI's and Core's) are
|
|
19
|
+
* stored: each doc that imports nothing, reads nothing of where it sits, and
|
|
20
|
+
* exports only plain data, by a hash of its text. Such a doc's exports depend
|
|
21
|
+
* on its text alone, so any file with that exact text reads them; an edited
|
|
22
|
+
* or unknown file is imported as before. The first line maps each key to the
|
|
23
|
+
* byte range of its exports, as JSON, in the rest of the file, so a read
|
|
24
|
+
* parses only the docs it needs.
|
|
22
25
|
*/
|
|
23
26
|
export const STORED_DOCS_FILE = path.join(
|
|
24
27
|
CLI_ROOT,
|
|
@@ -26,40 +29,70 @@ export const STORED_DOCS_FILE = path.join(
|
|
|
26
29
|
'docs.generated.json',
|
|
27
30
|
);
|
|
28
31
|
|
|
29
|
-
/** The folder of the files Astryx ships; only its doc files are stored. */
|
|
30
|
-
export const SHIPPED_ASSETS = path.join(CLI_ROOT, 'assets') + path.sep;
|
|
31
|
-
|
|
32
32
|
/**
|
|
33
33
|
* The key of a source file's text in a store written at publish (the stored
|
|
34
34
|
* docs, the stored template component lists): a hash of the text, so an
|
|
35
35
|
* edited or unknown file is never answered from a store.
|
|
36
|
-
* @param {string} text
|
|
36
|
+
* @param {string | Buffer} text
|
|
37
37
|
* @returns {string}
|
|
38
38
|
*/
|
|
39
39
|
export function storedKey(text) {
|
|
40
40
|
return createHash('sha256').update(text).digest('hex').slice(0, 32);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
/** @type {Map<string,
|
|
43
|
+
/** @type {Map<string, {get: (key: string) => any}>} */
|
|
44
44
|
const stores = new Map();
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* A store written at publish, by key, read once per process. A
|
|
48
|
-
*
|
|
47
|
+
* A store written at publish, by key, read once per process. A store is
|
|
48
|
+
* either one JSON object of key to value, or (the stored docs) a first line
|
|
49
|
+
* mapping each key to its byte range, then the values: a lookup parses only
|
|
50
|
+
* the value it reads. A missing or unreadable file reads as empty, so every
|
|
51
|
+
* source is worked out as before.
|
|
49
52
|
* @param {string} file
|
|
50
|
-
* @returns {
|
|
53
|
+
* @returns {{get: (key: string) => any}}
|
|
51
54
|
*/
|
|
52
55
|
export function readStore(file) {
|
|
53
56
|
let store = stores.get(file);
|
|
54
57
|
if (!store) {
|
|
55
|
-
|
|
56
|
-
store = new Map(
|
|
57
|
-
Object.entries(JSON.parse(fs.readFileSync(file, 'utf-8'))),
|
|
58
|
-
);
|
|
59
|
-
} catch {
|
|
60
|
-
store = new Map();
|
|
61
|
-
}
|
|
58
|
+
store = openStore(file);
|
|
62
59
|
stores.set(file, store);
|
|
63
60
|
}
|
|
64
61
|
return store;
|
|
65
62
|
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {string} file
|
|
66
|
+
* @returns {{get: (key: string) => any}}
|
|
67
|
+
*/
|
|
68
|
+
function openStore(file) {
|
|
69
|
+
/** @type {Buffer} */
|
|
70
|
+
let bytes;
|
|
71
|
+
try {
|
|
72
|
+
bytes = fs.readFileSync(file);
|
|
73
|
+
} catch {
|
|
74
|
+
return new Map();
|
|
75
|
+
}
|
|
76
|
+
const end = bytes.indexOf(0x0a);
|
|
77
|
+
try {
|
|
78
|
+
if (end !== -1 && end < bytes.length - 1) {
|
|
79
|
+
/** @type {Map<string, [number, number]>} */
|
|
80
|
+
const ranges = new Map(
|
|
81
|
+
Object.entries(JSON.parse(bytes.toString('utf-8', 0, end))),
|
|
82
|
+
);
|
|
83
|
+
const data = bytes.subarray(end + 1);
|
|
84
|
+
return {
|
|
85
|
+
get(key) {
|
|
86
|
+
const range = ranges.get(key);
|
|
87
|
+
if (!range) return undefined;
|
|
88
|
+
return JSON.parse(
|
|
89
|
+
data.toString('utf-8', range[0], range[0] + range[1]),
|
|
90
|
+
);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return new Map(Object.entries(JSON.parse(bytes.toString('utf-8'))));
|
|
95
|
+
} catch {
|
|
96
|
+
return new Map();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 current user's id, or null where the system has none (Windows).
|
|
6
|
+
* @returns {number | null}
|
|
7
|
+
*/
|
|
8
|
+
export function currentUid(): number | null;
|
|
9
|
+
/**
|
|
10
|
+
* Whether `dir` is a real folder (not a link) that the current user owns and
|
|
11
|
+
* no one else can reach, so nothing in it can have been planted by another
|
|
12
|
+
* account. False where the system has no user ids (Windows): ownership cannot
|
|
13
|
+
* be checked there, so such a folder is never used.
|
|
14
|
+
* @param {string} dir
|
|
15
|
+
* @returns {boolean}
|
|
16
|
+
*/
|
|
17
|
+
export function isPrivateDir(dir: string): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The check a folder of cached code or data must pass before the CLI
|
|
5
|
+
* reads from it: Node's compile cache (clients/cli/bin/astryx.mjs) and the
|
|
6
|
+
* kept search catalogs (foundation/fs/gather-cache.mjs). Built-ins only, so
|
|
7
|
+
* the bin can load it before anything else.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The current user's id, or null where the system has none (Windows).
|
|
14
|
+
* @returns {number | null}
|
|
15
|
+
*/
|
|
16
|
+
export function currentUid() {
|
|
17
|
+
return typeof process.getuid === 'function' ? process.getuid() : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Whether `dir` is a real folder (not a link) that the current user owns and
|
|
22
|
+
* no one else can reach, so nothing in it can have been planted by another
|
|
23
|
+
* account. False where the system has no user ids (Windows): ownership cannot
|
|
24
|
+
* be checked there, so such a folder is never used.
|
|
25
|
+
* @param {string} dir
|
|
26
|
+
* @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
export function isPrivateDir(dir) {
|
|
29
|
+
const uid = currentUid();
|
|
30
|
+
if (uid == null) return false;
|
|
31
|
+
try {
|
|
32
|
+
const stat = fs.lstatSync(dir);
|
|
33
|
+
return (
|
|
34
|
+
stat.isDirectory() &&
|
|
35
|
+
!stat.isSymbolicLink() &&
|
|
36
|
+
stat.uid === uid &&
|
|
37
|
+
(stat.mode & 0o077) === 0
|
|
38
|
+
);
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|