@astryxdesign/cli 0.7.17-canary.gbec2043 → 0.7.17-canary.geeb3d7c
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/api/render/_adapter.mjs +6 -10
- package/api/theme/build/build.d.mts +13 -0
- package/api/theme/build/build.mjs +60 -28
- package/api/theme/build/font-warning.d.mts +8 -0
- package/api/theme/build/font-warning.mjs +19 -0
- package/api/theme-edit/_adapter.d.mts +7 -0
- package/api/theme-edit/_adapter.mjs +95 -97
- package/api/theme-edit/_check.mjs +414 -97
- package/api/theme-edit/_color.d.mts +1 -0
- package/api/theme-edit/_color.mjs +8 -0
- package/api/theme-edit/_edit.mjs +533 -200
- package/api/theme-edit/_how-commands.mjs +62 -11
- package/api/theme-edit/_how-question.d.mts +15 -2
- package/api/theme-edit/_how-question.mjs +390 -85
- package/api/theme-edit/_how.mjs +31 -5
- package/api/theme-edit/_normal.d.mts +74 -8
- package/api/theme-edit/_normal.mjs +425 -45
- package/api/theme-edit/_playwright-picture.d.mts +4 -0
- package/api/theme-edit/_playwright-picture.mjs +34 -0
- package/api/theme-edit/_preview-app.mjs +191 -60
- package/api/theme-edit/_preview.d.mts +6 -1
- package/api/theme-edit/_preview.mjs +113 -49
- package/api/theme-edit/_settings.d.mts +72 -6
- package/api/theme-edit/_settings.mjs +491 -32
- package/api/theme-edit/_tables.mjs +12 -0
- package/api/theme-edit/_vet.d.mts +18 -0
- package/api/theme-edit/_vet.mjs +32 -0
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
- package/assets/component-list.generated.json +1 -1
- package/assets/docs/tree/render-pages.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
- package/assets/templates/components.generated.json +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/theme.mjs +80 -2
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/theme.mjs +30 -1
- package/clients/cli/lib/json-shim.mjs +77 -21
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/fonts/font-stylesheet.d.mts +31 -0
- package/foundation/fonts/font-stylesheet.mjs +115 -0
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/render/embedded-files.mjs +17 -4
- package/foundation/render/embedded-imports.mjs +3 -2
- package/foundation/render/file-header.d.mts +2 -2
- package/foundation/render/file-header.mjs +1 -1
- package/foundation/render/render-page.mjs +15 -12
- package/foundation/render/source-block.d.mts +2 -2
- package/foundation/render/source-block.mjs +29 -9
- package/package.json +6 -6
package/api/render/_adapter.mjs
CHANGED
|
@@ -45,7 +45,7 @@ import {isAstryxMarkup} from '../../foundation/render/html-reader.mjs';
|
|
|
45
45
|
import {rebuildPage} from '../../foundation/render/rebuild.mjs';
|
|
46
46
|
import {cliVersion} from '../../foundation/integrations/cli-peer-version.mjs';
|
|
47
47
|
import {assertWithin, PathSafetyError} from '../../foundation/fs/path-safety.mjs';
|
|
48
|
-
import {findPackageRoot, requireCoreDir} from '../../foundation/fs/paths.mjs';
|
|
48
|
+
import {climbsOut, findPackageRoot, isInside as liesInside, requireCoreDir} from '../../foundation/fs/paths.mjs';
|
|
49
49
|
import {runChoice} from '../../foundation/release/run-context.mjs';
|
|
50
50
|
import {isAlive, pidSpace} from '../../foundation/release/cache.mjs';
|
|
51
51
|
import {isServedPackage} from '../../foundation/render/served-packages.mjs';
|
|
@@ -56,7 +56,7 @@ export {PAGE_EXTENSIONS, embeddedPathProblem};
|
|
|
56
56
|
/** @param {string} cwd @param {string} file */
|
|
57
57
|
const shown = (cwd, file) => {
|
|
58
58
|
const rel = path.relative(cwd, file);
|
|
59
|
-
return rel && !rel
|
|
59
|
+
return rel && !climbsOut(rel) && !path.isAbsolute(rel)
|
|
60
60
|
? rel.split(path.sep).join('/')
|
|
61
61
|
: file;
|
|
62
62
|
};
|
|
@@ -158,11 +158,7 @@ function confined(file, cwd, what) {
|
|
|
158
158
|
* @param {string} file absolute
|
|
159
159
|
* @param {string | null} folder absolute
|
|
160
160
|
*/
|
|
161
|
-
const isInside = (file, folder) => {
|
|
162
|
-
if (!folder) return false;
|
|
163
|
-
const rel = path.relative(folder, file);
|
|
164
|
-
return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
165
|
-
};
|
|
161
|
+
const isInside = (file, folder) => Boolean(folder) && liesInside(file, /** @type {string} */ (folder));
|
|
166
162
|
|
|
167
163
|
/**
|
|
168
164
|
* Refuse, before anything is written, a write that reaches through a
|
|
@@ -574,7 +570,7 @@ function aliasEntry(spec, file, base) {
|
|
|
574
570
|
/** @param {string} p */
|
|
575
571
|
const fromBase = p => {
|
|
576
572
|
const rel = path.relative(base, p).split(path.sep).join('/');
|
|
577
|
-
return rel
|
|
573
|
+
return climbsOut(rel) ? rel : `./${rel}`;
|
|
578
574
|
};
|
|
579
575
|
const named = spec.split('/');
|
|
580
576
|
let held = path.relative(base, file).split(path.sep).join('/').replace(/\.[^./]+$/, '').split('/');
|
|
@@ -601,7 +597,7 @@ function aliasedResult(unaliased, page, cwd) {
|
|
|
601
597
|
/** @param {string} p */
|
|
602
598
|
const fromBase = p => {
|
|
603
599
|
const rel = path.relative(home.base, p).split(path.sep).join('/');
|
|
604
|
-
return rel
|
|
600
|
+
return climbsOut(rel) ? rel : `./${rel}`;
|
|
605
601
|
};
|
|
606
602
|
// The whole `paths` the config needs: the entries it has now (a `paths` of
|
|
607
603
|
// its own replaces inherited ones), then every target the imports need.
|
|
@@ -745,7 +741,7 @@ export function reverseToFile({cwd, input, output, overwrite}) {
|
|
|
745
741
|
/** A page is never written as a configuration, test, spec or story file. @param {string} file */
|
|
746
742
|
const refuseConfigTarget = file => {
|
|
747
743
|
const rel = path.relative(cwd, file).split(path.sep).join('/');
|
|
748
|
-
const where = rel
|
|
744
|
+
const where = climbsOut(rel) || path.isAbsolute(rel) ? path.basename(file) : rel;
|
|
749
745
|
// Where the page lands must be a page module, and a name no tool takes
|
|
750
746
|
// as its own (configuration, a runner's file): the same rules as any
|
|
751
747
|
// file a restore writes.
|
|
@@ -58,6 +58,8 @@ export function coreUnavailableMessage(cwd: string, importError: any): string;
|
|
|
58
58
|
* @returns {string}
|
|
59
59
|
*/
|
|
60
60
|
export function normalizeThemeBuildForCompare(content: string): string;
|
|
61
|
+
/** @param {string} dest absolute output path @param {string} root @returns {boolean} whether a build at `root` refuses to write `dest` */
|
|
62
|
+
export function refusedOutput(dest: string, root: string): boolean;
|
|
61
63
|
/**
|
|
62
64
|
* Whether `error` is a build's refusal of a theme that sets a private var
|
|
63
65
|
* (which `doctor` reports in its own check, not as a stale output).
|
|
@@ -131,6 +133,16 @@ export function setEditorFolderListener(listener: ((warning: string) => void) |
|
|
|
131
133
|
* and `familyKey` names its key (a family run never takes --out).
|
|
132
134
|
* @typedef {{glob?: boolean, family?: boolean, familyKey?: string}} SuggestionShape
|
|
133
135
|
*/
|
|
136
|
+
/**
|
|
137
|
+
* The refusal a build gives the file it is given before it reads it, or
|
|
138
|
+
* null: a file that is not there, and a folder. The build throws it, and a
|
|
139
|
+
* suggested build is checked by it before it is offered.
|
|
140
|
+
* @param {string} file as typed, from cwd
|
|
141
|
+
* @param {BuildMode} options
|
|
142
|
+
* @param {string} cwd
|
|
143
|
+
* @returns {AstryxError | null}
|
|
144
|
+
*/
|
|
145
|
+
export function buildInputProblem(file: string, options: BuildMode, cwd: string): AstryxError | null;
|
|
134
146
|
/**
|
|
135
147
|
* The `theme build` command for `source` with the caller's mode flags, so a
|
|
136
148
|
* suggestion never turns a check into a write or moves the outputs.
|
|
@@ -422,3 +434,4 @@ export type ThemeBuildHandOff = {
|
|
|
422
434
|
};
|
|
423
435
|
colorModes?: ["light"] | ["dark"] | null;
|
|
424
436
|
};
|
|
437
|
+
import { AstryxError } from '../../error.mjs';
|
|
@@ -823,7 +823,7 @@ function confineOutputs(writes, root, remedy) {
|
|
|
823
823
|
}
|
|
824
824
|
|
|
825
825
|
/** @param {string} dest absolute output path @param {string} root @returns {boolean} whether a build at `root` refuses to write `dest` */
|
|
826
|
-
function refusedOutput(dest, root) {
|
|
826
|
+
export function refusedOutput(dest, root) {
|
|
827
827
|
try {
|
|
828
828
|
confineOutput(dest, root, '');
|
|
829
829
|
return false;
|
|
@@ -1240,6 +1240,45 @@ export function setEditorFolderListener(listener) {
|
|
|
1240
1240
|
* @typedef {{glob?: boolean, family?: boolean, familyKey?: string}} SuggestionShape
|
|
1241
1241
|
*/
|
|
1242
1242
|
|
|
1243
|
+
/**
|
|
1244
|
+
* The refusal a build gives the file it is given before it reads it, or
|
|
1245
|
+
* null: a file that is not there, and a folder. The build throws it, and a
|
|
1246
|
+
* suggested build is checked by it before it is offered.
|
|
1247
|
+
* @param {string} file as typed, from cwd
|
|
1248
|
+
* @param {BuildMode} options
|
|
1249
|
+
* @param {string} cwd
|
|
1250
|
+
* @returns {AstryxError | null}
|
|
1251
|
+
*/
|
|
1252
|
+
export function buildInputProblem(file, options, cwd) {
|
|
1253
|
+
const filePath = path.resolve(cwd, file);
|
|
1254
|
+
if (!fs.existsSync(filePath))
|
|
1255
|
+
return new AstryxError(
|
|
1256
|
+
`File not found: ${filePath}`,
|
|
1257
|
+
themeSourceGuesses(file, cwd).map(guess => ({
|
|
1258
|
+
name: buildSuggestion(guess, options, cwd),
|
|
1259
|
+
reason: 'a theme source that exists',
|
|
1260
|
+
})),
|
|
1261
|
+
ERROR_CODES.ERR_FILE_NOT_FOUND,
|
|
1262
|
+
);
|
|
1263
|
+
if (fs.statSync(filePath).isDirectory())
|
|
1264
|
+
return new AstryxError(
|
|
1265
|
+
`${path.relative(cwd, filePath) || '.'} is a folder. Pass the theme file inside it.`,
|
|
1266
|
+
themeFilesIn(filePath).map(name => ({
|
|
1267
|
+
name: buildSuggestion(
|
|
1268
|
+
path
|
|
1269
|
+
.relative(cwd, path.join(filePath, name))
|
|
1270
|
+
.split(path.sep)
|
|
1271
|
+
.join('/'),
|
|
1272
|
+
options,
|
|
1273
|
+
cwd,
|
|
1274
|
+
),
|
|
1275
|
+
reason: 'a theme source in that folder',
|
|
1276
|
+
})),
|
|
1277
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1278
|
+
);
|
|
1279
|
+
return null;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1243
1282
|
/**
|
|
1244
1283
|
* The `theme build` command for `source` with the caller's mode flags, so a
|
|
1245
1284
|
* suggestion never turns a check into a write or moves the outputs.
|
|
@@ -3849,21 +3888,32 @@ async function themeBuildInternal(
|
|
|
3849
3888
|
report = {},
|
|
3850
3889
|
handOff = {},
|
|
3851
3890
|
) {
|
|
3891
|
+
// A blank --out names no file: the build would write files named by the
|
|
3892
|
+
// spaces alone.
|
|
3893
|
+
if (
|
|
3894
|
+
typeof options.out === 'string' &&
|
|
3895
|
+
options.out !== '' &&
|
|
3896
|
+
!options.out.trim()
|
|
3897
|
+
)
|
|
3898
|
+
throw new AstryxError(
|
|
3899
|
+
'--out is blank; name a file or folder, or leave out --out to write beside the source.',
|
|
3900
|
+
[
|
|
3901
|
+
{
|
|
3902
|
+
name: buildSuggestion(file, {...options, out: undefined}, cwd),
|
|
3903
|
+
reason: 'do this instead',
|
|
3904
|
+
},
|
|
3905
|
+
],
|
|
3906
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
3907
|
+
);
|
|
3852
3908
|
// A backslash in --out separates folders on every platform, as it does in
|
|
3853
3909
|
// the other theme paths (a Windows path copied into a POSIX shell).
|
|
3854
3910
|
if (typeof options.out === 'string' && options.out.includes('\\'))
|
|
3855
3911
|
options = {...options, out: options.out.replace(/\\/g, '/')};
|
|
3856
3912
|
const filePath = path.resolve(cwd, file);
|
|
3857
3913
|
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
themeSourceGuesses(file, cwd).map(guess => ({
|
|
3862
|
-
name: buildSuggestion(guess, options, cwd),
|
|
3863
|
-
reason: 'a theme source that exists',
|
|
3864
|
-
})),
|
|
3865
|
-
ERROR_CODES.ERR_FILE_NOT_FOUND,
|
|
3866
|
-
);
|
|
3914
|
+
{
|
|
3915
|
+
const problem = buildInputProblem(file, options, cwd);
|
|
3916
|
+
if (problem) throw problem;
|
|
3867
3917
|
}
|
|
3868
3918
|
|
|
3869
3919
|
// A theme the theme editor made is built from its settings by the editor;
|
|
@@ -3882,24 +3932,6 @@ async function themeBuildInternal(
|
|
|
3882
3932
|
);
|
|
3883
3933
|
}
|
|
3884
3934
|
|
|
3885
|
-
if (fs.statSync(filePath).isDirectory()) {
|
|
3886
|
-
throw new AstryxError(
|
|
3887
|
-
`${path.relative(cwd, filePath) || '.'} is a folder. Pass the theme file inside it.`,
|
|
3888
|
-
themeFilesIn(filePath).map(name => ({
|
|
3889
|
-
name: buildSuggestion(
|
|
3890
|
-
path
|
|
3891
|
-
.relative(cwd, path.join(filePath, name))
|
|
3892
|
-
.split(path.sep)
|
|
3893
|
-
.join('/'),
|
|
3894
|
-
options,
|
|
3895
|
-
cwd,
|
|
3896
|
-
),
|
|
3897
|
-
reason: 'a theme source in that folder',
|
|
3898
|
-
})),
|
|
3899
|
-
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
3900
|
-
);
|
|
3901
|
-
}
|
|
3902
|
-
|
|
3903
3935
|
assertThemeSourceFile(filePath, cwd, options);
|
|
3904
3936
|
|
|
3905
3937
|
if (!report.compact) {
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The font families a CSS font-family value names that something has to
|
|
6
|
+
* load: its names without generics, CSS-wide keywords, `var()` references
|
|
7
|
+
* or known system families.
|
|
8
|
+
* @param {string} value
|
|
9
|
+
* @returns {string[]}
|
|
10
|
+
*/
|
|
11
|
+
export function loadableFontFamilies(value: string): string[];
|
|
4
12
|
/**
|
|
5
13
|
* Collect the font families a resolved theme names but does not load —
|
|
6
14
|
* every `--font-family-*` token plus every component-override `fontFamily`,
|
|
@@ -60,6 +60,11 @@ const SYSTEM_FAMILIES = new Set([
|
|
|
60
60
|
'segoe ui',
|
|
61
61
|
'segoe ui emoji',
|
|
62
62
|
'segoe ui symbol',
|
|
63
|
+
// The weights Windows ships as families of their own.
|
|
64
|
+
'segoe ui light',
|
|
65
|
+
'segoe ui semilight',
|
|
66
|
+
'segoe ui semibold',
|
|
67
|
+
'segoe ui black',
|
|
63
68
|
'roboto',
|
|
64
69
|
'helvetica',
|
|
65
70
|
'helvetica neue',
|
|
@@ -129,6 +134,20 @@ function splitFamilies(value) {
|
|
|
129
134
|
return families;
|
|
130
135
|
}
|
|
131
136
|
|
|
137
|
+
/**
|
|
138
|
+
* The font families a CSS font-family value names that something has to
|
|
139
|
+
* load: its names without generics, CSS-wide keywords, `var()` references
|
|
140
|
+
* or known system families.
|
|
141
|
+
* @param {string} value
|
|
142
|
+
* @returns {string[]}
|
|
143
|
+
*/
|
|
144
|
+
export function loadableFontFamilies(value) {
|
|
145
|
+
return splitFamilies(value).filter(family => {
|
|
146
|
+
const key = family.toLowerCase();
|
|
147
|
+
return !GENERIC_KEYWORDS.has(key) && !SYSTEM_FAMILIES.has(key);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
132
151
|
/**
|
|
133
152
|
* Collect the font families a resolved theme names but does not load —
|
|
134
153
|
* every `--font-family-*` token plus every component-override `fontFamily`,
|
|
@@ -30,6 +30,13 @@ export function projectRoot(cwd: string): string;
|
|
|
30
30
|
* @returns {AstryxError | null}
|
|
31
31
|
*/
|
|
32
32
|
export function editorThemeRefusal(err: AstryxError, cwd: string): AstryxError | null;
|
|
33
|
+
/**
|
|
34
|
+
* The editor themes of the app the folder `cwd` is in, by name; none when
|
|
35
|
+
* the folder is in no app or its themes cannot be read.
|
|
36
|
+
* @param {string} cwd
|
|
37
|
+
* @returns {string[]}
|
|
38
|
+
*/
|
|
39
|
+
export function editorThemesAt(cwd: string): string[];
|
|
33
40
|
/**
|
|
34
41
|
* A refused compile whose first suggestion is another compile: that compile
|
|
35
42
|
* is run through compile's own checks before it is offered (in memory,
|
|
@@ -32,7 +32,12 @@
|
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
import {writeThemeTemplate} from '../theme/template/template.mjs';
|
|
35
|
-
import {
|
|
35
|
+
import {
|
|
36
|
+
buildInputProblem,
|
|
37
|
+
buildSuggestion,
|
|
38
|
+
realLocation,
|
|
39
|
+
refusedOutput,
|
|
40
|
+
} from '../theme/build/build.mjs';
|
|
36
41
|
import {createHash} from 'node:crypto';
|
|
37
42
|
import * as fs from 'node:fs';
|
|
38
43
|
import {createRequire} from 'node:module';
|
|
@@ -45,6 +50,10 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
|
45
50
|
import {findPackageRoot} from '../../foundation/fs/paths.mjs';
|
|
46
51
|
import {context, coreApp} from './_context.mjs';
|
|
47
52
|
import {APP_COPY_MARK} from './_marks.mjs';
|
|
53
|
+
import {
|
|
54
|
+
fontKey,
|
|
55
|
+
importedFontFamilies,
|
|
56
|
+
} from '../../foundation/fonts/font-stylesheet.mjs';
|
|
48
57
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
49
58
|
import {withFolderLock} from '../../foundation/release/folder-lock.mjs';
|
|
50
59
|
import {
|
|
@@ -56,7 +65,7 @@ import {LIKE, P} from './_tables.mjs';
|
|
|
56
65
|
/** The preview command, as a person runs it. */
|
|
57
66
|
const PREVIEW_WORDS = P.replace(/ editor$/, ' preview');
|
|
58
67
|
import {setLine} from './_check.mjs';
|
|
59
|
-
import {splitCommand} from './_vet.mjs';
|
|
68
|
+
import {followLine, splitCommand} from './_vet.mjs';
|
|
60
69
|
import {
|
|
61
70
|
SHOWCASE_GROUPS,
|
|
62
71
|
appCopyBehind,
|
|
@@ -75,6 +84,8 @@ import {
|
|
|
75
84
|
setAfterBuild,
|
|
76
85
|
editedThemes,
|
|
77
86
|
themeFiles,
|
|
87
|
+
fontsourcePackageOf,
|
|
88
|
+
themeSourceRefusal,
|
|
78
89
|
typedThemeName,
|
|
79
90
|
} from './_settings.mjs';
|
|
80
91
|
|
|
@@ -390,7 +401,7 @@ function absolute(result, root, from) {
|
|
|
390
401
|
* in-app preview's stale entries. Every project path in them (a theme
|
|
391
402
|
* file, an in-app preview folder) is made absolute, one style per line.
|
|
392
403
|
*/
|
|
393
|
-
const PROSE = new Set(['see', 'pictureProblem', 'previewStale']);
|
|
404
|
+
const PROSE = new Set(['see', 'pictureProblem', 'previewStale', 'wiring']);
|
|
394
405
|
/** A project-relative path that names a file or folder there. @param {string} p */
|
|
395
406
|
const inRoot = p => {
|
|
396
407
|
const bare = p.replace(/\/+$/, '');
|
|
@@ -881,6 +892,20 @@ export function editorThemeRefusal(err, cwd) {
|
|
|
881
892
|
);
|
|
882
893
|
}
|
|
883
894
|
|
|
895
|
+
/**
|
|
896
|
+
* The editor themes of the app the folder `cwd` is in, by name; none when
|
|
897
|
+
* the folder is in no app or its themes cannot be read.
|
|
898
|
+
* @param {string} cwd
|
|
899
|
+
* @returns {string[]}
|
|
900
|
+
*/
|
|
901
|
+
export function editorThemesAt(cwd) {
|
|
902
|
+
try {
|
|
903
|
+
return editedThemes(projectRoot(cwd));
|
|
904
|
+
} catch {
|
|
905
|
+
return [];
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
884
909
|
/**
|
|
885
910
|
* A refused compile whose first suggestion is another compile: that compile
|
|
886
911
|
* is run through compile's own checks before it is offered (in memory,
|
|
@@ -901,6 +926,8 @@ export async function editorFollowCompile(err, cwd) {
|
|
|
901
926
|
[' experimental theme compile ', ' theme build '].find(w =>
|
|
902
927
|
line.includes(w),
|
|
903
928
|
);
|
|
929
|
+
const isCompile = (/** @type {string} */ line) =>
|
|
930
|
+
/^cd /.test(line) || Boolean(wordsIn(line));
|
|
904
931
|
if (!first || /^cd /.test(first.name) || !wordsIn(first.name)) return err;
|
|
905
932
|
/** @param {string} line */
|
|
906
933
|
const read = line => {
|
|
@@ -921,69 +948,49 @@ export async function editorFollowCompile(err, cwd) {
|
|
|
921
948
|
return r.source ? r : null;
|
|
922
949
|
};
|
|
923
950
|
const COMPILE = {group: 'experimental theme', build: 'compile'};
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
continue;
|
|
947
|
-
}
|
|
948
|
-
/** @type {{message: string, next?: string} | null} */
|
|
949
|
-
let problem = null;
|
|
950
|
-
if (!fs.existsSync(abs)) problem = {message: `${source} is not there`};
|
|
951
|
-
else if (fs.statSync(abs).isDirectory()) {
|
|
952
|
-
const own = `${path.basename(abs)}.theme.ts`;
|
|
953
|
-
problem = {
|
|
954
|
-
message: `${source} is a folder`,
|
|
955
|
-
next: fs.existsSync(path.join(abs, own))
|
|
956
|
-
? buildSuggestion(
|
|
957
|
-
path.posix.join(source.replace(/\/+$/, ''), own),
|
|
958
|
-
r,
|
|
951
|
+
/** @type {string | null} */
|
|
952
|
+
let outDropped = null;
|
|
953
|
+
const followed = await followLine(
|
|
954
|
+
first.name,
|
|
955
|
+
async line => {
|
|
956
|
+
// A line that runs elsewhere is not checked from here.
|
|
957
|
+
if (/^cd /.test(line)) return null;
|
|
958
|
+
const r = read(line);
|
|
959
|
+
if (!r?.source) return null;
|
|
960
|
+
const refused =
|
|
961
|
+
(await editorCompileProblem([r.source], {cwd, ...r})) ??
|
|
962
|
+
buildInputProblem(r.source, r, cwd);
|
|
963
|
+
if (refused) return refused;
|
|
964
|
+
// A build writes only inside the working folder: the same build
|
|
965
|
+
// without --out writes beside the source.
|
|
966
|
+
if (r.out && refusedOutput(path.resolve(cwd, r.out), cwd)) {
|
|
967
|
+
outDropped = r.out;
|
|
968
|
+
return new AstryxError(`--out ${r.out} is outside the working folder`, [
|
|
969
|
+
{
|
|
970
|
+
name: buildSuggestion(
|
|
971
|
+
r.source,
|
|
972
|
+
{check: r.check, iconsSpecifier: r.iconsSpecifier},
|
|
959
973
|
cwd,
|
|
960
974
|
COMPILE,
|
|
961
|
-
)
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
if (/^cd /.test(line)) break;
|
|
978
|
-
continue;
|
|
979
|
-
}
|
|
980
|
-
reason = `${reason}; it is still refused: ${problem.message}`;
|
|
981
|
-
break;
|
|
982
|
-
}
|
|
983
|
-
if (line === first.name && reason === first.reason) return err;
|
|
975
|
+
),
|
|
976
|
+
reason: 'do this instead',
|
|
977
|
+
},
|
|
978
|
+
]);
|
|
979
|
+
}
|
|
980
|
+
return null;
|
|
981
|
+
},
|
|
982
|
+
isCompile,
|
|
983
|
+
);
|
|
984
|
+
if (followed.line === first.name) return err;
|
|
985
|
+
const reason = [
|
|
986
|
+
outDropped && !/ --out /.test(followed.line)
|
|
987
|
+
? `do this instead, without --out: ${outDropped} is outside the working folder, where a build may not write, so the outputs go beside the source`
|
|
988
|
+
: first.reason,
|
|
989
|
+
...(followed.why ? [`it is still refused: ${followed.why}`] : []),
|
|
990
|
+
].join('; ');
|
|
984
991
|
err.suggestions = [
|
|
985
|
-
{...first, name: line, reason},
|
|
986
|
-
...list.slice(1).filter(x => x.name !== line),
|
|
992
|
+
{...first, name: followed.line, reason},
|
|
993
|
+
...list.slice(1).filter(x => x.name !== followed.line),
|
|
987
994
|
];
|
|
988
995
|
return err;
|
|
989
996
|
}
|
|
@@ -1167,6 +1174,13 @@ export async function editorCompileProblem(
|
|
|
1167
1174
|
],
|
|
1168
1175
|
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
1169
1176
|
);
|
|
1177
|
+
// A source that no longer carries the settings (another theme's name,
|
|
1178
|
+
// or no extends of them) is refused as set refuses it: a build would
|
|
1179
|
+
// write another theme's files, or drop every setting.
|
|
1180
|
+
{
|
|
1181
|
+
const refusal = themeSourceRefusal(root, slug);
|
|
1182
|
+
if (refusal) return refusal;
|
|
1183
|
+
}
|
|
1170
1184
|
if (family)
|
|
1171
1185
|
return new AstryxError(
|
|
1172
1186
|
`${slug} is a theme the editor made; --family builds package theme families, not editor themes. Compile it on its own.`,
|
|
@@ -1520,51 +1534,35 @@ export async function editorLoadedFonts(file, cwd) {
|
|
|
1520
1534
|
? editorThemeAt(root, abs)?.slug
|
|
1521
1535
|
: null);
|
|
1522
1536
|
if (!slug) return null;
|
|
1523
|
-
/** @param {string} s */
|
|
1524
|
-
const key = s =>
|
|
1525
|
-
String(s)
|
|
1526
|
-
.replace(/["']/g, '')
|
|
1527
|
-
.toLowerCase()
|
|
1528
|
-
.replace(/[^a-z0-9]/g, '');
|
|
1529
|
-
/** @type {Set<string>} */
|
|
1530
|
-
const loaded = new Set();
|
|
1531
1537
|
// The stylesheets the copy's font file imports once this compile has
|
|
1532
|
-
// written it: from the fonts the theme loads now
|
|
1533
|
-
//
|
|
1538
|
+
// written it: from the fonts the theme loads now, as the copy write
|
|
1539
|
+
// computes them.
|
|
1534
1540
|
/** @type {string[]} */
|
|
1535
1541
|
let specs;
|
|
1536
1542
|
try {
|
|
1537
1543
|
specs = copyFontsCss(await context(root), slug, loadTheme(root, slug));
|
|
1538
1544
|
} catch {
|
|
1539
|
-
|
|
1540
|
-
specs = [
|
|
1541
|
-
...fs
|
|
1542
|
-
.readFileSync(
|
|
1543
|
-
path.join(root, 'src', 'themes', slug, `${slug}.fonts.css`),
|
|
1544
|
-
'utf8',
|
|
1545
|
-
)
|
|
1546
|
-
.matchAll(/@import\s+"([^"]+)"/g),
|
|
1547
|
-
].map(m => m[1]);
|
|
1548
|
-
} catch {
|
|
1549
|
-
return null;
|
|
1550
|
-
}
|
|
1545
|
+
return null;
|
|
1551
1546
|
}
|
|
1547
|
+
const copyDir = path.join(root, 'src', 'themes', slug);
|
|
1548
|
+
const from = fs.existsSync(copyDir) ? copyDir : root;
|
|
1549
|
+
/** @type {Set<string>} */
|
|
1550
|
+
const loaded = new Set();
|
|
1551
|
+
for (const spec of specs)
|
|
1552
|
+
for (const f of importedFontFamilies(spec, from)) loaded.add(f);
|
|
1553
|
+
// A family the build names whose @fontsource package is installed: the
|
|
1554
|
+
// copy written after this build imports that package (copyFontsCss).
|
|
1552
1555
|
const req = createRequire(path.join(root, 'package.json'));
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
if (pkg) {
|
|
1556
|
-
loaded.add(key(pkg[1]));
|
|
1557
|
-
continue;
|
|
1558
|
-
}
|
|
1556
|
+
/** @param {string} family */
|
|
1557
|
+
const installed = family => {
|
|
1559
1558
|
try {
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
loaded.add(key(decodeURIComponent(f[1].replace(/\+/g, ' '))));
|
|
1559
|
+
req.resolve(`${fontsourcePackageOf(family)}/package.json`);
|
|
1560
|
+
return true;
|
|
1563
1561
|
} catch {
|
|
1564
|
-
|
|
1562
|
+
return false;
|
|
1565
1563
|
}
|
|
1566
|
-
}
|
|
1567
|
-
return family => loaded.has(
|
|
1564
|
+
};
|
|
1565
|
+
return family => loaded.has(fontKey(family)) || installed(family);
|
|
1568
1566
|
}
|
|
1569
1567
|
|
|
1570
1568
|
/**
|