@astryxdesign/cli 0.7.15 → 0.7.16-canary.g3aa244b
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 +5 -3
- package/api/build/_adapter.d.mts +1 -0
- package/api/build/blocks/blocks.d.mts +1 -0
- package/api/build/blocks/blocks.mjs +18 -1
- package/api/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +35 -0
- package/api/doctor/_adapter.mjs +69 -0
- package/api/doctor/built-checks.mjs +1 -1
- package/api/doctor/doctor.d.mts +18 -0
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.mjs +104 -4
- package/api/doctor/theme-checks.mjs +6 -10
- package/api/integration/add-contribution.mjs +3 -3
- package/api/integration/pack-check.mjs +14 -8
- package/api/integration/validate-integration.mjs +1 -1
- package/api/search/_adapter.mjs +15 -16
- package/api/search/_entries.d.mts +2 -1
- package/api/search/_entries.mjs +28 -1
- package/api/swizzle/_moduleGraph.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/_fork.mjs +1 -1
- package/api/theme/build/build.d.mts +116 -32
- package/api/theme/build/build.mjs +449 -102
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +102 -25
- package/api/theme/theme.type.d.mts +5 -1
- package/api/theme/theme.type.mjs +2 -1
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +32 -2
- package/api/theme-edit/_adapter.mjs +264 -40
- package/api/theme-edit/_check.d.mts +93 -4
- package/api/theme-edit/_check.mjs +1727 -223
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +292 -219
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +20 -1
- package/api/theme-edit/_context.d.mts +31 -1
- package/api/theme-edit/_context.mjs +445 -41
- package/api/theme-edit/_css.d.mts +60 -1
- package/api/theme-edit/_css.mjs +404 -28
- package/api/theme-edit/_edit.d.mts +25 -0
- package/api/theme-edit/_edit.mjs +1532 -149
- package/api/theme-edit/_how-commands.d.mts +11 -26
- package/api/theme-edit/_how-commands.mjs +30 -2
- package/api/theme-edit/_how-question.d.mts +7 -0
- package/api/theme-edit/_how-question.mjs +1304 -176
- package/api/theme-edit/_how.mjs +144 -30
- package/api/theme-edit/_overview.mjs +2 -0
- package/api/theme-edit/_palette.d.mts +38 -0
- package/api/theme-edit/_palette.mjs +305 -71
- package/api/theme-edit/_parts.d.mts +33 -0
- package/api/theme-edit/_parts.mjs +138 -9
- package/api/theme-edit/_png.d.mts +18 -0
- package/api/theme-edit/_png.mjs +95 -14
- package/api/theme-edit/_preview-app.d.mts +36 -1
- package/api/theme-edit/_preview-app.mjs +1415 -96
- package/api/theme-edit/_preview.d.mts +64 -3
- package/api/theme-edit/_preview.mjs +514 -31
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +46 -12
- package/api/theme-edit/_settings.d.mts +278 -5
- package/api/theme-edit/_settings.mjs +2741 -195
- package/api/theme-edit/_tables.d.mts +24 -0
- package/api/theme-edit/_tables.mjs +211 -149
- package/api/theme-edit/_vet.d.mts +42 -0
- package/api/theme-edit/_vet.mjs +144 -0
- package/api/theme-edit/theme-edit.type.d.mts +20 -2
- package/api/theme-edit/theme-edit.type.mjs +6 -2
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/api/upgrade/registry/registry.mjs +6 -1
- package/assets/codemods/parse.mjs +2 -2
- package/assets/docs/tree/single-component.doc.mjs +11 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -2
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/preview-app/package.json +1 -0
- package/assets/preview-app/src/app/globals.css +1 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/dashboard/page.tsx +1 -1
- package/authoring/doctypes/_schema.d.mts +52 -5
- package/authoring/doctypes/_schema.mjs +62 -7
- package/authoring/doctypes/base/type.ts +10 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/function/function.doc.mjs +6 -0
- package/authoring/doctypes/function/type.ts +3 -0
- package/authoring/doctypes/legacy.mjs +5 -1
- package/authoring/index.d.ts +1 -0
- package/authoring/shadcn/source-variants.d.mts +1 -1
- package/authoring/shadcn/source-variants.mjs +32 -10
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/theme.mjs +239 -45
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
- 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 +1 -1
- 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-template.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +3 -1
- package/clients/cli/commands/theme.mjs +190 -46
- package/clients/cli/formatters/index.mjs +7 -4
- package/clients/cli/lib/cli-error.mjs +9 -3
- package/clients/cli/lib/component-format.mjs +27 -9
- package/clients/cli/lib/json-shim.mjs +72 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +49 -0
- package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
- package/foundation/agent-docs/agent-docs-target.mjs +9 -17
- package/foundation/agent-docs/agent-docs.mjs +3 -2
- package/foundation/config/config-writer.mjs +2 -2
- package/foundation/config/project.mjs +60 -14
- package/foundation/discovery/component-discovery.mjs +5 -17
- package/foundation/discovery/icon-set-writer.mjs +1 -1
- package/foundation/discovery/module-exports.mjs +1 -15
- package/foundation/discovery/template-adapter.mjs +44 -19
- package/foundation/discovery/template-source-tree.mjs +3 -16
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +61 -43
- package/foundation/fs/exact-codec.d.mts +35 -0
- package/foundation/fs/exact-codec.mjs +148 -0
- package/foundation/fs/gather-cache.d.mts +15 -5
- package/foundation/fs/gather-cache.mjs +129 -31
- package/foundation/fs/paths.d.mts +39 -0
- package/foundation/fs/paths.mjs +44 -11
- package/foundation/fs/read-record.mjs +11 -1
- package/foundation/integrations/contribution-fixes.mjs +1 -16
- package/foundation/integrations/may-have-integrations.mjs +3 -2
- package/foundation/integrations/public-imports.mjs +1 -1
- package/foundation/render/embedded-imports.mjs +1 -1
- package/foundation/render/host-exit.d.mts +8 -0
- package/foundation/render/host-exit.mjs +11 -0
- package/foundation/render/page-host.mjs +56 -10
- package/foundation/render/page-worker.mjs +14 -0
- package/foundation/render/render-page.mjs +37 -2
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +5 -0
- package/foundation/response/error-codes.mjs +3 -0
- package/foundation/response/json.d.mts +15 -0
- package/foundation/response/json.mjs +52 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/runtime/lazy-dependencies.d.mts +14 -0
- package/foundation/runtime/lazy-dependencies.mjs +82 -0
- package/foundation/xle/browser.d.mts +2 -2
- package/package.json +7 -6
package/clients/cli/run.mjs
CHANGED
|
@@ -28,6 +28,55 @@
|
|
|
28
28
|
* when, in a hosted run, that release's host entry answered
|
|
29
29
|
*/
|
|
30
30
|
export async function runCli({cliRoot, argv, declinedProjectCli}) {
|
|
31
|
+
// A folder deleted under the shell (another terminal, `git clean`): every
|
|
32
|
+
// command reads the working folder first, so say so once, plainly, in
|
|
33
|
+
// text and in --json, instead of a stack trace.
|
|
34
|
+
try {
|
|
35
|
+
process.cwd();
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (/** @type {any} */ (e)?.code !== 'ENOENT') throw e;
|
|
38
|
+
const fs = await import('node:fs');
|
|
39
|
+
const path = await import('node:path');
|
|
40
|
+
const os = await import('node:os');
|
|
41
|
+
let up = process.env.PWD ? path.dirname(process.env.PWD) : null;
|
|
42
|
+
while (up && !fs.existsSync(up) && path.dirname(up) !== up)
|
|
43
|
+
up = path.dirname(up);
|
|
44
|
+
const cd = up && fs.existsSync(up) ? up : '~';
|
|
45
|
+
// Help, the version and docs read no folder: run them from an existing
|
|
46
|
+
// one.
|
|
47
|
+
const first = argv.find(a => !a.startsWith('-'));
|
|
48
|
+
if (
|
|
49
|
+
argv.length === 0 ||
|
|
50
|
+
argv.some(a => ['--help', '-h', '--version', '-V'].includes(a)) ||
|
|
51
|
+
first === 'docs' ||
|
|
52
|
+
first === 'help'
|
|
53
|
+
) {
|
|
54
|
+
process.chdir(cd === '~' ? os.homedir() : cd);
|
|
55
|
+
return runCli({cliRoot, argv, declinedProjectCli});
|
|
56
|
+
}
|
|
57
|
+
const message =
|
|
58
|
+
'The current folder no longer exists (it was deleted or moved). Nothing was written. cd to an existing folder and run the command again.';
|
|
59
|
+
const {quoteCommandArgument} =
|
|
60
|
+
await import('../../foundation/env/package-manager.mjs');
|
|
61
|
+
const suggestions = [
|
|
62
|
+
{
|
|
63
|
+
name: `cd ${cd === '~' ? cd : quoteCommandArgument(cd)}`,
|
|
64
|
+
reason: 'an existing folder',
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
if (argv.includes('--json')) {
|
|
68
|
+
const {toErrorEnvelope} =
|
|
69
|
+
await import('../../foundation/response/json.mjs');
|
|
70
|
+
fs.writeSync(
|
|
71
|
+
1,
|
|
72
|
+
`${JSON.stringify(toErrorEnvelope(message, suggestions, 'ERR_PROJECT_REQUIRED'), null, 2)}\n`,
|
|
73
|
+
);
|
|
74
|
+
} else {
|
|
75
|
+
fs.writeSync(2, `Error: ${message}\n ${suggestions[0].name}\n`);
|
|
76
|
+
}
|
|
77
|
+
process.exitCode = 1;
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
31
80
|
const {startRun} = await import('../../foundation/release/handoff.mjs');
|
|
32
81
|
const answered = await startRun({cliRoot, argv, declinedProjectCli});
|
|
33
82
|
if (answered) return answered;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* `p` resolved, through symlinks when it exists.
|
|
6
|
-
* @param {string} p
|
|
7
|
-
* @returns {string}
|
|
8
|
-
*/
|
|
9
|
-
export function realDir(p: string): string;
|
|
10
4
|
/**
|
|
11
5
|
* Throw {@link AgentDocsHomeError} when `targetDir` is the home folder, or a
|
|
12
6
|
* settings folder in it outside a project.
|
|
@@ -32,6 +26,7 @@ export function resolveAgentDocsRoot(cwd: string): string | null;
|
|
|
32
26
|
* @returns {string}
|
|
33
27
|
*/
|
|
34
28
|
export function agentDocsTargetDir(cwd: string): string;
|
|
29
|
+
export { realDir };
|
|
35
30
|
/**
|
|
36
31
|
* Thrown when agent docs would be written into the home folder, or into a
|
|
37
32
|
* settings folder in it such as `~/.gemini` outside a project. Agents read the
|
|
@@ -47,3 +42,4 @@ export class AgentDocsHomeError extends Error {
|
|
|
47
42
|
}
|
|
48
43
|
/** Folders that mark a repository root; the project search stops there. */
|
|
49
44
|
export const REPOSITORY_MARKERS: string[];
|
|
45
|
+
import { realDir } from '../fs/paths.mjs';
|
|
@@ -5,15 +5,20 @@
|
|
|
5
5
|
* @input The folder a run starts in, the home folder, and the package.json
|
|
6
6
|
* files and repository markers above the folder
|
|
7
7
|
* @output AgentDocsHomeError, assertAgentDocsTarget, resolveAgentDocsRoot and
|
|
8
|
-
* agentDocsTargetDir, with the
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* agentDocsTargetDir, with the REPOSITORY_MARKERS helper (and realDir,
|
|
9
|
+
* re-exported from ../fs/paths.mjs)
|
|
10
|
+
* @position The folder agent docs go to. It imports node builtins and the
|
|
11
|
+
* CLI's paths module only, so the per-command setup nudge
|
|
12
|
+
* (clients/cli/index.mjs) loads it without agent-docs.mjs's discovery and
|
|
13
|
+
* config. agent-docs.mjs re-exports it.
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
import * as fs from 'node:fs';
|
|
15
17
|
import * as os from 'node:os';
|
|
16
18
|
import * as path from 'node:path';
|
|
19
|
+
import {realDir} from '../fs/paths.mjs';
|
|
20
|
+
|
|
21
|
+
export {realDir};
|
|
17
22
|
|
|
18
23
|
/**
|
|
19
24
|
* Thrown when agent docs would be written into the home folder, or into a
|
|
@@ -34,19 +39,6 @@ export class AgentDocsHomeError extends Error {
|
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
41
|
|
|
37
|
-
/**
|
|
38
|
-
* `p` resolved, through symlinks when it exists.
|
|
39
|
-
* @param {string} p
|
|
40
|
-
* @returns {string}
|
|
41
|
-
*/
|
|
42
|
-
export function realDir(p) {
|
|
43
|
-
try {
|
|
44
|
-
return fs.realpathSync(path.resolve(p));
|
|
45
|
-
} catch {
|
|
46
|
-
return path.resolve(p);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
42
|
/**
|
|
51
43
|
* `dir` relative to the home folder, compared without symlinks (and without
|
|
52
44
|
* case on Windows). null when there is no home folder.
|
|
@@ -83,8 +83,9 @@ import {
|
|
|
83
83
|
export {discoverAgentDocs, isAstryxInitialized, isAstryxPromptInReach};
|
|
84
84
|
|
|
85
85
|
// The folder the docs go to lives in ./agent-docs-target.mjs, with node
|
|
86
|
-
// builtins only. So the per-command setup nudge
|
|
87
|
-
// module's discovery and config. Re-exported here for
|
|
86
|
+
// builtins and the CLI's paths module only. So the per-command setup nudge
|
|
87
|
+
// loads it without this module's discovery and config. Re-exported here for
|
|
88
|
+
// existing importers.
|
|
88
89
|
export {
|
|
89
90
|
AgentDocsHomeError,
|
|
90
91
|
agentDocsTargetDir,
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
import * as fs from 'node:fs';
|
|
29
29
|
import * as path from 'node:path';
|
|
30
30
|
import {randomUUID} from 'node:crypto';
|
|
31
|
-
import jscodeshift from '
|
|
31
|
+
import {jscodeshift as loadJscodeshift} from '../runtime/lazy-dependencies.mjs';
|
|
32
32
|
import {
|
|
33
33
|
findManifestObject,
|
|
34
34
|
unwrapManifestExpression,
|
|
@@ -180,7 +180,7 @@ export function setConfigValue(projectDir, key, value) {
|
|
|
180
180
|
}
|
|
181
181
|
assertWritable(projectDir, existing);
|
|
182
182
|
const source = fs.readFileSync(existing, 'utf-8');
|
|
183
|
-
const j =
|
|
183
|
+
const j = loadJscodeshift().withParser('tsx');
|
|
184
184
|
const ast = j(source);
|
|
185
185
|
let object = findManifestObject(j, ast);
|
|
186
186
|
const refuse = () =>
|
|
@@ -118,6 +118,16 @@ import {
|
|
|
118
118
|
const ISSUES_CODEC = {
|
|
119
119
|
encode: (/** @type {any} */ value) => value,
|
|
120
120
|
decode: (/** @type {any} */ value) => value,
|
|
121
|
+
/** A list of issue records, each with its code, severity and message. */
|
|
122
|
+
valid: (/** @type {any} */ value) =>
|
|
123
|
+
Array.isArray(value) &&
|
|
124
|
+
value.every(
|
|
125
|
+
issue =>
|
|
126
|
+
issue != null &&
|
|
127
|
+
typeof issue.code === 'string' &&
|
|
128
|
+
typeof issue.severity === 'string' &&
|
|
129
|
+
typeof issue.message === 'string',
|
|
130
|
+
),
|
|
121
131
|
};
|
|
122
132
|
|
|
123
133
|
export {CONFIG_BASENAMES, findConfigPath} from './config-path.mjs';
|
|
@@ -1320,6 +1330,28 @@ export class Project {
|
|
|
1320
1330
|
return integration?.issuesUrl;
|
|
1321
1331
|
}
|
|
1322
1332
|
|
|
1333
|
+
/**
|
|
1334
|
+
* The passes that find every integration issue: template and component
|
|
1335
|
+
* replacement validity (over Core plus every integration), then each
|
|
1336
|
+
* integration's own checks.
|
|
1337
|
+
*/
|
|
1338
|
+
async #runIssuePasses() {
|
|
1339
|
+
// Template replacement validity depends on the combined Core +
|
|
1340
|
+
// integration catalog. Resolve it first so issue results never depend
|
|
1341
|
+
// on which discovery method the caller happened to invoke earlier. Only
|
|
1342
|
+
// an integration's own templates can replace one, so with none, Core's
|
|
1343
|
+
// templates stay unread.
|
|
1344
|
+
if (this.#loadedIntegrations.some(hasTemplatesRoot)) {
|
|
1345
|
+
await this.templates();
|
|
1346
|
+
}
|
|
1347
|
+
// Component replacement validity likewise depends on Core plus every
|
|
1348
|
+
// integration's components.
|
|
1349
|
+
await this.componentReplacements();
|
|
1350
|
+
for (const integration of this.#loadedIntegrations) {
|
|
1351
|
+
await this.#collectIssues(integration);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1323
1355
|
/**
|
|
1324
1356
|
* The accumulated integration issues (deduped by package, code, message).
|
|
1325
1357
|
* When called directly, also validates any configured integration not yet
|
|
@@ -1332,20 +1364,34 @@ export class Project {
|
|
|
1332
1364
|
// templates and components declare no replacement. A project with no
|
|
1333
1365
|
// integration skips them.
|
|
1334
1366
|
if (this.#loadedIntegrations.length > 0) {
|
|
1335
|
-
//
|
|
1336
|
-
//
|
|
1337
|
-
//
|
|
1338
|
-
//
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1367
|
+
// A function of the files the passes read and of the issues already
|
|
1368
|
+
// found (which the key holds): the kept gather stamps the files, so a
|
|
1369
|
+
// later run with every one unchanged reads the whole list back and
|
|
1370
|
+
// skips the passes, discovery included.
|
|
1371
|
+
const before = this.#issues.map(i => ({...i}));
|
|
1372
|
+
const all = await persistedGather(
|
|
1373
|
+
[
|
|
1374
|
+
'project-issues',
|
|
1375
|
+
this.#cwd,
|
|
1376
|
+
// The Core the replacement pass reads: a carried Core for everyday
|
|
1377
|
+
// commands, the project's own for doctor.
|
|
1378
|
+
this.#core,
|
|
1379
|
+
this.coreDir() ?? null,
|
|
1380
|
+
this.#loadedIntegrations.map(
|
|
1381
|
+
integration => integration.__packageDir ?? integration.name ?? null,
|
|
1382
|
+
),
|
|
1383
|
+
Boolean(this.#config.experimental?.iconSet),
|
|
1384
|
+
before,
|
|
1385
|
+
],
|
|
1386
|
+
async () => {
|
|
1387
|
+
await this.#runIssuePasses();
|
|
1388
|
+
return this.#issues.map(i => ({...i}));
|
|
1389
|
+
},
|
|
1390
|
+
ISSUES_CODEC,
|
|
1391
|
+
);
|
|
1392
|
+
this.#issues = all.map((/** @type {ProjectIntegrationIssue} */ i) => ({
|
|
1393
|
+
...i,
|
|
1394
|
+
}));
|
|
1349
1395
|
}
|
|
1350
1396
|
// Return a stable copy so callers can't mutate internal state.
|
|
1351
1397
|
return this.#issues.map(i => ({...i}));
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as fs from 'node:fs';
|
|
8
|
-
import {createRequire} from 'node:module';
|
|
9
8
|
import * as path from 'node:path';
|
|
10
9
|
import {DOC_EXPORTS} from '../doc-compiler/read.mjs';
|
|
11
10
|
import {
|
|
@@ -25,12 +24,8 @@ import {
|
|
|
25
24
|
moduleExportsName,
|
|
26
25
|
staticExportObject,
|
|
27
26
|
} from './module-exports.mjs';
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
sourceExportTarget,
|
|
31
|
-
} from './package-exports.mjs';
|
|
32
|
-
|
|
33
|
-
const require = createRequire(import.meta.url);
|
|
27
|
+
import {inspectPackageExport, sourceExportTarget} from './package-exports.mjs';
|
|
28
|
+
import {babelParser} from '../runtime/lazy-dependencies.mjs';
|
|
34
29
|
|
|
35
30
|
const SKIP_DIRS = new Set(['hooks', 'utils', '__tests__', 'node_modules']);
|
|
36
31
|
|
|
@@ -176,9 +171,6 @@ function readDocMeta(docPath) {
|
|
|
176
171
|
}
|
|
177
172
|
}
|
|
178
173
|
|
|
179
|
-
/** @type {typeof import('@babel/parser') | undefined} */
|
|
180
|
-
let babelParser;
|
|
181
|
-
|
|
182
174
|
/**
|
|
183
175
|
* A property of an object literal, by its plain key.
|
|
184
176
|
* @param {any} object - an ObjectExpression node
|
|
@@ -211,13 +203,9 @@ function docMemberNames(source) {
|
|
|
211
203
|
/** @type {any} */
|
|
212
204
|
let ast;
|
|
213
205
|
try {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
{
|
|
218
|
-
sourceType: 'module',
|
|
219
|
-
},
|
|
220
|
-
);
|
|
206
|
+
ast = babelParser().parse(source, {
|
|
207
|
+
sourceType: 'module',
|
|
208
|
+
});
|
|
221
209
|
} catch {
|
|
222
210
|
return [];
|
|
223
211
|
}
|
|
@@ -25,7 +25,7 @@ import * as fs from 'node:fs';
|
|
|
25
25
|
import * as path from 'node:path';
|
|
26
26
|
import {randomUUID} from 'node:crypto';
|
|
27
27
|
import {AsyncLocalStorage} from 'node:async_hooks';
|
|
28
|
-
import {parse} from '
|
|
28
|
+
import {babelParse as parse} from '../runtime/lazy-dependencies.mjs';
|
|
29
29
|
import {parseIconSetData} from '../../authoring/doctypes/icon-set/parse.mjs';
|
|
30
30
|
import {ICON_NAMES} from '../../authoring/doctypes/icon-set/icon-names.mjs';
|
|
31
31
|
import {assertWithin} from '../fs/path-safety.mjs';
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
|
|
20
20
|
import * as fs from 'node:fs';
|
|
21
21
|
import * as path from 'node:path';
|
|
22
|
-
import {createRequire} from 'node:module';
|
|
23
22
|
import {findInstalledPackage} from '../fs/paths.mjs';
|
|
24
23
|
import {inspectPackageExport} from './package-exports.mjs';
|
|
24
|
+
import {babelParser} from '../runtime/lazy-dependencies.mjs';
|
|
25
25
|
|
|
26
26
|
const MODULE_EXTENSIONS = [
|
|
27
27
|
'.mjs',
|
|
@@ -103,20 +103,6 @@ function moduleText(file) {
|
|
|
103
103
|
return text;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
const requireFromHere = createRequire(import.meta.url);
|
|
107
|
-
/** @type {typeof import('@babel/parser') | undefined} */
|
|
108
|
-
let parser;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* @babel/parser, loaded on first use: a run that reads no module's exports
|
|
112
|
-
* never loads it.
|
|
113
|
-
* @returns {typeof import('@babel/parser')}
|
|
114
|
-
*/
|
|
115
|
-
function babelParser() {
|
|
116
|
-
parser ??= requireFromHere('@babel/parser');
|
|
117
|
-
return /** @type {typeof import('@babel/parser')} */ (parser);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
106
|
/** @param {string} file */
|
|
121
107
|
function parseModule(file) {
|
|
122
108
|
const stamp = fileStamp(file);
|
|
@@ -24,11 +24,10 @@
|
|
|
24
24
|
|
|
25
25
|
import * as fs from 'node:fs';
|
|
26
26
|
import * as path from 'node:path';
|
|
27
|
-
import {createRequire} from 'node:module';
|
|
28
27
|
import {readDocView} from '../doc-compiler/read.mjs';
|
|
29
28
|
import {importDocModule} from '../doc-compiler/import.mjs';
|
|
30
29
|
import {readStore, storedKey} from '../doc-compiler/stored-docs.mjs';
|
|
31
|
-
import {CLI_ROOT, discoverExternalPackages} from '../fs/paths.mjs';
|
|
30
|
+
import {CLI_ROOT, discoverExternalPackages, realDir} from '../fs/paths.mjs';
|
|
32
31
|
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
33
32
|
import {CORE_PROVIDER_ID} from '../identity/providers.mjs';
|
|
34
33
|
import {Project} from '../config/project.mjs';
|
|
@@ -40,8 +39,10 @@ import {
|
|
|
40
39
|
writtenNames,
|
|
41
40
|
TEMPLATE_COMPONENTS_FILE,
|
|
42
41
|
} from './template-source-tree.mjs';
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
import {persistedGather} from '../fs/gather-cache.mjs';
|
|
43
|
+
import {EXACT_CODEC} from '../fs/exact-codec.mjs';
|
|
44
|
+
import {hostedRun} from '../runtime/package-root.mjs';
|
|
45
|
+
import {babelParser} from '../runtime/lazy-dependencies.mjs';
|
|
45
46
|
|
|
46
47
|
/** Identity used for core (built-in) templates in package-scoped listings. */
|
|
47
48
|
const CORE_PACKAGE = CORE_PROVIDER_ID;
|
|
@@ -1070,19 +1071,6 @@ function expressionUse(source, open, close) {
|
|
|
1070
1071
|
return null;
|
|
1071
1072
|
}
|
|
1072
1073
|
|
|
1073
|
-
/** @type {typeof import('@babel/parser') | undefined} */
|
|
1074
|
-
let babelParser;
|
|
1075
|
-
|
|
1076
|
-
/**
|
|
1077
|
-
* The template source parser, loaded on first use so listing templates
|
|
1078
|
-
* never pays for it.
|
|
1079
|
-
* @returns {typeof import('@babel/parser')}
|
|
1080
|
-
*/
|
|
1081
|
-
function templateSourceParser() {
|
|
1082
|
-
babelParser ??= require('@babel/parser');
|
|
1083
|
-
return /** @type {typeof import('@babel/parser')} */ (babelParser);
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
1074
|
/**
|
|
1087
1075
|
* The [start, end) range of every comment in `source`, or none when it does
|
|
1088
1076
|
* not parse as TSX.
|
|
@@ -1091,7 +1079,7 @@ function templateSourceParser() {
|
|
|
1091
1079
|
*/
|
|
1092
1080
|
function commentRanges(source) {
|
|
1093
1081
|
try {
|
|
1094
|
-
const {comments} =
|
|
1082
|
+
const {comments} = babelParser().parse(source, {
|
|
1095
1083
|
sourceType: 'module',
|
|
1096
1084
|
plugins: ['jsx', 'typescript'],
|
|
1097
1085
|
});
|
|
@@ -1569,6 +1557,18 @@ export async function discoverAllUnresolved(cwd = process.cwd()) {
|
|
|
1569
1557
|
);
|
|
1570
1558
|
}
|
|
1571
1559
|
|
|
1560
|
+
/** Template discovery's records, kept exactly, with the shape they need. */
|
|
1561
|
+
const TEMPLATE_SOURCES_CODEC = {
|
|
1562
|
+
...EXACT_CODEC,
|
|
1563
|
+
valid: (/** @type {any} */ value) =>
|
|
1564
|
+
value != null &&
|
|
1565
|
+
Array.isArray(value.templates) &&
|
|
1566
|
+
Array.isArray(value.errors) &&
|
|
1567
|
+
value.templates.every(
|
|
1568
|
+
(/** @type {any} */ t) => t != null && typeof t.name === 'string',
|
|
1569
|
+
),
|
|
1570
|
+
};
|
|
1571
|
+
|
|
1572
1572
|
/**
|
|
1573
1573
|
* Resolve replacement declarations while retaining package-addressable entries
|
|
1574
1574
|
* that are shadowed or rejected in the default discovery view.
|
|
@@ -1576,6 +1576,31 @@ export async function discoverAllUnresolved(cwd = process.cwd()) {
|
|
|
1576
1576
|
* @returns {Promise<{templates: DiscoveredTemplate[], errors: Array<TemplateDiscoveryError | TemplateReplacementError>}>}
|
|
1577
1577
|
*/
|
|
1578
1578
|
async function resolveAllSources(cwd = process.cwd()) {
|
|
1579
|
+
// A function of the files discovery reads, which the kept gather stamps:
|
|
1580
|
+
// a later run with every one unchanged reads the records back.
|
|
1581
|
+
return /** @type {Awaited<ReturnType<typeof resolveAllSourcesNow>>} */ (
|
|
1582
|
+
await persistedGather(
|
|
1583
|
+
// The folder, and the copy of the CLI that answers with the
|
|
1584
|
+
// integrations a host approves: outside a project the integrations
|
|
1585
|
+
// beside the answering copy load too.
|
|
1586
|
+
[
|
|
1587
|
+
'template-sources',
|
|
1588
|
+
realDir(cwd),
|
|
1589
|
+
CLI_ROOT,
|
|
1590
|
+
hostedRun()?.integrations ?? [],
|
|
1591
|
+
],
|
|
1592
|
+
() => resolveAllSourcesNow(cwd),
|
|
1593
|
+
TEMPLATE_SOURCES_CODEC,
|
|
1594
|
+
)
|
|
1595
|
+
);
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
/**
|
|
1599
|
+
* resolveAllSources, worked out now.
|
|
1600
|
+
* @param {string} cwd
|
|
1601
|
+
* @returns {Promise<{templates: DiscoveredTemplate[], errors: Array<TemplateDiscoveryError | TemplateReplacementError>}>}
|
|
1602
|
+
*/
|
|
1603
|
+
async function resolveAllSourcesNow(cwd) {
|
|
1579
1604
|
const discovered = await discoverAllSources(cwd);
|
|
1580
1605
|
const replacementErrors = discovered.errors.filter(
|
|
1581
1606
|
error => error.replacementTarget != null,
|
|
@@ -2079,7 +2104,7 @@ function topLevelBindings(src) {
|
|
|
2079
2104
|
const astryxImports = new Map();
|
|
2080
2105
|
let program;
|
|
2081
2106
|
try {
|
|
2082
|
-
program =
|
|
2107
|
+
program = babelParser().parse(src, {
|
|
2083
2108
|
sourceType: 'module',
|
|
2084
2109
|
plugins: ['jsx', 'typescript'],
|
|
2085
2110
|
errorRecovery: true,
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
* the demo-content replacement in template-adapter, and by template-needs
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {createRequire} from 'node:module';
|
|
15
14
|
import * as path from 'node:path';
|
|
16
15
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
16
|
+
import {babelCore, babelParser} from '../runtime/lazy-dependencies.mjs';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Where what parsing returns for each template Astryx ships is stored at
|
|
@@ -28,13 +28,6 @@ export const TEMPLATE_COMPONENTS_FILE = path.join(
|
|
|
28
28
|
'components.generated.json',
|
|
29
29
|
);
|
|
30
30
|
|
|
31
|
-
const require = createRequire(import.meta.url);
|
|
32
|
-
|
|
33
|
-
/** @type {typeof import('@babel/parser') | undefined} */
|
|
34
|
-
let babelParser;
|
|
35
|
-
/** @type {typeof import('@babel/core') | undefined} */
|
|
36
|
-
let babelCore;
|
|
37
|
-
|
|
38
31
|
/**
|
|
39
32
|
* Parse template source as TSX. Babel loads on first use, so a command that
|
|
40
33
|
* only lists templates never pays for it.
|
|
@@ -44,10 +37,7 @@ let babelCore;
|
|
|
44
37
|
* @returns {any} The file node.
|
|
45
38
|
*/
|
|
46
39
|
export function parseTemplateSource(source, {errorRecovery = false} = {}) {
|
|
47
|
-
babelParser
|
|
48
|
-
require('@babel/parser')
|
|
49
|
-
);
|
|
50
|
-
return babelParser.parse(source, {
|
|
40
|
+
return babelParser().parse(source, {
|
|
51
41
|
sourceType: 'module',
|
|
52
42
|
plugins: ['jsx', 'typescript'],
|
|
53
43
|
errorRecovery,
|
|
@@ -79,10 +69,7 @@ export function programPath(file) {
|
|
|
79
69
|
* @param {import('@babel/core').Visitor} visitor
|
|
80
70
|
*/
|
|
81
71
|
export function traverseTemplateSource(file, visitor) {
|
|
82
|
-
babelCore
|
|
83
|
-
require('@babel/core')
|
|
84
|
-
);
|
|
85
|
-
babelCore.traverse(file, visitor);
|
|
72
|
+
babelCore().traverse(file, visitor);
|
|
86
73
|
}
|
|
87
74
|
|
|
88
75
|
/**
|
|
@@ -30,9 +30,13 @@ export function themeImportPackage(theme: DiscoveredTheme): string;
|
|
|
30
30
|
/**
|
|
31
31
|
* Every module a theme source file imports or re-exports, as written.
|
|
32
32
|
* @param {string} file
|
|
33
|
+
* @param {{withRequire?: boolean}} [options] `withRequire`: also
|
|
34
|
+
* `require('./x')` and TypeScript `import x = require('./x')`.
|
|
33
35
|
* @returns {string[]}
|
|
34
36
|
*/
|
|
35
|
-
export function themeFileImports(file: string
|
|
37
|
+
export function themeFileImports(file: string, options?: {
|
|
38
|
+
withRequire?: boolean;
|
|
39
|
+
}): string[];
|
|
36
40
|
/**
|
|
37
41
|
* How messages about a theme descriptor name it.
|
|
38
42
|
* @param {string} docPath
|