@astryxdesign/cli 0.7.4 → 0.7.5-canary.07605c2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -18
- package/api/component/_adapter.mjs +16 -1
- package/api/component/component.test.mjs +31 -0
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +5 -2
- package/api/docs/_adapter.mjs +24 -16
- package/api/docs/docs.test.mjs +18 -0
- package/api/docs/integrationDocs.test.mjs +2 -2
- package/api/experimental.d.mts +5 -0
- package/api/experimental.mjs +15 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +16 -3
- package/api/icon/_authoring.d.mts +5 -1
- package/api/icon/_authoring.mjs +478 -63
- package/api/icon/_options.d.mts +11 -0
- package/api/icon/_options.mjs +39 -4
- package/api/icon/_records.d.mts +19 -0
- package/api/icon/_records.mjs +25 -0
- package/api/icon/add/add.d.mts +3 -3
- package/api/icon/add/add.mjs +227 -14
- package/api/icon/all-or-nothing.test.mjs +283 -0
- package/api/icon/detail/detail.mjs +2 -13
- package/api/icon/error-codes.test.mjs +14 -7
- package/api/icon/icon.d.mts +2 -2
- package/api/icon/icon.doc.mjs +30 -2
- package/api/icon/icon.mjs +57 -8
- package/api/icon/icon.test.mjs +133 -1
- package/api/icon/icon.type.d.mts +126 -1
- package/api/icon/icon.type.mjs +67 -3
- package/api/icon/iconAdd.doc.mjs +22 -6
- package/api/icon/iconMap.doc.mjs +24 -8
- package/api/icon/iconNewDefinition.doc.mjs +2 -2
- package/api/icon/iconNewSet.doc.mjs +30 -2
- package/api/icon/iconUse.doc.mjs +4 -1
- package/api/icon/map/map.d.mts +4 -4
- package/api/icon/map/map.mjs +134 -9
- package/api/icon/new-definition/new-definition.mjs +6 -2
- package/api/icon/new-set/new-set.mjs +2 -2
- package/api/icon/new-set/new-set.test.mjs +60 -10
- package/api/icon/option-pairs.test.mjs +368 -0
- package/api/icon/search/search.d.mts +10 -0
- package/api/icon/search/search.mjs +55 -14
- package/api/icon/use/use.mjs +2 -13
- package/api/integration/add-helpers.d.mts +15 -1
- package/api/integration/add-helpers.mjs +1 -1
- package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
- package/api/integration/pack-check.mjs +10 -4
- package/api/integration/pack-check.test.mjs +5 -1
- package/api/integration/validate-integration.type.d.mts +3 -2
- package/api/integration/validate-integration.type.mjs +3 -2
- package/api/render/_adapter.d.mts +28 -0
- package/api/render/_adapter.mjs +540 -0
- package/api/render/render.d.mts +15 -0
- package/api/render/render.doc.d.mts +9 -0
- package/api/render/render.doc.mjs +112 -0
- package/api/render/render.mjs +113 -0
- package/api/render/render.test.mjs +1155 -0
- package/api/render/render.type.d.mts +74 -0
- package/api/render/render.type.mjs +64 -0
- package/api/search/_adapter.test.mjs +21 -2
- package/api/search/_result.d.mts +5 -5
- package/api/search/search.d.mts +1 -1
- package/api/template/template.mjs +3 -1
- package/api/template/template.type.d.mts +2 -1
- package/api/template/template.type.mjs +1 -1
- package/api/template/unknown-name.test.mjs +63 -0
- package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +123 -70
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +19 -77
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
- package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +50 -20
- package/assets/docs/tree/render-pages.doc.mjs +94 -0
- package/assets/icons/definitions/activity.doc.mjs +1 -1
- package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
- package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
- package/assets/icons/definitions/alignStart.doc.mjs +10 -0
- package/assets/icons/definitions/archive.doc.mjs +1 -1
- package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
- package/assets/icons/definitions/attach.doc.mjs +1 -1
- package/assets/icons/definitions/audio.doc.mjs +1 -1
- package/assets/icons/definitions/cart.doc.mjs +1 -1
- package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
- package/assets/icons/definitions/close.doc.mjs +1 -1
- package/assets/icons/definitions/collapse.doc.mjs +1 -1
- package/assets/icons/definitions/compose.doc.mjs +1 -1
- package/assets/icons/definitions/conversation.doc.mjs +1 -1
- package/assets/icons/definitions/copy.doc.mjs +1 -1
- package/assets/icons/definitions/cpu.doc.mjs +9 -0
- package/assets/icons/definitions/database.doc.mjs +1 -1
- package/assets/icons/definitions/desktop.doc.mjs +1 -1
- package/assets/icons/definitions/discount.doc.mjs +1 -1
- package/assets/icons/definitions/download.doc.mjs +1 -1
- package/assets/icons/definitions/emoji.doc.mjs +1 -1
- package/assets/icons/definitions/error.doc.mjs +1 -1
- package/assets/icons/definitions/expand.doc.mjs +1 -1
- package/assets/icons/definitions/experiment.doc.mjs +1 -1
- package/assets/icons/definitions/externalLink.doc.mjs +7 -1
- package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
- package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
- package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
- package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
- package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
- package/assets/icons/definitions/gitFork.doc.mjs +9 -0
- package/assets/icons/definitions/info.doc.mjs +1 -1
- package/assets/icons/definitions/location.doc.mjs +1 -1
- package/assets/icons/definitions/mention.doc.mjs +1 -1
- package/assets/icons/definitions/menu.doc.mjs +1 -1
- package/assets/icons/definitions/microphone.doc.mjs +1 -1
- package/assets/icons/definitions/mobile.doc.mjs +1 -1
- package/assets/icons/definitions/money.doc.mjs +1 -1
- package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
- package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
- package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
- package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
- package/assets/icons/definitions/panelRight.doc.mjs +10 -0
- package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
- package/assets/icons/definitions/redo.doc.mjs +1 -1
- package/assets/icons/definitions/refresh.doc.mjs +1 -1
- package/assets/icons/definitions/rotate.doc.mjs +9 -0
- package/assets/icons/definitions/scale.doc.mjs +10 -0
- package/assets/icons/definitions/search.doc.mjs +1 -1
- package/assets/icons/definitions/send.doc.mjs +1 -1
- package/assets/icons/definitions/settings.doc.mjs +1 -1
- package/assets/icons/definitions/star.doc.mjs +1 -1
- package/assets/icons/definitions/stop.doc.mjs +1 -1
- package/assets/icons/definitions/success.doc.mjs +1 -1
- package/assets/icons/definitions/textCase.doc.mjs +9 -0
- package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
- package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
- package/assets/icons/definitions/trendDown.doc.mjs +7 -1
- package/assets/icons/definitions/trendUp.doc.mjs +1 -1
- package/assets/icons/definitions/undo.doc.mjs +1 -1
- package/assets/icons/definitions/upload.doc.mjs +1 -1
- package/assets/icons/definitions/userAdd.doc.mjs +1 -1
- package/assets/icons/definitions/warning.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +9 -8
- package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
- package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
- package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
- package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
- package/authoring/debug/parse.d.mts +2 -2
- package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
- package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
- package/authoring/doctypes/icon-set/parse.d.mts +1 -0
- package/authoring/doctypes/icon-set/parse.mjs +1 -0
- package/authoring/doctypes/icon-set/type.ts +5 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +2 -1
- package/clients/cli/commands/doctor.mjs +16 -17
- package/clients/cli/commands/experimental/icon.mjs +167 -35
- package/clients/cli/commands/experimental/index.mjs +2 -0
- package/clients/cli/commands/experimental/render.mjs +113 -0
- package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
- package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
- package/clients/cli/commands/experimental-render.doc.mjs +60 -0
- package/clients/cli/commands/experimental.doc.mjs +4 -2
- package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
- package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
- package/clients/cli/commands/icon.test.mjs +1 -1
- package/clients/cli/commands/template.mjs +4 -1
- package/clients/cli/commands/text-json-parity.test.mjs +46 -0
- package/clients/cli/index.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +2 -1
- package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
- package/foundation/discovery/component-discovery.mjs +13 -7
- package/foundation/discovery/icon-set-checks.d.mts +43 -9
- package/foundation/discovery/icon-set-checks.mjs +296 -21
- package/foundation/discovery/icon-set-checks.test.mjs +125 -12
- package/foundation/discovery/icon-set-writer.d.mts +192 -3
- package/foundation/discovery/icon-set-writer.mjs +608 -34
- package/foundation/discovery/icon-set-writer.test.mjs +26 -0
- package/foundation/discovery/module-exports.mjs +82 -25
- package/foundation/discovery/module-exports.test.mjs +38 -1
- package/foundation/discovery/package-exports.d.mts +13 -0
- package/foundation/discovery/package-exports.mjs +40 -1
- package/foundation/discovery/template-icons.d.mts +6 -0
- package/foundation/discovery/template-icons.mjs +98 -10
- package/foundation/discovery/template-icons.test.mjs +103 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +20 -5
- package/foundation/doc-compiler/import.mjs +81 -8
- package/foundation/doc-compiler/read.d.mts +4 -3
- package/foundation/doc-compiler/read.mjs +15 -10
- package/foundation/doc-compiler/read.test.mjs +59 -1
- package/foundation/doc-compiler/tree.mjs +3 -1
- package/foundation/fs/module-loader.d.mts +3 -2
- package/foundation/fs/module-loader.mjs +3 -2
- package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
- package/foundation/fs/read-record.d.mts +27 -0
- package/foundation/fs/read-record.mjs +83 -15
- package/foundation/fs/read-record.test.mjs +88 -1
- package/foundation/render/assets.d.mts +31 -0
- package/foundation/render/assets.mjs +102 -0
- package/foundation/render/component-map.d.mts +52 -0
- package/foundation/render/component-map.mjs +141 -0
- package/foundation/render/css-cut.d.mts +29 -0
- package/foundation/render/css-cut.mjs +144 -0
- package/foundation/render/embedded-files.d.mts +28 -0
- package/foundation/render/embedded-files.mjs +108 -0
- package/foundation/render/embedded-imports.d.mts +61 -0
- package/foundation/render/embedded-imports.mjs +315 -0
- package/foundation/render/html-reader.d.mts +37 -0
- package/foundation/render/html-reader.mjs +121 -0
- package/foundation/render/page-worker.d.mts +7 -0
- package/foundation/render/page-worker.mjs +519 -0
- package/foundation/render/rebuild.d.mts +19 -0
- package/foundation/render/rebuild.mjs +269 -0
- package/foundation/render/render-page.d.mts +85 -0
- package/foundation/render/render-page.mjs +612 -0
- package/foundation/render/render.test.mjs +117 -0
- package/foundation/render/source-block.d.mts +52 -0
- package/foundation/render/source-block.mjs +106 -0
- package/foundation/response/error-codes.d.mts +10 -1
- package/foundation/response/error-codes.doc.mjs +56 -0
- package/foundation/response/error-codes.mjs +61 -0
- package/foundation/response/response-types.doc.mjs +38 -1
- package/foundation/text/string-utils.mjs +33 -0
- package/foundation/text/string-utils.test.mjs +17 -0
- package/foundation/text/suggest-order.d.mts +17 -3
- package/foundation/text/suggest-order.mjs +58 -13
- package/foundation/text/suggest-order.test.mjs +53 -0
- package/package.json +14 -9
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Tests for the render helpers: the CSS cut, the embedded source, the
|
|
5
|
+
* HTML reader, and the time limit.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as fs from 'node:fs';
|
|
9
|
+
import {fileURLToPath} from 'node:url';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import {describe, expect, it} from 'vitest';
|
|
12
|
+
import {classesIn, cutCss, layerOrderOf, requiredClasses} from './css-cut.mjs';
|
|
13
|
+
import {readSourceBlock, sourceBlock} from './source-block.mjs';
|
|
14
|
+
import {isAstryxMarkup, parseHtml} from './html-reader.mjs';
|
|
15
|
+
import {renderPage} from './render-page.mjs';
|
|
16
|
+
|
|
17
|
+
describe('requiredClasses with grouped selectors', () => {
|
|
18
|
+
it('keeps a rule whose :is() or :where() alternatives are not all used', async () => {
|
|
19
|
+
const {cutCss} = await import('./css-cut.mjs');
|
|
20
|
+
const css = '.a:is(.b, .c) { color: red; } :where(.x, .y) .z { color: blue; } .gone { color: green; }';
|
|
21
|
+
const out = cutCss(css, new Set(['a', 'b', 'z']));
|
|
22
|
+
expect(out).toContain('color: red');
|
|
23
|
+
expect(out).toContain('color: blue');
|
|
24
|
+
expect(out).not.toContain('color: green');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('cutCss', () => {
|
|
29
|
+
const css = `/* @layer comment, not, order; */
|
|
30
|
+
@layer reset, base;
|
|
31
|
+
:root { --c: light-dark(#000, #fff); }
|
|
32
|
+
@property --x { syntax: '<length>'; inherits: false; initial-value: 0px; }
|
|
33
|
+
@keyframes spin { to { transform: rotate(1turn); } }
|
|
34
|
+
@keyframes unused { to { opacity: 0; } }
|
|
35
|
+
@layer base {
|
|
36
|
+
.a { color: red; }
|
|
37
|
+
.b .c { color: blue; }
|
|
38
|
+
.a:not(.zzz) { margin: 0; }
|
|
39
|
+
.gone, .a.d { padding: 0; }
|
|
40
|
+
@media (min-width: 1px) { .gone { color: red; } }
|
|
41
|
+
.spin { animation-name: spin; }
|
|
42
|
+
}`;
|
|
43
|
+
|
|
44
|
+
it('keeps used rules, tokens, properties and named keyframes', () => {
|
|
45
|
+
const out = cutCss(css, new Set(['a', 'spin']));
|
|
46
|
+
expect(out).toContain('.a { color: red; }');
|
|
47
|
+
expect(out).toContain('.a:not(.zzz)');
|
|
48
|
+
expect(out).toContain('--c: light-dark(#000, #fff)');
|
|
49
|
+
expect(out).toContain('@property --x');
|
|
50
|
+
expect(out).toContain('@keyframes spin');
|
|
51
|
+
expect(out).not.toContain('unused');
|
|
52
|
+
expect(out).not.toContain('.b .c');
|
|
53
|
+
expect(out).not.toContain('.gone');
|
|
54
|
+
expect(out).not.toContain('@media');
|
|
55
|
+
expect(out).not.toMatch(/@layer reset, base;/);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('reads the layer order, ignoring comments', () => {
|
|
59
|
+
expect(layerOrderOf(css)).toBe('@layer reset, base;');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('needs every class in a selector, except inside :not()', () => {
|
|
63
|
+
expect(requiredClasses('.a .b:hover:not(.c)')).toEqual(['a', 'b']);
|
|
64
|
+
expect(requiredClasses('.x\\:y')).toEqual(['x:y']);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('reads class names from markup', () => {
|
|
68
|
+
expect([...classesIn('<div class="a b"><p class="c"></p></div>')]).toEqual(['a', 'b', 'c']);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('the embedded source', () => {
|
|
73
|
+
it('round-trips any bytes, even text that would end a script', () => {
|
|
74
|
+
const bytes = Buffer.from('const s = "</script><!--";\r\n// ünïcode ✓\u2028', 'utf8');
|
|
75
|
+
const block = sourceBlock('page.tsx', [{path: 'page.tsx', bytes}]);
|
|
76
|
+
expect(block.match(/<\/script>/g)).toHaveLength(1);
|
|
77
|
+
const read = readSourceBlock(`<body><p>x</p>${block}</body>`);
|
|
78
|
+
expect(read.found && 'source' in read && Buffer.from(read.source.files[0].base64, 'base64')).toEqual(bytes);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('reports a damaged block', () => {
|
|
82
|
+
const block = sourceBlock('p.tsx', [{path: 'p.tsx', bytes: Buffer.from('a')}]);
|
|
83
|
+
expect(readSourceBlock(block.replace(/"sha256":"[0-9a-f]/, '"sha256":"Z'))).toMatchObject({found: true});
|
|
84
|
+
expect('damaged' in readSourceBlock(block.replace('"version":1', '"version":2'))).toBe(true);
|
|
85
|
+
expect(readSourceBlock('<p>none</p>')).toEqual({found: false});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('the HTML reader', () => {
|
|
90
|
+
it('parses rendered markup', () => {
|
|
91
|
+
const doc = parseHtml('<!doctype html><body><div class="astryx-card" data-x="1">a & b<br><img src="x"></div></body>');
|
|
92
|
+
const body = /** @type {any} */ (doc.children[0]);
|
|
93
|
+
expect(body.tag).toBe('body');
|
|
94
|
+
expect(body.children[0].attrs).toEqual({class: 'astryx-card', 'data-x': '1'});
|
|
95
|
+
expect(body.children[0].children[0].text).toBe('a & b');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('tells Astryx markup from other HTML', () => {
|
|
99
|
+
expect(isAstryxMarkup('<div class="x astryx-button"></div>')).toBe(true);
|
|
100
|
+
expect(isAstryxMarkup('<div class="button"></div>')).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('renderPage time limit', () => {
|
|
105
|
+
it('stops a page that never finishes rendering', async () => {
|
|
106
|
+
const dir = fs.mkdtempSync(
|
|
107
|
+
path.join(path.dirname(fileURLToPath(import.meta.url)), '../../.astryx-render-loop-'),
|
|
108
|
+
);
|
|
109
|
+
try {
|
|
110
|
+
const file = path.join(dir, 'loop.jsx');
|
|
111
|
+
fs.writeFileSync(file, 'export default function Page() { for (;;) {} }\n');
|
|
112
|
+
await expect(renderPage(file, {timeoutMs: 1500})).rejects.toMatchObject({code: 'ERR_RENDER_TIMEOUT'});
|
|
113
|
+
} finally {
|
|
114
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
115
|
+
}
|
|
116
|
+
}, 30_000);
|
|
117
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The data block for a page's files.
|
|
6
|
+
* @param {string} entry the page's file name
|
|
7
|
+
* @param {{path: string, bytes: Buffer}[]} files the page first
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
export function sourceBlock(entry: string, files: {
|
|
11
|
+
path: string;
|
|
12
|
+
bytes: Buffer;
|
|
13
|
+
}[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Read the embedded source from a rendered file.
|
|
16
|
+
* @param {string} html
|
|
17
|
+
* @returns {{found: false} | {found: true, source: EmbeddedSource} | {found: true, damaged: string}}
|
|
18
|
+
*/
|
|
19
|
+
export function readSourceBlock(html: string): {
|
|
20
|
+
found: false;
|
|
21
|
+
} | {
|
|
22
|
+
found: true;
|
|
23
|
+
source: EmbeddedSource;
|
|
24
|
+
} | {
|
|
25
|
+
found: true;
|
|
26
|
+
damaged: string;
|
|
27
|
+
};
|
|
28
|
+
/** The script type of the embedded-source block. */
|
|
29
|
+
export const SOURCE_TYPE: "application/x-astryx-source";
|
|
30
|
+
export function sha256(bytes: Buffer): string;
|
|
31
|
+
export type EmbeddedFile = {
|
|
32
|
+
/**
|
|
33
|
+
* - Path relative to the folder that holds every embedded file, `/`-separated; the page itself first.
|
|
34
|
+
*/
|
|
35
|
+
path: string;
|
|
36
|
+
/**
|
|
37
|
+
* - SHA-256 of the file's bytes, hex.
|
|
38
|
+
*/
|
|
39
|
+
sha256: string;
|
|
40
|
+
/**
|
|
41
|
+
* - The file's bytes.
|
|
42
|
+
*/
|
|
43
|
+
base64: string;
|
|
44
|
+
};
|
|
45
|
+
export type EmbeddedSource = {
|
|
46
|
+
version: 1;
|
|
47
|
+
/**
|
|
48
|
+
* - The page's file name.
|
|
49
|
+
*/
|
|
50
|
+
entry: string;
|
|
51
|
+
files: EmbeddedFile[];
|
|
52
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The page source a rendered file carries, so `astryx experimental
|
|
5
|
+
* render --reverse` can give it back byte for byte. It is one
|
|
6
|
+
* `<script type="application/x-astryx-source">` data block: browsers never run
|
|
7
|
+
* it, and its JSON holds each file base64-encoded with its SHA-256, so no text
|
|
8
|
+
* in the source (`</script>` included) can end the block early.
|
|
9
|
+
*
|
|
10
|
+
* @position foundation/render — used by render-page.mjs and the render subject
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {createHash} from 'node:crypto';
|
|
14
|
+
|
|
15
|
+
/** The script type of the embedded-source block. */
|
|
16
|
+
export const SOURCE_TYPE = 'application/x-astryx-source';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {object} EmbeddedFile
|
|
20
|
+
* @property {string} path - Path relative to the folder that holds every embedded file, `/`-separated; the page itself first.
|
|
21
|
+
* @property {string} sha256 - SHA-256 of the file's bytes, hex.
|
|
22
|
+
* @property {string} base64 - The file's bytes.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {object} EmbeddedSource
|
|
27
|
+
* @property {1} version
|
|
28
|
+
* @property {string} entry - The page's file name.
|
|
29
|
+
* @property {EmbeddedFile[]} files
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** @param {Buffer} bytes */
|
|
33
|
+
export const sha256 = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The data block for a page's files.
|
|
37
|
+
* @param {string} entry the page's file name
|
|
38
|
+
* @param {{path: string, bytes: Buffer}[]} files the page first
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
export function sourceBlock(entry, files) {
|
|
42
|
+
/** @type {EmbeddedSource} */
|
|
43
|
+
const payload = {
|
|
44
|
+
version: 1,
|
|
45
|
+
entry,
|
|
46
|
+
files: files.map(f => ({
|
|
47
|
+
path: f.path,
|
|
48
|
+
sha256: sha256(f.bytes),
|
|
49
|
+
base64: f.bytes.toString('base64'),
|
|
50
|
+
})),
|
|
51
|
+
};
|
|
52
|
+
const json = JSON.stringify(payload)
|
|
53
|
+
.replace(/</g, '\\u003c')
|
|
54
|
+
.replace(/>/g, '\\u003e')
|
|
55
|
+
.replace(/&/g, '\\u0026');
|
|
56
|
+
return `<script type="${SOURCE_TYPE}">${json}</script>`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Read the embedded source from a rendered file.
|
|
61
|
+
* @param {string} html
|
|
62
|
+
* @returns {{found: false} | {found: true, source: EmbeddedSource} | {found: true, damaged: string}}
|
|
63
|
+
*/
|
|
64
|
+
export function readSourceBlock(html) {
|
|
65
|
+
const all = [
|
|
66
|
+
...html.matchAll(
|
|
67
|
+
new RegExp(
|
|
68
|
+
`<script\\s+type=["']${SOURCE_TYPE.replace(/[/+.-]/g, c => `\\${c}`)}["'][^>]*>([\\s\\S]*?)</script>`,
|
|
69
|
+
'gi',
|
|
70
|
+
),
|
|
71
|
+
),
|
|
72
|
+
];
|
|
73
|
+
// The block is written last in the body; a page's own markup cannot end
|
|
74
|
+
// it, so the last one is the CLI's.
|
|
75
|
+
const m = all.at(-1);
|
|
76
|
+
if (!m) return {found: false};
|
|
77
|
+
/** @type {any} */
|
|
78
|
+
let payload;
|
|
79
|
+
try {
|
|
80
|
+
payload = JSON.parse(m[1]);
|
|
81
|
+
} catch {
|
|
82
|
+
return {found: true, damaged: 'its embedded source is not valid JSON'};
|
|
83
|
+
}
|
|
84
|
+
if (
|
|
85
|
+
payload?.version !== 1 ||
|
|
86
|
+
typeof payload.entry !== 'string' ||
|
|
87
|
+
!Array.isArray(payload.files) ||
|
|
88
|
+
payload.files.length === 0
|
|
89
|
+
) {
|
|
90
|
+
return {found: true, damaged: 'its embedded source has an unknown shape'};
|
|
91
|
+
}
|
|
92
|
+
for (const f of payload.files) {
|
|
93
|
+
if (
|
|
94
|
+
typeof f?.path !== 'string' ||
|
|
95
|
+
typeof f.base64 !== 'string' ||
|
|
96
|
+
typeof f.sha256 !== 'string' ||
|
|
97
|
+
sha256(Buffer.from(f.base64, 'base64')) !== f.sha256
|
|
98
|
+
) {
|
|
99
|
+
return {
|
|
100
|
+
found: true,
|
|
101
|
+
damaged: `its embedded copy of ${String(f?.path ?? 'a file')} does not match its checksum`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return {found: true, source: payload};
|
|
106
|
+
}
|
|
@@ -101,6 +101,15 @@ export function allErrorCodes(): string[];
|
|
|
101
101
|
* | 'ERR_SIGNAL_TERMINATED'
|
|
102
102
|
* | 'ERR_VERSIONS_UNAVAILABLE'
|
|
103
103
|
* | 'ERR_PROJECT_REQUIRED'
|
|
104
|
+
* | 'ERR_RENDER_COMPILE'
|
|
105
|
+
* | 'ERR_RENDER_NO_DEFAULT_EXPORT'
|
|
106
|
+
* | 'ERR_RENDER_MISSING_DEPENDENCY'
|
|
107
|
+
* | 'ERR_RENDER_BROWSER_API'
|
|
108
|
+
* | 'ERR_RENDER_ASSET_TOO_LARGE'
|
|
109
|
+
* | 'ERR_RENDER_TIMEOUT'
|
|
110
|
+
* | 'ERR_RENDER_FAILED'
|
|
111
|
+
* | 'ERR_RENDER_NOT_ASTRYX'
|
|
112
|
+
* | 'ERR_RENDER_SOURCE_DAMAGED'
|
|
104
113
|
* )} ErrorCode
|
|
105
114
|
*/
|
|
106
115
|
/**
|
|
@@ -111,4 +120,4 @@ export const ERROR_CODES: Readonly<Record<ErrorCode, ErrorCode>>;
|
|
|
111
120
|
/**
|
|
112
121
|
* Stable error-code string union. Append-only.
|
|
113
122
|
*/
|
|
114
|
-
export type ErrorCode = ("ERR_UNKNOWN" | "ERR_UNKNOWN_COMMAND" | "ERR_UNKNOWN_SUBCOMMAND" | "ERR_INVALID_OPTION" | "ERR_INVALID_ARGUMENT" | "ERR_MISSING_ARGUMENT" | "ERR_INVALID_LANG" | "ERR_INVALID_DETAIL" | "ERR_NODE_VERSION" | "ERR_CORE_NOT_FOUND" | "ERR_CORE_INCOMPATIBLE" | "ERR_UNKNOWN_COMPONENT" | "ERR_UNKNOWN_HOOK" | "ERR_UNKNOWN_TOPIC" | "ERR_UNKNOWN_SECTION" | "ERR_UNKNOWN_CATEGORY" | "ERR_UNKNOWN_TEMPLATE" | "ERR_AMBIGUOUS_TEMPLATE" | "ERR_AMBIGUOUS_COMPONENT" | "ERR_AMBIGUOUS_THEME" | "ERR_UNKNOWN_THEME" | "ERR_INTEGRATION_ROOT_CONFLICT" | "ERR_INTEGRATION_EXPORT_CONFLICT" | "ERR_UNKNOWN_PACKAGE" | "ERR_UNKNOWN_AGENT" | "ERR_UNKNOWN_FEATURE" | "ERR_UNKNOWN_CODEMOD" | "ERR_CODEMOD_FAILED" | "ERR_CODEMOD_PROTECTED" | "ERR_CODEMOD_PROTECTION_SOURCE" | "ERR_NOT_FOUND" | "ERR_NO_DOC" | "ERR_NO_SHOWCASE" | "ERR_NO_SOURCE" | "ERR_INVALID_DOC" | "ERR_FILE_NOT_FOUND" | "ERR_FILE_EXISTS" | "ERR_PATH_TRAVERSAL" | "ERR_WRITE_FAILED" | "ERR_THEME_INVALID" | "ERR_THEME_LOAD" | "ERR_PALETTE_GENERATION" | "ERR_VERSION_DETECT" | "ERR_INVALID_VERSION" | "ERR_DEP_MISSING" | "ERR_GH_CLI" | "ERR_UNKNOWN_POST" | "ERR_FETCH_FAILED" | "ERR_LAYOUT_PARSE" | "ERR_LAYOUT_INVALID" | "ERR_UNCLASSIFIED_EXIT" | "ERR_SIGNAL_TERMINATED" | "ERR_VERSIONS_UNAVAILABLE" | "ERR_PROJECT_REQUIRED");
|
|
123
|
+
export type ErrorCode = ("ERR_UNKNOWN" | "ERR_UNKNOWN_COMMAND" | "ERR_UNKNOWN_SUBCOMMAND" | "ERR_INVALID_OPTION" | "ERR_INVALID_ARGUMENT" | "ERR_MISSING_ARGUMENT" | "ERR_INVALID_LANG" | "ERR_INVALID_DETAIL" | "ERR_NODE_VERSION" | "ERR_CORE_NOT_FOUND" | "ERR_CORE_INCOMPATIBLE" | "ERR_UNKNOWN_COMPONENT" | "ERR_UNKNOWN_HOOK" | "ERR_UNKNOWN_TOPIC" | "ERR_UNKNOWN_SECTION" | "ERR_UNKNOWN_CATEGORY" | "ERR_UNKNOWN_TEMPLATE" | "ERR_AMBIGUOUS_TEMPLATE" | "ERR_AMBIGUOUS_COMPONENT" | "ERR_AMBIGUOUS_THEME" | "ERR_UNKNOWN_THEME" | "ERR_INTEGRATION_ROOT_CONFLICT" | "ERR_INTEGRATION_EXPORT_CONFLICT" | "ERR_UNKNOWN_PACKAGE" | "ERR_UNKNOWN_AGENT" | "ERR_UNKNOWN_FEATURE" | "ERR_UNKNOWN_CODEMOD" | "ERR_CODEMOD_FAILED" | "ERR_CODEMOD_PROTECTED" | "ERR_CODEMOD_PROTECTION_SOURCE" | "ERR_NOT_FOUND" | "ERR_NO_DOC" | "ERR_NO_SHOWCASE" | "ERR_NO_SOURCE" | "ERR_INVALID_DOC" | "ERR_FILE_NOT_FOUND" | "ERR_FILE_EXISTS" | "ERR_PATH_TRAVERSAL" | "ERR_WRITE_FAILED" | "ERR_THEME_INVALID" | "ERR_THEME_LOAD" | "ERR_PALETTE_GENERATION" | "ERR_VERSION_DETECT" | "ERR_INVALID_VERSION" | "ERR_DEP_MISSING" | "ERR_GH_CLI" | "ERR_UNKNOWN_POST" | "ERR_FETCH_FAILED" | "ERR_LAYOUT_PARSE" | "ERR_LAYOUT_INVALID" | "ERR_UNCLASSIFIED_EXIT" | "ERR_SIGNAL_TERMINATED" | "ERR_VERSIONS_UNAVAILABLE" | "ERR_PROJECT_REQUIRED" | "ERR_RENDER_COMPILE" | "ERR_RENDER_NO_DEFAULT_EXPORT" | "ERR_RENDER_MISSING_DEPENDENCY" | "ERR_RENDER_BROWSER_API" | "ERR_RENDER_ASSET_TOO_LARGE" | "ERR_RENDER_TIMEOUT" | "ERR_RENDER_FAILED" | "ERR_RENDER_NOT_ASTRYX" | "ERR_RENDER_SOURCE_DAMAGED");
|
|
@@ -289,5 +289,61 @@ export const doc = {
|
|
|
289
289
|
description:
|
|
290
290
|
'The command needs a project (an app with Astryx installed, or an integration package) and was run outside one. Nothing was written.',
|
|
291
291
|
},
|
|
292
|
+
|
|
293
|
+
// Render (experimental: may change or be removed in a patch release)
|
|
294
|
+
{
|
|
295
|
+
value: 'ERR_RENDER_COMPILE',
|
|
296
|
+
stability: 'experimental',
|
|
297
|
+
description:
|
|
298
|
+
'The page given to render does not compile. A stylesheet the page imports that is not valid CSS is reported this way too, naming the file. Nothing was written. Raised only by the experimental render command.',
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
value: 'ERR_RENDER_NO_DEFAULT_EXPORT',
|
|
302
|
+
stability: 'experimental',
|
|
303
|
+
description:
|
|
304
|
+
'The page given to render has no default export to render. Nothing was written. Raised only by the experimental render command.',
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
value: 'ERR_RENDER_MISSING_DEPENDENCY',
|
|
308
|
+
stability: 'experimental',
|
|
309
|
+
description:
|
|
310
|
+
'The page imports a package that is not installed where the page is. Nothing was written. Raised only by the experimental render command.',
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
value: 'ERR_RENDER_BROWSER_API',
|
|
314
|
+
stability: 'experimental',
|
|
315
|
+
description:
|
|
316
|
+
'The page reads a browser-only API, such as window or document, while rendering. Nothing was written. Raised only by the experimental render command.',
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
value: 'ERR_RENDER_ASSET_TOO_LARGE',
|
|
320
|
+
stability: 'experimental',
|
|
321
|
+
description:
|
|
322
|
+
'A local file the page uses is too large to inline into one file. Nothing was written. Raised only by the experimental render command.',
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
value: 'ERR_RENDER_TIMEOUT',
|
|
326
|
+
stability: 'experimental',
|
|
327
|
+
description:
|
|
328
|
+
'The page did not finish rendering in time and was stopped. Nothing was written. Raised only by the experimental render command.',
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
value: 'ERR_RENDER_FAILED',
|
|
332
|
+
stability: 'experimental',
|
|
333
|
+
description:
|
|
334
|
+
'The page threw while rendering. Nothing was written. Raised only by the experimental render command.',
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
value: 'ERR_RENDER_NOT_ASTRYX',
|
|
338
|
+
stability: 'experimental',
|
|
339
|
+
description:
|
|
340
|
+
'`render --reverse` was given a file with no embedded source and no Astryx markup. Nothing was written. Raised only by the experimental render command.',
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
value: 'ERR_RENDER_SOURCE_DAMAGED',
|
|
344
|
+
stability: 'experimental',
|
|
345
|
+
description:
|
|
346
|
+
'`render --reverse` refused the received file, and nothing was written: its embedded source is damaged (not valid, or a file does not match its checksum), lists a path twice, carries a module, stylesheet or JSON file the page does not reach through its own imports, or an image, font or media file whose bytes are not one, or carries a file a render never embeds: a dotfile or dot-folder, anything under node_modules, a package manifest, lockfile or tool configuration, a file a test, story or benchmark runner would run, or any kind but a page module, stylesheet, JSON file or image. Raised only by the experimental render command.',
|
|
347
|
+
},
|
|
292
348
|
],
|
|
293
349
|
};
|
|
@@ -90,6 +90,15 @@
|
|
|
90
90
|
* | 'ERR_SIGNAL_TERMINATED'
|
|
91
91
|
* | 'ERR_VERSIONS_UNAVAILABLE'
|
|
92
92
|
* | 'ERR_PROJECT_REQUIRED'
|
|
93
|
+
* | 'ERR_RENDER_COMPILE'
|
|
94
|
+
* | 'ERR_RENDER_NO_DEFAULT_EXPORT'
|
|
95
|
+
* | 'ERR_RENDER_MISSING_DEPENDENCY'
|
|
96
|
+
* | 'ERR_RENDER_BROWSER_API'
|
|
97
|
+
* | 'ERR_RENDER_ASSET_TOO_LARGE'
|
|
98
|
+
* | 'ERR_RENDER_TIMEOUT'
|
|
99
|
+
* | 'ERR_RENDER_FAILED'
|
|
100
|
+
* | 'ERR_RENDER_NOT_ASTRYX'
|
|
101
|
+
* | 'ERR_RENDER_SOURCE_DAMAGED'
|
|
93
102
|
* )} ErrorCode
|
|
94
103
|
*/
|
|
95
104
|
|
|
@@ -253,6 +262,58 @@ export const ERROR_CODES = Object.freeze({
|
|
|
253
262
|
* integration package) and was run outside one. Nothing was written.
|
|
254
263
|
*/
|
|
255
264
|
ERR_PROJECT_REQUIRED: 'ERR_PROJECT_REQUIRED',
|
|
265
|
+
|
|
266
|
+
// ── Render (experimental) ────────────────────────────────────────
|
|
267
|
+
/**
|
|
268
|
+
* The page given to `astryx experimental render` does not compile (a syntax
|
|
269
|
+
* or type-syntax error). Nothing was written.
|
|
270
|
+
*/
|
|
271
|
+
ERR_RENDER_COMPILE: 'ERR_RENDER_COMPILE',
|
|
272
|
+
/**
|
|
273
|
+
* The page module has no default export to render. Nothing was written.
|
|
274
|
+
*/
|
|
275
|
+
ERR_RENDER_NO_DEFAULT_EXPORT: 'ERR_RENDER_NO_DEFAULT_EXPORT',
|
|
276
|
+
/**
|
|
277
|
+
* The page imports a package that is not installed where the page is.
|
|
278
|
+
* Nothing was written.
|
|
279
|
+
*/
|
|
280
|
+
ERR_RENDER_MISSING_DEPENDENCY: 'ERR_RENDER_MISSING_DEPENDENCY',
|
|
281
|
+
/**
|
|
282
|
+
* The page reads a browser-only API (window, document, …) while rendering,
|
|
283
|
+
* and a rendered page has no browser yet. Nothing was written.
|
|
284
|
+
*/
|
|
285
|
+
ERR_RENDER_BROWSER_API: 'ERR_RENDER_BROWSER_API',
|
|
286
|
+
/**
|
|
287
|
+
* A local file the page uses is too large to inline into one HTML file.
|
|
288
|
+
* Nothing was written.
|
|
289
|
+
*/
|
|
290
|
+
ERR_RENDER_ASSET_TOO_LARGE: 'ERR_RENDER_ASSET_TOO_LARGE',
|
|
291
|
+
/**
|
|
292
|
+
* The page did not finish rendering in time and was stopped. Nothing was
|
|
293
|
+
* written.
|
|
294
|
+
*/
|
|
295
|
+
ERR_RENDER_TIMEOUT: 'ERR_RENDER_TIMEOUT',
|
|
296
|
+
/**
|
|
297
|
+
* The page threw while rendering for any other reason. Nothing was written.
|
|
298
|
+
*/
|
|
299
|
+
ERR_RENDER_FAILED: 'ERR_RENDER_FAILED',
|
|
300
|
+
/**
|
|
301
|
+
* `render --reverse` was given an HTML file that holds no Astryx markup and
|
|
302
|
+
* no embedded source, so there is nothing to rebuild. Nothing was written.
|
|
303
|
+
*/
|
|
304
|
+
ERR_RENDER_NOT_ASTRYX: 'ERR_RENDER_NOT_ASTRYX',
|
|
305
|
+
/**
|
|
306
|
+
* `render --reverse` refused the received file: its embedded source is
|
|
307
|
+
* damaged (not valid, or a file does not match its checksum), lists a path
|
|
308
|
+
* twice, carries a module, stylesheet or JSON file the page does not
|
|
309
|
+
* import or an image, font or media file whose bytes are not one, or
|
|
310
|
+
* carries a file a
|
|
311
|
+
* render never embeds (a dotfile, node_modules, a manifest, lockfile or
|
|
312
|
+
* tool configuration, a file a test, story or benchmark runner would run,
|
|
313
|
+
* or any kind but a page module, stylesheet, JSON file or image). Nothing
|
|
314
|
+
* was written.
|
|
315
|
+
*/
|
|
316
|
+
ERR_RENDER_SOURCE_DAMAGED: 'ERR_RENDER_SOURCE_DAMAGED',
|
|
256
317
|
});
|
|
257
318
|
|
|
258
319
|
/**
|
|
@@ -112,6 +112,19 @@ export const doc = {
|
|
|
112
112
|
description:
|
|
113
113
|
"One post's metadata plus the feed URL and the post's full plaintext body.",
|
|
114
114
|
},
|
|
115
|
+
// render (experimental: may change or be removed in a patch release)
|
|
116
|
+
{
|
|
117
|
+
value: 'render.page',
|
|
118
|
+
stability: 'experimental',
|
|
119
|
+
description:
|
|
120
|
+
'A page rendered to one self-contained file: `input`, `output`, `bytes`, the local files embedded (`files`: modules, stylesheets, images and JSON), the package `stylesheets` cut and inlined, `classes`, `cssBytes`, `images` inlined, and `warnings` (`{code, message}`; empty when nothing looked wrong). Experimental: may change or be removed in a patch release.',
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
value: 'render.reverse',
|
|
124
|
+
stability: 'experimental',
|
|
125
|
+
description:
|
|
126
|
+
'A rendered file turned back into a page: `input`, `mode` (`embedded`: the embedded source written back byte for byte; `rebuilt`: rebuilt from Astryx markup, text and layout only), `output`, every file written (`files`), `exact`, the relative imports it did not carry (`missing`, when any), and for a rebuilt page `components`, `elements`, `unknown` and `omitted`. Experimental: may change or be removed in a patch release.',
|
|
127
|
+
},
|
|
115
128
|
|
|
116
129
|
// experimental icon (installed icon sets, AST-084): experimental values,
|
|
117
130
|
// documented under `astryx docs cli/experimental`, not in this table.
|
|
@@ -139,6 +152,12 @@ export const doc = {
|
|
|
139
152
|
description:
|
|
140
153
|
'The `experimental.iconSet` written to astryx.config, the set it names as `<package>/<set>`, the config file, whether it was created, the value it replaced, and whether anything changed.',
|
|
141
154
|
},
|
|
155
|
+
{
|
|
156
|
+
value: 'icon.mapMany',
|
|
157
|
+
stability: 'experimental',
|
|
158
|
+
description:
|
|
159
|
+
'Many `map` entries written at once (--pairs): the set, its package, the data file, each entry {definition, icon, previous, changed}, whether anything changed, and the generated files rewritten.',
|
|
160
|
+
},
|
|
142
161
|
{
|
|
143
162
|
value: 'icon.map',
|
|
144
163
|
stability: 'experimental',
|
|
@@ -151,6 +170,24 @@ export const doc = {
|
|
|
151
170
|
description:
|
|
152
171
|
"One icon registered in the icon set being authored: the set, its package, the icon {id, export, module}, the variant when it was added as one, the definition mapped to it, the definition file written when it added the set's own, the files written, and whether anything changed.",
|
|
153
172
|
},
|
|
173
|
+
{
|
|
174
|
+
value: 'icon.definitions',
|
|
175
|
+
stability: 'experimental',
|
|
176
|
+
description:
|
|
177
|
+
'Every Astryx icon definition (--definitions): each {name, builtIn, description, words}.',
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
value: 'icon.setIcons',
|
|
181
|
+
stability: 'experimental',
|
|
182
|
+
description:
|
|
183
|
+
'Every icon of one set (--set with --all-icons): the set, its package, how many icons, and each icon {id, export, words, definitions}, by id.',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
value: 'icon.addVariants',
|
|
187
|
+
stability: 'experimental',
|
|
188
|
+
description:
|
|
189
|
+
'One variant added for every icon of the set at once (--all): the set, its package, the variant, the module read, how many icons gained it, how many already had it, the ids the module has no export for, the files written, and whether anything changed.',
|
|
190
|
+
},
|
|
154
191
|
{
|
|
155
192
|
value: 'icon.definitionMatches',
|
|
156
193
|
stability: 'experimental',
|
|
@@ -189,7 +226,7 @@ export const doc = {
|
|
|
189
226
|
{
|
|
190
227
|
value: 'discover.item',
|
|
191
228
|
description:
|
|
192
|
-
|
|
229
|
+
"One item that is not an installed component, for an @scope/name/<item> query: its kind, name, package, version, and whether the project has the package. The envelope's package names the same package.",
|
|
193
230
|
},
|
|
194
231
|
{
|
|
195
232
|
value: 'discover.search',
|
|
@@ -209,6 +209,39 @@ export async function searchComponents(needle, coreDir, components) {
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
// --- Pass 3: a name made of other words around a component's name ---
|
|
213
|
+
// Only when nothing above matched: a contiguous run of the needle's words
|
|
214
|
+
// ("Primitive Button", "Meta Employee Typeahead") that is a component's
|
|
215
|
+
// whole name. Longer runs and runs nearer the end score higher.
|
|
216
|
+
if (scored.size === 0) {
|
|
217
|
+
const words = String(needle)
|
|
218
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
219
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1 $2')
|
|
220
|
+
.toLowerCase()
|
|
221
|
+
.split(/[^a-z0-9]+/)
|
|
222
|
+
.filter(Boolean);
|
|
223
|
+
const byLower = new Map(allNames.map(n => [n.toLowerCase(), n]));
|
|
224
|
+
const longest = Math.max(0, ...allNames.map(n => n.length));
|
|
225
|
+
for (let i = 0; i < words.length; i++) {
|
|
226
|
+
let run = '';
|
|
227
|
+
for (let j = i + 1; j <= words.length; j++) {
|
|
228
|
+
// Grow the run one word at a time; stop once no name is that long.
|
|
229
|
+
run += words[j - 1];
|
|
230
|
+
if (run.length > longest) break;
|
|
231
|
+
if (run.length < 4 || run === term) continue;
|
|
232
|
+
const comp = byLower.get(run);
|
|
233
|
+
if (!comp) continue;
|
|
234
|
+
const span = j - i;
|
|
235
|
+
const atEnd = j === words.length ? 1 : 0;
|
|
236
|
+
addMatch(comp, 10 + Math.min(span, 4) + atEnd, 'name part "' + run + '"');
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// Keep only the strongest name parts, so a weaker part never sits
|
|
240
|
+
// beside the best one.
|
|
241
|
+
const best = Math.max(0, ...[...scored.values()].map(r => r.score));
|
|
242
|
+
for (const [name, r] of scored) if (r.score < best) scored.delete(name);
|
|
243
|
+
}
|
|
244
|
+
|
|
212
245
|
const results = Array.from(scored.values())
|
|
213
246
|
.map(r =>
|
|
214
247
|
keywordAt.has(r.name)
|
|
@@ -116,6 +116,23 @@ describe('searchComponents', () => {
|
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
+
it('suggests a component whose whole name is a run of the needle\'s words when nothing else matches', async () => {
|
|
120
|
+
const results = await searchComponents('FancyWidgetPanel', NO_CORE, {
|
|
121
|
+
g: ['Panel', 'Widget', 'Sheet'],
|
|
122
|
+
});
|
|
123
|
+
expect(results.map(r => r.name)).toEqual(['Panel']);
|
|
124
|
+
expect(results[0].reason).toBe('name part "panel"');
|
|
125
|
+
expect(results.every(r => r.score < 20)).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('adds no name-part matches when another signal matched', async () => {
|
|
129
|
+
const results = await searchComponents('Panl', NO_CORE, {
|
|
130
|
+
g: ['Panel', 'Sheet'],
|
|
131
|
+
});
|
|
132
|
+
expect(results.map(r => r.name)).toEqual(['Panel']);
|
|
133
|
+
expect(results[0].score).toBe(80);
|
|
134
|
+
});
|
|
135
|
+
|
|
119
136
|
it('breaks a score tie alphabetically', async () => {
|
|
120
137
|
// Both names are edit-distance 2 from "bcd" -> both score 40 -> alpha order.
|
|
121
138
|
const results = await searchComponents('bcd', NO_CORE, {g: ['Xbc', 'Abc']});
|
|
@@ -11,26 +11,40 @@ export function nameWords(text: string): string[];
|
|
|
11
11
|
/**
|
|
12
12
|
* The same items, closest to the typed name first; each item is as close as
|
|
13
13
|
* its closest name. Equal matches keep their original order.
|
|
14
|
+
*
|
|
15
|
+
* With `closest`, the list also stops where the matches get weaker. Only
|
|
16
|
+
* typed words longer than one character count here. When the best item
|
|
17
|
+
* carries every such word, only the items that carry every one of them stay;
|
|
18
|
+
* when it carries some of them, the items that carry none are left out. When
|
|
19
|
+
* no item carries one, nothing is left out. The list only ever gets shorter,
|
|
20
|
+
* and its order does not change.
|
|
14
21
|
* @template T
|
|
15
22
|
* @param {string} typedName
|
|
16
23
|
* @param {T[]} items
|
|
17
24
|
* @param {(item: T) => Array<string | undefined>} namesOf
|
|
25
|
+
* @param {{closest?: boolean}} [options]
|
|
18
26
|
* @returns {T[]}
|
|
19
27
|
*/
|
|
20
|
-
export function orderByAffinity<T>(typedName: string, items: T[], namesOf: (item: T) => Array<string | undefined
|
|
28
|
+
export function orderByAffinity<T>(typedName: string, items: T[], namesOf: (item: T) => Array<string | undefined>, options?: {
|
|
29
|
+
closest?: boolean;
|
|
30
|
+
}): T[];
|
|
21
31
|
/**
|
|
22
32
|
* Docs route suggestions, closest to the typed route first. When every
|
|
23
33
|
* suggestion sits under one namespace the typed route also starts with, that
|
|
24
34
|
* shared part is left out of the comparison: it says nothing about which page
|
|
25
|
-
* was meant. Equal matches keep their order.
|
|
35
|
+
* was meant. Equal matches keep their order. `closest` stops the list where
|
|
36
|
+
* the matches get weaker, as in {@link orderByAffinity}.
|
|
26
37
|
* @template {{name: string}} T
|
|
27
38
|
* @param {string} topic - the typed route
|
|
28
39
|
* @param {T[]} suggestions
|
|
40
|
+
* @param {{closest?: boolean}} [options]
|
|
29
41
|
* @returns {T[]}
|
|
30
42
|
*/
|
|
31
43
|
export function orderRouteSuggestions<T extends {
|
|
32
44
|
name: string;
|
|
33
|
-
}>(topic: string, suggestions: T[]
|
|
45
|
+
}>(topic: string, suggestions: T[], options?: {
|
|
46
|
+
closest?: boolean;
|
|
47
|
+
}): T[];
|
|
34
48
|
/**
|
|
35
49
|
* The components whose synonyms name what was typed. A synonym matches when
|
|
36
50
|
* its words, with or without a leading library name, are the typed words
|