@astryxdesign/cli 0.7.3-canary.b74cf21 → 0.7.3-canary.e9694dc
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/integration/pack-check.mjs +110 -4
- package/api/integration/pack-check.test.mjs +69 -0
- package/api/integration/validate-integration-gaps.test.mjs +292 -0
- package/api/integration/validate-integration.mjs +4 -1
- package/api/integration/validate-integration.type.d.mts +1 -0
- package/api/integration/validate-integration.type.mjs +1 -0
- package/assets/docs/is-my-code-good.doc.mjs +287 -0
- package/assets/docs/tree/template-grading-rubric.doc.mjs +16 -37
- package/foundation/config/project.test.mjs +26 -0
- package/foundation/discovery/template-adapter.mjs +18 -1
- package/foundation/discovery/theme-discovery.mjs +147 -3
- package/foundation/doc-compiler/read.mjs +59 -1
- package/foundation/doc-compiler/read.test.mjs +11 -2
- package/foundation/integrations/integrations.d.mts +9 -1
- package/foundation/integrations/integrations.mjs +38 -1
- package/foundation/integrations/validate-contributions.d.mts +19 -0
- package/foundation/integrations/validate-contributions.mjs +172 -3
- package/package.json +9 -9
|
@@ -26,7 +26,11 @@ import {fileURLToPath} from 'node:url';
|
|
|
26
26
|
import {spawnSync} from 'node:child_process';
|
|
27
27
|
import {assertWithin} from '../../foundation/fs/path-safety.mjs';
|
|
28
28
|
import {resolvePackageDir} from '../../foundation/integrations/integrations.mjs';
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
literalThemeName,
|
|
31
|
+
rootProblem,
|
|
32
|
+
symlinkedFolder,
|
|
33
|
+
} from '../../foundation/integrations/validate-contributions.mjs';
|
|
30
34
|
import {
|
|
31
35
|
componentReplacesCliProblem,
|
|
32
36
|
docsTreeCliProblem,
|
|
@@ -954,6 +958,10 @@ async function validatePackedThemeExports(
|
|
|
954
958
|
);
|
|
955
959
|
}
|
|
956
960
|
|
|
961
|
+
// The name the source gives defineTheme, when the file says it: the
|
|
962
|
+
// build names its files after it.
|
|
963
|
+
const builtName = literalThemeName(source, localTheme.exportName);
|
|
964
|
+
|
|
957
965
|
const declaredOutputs = declaredThemeBuildOutputs(
|
|
958
966
|
localIntegration,
|
|
959
967
|
localTheme,
|
|
@@ -1098,7 +1106,15 @@ async function validatePackedThemeExports(
|
|
|
1098
1106
|
? `Theme "${localTheme.slug}" module is not the module \`${formatCliCommand(`theme build ${sourceRelative}`, localIntegration.__packageDir)}\` writes and does not only wrap it: ${localWrapper.reason}. A module that wraps the built module may only import the theme's own stylesheet and font stylesheet for their side effects and re-export from the built module either everything or only its theme, as ${localTheme.exportName}.`
|
|
1099
1107
|
: localWrapper && !localWrapper.ok
|
|
1100
1108
|
? `Theme "${localTheme.slug}" module re-exports ${localWrapper.reason}, which does not match ${sourceRelative}. Run \`${formatCliCommand(`theme build ${sourceRelative}`, localIntegration.__packageDir)}\` before packing.`
|
|
1101
|
-
:
|
|
1109
|
+
: (renamedOutputMessage(
|
|
1110
|
+
localTheme,
|
|
1111
|
+
output.kind,
|
|
1112
|
+
output.local,
|
|
1113
|
+
source,
|
|
1114
|
+
builtName,
|
|
1115
|
+
localIntegration.__packageDir,
|
|
1116
|
+
) ??
|
|
1117
|
+
`Theme "${localTheme.slug}" ${output.kind} does not match ${sourceRelative}. Run \`${formatCliCommand(`theme build ${sourceRelative}`, localIntegration.__packageDir)}\` before packing.`),
|
|
1102
1118
|
),
|
|
1103
1119
|
);
|
|
1104
1120
|
}
|
|
@@ -1416,6 +1432,9 @@ export async function integrationPackCheck(options = {}) {
|
|
|
1416
1432
|
);
|
|
1417
1433
|
/** @type {string|null} */
|
|
1418
1434
|
let scratchBase = null;
|
|
1435
|
+
/** @type {string|undefined} the packed copy of the package */
|
|
1436
|
+
let extractDir;
|
|
1437
|
+
const issuesBeforePack = issues.length;
|
|
1419
1438
|
|
|
1420
1439
|
try {
|
|
1421
1440
|
// npm pack
|
|
@@ -1464,11 +1483,16 @@ export async function integrationPackCheck(options = {}) {
|
|
|
1464
1483
|
for (const root of fileInv.roots) {
|
|
1465
1484
|
const missing = root.files.filter(f => !packResult.packedPaths.has(f));
|
|
1466
1485
|
if (missing.length === root.files.length && root.files.length > 0) {
|
|
1486
|
+
const absolute = /** @type {string} */ (loaded[root.kind]);
|
|
1487
|
+
const link = symlinkedFolder(absolute, packageDir);
|
|
1467
1488
|
issues.push(
|
|
1468
1489
|
error(
|
|
1469
1490
|
'root_not_packed',
|
|
1470
1491
|
`Declared ${root.kind} root "${root.path}" has 0 of ${root.files.length} expected ` +
|
|
1471
|
-
`files in the pack list.
|
|
1492
|
+
`files in the pack list. ` +
|
|
1493
|
+
(link
|
|
1494
|
+
? `It is reached through the symlink "${path.relative(packageDir, link.path).split(path.sep).join('/')}", and npm pack does not follow a symlinked folder. Fix: replace the link with the folder itself, or point "${root.kind}" at the folder it links to.`
|
|
1495
|
+
: `Add "${root.path.replace(/^\.\//, '')}" to "files" in package.json.`),
|
|
1472
1496
|
),
|
|
1473
1497
|
);
|
|
1474
1498
|
} else {
|
|
@@ -1507,7 +1531,6 @@ export async function integrationPackCheck(options = {}) {
|
|
|
1507
1531
|
}
|
|
1508
1532
|
|
|
1509
1533
|
// ── Phase 3: extract + identity comparison ──
|
|
1510
|
-
let extractDir;
|
|
1511
1534
|
try {
|
|
1512
1535
|
extractDir = resolvePackageDir(pkgName, scratchBase);
|
|
1513
1536
|
} catch (err) {
|
|
@@ -1629,11 +1652,94 @@ export async function integrationPackCheck(options = {}) {
|
|
|
1629
1652
|
issues,
|
|
1630
1653
|
);
|
|
1631
1654
|
} finally {
|
|
1655
|
+
// The packed copy lives in a scratch folder that is gone once this
|
|
1656
|
+
// returns: name its files the way the package does.
|
|
1657
|
+
if (extractDir && scratchBase) {
|
|
1658
|
+
packageRelative(issues.slice(issuesBeforePack), extractDir, scratchBase);
|
|
1659
|
+
}
|
|
1632
1660
|
removeTreeBestEffort(tgzTmpDir, 'temporary tarball directory', issues);
|
|
1633
1661
|
removeTreeBestEffort(scratchBase, 'scratch consumer', issues);
|
|
1634
1662
|
}
|
|
1635
1663
|
}
|
|
1636
1664
|
|
|
1665
|
+
/**
|
|
1666
|
+
* When a theme's source names it something other than the file the package
|
|
1667
|
+
* exports for it, a rebuild writes new files under that name and leaves the
|
|
1668
|
+
* exported one stale forever: say so, with both ways out. Null otherwise.
|
|
1669
|
+
* @param {{slug: string}} theme
|
|
1670
|
+
* @param {string} kind 'module' or 'stylesheet'
|
|
1671
|
+
* @param {string} exported the file the package exports for it
|
|
1672
|
+
* @param {string} source the theme's source
|
|
1673
|
+
* @param {string | null} builtName the literal defineTheme name, if any
|
|
1674
|
+
* @param {string} packageDir
|
|
1675
|
+
* @returns {string | null}
|
|
1676
|
+
*/
|
|
1677
|
+
function renamedOutputMessage(
|
|
1678
|
+
theme,
|
|
1679
|
+
kind,
|
|
1680
|
+
exported,
|
|
1681
|
+
source,
|
|
1682
|
+
builtName,
|
|
1683
|
+
packageDir,
|
|
1684
|
+
) {
|
|
1685
|
+
if (builtName == null || builtName === theme.slug) return null;
|
|
1686
|
+
const extension = kind === 'module' ? '.js' : '.css';
|
|
1687
|
+
if (path.basename(exported) === `${builtName}${extension}`) return null;
|
|
1688
|
+
const rel = (/** @type {string} */ file) =>
|
|
1689
|
+
path.relative(packageDir, file).split(path.sep).join('/');
|
|
1690
|
+
const built = rel(
|
|
1691
|
+
path.join(path.dirname(source), `${builtName}${extension}`),
|
|
1692
|
+
);
|
|
1693
|
+
return `Theme "${theme.slug}" ${kind} is ${rel(exported)}, but ${path.basename(source)} calls defineTheme with name: '${builtName}', so \`${formatCliCommand(`theme build ${rel(source)}`, packageDir)}\` writes ${built} instead and rebuilding never updates ${path.basename(exported)}. Fix: point the package export that serves it at ${built} after building, or set name: '${theme.slug}' in ${path.basename(source)} and rebuild.`;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
/**
|
|
1697
|
+
* Rewrite the scratch copy's absolute paths in each issue's message: a file
|
|
1698
|
+
* of the packed package as its path in the package, and any other path in the
|
|
1699
|
+
* scratch consumer (such as the module that resolved an import) as that
|
|
1700
|
+
* consumer. Both folders are gone once verify returns.
|
|
1701
|
+
* @param {Issue[]} issues
|
|
1702
|
+
* @param {string} packedDir the packed package inside the scratch consumer
|
|
1703
|
+
* @param {string} consumerDir the scratch consumer
|
|
1704
|
+
*/
|
|
1705
|
+
function packageRelative(issues, packedDir, consumerDir) {
|
|
1706
|
+
/** @param {string} dir */
|
|
1707
|
+
const spellings = dir => {
|
|
1708
|
+
const out = [dir];
|
|
1709
|
+
try {
|
|
1710
|
+
const real = fs.realpathSync(dir);
|
|
1711
|
+
if (real !== dir) out.push(real);
|
|
1712
|
+
} catch {
|
|
1713
|
+
// Already removed: the plain path is all there is.
|
|
1714
|
+
}
|
|
1715
|
+
return out;
|
|
1716
|
+
};
|
|
1717
|
+
/** @param {string} text */
|
|
1718
|
+
const escape = text => text.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
1719
|
+
const packed = spellings(packedDir);
|
|
1720
|
+
const consumer = spellings(consumerDir);
|
|
1721
|
+
for (const issue of issues) {
|
|
1722
|
+
if (typeof issue.message !== 'string') continue;
|
|
1723
|
+
let message = issue.message;
|
|
1724
|
+
for (const prefix of packed) {
|
|
1725
|
+
message = message
|
|
1726
|
+
.split(`${prefix}${path.sep}`)
|
|
1727
|
+
.join('')
|
|
1728
|
+
.replace(
|
|
1729
|
+
new RegExp(`${escape(prefix)}(?![\\w-]|\\.\\w)`, 'gu'),
|
|
1730
|
+
'the package root',
|
|
1731
|
+
);
|
|
1732
|
+
}
|
|
1733
|
+
for (const prefix of consumer) {
|
|
1734
|
+
message = message.replace(
|
|
1735
|
+
new RegExp(`${escape(prefix)}[^\\s"'\`]*`, 'gu'),
|
|
1736
|
+
'a consumer project',
|
|
1737
|
+
);
|
|
1738
|
+
}
|
|
1739
|
+
issue.message = message;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1637
1743
|
/**
|
|
1638
1744
|
* Assemble the receipt.
|
|
1639
1745
|
* @param {string} name
|
|
@@ -580,6 +580,24 @@ describe('a theme module that loads its own styles', () => {
|
|
|
580
580
|
expect(cli.status, cli.stderr).toBe(0);
|
|
581
581
|
});
|
|
582
582
|
|
|
583
|
+
it('says a rebuild cannot fix exports that name the theme after its folder once its source renames it', async () => {
|
|
584
|
+
writePackage({
|
|
585
|
+
files: ['astryx.integration.mjs', 'themes'],
|
|
586
|
+
themeExports: true,
|
|
587
|
+
});
|
|
588
|
+
fs.writeFileSync(
|
|
589
|
+
path.join(tmpDir, 'themes', 'ocean', 'oceanTheme.ts'),
|
|
590
|
+
"import {defineTheme} from '@astryxdesign/core/theme';\n\nexport const oceanTheme = defineTheme({name: 'sea'});\n",
|
|
591
|
+
);
|
|
592
|
+
|
|
593
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
594
|
+
|
|
595
|
+
expect(result.data.issues.map(issue => issue.message)).toEqual([
|
|
596
|
+
`Theme "ocean" module is themes/ocean/ocean.js, but oceanTheme.ts calls defineTheme with name: 'sea', so \`${formatCliCommand('theme build themes/ocean/oceanTheme.ts', tmpDir)}\` writes themes/ocean/sea.js instead and rebuilding never updates ocean.js. Fix: point the package export that serves it at themes/ocean/sea.js after building, or set name: 'ocean' in oceanTheme.ts and rebuild.`,
|
|
597
|
+
`Theme "ocean" stylesheet is themes/ocean/ocean.css, but oceanTheme.ts calls defineTheme with name: 'sea', so \`${formatCliCommand('theme build themes/ocean/oceanTheme.ts', tmpDir)}\` writes themes/ocean/sea.css instead and rebuilding never updates ocean.css. Fix: point the package export that serves it at themes/ocean/sea.css after building, or set name: 'ocean' in oceanTheme.ts and rebuild.`,
|
|
598
|
+
]);
|
|
599
|
+
});
|
|
600
|
+
|
|
583
601
|
it('compares a partial export set with the module named after the theme', async () => {
|
|
584
602
|
writeRenamedOcean();
|
|
585
603
|
setThemeExports({'./themes/ocean': './themes/ocean/deep-sea.js'});
|
|
@@ -1919,6 +1937,57 @@ describe('integrationPackCheck', () => {
|
|
|
1919
1937
|
expect(sourceWarnings[0].message).toContain('stray.tsx');
|
|
1920
1938
|
});
|
|
1921
1939
|
|
|
1940
|
+
it('says npm pack skips a symlinked root instead of asking for a "files" entry', async () => {
|
|
1941
|
+
writePackage({
|
|
1942
|
+
manifest:
|
|
1943
|
+
"export default {themes: './themes', components: './components'};\n",
|
|
1944
|
+
});
|
|
1945
|
+
const real = path.join(tmpDir, 'real-components');
|
|
1946
|
+
fs.mkdirSync(real, {recursive: true});
|
|
1947
|
+
fs.writeFileSync(
|
|
1948
|
+
path.join(real, 'Card.doc.mjs'),
|
|
1949
|
+
"export default {type: 'component', name: 'Card', displayName: 'Card', usage: {description: 'Card.'}, props: []};\n",
|
|
1950
|
+
);
|
|
1951
|
+
fs.writeFileSync(
|
|
1952
|
+
path.join(real, 'Card.tsx'),
|
|
1953
|
+
'export function Card() { return null; }\n',
|
|
1954
|
+
);
|
|
1955
|
+
fs.symlinkSync('real-components', path.join(tmpDir, 'components'));
|
|
1956
|
+
|
|
1957
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
1958
|
+
const codes = result.data.issues.map(issue => issue.code);
|
|
1959
|
+
expect(codes).toContain('symlinked_root');
|
|
1960
|
+
const notPacked = result.data.issues.find(
|
|
1961
|
+
issue => issue.code === 'root_not_packed',
|
|
1962
|
+
);
|
|
1963
|
+
expect(notPacked?.message).toBe(
|
|
1964
|
+
'Declared components root "components" has 0 of 2 expected files in the pack list. It is reached through the symlink "components", and npm pack does not follow a symlinked folder. Fix: replace the link with the folder itself, or point "components" at the folder it links to.',
|
|
1965
|
+
);
|
|
1966
|
+
});
|
|
1967
|
+
|
|
1968
|
+
it('names packed files by their path in the package, never the scratch copy', async () => {
|
|
1969
|
+
writePackage({
|
|
1970
|
+
manifest:
|
|
1971
|
+
"export default {themes: './themes', docs: './docs/a.doc.mjs'};\n",
|
|
1972
|
+
});
|
|
1973
|
+
fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
|
|
1974
|
+
fs.writeFileSync(path.join(tmpDir, 'docs', 'a.doc.mjs'), '');
|
|
1975
|
+
|
|
1976
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
1977
|
+
const messages = result.data.issues.map(issue => issue.message);
|
|
1978
|
+
expect(messages.join('\n')).not.toContain(
|
|
1979
|
+
path.join(tmpDir, '.astryx-pack-check-'),
|
|
1980
|
+
);
|
|
1981
|
+
expect(messages).toContain(
|
|
1982
|
+
'Packed: Declared docs root is a file, not a folder: docs/a.doc.mjs. Fix: point "docs" in the manifest at the folder that holds them.',
|
|
1983
|
+
);
|
|
1984
|
+
// The root's own issue covers it: no empty-root error, no raw errno.
|
|
1985
|
+
const codes = result.data.issues.map(issue => issue.code);
|
|
1986
|
+
expect(codes).not.toContain('empty_contribution_root');
|
|
1987
|
+
expect(codes).not.toContain('local_discovery_failed');
|
|
1988
|
+
expect(codes).not.toContain('packed_discovery_failed');
|
|
1989
|
+
});
|
|
1990
|
+
|
|
1922
1991
|
it('fails on a package.json npm cannot pack, which validate only warns about', async () => {
|
|
1923
1992
|
writePackage({files: ['astryx.integration.mjs', 'themes']});
|
|
1924
1993
|
const packageFile = path.join(tmpDir, 'package.json');
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
summarizeCheck,
|
|
29
29
|
} from './check/check.mjs';
|
|
30
30
|
import {componentDocNamesCheck} from '../../foundation/integrations/validate-contributions.mjs';
|
|
31
|
+
import {formatCliCommand} from '../../foundation/env/package-manager.mjs';
|
|
31
32
|
|
|
32
33
|
let tmpDir;
|
|
33
34
|
let copies = 0;
|
|
@@ -1023,6 +1024,219 @@ describe('component doc files', () => {
|
|
|
1023
1024
|
});
|
|
1024
1025
|
expect(await issuesOf(fixed)).toEqual([]);
|
|
1025
1026
|
});
|
|
1027
|
+
|
|
1028
|
+
it('names a .jsx source beside a component doc and says to rename it', async () => {
|
|
1029
|
+
const dir = writePackage({
|
|
1030
|
+
[MANIFEST]: manifest({components: './components'}),
|
|
1031
|
+
'components/AcmeWidget.doc.mjs': componentDoc('AcmeWidget'),
|
|
1032
|
+
'components/AcmeWidget.jsx': componentSource('AcmeWidget'),
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
const message = only(await issuesOf(dir), 'invalid_component');
|
|
1036
|
+
expect(message).toBe(
|
|
1037
|
+
'Component "AcmeWidget" is missing its same-stem source file AcmeWidget.tsx: found AcmeWidget.jsx, but a component source must be a .tsx file. Fix: rename AcmeWidget.jsx to AcmeWidget.tsx (and point its package export at the new file).',
|
|
1038
|
+
);
|
|
1039
|
+
|
|
1040
|
+
const fixed = follow(dir, {
|
|
1041
|
+
move: [['components/AcmeWidget.jsx', 'components/AcmeWidget.tsx']],
|
|
1042
|
+
});
|
|
1043
|
+
expect(await issuesOf(fixed)).toEqual([]);
|
|
1044
|
+
});
|
|
1045
|
+
|
|
1046
|
+
it('says what an empty doc and a doc with no default export are missing', async () => {
|
|
1047
|
+
const dir = writePackage({
|
|
1048
|
+
[MANIFEST]: manifest({components: './components'}),
|
|
1049
|
+
'components/Empty.doc.mjs': '',
|
|
1050
|
+
'components/Empty.tsx': componentSource('Empty'),
|
|
1051
|
+
'components/Named.doc.mjs': componentDoc('Named').replace(
|
|
1052
|
+
'export default',
|
|
1053
|
+
'export const doc =',
|
|
1054
|
+
),
|
|
1055
|
+
'components/Named.tsx': componentSource('Named'),
|
|
1056
|
+
});
|
|
1057
|
+
|
|
1058
|
+
const messages = (await issuesOf(dir)).map(issue => issue.message);
|
|
1059
|
+
const fix =
|
|
1060
|
+
'Fix: export the doc object as the default export: `export default {type: ..., name: ..., ...}`.';
|
|
1061
|
+
expect(messages).toEqual([
|
|
1062
|
+
`Component "Empty" has invalid metadata: ${path.join(dir, 'components', 'Empty.doc.mjs')} is empty, so it documents nothing. ${fix}`,
|
|
1063
|
+
`Component "Named" has invalid metadata: ${path.join(dir, 'components', 'Named.doc.mjs')} has no default export or \`docs\` export (it exports \`doc\`), so it documents nothing. ${fix}`,
|
|
1064
|
+
]);
|
|
1065
|
+
expect(messages.join('\n')).not.toContain('Invalid input');
|
|
1066
|
+
});
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
describe('template and theme pairing', () => {
|
|
1070
|
+
it('gives a template doc with no source a fix', async () => {
|
|
1071
|
+
const dir = writePackage({
|
|
1072
|
+
[MANIFEST]: manifest({templates: './templates'}),
|
|
1073
|
+
'templates/account-card.doc.mjs': templateDoc('Account card'),
|
|
1074
|
+
});
|
|
1075
|
+
|
|
1076
|
+
const message = only(await issuesOf(dir), 'invalid_template');
|
|
1077
|
+
expect(message).toBe(
|
|
1078
|
+
'Template "account-card" is missing its same-stem source file account-card.tsx. Fix: add account-card.tsx beside account-card.doc.mjs, with the template as its default export.',
|
|
1079
|
+
);
|
|
1080
|
+
const fixed = follow(dir, {
|
|
1081
|
+
write: {'templates/account-card.tsx': templateSource},
|
|
1082
|
+
});
|
|
1083
|
+
expect(await issuesOf(fixed)).toEqual([]);
|
|
1084
|
+
});
|
|
1085
|
+
|
|
1086
|
+
const themeDoc = `${THEME_TYPE}export default {type: 'theme', name: 'ocean', displayName: 'Ocean', description: 'A theme.', maintained: true};\n`;
|
|
1087
|
+
const themeSource =
|
|
1088
|
+
"import {defineTheme} from '@astryxdesign/core/theme';\nexport const oceanTheme = defineTheme({name: 'ocean'});\n";
|
|
1089
|
+
|
|
1090
|
+
it('gives a theme descriptor with no source a fix', async () => {
|
|
1091
|
+
const dir = writePackage({
|
|
1092
|
+
[MANIFEST]: manifest({themes: './themes'}),
|
|
1093
|
+
'themes/ocean/oceanTheme.doc.mjs': themeDoc,
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
expect(only(await issuesOf(dir), 'invalid_theme')).toBe(
|
|
1097
|
+
'Theme "ocean" for @acme/kit must contain exactly one same-stem source for oceanTheme.doc.mjs; found 0. Fix: add oceanTheme.ts beside oceanTheme.doc.mjs, exporting `oceanTheme` from defineTheme.',
|
|
1098
|
+
);
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
it('gives a theme source with no descriptor a fix', async () => {
|
|
1102
|
+
const dir = writePackage({
|
|
1103
|
+
[MANIFEST]: manifest({themes: './themes'}),
|
|
1104
|
+
'themes/ocean/oceanTheme.ts': themeSource,
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
const message = only(await issuesOf(dir), 'invalid_theme');
|
|
1108
|
+
expect(message).toBe(
|
|
1109
|
+
`Theme "ocean" for @acme/kit must contain exactly one same-stem .doc.mjs descriptor; found 0 beside "oceanTheme.ts". Fix: add oceanTheme.doc.mjs beside it with type: 'theme' and name: 'ocean'; \`${formatCliCommand('docs authoring theme-doc', path.join(dir, 'themes', 'ocean'))}\` lists its fields.`,
|
|
1110
|
+
);
|
|
1111
|
+
const fixed = follow(dir, {
|
|
1112
|
+
write: {'themes/ocean/oceanTheme.doc.mjs': themeDoc},
|
|
1113
|
+
});
|
|
1114
|
+
expect(
|
|
1115
|
+
(await issuesOf(fixed)).filter(issue => issue.code === 'invalid_theme'),
|
|
1116
|
+
).toEqual([]);
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
it('says to rename a source named for its theme when the build writes beside it, and the rename clears it', async () => {
|
|
1120
|
+
const brandDoc = `${THEME_TYPE}export default {type: 'theme', name: 'brand', displayName: 'Brand', description: 'A theme.', maintained: true};\n`;
|
|
1121
|
+
const dir = writePackage({
|
|
1122
|
+
[MANIFEST]: manifest({themes: './themes'}),
|
|
1123
|
+
'themes/brand/brand.doc.mjs': brandDoc,
|
|
1124
|
+
'themes/brand/brand.ts':
|
|
1125
|
+
"import {defineTheme} from '@astryxdesign/core/theme';\nexport const brand = defineTheme({name: 'brand'});\n",
|
|
1126
|
+
'themes/brand/brand.js':
|
|
1127
|
+
"/**\n * @generated by `astryx theme build` — do not edit manually.\n */\nimport './brand.css';\nexport const brandTheme = {};\n",
|
|
1128
|
+
'themes/brand/brand.css': '.astryx-theme-brand {}\n',
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
expect(only(await issuesOf(dir), 'invalid_theme')).toBe(
|
|
1132
|
+
`Theme "brand" for @acme/kit must contain exactly one same-stem source for brand.doc.mjs; found 2: "brand.js", "brand.ts". Fix: "brand.js" is the module \`${formatCliCommand('theme build', path.join(dir, 'themes', 'brand'))}\` writes, which takes the theme's name; rename brand.ts to brandTheme.ts and brand.doc.mjs to brandTheme.doc.mjs, export \`brandTheme\` from it, and build again.`,
|
|
1133
|
+
);
|
|
1134
|
+
|
|
1135
|
+
const fixed = follow(dir, {
|
|
1136
|
+
remove: ['themes/brand/brand.ts', 'themes/brand/brand.doc.mjs'],
|
|
1137
|
+
write: {
|
|
1138
|
+
'themes/brand/brandTheme.ts':
|
|
1139
|
+
"import {defineTheme} from '@astryxdesign/core/theme';\nexport const brandTheme = defineTheme({name: 'brand'});\n",
|
|
1140
|
+
'themes/brand/brandTheme.doc.mjs': brandDoc,
|
|
1141
|
+
},
|
|
1142
|
+
});
|
|
1143
|
+
expect(
|
|
1144
|
+
(await issuesOf(fixed)).filter(issue => issue.code === 'invalid_theme'),
|
|
1145
|
+
).toEqual([]);
|
|
1146
|
+
});
|
|
1147
|
+
|
|
1148
|
+
const builtOcean = (/** @type {string} */ extra) =>
|
|
1149
|
+
`/**\n * @generated by \`astryx theme build\` — do not edit manually.\n${extra} */\nimport './ocean.css';\nexport const oceanTheme = {};\n`;
|
|
1150
|
+
|
|
1151
|
+
it("names the theme's source when its defineTheme gives the theme's name, for a descriptor named for the built module", async () => {
|
|
1152
|
+
const dir = writePackage({
|
|
1153
|
+
[MANIFEST]: manifest({themes: './themes'}),
|
|
1154
|
+
'themes/ocean/ocean.doc.mjs': themeDoc,
|
|
1155
|
+
'themes/ocean/oceanTheme.ts': themeSource,
|
|
1156
|
+
'themes/ocean/ocean.js': builtOcean(''),
|
|
1157
|
+
'themes/ocean/ocean.css': '.astryx-theme-ocean {}\n',
|
|
1158
|
+
});
|
|
1159
|
+
|
|
1160
|
+
const message = only(await issuesOf(dir), 'invalid_theme');
|
|
1161
|
+
expect(message).toContain(
|
|
1162
|
+
'shares its stem with the built module "ocean.js", which does not export "ocean": a descriptor must share its stem with the source that calls defineTheme. The theme\'s source is "oceanTheme.ts". Fix: rename ocean.doc.mjs to oceanTheme.doc.mjs.',
|
|
1163
|
+
);
|
|
1164
|
+
const fixed = follow(dir, {
|
|
1165
|
+
move: [['themes/ocean/ocean.doc.mjs', 'themes/ocean/oceanTheme.doc.mjs']],
|
|
1166
|
+
});
|
|
1167
|
+
expect(
|
|
1168
|
+
(await issuesOf(fixed)).filter(issue => issue.code === 'invalid_theme'),
|
|
1169
|
+
).toEqual([]);
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
it("names the source the built module's Source: line gives, over a <name>Theme helper", async () => {
|
|
1173
|
+
const dir = writePackage({
|
|
1174
|
+
[MANIFEST]: manifest({themes: './themes'}),
|
|
1175
|
+
'themes/ocean/ocean.doc.mjs': themeDoc,
|
|
1176
|
+
'themes/ocean/seaTheme.ts': themeSource.replace('oceanTheme', 'seaTheme'),
|
|
1177
|
+
'themes/ocean/baseTheme.ts':
|
|
1178
|
+
"import {defineTheme} from '@astryxdesign/core/theme';\nexport const baseTheme = defineTheme({name: 'base'});\n",
|
|
1179
|
+
'themes/ocean/ocean.js': builtOcean(
|
|
1180
|
+
' * Source: themes/ocean/seaTheme.ts\n',
|
|
1181
|
+
),
|
|
1182
|
+
'themes/ocean/ocean.css': '.astryx-theme-ocean {}\n',
|
|
1183
|
+
});
|
|
1184
|
+
|
|
1185
|
+
expect(only(await issuesOf(dir), 'invalid_theme')).toContain(
|
|
1186
|
+
'The theme\'s source is "seaTheme.ts". Fix: rename ocean.doc.mjs to seaTheme.doc.mjs.',
|
|
1187
|
+
);
|
|
1188
|
+
});
|
|
1189
|
+
|
|
1190
|
+
it('never names a lone <name>Theme helper as the source: the message stays generic', async () => {
|
|
1191
|
+
const dir = writePackage({
|
|
1192
|
+
[MANIFEST]: manifest({themes: './themes'}),
|
|
1193
|
+
'themes/ocean/ocean.doc.mjs': themeDoc,
|
|
1194
|
+
'themes/ocean/oceanTheme.ts':
|
|
1195
|
+
"import {defineTheme} from '@astryxdesign/core/theme';\nexport const oceanTheme = defineTheme({name: 'base'});\n",
|
|
1196
|
+
'themes/ocean/ocean.js': builtOcean(''),
|
|
1197
|
+
'themes/ocean/ocean.css': '.astryx-theme-ocean {}\n',
|
|
1198
|
+
});
|
|
1199
|
+
|
|
1200
|
+
const message = only(await issuesOf(dir), 'invalid_theme');
|
|
1201
|
+
expect(message).toContain(
|
|
1202
|
+
'shares its stem with the built module "ocean.js", which does not export "ocean": a descriptor must share its stem with the source that calls defineTheme. Fix: rename ocean.doc.mjs to share its stem with the theme\'s source (the module that calls defineTheme, such as oceanTheme.ts).',
|
|
1203
|
+
);
|
|
1204
|
+
expect(message).not.toContain("The theme's source is");
|
|
1205
|
+
});
|
|
1206
|
+
|
|
1207
|
+
it('accepts a descriptor named for a built module that exports its stem, as 0.7.2 does', async () => {
|
|
1208
|
+
const dir = writePackage({
|
|
1209
|
+
[MANIFEST]: manifest({themes: './themes'}),
|
|
1210
|
+
'themes/ocean/ocean.doc.mjs': themeDoc,
|
|
1211
|
+
'themes/ocean/oceanTheme.ts': themeSource,
|
|
1212
|
+
'themes/ocean/ocean.js': builtOcean('').replace(
|
|
1213
|
+
'export const oceanTheme = {};',
|
|
1214
|
+
'export const oceanTheme = {};\nexport const ocean = oceanTheme;',
|
|
1215
|
+
),
|
|
1216
|
+
'themes/ocean/ocean.css': '.astryx-theme-ocean {}\n',
|
|
1217
|
+
});
|
|
1218
|
+
|
|
1219
|
+
expect(
|
|
1220
|
+
(await issuesOf(dir)).filter(issue => issue.code === 'invalid_theme'),
|
|
1221
|
+
).toEqual([]);
|
|
1222
|
+
});
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
describe('a theme folder with a helper', () => {
|
|
1226
|
+
it('reads a descriptor beside its own defineTheme source, with a <name>Theme helper beside them', async () => {
|
|
1227
|
+
const dir = writePackage({
|
|
1228
|
+
[MANIFEST]: manifest({themes: './themes'}),
|
|
1229
|
+
'themes/brand/brand.doc.mjs': `${THEME_TYPE}export default {type: 'theme', name: 'brand', displayName: 'Brand', description: 'A theme.', maintained: true};\n`,
|
|
1230
|
+
'themes/brand/brand.ts':
|
|
1231
|
+
"import {defineTheme} from '@astryxdesign/core/theme';\nimport {baseTheme} from './baseTheme';\nexport const brand = defineTheme({name: 'brand', extends: baseTheme});\n",
|
|
1232
|
+
'themes/brand/baseTheme.ts':
|
|
1233
|
+
"import {defineTheme} from '@astryxdesign/core/theme';\nexport const baseTheme = defineTheme({name: 'base'});\n",
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1236
|
+
expect(
|
|
1237
|
+
(await issuesOf(dir)).filter(issue => issue.code === 'invalid_theme'),
|
|
1238
|
+
).toEqual([]);
|
|
1239
|
+
});
|
|
1026
1240
|
});
|
|
1027
1241
|
|
|
1028
1242
|
describe('a hidden doc beside a source whose name differs only in case', () => {
|
|
@@ -1404,6 +1618,84 @@ describe('package.json', () => {
|
|
|
1404
1618
|
});
|
|
1405
1619
|
});
|
|
1406
1620
|
|
|
1621
|
+
describe('the manifest', () => {
|
|
1622
|
+
it('asks about a key one letter from a known one before blaming the CLI version', async () => {
|
|
1623
|
+
const dir = writePackage({
|
|
1624
|
+
[MANIFEST]: manifest({component: './components'}),
|
|
1625
|
+
});
|
|
1626
|
+
|
|
1627
|
+
const message = only(await issuesOf(dir), 'unknown_manifest_key');
|
|
1628
|
+
expect(message).toBe(
|
|
1629
|
+
'This CLI does not know the manifest key "component", so it is ignored. Did you mean `components`? Fix: rename "component" to "components" in astryx.integration.mjs. If it is a key from a newer Astryx CLI instead, upgrading @astryxdesign/cli picks it up.',
|
|
1630
|
+
);
|
|
1631
|
+
});
|
|
1632
|
+
|
|
1633
|
+
it('says to remove a near-miss key when the manifest already sets the key it suggests', async () => {
|
|
1634
|
+
const dir = writePackage({
|
|
1635
|
+
[MANIFEST]: manifest({components: './components', component: './x'}),
|
|
1636
|
+
'components/AcmeWidget.doc.mjs': componentDoc('AcmeWidget'),
|
|
1637
|
+
'components/AcmeWidget.tsx': componentSource('AcmeWidget'),
|
|
1638
|
+
});
|
|
1639
|
+
|
|
1640
|
+
expect(only(await issuesOf(dir), 'unknown_manifest_key')).toBe(
|
|
1641
|
+
'This CLI does not know the manifest key "component", so it is ignored. Did you mean `components`? Fix: remove "component" from astryx.integration.mjs; it already sets "components". If it is a key from a newer Astryx CLI instead, upgrading @astryxdesign/cli picks it up.',
|
|
1642
|
+
);
|
|
1643
|
+
const fixed = follow(dir, {
|
|
1644
|
+
write: {[MANIFEST]: manifest({components: './components'})},
|
|
1645
|
+
});
|
|
1646
|
+
expect(await issuesOf(fixed)).toEqual([]);
|
|
1647
|
+
});
|
|
1648
|
+
|
|
1649
|
+
it.each([
|
|
1650
|
+
[
|
|
1651
|
+
'alone, though the package name gives a provider ID',
|
|
1652
|
+
{providerID: '@acme/kit', docs: './docs'},
|
|
1653
|
+
'Fix: rename "providerID" to "providerId" in astryx.integration.mjs.',
|
|
1654
|
+
],
|
|
1655
|
+
[
|
|
1656
|
+
'beside the key it suggests',
|
|
1657
|
+
{providerID: '@acme/kit', providerId: '@acme/kit', docs: './docs'},
|
|
1658
|
+
'Fix: remove "providerID" from astryx.integration.mjs; it already sets "providerId".',
|
|
1659
|
+
],
|
|
1660
|
+
])(
|
|
1661
|
+
'reads the keys the manifest declares: providerID %s',
|
|
1662
|
+
async (_label, keys, fix) => {
|
|
1663
|
+
const dir = writePackage({
|
|
1664
|
+
[MANIFEST]: manifest(keys),
|
|
1665
|
+
'docs/a.doc.mjs': topic('a'),
|
|
1666
|
+
});
|
|
1667
|
+
|
|
1668
|
+
expect(only(await issuesOf(dir), 'unknown_manifest_key')).toContain(fix);
|
|
1669
|
+
},
|
|
1670
|
+
);
|
|
1671
|
+
|
|
1672
|
+
it('keeps the newer-CLI explanation for a key that is no near miss', async () => {
|
|
1673
|
+
const dir = writePackage({[MANIFEST]: manifest({playgrounds: './x'})});
|
|
1674
|
+
|
|
1675
|
+
expect(only(await issuesOf(dir), 'unknown_manifest_key')).toContain(
|
|
1676
|
+
'published against a newer Astryx CLI',
|
|
1677
|
+
);
|
|
1678
|
+
});
|
|
1679
|
+
|
|
1680
|
+
it('says a manifest has no default export, and what it exports', async () => {
|
|
1681
|
+
const dir = writePackage({
|
|
1682
|
+
[MANIFEST]: "export const integration = {docs: './docs'};\n",
|
|
1683
|
+
});
|
|
1684
|
+
|
|
1685
|
+
expect(only(await issuesOf(dir), 'invalid_manifest')).toBe(
|
|
1686
|
+
"Integration manifest (astryx.integration.mjs) has no default export (it exports `integration`). Fix: export the manifest object as the default export: `export default {components: './components'}`, naming the roots the package has.",
|
|
1687
|
+
);
|
|
1688
|
+
});
|
|
1689
|
+
|
|
1690
|
+
it('says a manifest is empty', async () => {
|
|
1691
|
+
const dir = writePackage({[MANIFEST]: ''});
|
|
1692
|
+
|
|
1693
|
+
expect(only(await issuesOf(dir), 'invalid_manifest')).toMatch(
|
|
1694
|
+
/^Integration manifest \(astryx\.integration\.mjs\) is empty\. Fix: /u,
|
|
1695
|
+
);
|
|
1696
|
+
});
|
|
1697
|
+
});
|
|
1698
|
+
|
|
1407
1699
|
describe('unreadable files and theme names', () => {
|
|
1408
1700
|
const asRoot = process.getuid?.() === 0;
|
|
1409
1701
|
|
|
@@ -328,12 +328,14 @@ async function validateAtPackageDir(
|
|
|
328
328
|
let manifest;
|
|
329
329
|
/** @type {string[]} */
|
|
330
330
|
let unknownKeys;
|
|
331
|
+
/** @type {string[]} */
|
|
332
|
+
let declaredKeys;
|
|
331
333
|
/** @type {string | undefined} */
|
|
332
334
|
let agentDocsError;
|
|
333
335
|
/** @type {string | undefined} */
|
|
334
336
|
let cliCommandError;
|
|
335
337
|
try {
|
|
336
|
-
({manifest, unknownKeys, agentDocsError, cliCommandError} =
|
|
338
|
+
({manifest, unknownKeys, declaredKeys, agentDocsError, cliCommandError} =
|
|
337
339
|
await loadManifest(
|
|
338
340
|
manifestFile,
|
|
339
341
|
`Integration manifest (${path.basename(manifestFile)})`,
|
|
@@ -400,6 +402,7 @@ async function validateAtPackageDir(
|
|
|
400
402
|
__cliCommandError: cliCommandError,
|
|
401
403
|
__agentDocsError: agentDocsError,
|
|
402
404
|
__unknownKeys: unknownKeys,
|
|
405
|
+
__declaredKeys: declaredKeys,
|
|
403
406
|
__spec: identity.name,
|
|
404
407
|
__declaredProviderId: manifest.providerId,
|
|
405
408
|
__packageDir: packageDir,
|