@astryxdesign/cli 0.7.4 → 0.7.5-canary.0418c47
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 +20 -20
- 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/tokenizer-showcase.test.mjs +47 -0
- package/api/template/unknown-name.test.mjs +63 -0
- package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
- package/api/theme/build/build.icon-variants.test.mjs +105 -0
- package/api/theme/build/build.mjs +36 -7
- package/api/theme/build/build.test.mjs +27 -0
- package/api/upgrade/_adapter.d.mts +47 -2
- package/api/upgrade/_adapter.mjs +58 -2
- package/api/upgrade/run/failure-receipt.test.mjs +212 -0
- package/api/upgrade/run/outcomes.test.mjs +646 -0
- package/api/upgrade/run/run.d.mts +36 -0
- package/api/upgrade/run/run.mjs +670 -44
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +36 -1
- package/api/upgrade/upgrade.type.mjs +29 -4
- package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
- package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
- package/assets/codemods/integration-runner.mjs +8 -2
- package/assets/codemods/integration-runner.protection.test.mjs +53 -0
- package/assets/codemods/outcome.mjs +79 -0
- package/assets/codemods/outcome.test.mjs +40 -0
- package/assets/codemods/parse.mjs +94 -0
- package/assets/codemods/run-codemod.mjs +109 -5
- package/assets/codemods/runner.mjs +119 -13
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- package/assets/codemods/transforms/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-codeblock-tokenizer-to-language.mjs +315 -0
- package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
- package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
- package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
- package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
- package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +143 -70
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +23 -78
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +71 -1
- package/assets/docs/theme.doc.dense.mjs +8 -0
- package/assets/docs/theme.doc.mjs +16 -0
- package/assets/docs/theme.doc.zh.mjs +11 -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/docs/tree/styling-advanced.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +145 -1
- package/assets/docs/tree/tokens.doc.mjs +1 -1
- 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/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
- package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.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 +22 -14
- 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/dashboard-alert-rail/page.tsx +3 -3
- package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
- package/assets/templates/pages/library/page.tsx +1 -2
- package/assets/templates/pages/table-comparison/page.tsx +12 -3
- package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
- package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
- package/assets/templates/themes/butter/butterTheme.ts +47 -44
- package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
- package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
- package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
- package/assets/templates/themes/stone/stoneTheme.ts +46 -21
- package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
- package/assets/theme.template.ts +18 -5
- package/authoring/codemod/type.ts +10 -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/build-theme.adaptations.test.mjs +110 -0
- 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/commands/upgrade.doc.mjs +47 -2
- package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
- package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
- package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
- package/clients/cli/commands/upgrade.mjs +9 -2
- package/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
- package/clients/cli/index.mjs +1 -0
- package/foundation/agent-docs/agent-docs.mjs +1 -0
- package/foundation/agent-docs/agent-docs.test.mjs +5 -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/base.d.ts +7 -0
- package/foundation/response/error-codes.d.mts +10 -1
- package/foundation/response/error-codes.doc.mjs +59 -2
- package/foundation/response/error-codes.mjs +62 -1
- package/foundation/response/json.d.mts +10 -3
- package/foundation/response/json.mjs +16 -4
- package/foundation/response/response-types.doc.mjs +39 -2
- 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 +15 -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
|
+
}
|
|
@@ -34,6 +34,13 @@ export interface CLIError {
|
|
|
34
34
|
error: string;
|
|
35
35
|
code: ErrorCode;
|
|
36
36
|
suggestions?: Suggestion[];
|
|
37
|
+
/**
|
|
38
|
+
* What the command had already done when it failed, present only on errors
|
|
39
|
+
* from a command that changes files before it can fail (for example the
|
|
40
|
+
* `upgrade.run` data of a failed `astryx upgrade`). The error is still an
|
|
41
|
+
* error: branch on `code`.
|
|
42
|
+
*/
|
|
43
|
+
receipt?: Record<string, unknown>;
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
/** Returned by the fallback hook for commands without --json support. */
|
|
@@ -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");
|
|
@@ -150,7 +150,8 @@ export const doc = {
|
|
|
150
150
|
},
|
|
151
151
|
{
|
|
152
152
|
value: 'ERR_CODEMOD_FAILED',
|
|
153
|
-
description:
|
|
153
|
+
description:
|
|
154
|
+
'A codemod or post-codemod hook failed during an upgrade run; the error carries a `receipt` that lists the files the run already changed.',
|
|
154
155
|
},
|
|
155
156
|
{
|
|
156
157
|
value: 'ERR_CODEMOD_PROTECTED',
|
|
@@ -282,12 +283,68 @@ export const doc = {
|
|
|
282
283
|
{
|
|
283
284
|
value: 'ERR_VERSIONS_UNAVAILABLE',
|
|
284
285
|
description:
|
|
285
|
-
|
|
286
|
+
"Nothing could answer this run, and nothing was written: the project's own CLI could not start and nothing else could answer, or the Core a command needs outside a project could not be installed.",
|
|
286
287
|
},
|
|
287
288
|
{
|
|
288
289
|
value: 'ERR_PROJECT_REQUIRED',
|
|
289
290
|
description:
|
|
290
291
|
'The command needs a project (an app with Astryx installed, or an integration package) and was run outside one. Nothing was written.',
|
|
291
292
|
},
|
|
293
|
+
|
|
294
|
+
// Render (experimental: may change or be removed in a patch release)
|
|
295
|
+
{
|
|
296
|
+
value: 'ERR_RENDER_COMPILE',
|
|
297
|
+
stability: 'experimental',
|
|
298
|
+
description:
|
|
299
|
+
'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.',
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
value: 'ERR_RENDER_NO_DEFAULT_EXPORT',
|
|
303
|
+
stability: 'experimental',
|
|
304
|
+
description:
|
|
305
|
+
'The page given to render has no default export to render. Nothing was written. Raised only by the experimental render command.',
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
value: 'ERR_RENDER_MISSING_DEPENDENCY',
|
|
309
|
+
stability: 'experimental',
|
|
310
|
+
description:
|
|
311
|
+
'The page imports a package that is not installed where the page is. Nothing was written. Raised only by the experimental render command.',
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
value: 'ERR_RENDER_BROWSER_API',
|
|
315
|
+
stability: 'experimental',
|
|
316
|
+
description:
|
|
317
|
+
'The page reads a browser-only API, such as window or document, while rendering. Nothing was written. Raised only by the experimental render command.',
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
value: 'ERR_RENDER_ASSET_TOO_LARGE',
|
|
321
|
+
stability: 'experimental',
|
|
322
|
+
description:
|
|
323
|
+
'A local file the page uses is too large to inline into one file. Nothing was written. Raised only by the experimental render command.',
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
value: 'ERR_RENDER_TIMEOUT',
|
|
327
|
+
stability: 'experimental',
|
|
328
|
+
description:
|
|
329
|
+
'The page did not finish rendering in time and was stopped. Nothing was written. Raised only by the experimental render command.',
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
value: 'ERR_RENDER_FAILED',
|
|
333
|
+
stability: 'experimental',
|
|
334
|
+
description:
|
|
335
|
+
'The page threw while rendering. Nothing was written. Raised only by the experimental render command.',
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
value: 'ERR_RENDER_NOT_ASTRYX',
|
|
339
|
+
stability: 'experimental',
|
|
340
|
+
description:
|
|
341
|
+
'`render --reverse` was given a file with no embedded source and no Astryx markup. Nothing was written. Raised only by the experimental render command.',
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
value: 'ERR_RENDER_SOURCE_DAMAGED',
|
|
345
|
+
stability: 'experimental',
|
|
346
|
+
description:
|
|
347
|
+
'`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.',
|
|
348
|
+
},
|
|
292
349
|
],
|
|
293
350
|
};
|
|
@@ -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
|
|
|
@@ -163,7 +172,7 @@ export const ERROR_CODES = Object.freeze({
|
|
|
163
172
|
ERR_UNKNOWN_FEATURE: 'ERR_UNKNOWN_FEATURE',
|
|
164
173
|
/** A `--codemod` value did not match any registered codemod (upgrade). */
|
|
165
174
|
ERR_UNKNOWN_CODEMOD: 'ERR_UNKNOWN_CODEMOD',
|
|
166
|
-
/** One or more codemods failed during an upgrade run. */
|
|
175
|
+
/** One or more codemods, or a post-codemod hook, failed during an upgrade run. */
|
|
167
176
|
ERR_CODEMOD_FAILED: 'ERR_CODEMOD_FAILED',
|
|
168
177
|
/** A required codemod change remains blocked by a protected consumer file. */
|
|
169
178
|
ERR_CODEMOD_PROTECTED: 'ERR_CODEMOD_PROTECTED',
|
|
@@ -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
|
/**
|
|
@@ -62,19 +62,26 @@ export function jsonOut(response: {
|
|
|
62
62
|
* @param {import('./base').Suggestion[]} [suggestions]
|
|
63
63
|
* @param {string} [code] - Explicit stable error code. Overrides any code
|
|
64
64
|
* carried on a thrown Error.
|
|
65
|
-
* @
|
|
65
|
+
* @param {Record<string, unknown>} [receipt] - What the failed command had
|
|
66
|
+
* already done, for a command that changes files before it can fail.
|
|
67
|
+
* Overrides a `receipt` carried on a thrown Error. Additive: the envelope
|
|
68
|
+
* is still an error with its `code`.
|
|
69
|
+
* @returns {{apiVersion: number, error: string, code: string, suggestions?: import('./base').Suggestion[], receipt?: Record<string, unknown>}}
|
|
66
70
|
*/
|
|
67
|
-
export function toErrorEnvelope(err: unknown, suggestions?: import("./base").Suggestion[], code?: string): {
|
|
71
|
+
export function toErrorEnvelope(err: unknown, suggestions?: import("./base").Suggestion[], code?: string, receipt?: Record<string, unknown>): {
|
|
68
72
|
apiVersion: number;
|
|
69
73
|
error: string;
|
|
70
74
|
code: string;
|
|
71
75
|
suggestions?: import("./base").Suggestion[];
|
|
76
|
+
receipt?: Record<string, unknown>;
|
|
72
77
|
};
|
|
73
78
|
/**
|
|
74
79
|
* Output a structured JSON error and exit.
|
|
75
80
|
* @param {string} message
|
|
76
81
|
* @param {import('./base').Suggestion[]} [suggestions]
|
|
77
82
|
* @param {string} [code] - Stable machine-readable error code (error-codes.mjs).
|
|
83
|
+
* @param {Record<string, unknown>} [receipt] - What the command had already
|
|
84
|
+
* done before it failed (see toErrorEnvelope).
|
|
78
85
|
*/
|
|
79
|
-
export function jsonError(message: string, suggestions?: import("./base").Suggestion[], code?: string): void;
|
|
86
|
+
export function jsonError(message: string, suggestions?: import("./base").Suggestion[], code?: string, receipt?: Record<string, unknown>): void;
|
|
80
87
|
export const API_VERSION: 1;
|
|
@@ -134,9 +134,13 @@ export function jsonOut(response) {
|
|
|
134
134
|
* @param {import('./base').Suggestion[]} [suggestions]
|
|
135
135
|
* @param {string} [code] - Explicit stable error code. Overrides any code
|
|
136
136
|
* carried on a thrown Error.
|
|
137
|
-
* @
|
|
137
|
+
* @param {Record<string, unknown>} [receipt] - What the failed command had
|
|
138
|
+
* already done, for a command that changes files before it can fail.
|
|
139
|
+
* Overrides a `receipt` carried on a thrown Error. Additive: the envelope
|
|
140
|
+
* is still an error with its `code`.
|
|
141
|
+
* @returns {{apiVersion: number, error: string, code: string, suggestions?: import('./base').Suggestion[], receipt?: Record<string, unknown>}}
|
|
138
142
|
*/
|
|
139
|
-
export function toErrorEnvelope(err, suggestions, code) {
|
|
143
|
+
export function toErrorEnvelope(err, suggestions, code, receipt) {
|
|
140
144
|
const message =
|
|
141
145
|
err instanceof Error ? err.message : typeof err === 'string' ? err : String(err);
|
|
142
146
|
const carried =
|
|
@@ -145,6 +149,12 @@ export function toErrorEnvelope(err, suggestions, code) {
|
|
|
145
149
|
/** @type {any} */
|
|
146
150
|
const env = {apiVersion: API_VERSION, error: message, code: resolvedCode};
|
|
147
151
|
if (Array.isArray(suggestions) && suggestions.length) env.suggestions = suggestions;
|
|
152
|
+
const carriedReceipt =
|
|
153
|
+
err && typeof err === 'object' ? /** @type {any} */ (err).receipt : undefined;
|
|
154
|
+
const resolvedReceipt = receipt ?? carriedReceipt;
|
|
155
|
+
if (resolvedReceipt && typeof resolvedReceipt === 'object') {
|
|
156
|
+
env.receipt = resolvedReceipt;
|
|
157
|
+
}
|
|
148
158
|
return env;
|
|
149
159
|
}
|
|
150
160
|
|
|
@@ -153,10 +163,12 @@ export function toErrorEnvelope(err, suggestions, code) {
|
|
|
153
163
|
* @param {string} message
|
|
154
164
|
* @param {import('./base').Suggestion[]} [suggestions]
|
|
155
165
|
* @param {string} [code] - Stable machine-readable error code (error-codes.mjs).
|
|
166
|
+
* @param {Record<string, unknown>} [receipt] - What the command had already
|
|
167
|
+
* done before it failed (see toErrorEnvelope).
|
|
156
168
|
*/
|
|
157
|
-
export function jsonError(message, suggestions, code) {
|
|
169
|
+
export function jsonError(message, suggestions, code, receipt) {
|
|
158
170
|
process.__xdsJsonHandled = true;
|
|
159
|
-
const err = toErrorEnvelope(message, suggestions, code);
|
|
171
|
+
const err = toErrorEnvelope(message, suggestions, code, receipt);
|
|
160
172
|
// No-op when cliError already classified this failure — first outcome wins.
|
|
161
173
|
setOutcome('error', {exitCode: 1, error: new Error(message), code: err.code});
|
|
162
174
|
console.log(JSON.stringify(err, null, 2));
|
|
@@ -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',
|
|
@@ -351,7 +388,7 @@ export const doc = {
|
|
|
351
388
|
{
|
|
352
389
|
value: 'upgrade.run',
|
|
353
390
|
description:
|
|
354
|
-
'The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, sourcePathFound (false when the resolved source directory does not exist, so no source file was read), and (apply mode) filesChanged, transformsApplied, and per-codemod errors. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run.',
|
|
391
|
+
'The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, sourcePathFound (false when the resolved source directory does not exist, so no source file was read), and (apply mode) filesChanged, transformsApplied, and per-codemod errors. regenerate lists generated files to rebuild, each with its codemods, commands and messages. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run.',
|
|
355
392
|
},
|
|
356
393
|
|
|
357
394
|
// manifest
|