@astryxdesign/cli 0.6.1 → 0.6.2-canary.2b2113d
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 +35 -1
- package/README.md +1 -1
- package/api/component/_adapter.mjs +64 -23
- package/api/component/component.doc.mjs +1 -1
- package/api/component/component.type.d.mts +8 -2
- package/api/component/component.type.mjs +5 -2
- package/api/component/integration-import-agreement.test.mjs +162 -6
- package/api/component/list/list.mjs +91 -15
- package/api/doctor/doctor.mjs +5 -16
- package/api/init/init.doc.mjs +2 -2
- package/api/init/init.type.d.mts +1 -1
- package/api/init/init.type.mjs +1 -1
- package/api/init/run/run.mjs +1 -1
- package/api/integration/add-helpers.mjs +2 -1
- package/api/integration/pack-check.mjs +9 -3
- package/api/search/search.d.mts +1 -1
- package/api/search/search.mjs +135 -41
- package/api/theme/build/build.d.mts +45 -17
- package/api/theme/build/build.family.test.mjs +435 -0
- package/api/theme/build/build.mjs +681 -121
- package/api/theme/build/build.packed-old-core.test.mjs +25 -9
- package/api/theme/build/build.test.mjs +142 -0
- package/api/theme/build/core-interception.d.mts +14 -2
- package/api/theme/build/core-interception.mjs +38 -14
- package/api/theme/build/family.d.mts +15 -0
- package/api/theme/build/family.mjs +442 -0
- package/api/theme/palette/generate/generate.mjs +2 -1
- package/assets/docs/theme.doc.dense.mjs +12 -0
- package/assets/docs/theme.doc.mjs +37 -0
- package/assets/docs/working-with-ai.doc.mjs +2 -1
- package/clients/cli/commands/build-theme.mjs +63 -5
- package/clients/cli/commands/component/index.mjs +4 -1
- package/clients/cli/commands/init.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +28 -10
- package/foundation/agent-docs/agent-doc-state.mjs +1 -1
- package/foundation/agent-docs/agent-docs.d.mts +2 -2
- package/foundation/agent-docs/agent-docs.mjs +8 -6
- package/foundation/agent-docs/agent-docs.test.mjs +14 -0
- package/foundation/discovery/__fixtures__/component-both-exports.doc.d.mts +24 -0
- package/foundation/discovery/__fixtures__/component-both-exports.doc.mjs +19 -0
- package/foundation/discovery/__fixtures__/component-default-export.doc.d.mts +14 -0
- package/foundation/discovery/__fixtures__/component-default-export.doc.mjs +13 -0
- package/foundation/discovery/__fixtures__/component-named-export.doc.d.mts +13 -0
- package/foundation/discovery/__fixtures__/component-named-export.doc.mjs +11 -0
- package/foundation/discovery/component-discovery.d.mts +5 -3
- package/foundation/discovery/component-discovery.mjs +25 -9
- package/foundation/discovery/component-loader.mjs +4 -1
- package/foundation/discovery/component-loader.test.mjs +48 -0
- package/foundation/discovery/theming-targets.test.mjs +29 -0
- package/foundation/fs/paths.d.mts +19 -0
- package/foundation/fs/paths.mjs +54 -0
- package/foundation/fs/paths.test.mjs +102 -1
- package/foundation/fs/publish-file-eperm-mutation.test.mjs +62 -0
- package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +107 -0
- package/foundation/fs/publish-file.d.mts +22 -0
- package/foundation/fs/publish-file.mjs +68 -0
- package/foundation/fs/publish-file.test.mjs +136 -0
- package/foundation/integrations/manifest-writer.mjs +2 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +15 -10
|
@@ -36,6 +36,8 @@ import * as os from 'node:os';
|
|
|
36
36
|
import * as path from 'node:path';
|
|
37
37
|
import {fileURLToPath} from 'node:url';
|
|
38
38
|
|
|
39
|
+
import {findInstalledPackage} from '../../../foundation/fs/paths.mjs';
|
|
40
|
+
|
|
39
41
|
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
40
42
|
const REPO_ROOT = path.resolve(HERE, '../../../../..');
|
|
41
43
|
const CLI_PKG = path.join(REPO_ROOT, 'packages/cli');
|
|
@@ -45,7 +47,13 @@ const CORE_THEME_ENTRY = path.join(CORE_DIST, 'theme/index.js');
|
|
|
45
47
|
/** The CLI's published file set (packages/cli package.json `files`). */
|
|
46
48
|
const PACKED_DIRS = ['clients', 'api', 'assets', 'authoring', 'foundation'];
|
|
47
49
|
/** Runtime dependencies the packed CLI resolves from its install root. */
|
|
48
|
-
const RUNTIME_DEPS = [
|
|
50
|
+
const RUNTIME_DEPS = [
|
|
51
|
+
'@babel/parser',
|
|
52
|
+
'commander',
|
|
53
|
+
'jiti',
|
|
54
|
+
'jscodeshift',
|
|
55
|
+
'zod',
|
|
56
|
+
];
|
|
49
57
|
|
|
50
58
|
const OLD_CORE_VERSION = '0.5.4';
|
|
51
59
|
const CURRENT_CORE_VERSION = '0.6.0';
|
|
@@ -260,7 +268,7 @@ ${options.tla ? `const surface = await Promise.resolve('#eee');\n` : ''}export c
|
|
|
260
268
|
}
|
|
261
269
|
|
|
262
270
|
/**
|
|
263
|
-
* @param {string} themeFile
|
|
271
|
+
* @param {string | string[]} themeFile
|
|
264
272
|
* @param {string[]} [extraArgs]
|
|
265
273
|
* @returns {{status: number, envelope: any}}
|
|
266
274
|
*/
|
|
@@ -270,11 +278,8 @@ function buildTheme(themeFile, extraArgs = []) {
|
|
|
270
278
|
'node_modules/@astryxdesign/cli/clients/cli/bin/astryx.mjs',
|
|
271
279
|
);
|
|
272
280
|
try {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
[bin, 'theme', 'build', themeFile, ...extraArgs, '--json'],
|
|
276
|
-
{cwd: consumer, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe']},
|
|
277
|
-
);
|
|
281
|
+
// prettier-ignore
|
|
282
|
+
const stdout = execFileSync(process.execPath, [bin, 'theme', 'build', ...(Array.isArray(themeFile) ? themeFile : [themeFile]), ...extraArgs, '--json'], {cwd: consumer, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe']});
|
|
278
283
|
return {status: 0, envelope: JSON.parse(stdout)};
|
|
279
284
|
} catch (error) {
|
|
280
285
|
const e = /** @type {any} */ (error);
|
|
@@ -425,9 +430,14 @@ beforeAll(() => {
|
|
|
425
430
|
);
|
|
426
431
|
|
|
427
432
|
// Its runtime dependencies, resolved from the install root like a real one.
|
|
433
|
+
// Found from the CLI package rather than the repo root: only a hoisted
|
|
434
|
+
// node_modules puts a package's own dependencies at the workspace root.
|
|
428
435
|
for (const dep of RUNTIME_DEPS) {
|
|
429
|
-
const
|
|
430
|
-
|
|
436
|
+
const installed = findInstalledPackage(CLI_PKG, dep);
|
|
437
|
+
if (!installed) throw new Error(`${dep} is not installed under ${CLI_PKG}`);
|
|
438
|
+
const target = path.join(modules, dep);
|
|
439
|
+
fs.mkdirSync(path.dirname(target), {recursive: true});
|
|
440
|
+
fs.symlinkSync(fs.realpathSync(installed), target);
|
|
431
441
|
}
|
|
432
442
|
|
|
433
443
|
// The installed core. Real built implementations behind a swappable
|
|
@@ -1083,6 +1093,12 @@ afterAll(() => {
|
|
|
1083
1093
|
describe('packed CLI against a core that predates adaptations', () => {
|
|
1084
1094
|
beforeAll(() => useCore('old'));
|
|
1085
1095
|
|
|
1096
|
+
it('rejects a family before an old core can erase adaptations', () => {
|
|
1097
|
+
// prettier-ignore
|
|
1098
|
+
const result = buildTheme(['adaptive-base.ts', 'extending.ts'], ['--family', '--family-key', 'adaptive-family']);
|
|
1099
|
+
expect(result.envelope.code).toBe('ERR_CORE_INCOMPATIBLE');
|
|
1100
|
+
});
|
|
1101
|
+
|
|
1086
1102
|
it('builds a non-adaptation theme', () => {
|
|
1087
1103
|
const {status, envelope} = buildTheme('plain.ts');
|
|
1088
1104
|
|
|
@@ -704,3 +704,145 @@ describe('themeBuild() — extends', () => {
|
|
|
704
704
|
).rejects.toThrow(/extends/);
|
|
705
705
|
});
|
|
706
706
|
});
|
|
707
|
+
|
|
708
|
+
// =============================================================================
|
|
709
|
+
// Theme name → valid JS identifier contract (deterministic from theme.name)
|
|
710
|
+
// =============================================================================
|
|
711
|
+
|
|
712
|
+
describe('themeBuild() — theme name identifier sanitization', () => {
|
|
713
|
+
/**
|
|
714
|
+
* Write a theme source with a given theme name and return the generated JS
|
|
715
|
+
* and declarations. The identifier is derived only from theme.name.
|
|
716
|
+
*/
|
|
717
|
+
async function buildNamed(themeName) {
|
|
718
|
+
const themeFile = path.join(
|
|
719
|
+
tmpDir,
|
|
720
|
+
`src-${themeName.replace(/[^a-z0-9]/gi, '')}.mjs`,
|
|
721
|
+
);
|
|
722
|
+
// Use a default export so no source export name is available — the
|
|
723
|
+
// identifier must come purely from toIdentifier(themeName) + 'Theme'.
|
|
724
|
+
fs.writeFileSync(
|
|
725
|
+
themeFile,
|
|
726
|
+
`export default { name: '${themeName}', tokens: { '--color-bg': '#000' } };\n`,
|
|
727
|
+
);
|
|
728
|
+
await themeBuild(path.basename(themeFile), {}, {cwd: tmpDir});
|
|
729
|
+
const js = fs.readFileSync(path.join(tmpDir, `${themeName}.js`), 'utf8');
|
|
730
|
+
const dts = fs.readFileSync(path.join(tmpDir, `${themeName}.d.ts`), 'utf8');
|
|
731
|
+
return {js, dts};
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// -- Core bug: hyphen followed by digit -----------------------------------
|
|
735
|
+
|
|
736
|
+
it('chaos-07 → chaos07Theme (the motivating bug)', async () => {
|
|
737
|
+
const {js, dts} = await buildNamed('chaos-07');
|
|
738
|
+
expect(js).toContain('export const chaos07Theme = {');
|
|
739
|
+
expect(js).not.toMatch(/export const chaos-07/);
|
|
740
|
+
expect(dts).toContain('export declare const chaos07Theme: DefinedTheme;');
|
|
741
|
+
// Must parse as valid JS
|
|
742
|
+
expect(() => new Function(js.replace(/^export /gm, ''))).not.toThrow();
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
// -- Dot separator --------------------------------------------------------
|
|
746
|
+
|
|
747
|
+
it('brand.v2 → brandV2Theme', async () => {
|
|
748
|
+
const {js, dts} = await buildNamed('brand.v2');
|
|
749
|
+
expect(js).toContain('export const brandV2Theme = {');
|
|
750
|
+
expect(dts).toContain('export declare const brandV2Theme: DefinedTheme;');
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
it('ui.dark.3 → uiDark3Theme', async () => {
|
|
754
|
+
const {js, dts} = await buildNamed('ui.dark.3');
|
|
755
|
+
expect(js).toContain('export const uiDark3Theme = {');
|
|
756
|
+
expect(dts).toContain('export declare const uiDark3Theme: DefinedTheme;');
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
// -- Underscore preserved (already valid) ---------------------------------
|
|
760
|
+
|
|
761
|
+
it('my_theme → my_themeTheme (underscore preserved)', async () => {
|
|
762
|
+
const {js, dts} = await buildNamed('my_theme');
|
|
763
|
+
expect(js).toContain('export const my_themeTheme = {');
|
|
764
|
+
expect(dts).toContain('export declare const my_themeTheme: DefinedTheme;');
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
// -- Mixed separators -----------------------------------------------------
|
|
768
|
+
|
|
769
|
+
it('neo_wave-2.x → neo_wave2XTheme (underscore kept, others camelCased)', async () => {
|
|
770
|
+
const {js, dts} = await buildNamed('neo_wave-2.x');
|
|
771
|
+
expect(js).toContain('export const neo_wave2XTheme = {');
|
|
772
|
+
expect(dts).toContain(
|
|
773
|
+
'export declare const neo_wave2XTheme: DefinedTheme;',
|
|
774
|
+
);
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
// -- Multiple and consecutive separators ----------------------------------
|
|
778
|
+
|
|
779
|
+
it('a-1-b → a1BTheme', async () => {
|
|
780
|
+
const {js, dts} = await buildNamed('a-1-b');
|
|
781
|
+
expect(js).toContain('export const a1BTheme = {');
|
|
782
|
+
expect(dts).toContain('export declare const a1BTheme: DefinedTheme;');
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
it('my--theme → myThemeTheme (consecutive hyphens)', async () => {
|
|
786
|
+
const {js, dts} = await buildNamed('my--theme');
|
|
787
|
+
expect(js).toContain('export const myThemeTheme = {');
|
|
788
|
+
expect(dts).toContain('export declare const myThemeTheme: DefinedTheme;');
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
it('trailing- → trailingTheme (trailing separator stripped)', async () => {
|
|
792
|
+
const {js, dts} = await buildNamed('trailing-');
|
|
793
|
+
expect(js).toContain('export const trailingTheme = {');
|
|
794
|
+
expect(dts).toContain('export declare const trailingTheme: DefinedTheme;');
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
it('neon-green-42 → neonGreen42Theme', async () => {
|
|
798
|
+
const {js, dts} = await buildNamed('neon-green-42');
|
|
799
|
+
expect(js).toContain('export const neonGreen42Theme = {');
|
|
800
|
+
expect(dts).toContain(
|
|
801
|
+
'export declare const neonGreen42Theme: DefinedTheme;',
|
|
802
|
+
);
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
// -- JS and d.ts agree on every case --------------------------------------
|
|
806
|
+
|
|
807
|
+
it('JS, d.ts, and install example agree', async () => {
|
|
808
|
+
const {js, dts} = await buildNamed('dark-v2');
|
|
809
|
+
const jsMatch = js.match(/export const (\w+) = \{/);
|
|
810
|
+
const dtsMatch = dts.match(/export declare const (\w+): DefinedTheme;/);
|
|
811
|
+
expect(jsMatch?.[1]).toBe('darkV2Theme');
|
|
812
|
+
expect(dtsMatch?.[1]).toBe('darkV2Theme');
|
|
813
|
+
// Import example in JSDoc
|
|
814
|
+
expect(js).toContain("import { darkV2Theme } from './dark-v2'");
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
// -- Check mode -----------------------------------------------------------
|
|
818
|
+
|
|
819
|
+
it('check mode agrees with the deterministic identifier', async () => {
|
|
820
|
+
await buildNamed('wave-99');
|
|
821
|
+
// Source file was written by buildNamed; re-run in check mode
|
|
822
|
+
const checkResult = await themeBuild(
|
|
823
|
+
path.basename(
|
|
824
|
+
fs.readdirSync(tmpDir).find(f => f.startsWith('src-wave99')),
|
|
825
|
+
),
|
|
826
|
+
{check: true},
|
|
827
|
+
{cwd: tmpDir},
|
|
828
|
+
);
|
|
829
|
+
expect(checkResult?.data.upToDate).toBe(true);
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
// -- Reserved words are safe via the Theme suffix -------------------------
|
|
833
|
+
|
|
834
|
+
it('reserved word "for" → forTheme (safe)', async () => {
|
|
835
|
+
const {js, dts} = await buildNamed('for');
|
|
836
|
+
expect(js).toContain('export const forTheme = {');
|
|
837
|
+
expect(dts).toContain('export declare const forTheme: DefinedTheme;');
|
|
838
|
+
expect(() => new Function(js.replace(/^export /gm, ''))).not.toThrow();
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
// -- Simple name (no separators) is unchanged -----------------------------
|
|
842
|
+
|
|
843
|
+
it('ocean → oceanTheme (no-op sanitization)', async () => {
|
|
844
|
+
const {js, dts} = await buildNamed('ocean');
|
|
845
|
+
expect(js).toContain('export const oceanTheme = {');
|
|
846
|
+
expect(dts).toContain('export declare const oceanTheme: DefinedTheme;');
|
|
847
|
+
});
|
|
848
|
+
});
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* silently delete every one of those exports from a theme file that imports a
|
|
13
13
|
* component. Every real export is preserved on each; one function is wrapped.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* Current-Core family builds also use this private recorder for exact parents;
|
|
16
|
+
* standalone builds with current Core do not.
|
|
17
17
|
*
|
|
18
18
|
* @param {any} coreThemeModule - The installed `@astryxdesign/core/theme` namespace.
|
|
19
19
|
* @param {any} [coreRootModule] - The installed `@astryxdesign/core` namespace.
|
|
@@ -44,6 +44,18 @@ export type CoreInterception = {
|
|
|
44
44
|
* - `virtualModules` for jiti.
|
|
45
45
|
*/
|
|
46
46
|
modules: Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* - Whether authored input was captured.
|
|
49
|
+
*/
|
|
50
|
+
observed: (theme: any) => boolean;
|
|
51
|
+
/**
|
|
52
|
+
* - Retain capture before stripping.
|
|
53
|
+
*/
|
|
54
|
+
retain: (theme: any) => void;
|
|
55
|
+
/**
|
|
56
|
+
* - Exact authored `extends` value.
|
|
57
|
+
*/
|
|
58
|
+
parentOf: (theme: any) => any;
|
|
47
59
|
/**
|
|
48
60
|
* - Every raw input that fed a
|
|
49
61
|
* theme, following its own `extends` chain and spread provenance.
|
|
@@ -68,6 +68,9 @@
|
|
|
68
68
|
*/
|
|
69
69
|
|
|
70
70
|
import {createRequire} from 'node:module';
|
|
71
|
+
import * as path from 'node:path';
|
|
72
|
+
|
|
73
|
+
import {findInstalledPackage} from '../../../foundation/fs/paths.mjs';
|
|
71
74
|
|
|
72
75
|
/**
|
|
73
76
|
* Marks a theme object with the raw input it was resolved from. Enumerable on
|
|
@@ -76,6 +79,8 @@ import {createRequire} from 'node:module';
|
|
|
76
79
|
*/
|
|
77
80
|
export const THEME_LINEAGE = Symbol.for('astryx.theme.lineage');
|
|
78
81
|
|
|
82
|
+
/** Complete private capture retained for cached exports and repeated checks. */
|
|
83
|
+
const retainedLineageByReference = new WeakMap();
|
|
79
84
|
/**
|
|
80
85
|
* @typedef {object} ThemeLineage
|
|
81
86
|
* @property {any} input - The raw `defineTheme()` argument.
|
|
@@ -87,6 +92,9 @@ export const THEME_LINEAGE = Symbol.for('astryx.theme.lineage');
|
|
|
87
92
|
*
|
|
88
93
|
* @typedef {object} CoreInterception
|
|
89
94
|
* @property {Record<string, unknown>} modules - `virtualModules` for jiti.
|
|
95
|
+
* @property {(theme: any) => boolean} observed - Whether authored input was captured.
|
|
96
|
+
* @property {(theme: any) => void} retain - Retain capture before stripping.
|
|
97
|
+
* @property {(theme: any) => any} parentOf - Exact authored `extends` value.
|
|
90
98
|
* @property {(theme: any) => any[]} lineageOf - Every raw input that fed a
|
|
91
99
|
* theme, following its own `extends` chain and spread provenance.
|
|
92
100
|
* @property {(theme: any) => any[]} unobservedIn - Lineage members this
|
|
@@ -102,17 +110,16 @@ export const THEME_LINEAGE = Symbol.for('astryx.theme.lineage');
|
|
|
102
110
|
*/
|
|
103
111
|
|
|
104
112
|
/**
|
|
105
|
-
* Was this theme produced by a `defineTheme()` call the recorder saw?
|
|
106
|
-
*
|
|
113
|
+
* Was this theme produced by a `defineTheme()` call the recorder saw? The
|
|
114
|
+
* temporary symbol must be read before `strip`; retained WeakMap capture remains
|
|
115
|
+
* available for cached retries.
|
|
107
116
|
*
|
|
108
117
|
* @param {any} value
|
|
109
118
|
* @param {WeakMap<object, ThemeLineage>} byReference
|
|
110
119
|
* @returns {boolean}
|
|
111
120
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return byReference.has(value) || value[THEME_LINEAGE] !== undefined;
|
|
115
|
-
}
|
|
121
|
+
// prettier-ignore
|
|
122
|
+
function wasObserved(value, byReference) { return Boolean(value && typeof value === 'object' && (byReference.has(value) || retainedLineageByReference.has(value) || value[THEME_LINEAGE] !== undefined)); }
|
|
116
123
|
|
|
117
124
|
const GENERATIVE_AXIS_KEYS = ['typography', 'color', 'radius', 'motion'];
|
|
118
125
|
|
|
@@ -225,8 +232,8 @@ function mergeGenerativeAxes(inherited, own) {
|
|
|
225
232
|
* silently delete every one of those exports from a theme file that imports a
|
|
226
233
|
* component. Every real export is preserved on each; one function is wrapped.
|
|
227
234
|
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
235
|
+
* Current-Core family builds also use this private recorder for exact parents;
|
|
236
|
+
* standalone builds with current Core do not.
|
|
230
237
|
*
|
|
231
238
|
* @param {any} coreThemeModule - The installed `@astryxdesign/core/theme` namespace.
|
|
232
239
|
* @param {any} [coreRootModule] - The installed `@astryxdesign/core` namespace.
|
|
@@ -240,6 +247,7 @@ export function interceptCore(coreThemeModule, coreRootModule) {
|
|
|
240
247
|
const mark = (value, lineage) => {
|
|
241
248
|
if (!value || typeof value !== 'object') return;
|
|
242
249
|
byReference.set(value, lineage);
|
|
250
|
+
retainedLineageByReference.set(value, lineage);
|
|
243
251
|
try {
|
|
244
252
|
// Enumerable so a spread of this theme carries it; configurable so it
|
|
245
253
|
// can be removed again before the theme is used for output.
|
|
@@ -255,10 +263,8 @@ export function interceptCore(coreThemeModule, coreRootModule) {
|
|
|
255
263
|
};
|
|
256
264
|
|
|
257
265
|
/** @param {any} value @returns {ThemeLineage | undefined} */
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return byReference.get(value) ?? value[THEME_LINEAGE];
|
|
261
|
-
};
|
|
266
|
+
// prettier-ignore
|
|
267
|
+
const lineageFor = value => value && typeof value === 'object' ? byReference.get(value) ?? retainedLineageByReference.get(value) ?? value[THEME_LINEAGE] : undefined;
|
|
262
268
|
|
|
263
269
|
/**
|
|
264
270
|
* One namespace, spread so exports this file does not know about still
|
|
@@ -290,6 +296,12 @@ export function interceptCore(coreThemeModule, coreRootModule) {
|
|
|
290
296
|
'@astryxdesign/core': wrapNamespace(coreRootModule ?? coreThemeModule),
|
|
291
297
|
},
|
|
292
298
|
|
|
299
|
+
// prettier-ignore
|
|
300
|
+
observed(theme) { return wasObserved(theme, byReference); },
|
|
301
|
+
// prettier-ignore
|
|
302
|
+
retain(theme) { const lineage = lineageFor(theme); if (lineage && theme && typeof theme === 'object') retainedLineageByReference.set(theme, lineage); },
|
|
303
|
+
// prettier-ignore
|
|
304
|
+
parentOf(theme) { const input = lineageFor(theme)?.input; return input && typeof input === 'object' && 'extends' in input ? input.extends : theme && typeof theme === 'object' ? theme.extends : undefined; },
|
|
293
305
|
lineageOf(theme) {
|
|
294
306
|
/** @type {any[]} */
|
|
295
307
|
const inputs = [];
|
|
@@ -324,8 +336,8 @@ export function interceptCore(coreThemeModule, coreRootModule) {
|
|
|
324
336
|
unobservedIn(theme) {
|
|
325
337
|
// Lineage members this recorder never saw AND that carry no adaptation
|
|
326
338
|
// metadata of their own. On a degraded load these are exactly the
|
|
327
|
-
// themes whose adaptations, if any, were erased unobserved.
|
|
328
|
-
//
|
|
339
|
+
// themes whose adaptations, if any, were erased unobserved. Retained
|
|
340
|
+
// WeakMap capture keeps this answer stable after a cached retry.
|
|
329
341
|
//
|
|
330
342
|
// A RAW INPUT reached through an observed result is itself evidence —
|
|
331
343
|
// it is the very object the recorder captured, and only the result
|
|
@@ -401,6 +413,7 @@ export function interceptCore(coreThemeModule, coreRootModule) {
|
|
|
401
413
|
if (!value || typeof value !== 'object' || seen.has(value)) continue;
|
|
402
414
|
seen.add(value);
|
|
403
415
|
const lineage = lineageFor(value);
|
|
416
|
+
if (lineage) retainedLineageByReference.set(value, lineage);
|
|
404
417
|
if (Object.hasOwn(value, THEME_LINEAGE)) {
|
|
405
418
|
try {
|
|
406
419
|
delete value[THEME_LINEAGE];
|
|
@@ -427,6 +440,17 @@ export function interceptCore(coreThemeModule, coreRootModule) {
|
|
|
427
440
|
/** @type {Array<() => void>} */
|
|
428
441
|
const undo = [];
|
|
429
442
|
let covered = true;
|
|
443
|
+
|
|
444
|
+
// Only a core the theme's OWN node_modules chain can reach is one a
|
|
445
|
+
// `.cjs` source dependency beside it could require. `require` also folds
|
|
446
|
+
// NODE_PATH in, and pnpm's isolated layout puts every package in
|
|
447
|
+
// `node_modules/.pnpm/node_modules` — which Vitest puts on NODE_PATH.
|
|
448
|
+
// An ambient hit there belongs to no dependency here, so wrapping it
|
|
449
|
+
// proves nothing and failing to wrap it gaps nothing.
|
|
450
|
+
if (!findInstalledPackage(path.dirname(fromFile), '@astryxdesign/core')) {
|
|
451
|
+
return {covered, undo: () => {}};
|
|
452
|
+
}
|
|
453
|
+
|
|
430
454
|
for (const specifier of [
|
|
431
455
|
'@astryxdesign/core/theme',
|
|
432
456
|
'@astryxdesign/core',
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {Array<{theme: any, sourceTheme: any, sourceParent: any, filePath: string}>} members
|
|
6
|
+
* @returns {any[]}
|
|
7
|
+
*/
|
|
8
|
+
export function resolveThemeFamily(members: Array<{
|
|
9
|
+
theme: any;
|
|
10
|
+
sourceTheme: any;
|
|
11
|
+
sourceParent: any;
|
|
12
|
+
filePath: string;
|
|
13
|
+
}>): any[];
|
|
14
|
+
/** @param {any[]} members */
|
|
15
|
+
export function generateFamilyCSS(members: any[]): string;
|