@astryxdesign/cli 0.7.16 → 0.7.17-canary.gb36275e
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 +13 -23
- package/api/build/_adapter.d.mts +5 -0
- package/api/build/_adapter.mjs +49 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +2 -1
- package/api/build/kit/rank.mjs +59 -12
- package/api/build/kit/weights.d.mts +16 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +238 -31
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +42 -0
- package/api/build/kit/words.mjs +82 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +46 -5
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +26 -2
- package/api/docs/_adapter.mjs +217 -5
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +77 -6
- package/api/doctor/built-checks.mjs +38 -13
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/render/_adapter.mjs +531 -192
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +30 -0
- package/api/render/render.type.mjs +19 -0
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_result.d.mts +5 -5
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +10 -0
- package/api/theme/build/build.d.mts +47 -0
- package/api/theme/build/build.mjs +147 -25
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +48 -0
- package/api/theme-edit/_adapter.mjs +675 -42
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1481 -252
- package/api/theme-edit/_color.d.mts +9 -0
- package/api/theme-edit/_color.mjs +41 -1
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.mjs +60 -3
- package/api/theme-edit/_css.mjs +21 -1
- package/api/theme-edit/_edit.d.mts +22 -0
- package/api/theme-edit/_edit.mjs +1196 -88
- package/api/theme-edit/_how-commands.d.mts +57 -0
- package/api/theme-edit/_how-commands.mjs +536 -1
- package/api/theme-edit/_how-question.d.mts +65 -0
- package/api/theme-edit/_how-question.mjs +4401 -225
- package/api/theme-edit/_how.mjs +104 -4
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_normal.d.mts +153 -0
- package/api/theme-edit/_normal.mjs +661 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +8 -0
- package/api/theme-edit/_parts.mjs +103 -2
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +205 -17
- package/api/theme-edit/_preview.d.mts +64 -8
- package/api/theme-edit/_preview.mjs +447 -89
- package/api/theme-edit/_settings.d.mts +176 -5
- package/api/theme-edit/_settings.mjs +1936 -128
- package/api/theme-edit/_tables.d.mts +6 -0
- package/api/theme-edit/_tables.mjs +32 -1
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/assets/codemods/run-codemod.mjs +73 -6
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +43 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +20 -2
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +22 -14
- package/clients/cli/commands/experimental/render.mjs +32 -1
- package/clients/cli/commands/experimental/theme.mjs +65 -14
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +153 -5
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +27 -2
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +20 -7
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +173 -10
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +163 -53
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/module-loader.d.mts +18 -2
- package/foundation/fs/module-loader.mjs +92 -20
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/render/embedded-imports.d.mts +5 -4
- package/foundation/render/embedded-imports.mjs +7 -16
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +83 -13
- package/foundation/render/render-page.d.mts +34 -2
- package/foundation/render/render-page.mjs +210 -29
- package/foundation/render/source-block.d.mts +73 -6
- package/foundation/render/source-block.mjs +170 -19
- package/foundation/render/ts-paths.d.mts +53 -6
- package/foundation/render/ts-paths.mjs +286 -41
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +10 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +16 -3
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +13 -0
- package/host/index.mjs +8 -6
- package/package.json +6 -6
|
@@ -2,18 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @file A project's `compilerOptions.paths` (tsconfig.json or jsconfig.json),
|
|
5
|
-
* read and matched by TypeScript's rules, for `astryx experimental render
|
|
5
|
+
* read and matched by TypeScript's rules, for `astryx experimental render`.
|
|
6
|
+
* The config of a file is the nearest tsconfig.json (else jsconfig.json) in
|
|
7
|
+
* its folder or above, read through its `extends`; a config that does not
|
|
8
|
+
* include the file lends the referenced project that does, as a
|
|
9
|
+
* solution-style config (`"files": []` with `references`) does. Matching:
|
|
6
10
|
* an exact key matches only itself; a key may hold one `*` anywhere, and the
|
|
7
11
|
* longest matching prefix wins; a target may hold one `*`, which takes what
|
|
8
12
|
* the key's `*` matched; targets are tried in order, and when none exists the
|
|
9
13
|
* import resolves as a package. Only bare specifiers are matched. Targets
|
|
10
|
-
* resolve from `baseUrl
|
|
14
|
+
* resolve from `baseUrl`, else from the folder of the config that writes
|
|
15
|
+
* `paths`.
|
|
11
16
|
*
|
|
12
17
|
* @position foundation/render — used by page-worker.mjs and embedded-imports.mjs
|
|
13
18
|
*/
|
|
14
19
|
|
|
15
20
|
import * as fs from 'node:fs';
|
|
16
21
|
import * as path from 'node:path';
|
|
22
|
+
import {conditionalExportTarget} from '../discovery/package-exports.mjs';
|
|
23
|
+
import {findNodeModulesPackage} from '../fs/paths.mjs';
|
|
17
24
|
|
|
18
25
|
/**
|
|
19
26
|
* @typedef {object} PathPattern
|
|
@@ -27,45 +34,282 @@ import * as path from 'node:path';
|
|
|
27
34
|
/** Extensions an extensionless candidate may stand for, in resolution order. */
|
|
28
35
|
const EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.mts', '.cts', '.json'];
|
|
29
36
|
|
|
37
|
+
/** The extensions the render's module loader tries for an extensionless import, in its order. */
|
|
38
|
+
export const LOAD_EXTENSIONS = ['.js', '.mjs', '.cjs', '.jsx', '.ts', '.tsx', '.mts', '.cts', '.json'];
|
|
39
|
+
|
|
40
|
+
/** The config file names TypeScript looks for in a folder, in its order. */
|
|
41
|
+
const CONFIG_NAMES = ['tsconfig.json', 'jsconfig.json'];
|
|
42
|
+
|
|
43
|
+
/** What a config excludes when it names nothing to exclude. */
|
|
44
|
+
const DEFAULT_EXCLUDE = ['node_modules', 'bower_components', 'jspm_packages'];
|
|
45
|
+
|
|
46
|
+
/** @param {string} file */
|
|
47
|
+
const isFile = file => {
|
|
48
|
+
try {
|
|
49
|
+
return fs.statSync(file).isFile();
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
30
55
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @
|
|
34
|
-
* @returns {PathPattern[] | null} null when neither file is there
|
|
56
|
+
* A config's JSON, with comments and trailing commas allowed, or null.
|
|
57
|
+
* @param {string} file
|
|
58
|
+
* @returns {any}
|
|
35
59
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const base = path.resolve(dir, typeof options.baseUrl === 'string' ? options.baseUrl : '.');
|
|
47
|
-
/** @type {PathPattern[]} */
|
|
48
|
-
const out = [];
|
|
49
|
-
for (const [key, targets] of Object.entries(options.paths ?? {})) {
|
|
50
|
-
if (!Array.isArray(targets)) continue;
|
|
51
|
-
const star = key.indexOf('*');
|
|
52
|
-
if (star !== key.lastIndexOf('*')) continue;
|
|
53
|
-
out.push({
|
|
54
|
-
key,
|
|
55
|
-
prefix: star === -1 ? key : key.slice(0, star),
|
|
56
|
-
suffix: star === -1 ? '' : key.slice(star + 1),
|
|
57
|
-
wildcard: star !== -1,
|
|
58
|
-
targets: targets
|
|
59
|
-
.filter(t => typeof t === 'string' && t.indexOf('*') === t.lastIndexOf('*'))
|
|
60
|
-
.map(t => path.resolve(base, t)),
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return out;
|
|
64
|
-
} catch {
|
|
65
|
-
return [];
|
|
66
|
-
}
|
|
60
|
+
function readJsonc(file) {
|
|
61
|
+
try {
|
|
62
|
+
const text = fs
|
|
63
|
+
.readFileSync(file, 'utf8')
|
|
64
|
+
.replace(/("(?:[^"\\]|\\.)*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, str) => str ?? '')
|
|
65
|
+
.replace(/,(\s*[}\]])/g, '$1');
|
|
66
|
+
const json = JSON.parse(text);
|
|
67
|
+
return json && typeof json === 'object' && !Array.isArray(json) ? json : null;
|
|
68
|
+
} catch {
|
|
69
|
+
return null;
|
|
67
70
|
}
|
|
68
|
-
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The conditions TypeScript matches in a package's `exports` for a config (`default` always matches). */
|
|
74
|
+
const CONFIG_CONDITIONS = ['require', 'types', 'node'];
|
|
75
|
+
|
|
76
|
+
/** @param {string} file */
|
|
77
|
+
const jsonFile = file => (isFile(file) ? file : isFile(`${file}.json`) ? `${file}.json` : null);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The config one installed copy of a package holds for a subpath (`''` for
|
|
81
|
+
* the package alone): where its `exports` send it, else the subpath as
|
|
82
|
+
* written, else the file its package.json names in `tsconfig`, else its
|
|
83
|
+
* `tsconfig.json`. A package's `main` is code, never its config.
|
|
84
|
+
* @param {string} packageDir
|
|
85
|
+
* @param {string} sub
|
|
86
|
+
* @returns {string | null}
|
|
87
|
+
*/
|
|
88
|
+
function packageConfig(packageDir, sub) {
|
|
89
|
+
const pkg = readJsonc(path.join(packageDir, 'package.json')) ?? {};
|
|
90
|
+
if (pkg.exports !== undefined && pkg.exports !== null) {
|
|
91
|
+
const target = conditionalExportTarget(pkg.exports, sub ? `./${sub}` : '.', CONFIG_CONDITIONS);
|
|
92
|
+
return target === null ? null : jsonFile(path.join(packageDir, target));
|
|
93
|
+
}
|
|
94
|
+
if (sub) return jsonFile(path.join(packageDir, sub));
|
|
95
|
+
return jsonFile(path.join(packageDir, typeof pkg.tsconfig === 'string' ? pkg.tsconfig : 'tsconfig.json'));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The config file an `extends` entry names, from the folder of the config
|
|
100
|
+
* that writes it, as TypeScript finds it: a path (`.json` may be left off);
|
|
101
|
+
* or a package's config, from the nearest installed copy that holds it. A
|
|
102
|
+
* package's config is read where it really is, through any link, so what it
|
|
103
|
+
* names in turn resolves from there.
|
|
104
|
+
* @param {unknown} spec
|
|
105
|
+
* @param {string} fromDir
|
|
106
|
+
* @returns {string | null}
|
|
107
|
+
*/
|
|
108
|
+
function extendedFile(spec, fromDir) {
|
|
109
|
+
if (typeof spec !== 'string' || !spec) return null;
|
|
110
|
+
if (spec.startsWith('.') || path.isAbsolute(spec)) return jsonFile(path.resolve(fromDir, spec));
|
|
111
|
+
const parts = spec.split('/');
|
|
112
|
+
const scoped = spec.startsWith('@');
|
|
113
|
+
const name = parts.slice(0, scoped ? 2 : 1).join('/');
|
|
114
|
+
const sub = parts.slice(scoped ? 2 : 1).join('/');
|
|
115
|
+
for (let from = fromDir; ; ) {
|
|
116
|
+
const found = findNodeModulesPackage(from, name);
|
|
117
|
+
if (!found) return null;
|
|
118
|
+
const file = packageConfig(found.packageDir, sub);
|
|
119
|
+
if (file) return fs.realpathSync(file);
|
|
120
|
+
const above = path.dirname(found.hostDir);
|
|
121
|
+
if (above === found.hostDir) return null;
|
|
122
|
+
from = above;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @typedef {object} ReadConfig
|
|
128
|
+
* @property {Record<string, unknown>} options - Compiler options, the extending config's winning key by key.
|
|
129
|
+
* @property {string} baseUrlDir - The folder of the config that writes `baseUrl`.
|
|
130
|
+
* @property {string} pathsDir - The folder of the config that writes `paths`.
|
|
131
|
+
* @property {{list: unknown[], dir: string} | null} files - `files`, from the nearest config that writes it, with that config's folder.
|
|
132
|
+
* @property {{list: unknown[], dir: string} | null} include - `include`, likewise.
|
|
133
|
+
* @property {{list: unknown[], dir: string} | null} exclude - `exclude`, likewise.
|
|
134
|
+
* @property {{path?: unknown}[]} references - The config's own `references`.
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* A config read through its `extends`, as TypeScript merges them: a later
|
|
139
|
+
* entry of a list wins over an earlier one, and the config itself over all.
|
|
140
|
+
* @param {string} file
|
|
141
|
+
* @param {Set<string>} [seen] configs on the way here, so a cycle ends
|
|
142
|
+
* @returns {ReadConfig | null}
|
|
143
|
+
*/
|
|
144
|
+
function readConfig(file, seen = new Set()) {
|
|
145
|
+
if (seen.has(file)) return null;
|
|
146
|
+
const json = readJsonc(file);
|
|
147
|
+
if (!json) return null;
|
|
148
|
+
const dir = path.dirname(file);
|
|
149
|
+
// A jsconfig.json takes JavaScript files unless it says otherwise.
|
|
150
|
+
/** @type {Record<string, unknown>} */
|
|
151
|
+
const options = path.basename(file) === 'jsconfig.json' ? {allowJs: true} : {};
|
|
152
|
+
/** @type {ReadConfig} */
|
|
153
|
+
const config = {options, baseUrlDir: dir, pathsDir: dir, files: null, include: null, exclude: null, references: []};
|
|
154
|
+
const bases = Array.isArray(json.extends) ? json.extends : json.extends === undefined ? [] : [json.extends];
|
|
155
|
+
for (const spec of bases) {
|
|
156
|
+
const baseFile = extendedFile(spec, dir);
|
|
157
|
+
const base = baseFile ? readConfig(baseFile, new Set([...seen, file])) : null;
|
|
158
|
+
if (!base) continue;
|
|
159
|
+
Object.assign(config.options, base.options);
|
|
160
|
+
if ('baseUrl' in base.options) config.baseUrlDir = base.baseUrlDir;
|
|
161
|
+
if ('paths' in base.options) config.pathsDir = base.pathsDir;
|
|
162
|
+
for (const key of /** @type {const} */ (['files', 'include', 'exclude'])) config[key] = base[key] ?? config[key];
|
|
163
|
+
}
|
|
164
|
+
const own = json.compilerOptions && typeof json.compilerOptions === 'object' ? json.compilerOptions : {};
|
|
165
|
+
for (const [key, value] of Object.entries(own)) {
|
|
166
|
+
config.options[key] = value;
|
|
167
|
+
if (key === 'baseUrl') config.baseUrlDir = dir;
|
|
168
|
+
if (key === 'paths') config.pathsDir = dir;
|
|
169
|
+
}
|
|
170
|
+
for (const key of /** @type {const} */ (['files', 'include', 'exclude'])) {
|
|
171
|
+
if (Array.isArray(json[key])) config[key] = {list: json[key], dir};
|
|
172
|
+
}
|
|
173
|
+
config.references = Array.isArray(json.references) ? json.references.filter((/** @type {unknown} */ ref) => ref !== null && typeof ref === 'object') : [];
|
|
174
|
+
return config;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* A path a config writes, with `${configDir}` taken as the folder of the
|
|
179
|
+
* config the project reads, and resolved from `from`.
|
|
180
|
+
* @param {string} value
|
|
181
|
+
* @param {string} from
|
|
182
|
+
* @param {string} configDir
|
|
183
|
+
*/
|
|
184
|
+
const configPath = (value, from, configDir) => path.resolve(from, value.split('${configDir}').join(configDir));
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* A TypeScript `include` or `exclude` pattern as a regular expression over
|
|
188
|
+
* absolute, `/`-separated paths: `*` matches within a folder name, `?` one
|
|
189
|
+
* character of one, and `**` any number of folders.
|
|
190
|
+
* @param {string} pattern absolute
|
|
191
|
+
*/
|
|
192
|
+
function patternRegExp(pattern) {
|
|
193
|
+
const segments = pattern.split(path.sep).join('/').split('/');
|
|
194
|
+
const body = segments
|
|
195
|
+
.map((segment, i) =>
|
|
196
|
+
segment === '**'
|
|
197
|
+
? '(?:/[^/]+)*'
|
|
198
|
+
: `${i === 0 ? '' : '/'}${segment
|
|
199
|
+
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
200
|
+
.replace(/\*/g, '[^/]*')
|
|
201
|
+
.replace(/\?/g, '[^/]')}`,
|
|
202
|
+
)
|
|
203
|
+
.join('');
|
|
204
|
+
return new RegExp(`^${body}$`, process.platform === 'win32' || process.platform === 'darwin' ? 'i' : '');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Whether a config takes `file` as one of its own, by TypeScript's rules: a
|
|
209
|
+
* `files` entry names it; or an `include` pattern matches it (a pattern
|
|
210
|
+
* whose last part has no wildcard and no extension names a folder and all
|
|
211
|
+
* below it), a wildcard matching only TypeScript files (and JavaScript ones
|
|
212
|
+
* with `allowJs`), and no `exclude` pattern matches it or a folder above it.
|
|
213
|
+
* @param {ReadConfig} config
|
|
214
|
+
* @param {string} configDir
|
|
215
|
+
* @param {string} file absolute
|
|
216
|
+
*/
|
|
217
|
+
function includesFile(config, configDir, file) {
|
|
218
|
+
const at = file.split(path.sep).join('/');
|
|
219
|
+
const files = config.files;
|
|
220
|
+
if (files?.list.some(f => typeof f === 'string' && configPath(f, files.dir, configDir) === file)) return true;
|
|
221
|
+
const include = config.include ?? (files ? null : {list: ['**/*'], dir: configDir});
|
|
222
|
+
if (!include) return false;
|
|
223
|
+
const allowJs = config.options.allowJs === true;
|
|
224
|
+
const typed = /\.(?:tsx?|mts|cts)$/i.test(file) || (allowJs && /\.(?:jsx?|mjs|cjs)$/i.test(file));
|
|
225
|
+
const included = include.list.some(spec => {
|
|
226
|
+
if (typeof spec !== 'string') return false;
|
|
227
|
+
const absolute = configPath(spec, include.dir, configDir);
|
|
228
|
+
const last = path.basename(absolute);
|
|
229
|
+
if (/[*?]/.test(last)) return typed && patternRegExp(absolute).test(at);
|
|
230
|
+
if (path.extname(last)) return patternRegExp(absolute).test(at);
|
|
231
|
+
return typed && patternRegExp(path.join(absolute, '**', '*')).test(at);
|
|
232
|
+
});
|
|
233
|
+
if (!included) return false;
|
|
234
|
+
const exclude = config.exclude ?? {list: DEFAULT_EXCLUDE, dir: configDir};
|
|
235
|
+
return !exclude.list.some(spec => {
|
|
236
|
+
if (typeof spec !== 'string') return false;
|
|
237
|
+
const pattern = patternRegExp(configPath(spec, exclude.dir, configDir));
|
|
238
|
+
for (let d = at; d.includes('/'); d = d.slice(0, d.lastIndexOf('/'))) if (pattern.test(d)) return true;
|
|
239
|
+
return false;
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The path patterns a read config gives.
|
|
245
|
+
* @param {ReadConfig} config
|
|
246
|
+
* @param {string} configDir the folder of the config the project reads
|
|
247
|
+
* @returns {PathPattern[]}
|
|
248
|
+
*/
|
|
249
|
+
function patternsOf(config, configDir) {
|
|
250
|
+
const {paths, baseUrl} = config.options;
|
|
251
|
+
if (!paths || typeof paths !== 'object') return [];
|
|
252
|
+
const base = typeof baseUrl === 'string' ? configPath(baseUrl, config.baseUrlDir, configDir) : config.pathsDir;
|
|
253
|
+
/** @type {PathPattern[]} */
|
|
254
|
+
const out = [];
|
|
255
|
+
for (const [key, targets] of Object.entries(paths)) {
|
|
256
|
+
if (!Array.isArray(targets)) continue;
|
|
257
|
+
const star = key.indexOf('*');
|
|
258
|
+
if (star !== key.lastIndexOf('*')) continue;
|
|
259
|
+
out.push({
|
|
260
|
+
key,
|
|
261
|
+
prefix: star === -1 ? key : key.slice(0, star),
|
|
262
|
+
suffix: star === -1 ? '' : key.slice(star + 1),
|
|
263
|
+
wildcard: star !== -1,
|
|
264
|
+
targets: targets
|
|
265
|
+
.filter(t => typeof t === 'string' && t.indexOf('*') === t.lastIndexOf('*'))
|
|
266
|
+
.map(t => configPath(t, base, configDir)),
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return out;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The path patterns that apply to a file, which need not exist yet: from the
|
|
274
|
+
* nearest tsconfig.json (else jsconfig.json) in its folder or above, read
|
|
275
|
+
* through `extends`. When that config does not take the file as its own, a
|
|
276
|
+
* project it references (at any depth) that does lends its patterns, as
|
|
277
|
+
* TypeScript finds a file's project behind a solution-style config.
|
|
278
|
+
* @param {string} file absolute
|
|
279
|
+
* @returns {PathPattern[]}
|
|
280
|
+
*/
|
|
281
|
+
export function pathsFor(file) {
|
|
282
|
+
/** @type {string | null} */
|
|
283
|
+
let nearest = null;
|
|
284
|
+
for (let d = path.dirname(file); !nearest; d = path.dirname(d)) {
|
|
285
|
+
nearest = CONFIG_NAMES.map(name => path.join(d, name)).find(isFile) ?? null;
|
|
286
|
+
if (path.dirname(d) === d) break;
|
|
287
|
+
}
|
|
288
|
+
if (!nearest) return [];
|
|
289
|
+
const visited = new Set();
|
|
290
|
+
/** @type {(configFile: string) => {config: ReadConfig, dir: string} | null} */
|
|
291
|
+
const owning = configFile => {
|
|
292
|
+
if (visited.has(configFile)) return null;
|
|
293
|
+
visited.add(configFile);
|
|
294
|
+
const config = readConfig(configFile);
|
|
295
|
+
if (!config) return null;
|
|
296
|
+
const dir = path.dirname(configFile);
|
|
297
|
+
if (includesFile(config, dir, file)) return {config, dir};
|
|
298
|
+
for (const ref of config.references) {
|
|
299
|
+
if (typeof ref.path !== 'string') continue;
|
|
300
|
+
const target = path.resolve(dir, ref.path);
|
|
301
|
+
const next = isFile(target) ? target : path.join(target, 'tsconfig.json');
|
|
302
|
+
const hit = isFile(next) ? owning(next) : null;
|
|
303
|
+
if (hit) return hit;
|
|
304
|
+
}
|
|
305
|
+
return null;
|
|
306
|
+
};
|
|
307
|
+
const found = owning(nearest);
|
|
308
|
+
if (found) return patternsOf(found.config, found.dir);
|
|
309
|
+
// No project takes the file as its own: the nearest config's patterns
|
|
310
|
+
// still apply, as they always did for a page outside its `include`.
|
|
311
|
+
const config = readConfig(nearest);
|
|
312
|
+
return config ? patternsOf(config, path.dirname(nearest)) : [];
|
|
69
313
|
}
|
|
70
314
|
|
|
71
315
|
/**
|
|
@@ -103,9 +347,10 @@ export const candidatesOf = match => match.pattern.targets.map(t => t.replace('*
|
|
|
103
347
|
* The file a candidate path stands for: itself, with an extension, or its
|
|
104
348
|
* folder's index; null when none exists.
|
|
105
349
|
* @param {string} candidate
|
|
350
|
+
* @param {readonly string[]} [extensions] the extensions to try, in order (default: TypeScript's)
|
|
106
351
|
* @returns {string | null}
|
|
107
352
|
*/
|
|
108
|
-
export function existingFile(candidate) {
|
|
353
|
+
export function existingFile(candidate, extensions = EXTENSIONS) {
|
|
109
354
|
const isFile = (/** @type {string} */ f) => {
|
|
110
355
|
try {
|
|
111
356
|
return fs.statSync(f).isFile();
|
|
@@ -114,8 +359,8 @@ export function existingFile(candidate) {
|
|
|
114
359
|
}
|
|
115
360
|
};
|
|
116
361
|
if (isFile(candidate)) return candidate;
|
|
117
|
-
for (const ext of
|
|
118
|
-
for (const ext of
|
|
362
|
+
for (const ext of extensions) if (isFile(candidate + ext)) return candidate + ext;
|
|
363
|
+
for (const ext of extensions) if (isFile(path.join(candidate, `index${ext}`))) return path.join(candidate, `index${ext}`);
|
|
119
364
|
return null;
|
|
120
365
|
}
|
|
121
366
|
|
|
@@ -86,6 +86,7 @@ export function allErrorCodes(): string[];
|
|
|
86
86
|
* | 'ERR_FILE_EXISTS'
|
|
87
87
|
* | 'ERR_PATH_TRAVERSAL'
|
|
88
88
|
* | 'ERR_WRITE_FAILED'
|
|
89
|
+
* | 'ERR_READ_FAILED'
|
|
89
90
|
* | 'ERR_THEME_INVALID'
|
|
90
91
|
* | 'ERR_THEME_LOAD'
|
|
91
92
|
* | 'ERR_THEME_STALE'
|
|
@@ -111,6 +112,7 @@ export function allErrorCodes(): string[];
|
|
|
111
112
|
* | 'ERR_RENDER_FAILED'
|
|
112
113
|
* | 'ERR_RENDER_NOT_ASTRYX'
|
|
113
114
|
* | 'ERR_RENDER_SOURCE_DAMAGED'
|
|
115
|
+
* | 'ERR_RENDER_NEWER_FORMAT'
|
|
114
116
|
* | 'ERR_THEME_BAD_VALUE'
|
|
115
117
|
* | 'ERR_THEME_NO_MODE'
|
|
116
118
|
* | 'ERR_THEME_UNKNOWN_PART'
|
|
@@ -134,4 +136,4 @@ export const ERROR_CODES: Readonly<Record<ErrorCode, ErrorCode>>;
|
|
|
134
136
|
/**
|
|
135
137
|
* Stable error-code string union. Append-only.
|
|
136
138
|
*/
|
|
137
|
-
export type ErrorCode = ("ERR_UNKNOWN" | "ERR_UNKNOWN_COMMAND" | "ERR_UNKNOWN_SUBCOMMAND" | "ERR_INVALID_OPTION" | "ERR_INVALID_ARGUMENT" | "ERR_MISSING_ARGUMENT" | "ERR_INVALID_LANG" | "ERR_INVALID_DETAIL" | "ERR_NODE_VERSION" | "ERR_CORE_NOT_FOUND" | "ERR_CORE_INCOMPATIBLE" | "ERR_UNKNOWN_COMPONENT" | "ERR_UNKNOWN_HOOK" | "ERR_UNKNOWN_TOPIC" | "ERR_UNKNOWN_SECTION" | "ERR_UNKNOWN_CATEGORY" | "ERR_UNKNOWN_TEMPLATE" | "ERR_AMBIGUOUS_TEMPLATE" | "ERR_AMBIGUOUS_COMPONENT" | "ERR_AMBIGUOUS_THEME" | "ERR_UNKNOWN_THEME" | "ERR_INTEGRATION_ROOT_CONFLICT" | "ERR_INTEGRATION_EXPORT_CONFLICT" | "ERR_UNKNOWN_PACKAGE" | "ERR_UNKNOWN_AGENT" | "ERR_UNKNOWN_FEATURE" | "ERR_UNKNOWN_CODEMOD" | "ERR_CODEMOD_FAILED" | "ERR_CODEMOD_PROTECTED" | "ERR_CODEMOD_PROTECTION_SOURCE" | "ERR_NOT_FOUND" | "ERR_NO_DOC" | "ERR_NO_SHOWCASE" | "ERR_NO_SOURCE" | "ERR_INVALID_DOC" | "ERR_FILE_NOT_FOUND" | "ERR_FILE_EXISTS" | "ERR_PATH_TRAVERSAL" | "ERR_WRITE_FAILED" | "ERR_THEME_INVALID" | "ERR_THEME_LOAD" | "ERR_THEME_STALE" | "ERR_PALETTE_GENERATION" | "ERR_VERSION_DETECT" | "ERR_INVALID_VERSION" | "ERR_DEP_MISSING" | "ERR_GH_CLI" | "ERR_UNKNOWN_POST" | "ERR_FETCH_FAILED" | "ERR_LAYOUT_PARSE" | "ERR_LAYOUT_INVALID" | "ERR_UNCLASSIFIED_EXIT" | "ERR_SIGNAL_TERMINATED" | "ERR_VERSIONS_UNAVAILABLE" | "ERR_PROJECT_REQUIRED" | "ERR_RENDER_COMPILE" | "ERR_RENDER_NO_DEFAULT_EXPORT" | "ERR_RENDER_MISSING_DEPENDENCY" | "ERR_RENDER_BROWSER_API" | "ERR_RENDER_ASSET_TOO_LARGE" | "ERR_RENDER_TIMEOUT" | "ERR_RENDER_FAILED" | "ERR_RENDER_NOT_ASTRYX" | "ERR_RENDER_SOURCE_DAMAGED" | "ERR_THEME_BAD_VALUE" | "ERR_THEME_NO_MODE" | "ERR_THEME_UNKNOWN_PART" | "ERR_THEME_UNKNOWN_VARIANT" | "ERR_THEME_UNKNOWN_STATE" | "ERR_THEME_PRIVATE_TOKEN" | "ERR_THEME_UNKNOWN_TOKEN" | "ERR_THEME_NO_EFFECT" | "ERR_THEME_NOT_CHECKED" | "ERR_THEME_BUSY" | "ERR_THEME_UNKNOWN_THING" | "ERR_THEME_NOT_SET" | "ERR_THEME_NOTHING_TO_UNDO");
|
|
139
|
+
export type ErrorCode = ("ERR_UNKNOWN" | "ERR_UNKNOWN_COMMAND" | "ERR_UNKNOWN_SUBCOMMAND" | "ERR_INVALID_OPTION" | "ERR_INVALID_ARGUMENT" | "ERR_MISSING_ARGUMENT" | "ERR_INVALID_LANG" | "ERR_INVALID_DETAIL" | "ERR_NODE_VERSION" | "ERR_CORE_NOT_FOUND" | "ERR_CORE_INCOMPATIBLE" | "ERR_UNKNOWN_COMPONENT" | "ERR_UNKNOWN_HOOK" | "ERR_UNKNOWN_TOPIC" | "ERR_UNKNOWN_SECTION" | "ERR_UNKNOWN_CATEGORY" | "ERR_UNKNOWN_TEMPLATE" | "ERR_AMBIGUOUS_TEMPLATE" | "ERR_AMBIGUOUS_COMPONENT" | "ERR_AMBIGUOUS_THEME" | "ERR_UNKNOWN_THEME" | "ERR_INTEGRATION_ROOT_CONFLICT" | "ERR_INTEGRATION_EXPORT_CONFLICT" | "ERR_UNKNOWN_PACKAGE" | "ERR_UNKNOWN_AGENT" | "ERR_UNKNOWN_FEATURE" | "ERR_UNKNOWN_CODEMOD" | "ERR_CODEMOD_FAILED" | "ERR_CODEMOD_PROTECTED" | "ERR_CODEMOD_PROTECTION_SOURCE" | "ERR_NOT_FOUND" | "ERR_NO_DOC" | "ERR_NO_SHOWCASE" | "ERR_NO_SOURCE" | "ERR_INVALID_DOC" | "ERR_FILE_NOT_FOUND" | "ERR_FILE_EXISTS" | "ERR_PATH_TRAVERSAL" | "ERR_WRITE_FAILED" | "ERR_READ_FAILED" | "ERR_THEME_INVALID" | "ERR_THEME_LOAD" | "ERR_THEME_STALE" | "ERR_PALETTE_GENERATION" | "ERR_VERSION_DETECT" | "ERR_INVALID_VERSION" | "ERR_DEP_MISSING" | "ERR_GH_CLI" | "ERR_UNKNOWN_POST" | "ERR_FETCH_FAILED" | "ERR_LAYOUT_PARSE" | "ERR_LAYOUT_INVALID" | "ERR_UNCLASSIFIED_EXIT" | "ERR_SIGNAL_TERMINATED" | "ERR_VERSIONS_UNAVAILABLE" | "ERR_PROJECT_REQUIRED" | "ERR_RENDER_COMPILE" | "ERR_RENDER_NO_DEFAULT_EXPORT" | "ERR_RENDER_MISSING_DEPENDENCY" | "ERR_RENDER_BROWSER_API" | "ERR_RENDER_ASSET_TOO_LARGE" | "ERR_RENDER_TIMEOUT" | "ERR_RENDER_FAILED" | "ERR_RENDER_NOT_ASTRYX" | "ERR_RENDER_SOURCE_DAMAGED" | "ERR_RENDER_NEWER_FORMAT" | "ERR_THEME_BAD_VALUE" | "ERR_THEME_NO_MODE" | "ERR_THEME_UNKNOWN_PART" | "ERR_THEME_UNKNOWN_VARIANT" | "ERR_THEME_UNKNOWN_STATE" | "ERR_THEME_PRIVATE_TOKEN" | "ERR_THEME_UNKNOWN_TOKEN" | "ERR_THEME_NO_EFFECT" | "ERR_THEME_NOT_CHECKED" | "ERR_THEME_BUSY" | "ERR_THEME_UNKNOWN_THING" | "ERR_THEME_NOT_SET" | "ERR_THEME_NOTHING_TO_UNDO");
|
|
@@ -207,6 +207,11 @@ export const doc = {
|
|
|
207
207
|
value: 'ERR_WRITE_FAILED',
|
|
208
208
|
description: 'Writing output files failed (and was rolled back).',
|
|
209
209
|
},
|
|
210
|
+
{
|
|
211
|
+
value: 'ERR_READ_FAILED',
|
|
212
|
+
description:
|
|
213
|
+
'An input file cannot be read: no permission on it or on a folder on its path, a folder or other entry that is not a regular file, or another error from the file system.',
|
|
214
|
+
},
|
|
210
215
|
|
|
211
216
|
// Theme build
|
|
212
217
|
{
|
|
@@ -349,7 +354,13 @@ export const doc = {
|
|
|
349
354
|
value: 'ERR_RENDER_SOURCE_DAMAGED',
|
|
350
355
|
stability: 'experimental',
|
|
351
356
|
description:
|
|
352
|
-
'`render --reverse` refused the received file, and nothing was written: its embedded source was removed (a file a render wrote, with no Astryx components left to rebuild from) or is damaged (not valid,
|
|
357
|
+
'`render --reverse` refused the received file, and nothing was written: its embedded source was removed (a file a render wrote, with no Astryx components left to rebuild from), is cut short (also a file a render wrote that ends before it), or is damaged (not valid, a file does not match its checksum, or it names a CLI version that is not a release version), the page holds merge conflict markers, lists a path twice, carries a module, stylesheet or JSON file the page does not reach through its own imports, or an image, font or media file whose bytes are not one, or carries a file a render never embeds: a dotfile or dot-folder, anything under node_modules, a package manifest, lockfile or tool configuration, a file a test, story or benchmark runner would run, or any kind but a page module, stylesheet, JSON file or image. Raised only by the experimental render command.',
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
value: 'ERR_RENDER_NEWER_FORMAT',
|
|
361
|
+
stability: 'experimental',
|
|
362
|
+
description:
|
|
363
|
+
'`render --reverse` was given a file in a newer render format than this CLI reads. Nothing was written. The message names the version of the CLI that wrote the file, which reads it. Raised only by the experimental render command.',
|
|
353
364
|
},
|
|
354
365
|
{
|
|
355
366
|
value: 'ERR_THEME_BAD_VALUE',
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
* | 'ERR_FILE_EXISTS'
|
|
76
76
|
* | 'ERR_PATH_TRAVERSAL'
|
|
77
77
|
* | 'ERR_WRITE_FAILED'
|
|
78
|
+
* | 'ERR_READ_FAILED'
|
|
78
79
|
* | 'ERR_THEME_INVALID'
|
|
79
80
|
* | 'ERR_THEME_LOAD'
|
|
80
81
|
* | 'ERR_THEME_STALE'
|
|
@@ -100,6 +101,7 @@
|
|
|
100
101
|
* | 'ERR_RENDER_FAILED'
|
|
101
102
|
* | 'ERR_RENDER_NOT_ASTRYX'
|
|
102
103
|
* | 'ERR_RENDER_SOURCE_DAMAGED'
|
|
104
|
+
* | 'ERR_RENDER_NEWER_FORMAT'
|
|
103
105
|
* | 'ERR_THEME_BAD_VALUE'
|
|
104
106
|
* | 'ERR_THEME_NO_MODE'
|
|
105
107
|
* | 'ERR_THEME_UNKNOWN_PART'
|
|
@@ -214,6 +216,8 @@ export const ERROR_CODES = Object.freeze({
|
|
|
214
216
|
ERR_PATH_TRAVERSAL: 'ERR_PATH_TRAVERSAL',
|
|
215
217
|
/** Writing output files failed (and was rolled back). */
|
|
216
218
|
ERR_WRITE_FAILED: 'ERR_WRITE_FAILED',
|
|
219
|
+
/** An input file cannot be read: no permission on it or on a folder on its path, a folder or other entry that is not a regular file, or another error from the file system. */
|
|
220
|
+
ERR_READ_FAILED: 'ERR_READ_FAILED',
|
|
217
221
|
|
|
218
222
|
// ── Theme build ──────────────────────────────────────────────────
|
|
219
223
|
/** A theme definition or contributed theme descriptor is invalid. */
|
|
@@ -331,6 +335,12 @@ export const ERROR_CODES = Object.freeze({
|
|
|
331
335
|
* was written.
|
|
332
336
|
*/
|
|
333
337
|
ERR_RENDER_SOURCE_DAMAGED: 'ERR_RENDER_SOURCE_DAMAGED',
|
|
338
|
+
/**
|
|
339
|
+
* `render --reverse` was given a file in a newer render format than this
|
|
340
|
+
* CLI reads. Nothing was written. The message names the CLI version that
|
|
341
|
+
* wrote the file, which reads it.
|
|
342
|
+
*/
|
|
343
|
+
ERR_RENDER_NEWER_FORMAT: 'ERR_RENDER_NEWER_FORMAT',
|
|
334
344
|
/**
|
|
335
345
|
* A value does not fit what it sets: not a color for a color token, not a size for a size, a step (`more`/`less`) on something that is not a dial, or a word a dial does not take. Nothing was changed. Raised only by `experimental theme`.
|
|
336
346
|
*/
|
|
@@ -43,8 +43,9 @@ export function searchComponents(needle: string, coreDir: string, components: Re
|
|
|
43
43
|
}[]>;
|
|
44
44
|
/**
|
|
45
45
|
* The first sentence of a text, whitespace collapsed. A period after "e.g" or
|
|
46
|
-
* "i.e"
|
|
47
|
-
*
|
|
46
|
+
* "i.e", or inside an open quote (a quoted date such as "2. Nov. 2026"), does
|
|
47
|
+
* not end the sentence. Used where a description has to fit on one line:
|
|
48
|
+
* `build`'s text kit, and the text views of `search` and `template --list`.
|
|
48
49
|
* @param {string} text
|
|
49
50
|
* @returns {string}
|
|
50
51
|
*/
|
|
@@ -255,8 +255,9 @@ export async function searchComponents(needle, coreDir, components) {
|
|
|
255
255
|
|
|
256
256
|
/**
|
|
257
257
|
* The first sentence of a text, whitespace collapsed. A period after "e.g" or
|
|
258
|
-
* "i.e"
|
|
259
|
-
*
|
|
258
|
+
* "i.e", or inside an open quote (a quoted date such as "2. Nov. 2026"), does
|
|
259
|
+
* not end the sentence. Used where a description has to fit on one line:
|
|
260
|
+
* `build`'s text kit, and the text views of `search` and `template --list`.
|
|
260
261
|
* @param {string} text
|
|
261
262
|
* @returns {string}
|
|
262
263
|
*/
|
|
@@ -264,9 +265,21 @@ export function firstSentence(text) {
|
|
|
264
265
|
const flat = String(text ?? '').replace(/\s+/g, ' ').trim();
|
|
265
266
|
const ends = /[.!?](?=\s|$)/g;
|
|
266
267
|
for (let m = ends.exec(flat); m; m = ends.exec(flat)) {
|
|
267
|
-
|
|
268
|
+
const before = flat.slice(0, m.index);
|
|
269
|
+
if (!/\b(e\.g|i\.e)$/i.test(before) && !insideQuote(before)) {
|
|
268
270
|
return flat.slice(0, m.index + 1);
|
|
269
271
|
}
|
|
270
272
|
}
|
|
271
273
|
return flat;
|
|
272
274
|
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Whether a text ends inside a quote it opened: an odd count of straight
|
|
278
|
+
* double quotes, or more opening curly quotes than closing ones.
|
|
279
|
+
* @param {string} text
|
|
280
|
+
* @returns {boolean}
|
|
281
|
+
*/
|
|
282
|
+
function insideQuote(text) {
|
|
283
|
+
const count = (/** @type {RegExp} */ re) => (text.match(re) ?? []).length;
|
|
284
|
+
return count(/"/g) % 2 === 1 || count(/\u201C/g) > count(/\u201D/g);
|
|
285
|
+
}
|
|
@@ -35,6 +35,15 @@ export function orderByAffinity<T>(typedName: string, items: T[], namesOf: (item
|
|
|
35
35
|
closest?: boolean;
|
|
36
36
|
typos?: boolean;
|
|
37
37
|
}): T[];
|
|
38
|
+
/**
|
|
39
|
+
* Whether a name carries a typed word longer than one character: the words
|
|
40
|
+
* the `closest` cut of {@link orderByAffinity} counts. When no candidate
|
|
41
|
+
* carries one, that cut leaves every candidate in.
|
|
42
|
+
* @param {string} typedName
|
|
43
|
+
* @param {string} name
|
|
44
|
+
* @returns {boolean}
|
|
45
|
+
*/
|
|
46
|
+
export function carriesTypedWord(typedName: string, name: string): boolean;
|
|
38
47
|
/**
|
|
39
48
|
* Docs route suggestions, closest to the typed route first. When every
|
|
40
49
|
* suggestion sits under one namespace the typed route also starts with, that
|
|
@@ -206,6 +206,19 @@ function orderByWords(typedName, items, namesOf, options) {
|
|
|
206
206
|
return scored.filter((_, i) => tiers[i] >= need).map(s => s.item);
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Whether a name carries a typed word longer than one character: the words
|
|
211
|
+
* the `closest` cut of {@link orderByAffinity} counts. When no candidate
|
|
212
|
+
* carries one, that cut leaves every candidate in.
|
|
213
|
+
* @param {string} typedName
|
|
214
|
+
* @param {string} name
|
|
215
|
+
* @returns {boolean}
|
|
216
|
+
*/
|
|
217
|
+
export function carriesTypedWord(typedName, name) {
|
|
218
|
+
const words = nameWords(typedName).filter(w => w.length > 1);
|
|
219
|
+
return affinityOf(words, name) >= 10;
|
|
220
|
+
}
|
|
221
|
+
|
|
209
222
|
/**
|
|
210
223
|
* Docs route suggestions, closest to the typed route first. When every
|
|
211
224
|
* suggestion sits under one namespace the typed route also starts with, that
|
package/host/index.mjs
CHANGED
|
@@ -272,19 +272,21 @@ export async function runHostedCli(options) {
|
|
|
272
272
|
);
|
|
273
273
|
|
|
274
274
|
const {runCli} = await import('../clients/cli/run.mjs');
|
|
275
|
+
const {recordRunFor} = await import('../foundation/fs/gather-cache.mjs');
|
|
275
276
|
const run = () =>
|
|
276
277
|
runCli({
|
|
277
278
|
cliRoot: CLI_ROOT,
|
|
278
279
|
argv: [...input.argv],
|
|
279
280
|
declinedProjectCli: input.declinedProjectCli,
|
|
280
281
|
});
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
282
|
+
const {cliCommand} = input;
|
|
283
|
+
// A hosted run records what it reads as a run of the bin does, so a later
|
|
284
|
+
// run with the same inputs reuses its kept catalog.
|
|
285
|
+
const answered = await recordRunFor(input.argv, async () => {
|
|
286
|
+
if (cliCommand === undefined) return run();
|
|
285
287
|
const {runWithCliDoor} = await import('../foundation/env/cli-command.mjs');
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
+
return runWithCliDoor(cliCommand, run);
|
|
289
|
+
});
|
|
288
290
|
// Another package set's host entry answered the run (INV30).
|
|
289
291
|
if (answered) return answered;
|
|
290
292
|
const code = process.exitCode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.17-canary.gb36275e",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"zod": "^4.6.7"
|
|
128
128
|
},
|
|
129
129
|
"peerDependencies": {
|
|
130
|
-
"@astryxdesign/core": "
|
|
130
|
+
"@astryxdesign/core": "0.7.17-canary.gb36275e"
|
|
131
131
|
},
|
|
132
132
|
"peerDependenciesMeta": {
|
|
133
133
|
"@astryxdesign/core": {
|
|
@@ -135,10 +135,10 @@
|
|
|
135
135
|
}
|
|
136
136
|
},
|
|
137
137
|
"devDependencies": {
|
|
138
|
-
"@astryxdesign/charts": "
|
|
139
|
-
"@astryxdesign/core": "
|
|
140
|
-
"@astryxdesign/lab": "
|
|
141
|
-
"@astryxdesign/theme-neutral": "
|
|
138
|
+
"@astryxdesign/charts": "0.7.17-canary.gb36275e",
|
|
139
|
+
"@astryxdesign/core": "0.7.17-canary.gb36275e",
|
|
140
|
+
"@astryxdesign/lab": "0.7.17-canary.gb36275e",
|
|
141
|
+
"@astryxdesign/theme-neutral": "0.7.17-canary.gb36275e",
|
|
142
142
|
"@heroicons/react": "^2.2.0",
|
|
143
143
|
"@stylexjs/stylex": "^0.19.1",
|
|
144
144
|
"@types/babel__core": "^7.20.5",
|