@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
|
@@ -31,6 +31,8 @@ import {
|
|
|
31
31
|
resolveRecordedTheme,
|
|
32
32
|
resolveThemeModule,
|
|
33
33
|
SOURCE_EXTENSIONS,
|
|
34
|
+
missingThemePackage,
|
|
35
|
+
packageInstallCommand,
|
|
34
36
|
themeBuild,
|
|
35
37
|
themeRecordOwner,
|
|
36
38
|
validateThemePrivateInputs,
|
|
@@ -1083,6 +1085,8 @@ export async function checkAppThemes(cwd) {
|
|
|
1083
1085
|
});
|
|
1084
1086
|
} else {
|
|
1085
1087
|
const stale = [];
|
|
1088
|
+
/** @type {Map<string, string[]>} theme slugs by the package they import and the app lacks */
|
|
1089
|
+
const missingPackages = new Map();
|
|
1086
1090
|
const previousSilent = logger.silent;
|
|
1087
1091
|
logger.setSilent(true);
|
|
1088
1092
|
try {
|
|
@@ -1106,38 +1110,69 @@ export async function checkAppThemes(cwd) {
|
|
|
1106
1110
|
) {
|
|
1107
1111
|
stale.push(theme.slug);
|
|
1108
1112
|
}
|
|
1109
|
-
} catch {
|
|
1110
|
-
|
|
1113
|
+
} catch (error) {
|
|
1114
|
+
const missing = missingThemePackage(error);
|
|
1115
|
+
if (missing) {
|
|
1116
|
+
missingPackages.set(missing, [
|
|
1117
|
+
...(missingPackages.get(missing) ?? []),
|
|
1118
|
+
theme.slug,
|
|
1119
|
+
]);
|
|
1120
|
+
} else {
|
|
1121
|
+
stale.push(theme.slug);
|
|
1122
|
+
}
|
|
1111
1123
|
}
|
|
1112
1124
|
}
|
|
1113
1125
|
} finally {
|
|
1114
1126
|
logger.setSilent(previousSilent);
|
|
1115
1127
|
}
|
|
1128
|
+
const packages = [...missingPackages.keys()];
|
|
1129
|
+
const install =
|
|
1130
|
+
packages.length > 0
|
|
1131
|
+
? packageInstallCommand(packages, state.projectDir)
|
|
1132
|
+
: null;
|
|
1133
|
+
const refresh = stale.map(slug =>
|
|
1134
|
+
refreshThemeCommand(
|
|
1135
|
+
state.projectDir,
|
|
1136
|
+
run,
|
|
1137
|
+
available,
|
|
1138
|
+
slug,
|
|
1139
|
+
state.themes[slug],
|
|
1140
|
+
),
|
|
1141
|
+
);
|
|
1116
1142
|
checks.push(
|
|
1117
|
-
|
|
1143
|
+
packages.length > 0
|
|
1118
1144
|
? {
|
|
1119
1145
|
id: 'theme-local-builds',
|
|
1120
1146
|
label: 'Local theme build freshness',
|
|
1121
1147
|
status: 'fail',
|
|
1122
|
-
message: `Local
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1148
|
+
message: `Local themes import packages the app does not have installed, so they cannot build: ${[
|
|
1149
|
+
...missingPackages,
|
|
1150
|
+
]
|
|
1151
|
+
.map(([pkg, slugs]) => `${pkg} (${slugs.join(', ')})`)
|
|
1152
|
+
.join(
|
|
1153
|
+
'; ',
|
|
1154
|
+
)}.${stale.length > 0 ? ` Local theme outputs are also missing or stale: ${stale.join(', ')}.` : ''}`,
|
|
1155
|
+
fix: [
|
|
1156
|
+
install?.installCommand ??
|
|
1157
|
+
install?.noCommandReason ??
|
|
1158
|
+
`Install ${packages.join(', ')}.`,
|
|
1159
|
+
...refresh,
|
|
1160
|
+
].join(' '),
|
|
1134
1161
|
}
|
|
1135
|
-
:
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1162
|
+
: stale.length > 0
|
|
1163
|
+
? {
|
|
1164
|
+
id: 'theme-local-builds',
|
|
1165
|
+
label: 'Local theme build freshness',
|
|
1166
|
+
status: 'fail',
|
|
1167
|
+
message: `Local theme outputs are missing or stale: ${stale.join(', ')}.`,
|
|
1168
|
+
fix: refresh.join(' '),
|
|
1169
|
+
}
|
|
1170
|
+
: {
|
|
1171
|
+
id: 'theme-local-builds',
|
|
1172
|
+
label: 'Local theme build freshness',
|
|
1173
|
+
status: 'pass',
|
|
1174
|
+
message: 'Every added local theme output matches its source.',
|
|
1175
|
+
},
|
|
1141
1176
|
);
|
|
1142
1177
|
}
|
|
1143
1178
|
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* same transaction. Side-effect-free outside of {@link applyWrites}.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import {stillHolds} from '../../foundation/release/folder-lock.mjs';
|
|
15
16
|
import * as fs from 'node:fs';
|
|
16
17
|
import * as path from 'node:path';
|
|
17
18
|
import {randomUUID} from 'node:crypto';
|
|
@@ -376,6 +377,10 @@ export function applyWrites(plans) {
|
|
|
376
377
|
staged.push({...plan, temporary, original, mode});
|
|
377
378
|
}
|
|
378
379
|
|
|
380
|
+
// Under a folder lock (the theme editor's), a run that lost the lock
|
|
381
|
+
// while it was stopped publishes nothing. Outside a lock this does
|
|
382
|
+
// nothing.
|
|
383
|
+
stillHolds();
|
|
379
384
|
for (const plan of staged) {
|
|
380
385
|
if (plan.original == null) {
|
|
381
386
|
publishNewFile(plan.temporary, plan.path);
|
|
@@ -18,7 +18,6 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
|
18
18
|
import {
|
|
19
19
|
assertWithin,
|
|
20
20
|
PathSafetyError,
|
|
21
|
-
sanitizeName,
|
|
22
21
|
} from '../../foundation/fs/path-safety.mjs';
|
|
23
22
|
import {
|
|
24
23
|
discoverBundledThemes,
|
|
@@ -46,47 +45,14 @@ import {
|
|
|
46
45
|
projectPath,
|
|
47
46
|
} from './add-helpers.mjs';
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
import {
|
|
49
|
+
renameDefinedTheme,
|
|
50
|
+
renameThemeFile,
|
|
51
|
+
rewriteThemeSource,
|
|
52
|
+
themeIdentity,
|
|
53
|
+
} from '../theme/_fork.mjs';
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
function themeIdentity(slug) {
|
|
53
|
-
try {
|
|
54
|
-
sanitizeName(slug, {label: 'theme name'});
|
|
55
|
-
} catch (error) {
|
|
56
|
-
if (error instanceof PathSafetyError) {
|
|
57
|
-
throw new AstryxError(
|
|
58
|
-
error.message,
|
|
59
|
-
undefined,
|
|
60
|
-
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
if (!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(slug)) {
|
|
66
|
-
throw new AstryxError(
|
|
67
|
-
`Invalid theme name "${slug}": use lowercase kebab-case starting with a letter.`,
|
|
68
|
-
undefined,
|
|
69
|
-
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
const identifier = slug.replace(/-([a-z0-9])/gu, (_, character) =>
|
|
73
|
-
character.toUpperCase(),
|
|
74
|
-
);
|
|
75
|
-
const displayName = slug
|
|
76
|
-
.split('-')
|
|
77
|
-
.map(part =>
|
|
78
|
-
part === 'y2k' ? 'Y2K' : part[0].toUpperCase() + part.slice(1),
|
|
79
|
-
)
|
|
80
|
-
.join(' ');
|
|
81
|
-
return {
|
|
82
|
-
slug,
|
|
83
|
-
identifier,
|
|
84
|
-
displayName,
|
|
85
|
-
exportName: `${identifier}Theme`,
|
|
86
|
-
entry: `${identifier}Theme.ts`,
|
|
87
|
-
descriptor: `${identifier}Theme.doc.mjs`,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
55
|
+
const DEFAULT_THEMES_ROOT = './themes';
|
|
90
56
|
|
|
91
57
|
/** @param {{slug: string, exportName: string}} identity */
|
|
92
58
|
function themeSource(identity) {
|
|
@@ -129,7 +95,10 @@ function resolveBaseTheme(slug, packageDir, owner, themesRoot) {
|
|
|
129
95
|
// Also check the package's own themes root.
|
|
130
96
|
if (themesRoot && fs.existsSync(themesRoot)) {
|
|
131
97
|
try {
|
|
132
|
-
candidates = [
|
|
98
|
+
candidates = [
|
|
99
|
+
...candidates,
|
|
100
|
+
...discoverThemeDirectory(themesRoot, owner),
|
|
101
|
+
];
|
|
133
102
|
} catch {
|
|
134
103
|
// A broken local root is not the caller's problem here.
|
|
135
104
|
}
|
|
@@ -149,74 +118,6 @@ function resolveBaseTheme(slug, packageDir, owner, themesRoot) {
|
|
|
149
118
|
return match;
|
|
150
119
|
}
|
|
151
120
|
|
|
152
|
-
/**
|
|
153
|
-
* Rename a file from the base theme's namespace to the new theme's namespace.
|
|
154
|
-
* Files whose name starts with the base identifier get the new identifier;
|
|
155
|
-
* others keep their name as-is.
|
|
156
|
-
* @param {string} file POSIX relative path inside the theme directory
|
|
157
|
-
* @param {string} baseIdentifier
|
|
158
|
-
* @param {string} newIdentifier
|
|
159
|
-
* @returns {string}
|
|
160
|
-
*/
|
|
161
|
-
function renameThemeFile(file, baseIdentifier, newIdentifier) {
|
|
162
|
-
const basename = path.posix.basename(file);
|
|
163
|
-
const dir = path.posix.dirname(file);
|
|
164
|
-
if (!basename.startsWith(baseIdentifier)) return file;
|
|
165
|
-
const renamed = newIdentifier + basename.slice(baseIdentifier.length);
|
|
166
|
-
return dir === '.' ? renamed : `${dir}/${renamed}`;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Rewrite a source file's contents from the base theme's names to the new
|
|
171
|
-
* theme's names. This replaces:
|
|
172
|
-
* 1. Identifier prefixes (camelCase variables, import paths): baseIdentifier
|
|
173
|
-
* followed by an uppercase letter.
|
|
174
|
-
* 2. The theme slug in string literals: 'baseSlug' → 'newSlug' and
|
|
175
|
-
* 'astryx-baseSlug' → 'astryx-newSlug'.
|
|
176
|
-
* 3. CSS custom properties scoped to the theme: --astryx-theme-baseSlug-.
|
|
177
|
-
* @param {string} source
|
|
178
|
-
* @param {string} baseSlug
|
|
179
|
-
* @param {string} baseIdentifier
|
|
180
|
-
* @param {string} newSlug
|
|
181
|
-
* @param {string} newIdentifier
|
|
182
|
-
* @returns {string}
|
|
183
|
-
*/
|
|
184
|
-
function rewriteThemeSource(
|
|
185
|
-
source,
|
|
186
|
-
baseSlug,
|
|
187
|
-
baseIdentifier,
|
|
188
|
-
newSlug,
|
|
189
|
-
newIdentifier,
|
|
190
|
-
) {
|
|
191
|
-
let result = source;
|
|
192
|
-
// 1. Identifier prefixes: neutralPalettes → oceanPalettes, neutralTheme → oceanTheme
|
|
193
|
-
const identRe = new RegExp(`${escapeRegExp(baseIdentifier)}(?=[A-Z])`, 'gu');
|
|
194
|
-
result = result.replace(identRe, newIdentifier);
|
|
195
|
-
// 2. String-literal theme names
|
|
196
|
-
result = result.replace(
|
|
197
|
-
new RegExp(`'astryx-${escapeRegExp(baseSlug)}'`, 'gu'),
|
|
198
|
-
`'astryx-${newSlug}'`,
|
|
199
|
-
);
|
|
200
|
-
result = result.replace(
|
|
201
|
-
new RegExp(`'${escapeRegExp(baseSlug)}'`, 'gu'),
|
|
202
|
-
`'${newSlug}'`,
|
|
203
|
-
);
|
|
204
|
-
// 3. CSS custom properties scoped to the base theme
|
|
205
|
-
result = result.replace(
|
|
206
|
-
new RegExp(
|
|
207
|
-
`--astryx-theme-${escapeRegExp(baseSlug)}-`,
|
|
208
|
-
'gu',
|
|
209
|
-
),
|
|
210
|
-
`--astryx-theme-${newSlug}-`,
|
|
211
|
-
);
|
|
212
|
-
return result;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/** @param {string} s */
|
|
216
|
-
function escapeRegExp(s) {
|
|
217
|
-
return s.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
218
|
-
}
|
|
219
|
-
|
|
220
121
|
/** What every app that uses Astryx already has: Core, and React through Core's peers. */
|
|
221
122
|
const APP_PROVIDED = new Set(['@astryxdesign/core', 'react', 'react-dom']);
|
|
222
123
|
|
|
@@ -332,6 +233,10 @@ function forkThemePlans(base, identity, themeDir) {
|
|
|
332
233
|
identity.slug,
|
|
333
234
|
identity.identifier,
|
|
334
235
|
);
|
|
236
|
+
// The entry's defineTheme name, wherever it sits (a double-quoted name,
|
|
237
|
+
// one after `extends`), is the fork's, as the build names its files.
|
|
238
|
+
if (file === base.files[0])
|
|
239
|
+
contents = renameDefinedTheme(contents, identity.slug) ?? contents;
|
|
335
240
|
} else {
|
|
336
241
|
contents = bytes;
|
|
337
242
|
}
|
|
@@ -74,6 +74,7 @@ import {
|
|
|
74
74
|
import {
|
|
75
75
|
blockComponentsCheck,
|
|
76
76
|
componentExamplesCheck,
|
|
77
|
+
packageListingCheck,
|
|
77
78
|
componentDocNamesCheck,
|
|
78
79
|
INVALID_CLI_COMMAND,
|
|
79
80
|
isListedIssue,
|
|
@@ -448,6 +449,7 @@ async function validateAtPackageDir(
|
|
|
448
449
|
? resolveRoot(manifest.experimental?.iconSets, 'experimental.iconSets')
|
|
449
450
|
: undefined,
|
|
450
451
|
issuesUrl: manifest.issuesUrl,
|
|
452
|
+
logo: manifest.logo,
|
|
451
453
|
agentDocs: manifest.agentDocs,
|
|
452
454
|
cliCommand: manifest.cliCommand,
|
|
453
455
|
__cliCommandError: cliCommandError,
|
|
@@ -889,6 +891,11 @@ export async function validateIntegration(pkg, options = {}) {
|
|
|
889
891
|
const examples = integration
|
|
890
892
|
? await componentExamplesCheck(integration)
|
|
891
893
|
: undefined;
|
|
894
|
+
// What a catalog needs to list the package: a logo, and an example of
|
|
895
|
+
// its components.
|
|
896
|
+
const listing = integration
|
|
897
|
+
? packageListingCheck(integration, examples?.examples)
|
|
898
|
+
: undefined;
|
|
892
899
|
const docNames = names?.[0].report;
|
|
893
900
|
const blockComponents = names?.[1].report;
|
|
894
901
|
// Notes fail nothing: a malformed `cliCommand`, and the findings added
|
|
@@ -913,6 +920,9 @@ export async function validateIntegration(pkg, options = {}) {
|
|
|
913
920
|
each.notes.map(note => ({...note, next: true})),
|
|
914
921
|
),
|
|
915
922
|
...(examples?.notes ?? []).map(note => ({...note, next: true})),
|
|
923
|
+
// What a catalog needs to list the package is information only:
|
|
924
|
+
// these notes fail no check, under any flag.
|
|
925
|
+
...(listing?.notes ?? []),
|
|
916
926
|
]
|
|
917
927
|
: [];
|
|
918
928
|
// The doc-syntax findings in the package's topics, as `next` notes with
|
|
@@ -926,6 +936,10 @@ export async function validateIntegration(pkg, options = {}) {
|
|
|
926
936
|
})),
|
|
927
937
|
);
|
|
928
938
|
}
|
|
939
|
+
const assetsUnchecked = [
|
|
940
|
+
...(examples?.unchecked ?? []),
|
|
941
|
+
...(listing?.unchecked ?? []),
|
|
942
|
+
];
|
|
929
943
|
return {
|
|
930
944
|
type: 'integration.validate',
|
|
931
945
|
data: {
|
|
@@ -955,13 +969,13 @@ export async function validateIntegration(pkg, options = {}) {
|
|
|
955
969
|
...(result.found && result.olderCliNotes
|
|
956
970
|
? {olderCliNotes: result.olderCliNotes}
|
|
957
971
|
: {}),
|
|
958
|
-
// Template assets npm could not place, when there are any.
|
|
959
|
-
...(
|
|
972
|
+
// Template assets and logos npm could not place, when there are any.
|
|
973
|
+
...(assetsUnchecked.length > 0
|
|
960
974
|
? {
|
|
961
975
|
exampleAssets: {
|
|
962
976
|
status: 'checked',
|
|
963
977
|
findings: [],
|
|
964
|
-
unchecked:
|
|
978
|
+
unchecked: assetsUnchecked,
|
|
965
979
|
},
|
|
966
980
|
}
|
|
967
981
|
: {}),
|
|
@@ -62,7 +62,7 @@ export const doc = {
|
|
|
62
62
|
{
|
|
63
63
|
type: 'integration.validate',
|
|
64
64
|
description:
|
|
65
|
-
"The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means \"not looked at\", not \"healthy\"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message, next?} information beside the issues; a note fails nothing by default, and one with `next: true` counts as a warning under `integration check --next`, fails `integration check --strict --next`, and fails `--strict` from the next minor release. Notes include `invalid_cli_command` for a `cliCommand` that was ignored as malformed and `cli_peer_version` when the running CLI is outside the `@astryxdesign/cli` peer range of the package, and the package layout findings added after the last minor release, each with its fix in the message: `duplicate_component_doc`, `symlinked_root`, `unreadable_file`, `invalid_package_json` (no `name` or `version`), `no_provider_id`, and `source_without_component_doc` for a doc whose file name differs from its source only in letter case where the two still pair; and `doc_name_mismatch` and `unknown_block_component` (see `docNames` and `blockComponents`); they become warnings in the next minor release. For the commands a topic writes, `runner_command` (written with a package runner), `plain_command` (written bare), `package_manager_command` (written for one package manager) and `doc_token` (a token that does not parse) notes each give the file, line and the token to write. A `doc_target_not_found` note names a doc whose `replaces` or `extends` names no topic and no guide of the CLI's docs or the package's own (such as a namespace, with the guides below it), so it changes nothing unless an app also installs a package that provides it, and a `doc_section_unplaced` note a section whose `before` or `after` names no section of the topic or guide it extends, so it is added at the end, and a `duplicate_guide_replacement` note two docs of the package that replace one guide, of which only the last is read; they become warnings in the next minor release. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked. When the manifest loads, `data.docNames` lists the component doc names it could not judge: `status` (`checked`), `findings` (always empty; a doc name the module its import names provably does not export is a `doc_name_mismatch` note, with its fix in the message) and `unchecked` ({file, name, reason}: a doc whose `name` differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, `data.blockComponents` lists the component names templates give in `exampleFor` or `componentsUsed` that could not be judged: `status` (`checked`), `findings` (always empty; a name neither the package nor Core has, and the template does not import, is an `unknown_block_component` note, with its fix in the message) and `unchecked` ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed). Since 0.7.3 each import apps cannot use is a note in `data.notes`, its fix inside the message, listed only: it does not fail this command or `integration check --strict`, and fails `--strict` from the next minor release. The codes are `component_import_not_exported`, `component_import_other_package`, `component_import_missing_name`, `example_import_not_exported`, `example_import_missing_name`, `template_import_not_exported`, `template_import_outside_root`, `template_private_import`, `template_import_missing_name` and `template_no_default_export`. Since 0.7.4 the examples a package ships are checked the same way: `component_without_example` (a published component no block template shows with `exampleFor` and `isShowcase: true`, or names in `alsoShowcaseFor`), `template_category` (a template category written as a path, such as `components/X`), `showcase_not_standalone` (a showcase that imports server-only code or reads `process.env` past `NODE_ENV`) and `template_asset_not_packed` (a `new URL(…, import.meta.url)` asset that is missing, or that `npm pack --dry-run` leaves out of the package). When npm cannot list the package's files, an asset no `files` entry can reach is still a note, and any other is listed in `data.exampleAssets` (`{status: 'checked', findings: [], unchecked}`, present only when it lists any) as {file, asset, reason}; `integration check` counts them as not compared. When the manifest loads, `data.publicImports` is `{status: 'checked', findings: [], unchecked}`: `unchecked` lists each import the check could not judge, as {file, specifier, reason}, the reason starting `example <label>:` for an import in a component example: an `exports` target not built yet; a module whose export list cannot be read in full (CommonJS, or a declaration file it cannot read); a root import in a package with no `exports` (the root module `main` names is not read); every name an import (other than a component doc's own component) names that its module does not export, while a TypeScript file in the package has a `declare module` block for a relative path or the package's own name or a subpath of it, which can add names to that module (a `declare module` in a comment, `declare global`, a wildcard such as `'*.css'`, and another package's name do not count; a file whose text has `declare module` but that cannot be parsed counts); the same for every such name when the package has more than 5,000 files to search for that block; a deep path into build output not built yet in a package with no `exports`; a template import of Core when `@astryxdesign/core` is not installed beside the package (a `packages/core` of the workspace under another name does not count); every import of the package's own name when package.json has no `name` or a `name` that is not a bare package name; one entry for the whole check when package.json cannot be read; and an import of a subpath whose `exports` entry has only a `types` target, unless it is `import type`, every binding is an inline `type`, or every name it imports is a type its types file declares: a value import of a name that file does not declare as a type, a namespace or side-effect import, or any import when the types file cannot be read (it may be build output). `integration check` counts the unchecked as not compared; they never fail it. `data.olderCliNotes` ({file, kind: `template` | `namespace`, field, message}), for the local package, lists each descriptor field a release before 0.7.4 refuses while the package's CLI peer range admits one, such as `stability` on a template or namespace doc; it is present only when it has entries, is never counted, and never fails a check.",
|
|
65
|
+
"The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means \"not looked at\", not \"healthy\"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message, next?} information beside the issues; a note fails nothing by default, and one with `next: true` counts as a warning under `integration check --next`, fails `integration check --strict --next`, and fails `--strict` from the next minor release. Notes include `invalid_cli_command` for a `cliCommand` that was ignored as malformed and `cli_peer_version` when the running CLI is outside the `@astryxdesign/cli` peer range of the package, and the package layout findings added after the last minor release, each with its fix in the message: `duplicate_component_doc`, `symlinked_root`, `unreadable_file`, `invalid_package_json` (no `name` or `version`), `no_provider_id`, and `source_without_component_doc` for a doc whose file name differs from its source only in letter case where the two still pair; and `doc_name_mismatch` and `unknown_block_component` (see `docNames` and `blockComponents`); they become warnings in the next minor release. For the commands a topic writes, `runner_command` (written with a package runner), `plain_command` (written bare), `package_manager_command` (written for one package manager) and `doc_token` (a token that does not parse) notes each give the file, line and the token to write. A `doc_target_not_found` note names a doc whose `replaces` or `extends` names no topic and no guide of the CLI's docs or the package's own (such as a namespace, with the guides below it), so it changes nothing unless an app also installs a package that provides it, and a `doc_section_unplaced` note a section whose `before` or `after` names no section of the topic or guide it extends, so it is added at the end, and a `duplicate_guide_replacement` note two docs of the package that replace one guide, of which only the last is read; they become warnings in the next minor release. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked. When the manifest loads, `data.docNames` lists the component doc names it could not judge: `status` (`checked`), `findings` (always empty; a doc name the module its import names provably does not export is a `doc_name_mismatch` note, with its fix in the message) and `unchecked` ({file, name, reason}: a doc whose `name` differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, `data.blockComponents` lists the component names templates give in `exampleFor` or `componentsUsed` that could not be judged: `status` (`checked`), `findings` (always empty; a name neither the package nor Core has, and the template does not import, is an `unknown_block_component` note, with its fix in the message) and `unchecked` ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed). Since 0.7.3 each import apps cannot use is a note in `data.notes`, its fix inside the message, listed only: it does not fail this command or `integration check --strict`, and fails `--strict` from the next minor release. The codes are `component_import_not_exported`, `component_import_other_package`, `component_import_missing_name`, `example_import_not_exported`, `example_import_missing_name`, `template_import_not_exported`, `template_import_outside_root`, `template_private_import`, `template_import_missing_name` and `template_no_default_export`. Since 0.7.4 the examples a package ships are checked the same way: `component_without_example` (a published component no block template shows with `exampleFor` and `isShowcase: true`, or names in `alsoShowcaseFor`), `template_category` (a template category written as a path, such as `components/X`), `showcase_not_standalone` (a showcase that imports server-only code or reads `process.env` past `NODE_ENV`) and `template_asset_not_packed` (a `new URL(…, import.meta.url)` asset that is missing, or that `npm pack --dry-run` leaves out of the package). When npm cannot list the package's files, an asset no `files` entry can reach is still a note, and any other is listed in `data.exampleAssets` (`{status: 'checked', findings: [], unchecked}`, present only when it lists any) as {file, asset, reason}; `integration check` counts them as not compared. Since 0.7.15 two notes, without `next`, say what a catalog needs to list the package, each with its fix in the message; they fail no check under any flag: `package_without_logo` (the integration file's `logo.light`, or a `logo.dark` that is set, names no file in the package that is a PNG, JPEG, WebP or shapes-only SVG of at most 512 KB and that npm packs; when the integration file has no `logo`, package.json `marketplace.logo` is read the same way) and `package_without_example` (the package contributes components, other than the ones `component_without_example` exempts, but no block template sets `isShowcase: true` with `exampleFor`, or `alsoShowcaseFor`; a package of themes, docs or codemods alone needs none). A logo npm cannot be asked about is listed in `data.exampleAssets` with `file` set to the file that names it. When the manifest loads, `data.publicImports` is `{status: 'checked', findings: [], unchecked}`: `unchecked` lists each import the check could not judge, as {file, specifier, reason}, the reason starting `example <label>:` for an import in a component example: an `exports` target not built yet; a module whose export list cannot be read in full (CommonJS, or a declaration file it cannot read); a root import in a package with no `exports` (the root module `main` names is not read); every name an import (other than a component doc's own component) names that its module does not export, while a TypeScript file in the package has a `declare module` block for a relative path or the package's own name or a subpath of it, which can add names to that module (a `declare module` in a comment, `declare global`, a wildcard such as `'*.css'`, and another package's name do not count; a file whose text has `declare module` but that cannot be parsed counts); the same for every such name when the package has more than 5,000 files to search for that block; a deep path into build output not built yet in a package with no `exports`; a template import of Core when `@astryxdesign/core` is not installed beside the package (a `packages/core` of the workspace under another name does not count); every import of the package's own name when package.json has no `name` or a `name` that is not a bare package name; one entry for the whole check when package.json cannot be read; and an import of a subpath whose `exports` entry has only a `types` target, unless it is `import type`, every binding is an inline `type`, or every name it imports is a type its types file declares: a value import of a name that file does not declare as a type, a namespace or side-effect import, or any import when the types file cannot be read (it may be build output). `integration check` counts the unchecked as not compared; they never fail it. `data.olderCliNotes` ({file, kind: `template` | `namespace`, field, message}), for the local package, lists each descriptor field a release before 0.7.4 refuses while the package's CLI peer range admits one, such as `stability` on a template or namespace doc; it is present only when it has entries, is never counted, and never fails a check.",
|
|
66
66
|
},
|
|
67
67
|
],
|
|
68
68
|
examples: [
|
package/api/search/_adapter.mjs
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
* domain, _gather-*.mjs) and loads the tree's static data before it runs.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {readFileSync} from 'node:fs';
|
|
9
|
+
import {readFileSync, realpathSync} from 'node:fs';
|
|
10
10
|
import * as path from 'node:path';
|
|
11
11
|
import {requireCoreDir} from '../../foundation/fs/paths.mjs';
|
|
12
12
|
import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
|
|
13
|
+
import {persistedGather} from '../../foundation/fs/gather-cache.mjs';
|
|
13
14
|
import {
|
|
14
15
|
reusedWhileUnchanged,
|
|
15
16
|
unchangedSince,
|
|
@@ -21,7 +22,12 @@ import {CORELESS_DOMAINS} from './_query.mjs';
|
|
|
21
22
|
import {gatherComponents} from './_gather-components.mjs';
|
|
22
23
|
import {gatherHooks} from './_gather-hooks.mjs';
|
|
23
24
|
import {gatherDocs} from './_gather-docs.mjs';
|
|
24
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
derivedFromSource,
|
|
27
|
+
gatherTemplates,
|
|
28
|
+
gatherThemes,
|
|
29
|
+
} from './_gather-templates.mjs';
|
|
30
|
+
import {componentsInSource} from '../../foundation/discovery/template-adapter.mjs';
|
|
25
31
|
|
|
26
32
|
export {componentKeywords} from './_gather-components.mjs';
|
|
27
33
|
|
|
@@ -124,6 +130,112 @@ async function gatherDomains(options) {
|
|
|
124
130
|
};
|
|
125
131
|
}
|
|
126
132
|
|
|
133
|
+
/**
|
|
134
|
+
* The folder's real path, so a link and its target share a kept gather.
|
|
135
|
+
* @param {string} dir
|
|
136
|
+
* @returns {string}
|
|
137
|
+
*/
|
|
138
|
+
function realFolder(dir) {
|
|
139
|
+
try {
|
|
140
|
+
return realpathSync(dir);
|
|
141
|
+
} catch {
|
|
142
|
+
return dir;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A gathered catalog as plain JSON and back, for a gather kept between runs
|
|
148
|
+
* (persistedGather). A template's derived component names are read once and
|
|
149
|
+
* stored as their value; `components` is stored by position in `all`, whose
|
|
150
|
+
* objects it shares.
|
|
151
|
+
*/
|
|
152
|
+
const GATHER_CODEC = {
|
|
153
|
+
/**
|
|
154
|
+
* @param {any} gathered
|
|
155
|
+
* @returns {any}
|
|
156
|
+
*/
|
|
157
|
+
encode(gathered) {
|
|
158
|
+
const position = new Map(
|
|
159
|
+
gathered.all.map((/** @type {any} */ c, /** @type {number} */ i) => [
|
|
160
|
+
c,
|
|
161
|
+
i,
|
|
162
|
+
]),
|
|
163
|
+
);
|
|
164
|
+
return {
|
|
165
|
+
...gathered,
|
|
166
|
+
all: gathered.all.map((/** @type {any} */ c) => {
|
|
167
|
+
if (!Object.getOwnPropertyDescriptor(c, 'weakKeywords')?.get) return c;
|
|
168
|
+
// The names come from the source file, read again when first asked
|
|
169
|
+
// for (its content is one of the stored inputs); a source that could
|
|
170
|
+
// not be read derives none.
|
|
171
|
+
const from = derivedFromSource.get(c);
|
|
172
|
+
const names = from?.derivedSoFar();
|
|
173
|
+
/** @type {Record<string, unknown>} */
|
|
174
|
+
const out = {};
|
|
175
|
+
for (const k of Object.keys(c)) {
|
|
176
|
+
out[k] =
|
|
177
|
+
k === 'weakKeywords'
|
|
178
|
+
? {[DERIVED]: names ?? from?.file ?? null}
|
|
179
|
+
: c[k];
|
|
180
|
+
}
|
|
181
|
+
return out;
|
|
182
|
+
}),
|
|
183
|
+
components: gathered.components.map((/** @type {any} */ c) =>
|
|
184
|
+
position.get(c),
|
|
185
|
+
),
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
/**
|
|
189
|
+
* @param {any} stored
|
|
190
|
+
* @returns {any}
|
|
191
|
+
*/
|
|
192
|
+
decode(stored) {
|
|
193
|
+
const all = stored.all.map((/** @type {any} */ c) => {
|
|
194
|
+
const stored = c.weakKeywords?.[DERIVED];
|
|
195
|
+
if (stored === undefined) return c;
|
|
196
|
+
// Names read by the run that stored them, or the file to read them from.
|
|
197
|
+
const file = typeof stored === 'string' ? stored : null;
|
|
198
|
+
/** @type {string[] | undefined} */
|
|
199
|
+
let derived = Array.isArray(stored) ? stored : undefined;
|
|
200
|
+
const derive = () => {
|
|
201
|
+
if (derived === undefined) {
|
|
202
|
+
try {
|
|
203
|
+
derived =
|
|
204
|
+
file == null
|
|
205
|
+
? []
|
|
206
|
+
: componentsInSource(readFileSync(file, 'utf-8'));
|
|
207
|
+
} catch {
|
|
208
|
+
derived = [];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return derived;
|
|
212
|
+
};
|
|
213
|
+
/** @type {Record<string, unknown>} */
|
|
214
|
+
const out = {};
|
|
215
|
+
for (const k of Object.keys(c)) {
|
|
216
|
+
if (k === 'weakKeywords') {
|
|
217
|
+
Object.defineProperty(out, k, {
|
|
218
|
+
get: derive,
|
|
219
|
+
enumerable: true,
|
|
220
|
+
configurable: true,
|
|
221
|
+
});
|
|
222
|
+
} else {
|
|
223
|
+
out[k] = c[k];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return out;
|
|
227
|
+
});
|
|
228
|
+
return {
|
|
229
|
+
...stored,
|
|
230
|
+
all,
|
|
231
|
+
components: stored.components.map((/** @type {number} */ i) => all[i]),
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/** The key a stored template's derived component names sit under. */
|
|
237
|
+
const DERIVED = '\0derived';
|
|
238
|
+
|
|
127
239
|
/**
|
|
128
240
|
* @typedef {Awaited<ReturnType<typeof gatherCandidates>>} Gathered
|
|
129
241
|
* @type {Map<string, (options?: {fresh?: boolean}) => Promise<Gathered>>}
|
|
@@ -150,7 +262,16 @@ export function gatherCandidatesReused(options) {
|
|
|
150
262
|
let gather = gathered.get(key);
|
|
151
263
|
if (!gather) {
|
|
152
264
|
gather = reusedWhileUnchanged(
|
|
153
|
-
() =>
|
|
265
|
+
() =>
|
|
266
|
+
persistedGather(
|
|
267
|
+
[realFolder(cwd), type ?? null],
|
|
268
|
+
() => gatherCandidates({cwd, type}),
|
|
269
|
+
GATHER_CODEC,
|
|
270
|
+
// A gather that skipped Core (a failed install still in its
|
|
271
|
+
// backoff, spec:AST-081 FR2) is not kept: once the backoff ends,
|
|
272
|
+
// the next run must try again.
|
|
273
|
+
value => value.coreSkipped == null,
|
|
274
|
+
),
|
|
154
275
|
unchangedSince,
|
|
155
276
|
);
|
|
156
277
|
gathered.set(key, gather);
|
|
@@ -94,6 +94,65 @@ function headOfLetters(t, name) {
|
|
|
94
94
|
/** How many of a family's members a query naming the family lists. */
|
|
95
95
|
const FAMILY_MEMBERS = 3;
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* The pattern that finds any form of a term as a whole word in prose, with
|
|
99
|
+
* any common suffix, built once per term: a search tests it against every
|
|
100
|
+
* candidate's description.
|
|
101
|
+
* @type {Map<string, RegExp>}
|
|
102
|
+
*/
|
|
103
|
+
const mentionPatterns = new Map();
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* How many terms' patterns are kept before the cache starts over. A compiled
|
|
107
|
+
* pattern is several kilobytes and a long-running caller sees ever new
|
|
108
|
+
* terms, so this cache stays small; one search uses a handful of terms.
|
|
109
|
+
*/
|
|
110
|
+
const MENTION_LIMIT = 1_000;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {string} term
|
|
114
|
+
* @param {ReturnType<typeof termWords>} t - the term's words
|
|
115
|
+
* @returns {RegExp}
|
|
116
|
+
*/
|
|
117
|
+
function mentionPattern(term, t) {
|
|
118
|
+
let re = mentionPatterns.get(term);
|
|
119
|
+
if (!re) {
|
|
120
|
+
if (mentionPatterns.size >= MENTION_LIMIT) mentionPatterns.clear();
|
|
121
|
+
// Any form of the term, with any common suffix: `spacing` finds
|
|
122
|
+
// "space" and "spaces", `tables` finds "table".
|
|
123
|
+
const roots = [...new Set([stem(term), ...t.forms])]
|
|
124
|
+
.filter(f => f.length >= 3)
|
|
125
|
+
.map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
126
|
+
re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
|
|
127
|
+
mentionPatterns.set(term, re);
|
|
128
|
+
}
|
|
129
|
+
return re;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Each prose text lowercased once per process: a search reads every
|
|
134
|
+
* candidate's description for every term.
|
|
135
|
+
* @type {Map<string, string>}
|
|
136
|
+
*/
|
|
137
|
+
const lowered = new Map();
|
|
138
|
+
|
|
139
|
+
/** How many texts are kept lowercased before the cache starts over. */
|
|
140
|
+
const CACHE_LIMIT = 100_000;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {string} text
|
|
144
|
+
* @returns {string}
|
|
145
|
+
*/
|
|
146
|
+
function lower(text) {
|
|
147
|
+
let out = lowered.get(text);
|
|
148
|
+
if (out === undefined) {
|
|
149
|
+
if (lowered.size >= CACHE_LIMIT) lowered.clear();
|
|
150
|
+
out = text.toLowerCase();
|
|
151
|
+
lowered.set(text, out);
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
97
156
|
/**
|
|
98
157
|
* A derived name's score for a term: 60 for the same word, 40 for a word the
|
|
99
158
|
* term starts, else 0.
|
|
@@ -308,18 +367,13 @@ export function scoreCandidate(
|
|
|
308
367
|
// Match the term's stem as a whole word, tolerating plural/gerund suffixes
|
|
309
368
|
// so "chart" matches "charts" and "filter" matches "filtering".
|
|
310
369
|
if (term.length >= 3) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const roots = [...new Set([stem(term), ...t.forms])]
|
|
314
|
-
.filter(f => f.length >= 3)
|
|
315
|
-
.map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
316
|
-
const re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
|
|
317
|
-
if (description && re.test(description.toLowerCase())) {
|
|
370
|
+
const re = mentionPattern(term, t);
|
|
371
|
+
if (description && re.test(lower(description))) {
|
|
318
372
|
consider(50, `description mentions "${term}"`);
|
|
319
373
|
} else {
|
|
320
374
|
let matchedProse = false;
|
|
321
375
|
for (const blob of prose) {
|
|
322
|
-
if (blob && re.test(String(blob)
|
|
376
|
+
if (blob && re.test(lower(String(blob)))) {
|
|
323
377
|
consider(50, `docs mention "${term}"`);
|
|
324
378
|
matchedProse = true;
|
|
325
379
|
break;
|
|
@@ -330,7 +384,7 @@ export function scoreCandidate(
|
|
|
330
384
|
// summary. Only consulted when nothing stronger matched.
|
|
331
385
|
if (!matchedProse) {
|
|
332
386
|
for (const blob of guidance) {
|
|
333
|
-
if (blob && re.test(String(blob)
|
|
387
|
+
if (blob && re.test(lower(String(blob)))) {
|
|
334
388
|
consider(45, `guidance mentions "${term}"`);
|
|
335
389
|
break;
|
|
336
390
|
}
|
|
@@ -13,6 +13,16 @@ export function entryTable(all: any[], cards: Record<string, {
|
|
|
13
13
|
synonyms?: string[];
|
|
14
14
|
props?: string[];
|
|
15
15
|
}>): EntryTable;
|
|
16
|
+
/**
|
|
17
|
+
* A table's plain-JSON form and back. Candidates are kept as their place in
|
|
18
|
+
* `all`, maps as their entries in order, so the table reads back the same.
|
|
19
|
+
* @param {any[]} all
|
|
20
|
+
* @returns {{encode: (table: EntryTable) => any, decode: (stored: any) => EntryTable}}
|
|
21
|
+
*/
|
|
22
|
+
export function tableCodec(all: any[]): {
|
|
23
|
+
encode: (table: EntryTable) => any;
|
|
24
|
+
decode: (stored: any) => EntryTable;
|
|
25
|
+
};
|
|
16
26
|
/**
|
|
17
27
|
* @param {any[]} all
|
|
18
28
|
* @param {Record<string, {what?: string, synonyms?: string[], props?: string[]}>} cards
|