@astryxdesign/cli 0.7.15 → 0.7.16-canary.g723a112
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/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +17 -0
- package/api/doctor/_adapter.mjs +35 -0
- package/api/doctor/doctor.mjs +18 -4
- package/api/integration/validate-integration.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/build/build.d.mts +15 -23
- package/api/theme/build/build.mjs +285 -47
- 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 +33 -0
- package/api/theme-edit/_adapter.mjs +208 -31
- package/api/theme-edit/_check.d.mts +38 -0
- package/api/theme-edit/_check.mjs +1326 -211
- 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 +29 -0
- package/api/theme-edit/_context.mjs +329 -30
- package/api/theme-edit/_css.d.mts +60 -1
- package/api/theme-edit/_css.mjs +404 -28
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +1025 -126
- 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 +11 -0
- package/api/theme-edit/_palette.mjs +194 -65
- package/api/theme-edit/_parts.d.mts +16 -0
- package/api/theme-edit/_parts.mjs +59 -7
- package/api/theme-edit/_png.mjs +19 -14
- package/api/theme-edit/_preview-app.d.mts +3 -0
- package/api/theme-edit/_preview-app.mjs +843 -45
- package/api/theme-edit/_preview.d.mts +15 -2
- package/api/theme-edit/_preview.mjs +288 -28
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +35 -9
- package/api/theme-edit/_settings.d.mts +178 -5
- package/api/theme-edit/_settings.mjs +2035 -86
- 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 +2 -1
- package/api/theme-edit/theme-edit.type.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/api/upgrade/registry/registry.mjs +6 -1
- 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/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/theme.mjs +190 -37
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- 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-eject.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 +153 -37
- 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 +40 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +49 -0
- package/foundation/config/project.mjs +50 -14
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +24 -3
- package/foundation/fs/gather-cache.d.mts +9 -2
- package/foundation/fs/gather-cache.mjs +79 -15
- package/foundation/fs/paths.d.mts +31 -0
- package/foundation/fs/paths.mjs +43 -10
- 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/package.json +7 -6
|
@@ -84,6 +84,7 @@ import {
|
|
|
84
84
|
PathSafetyError,
|
|
85
85
|
} from '../../../foundation/fs/path-safety.mjs';
|
|
86
86
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
87
|
+
import {editorThemeRecord} from '../../../foundation/config/theme-state.mjs';
|
|
87
88
|
import {validatePrivateVars} from '../../../foundation/config/theme-private-vars.mjs';
|
|
88
89
|
import {AstryxError} from '../../error.mjs';
|
|
89
90
|
import {applyWrites} from '../../integration/add-helpers.mjs';
|
|
@@ -710,16 +711,21 @@ export function normalizeThemeBuildForCompare(content) {
|
|
|
710
711
|
.join('\n');
|
|
711
712
|
}
|
|
712
713
|
|
|
713
|
-
/**
|
|
714
|
+
/**
|
|
715
|
+
* The outputs that are missing or differ from what the build would write. A
|
|
716
|
+
* missing `.css.d.ts` stylesheet type stub (a write marked `warnWhenMissing`)
|
|
717
|
+
* is not stale: projects that ignore it in version control run the check in
|
|
718
|
+
* CI, so the check warns about it instead (missingDeclarations). Every other
|
|
719
|
+
* missing output, the module's `.d.ts` too, is stale.
|
|
720
|
+
* @param {Array<{dest: string, content: string, warnWhenMissing?: boolean}>} writes @param {string} cwd @returns {Array<{path: string, reason: 'missing' | 'outdated'}>}
|
|
721
|
+
*/
|
|
714
722
|
function staleBuildOutputs(writes, cwd) {
|
|
715
723
|
/** @type {Array<{path: string, reason: 'missing' | 'outdated'}>} */
|
|
716
724
|
const stale = [];
|
|
717
725
|
for (const write of writes) {
|
|
718
726
|
const rel = path.relative(cwd, write.dest);
|
|
719
727
|
if (!fs.existsSync(write.dest)) {
|
|
720
|
-
if (!write.
|
|
721
|
-
stale.push({path: rel, reason: 'missing'});
|
|
722
|
-
}
|
|
728
|
+
if (!write.warnWhenMissing) stale.push({path: rel, reason: 'missing'});
|
|
723
729
|
continue;
|
|
724
730
|
}
|
|
725
731
|
const onDisk = fs.readFileSync(write.dest, 'utf8');
|
|
@@ -733,13 +739,42 @@ function staleBuildOutputs(writes, cwd) {
|
|
|
733
739
|
return stale;
|
|
734
740
|
}
|
|
735
741
|
|
|
736
|
-
/**
|
|
742
|
+
/**
|
|
743
|
+
* Every output the build writes, from the same write list the build and the
|
|
744
|
+
* stale comparison use. A missing output makes the check stale, except the
|
|
745
|
+
* `.css.d.ts` stub, which it warns about (missingDeclarations).
|
|
746
|
+
* @param {Array<{dest: string}>} writes @param {string} cwd
|
|
747
|
+
*/
|
|
737
748
|
function checkedBuildOutputs(writes, cwd) {
|
|
749
|
+
return writes.map(write => path.relative(cwd, write.dest));
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* The `.css.d.ts` stylesheet type stubs the build writes that are missing,
|
|
754
|
+
* which the check names as checked and warns about in text mode without
|
|
755
|
+
* failing.
|
|
756
|
+
* @param {Array<{dest: string, warnWhenMissing?: boolean}>} writes @param {string} cwd
|
|
757
|
+
* @returns {string[]}
|
|
758
|
+
*/
|
|
759
|
+
function missingDeclarations(writes, cwd) {
|
|
738
760
|
return writes
|
|
739
|
-
.filter(write =>
|
|
761
|
+
.filter(write => write.warnWhenMissing && !fs.existsSync(write.dest))
|
|
740
762
|
.map(write => path.relative(cwd, write.dest));
|
|
741
763
|
}
|
|
742
764
|
|
|
765
|
+
/**
|
|
766
|
+
* The one text-mode warning line for missing stylesheet type stubs, or
|
|
767
|
+
* nothing when none is missing. The logger is silent under --json.
|
|
768
|
+
* @param {Array<{dest: string, warnWhenMissing?: boolean}>} writes @param {string} cwd
|
|
769
|
+
*/
|
|
770
|
+
function warnMissingDeclarations(writes, cwd) {
|
|
771
|
+
const missing = missingDeclarations(writes, cwd);
|
|
772
|
+
if (missing.length === 0) return;
|
|
773
|
+
logger.warn(
|
|
774
|
+
` Warning: stylesheet type declaration file${missing.length === 1 ? '' : 's'} not found: ${missing.join(', ')}. The check does not fail on ${missing.length === 1 ? 'it' : 'them'}; a build writes ${missing.length === 1 ? 'it' : 'them'}.`,
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
743
778
|
/** Remedies that end a confinement error, by where the output path came from. */
|
|
744
779
|
const OUT_REMEDY = 'Pass an --out path inside it.';
|
|
745
780
|
const SOURCE_REMEDY =
|
|
@@ -1059,6 +1094,42 @@ function assertThemeSourceFile(filePath, cwd) {
|
|
|
1059
1094
|
}
|
|
1060
1095
|
}
|
|
1061
1096
|
|
|
1097
|
+
/**
|
|
1098
|
+
* Who takes the theme editor warnings (an editor folder, an editor-made
|
|
1099
|
+
* theme) instead of the logger: the watcher's child build hands each to its
|
|
1100
|
+
* parent, which prints it once per session. Set
|
|
1101
|
+
* only by the CLI (not part of the public API), and never by an option of
|
|
1102
|
+
* themeBuild.
|
|
1103
|
+
* @type {((warning: string) => void) | null}
|
|
1104
|
+
*/
|
|
1105
|
+
let editorFolderListener = null;
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* Hand the theme editor warnings of the builds in this process to
|
|
1109
|
+
* `listener` instead of the logger. CLI-internal: the watch child's
|
|
1110
|
+
* hand-off to its parent.
|
|
1111
|
+
* @param {((warning: string) => void) | null} listener
|
|
1112
|
+
*/
|
|
1113
|
+
export function setEditorFolderListener(listener) {
|
|
1114
|
+
editorFolderListener = listener;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* Who is told a build found private var errors (the CLI, to exit 1). Set
|
|
1119
|
+
* only by the CLI, never by an option of themeBuild.
|
|
1120
|
+
* @type {(() => void) | null}
|
|
1121
|
+
*/
|
|
1122
|
+
let privateVarErrorListener = null;
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* Tell `listener` when a build in this process finds private var errors.
|
|
1126
|
+
* CLI-internal.
|
|
1127
|
+
* @param {(() => void) | null} listener
|
|
1128
|
+
*/
|
|
1129
|
+
export function setPrivateVarErrorListener(listener) {
|
|
1130
|
+
privateVarErrorListener = listener;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1062
1133
|
/**
|
|
1063
1134
|
* Refuse a build that would replace a file it does not own. A build never
|
|
1064
1135
|
* writes over its input, two of its own outputs at one path, or an output
|
|
@@ -1069,21 +1140,49 @@ function assertThemeSourceFile(filePath, cwd) {
|
|
|
1069
1140
|
* @param {Array<{dest: string}>} writes
|
|
1070
1141
|
* @param {string} filePath the theme source
|
|
1071
1142
|
* @param {string} cwd
|
|
1072
|
-
* @param {{claimed?: Map<string, string>, rerun?: string, refuseUnmarked?: boolean, elsewhere?: string}} [options]
|
|
1143
|
+
* @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void}} [options]
|
|
1073
1144
|
* `claimed`: outputs written earlier in this run, by the source that wrote
|
|
1074
|
-
* them; `rerun`: this build's command
|
|
1075
|
-
* `elsewhere`: the option that moves the outputs
|
|
1145
|
+
* them; `rerun`: this build's command with another --out, or without one;
|
|
1146
|
+
* `elsewhere`: the option that moves the outputs; `onEditorFolder`: takes
|
|
1147
|
+
* the editor-folder warning instead of the logger (a watcher prints it once)
|
|
1076
1148
|
*/
|
|
1077
1149
|
function assertOutputsReplaceable(
|
|
1078
1150
|
writes,
|
|
1079
1151
|
filePath,
|
|
1080
1152
|
cwd,
|
|
1081
|
-
{
|
|
1153
|
+
{
|
|
1154
|
+
claimed,
|
|
1155
|
+
rerun,
|
|
1156
|
+
refuseUnmarked = false,
|
|
1157
|
+
elsewhere = '--out',
|
|
1158
|
+
onEditorFolder,
|
|
1159
|
+
} = {},
|
|
1082
1160
|
) {
|
|
1083
1161
|
const rel = (/** @type {string} */ file) => path.relative(cwd, file);
|
|
1084
1162
|
const sourceKey = outputKey(filePath);
|
|
1085
1163
|
const seen = new Set();
|
|
1164
|
+
/** @type {string | false} */
|
|
1086
1165
|
let warnedOtherSource = false;
|
|
1166
|
+
// The same build without --out, with its other options.
|
|
1167
|
+
const beside = {
|
|
1168
|
+
name: rerun
|
|
1169
|
+
? rerun(null)
|
|
1170
|
+
: formatCliCommand(`theme build ${shellWord(rel(filePath))}`, cwd),
|
|
1171
|
+
reason: 'write the outputs beside this source',
|
|
1172
|
+
};
|
|
1173
|
+
// A folder the theme editor made holds that theme's outputs only: another
|
|
1174
|
+
// source's outputs there would sit beside its settings as if they were
|
|
1175
|
+
// its own. A source inside the folder builds there as always; one outside
|
|
1176
|
+
// it writes there too, with a warning.
|
|
1177
|
+
let editorFolder = false;
|
|
1178
|
+
if (refuseUnmarked && writes.length) {
|
|
1179
|
+
const dir = path.resolve(path.dirname(writes[0].dest));
|
|
1180
|
+
const record = editorThemeRecord(dir);
|
|
1181
|
+
const fromDir = path.relative(dir, path.resolve(filePath));
|
|
1182
|
+
// On Windows a source on another drive has an absolute relative path.
|
|
1183
|
+
const inside = !fromDir.startsWith('..') && !path.isAbsolute(fromDir);
|
|
1184
|
+
if (record && !inside) editorFolder = true;
|
|
1185
|
+
}
|
|
1087
1186
|
for (const write of writes) {
|
|
1088
1187
|
const key = outputKey(write.dest);
|
|
1089
1188
|
if (key === sourceKey) {
|
|
@@ -1139,23 +1238,14 @@ function assertOutputsReplaceable(
|
|
|
1139
1238
|
: null;
|
|
1140
1239
|
if (otherSource && !OUT_REFUSES_OTHER_SOURCE) {
|
|
1141
1240
|
// One warning per build: every output of that source goes together.
|
|
1241
|
+
// It is printed after every output passes, so it names a replacement
|
|
1242
|
+
// that happens.
|
|
1142
1243
|
if (warnedOtherSource) continue;
|
|
1143
|
-
warnedOtherSource =
|
|
1144
|
-
logger.warn(
|
|
1145
|
-
`Warning: ${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`,
|
|
1146
|
-
);
|
|
1244
|
+
warnedOtherSource = `Warning: ${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`;
|
|
1147
1245
|
} else if (otherSource) {
|
|
1148
1246
|
throw new AstryxError(
|
|
1149
1247
|
`${rel(write.dest)} is the build output of another theme source, ${otherSource}, so this build does not replace it. Pick another ${elsewhere}.`,
|
|
1150
|
-
[
|
|
1151
|
-
{
|
|
1152
|
-
name: formatCliCommand(
|
|
1153
|
-
`theme build ${shellWord(rel(filePath))}`,
|
|
1154
|
-
cwd,
|
|
1155
|
-
),
|
|
1156
|
-
reason: 'write the outputs beside this source',
|
|
1157
|
-
},
|
|
1158
|
-
],
|
|
1248
|
+
[beside],
|
|
1159
1249
|
ERROR_CODES.ERR_FILE_EXISTS,
|
|
1160
1250
|
);
|
|
1161
1251
|
}
|
|
@@ -1166,20 +1256,71 @@ function assertOutputsReplaceable(
|
|
|
1166
1256
|
stat.size > 0 &&
|
|
1167
1257
|
!fileHead(write.dest).includes(GENERATED_MARKER)
|
|
1168
1258
|
) {
|
|
1259
|
+
// Never advice to delete it: it may be the person's file (a settings
|
|
1260
|
+
// file, app source). A path that takes every output instead.
|
|
1261
|
+
const free = freeOutPath(writes);
|
|
1169
1262
|
throw new AstryxError(
|
|
1170
|
-
`${rel(write.dest)}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1263
|
+
`${rel(write.dest)} is a file this build did not write (it has no build header: your own file, another tool's, or an output from a CLI before 0.6.7), so the build does not replace it. Pick another ${elsewhere}.`,
|
|
1264
|
+
[
|
|
1265
|
+
...(free && rerun
|
|
1266
|
+
? [
|
|
1267
|
+
{
|
|
1268
|
+
name: rerun(rel(free)),
|
|
1269
|
+
reason: 'a path where no output of this build exists yet',
|
|
1270
|
+
},
|
|
1271
|
+
]
|
|
1272
|
+
: []),
|
|
1273
|
+
beside,
|
|
1274
|
+
],
|
|
1179
1275
|
ERROR_CODES.ERR_FILE_EXISTS,
|
|
1180
1276
|
);
|
|
1181
1277
|
}
|
|
1182
1278
|
}
|
|
1279
|
+
// Warned only once nothing refuses the build, so it names a write that
|
|
1280
|
+
// happens.
|
|
1281
|
+
if (warnedOtherSource) logger.warn(warnedOtherSource);
|
|
1282
|
+
if (editorFolder) {
|
|
1283
|
+
const dir = path.dirname(writes[0].dest);
|
|
1284
|
+
const warning = `Warning: ${rel(dir) || '.'} is a folder the theme editor made, and ${rel(filePath)} is outside it; the build writes there anyway. Build beside the source, or pick another ${elsewhere}, to keep the editor's folder to its own theme.`;
|
|
1285
|
+
if (onEditorFolder) onEditorFolder(warning);
|
|
1286
|
+
else logger.warn(warning);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* An --out path where no output of this build exists yet, or null. The
|
|
1292
|
+
* stylesheet and its `.css.d.ts` follow the name --out gives; the module and
|
|
1293
|
+
* its types are named after the theme, so a new name beside them (`brand-2.css`)
|
|
1294
|
+
* helps only when those are free, else a new folder (`brand-2/brand.css`).
|
|
1295
|
+
* @param {Array<{dest: string}>} writes the stylesheet first
|
|
1296
|
+
* @returns {string | null}
|
|
1297
|
+
*/
|
|
1298
|
+
function freeOutPath(writes) {
|
|
1299
|
+
const css = writes[0]?.dest;
|
|
1300
|
+
if (!css) return null;
|
|
1301
|
+
const dir = path.dirname(css);
|
|
1302
|
+
const stem = path.basename(css).replace(/\.css$/i, '');
|
|
1303
|
+
/** Whether a write set (each output moved by `move`) touches any file. */
|
|
1304
|
+
const blocked = (/** @type {(dest: string) => string} */ move) =>
|
|
1305
|
+
writes.some(w => fs.existsSync(move(w.dest)));
|
|
1306
|
+
for (let n = 2; n < 100; n += 1) {
|
|
1307
|
+
const next = `${stem}-${n}`;
|
|
1308
|
+
// Only the stylesheet and its types follow --out's name.
|
|
1309
|
+
// The exact names a build with `--out <next>.css` writes, also when
|
|
1310
|
+
// --out did not end in .css (`o.txt` suggests `o.txt-2.css`).
|
|
1311
|
+
const renamed = (/** @type {string} */ dest) =>
|
|
1312
|
+
dest === css
|
|
1313
|
+
? path.join(dir, `${next}.css`)
|
|
1314
|
+
: dest === `${css}.d.ts`
|
|
1315
|
+
? path.join(dir, `${next}.css.d.ts`)
|
|
1316
|
+
: dest;
|
|
1317
|
+
if (!blocked(renamed)) return path.join(dir, `${next}.css`);
|
|
1318
|
+
const folder = (/** @type {string} */ dest) =>
|
|
1319
|
+
path.join(dir, next, path.basename(dest));
|
|
1320
|
+
if (!fs.existsSync(path.join(dir, next)) && !blocked(folder))
|
|
1321
|
+
return path.join(dir, next, path.basename(css));
|
|
1322
|
+
}
|
|
1323
|
+
return null;
|
|
1183
1324
|
}
|
|
1184
1325
|
|
|
1185
1326
|
/**
|
|
@@ -1283,7 +1424,9 @@ function toIdentifier(name) {
|
|
|
1283
1424
|
* @returns {string}
|
|
1284
1425
|
*/
|
|
1285
1426
|
export function importSpecifier(relDir, base) {
|
|
1286
|
-
|
|
1427
|
+
// An import specifier always uses `/`. On Windows the cwd-relative dir comes
|
|
1428
|
+
// from path.relative with `\`, which would print `./\themes\ocean/ocean`.
|
|
1429
|
+
const normalized = relDir === '.' ? '' : relDir.split(path.sep).join('/');
|
|
1287
1430
|
const withinSrc = normalized.replace(/^src\/?/, '').replace(/\/+$/, '');
|
|
1288
1431
|
return withinSrc ? `./${withinSrc}/${base}` : `./${base}`;
|
|
1289
1432
|
}
|
|
@@ -3504,7 +3647,7 @@ function validateHeadingTypeAugmentationSupport(themeDef) {
|
|
|
3504
3647
|
* `logger` (silent by default).
|
|
3505
3648
|
*
|
|
3506
3649
|
* @param {string} file - Theme file path, resolved against `cwd`.
|
|
3507
|
-
* @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any,
|
|
3650
|
+
* @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __writeRoot?: string, __claimedOutputs?: Map<string, string>, __deferredWrites?: Array<Array<{dest: string, content: string}>>, __commandWords?: {group: string, build: string}}} [options] -
|
|
3508
3651
|
* `out` overrides the output CSS path, or names the folder for it; `check` compares against on-disk outputs
|
|
3509
3652
|
* instead of writing. `__claimedOutputs` records the outputs earlier builds
|
|
3510
3653
|
* in one run wrote, so a later theme cannot replace them; with
|
|
@@ -3523,6 +3666,10 @@ async function themeBuildInternal(
|
|
|
3523
3666
|
{cwd = process.cwd(), projectCore = false} = {},
|
|
3524
3667
|
/** @type {{compact?: boolean, trailers?: ThemeBuildTrailer[]}} */ report = {},
|
|
3525
3668
|
) {
|
|
3669
|
+
// A backslash in --out separates folders on every platform, as it does in
|
|
3670
|
+
// the other theme paths (a Windows path copied into a POSIX shell).
|
|
3671
|
+
if (typeof options.out === 'string' && options.out.includes('\\'))
|
|
3672
|
+
options = {...options, out: options.out.replace(/\\/g, '/')};
|
|
3526
3673
|
const filePath = path.resolve(cwd, file);
|
|
3527
3674
|
|
|
3528
3675
|
if (!fs.existsSync(filePath)) {
|
|
@@ -3536,6 +3683,22 @@ async function themeBuildInternal(
|
|
|
3536
3683
|
);
|
|
3537
3684
|
}
|
|
3538
3685
|
|
|
3686
|
+
// A theme the theme editor made is built from its settings by the editor;
|
|
3687
|
+
// a plain build reads its settings module as last written (released CLIs
|
|
3688
|
+
// built it, so it still does, and says so).
|
|
3689
|
+
{
|
|
3690
|
+
const dir = path.dirname(filePath);
|
|
3691
|
+
const slug = path.basename(dir);
|
|
3692
|
+
if (
|
|
3693
|
+
(!options.__commandWords || options.__commandWords.group === 'theme') &&
|
|
3694
|
+
path.basename(filePath) === `${slug}.theme.ts` &&
|
|
3695
|
+
editorThemeRecord(dir)
|
|
3696
|
+
)
|
|
3697
|
+
(editorFolderListener ?? (w => logger.warn(w)))(
|
|
3698
|
+
`Warning: ${path.relative(cwd, filePath)} is a theme the theme editor made (${slug}.settings.json is beside it). This build reads ${slug}.settings.ts as last written; to build it from its settings, run ${formatCliCommand(`experimental theme editor show ${shellWord(slug)}`, cwd)}.`,
|
|
3699
|
+
);
|
|
3700
|
+
}
|
|
3701
|
+
|
|
3539
3702
|
if (fs.statSync(filePath).isDirectory()) {
|
|
3540
3703
|
throw new AstryxError(
|
|
3541
3704
|
`${path.relative(cwd, filePath) || '.'} is a folder. Pass the theme file inside it.`,
|
|
@@ -3614,9 +3777,64 @@ async function themeBuildInternal(
|
|
|
3614
3777
|
} catch (e) {
|
|
3615
3778
|
const err = /** @type {Error} */ (e);
|
|
3616
3779
|
const shown = path.relative(cwd, filePath) || filePath;
|
|
3780
|
+
// A theme file that is a link and does not load: named with the file it
|
|
3781
|
+
// points to (some loaders read its relative imports from the link's
|
|
3782
|
+
// folder, others from the file's own), never with Node's require stack.
|
|
3783
|
+
// Only an unresolved relative import is about the link; any other
|
|
3784
|
+
// failure (a package not installed) keeps its own remedy.
|
|
3785
|
+
let link = null;
|
|
3786
|
+
try {
|
|
3787
|
+
if (
|
|
3788
|
+
fs.lstatSync(filePath).isSymbolicLink() &&
|
|
3789
|
+
/Cannot find (?:module|package) '\.\.?\//.test(err.message)
|
|
3790
|
+
)
|
|
3791
|
+
link = fs.realpathSync(filePath);
|
|
3792
|
+
} catch {
|
|
3793
|
+
link = null;
|
|
3794
|
+
}
|
|
3795
|
+
const message = err.message
|
|
3796
|
+
.replace(/\n+Require stack:(?:\n- [^\n]*)*/, '')
|
|
3797
|
+
.split(filePath)
|
|
3798
|
+
.join(shown);
|
|
3617
3799
|
throw new AstryxError(
|
|
3618
|
-
|
|
3619
|
-
|
|
3800
|
+
link
|
|
3801
|
+
? `${shown} is a link to ${path.relative(cwd, link) || link}, and it could not be loaded (a relative import may be read from the link's folder or from the file's own, depending on the loader); build the file itself: ${message}`
|
|
3802
|
+
: message,
|
|
3803
|
+
link
|
|
3804
|
+
? [
|
|
3805
|
+
{
|
|
3806
|
+
// The file itself, with its outputs kept inside the working
|
|
3807
|
+
// folder (beside the link) when the file is outside it.
|
|
3808
|
+
name: formatCliCommand(
|
|
3809
|
+
[
|
|
3810
|
+
'theme',
|
|
3811
|
+
'build',
|
|
3812
|
+
path.relative(cwd, link) || link,
|
|
3813
|
+
...(path.relative(cwd, link).startsWith('..') ||
|
|
3814
|
+
path.isAbsolute(path.relative(cwd, link))
|
|
3815
|
+
? [
|
|
3816
|
+
'--out',
|
|
3817
|
+
path
|
|
3818
|
+
.relative(
|
|
3819
|
+
cwd,
|
|
3820
|
+
path.join(
|
|
3821
|
+
path.dirname(filePath),
|
|
3822
|
+
`${path.basename(filePath).replace(/\.[^.]+$/, '')}.css`,
|
|
3823
|
+
),
|
|
3824
|
+
)
|
|
3825
|
+
.split(path.sep)
|
|
3826
|
+
.join('/'),
|
|
3827
|
+
]
|
|
3828
|
+
: []),
|
|
3829
|
+
]
|
|
3830
|
+
.map(shellWord)
|
|
3831
|
+
.join(' '),
|
|
3832
|
+
cwd,
|
|
3833
|
+
),
|
|
3834
|
+
reason: 'build the file itself',
|
|
3835
|
+
},
|
|
3836
|
+
]
|
|
3837
|
+
: themeLoadSuggestions(err, shown, cwd),
|
|
3620
3838
|
ERROR_CODES.ERR_THEME_LOAD,
|
|
3621
3839
|
);
|
|
3622
3840
|
}
|
|
@@ -3750,7 +3968,7 @@ async function themeBuildInternal(
|
|
|
3750
3968
|
logger.error(` [error] ${source}${e}`);
|
|
3751
3969
|
}
|
|
3752
3970
|
if (privateVarErrors.length > 0) {
|
|
3753
|
-
|
|
3971
|
+
privateVarErrorListener?.();
|
|
3754
3972
|
logger.error(
|
|
3755
3973
|
`\n ${source}${privateVarErrors.length} private var error(s). Use standard CSS properties instead.`,
|
|
3756
3974
|
);
|
|
@@ -4067,7 +4285,20 @@ async function themeBuildInternal(
|
|
|
4067
4285
|
// Source path relative to cwd — used in @generated headers
|
|
4068
4286
|
const sourceRelative = path.relative(cwd, filePath);
|
|
4069
4287
|
// What `--check` prints to rebuild, from the working folder.
|
|
4070
|
-
|
|
4288
|
+
// The project's own invocation, each path quoted for the shell.
|
|
4289
|
+
const rebuildCommand = formatCliCommand(
|
|
4290
|
+
[
|
|
4291
|
+
'theme',
|
|
4292
|
+
'build',
|
|
4293
|
+
sourceRelative,
|
|
4294
|
+
...(options.out
|
|
4295
|
+
? ['--out', path.relative(cwd, path.resolve(cwd, options.out))]
|
|
4296
|
+
: []),
|
|
4297
|
+
]
|
|
4298
|
+
.map(shellWord)
|
|
4299
|
+
.join(' '),
|
|
4300
|
+
cwd,
|
|
4301
|
+
);
|
|
4071
4302
|
// Stable provenance recorded in @generated headers — versions, not a
|
|
4072
4303
|
// timestamp, so identical inputs produce byte-identical output.
|
|
4073
4304
|
const versions = resolveToolVersions(cwd);
|
|
@@ -4209,7 +4440,7 @@ async function themeBuildInternal(
|
|
|
4209
4440
|
|
|
4210
4441
|
const writes = [
|
|
4211
4442
|
{dest: outPath, content: cssContent},
|
|
4212
|
-
{dest: cssDtsPath, content: cssDtsContent,
|
|
4443
|
+
{dest: cssDtsPath, content: cssDtsContent, warnWhenMissing: true},
|
|
4213
4444
|
{dest: jsPath, content: jsContent},
|
|
4214
4445
|
{dest: dtsPath, content: dtsContent},
|
|
4215
4446
|
];
|
|
@@ -4223,7 +4454,7 @@ async function themeBuildInternal(
|
|
|
4223
4454
|
if (!options.check) {
|
|
4224
4455
|
confineOutputs(writes, writeRoot, options.out ? OUT_REMEDY : SOURCE_REMEDY);
|
|
4225
4456
|
// prettier-ignore
|
|
4226
|
-
const rerun = formatCliCommand(['theme', 'build', path.relative(cwd, filePath), ...(
|
|
4457
|
+
const rerun = (/** @type {string | null} */ out) => formatCliCommand(['theme', 'build', path.relative(cwd, filePath), ...(out == null ? [] : ['--out', out]), ...(options.iconsSpecifier ? ['--icons-specifier', options.iconsSpecifier] : [])].map(shellWord).join(' '), cwd);
|
|
4227
4458
|
// A header-less file at the default paths beside the source is an output
|
|
4228
4459
|
// of a CLI before 0.6.7, which the build has always replaced. A path that
|
|
4229
4460
|
// --out names may hold anything, so there only build outputs are replaced.
|
|
@@ -4231,6 +4462,7 @@ async function themeBuildInternal(
|
|
|
4231
4462
|
claimed: options.__claimedOutputs,
|
|
4232
4463
|
rerun,
|
|
4233
4464
|
refuseUnmarked: Boolean(options.out),
|
|
4465
|
+
onEditorFolder: editorFolderListener ?? undefined,
|
|
4234
4466
|
});
|
|
4235
4467
|
}
|
|
4236
4468
|
|
|
@@ -4263,15 +4495,18 @@ async function themeBuildInternal(
|
|
|
4263
4495
|
`\n Rebuild with: ${rebuildLine(rebuildCommand, options.__commandWords)}`,
|
|
4264
4496
|
);
|
|
4265
4497
|
}
|
|
4266
|
-
|
|
4498
|
+
warnMissingDeclarations(writes, cwd);
|
|
4499
|
+
return /** @type {import('../theme.type.mjs').ThemeBuildCheckResponse} */ ({
|
|
4267
4500
|
type: 'theme.build.check',
|
|
4268
4501
|
data: {
|
|
4269
4502
|
name: themeDef.name,
|
|
4270
4503
|
upToDate,
|
|
4271
4504
|
stale,
|
|
4272
4505
|
checked: checkedBuildOutputs(writes, cwd),
|
|
4506
|
+
// The code a stale check exits 1 with, for --json callers.
|
|
4507
|
+
...(upToDate ? {} : {code: ERROR_CODES.ERR_THEME_STALE}),
|
|
4273
4508
|
},
|
|
4274
|
-
};
|
|
4509
|
+
});
|
|
4275
4510
|
}
|
|
4276
4511
|
|
|
4277
4512
|
// A batch publishes every theme's outputs after all of them are built, so
|
|
@@ -4660,7 +4895,7 @@ async function preloadFamilySource(filePath, loader, interception) {
|
|
|
4660
4895
|
finally { patch.undo(); }
|
|
4661
4896
|
}
|
|
4662
4897
|
|
|
4663
|
-
/** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string,
|
|
4898
|
+
/** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __commandWords?: {group: string, build: string}}} options @param {{cwd?: string}} [ctx] */
|
|
4664
4899
|
export async function themeBuildFamily(
|
|
4665
4900
|
files,
|
|
4666
4901
|
options,
|
|
@@ -4697,7 +4932,7 @@ export async function themeBuildFamily(
|
|
|
4697
4932
|
}
|
|
4698
4933
|
const file = source.file;
|
|
4699
4934
|
// prettier-ignore
|
|
4700
|
-
const member = await themeBuildInternal(file, {iconsSpecifier: options.iconsSpecifier, __prepareFamily: true, __familyLoader: familyLoader, __familyInterception: familyInterception
|
|
4935
|
+
const member = await themeBuildInternal(file, {iconsSpecifier: options.iconsSpecifier, __prepareFamily: true, __familyLoader: familyLoader, __familyInterception: familyInterception}, {cwd});
|
|
4701
4936
|
if (!member || member.type) {
|
|
4702
4937
|
throw new AstryxError(
|
|
4703
4938
|
`Theme family member "${file}" did not produce a complete build plan.`,
|
|
@@ -4871,7 +5106,7 @@ export async function themeBuildFamily(
|
|
|
4871
5106
|
},
|
|
4872
5107
|
{
|
|
4873
5108
|
dest: cssDtsPath,
|
|
4874
|
-
|
|
5109
|
+
warnWhenMissing: true,
|
|
4875
5110
|
content:
|
|
4876
5111
|
generatedHeader(headerSource, 'ts', buildCommand, root.versions) +
|
|
4877
5112
|
'export {};\n',
|
|
@@ -4931,15 +5166,18 @@ export async function themeBuildFamily(
|
|
|
4931
5166
|
`\n Rebuild with: ${rebuildLine(rebuildCommand, options.__commandWords)}`,
|
|
4932
5167
|
);
|
|
4933
5168
|
}
|
|
4934
|
-
|
|
5169
|
+
warnMissingDeclarations(writes, cwd);
|
|
5170
|
+
return /** @type {import('../theme.type.mjs').ThemeBuildCheckResponse} */ ({
|
|
4935
5171
|
type: 'theme.build.check',
|
|
4936
5172
|
data: {
|
|
4937
5173
|
name: root.theme.name,
|
|
4938
5174
|
upToDate,
|
|
4939
5175
|
stale,
|
|
4940
5176
|
checked: checkedBuildOutputs(writes, cwd),
|
|
5177
|
+
// The code a stale check exits 1 with, for --json callers.
|
|
5178
|
+
...(upToDate ? {} : {code: ERROR_CODES.ERR_THEME_STALE}),
|
|
4941
5179
|
},
|
|
4942
|
-
};
|
|
5180
|
+
});
|
|
4943
5181
|
}
|
|
4944
5182
|
writeBuildOutputs(writes);
|
|
4945
5183
|
for (const output of Object.values(outputs)) logger.log(`[ok] ${output}`);
|
|
@@ -7,7 +7,12 @@
|
|
|
7
7
|
|
|
8
8
|
import * as path from 'node:path';
|
|
9
9
|
import {AstryxError} from '../../error.mjs';
|
|
10
|
+
import {logger} from '../../logger.mjs';
|
|
10
11
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
12
|
+
import {
|
|
13
|
+
formatCliCommand,
|
|
14
|
+
quoteCommandArgument,
|
|
15
|
+
} from '../../../foundation/env/package-manager.mjs';
|
|
11
16
|
import {
|
|
12
17
|
ejectThemeFiles,
|
|
13
18
|
findTheme,
|
|
@@ -54,12 +59,28 @@ export async function themeEject(slug, options = {}) {
|
|
|
54
59
|
);
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
const {outputDir, files} = ejectThemeFiles(match, {
|
|
62
|
+
const {outputDir, files, editorFolder} = ejectThemeFiles(match, {
|
|
58
63
|
cwd,
|
|
59
64
|
targetPath,
|
|
60
65
|
overwrite,
|
|
61
66
|
takenSlugs: await availableSlugs(cwd),
|
|
62
67
|
});
|
|
68
|
+
// A folder the theme editor made holds that theme only, but a subfolder of
|
|
69
|
+
// it was always writable, so the fork is written there with one warning.
|
|
70
|
+
if (editorFolder != null) {
|
|
71
|
+
const fork = formatCliCommand(
|
|
72
|
+
[
|
|
73
|
+
'theme eject',
|
|
74
|
+
match.slug,
|
|
75
|
+
...(packageName
|
|
76
|
+
? ['--package', quoteCommandArgument(packageName)]
|
|
77
|
+
: []),
|
|
78
|
+
].join(' '),
|
|
79
|
+
cwd,
|
|
80
|
+
);
|
|
81
|
+
const warning = `Warning: ${editorFolder} is a folder the theme editor made, and the fork in ${outputDir} is inside it; eject writes there anyway. Fork into the project's local themes folder (${fork}), or pick a path outside ${editorFolder}, to keep the editor's folder to its own theme.`;
|
|
82
|
+
logger.warn(warning);
|
|
83
|
+
}
|
|
63
84
|
const {missingPackages, installCommand} = forkNeeds(outputDir, files, cwd);
|
|
64
85
|
return {
|
|
65
86
|
type: 'theme.eject',
|
|
@@ -15,7 +15,26 @@ export function themeTemplate(options?: {
|
|
|
15
15
|
overwrite?: boolean;
|
|
16
16
|
cwd?: string;
|
|
17
17
|
}): import("../theme.type.mjs").ThemeTemplateResponse;
|
|
18
|
+
/**
|
|
19
|
+
* The template write behind `themeTemplate`, with the experimental editor's
|
|
20
|
+
* one difference: with `editorFilesOnly`, in a folder the theme editor made
|
|
21
|
+
* only the editor's own files (`<folder>.*`) are protected, so an earlier
|
|
22
|
+
* template there is the person's. Internal: the experimental `template`
|
|
23
|
+
* command reaches it through `editorThemeTemplate` (api/theme-edit), and it
|
|
24
|
+
* is not part of the public API.
|
|
25
|
+
* @internal
|
|
26
|
+
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} options
|
|
27
|
+
* @param {boolean} editorFilesOnly
|
|
28
|
+
* @returns {import('../theme.type.mjs').ThemeTemplateResponse}
|
|
29
|
+
*/
|
|
30
|
+
export function writeThemeTemplate(options: {
|
|
31
|
+
targetPath?: string;
|
|
32
|
+
overwrite?: boolean;
|
|
33
|
+
cwd?: string;
|
|
34
|
+
}, editorFilesOnly: boolean): import("../theme.type.mjs").ThemeTemplateResponse;
|
|
18
35
|
/** The annotated `defineTheme` reference that ships with the CLI. */
|
|
19
36
|
export const THEME_TEMPLATE_SRC: string;
|
|
37
|
+
/** The warning the CLI prints when it writes the template outside a project. */
|
|
38
|
+
export const OUTSIDE_PROJECT_WARNING: "Warning: no package.json is in this folder or above it, so the template is written here. Run it inside a project, or run `npm init -y` here first, to write it at a project root.";
|
|
20
39
|
/** Where it lands when the caller does not say. */
|
|
21
40
|
export const THEME_TEMPLATE_DEFAULT_PATH: "theme.template.ts";
|