@astryxdesign/cli 0.6.5-canary.eb58bba → 0.6.5-canary.efac39f
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 +2 -2
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-theme.mjs +243 -22
- package/api/integration/add-theme.test.mjs +213 -0
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/template/copy/copy.mjs +5 -3
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +1 -1
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +1 -0
- package/api/template/template.type.mjs +1 -0
- package/api/theme/build/build.d.mts +24 -0
- package/api/theme/build/build.icon-lineage.test.mjs +117 -0
- package/api/theme/build/build.icon-preservation.test.mjs +639 -0
- package/api/theme/build/build.mjs +381 -77
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/theme/build/build.test.mjs +190 -1
- package/api/theme/build/icon-imports.d.mts +47 -0
- package/api/theme/build/icon-imports.mjs +691 -0
- package/api/theme/themeBuild.doc.d.mts +4 -1
- package/api/theme/themeBuild.doc.mjs +14 -3
- package/assets/docs/icons.doc.mjs +1 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-expand.doc.mjs +3 -1
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +16 -0
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +8 -3
- package/foundation/doc-compiler/doc-loads.test.mjs +3 -3
- package/foundation/response/response-types.doc.mjs +2 -2
- package/package.json +9 -9
|
@@ -33,6 +33,12 @@ export const doc = {
|
|
|
33
33
|
'Validate and return the same receipt without writing; data.written is false and data.dryRun is true.',
|
|
34
34
|
default: 'false',
|
|
35
35
|
},
|
|
36
|
+
{
|
|
37
|
+
name: 'options.from',
|
|
38
|
+
type: 'string',
|
|
39
|
+
description:
|
|
40
|
+
'Slug of an existing theme to fork as the starting point. The new theme copies the base and has no link back.',
|
|
41
|
+
},
|
|
36
42
|
],
|
|
37
43
|
returns: [
|
|
38
44
|
{
|
|
@@ -76,6 +82,10 @@ export const doc = {
|
|
|
76
82
|
label: 'Add a theme',
|
|
77
83
|
code: "await integrationAddTheme('ocean');",
|
|
78
84
|
},
|
|
85
|
+
{
|
|
86
|
+
label: 'Fork an existing theme',
|
|
87
|
+
code: "await integrationAddTheme('ocean', {from: 'neutral'});",
|
|
88
|
+
},
|
|
79
89
|
{
|
|
80
90
|
label: 'Preview writes',
|
|
81
91
|
code: "await integrationAddTheme('ocean', {dryRun: true});",
|
|
@@ -18,7 +18,7 @@ import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
|
18
18
|
import {assertWithin, isFilePathArg, PathSafetyError} from '../../../foundation/fs/path-safety.mjs';
|
|
19
19
|
import {detectForm} from '../../../foundation/xle/parse.mjs';
|
|
20
20
|
import {expand} from '../../../foundation/xle/expand.mjs';
|
|
21
|
-
import {
|
|
21
|
+
import {replaceDemoMedia} from '../../template/template.mjs';
|
|
22
22
|
import {analyze, formatIssue} from '../_adapter.mjs';
|
|
23
23
|
|
|
24
24
|
/** @param {string} name */
|
|
@@ -59,28 +59,32 @@ function collectHintNames(doc) {
|
|
|
59
59
|
/**
|
|
60
60
|
* Build the blockModules map expand() needs: import-mode for app components,
|
|
61
61
|
* splice-mode (reading + asset-stripping the block source) for template blocks.
|
|
62
|
-
* Only blocks actually referenced are read.
|
|
62
|
+
* Only blocks actually referenced are read. Also returns how many demo media
|
|
63
|
+
* references the splice-mode sources had replaced.
|
|
63
64
|
*
|
|
64
65
|
* @param {import('../../../foundation/xle/xle-ast').XLEDoc} doc
|
|
65
66
|
* @param {import('../_adapter.mjs').LayoutBlock[]} blocks
|
|
66
|
-
* @returns {Map<string, import('../../../foundation/xle/xle-ast').BlockModule
|
|
67
|
+
* @returns {{modules: Map<string, import('../../../foundation/xle/xle-ast').BlockModule>, demoMediaReplaced: number}}
|
|
67
68
|
*/
|
|
68
69
|
function buildBlockModules(doc, blocks) {
|
|
69
70
|
const referenced = collectHintNames(doc);
|
|
70
|
-
if (referenced.size === 0) return new Map();
|
|
71
|
+
if (referenced.size === 0) return {modules: new Map(), demoMediaReplaced: 0};
|
|
71
72
|
const byKey = new Map(blocks.map(b => [normKey(b.dirName), b]));
|
|
72
73
|
/** @type {Map<string, import('../../../foundation/xle/xle-ast').BlockModule>} */
|
|
73
74
|
const modules = new Map();
|
|
75
|
+
let demoMediaReplaced = 0;
|
|
74
76
|
for (const name of referenced) {
|
|
75
77
|
const block = byKey.get(normKey(name));
|
|
76
78
|
if (!block) continue;
|
|
77
79
|
if (block.kind === 'component') {
|
|
78
80
|
modules.set(name, /** @type {import('../../../foundation/xle/xle-ast').BlockModule} */ (/** @type {unknown} */ ({mode: 'import', componentName: block.name, importPath: block.importPath, isDefault: block.isDefault})));
|
|
79
81
|
} else if (block.filePath && fs.existsSync(block.filePath)) {
|
|
80
|
-
|
|
82
|
+
const spliced = replaceDemoMedia(fs.readFileSync(block.filePath, 'utf-8'));
|
|
83
|
+
demoMediaReplaced += spliced.demoMediaReplaced;
|
|
84
|
+
modules.set(name, /** @type {import('../../../foundation/xle/xle-ast').BlockModule} */ ({mode: 'splice', componentName: block.dirName, source: spliced.source}));
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
|
-
return modules;
|
|
87
|
+
return {modules, demoMediaReplaced};
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
/**
|
|
@@ -115,7 +119,7 @@ export async function layoutExpand(expression, options = {}) {
|
|
|
115
119
|
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
116
120
|
);
|
|
117
121
|
}
|
|
118
|
-
const blockModules = buildBlockModules(doc, blocks);
|
|
122
|
+
const {modules: blockModules, demoMediaReplaced} = buildBlockModules(doc, blocks);
|
|
119
123
|
const result = expand(doc, registry, {componentName, blockModules});
|
|
120
124
|
|
|
121
125
|
let written = null;
|
|
@@ -150,6 +154,7 @@ export async function layoutExpand(expression, options = {}) {
|
|
|
150
154
|
blocksReferenced: [...blockModules.entries()].map(([name, m]) => ({name, mode: m.mode})),
|
|
151
155
|
warnings: warnings.map(formatIssue),
|
|
152
156
|
written,
|
|
157
|
+
demoMediaReplaced,
|
|
153
158
|
},
|
|
154
159
|
};
|
|
155
160
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The layout.expand receipt discloses demo media replaced in the template
|
|
5
|
+
* blocks it splices. Blocks are picked by what their source contains, not by
|
|
6
|
+
* name, so catalog renames do not break the suite.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {describe, it, expect, beforeAll} from 'vitest';
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
import {layoutExpand} from '../layout.mjs';
|
|
12
|
+
import {discoverTemplates} from '../../template/template.mjs';
|
|
13
|
+
import {buildRegistry} from '../../../foundation/xle/registry.mjs';
|
|
14
|
+
|
|
15
|
+
const SLOW = 60_000;
|
|
16
|
+
const FIXTURE_REF = /\/template-assets\/[\w.-]+\.\w+/g;
|
|
17
|
+
|
|
18
|
+
beforeAll(async () => {
|
|
19
|
+
await buildRegistry();
|
|
20
|
+
}, 120_000);
|
|
21
|
+
|
|
22
|
+
/** @param {string} name */
|
|
23
|
+
const hintKey = name => name.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
24
|
+
|
|
25
|
+
/** @type {Promise<Array<{hint: string, refs: number}>> | undefined} */
|
|
26
|
+
let catalog;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Template blocks a `{hint}` resolves to unambiguously, with the number of demo
|
|
30
|
+
* media references in each one's source.
|
|
31
|
+
* @returns {Promise<Array<{hint: string, refs: number}>>}
|
|
32
|
+
*/
|
|
33
|
+
function catalogBlocks() {
|
|
34
|
+
catalog ??= discoverTemplates().then(found => {
|
|
35
|
+
const all = /** @type {Array<{dirName: string, type: string, filePath: string}>} */ (
|
|
36
|
+
found
|
|
37
|
+
).filter(t => t.type === 'block' && t.filePath && fs.existsSync(t.filePath));
|
|
38
|
+
const seen = new Map();
|
|
39
|
+
for (const t of all) seen.set(hintKey(t.dirName), (seen.get(hintKey(t.dirName)) ?? 0) + 1);
|
|
40
|
+
return all
|
|
41
|
+
.filter(t => seen.get(hintKey(t.dirName)) === 1)
|
|
42
|
+
.map(t => ({
|
|
43
|
+
hint: hintKey(t.dirName),
|
|
44
|
+
refs: (fs.readFileSync(t.filePath, 'utf-8').match(FIXTURE_REF) ?? []).length,
|
|
45
|
+
}));
|
|
46
|
+
});
|
|
47
|
+
return catalog;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('layout.expand receipt - replaced demo media', () => {
|
|
51
|
+
it('counts the demo media of a spliced block once, however often it is referenced', async () => {
|
|
52
|
+
const block = (await catalogBlocks()).find(b => b.refs > 0);
|
|
53
|
+
if (!block) throw new Error('no template block carries demo media');
|
|
54
|
+
const res = await layoutExpand(`V > {${block.hint}}*3`);
|
|
55
|
+
expect(res.type).toBe('layout.expand');
|
|
56
|
+
expect(res.data.blocksReferenced).toHaveLength(1);
|
|
57
|
+
expect(res.data.demoMediaReplaced).toBe(block.refs);
|
|
58
|
+
expect(res.data.code).not.toContain('/template-assets/');
|
|
59
|
+
}, SLOW);
|
|
60
|
+
|
|
61
|
+
it('sums the demo media of every spliced block', async () => {
|
|
62
|
+
const [a, b] = (await catalogBlocks()).filter(x => x.refs > 0);
|
|
63
|
+
if (!b) throw new Error('fewer than two template blocks carry demo media');
|
|
64
|
+
const res = await layoutExpand(`V > {${a.hint}} + {${b.hint}}`);
|
|
65
|
+
expect(res.data.demoMediaReplaced).toBe(a.refs + b.refs);
|
|
66
|
+
}, SLOW);
|
|
67
|
+
|
|
68
|
+
it('reports 0 when nothing spliced carries demo media', async () => {
|
|
69
|
+
const plain = (await catalogBlocks()).find(b => b.refs === 0);
|
|
70
|
+
if (!plain) throw new Error('every template block carries demo media');
|
|
71
|
+
expect((await layoutExpand(`V > {${plain.hint}}`)).data.demoMediaReplaced).toBe(0);
|
|
72
|
+
expect((await layoutExpand('V > B"Save"')).data.demoMediaReplaced).toBe(0);
|
|
73
|
+
}, SLOW);
|
|
74
|
+
});
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
* @property {LayoutBlockReference[]} data.blocksReferenced
|
|
49
49
|
* @property {string[]} data.warnings
|
|
50
50
|
* @property {string | null} data.written
|
|
51
|
+
* @property {number} data.demoMediaReplaced Astryx demo media references (images, posters, videos) replaced in the spliced template blocks: images with a neutral placeholder, videos with an empty source. Swap in your own media at those points in the code; no media is installed. 0 when no spliced block carried any.
|
|
51
52
|
*/
|
|
52
53
|
|
|
53
54
|
/**
|
|
@@ -70,7 +70,7 @@ export const doc = {
|
|
|
70
70
|
{
|
|
71
71
|
type: 'layout.expand',
|
|
72
72
|
description:
|
|
73
|
-
'The expansion: the parsed form, the generated TSX code, componentsUsed, states (count of useState hooks scaffolded), todos, blocksReferenced (each {name, mode}), warnings,
|
|
73
|
+
'The expansion: the parsed form, the generated TSX code, componentsUsed, states (count of useState hooks scaffolded), todos, blocksReferenced (each {name, mode}), warnings, written (the relative output path, or null when nothing was written), and demoMediaReplaced (how many Astryx demo media references in the spliced template blocks, such as images, posters and videos, were replaced with placeholders for you to swap for your own media).',
|
|
74
74
|
},
|
|
75
75
|
],
|
|
76
76
|
throws: [
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from '../../../foundation/fs/path-safety.mjs';
|
|
19
19
|
import {AstryxError, writeFailed} from '../../error.mjs';
|
|
20
20
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
21
|
-
import {
|
|
21
|
+
import {replaceDemoMedia} from '../../../foundation/discovery/template-adapter.mjs';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Scaffold an already-resolved template to `targetPath` (relative to `cwd`) and
|
|
@@ -83,8 +83,9 @@ export function templateCopy(match, {targetPath, cwd, overwrite = false}) {
|
|
|
83
83
|
// Strip demo image references so the scaffolded file renders without a
|
|
84
84
|
// Meta-only network dependency. Read before any write, so a failure below
|
|
85
85
|
// leaves nothing behind.
|
|
86
|
-
const source =
|
|
87
|
-
|
|
86
|
+
const {source: outputSource, demoMediaReplaced} = replaceDemoMedia(
|
|
87
|
+
fs.readFileSync(match.filePath, 'utf-8'),
|
|
88
|
+
);
|
|
88
89
|
try {
|
|
89
90
|
fs.mkdirSync(outputDir, {recursive: true});
|
|
90
91
|
fs.writeFileSync(outputFilePath, outputSource);
|
|
@@ -100,6 +101,7 @@ export function templateCopy(match, {targetPath, cwd, overwrite = false}) {
|
|
|
100
101
|
outputDir: relOutput,
|
|
101
102
|
fileName: outputFileName,
|
|
102
103
|
filesCopied: 1,
|
|
104
|
+
demoMediaReplaced,
|
|
103
105
|
},
|
|
104
106
|
};
|
|
105
107
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The template.copy receipt discloses replaced demo media. Templates are
|
|
5
|
+
* picked by what their source contains, not by slug, so catalog renames do not
|
|
6
|
+
* break the suite.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
import * as os from 'node:os';
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
import {template, discoverTemplates} from '../template.mjs';
|
|
14
|
+
|
|
15
|
+
const SLOW = 60_000;
|
|
16
|
+
const FIXTURE_REF = /\/template-assets\/[\w.-]+\.(\w+)/g;
|
|
17
|
+
const VIDEO = new Set(['mp4', 'webm', 'mov', 'ogv', 'm4v']);
|
|
18
|
+
|
|
19
|
+
/** @param {string} filePath */
|
|
20
|
+
const fixtureRefs = filePath =>
|
|
21
|
+
[...fs.readFileSync(filePath, 'utf-8').matchAll(FIXTURE_REF)].map(m =>
|
|
22
|
+
m[1].toLowerCase(),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {(refs: string[]) => boolean} predicate
|
|
27
|
+
* @param {'page' | 'block'} type
|
|
28
|
+
*/
|
|
29
|
+
async function findTemplate(type, predicate) {
|
|
30
|
+
const all = /** @type {Array<{dirName: string, type: string, filePath: string}>} */ (
|
|
31
|
+
await discoverTemplates()
|
|
32
|
+
);
|
|
33
|
+
const ids = new Map();
|
|
34
|
+
for (const t of all) ids.set(t.dirName, (ids.get(t.dirName) ?? 0) + 1);
|
|
35
|
+
const found = all.find(
|
|
36
|
+
t =>
|
|
37
|
+
t.type === type &&
|
|
38
|
+
ids.get(t.dirName) === 1 &&
|
|
39
|
+
fs.existsSync(t.filePath) &&
|
|
40
|
+
predicate(fixtureRefs(t.filePath)),
|
|
41
|
+
);
|
|
42
|
+
if (!found) throw new Error(`no ${type} template matches`);
|
|
43
|
+
return {id: found.dirName, refs: fixtureRefs(found.filePath)};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe('template.copy receipt — replaced demo media', () => {
|
|
47
|
+
let dir;
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpl-receipt-'));
|
|
50
|
+
});
|
|
51
|
+
afterEach(() => fs.rmSync(dir, {recursive: true, force: true}));
|
|
52
|
+
|
|
53
|
+
it('counts every demo image a page template carried, and leaves none behind', async () => {
|
|
54
|
+
const {id, refs} = await findTemplate(
|
|
55
|
+
'page',
|
|
56
|
+
r => r.length > 0 && r.every(ext => !VIDEO.has(ext)),
|
|
57
|
+
);
|
|
58
|
+
const res = await template(id, {targetPath: './dest', cwd: dir});
|
|
59
|
+
expect(res.type).toBe('template.copy');
|
|
60
|
+
expect(res.data.demoMediaReplaced).toBe(refs.length);
|
|
61
|
+
expect(
|
|
62
|
+
fs.readFileSync(path.join(dir, 'dest', 'page.tsx'), 'utf-8'),
|
|
63
|
+
).not.toContain('/template-assets/');
|
|
64
|
+
}, SLOW);
|
|
65
|
+
|
|
66
|
+
it('counts a demo video in a block template', async () => {
|
|
67
|
+
const {id, refs} = await findTemplate('block', r => r.some(ext => VIDEO.has(ext)));
|
|
68
|
+
const res = await template(id, {targetPath: './dest', cwd: dir});
|
|
69
|
+
expect(res.data.demoMediaReplaced).toBe(refs.length);
|
|
70
|
+
}, SLOW);
|
|
71
|
+
|
|
72
|
+
it('reports 0 when the template carries no demo media', async () => {
|
|
73
|
+
const {id} = await findTemplate('page', r => r.length === 0);
|
|
74
|
+
const res = await template(id, {targetPath: './dest', cwd: dir});
|
|
75
|
+
expect(res.data.demoMediaReplaced).toBe(0);
|
|
76
|
+
}, SLOW);
|
|
77
|
+
});
|
|
@@ -41,4 +41,4 @@ export function template(name?: string, options?: {
|
|
|
41
41
|
export type DiscoveredTemplate = import("../../foundation/discovery/template-adapter.mjs").DiscoveredTemplate;
|
|
42
42
|
export type TemplateDiscoveryError = import("../../foundation/discovery/template-adapter.mjs").TemplateDiscoveryError;
|
|
43
43
|
export type TemplateDocModule = import("../../foundation/discovery/template-adapter.mjs").TemplateDocModule;
|
|
44
|
-
export { discoverAll, discoverAll as discoverTemplates, discoverAllWithErrors, discoverCoreTemplates, discoverIntegrationTemplatesForOne, stripTemplateAssetRefs, listTemplates, findRelatedBlocks, findShowcase, extractComponents } from "../../foundation/discovery/template-adapter.mjs";
|
|
44
|
+
export { discoverAll, discoverAll as discoverTemplates, discoverAllWithErrors, discoverCoreTemplates, discoverIntegrationTemplatesForOne, stripTemplateAssetRefs, replaceDemoMedia, listTemplates, findRelatedBlocks, findShowcase, extractComponents } from "../../foundation/discovery/template-adapter.mjs";
|
|
@@ -124,7 +124,7 @@ export const doc = {
|
|
|
124
124
|
{
|
|
125
125
|
type: 'template.copy',
|
|
126
126
|
description:
|
|
127
|
-
'A receipt after scaffolding the template into the project: the template id, output directory, written file name, and file
|
|
127
|
+
'A receipt after scaffolding the template into the project: the template id, output directory, written file name, file count, and `demoMediaReplaced` — how many Astryx demo media references (images, posters, videos) in the written file were replaced with placeholders for you to swap for your own media.',
|
|
128
128
|
},
|
|
129
129
|
{
|
|
130
130
|
type: 'template.cdn',
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
* @property {string} data.outputDir
|
|
77
77
|
* @property {string} data.fileName
|
|
78
78
|
* @property {number} data.filesCopied
|
|
79
|
+
* @property {number} data.demoMediaReplaced Astryx demo media references (images, posters, videos) replaced in the written file: images with a neutral placeholder, videos with an empty source. Swap in your own media at those points; no media is installed. 0 when the template carried none.
|
|
79
80
|
*/
|
|
80
81
|
|
|
81
82
|
/**
|
|
@@ -1,6 +1,16 @@
|
|
|
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
|
+
* Why `theme build` has no Core to generate with, and the fix for where it
|
|
6
|
+
* ran: the Astryx repository builds Core, an app installs it, and an installed
|
|
7
|
+
* Core that will not load is named.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} cwd
|
|
10
|
+
* @param {any} importError - Why the import failed, when it threw.
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
export function coreUnavailableMessage(cwd: string, importError: any): string;
|
|
4
14
|
/**
|
|
5
15
|
* Import specifier for install/scaffold instructions. Drops a leading `src/`
|
|
6
16
|
* from the cwd-relative dir (most consumers import from a file under src/) but
|
|
@@ -106,3 +116,17 @@ export function themeBuildFamily(files: string[], options: {
|
|
|
106
116
|
* validateAdaptationEnrollment)
|
|
107
117
|
*/
|
|
108
118
|
export type ComponentValueClass = "builtin" | "enrollment" | "unresolved";
|
|
119
|
+
/**
|
|
120
|
+
* The bindings one Core provides: the namespaces interception spreads, the
|
|
121
|
+
* functions the build calls, and why the import failed, if it did.
|
|
122
|
+
*/
|
|
123
|
+
export type CoreBindings = {
|
|
124
|
+
themeModule: any;
|
|
125
|
+
rootModule: any;
|
|
126
|
+
importError: any;
|
|
127
|
+
defineTheme: any;
|
|
128
|
+
generateThemeRulesSplit: any;
|
|
129
|
+
generateOnMediaCSS: any;
|
|
130
|
+
generateAdaptationCSS: any;
|
|
131
|
+
dataTokenDefaults: any;
|
|
132
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Icon preservation through multiple generations of built themes.
|
|
5
|
+
* @input Real themeBuild calls and registries imported under the same local
|
|
6
|
+
* binding name from separate base and child theme directories.
|
|
7
|
+
* @output A native ESM load verifies inherited and overridden React icons
|
|
8
|
+
* survive when a grandchild extends the child's generated artifact.
|
|
9
|
+
* @position Direct API regression for persisted icon inheritance in #5058.
|
|
10
|
+
* The node project's global setup supplies the compiled core package.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {expect, it} from 'vitest';
|
|
14
|
+
import {execFileSync} from 'node:child_process';
|
|
15
|
+
import * as fs from 'node:fs';
|
|
16
|
+
import * as path from 'node:path';
|
|
17
|
+
import {themeBuild} from './build.mjs';
|
|
18
|
+
|
|
19
|
+
it('preserves merged icon lineage through a built child with colliding import names', async () => {
|
|
20
|
+
const tmpDir = fs.mkdtempSync(
|
|
21
|
+
path.resolve(import.meta.dirname, '../../..', '.tmp-icon-lineage-'),
|
|
22
|
+
);
|
|
23
|
+
try {
|
|
24
|
+
for (const directory of ['base', 'child']) {
|
|
25
|
+
fs.mkdirSync(path.join(tmpDir, directory));
|
|
26
|
+
}
|
|
27
|
+
const write = (file, source) =>
|
|
28
|
+
fs.writeFileSync(path.join(tmpDir, file), source);
|
|
29
|
+
const writeRegistry = (file, labels) => {
|
|
30
|
+
write(
|
|
31
|
+
file,
|
|
32
|
+
`import {createElement} from 'react';
|
|
33
|
+
export const icons = {
|
|
34
|
+
${Object.entries(labels)
|
|
35
|
+
.map(
|
|
36
|
+
([key, label]) =>
|
|
37
|
+
` ${JSON.stringify(key)}: createElement('svg', {'data-icon': ${JSON.stringify(label)}}),`,
|
|
38
|
+
)
|
|
39
|
+
.join('\n')}
|
|
40
|
+
};
|
|
41
|
+
`,
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
writeRegistry('base/icons.mjs', {
|
|
46
|
+
check: 'base-check',
|
|
47
|
+
close: 'base-close',
|
|
48
|
+
});
|
|
49
|
+
writeRegistry('child/icons.mjs', {
|
|
50
|
+
add: 'child-add',
|
|
51
|
+
close: 'child-close',
|
|
52
|
+
});
|
|
53
|
+
write(
|
|
54
|
+
'base/source.mjs',
|
|
55
|
+
`import {defineTheme} from '@astryxdesign/core/theme';
|
|
56
|
+
import {icons} from './icons.mjs';
|
|
57
|
+
export const baseTheme = defineTheme({
|
|
58
|
+
name: 'base', tokens: {'--color-bg': '#fff'}, icons,
|
|
59
|
+
});
|
|
60
|
+
`,
|
|
61
|
+
);
|
|
62
|
+
write(
|
|
63
|
+
'child/source.mjs',
|
|
64
|
+
`import {defineTheme} from '@astryxdesign/core/theme';
|
|
65
|
+
import {baseTheme} from '../base/source.mjs';
|
|
66
|
+
import {icons} from './icons.mjs';
|
|
67
|
+
export default defineTheme({
|
|
68
|
+
name: 'child', extends: baseTheme, tokens: {}, icons,
|
|
69
|
+
});
|
|
70
|
+
`,
|
|
71
|
+
);
|
|
72
|
+
const child = await themeBuild('child/source.mjs', {}, {cwd: tmpDir});
|
|
73
|
+
expect(child?.type).toBe('theme.build');
|
|
74
|
+
|
|
75
|
+
write(
|
|
76
|
+
'grandchild.mjs',
|
|
77
|
+
`import {defineTheme} from '@astryxdesign/core/theme';
|
|
78
|
+
import {childTheme} from './child/child.js';
|
|
79
|
+
export default defineTheme({name: 'grandchild', extends: childTheme, tokens: {}});
|
|
80
|
+
`,
|
|
81
|
+
);
|
|
82
|
+
const grandchild = await themeBuild('grandchild.mjs', {}, {cwd: tmpDir});
|
|
83
|
+
expect(grandchild?.type).toBe('theme.build');
|
|
84
|
+
const checked = await themeBuild(
|
|
85
|
+
'grandchild.mjs',
|
|
86
|
+
{check: true},
|
|
87
|
+
{cwd: tmpDir},
|
|
88
|
+
);
|
|
89
|
+
expect(checked?.data.upToDate).toBe(true);
|
|
90
|
+
|
|
91
|
+
// Native imports catch invalid aliases and incorrect relative specifiers
|
|
92
|
+
// that the source loader could otherwise resolve or transform away.
|
|
93
|
+
execFileSync(
|
|
94
|
+
process.execPath,
|
|
95
|
+
[
|
|
96
|
+
'--input-type=module',
|
|
97
|
+
'--eval',
|
|
98
|
+
`import assert from 'node:assert/strict';
|
|
99
|
+
import {isValidElement} from 'react';
|
|
100
|
+
import {childTheme} from './child/child.js';
|
|
101
|
+
import {grandchildTheme} from './grandchild.js';
|
|
102
|
+
const expected = {check: 'base-check', close: 'child-close', add: 'child-add'};
|
|
103
|
+
assert.deepEqual(Object.keys(grandchildTheme.icons).sort(), Object.keys(expected).sort());
|
|
104
|
+
for (const [key, label] of Object.entries(expected)) {
|
|
105
|
+
const icon = grandchildTheme.icons[key];
|
|
106
|
+
assert.ok(isValidElement(icon), key + ' must remain a React element');
|
|
107
|
+
assert.equal(icon.type, 'svg');
|
|
108
|
+
assert.equal(icon.props['data-icon'], label);
|
|
109
|
+
assert.equal(icon, childTheme.icons[key], key + ' must retain its imported identity');
|
|
110
|
+
}`,
|
|
111
|
+
],
|
|
112
|
+
{cwd: tmpDir, stdio: 'pipe', timeout: 10000},
|
|
113
|
+
);
|
|
114
|
+
} finally {
|
|
115
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
116
|
+
}
|
|
117
|
+
});
|