@astryxdesign/cli 0.7.15-canary.gea16e8d → 0.7.15
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 +353 -3
- package/README.md +63 -63
- package/api/build/_adapter.d.mts +4 -0
- package/api/build/_adapter.mjs +28 -2
- package/api/build/blocks/blocks.d.mts +10 -1
- package/api/build/blocks/blocks.mjs +84 -7
- package/api/build/build.mjs +6 -1
- package/api/build/tree.d.mts +4 -0
- package/api/build/tree.mjs +9 -2
- package/api/doctor/_adapter.d.mts +2 -1
- package/api/doctor/_adapter.mjs +6 -1
- package/api/doctor/doctor.mjs +2 -2
- package/api/doctor/theme-checks.mjs +56 -21
- package/api/integration/add-helpers.mjs +5 -0
- package/api/integration/add-theme.mjs +15 -110
- package/api/integration/validate-integration.mjs +17 -3
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/theme/_adapter.d.mts +37 -5
- package/api/theme/_adapter.mjs +363 -50
- package/api/theme/_fork.d.mts +90 -0
- package/api/theme/_fork.mjs +246 -0
- package/api/theme/build/build.d.mts +25 -1
- package/api/theme/build/build.mjs +352 -41
- package/api/theme/eject/eject.mjs +36 -15
- package/api/theme/list/list.mjs +3 -6
- package/api/theme/palette/generate/generator.d.mts +13 -0
- package/api/theme/palette/generate/generator.mjs +32 -2
- package/api/theme/targets/targets.mjs +10 -3
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +2 -2
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.mjs +157 -36
- package/api/theme-edit/_catalog.d.mts +1 -6
- package/api/theme-edit/_catalog.mjs +5 -268
- package/api/theme-edit/_check.d.mts +3 -1
- package/api/theme-edit/_check.mjs +733 -308
- package/api/theme-edit/_color.d.mts +19 -0
- package/api/theme-edit/_color.mjs +277 -33
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +25 -0
- package/api/theme-edit/_context.d.mts +2 -0
- package/api/theme-edit/_context.mjs +83 -9
- package/api/theme-edit/_css.d.mts +84 -0
- package/api/theme-edit/_css.mjs +700 -0
- package/api/theme-edit/_edit.mjs +370 -85
- package/api/theme-edit/_how-commands.d.mts +5 -0
- package/api/theme-edit/_how-commands.mjs +20 -13
- package/api/theme-edit/_how-question.d.mts +29 -0
- package/api/theme-edit/_how-question.mjs +1573 -182
- package/api/theme-edit/_how.mjs +306 -22
- package/api/theme-edit/_overview.mjs +2 -7
- package/api/theme-edit/_palette.d.mts +27 -5
- package/api/theme-edit/_palette.mjs +231 -97
- package/api/theme-edit/_parts.d.mts +42 -10
- package/api/theme-edit/_parts.mjs +224 -69
- package/api/theme-edit/_preview-app.d.mts +8 -0
- package/api/theme-edit/_preview-app.mjs +549 -96
- package/api/theme-edit/_preview.d.mts +7 -16
- package/api/theme-edit/_preview.mjs +77 -84
- package/api/theme-edit/_project.d.mts +20 -1
- package/api/theme-edit/_project.mjs +43 -13
- package/api/theme-edit/_settings.d.mts +96 -20
- package/api/theme-edit/_settings.mjs +646 -141
- package/api/theme-edit/_tables.d.mts +18 -12
- package/api/theme-edit/_tables.mjs +144 -147
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +3 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
- package/api/theme-edit/themeEditSet.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +22 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -0
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +8 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +9 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/index.mjs +10 -10
- package/clients/cli/commands/experimental/theme.mjs +22 -3
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/integration.mjs +8 -0
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +325 -48
- package/clients/cli/index.mjs +18 -3
- package/clients/cli/lib/cli-error.mjs +118 -3
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/config/project.mjs +34 -8
- package/foundation/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- package/foundation/discovery/template-needs.d.mts +13 -0
- package/foundation/discovery/template-needs.mjs +30 -15
- package/foundation/discovery/theme-discovery.mjs +14 -2
- package/foundation/discovery/theme-imports.d.mts +16 -0
- package/foundation/discovery/theme-imports.mjs +30 -2
- package/foundation/doc-compiler/import.mjs +10 -4
- package/foundation/fs/gather-cache.mjs +82 -23
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +7 -2
- package/foundation/integrations/autolink.d.mts +1 -24
- package/foundation/integrations/autolink.mjs +7 -60
- package/foundation/integrations/declared-dependencies.d.mts +27 -0
- package/foundation/integrations/declared-dependencies.mjs +73 -0
- package/foundation/integrations/integrations.d.mts +8 -0
- package/foundation/integrations/integrations.mjs +4 -0
- package/foundation/integrations/may-have-integrations.d.mts +8 -0
- package/foundation/integrations/may-have-integrations.mjs +47 -0
- package/foundation/integrations/validate-contributions.d.mts +62 -1
- package/foundation/integrations/validate-contributions.mjs +452 -29
- package/foundation/release/cache.d.mts +21 -2
- package/foundation/release/cache.mjs +48 -8
- package/foundation/release/folder-lock.d.mts +7 -0
- package/foundation/release/folder-lock.mjs +60 -26
- package/foundation/release/lock-lease.d.mts +2 -1
- package/foundation/release/lock-lease.mjs +7 -2
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +5 -5
- package/package.json +6 -6
- package/api/theme-edit/_css-properties.d.mts +0 -10
- package/api/theme-edit/_css-properties.mjs +0 -556
|
@@ -1478,6 +1478,38 @@ function readModule(source, builtins) {
|
|
|
1478
1478
|
return {server: found, assets};
|
|
1479
1479
|
}
|
|
1480
1480
|
|
|
1481
|
+
/**
|
|
1482
|
+
* Whether npm packs one file (or, with `folder`, anything inside one
|
|
1483
|
+
* folder) of the package at `base`. `cache` holds what npm packs, asked at
|
|
1484
|
+
* most once per cache. With no `files` field and no ignore file on the
|
|
1485
|
+
* path, npm packs everything, so nothing is asked. Without npm's answer, a
|
|
1486
|
+
* path no `files` entry can reach is left out, and any other is unknown.
|
|
1487
|
+
* @param {string} base package root
|
|
1488
|
+
* @param {string} rel path relative to `base`, with forward slashes
|
|
1489
|
+
* @param {unknown} packedFiles package.json `files`
|
|
1490
|
+
* @param {{packed?: {paths: Set<string>} | {error: string}}} cache
|
|
1491
|
+
* @param {{folder?: boolean}} [options]
|
|
1492
|
+
* @returns {{packed: true} | {packed: false, by: 'npm' | 'files'} | {packed: 'unknown', error: string}}
|
|
1493
|
+
*/
|
|
1494
|
+
function packState(base, rel, packedFiles, cache, {folder = false} = {}) {
|
|
1495
|
+
if (!Array.isArray(packedFiles) && ignoreFilesFor(base, rel).length === 0) {
|
|
1496
|
+
return {packed: true};
|
|
1497
|
+
}
|
|
1498
|
+
cache.packed ??= npmPackedPaths(base);
|
|
1499
|
+
const packed = cache.packed;
|
|
1500
|
+
if ('paths' in packed) {
|
|
1501
|
+
if (packed.paths.has(rel)) return {packed: true};
|
|
1502
|
+
if (folder && [...packed.paths].some(each => each.startsWith(`${rel}/`))) {
|
|
1503
|
+
return {packed: true};
|
|
1504
|
+
}
|
|
1505
|
+
return {packed: false, by: 'npm'};
|
|
1506
|
+
}
|
|
1507
|
+
if (Array.isArray(packedFiles) && outsideFiles(rel, packedFiles)) {
|
|
1508
|
+
return {packed: false, by: 'files'};
|
|
1509
|
+
}
|
|
1510
|
+
return {packed: 'unknown', error: packed.error};
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1481
1513
|
/**
|
|
1482
1514
|
* What a package's examples need to work everywhere they are shown: template
|
|
1483
1515
|
* lists, docs pages and catalog cards, which render each block alone from
|
|
@@ -1503,8 +1535,12 @@ function readModule(source, builtins) {
|
|
|
1503
1535
|
* package (`npm pack --dry-run`). When npm cannot answer, an asset no
|
|
1504
1536
|
* `files` entry can reach is still a note, and any other is returned in
|
|
1505
1537
|
* `unchecked`.
|
|
1538
|
+
* It also returns `examples`, what the package-level listing note needs:
|
|
1539
|
+
* whether any block is a showcase, and, when none is, how many components
|
|
1540
|
+
* need an example (the exemptions above apply). It is absent when the
|
|
1541
|
+
* templates or components cannot be read, so no listing note is drawn.
|
|
1506
1542
|
* @param {LoadedIntegration} integration
|
|
1507
|
-
* @returns {Promise<{notes: Note[], unchecked: Array<{file: string, asset: string, reason: string}
|
|
1543
|
+
* @returns {Promise<{notes: Note[], unchecked: Array<{file: string, asset: string, reason: string}>, examples?: ExampleSummary}>}
|
|
1508
1544
|
*/
|
|
1509
1545
|
export async function componentExamplesCheck(integration) {
|
|
1510
1546
|
/** @type {Note[]} */
|
|
@@ -1542,8 +1578,8 @@ export async function componentExamplesCheck(integration) {
|
|
|
1542
1578
|
} catch {
|
|
1543
1579
|
packedFiles = undefined;
|
|
1544
1580
|
}
|
|
1545
|
-
/** @type {{paths: Set<string>} | {error: string}
|
|
1546
|
-
|
|
1581
|
+
/** @type {{packed?: {paths: Set<string>} | {error: string}}} what npm packs, read once */
|
|
1582
|
+
const npm = {};
|
|
1547
1583
|
/** @type {Array<{file: string, asset: string, reason: string}>} */
|
|
1548
1584
|
const unchecked = [];
|
|
1549
1585
|
// A bare builtin name the package installs from npm (`buffer`, `events`)
|
|
@@ -1612,36 +1648,19 @@ export async function componentExamplesCheck(integration) {
|
|
|
1612
1648
|
// A folder URL is packed when npm packs anything inside it.
|
|
1613
1649
|
const isFolder = exists && fs.statSync(asset).isDirectory();
|
|
1614
1650
|
if (exists) {
|
|
1615
|
-
// With no `files` field npm packs everything but what an ignore file
|
|
1616
|
-
// drops, in the package root or any folder down to the asset, so
|
|
1617
|
-
// with no ignore file on that path there is nothing to ask.
|
|
1618
|
-
if (
|
|
1619
|
-
!Array.isArray(packedFiles) &&
|
|
1620
|
-
ignoreFilesFor(base, assetRel).length === 0
|
|
1621
|
-
) {
|
|
1622
|
-
continue;
|
|
1623
|
-
}
|
|
1624
1651
|
// What npm packs decides. Without npm's answer, an asset no entry
|
|
1625
1652
|
// can reach is reported, and any other is listed as not checked.
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
[...packed.paths].some(each => each.startsWith(`${assetRel}/`))
|
|
1632
|
-
) {
|
|
1633
|
-
continue;
|
|
1634
|
-
}
|
|
1635
|
-
} else if (
|
|
1636
|
-
!Array.isArray(packedFiles) ||
|
|
1637
|
-
!outsideFiles(assetRel, packedFiles)
|
|
1638
|
-
) {
|
|
1653
|
+
const state = packState(base, assetRel, packedFiles, npm, {
|
|
1654
|
+
folder: isFolder,
|
|
1655
|
+
});
|
|
1656
|
+
if (state.packed === true) continue;
|
|
1657
|
+
if (state.packed === 'unknown') {
|
|
1639
1658
|
unchecked.push({
|
|
1640
1659
|
file: rel(template.filePath),
|
|
1641
1660
|
asset: assetRel,
|
|
1642
1661
|
reason: Array.isArray(packedFiles)
|
|
1643
|
-
? `${
|
|
1644
|
-
: `${
|
|
1662
|
+
? `${state.error}, and a \`files\` entry may reach it`
|
|
1663
|
+
: `${state.error}, and ${ignoreFilesFor(base, assetRel).at(-1) ?? '.npmignore'} may drop it`,
|
|
1645
1664
|
});
|
|
1646
1665
|
continue;
|
|
1647
1666
|
}
|
|
@@ -1673,7 +1692,7 @@ export async function componentExamplesCheck(integration) {
|
|
|
1673
1692
|
}
|
|
1674
1693
|
}
|
|
1675
1694
|
if (!integration.components || rootProblem(integration.components)) {
|
|
1676
|
-
return {notes, unchecked};
|
|
1695
|
+
return {notes, unchecked, examples: {needed: 0, showcase: shown.size > 0}};
|
|
1677
1696
|
}
|
|
1678
1697
|
/** @type {any[]} */
|
|
1679
1698
|
let records;
|
|
@@ -1716,6 +1735,8 @@ export async function componentExamplesCheck(integration) {
|
|
|
1716
1735
|
);
|
|
1717
1736
|
if (owner) ownerOf.set(template, owner);
|
|
1718
1737
|
}
|
|
1738
|
+
/** components that need an example and have none */
|
|
1739
|
+
let needed = 0;
|
|
1719
1740
|
for (const record of records) {
|
|
1720
1741
|
if (componentDiscovery.isIntegrationMember(record)) continue;
|
|
1721
1742
|
if (shown.has(record.name)) continue;
|
|
@@ -1727,6 +1748,7 @@ export async function componentExamplesCheck(integration) {
|
|
|
1727
1748
|
}
|
|
1728
1749
|
if (doc?.hidden === true || doc?.isHiddenFromOverview === true) continue;
|
|
1729
1750
|
if (doc?.category === 'Utility') continue;
|
|
1751
|
+
needed++;
|
|
1730
1752
|
const name = record.name;
|
|
1731
1753
|
const stem = `${name.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase()}-showcase`;
|
|
1732
1754
|
// A block that already composes the component only needs the fields.
|
|
@@ -1822,7 +1844,7 @@ export async function componentExamplesCheck(integration) {
|
|
|
1822
1844
|
' A doc set to `hidden`, `isHiddenFromOverview` or category `Utility` needs no example.',
|
|
1823
1845
|
});
|
|
1824
1846
|
}
|
|
1825
|
-
return {notes, unchecked};
|
|
1847
|
+
return {notes, unchecked, examples: {needed, showcase: shown.size > 0}};
|
|
1826
1848
|
}
|
|
1827
1849
|
|
|
1828
1850
|
/**
|
|
@@ -2461,3 +2483,404 @@ async function allLoadedIntegrationIssues(loaded) {
|
|
|
2461
2483
|
await runContributionChecks(loaded, issues);
|
|
2462
2484
|
return issues;
|
|
2463
2485
|
}
|
|
2486
|
+
|
|
2487
|
+
/**
|
|
2488
|
+
* Where the package declares the logo a catalog shows, and the field that
|
|
2489
|
+
* holds it for messages. The integration file's `logo` comes first; a
|
|
2490
|
+
* package.json `marketplace.logo` is also read when the integration file
|
|
2491
|
+
* has none, so a package that set it there keeps its logo.
|
|
2492
|
+
* @param {LoadedIntegration} integration
|
|
2493
|
+
* @param {any} pkg parsed package.json
|
|
2494
|
+
* @returns {{file: string, field: string, light: unknown, dark: unknown}}
|
|
2495
|
+
*/
|
|
2496
|
+
function listingLogo(integration, pkg) {
|
|
2497
|
+
const manifestFile = integration.__manifestFile
|
|
2498
|
+
? path.basename(integration.__manifestFile)
|
|
2499
|
+
: 'astryx.integration.mjs';
|
|
2500
|
+
const declared = integration.logo;
|
|
2501
|
+
if (declared && typeof declared === 'object') {
|
|
2502
|
+
return {
|
|
2503
|
+
file: manifestFile,
|
|
2504
|
+
field: 'logo',
|
|
2505
|
+
light: declared.light,
|
|
2506
|
+
dark: declared.dark,
|
|
2507
|
+
};
|
|
2508
|
+
}
|
|
2509
|
+
const legacy = pkg?.marketplace?.logo;
|
|
2510
|
+
if (legacy && typeof legacy === 'object') {
|
|
2511
|
+
return {
|
|
2512
|
+
file: 'package.json',
|
|
2513
|
+
field: 'marketplace.logo',
|
|
2514
|
+
light: legacy.light,
|
|
2515
|
+
dark: legacy.dark,
|
|
2516
|
+
};
|
|
2517
|
+
}
|
|
2518
|
+
return {file: manifestFile, field: 'logo', light: undefined, dark: undefined};
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
/** The largest logo a catalog shows, in bytes. */
|
|
2522
|
+
const LOGO_MAX_BYTES = 512 * 1024;
|
|
2523
|
+
|
|
2524
|
+
/** SVG elements a logo may use: shapes, groups, paint servers and text alternatives. */
|
|
2525
|
+
const SVG_ELEMENTS = new Set([
|
|
2526
|
+
'svg',
|
|
2527
|
+
'g',
|
|
2528
|
+
'defs',
|
|
2529
|
+
'symbol',
|
|
2530
|
+
'use',
|
|
2531
|
+
'path',
|
|
2532
|
+
'rect',
|
|
2533
|
+
'circle',
|
|
2534
|
+
'ellipse',
|
|
2535
|
+
'line',
|
|
2536
|
+
'polyline',
|
|
2537
|
+
'polygon',
|
|
2538
|
+
'lineargradient',
|
|
2539
|
+
'radialgradient',
|
|
2540
|
+
'stop',
|
|
2541
|
+
'clippath',
|
|
2542
|
+
'mask',
|
|
2543
|
+
'title',
|
|
2544
|
+
'desc',
|
|
2545
|
+
]);
|
|
2546
|
+
|
|
2547
|
+
/** SVG attributes a logo may use: geometry, paint and labels, no events or styles. */
|
|
2548
|
+
const SVG_ATTRIBUTES = new Set([
|
|
2549
|
+
'xmlns',
|
|
2550
|
+
'xmlns:xlink',
|
|
2551
|
+
'version',
|
|
2552
|
+
'id',
|
|
2553
|
+
'class',
|
|
2554
|
+
'role',
|
|
2555
|
+
'aria-label',
|
|
2556
|
+
'aria-hidden',
|
|
2557
|
+
'focusable',
|
|
2558
|
+
'viewbox',
|
|
2559
|
+
'preserveaspectratio',
|
|
2560
|
+
'width',
|
|
2561
|
+
'height',
|
|
2562
|
+
'x',
|
|
2563
|
+
'y',
|
|
2564
|
+
'x1',
|
|
2565
|
+
'y1',
|
|
2566
|
+
'x2',
|
|
2567
|
+
'y2',
|
|
2568
|
+
'cx',
|
|
2569
|
+
'cy',
|
|
2570
|
+
'r',
|
|
2571
|
+
'rx',
|
|
2572
|
+
'ry',
|
|
2573
|
+
'fx',
|
|
2574
|
+
'fy',
|
|
2575
|
+
'd',
|
|
2576
|
+
'points',
|
|
2577
|
+
'pathlength',
|
|
2578
|
+
'transform',
|
|
2579
|
+
'opacity',
|
|
2580
|
+
'color',
|
|
2581
|
+
'display',
|
|
2582
|
+
'visibility',
|
|
2583
|
+
'overflow',
|
|
2584
|
+
'fill',
|
|
2585
|
+
'fill-opacity',
|
|
2586
|
+
'fill-rule',
|
|
2587
|
+
'stroke',
|
|
2588
|
+
'stroke-width',
|
|
2589
|
+
'stroke-opacity',
|
|
2590
|
+
'stroke-linecap',
|
|
2591
|
+
'stroke-linejoin',
|
|
2592
|
+
'stroke-miterlimit',
|
|
2593
|
+
'stroke-dasharray',
|
|
2594
|
+
'stroke-dashoffset',
|
|
2595
|
+
'vector-effect',
|
|
2596
|
+
'shape-rendering',
|
|
2597
|
+
'clip-path',
|
|
2598
|
+
'clip-rule',
|
|
2599
|
+
'mask',
|
|
2600
|
+
'offset',
|
|
2601
|
+
'stop-color',
|
|
2602
|
+
'stop-opacity',
|
|
2603
|
+
'gradientunits',
|
|
2604
|
+
'gradienttransform',
|
|
2605
|
+
'spreadmethod',
|
|
2606
|
+
'clippathunits',
|
|
2607
|
+
'maskunits',
|
|
2608
|
+
'maskcontentunits',
|
|
2609
|
+
'href',
|
|
2610
|
+
'xlink:href',
|
|
2611
|
+
]);
|
|
2612
|
+
|
|
2613
|
+
const SVG_TAG =
|
|
2614
|
+
/^<(\/?)([A-Za-z][\w:.-]*)((?:\s+[^\s"'=<>/]+(?:\s*=\s*(?:"[^"]*"|'[^']*'))?)*)\s*(\/?)>/u;
|
|
2615
|
+
const SVG_ATTRIBUTE = /([^\s"'=<>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'))?/gu;
|
|
2616
|
+
|
|
2617
|
+
/**
|
|
2618
|
+
* Whether an attribute value stays inside the image: a reference is only to
|
|
2619
|
+
* an element of the same file (`#id`, `url(#id)`).
|
|
2620
|
+
* @param {string} name lower-case attribute name
|
|
2621
|
+
* @param {string} value
|
|
2622
|
+
* @returns {boolean}
|
|
2623
|
+
*/
|
|
2624
|
+
function isLocalSvgValue(name, value) {
|
|
2625
|
+
// A character reference or a CSS escape could spell a reference the
|
|
2626
|
+
// tests below would miss.
|
|
2627
|
+
if (/[<>&\\]/u.test(value)) return false;
|
|
2628
|
+
if (name === 'xmlns') return value === 'http://www.w3.org/2000/svg';
|
|
2629
|
+
if (name === 'xmlns:xlink') return value === 'http://www.w3.org/1999/xlink';
|
|
2630
|
+
if (name === 'href' || name === 'xlink:href') {
|
|
2631
|
+
return /^#[\w.-]+$/u.test(value.trim());
|
|
2632
|
+
}
|
|
2633
|
+
if (name === 'mask' || name === 'clip-path') {
|
|
2634
|
+
return /^\s*(?:none|url\(\s*(["']?)#[\w.-]+\1\s*\))\s*$/iu.test(value);
|
|
2635
|
+
}
|
|
2636
|
+
if (name === 'fill' || name === 'stroke') {
|
|
2637
|
+
// A local paint server, then colors; the only functions are colors.
|
|
2638
|
+
const rest = value.replace(/url\(\s*(["']?)#[\w.-]+\1\s*\)/giu, '');
|
|
2639
|
+
return [...rest.matchAll(/([\w-]*)\s*\(/gu)].every(([, fn]) =>
|
|
2640
|
+
/^(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix|light-dark)$/iu.test(
|
|
2641
|
+
fn,
|
|
2642
|
+
),
|
|
2643
|
+
);
|
|
2644
|
+
}
|
|
2645
|
+
return true;
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
const XML_DECLARATION =
|
|
2649
|
+
/^<\?xml((?:\s+(?:version|encoding|standalone)\s*=\s*(?:"[\w.-]*"|'[\w.-]*'))*)\s*\?>/u;
|
|
2650
|
+
|
|
2651
|
+
/**
|
|
2652
|
+
* Whether `source` is an SVG drawn only with shapes: after an optional XML
|
|
2653
|
+
* declaration (only `version`, `encoding` and `standalone`, in UTF-8), every
|
|
2654
|
+
* element and attribute is on the allowlists above, every reference points
|
|
2655
|
+
* inside the file, no attribute value holds a character reference or a CSS
|
|
2656
|
+
* escape, and only `title` and `desc` hold text, and nothing else. Comments
|
|
2657
|
+
* are skipped where a tag could start; a doctype, CDATA or processing
|
|
2658
|
+
* instruction is refused.
|
|
2659
|
+
* @param {string} source
|
|
2660
|
+
* @returns {boolean}
|
|
2661
|
+
*/
|
|
2662
|
+
function isShapesOnlySvg(source) {
|
|
2663
|
+
let rest = source.replace(/^\uFEFF/u, '').trim();
|
|
2664
|
+
if (rest.startsWith('<?')) {
|
|
2665
|
+
const declaration = XML_DECLARATION.exec(rest);
|
|
2666
|
+
if (declaration == null) return false;
|
|
2667
|
+
const encoding = /encoding\s*=\s*["']([^"']*)["']/u.exec(declaration[1]);
|
|
2668
|
+
if (encoding != null && encoding[1].toLowerCase() !== 'utf-8') return false;
|
|
2669
|
+
rest = rest.slice(declaration[0].length).trim();
|
|
2670
|
+
}
|
|
2671
|
+
/** @type {string[]} */
|
|
2672
|
+
const open = [];
|
|
2673
|
+
let rootClosed = false;
|
|
2674
|
+
while (rest.length > 0) {
|
|
2675
|
+
const inText = open.at(-1) === 'title' || open.at(-1) === 'desc';
|
|
2676
|
+
// `title` and `desc` hold text alone: no comment and no element.
|
|
2677
|
+
if (
|
|
2678
|
+
inText &&
|
|
2679
|
+
rest.startsWith('<') &&
|
|
2680
|
+
!rest.startsWith(`</${open.at(-1)}`)
|
|
2681
|
+
) {
|
|
2682
|
+
return false;
|
|
2683
|
+
}
|
|
2684
|
+
// A comment is skipped only where a tag could start, so one opened
|
|
2685
|
+
// inside an attribute value cannot hide markup.
|
|
2686
|
+
// Its body may not start with `>` or `->` or hold `--`: an HTML parser
|
|
2687
|
+
// ends such a comment early, at `<!-->`, `<!--->` or `--!>`.
|
|
2688
|
+
if (rest.startsWith('<!--')) {
|
|
2689
|
+
const end = rest.indexOf('-->', 4);
|
|
2690
|
+
if (end === -1) return false;
|
|
2691
|
+
const body = rest.slice(4, end);
|
|
2692
|
+
if (
|
|
2693
|
+
body.startsWith('>') ||
|
|
2694
|
+
body.startsWith('->') ||
|
|
2695
|
+
body.includes('--')
|
|
2696
|
+
) {
|
|
2697
|
+
return false;
|
|
2698
|
+
}
|
|
2699
|
+
rest = rest.slice(end + 3);
|
|
2700
|
+
continue;
|
|
2701
|
+
}
|
|
2702
|
+
if (rest.startsWith('<')) {
|
|
2703
|
+
const tag = SVG_TAG.exec(rest);
|
|
2704
|
+
if (tag == null || rootClosed) return false;
|
|
2705
|
+
const [whole, closing, rawName, attributes, selfClosing] = tag;
|
|
2706
|
+
const name = rawName.toLowerCase();
|
|
2707
|
+
if (!SVG_ELEMENTS.has(name)) return false;
|
|
2708
|
+
if (closing) {
|
|
2709
|
+
if (attributes.trim() !== '' || open.pop() !== name) return false;
|
|
2710
|
+
if (open.length === 0) rootClosed = true;
|
|
2711
|
+
} else {
|
|
2712
|
+
if (open.length === 0 && name !== 'svg') return false;
|
|
2713
|
+
for (const match of attributes.matchAll(SVG_ATTRIBUTE)) {
|
|
2714
|
+
const attribute = match[1].toLowerCase();
|
|
2715
|
+
if (!SVG_ATTRIBUTES.has(attribute)) return false;
|
|
2716
|
+
if (!isLocalSvgValue(attribute, match[2] ?? match[3] ?? '')) {
|
|
2717
|
+
return false;
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
if (selfClosing) {
|
|
2721
|
+
if (open.length === 0) rootClosed = true;
|
|
2722
|
+
} else {
|
|
2723
|
+
open.push(name);
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
rest = rest.slice(whole.length);
|
|
2727
|
+
continue;
|
|
2728
|
+
}
|
|
2729
|
+
const end = rest.indexOf('<');
|
|
2730
|
+
const text = end === -1 ? rest : rest.slice(0, end);
|
|
2731
|
+
const parent = open.at(-1);
|
|
2732
|
+
if (text.trim() !== '' && parent !== 'title' && parent !== 'desc') {
|
|
2733
|
+
return false;
|
|
2734
|
+
}
|
|
2735
|
+
rest = end === -1 ? '' : rest.slice(end);
|
|
2736
|
+
}
|
|
2737
|
+
return rootClosed && open.length === 0;
|
|
2738
|
+
}
|
|
2739
|
+
|
|
2740
|
+
/**
|
|
2741
|
+
* Whether these bytes are an image a catalog can show as a logo, in the
|
|
2742
|
+
* format the file's extension names: `.png`, `.jpg` or `.jpeg`, `.webp`, or
|
|
2743
|
+
* `.svg` drawn only with shapes; at most 512 KB. A file whose bytes claim
|
|
2744
|
+
* another format, or any other extension, is refused.
|
|
2745
|
+
* @param {Buffer} bytes
|
|
2746
|
+
* @param {string} file the image's path or name
|
|
2747
|
+
* @returns {boolean}
|
|
2748
|
+
*/
|
|
2749
|
+
export function isListingImage(bytes, file) {
|
|
2750
|
+
if (bytes.length === 0 || bytes.length > LOGO_MAX_BYTES) return false;
|
|
2751
|
+
const png = [137, 80, 78, 71, 13, 10, 26, 10].every(
|
|
2752
|
+
(byte, index) => bytes[index] === byte,
|
|
2753
|
+
);
|
|
2754
|
+
const jpeg = bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255;
|
|
2755
|
+
const webp =
|
|
2756
|
+
bytes.subarray(0, 4).toString('latin1') === 'RIFF' &&
|
|
2757
|
+
bytes.subarray(8, 12).toString('latin1') === 'WEBP';
|
|
2758
|
+
switch (path.extname(file).toLowerCase()) {
|
|
2759
|
+
case '.png':
|
|
2760
|
+
return png;
|
|
2761
|
+
case '.jpg':
|
|
2762
|
+
case '.jpeg':
|
|
2763
|
+
return jpeg;
|
|
2764
|
+
case '.webp':
|
|
2765
|
+
return webp;
|
|
2766
|
+
case '.svg':
|
|
2767
|
+
return !png && !jpeg && !webp && isShapesOnlySvg(bytes.toString('utf8'));
|
|
2768
|
+
default:
|
|
2769
|
+
return false;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2773
|
+
/**
|
|
2774
|
+
* What `componentExamplesCheck` found that the package-level note needs.
|
|
2775
|
+
* @typedef {object} ExampleSummary
|
|
2776
|
+
* @property {number} needed components that need an example and have none
|
|
2777
|
+
* @property {boolean} showcase whether any block template is a showcase
|
|
2778
|
+
*/
|
|
2779
|
+
|
|
2780
|
+
/**
|
|
2781
|
+
* What a catalog needs to list the package well, as two information-only
|
|
2782
|
+
* notes that fail no check under any flag, each with its fix:
|
|
2783
|
+
* - `package_without_logo`: the integration file's `logo.light` (or, when
|
|
2784
|
+
* the integration file has no `logo`, package.json `marketplace.logo.light`)
|
|
2785
|
+
* names no image the package ships: missing, outside the package, not a
|
|
2786
|
+
* file, not a PNG, JPEG, WebP or shapes-only SVG of at most 512 KB, or left
|
|
2787
|
+
* out of the packed files. `dark`, when set, is checked the same way.
|
|
2788
|
+
* - `package_without_example`: from `examples`, the summary
|
|
2789
|
+
* `componentExamplesCheck` returns: the package has components that need
|
|
2790
|
+
* an example and no block template is a showcase. A package of themes,
|
|
2791
|
+
* docs, codemods or agent docs alone needs none.
|
|
2792
|
+
* A package of icon sets alone draws neither note. When npm cannot say
|
|
2793
|
+
* whether a logo is packed, it is returned in `unchecked`, listed with the
|
|
2794
|
+
* template assets npm could not place.
|
|
2795
|
+
* @param {LoadedIntegration} integration
|
|
2796
|
+
* @param {ExampleSummary} [examples]
|
|
2797
|
+
* @returns {{notes: Note[], unchecked: Array<{file: string, asset: string, reason: string}>}}
|
|
2798
|
+
*/
|
|
2799
|
+
export function packageListingCheck(integration, examples) {
|
|
2800
|
+
/** @type {Note[]} */
|
|
2801
|
+
const notes = [];
|
|
2802
|
+
/** @type {Array<{file: string, asset: string, reason: string}>} */
|
|
2803
|
+
const unchecked = [];
|
|
2804
|
+
const base = integration.__packageDir;
|
|
2805
|
+
if (!base) return {notes, unchecked};
|
|
2806
|
+
/** @type {any} */
|
|
2807
|
+
let pkg;
|
|
2808
|
+
try {
|
|
2809
|
+
pkg = JSON.parse(fs.readFileSync(path.join(base, 'package.json'), 'utf8'));
|
|
2810
|
+
} catch {
|
|
2811
|
+
// package.json problems are reported by their own check.
|
|
2812
|
+
return {notes, unchecked};
|
|
2813
|
+
}
|
|
2814
|
+
// A package of icon sets alone is experimental; listing it is not.
|
|
2815
|
+
const stableRoots = [
|
|
2816
|
+
'components',
|
|
2817
|
+
'templates',
|
|
2818
|
+
'themes',
|
|
2819
|
+
'docs',
|
|
2820
|
+
'codemods',
|
|
2821
|
+
'agentDocs',
|
|
2822
|
+
];
|
|
2823
|
+
if (!stableRoots.some(key => /** @type {any} */ (integration)[key])) {
|
|
2824
|
+
return {notes, unchecked};
|
|
2825
|
+
}
|
|
2826
|
+
const logo = listingLogo(integration, pkg);
|
|
2827
|
+
const fix = `Fix: add a square logo inside the package, such as \`marketplace/logo.svg\` (an SVG drawn only with shapes, or a PNG, JPEG or WebP, at most 512 KB), make sure \`files\` packs it, and set \`logo: {light: './marketplace/logo.svg'}\` in ${logo.file === 'package.json' ? 'the integration file' : logo.file}; add \`dark\` for a version drawn for dark backgrounds.`;
|
|
2828
|
+
/** @type {{packed?: {paths: Set<string>} | {error: string}}} */
|
|
2829
|
+
const npm = {};
|
|
2830
|
+
/**
|
|
2831
|
+
* Why the image at `value` cannot be shown, or null when it can (or when
|
|
2832
|
+
* only npm could tell, which adds it to `unchecked`).
|
|
2833
|
+
* @param {unknown} value
|
|
2834
|
+
* @param {string} field
|
|
2835
|
+
* @returns {string | null}
|
|
2836
|
+
*/
|
|
2837
|
+
const problem = (value, field) => {
|
|
2838
|
+
const where = `${logo.file} \`${field}\``;
|
|
2839
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
2840
|
+
return `${where} is ${value === undefined ? 'not set' : 'not a path'}`;
|
|
2841
|
+
}
|
|
2842
|
+
const rel = slash(path.normalize(value.trim())).replace(/^\.\//u, '');
|
|
2843
|
+
if (path.isAbsolute(value) || rel === '..' || rel.startsWith('../')) {
|
|
2844
|
+
return `${where} "${value}" points outside the package`;
|
|
2845
|
+
}
|
|
2846
|
+
const file = path.join(base, rel);
|
|
2847
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) {
|
|
2848
|
+
return `${where} names ${rel}, which does not exist`;
|
|
2849
|
+
}
|
|
2850
|
+
if (!isListingImage(fs.readFileSync(file), rel)) {
|
|
2851
|
+
return `${where} names ${rel}, which is not a PNG, JPEG, WebP or shapes-only SVG of at most 512 KB whose contents match its extension`;
|
|
2852
|
+
}
|
|
2853
|
+
const state = packState(base, rel, pkg.files, npm);
|
|
2854
|
+
if (state.packed === true) return null;
|
|
2855
|
+
if (state.packed === 'unknown') {
|
|
2856
|
+
unchecked.push({file: logo.file, asset: rel, reason: state.error});
|
|
2857
|
+
return null;
|
|
2858
|
+
}
|
|
2859
|
+
return state.by === 'npm'
|
|
2860
|
+
? `${where} names ${rel}, which npm leaves out of the package`
|
|
2861
|
+
: `${where} names ${rel}, which no \`files\` entry packs`;
|
|
2862
|
+
};
|
|
2863
|
+
const light = problem(logo.light, `${logo.field}.light`);
|
|
2864
|
+
if (light != null) {
|
|
2865
|
+
notes.push({
|
|
2866
|
+
code: 'package_without_logo',
|
|
2867
|
+
message: `${light}, so a catalog that lists this package shows no logo beside its name. ${fix}`,
|
|
2868
|
+
});
|
|
2869
|
+
} else if (logo.dark !== undefined) {
|
|
2870
|
+
const dark = problem(logo.dark, `${logo.field}.dark`);
|
|
2871
|
+
if (dark != null) {
|
|
2872
|
+
notes.push({
|
|
2873
|
+
code: 'package_without_logo',
|
|
2874
|
+
message: `${dark}, so on a dark background a catalog shows no logo for this package. Fix: point \`${logo.field}.dark\` at a packed image, or remove it to use the light logo everywhere.`,
|
|
2875
|
+
});
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
if (examples != null && !examples.showcase && examples.needed > 0) {
|
|
2879
|
+
const {needed} = examples;
|
|
2880
|
+
notes.push({
|
|
2881
|
+
code: 'package_without_example',
|
|
2882
|
+
message: `The package contributes ${needed} component${needed === 1 ? '' : 's'} but no example block, so a catalog that lists it has nothing to preview. Fix: add a block template that renders one of them, with \`exampleFor: '<Component>'\` and \`isShowcase: true\` in its .doc.mjs; each \`component_without_example\` note gives the files to add.`,
|
|
2883
|
+
});
|
|
2884
|
+
}
|
|
2885
|
+
return {notes, unchecked};
|
|
2886
|
+
}
|
|
@@ -185,6 +185,12 @@ export function recentFailedInstall(version: string, cacheDir: string, now?: num
|
|
|
185
185
|
failures: number;
|
|
186
186
|
waitMs: number;
|
|
187
187
|
} | null;
|
|
188
|
+
/**
|
|
189
|
+
* This process's process-id space (Linux: the pid namespace), or null where
|
|
190
|
+
* process ids are one space for the whole computer.
|
|
191
|
+
* @returns {string | null}
|
|
192
|
+
*/
|
|
193
|
+
export function pidSpace(): string | null;
|
|
188
194
|
/**
|
|
189
195
|
* Is process `pid` on this computer still running?
|
|
190
196
|
* @param {number} pid
|
|
@@ -197,12 +203,25 @@ export function isAlive(pid: number): boolean;
|
|
|
197
203
|
* over at once, and one from another computer once its holder has stopped
|
|
198
204
|
* renewing it. Throws when the cache folder cannot be written.
|
|
199
205
|
* @param {string} lockDir
|
|
200
|
-
* @param {{now?: number}} [options] the clock, for tests
|
|
206
|
+
* @param {{now?: number, leased?: boolean}} [options] the clock, for tests;
|
|
207
|
+
* `leased` for a lock whose holder renews it (lock-lease.mjs): its record
|
|
208
|
+
* names its process space, and a holder on this computer that looks gone
|
|
209
|
+
* from another space (a container with the same computer name) is taken
|
|
210
|
+
* over only once its record has stood unrenewed for three renewals.
|
|
201
211
|
* @returns {boolean}
|
|
202
212
|
*/
|
|
203
|
-
export function tryLock(lockDir: string, { now }?: {
|
|
213
|
+
export function tryLock(lockDir: string, { now, leased }?: {
|
|
204
214
|
now?: number;
|
|
215
|
+
leased?: boolean;
|
|
205
216
|
}): boolean;
|
|
217
|
+
/**
|
|
218
|
+
* Which lock folder this is: its device, inode and creation time, and its
|
|
219
|
+
* owner record. A rename keeps them all; a lock made again in its place
|
|
220
|
+
* differs, even before it has a record. Null when there is no folder.
|
|
221
|
+
* @param {string} lockDir
|
|
222
|
+
* @returns {string | null}
|
|
223
|
+
*/
|
|
224
|
+
export function lockIdentity(lockDir: string): string | null;
|
|
206
225
|
/**
|
|
207
226
|
* Whether a process's arguments are this CLI's install of `version`, as
|
|
208
227
|
* runNpm starts it: the program (`argv[0]`) is npm, or a Node running npm's
|