@astryxdesign/cli 0.7.4 → 0.7.5-canary.04434e7
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 +19 -19
- 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/api/upgrade/run/failure-receipt.test.mjs +155 -0
- package/api/upgrade/run/run.mjs +170 -8
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +12 -1
- package/api/upgrade/upgrade.type.mjs +16 -3
- package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
- package/assets/codemods/integration-runner.mjs +1 -1
- package/assets/codemods/run-codemod.mjs +17 -3
- package/assets/codemods/runner.mjs +81 -8
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- 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 +123 -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 +200 -32
- 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/docs/tree/styling-advanced.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/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/commands/upgrade.doc.mjs +17 -0
- package/clients/cli/commands/upgrade.file-protection.test.mjs +29 -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/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/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 +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,283 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Every icon authoring write is all or nothing (AST-084 FR13): for each
|
|
5
|
+
* command, a failure injected at each of its file writes in turn leaves
|
|
6
|
+
* every file in the package byte-identical, and the command fails with
|
|
7
|
+
* `ERR_WRITE_FAILED`, never an unknown error.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as os from 'node:os';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
|
13
|
+
|
|
14
|
+
// Counts the command's file writes, and fails the one numbered `failAt`.
|
|
15
|
+
const fault = vi.hoisted(() => ({
|
|
16
|
+
root: /** @type {string | null} */ (null),
|
|
17
|
+
count: 0,
|
|
18
|
+
failAt: 0,
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
vi.mock('node:fs', async importOriginal => {
|
|
22
|
+
const actual = /** @type {typeof import('node:fs')} */ (
|
|
23
|
+
await importOriginal()
|
|
24
|
+
);
|
|
25
|
+
/**
|
|
26
|
+
* @param {unknown} target a path, or a file descriptor
|
|
27
|
+
*/
|
|
28
|
+
const hit = target => {
|
|
29
|
+
if (fault.root == null) return;
|
|
30
|
+
if (
|
|
31
|
+
typeof target === 'string' &&
|
|
32
|
+
!path.resolve(target).startsWith(fault.root)
|
|
33
|
+
) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
fault.count += 1;
|
|
37
|
+
if (fault.count === fault.failAt) {
|
|
38
|
+
fault.root = null;
|
|
39
|
+
throw Object.assign(new Error('EIO: i/o error (injected)'), {
|
|
40
|
+
code: 'EIO',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/** @type {any} */
|
|
45
|
+
const mocked = {
|
|
46
|
+
...actual,
|
|
47
|
+
/** @type {typeof actual.writeFileSync} */
|
|
48
|
+
writeFileSync: (file, ...rest) => {
|
|
49
|
+
hit(file);
|
|
50
|
+
return actual.writeFileSync(file, ...rest);
|
|
51
|
+
},
|
|
52
|
+
/** @type {typeof actual.renameSync} */
|
|
53
|
+
renameSync: (from, to) => {
|
|
54
|
+
hit(to);
|
|
55
|
+
return actual.renameSync(from, to);
|
|
56
|
+
},
|
|
57
|
+
/** @type {typeof actual.copyFileSync} */
|
|
58
|
+
copyFileSync: (from, to, mode) => {
|
|
59
|
+
hit(to);
|
|
60
|
+
return actual.copyFileSync(from, to, mode);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
return {...mocked, default: mocked};
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const fs = await import('node:fs');
|
|
67
|
+
const {iconNewSet} = await import('./new-set/new-set.mjs');
|
|
68
|
+
const {iconNewDefinition} = await import('./new-definition/new-definition.mjs');
|
|
69
|
+
const {iconAdd} = await import('./add/add.mjs');
|
|
70
|
+
const {iconMap} = await import('./map/map.mjs');
|
|
71
|
+
|
|
72
|
+
/** @type {string} */
|
|
73
|
+
let tmp;
|
|
74
|
+
beforeEach(() => {
|
|
75
|
+
tmp = fs.realpathSync(
|
|
76
|
+
fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-icon-atomic-')),
|
|
77
|
+
);
|
|
78
|
+
fault.root = null;
|
|
79
|
+
});
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
fault.root = null;
|
|
82
|
+
fs.rmSync(tmp, {recursive: true, force: true});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* An icon-set package `@acme/icons` with an installed library of two icons
|
|
87
|
+
* (and a solid variant module), and a local artwork file.
|
|
88
|
+
* @returns {string}
|
|
89
|
+
*/
|
|
90
|
+
function makePackage() {
|
|
91
|
+
const dir = fs.mkdtempSync(path.join(tmp, 'pkg-'));
|
|
92
|
+
fs.writeFileSync(
|
|
93
|
+
path.join(dir, 'package.json'),
|
|
94
|
+
`${JSON.stringify(
|
|
95
|
+
{
|
|
96
|
+
name: '@acme/icons',
|
|
97
|
+
version: '1.0.0',
|
|
98
|
+
license: 'MIT',
|
|
99
|
+
type: 'module',
|
|
100
|
+
exports: {'.': './index.js'},
|
|
101
|
+
files: ['index.js'],
|
|
102
|
+
dependencies: {'@acme/glyph-library': '^2.0.0'},
|
|
103
|
+
},
|
|
104
|
+
null,
|
|
105
|
+
2,
|
|
106
|
+
)}\n`,
|
|
107
|
+
);
|
|
108
|
+
fs.writeFileSync(path.join(dir, 'index.js'), 'export {};\n');
|
|
109
|
+
const lib = path.join(dir, 'node_modules', '@acme', 'glyph-library');
|
|
110
|
+
fs.mkdirSync(lib, {recursive: true});
|
|
111
|
+
fs.writeFileSync(
|
|
112
|
+
path.join(lib, 'package.json'),
|
|
113
|
+
JSON.stringify({
|
|
114
|
+
name: '@acme/glyph-library',
|
|
115
|
+
version: '2.0.0',
|
|
116
|
+
license: 'ISC',
|
|
117
|
+
type: 'module',
|
|
118
|
+
exports: {'.': './index.js', './solid': './solid.js'},
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
fs.writeFileSync(path.join(lib, 'LICENSE'), 'MIT License\n');
|
|
122
|
+
fs.writeFileSync(
|
|
123
|
+
path.join(lib, 'index.js'),
|
|
124
|
+
'export const Bin = props => null;\nexport const Close = props => null;\n',
|
|
125
|
+
);
|
|
126
|
+
fs.writeFileSync(
|
|
127
|
+
path.join(lib, 'solid.js'),
|
|
128
|
+
'export const Bin = props => null;\nexport const Close = props => null;\n',
|
|
129
|
+
);
|
|
130
|
+
fs.mkdirSync(path.join(dir, 'art'));
|
|
131
|
+
fs.writeFileSync(
|
|
132
|
+
path.join(dir, 'art', 'spark.js'),
|
|
133
|
+
'export const Spark = props => null;\n',
|
|
134
|
+
);
|
|
135
|
+
return dir;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Every file and folder under `dir` (the installed library aside), with its
|
|
140
|
+
* bytes.
|
|
141
|
+
* @param {string} dir
|
|
142
|
+
* @returns {Record<string, string>}
|
|
143
|
+
*/
|
|
144
|
+
function snapshot(dir) {
|
|
145
|
+
/** @type {Record<string, string>} */
|
|
146
|
+
const found = {};
|
|
147
|
+
/** @param {string} at */
|
|
148
|
+
const walk = at => {
|
|
149
|
+
for (const entry of fs.readdirSync(at, {withFileTypes: true})) {
|
|
150
|
+
const full = path.join(at, entry.name);
|
|
151
|
+
const rel = path.relative(dir, full);
|
|
152
|
+
if (entry.name === 'node_modules') continue;
|
|
153
|
+
if (entry.isDirectory()) {
|
|
154
|
+
found[`${rel}/`] = '';
|
|
155
|
+
walk(full);
|
|
156
|
+
} else {
|
|
157
|
+
found[rel] = fs.readFileSync(full).toString('base64');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
walk(dir);
|
|
162
|
+
return found;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const FROM = '@acme/glyph-library';
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Each command, with what the package holds before it runs.
|
|
169
|
+
* @type {Array<[string, (dir: string) => Promise<unknown>, (dir: string) => Promise<unknown>]>}
|
|
170
|
+
*/
|
|
171
|
+
const COMMANDS = [
|
|
172
|
+
[
|
|
173
|
+
'new-set --from',
|
|
174
|
+
async () => {},
|
|
175
|
+
dir => iconNewSet('glyphs', {cwd: dir, from: FROM}),
|
|
176
|
+
],
|
|
177
|
+
[
|
|
178
|
+
'new-set refresh with --display-name and --description',
|
|
179
|
+
dir => iconNewSet('glyphs', {cwd: dir, from: FROM}),
|
|
180
|
+
dir =>
|
|
181
|
+
iconNewSet('glyphs', {
|
|
182
|
+
cwd: dir,
|
|
183
|
+
from: FROM,
|
|
184
|
+
displayName: 'Acme Glyphs',
|
|
185
|
+
description: 'Acme glyphs.',
|
|
186
|
+
variants: 'outline,solid',
|
|
187
|
+
}),
|
|
188
|
+
],
|
|
189
|
+
[
|
|
190
|
+
'a refresh that first records the source (notices and license)',
|
|
191
|
+
dir => iconNewSet('glyphs', {cwd: dir}),
|
|
192
|
+
dir => iconNewSet('glyphs', {cwd: dir, from: FROM}),
|
|
193
|
+
],
|
|
194
|
+
[
|
|
195
|
+
'add --new-definition',
|
|
196
|
+
dir => iconNewSet('glyphs', {cwd: dir}),
|
|
197
|
+
dir =>
|
|
198
|
+
iconAdd('Bin', {
|
|
199
|
+
cwd: dir,
|
|
200
|
+
from: FROM,
|
|
201
|
+
newDefinition: 'binIt',
|
|
202
|
+
description: 'Put something in the bin.',
|
|
203
|
+
words: ['bin'],
|
|
204
|
+
}),
|
|
205
|
+
],
|
|
206
|
+
[
|
|
207
|
+
'add --from ./file',
|
|
208
|
+
dir => iconNewSet('glyphs', {cwd: dir}),
|
|
209
|
+
dir =>
|
|
210
|
+
iconAdd('Spark', {cwd: dir, from: './art/spark.js', definition: 'close'}),
|
|
211
|
+
],
|
|
212
|
+
[
|
|
213
|
+
'add --variant --all',
|
|
214
|
+
dir =>
|
|
215
|
+
iconNewSet('glyphs', {cwd: dir, from: FROM, variants: 'outline,solid'}),
|
|
216
|
+
dir =>
|
|
217
|
+
iconAdd(undefined, {
|
|
218
|
+
cwd: dir,
|
|
219
|
+
from: `${FROM}/solid`,
|
|
220
|
+
variant: 'solid',
|
|
221
|
+
all: true,
|
|
222
|
+
}),
|
|
223
|
+
],
|
|
224
|
+
[
|
|
225
|
+
'map',
|
|
226
|
+
dir => iconNewSet('glyphs', {cwd: dir, from: FROM}),
|
|
227
|
+
dir => iconMap('delete', 'bin', {cwd: dir}),
|
|
228
|
+
],
|
|
229
|
+
[
|
|
230
|
+
'map --pairs',
|
|
231
|
+
dir => iconNewSet('glyphs', {cwd: dir, from: FROM}),
|
|
232
|
+
dir =>
|
|
233
|
+
iconMap(undefined, undefined, {
|
|
234
|
+
cwd: dir,
|
|
235
|
+
pairs: 'delete=bin,check=close',
|
|
236
|
+
}),
|
|
237
|
+
],
|
|
238
|
+
[
|
|
239
|
+
'new-definition --icon',
|
|
240
|
+
dir => iconNewSet('glyphs', {cwd: dir, from: FROM}),
|
|
241
|
+
dir =>
|
|
242
|
+
iconNewDefinition('binIt', {
|
|
243
|
+
cwd: dir,
|
|
244
|
+
description: 'Put something in the bin.',
|
|
245
|
+
words: ['bin'],
|
|
246
|
+
icon: 'bin',
|
|
247
|
+
}),
|
|
248
|
+
],
|
|
249
|
+
];
|
|
250
|
+
|
|
251
|
+
describe('every icon authoring write is all or nothing', () => {
|
|
252
|
+
it.each(COMMANDS)(
|
|
253
|
+
'%s: a failure at any write leaves every file as it was',
|
|
254
|
+
async (_, prepare, run) => {
|
|
255
|
+
// A clean run counts the command's writes.
|
|
256
|
+
const counted = makePackage();
|
|
257
|
+
await prepare(counted);
|
|
258
|
+
fault.count = 0;
|
|
259
|
+
fault.failAt = 0;
|
|
260
|
+
fault.root = counted;
|
|
261
|
+
await run(counted);
|
|
262
|
+
fault.root = null;
|
|
263
|
+
const writes = fault.count;
|
|
264
|
+
expect(writes).toBeGreaterThan(0);
|
|
265
|
+
|
|
266
|
+
for (let at = 1; at <= writes; at++) {
|
|
267
|
+
const dir = makePackage();
|
|
268
|
+
await prepare(dir);
|
|
269
|
+
const before = snapshot(dir);
|
|
270
|
+
fault.count = 0;
|
|
271
|
+
fault.failAt = at;
|
|
272
|
+
fault.root = dir;
|
|
273
|
+
await expect(
|
|
274
|
+
run(dir),
|
|
275
|
+
`write ${at} of ${writes}`,
|
|
276
|
+
).rejects.toMatchObject({code: 'ERR_WRITE_FAILED'});
|
|
277
|
+
fault.root = null;
|
|
278
|
+
expect(snapshot(dir), `write ${at} of ${writes}`).toEqual(before);
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
60_000,
|
|
282
|
+
);
|
|
283
|
+
});
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
importLine,
|
|
19
19
|
rankIcons,
|
|
20
20
|
setsNamed,
|
|
21
|
-
|
|
21
|
+
unusableSet,
|
|
22
22
|
} from '../_records.mjs';
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -33,18 +33,7 @@ export async function iconDetail(reference, {cwd}) {
|
|
|
33
33
|
const id = reference.slice(slash + 1);
|
|
34
34
|
const {sets, withdrawn} = await loadIconSets(cwd);
|
|
35
35
|
const named = setsNamed(sets, selector);
|
|
36
|
-
if (named.length === 0)
|
|
37
|
-
throw new AstryxError(
|
|
38
|
-
withdrawnReason(withdrawn, selector) ??
|
|
39
|
-
`No installed icon set named "${selector}"`,
|
|
40
|
-
closest(
|
|
41
|
-
selector,
|
|
42
|
-
sets.flatMap(each => [each.name, `${each.package}/${each.name}`]),
|
|
43
|
-
'installed icon set',
|
|
44
|
-
),
|
|
45
|
-
ERROR_CODES.ERR_NOT_FOUND,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
36
|
+
if (named.length === 0) throw unusableSet(sets, withdrawn, selector);
|
|
48
37
|
if (named.length > 1) {
|
|
49
38
|
throw new AstryxError(
|
|
50
39
|
`Icon set name "${selector}" is installed by ${named.map(each => each.package).join(' and ')}`,
|
|
@@ -133,8 +133,11 @@ const CASES = {
|
|
|
133
133
|
ERR_MISSING_ARGUMENT: () => icon('', {cwd: app()}),
|
|
134
134
|
ERR_INVALID_ARGUMENT: () => icon('close', {cwd: app(), limit: 0}),
|
|
135
135
|
ERR_NOT_FOUND: () => icon('glyphs/nope', {cwd: app()}),
|
|
136
|
+
ERR_INVALID_OPTION: () => icon('close', {cwd: app(), list: true}),
|
|
136
137
|
},
|
|
137
138
|
iconAdd: {
|
|
139
|
+
ERR_INVALID_OPTION: () =>
|
|
140
|
+
iconAdd('XIcon', {cwd: pkg(), from: './icons/x.js', all: true}),
|
|
138
141
|
ERR_PROJECT_REQUIRED: () =>
|
|
139
142
|
iconAdd('XIcon', {cwd: outside(), from: './x.js'}),
|
|
140
143
|
ERR_INVALID_ARGUMENT: () =>
|
|
@@ -171,6 +174,8 @@ const CASES = {
|
|
|
171
174
|
},
|
|
172
175
|
iconMap: {
|
|
173
176
|
ERR_PROJECT_REQUIRED: () => iconMap('close', 'x', {cwd: outside()}),
|
|
177
|
+
ERR_INVALID_OPTION: () =>
|
|
178
|
+
iconMap('close', undefined, {cwd: pkg(), pairs: 'close=x'}),
|
|
174
179
|
ERR_MISSING_ARGUMENT: () => iconMap('', 'x', {cwd: pkg()}),
|
|
175
180
|
ERR_INVALID_ARGUMENT: () =>
|
|
176
181
|
iconMap('close', 'x', {cwd: withSecondSet(pkg())}),
|
|
@@ -221,6 +226,8 @@ const CASES = {
|
|
|
221
226
|
iconNewSet: {
|
|
222
227
|
ERR_PROJECT_REQUIRED: () => iconNewSet('outline', {cwd: outside()}),
|
|
223
228
|
ERR_INVALID_ARGUMENT: () => iconNewSet('Outline', {cwd: bare()}),
|
|
229
|
+
ERR_INVALID_OPTION: () =>
|
|
230
|
+
iconNewSet('outline', {cwd: bare(), exclude: 'Meta'}),
|
|
224
231
|
ERR_FILE_EXISTS: async () => {
|
|
225
232
|
const dir = bare();
|
|
226
233
|
await iconNewSet('outline', {cwd: dir});
|
|
@@ -249,27 +256,27 @@ const CASES = {
|
|
|
249
256
|
},
|
|
250
257
|
iconNewDefinition: {
|
|
251
258
|
ERR_PROJECT_REQUIRED: () =>
|
|
252
|
-
iconNewDefinition('
|
|
259
|
+
iconNewDefinition('random', {cwd: outside(), ...DEFINITION}),
|
|
253
260
|
ERR_INVALID_ARGUMENT: () =>
|
|
254
261
|
iconNewDefinition('Not-Camel', {cwd: pkg(), ...DEFINITION}),
|
|
255
262
|
ERR_MISSING_ARGUMENT: () =>
|
|
256
|
-
iconNewDefinition('
|
|
263
|
+
iconNewDefinition('random', {cwd: pkg(), words: ['turn']}),
|
|
257
264
|
ERR_FILE_EXISTS: async () => {
|
|
258
265
|
const dir = pkg();
|
|
259
|
-
await iconNewDefinition('
|
|
260
|
-
return iconNewDefinition('
|
|
266
|
+
await iconNewDefinition('random', {cwd: dir, ...DEFINITION});
|
|
267
|
+
return iconNewDefinition('random', {cwd: dir, ...DEFINITION});
|
|
261
268
|
},
|
|
262
269
|
ERR_NOT_FOUND: () =>
|
|
263
|
-
iconNewDefinition('
|
|
270
|
+
iconNewDefinition('random', {cwd: pkg(), ...DEFINITION, icon: 'nope'}),
|
|
264
271
|
ERR_PATH_TRAVERSAL: () => {
|
|
265
272
|
const dir = pkg();
|
|
266
273
|
manifest(dir, "export default {experimental: {iconSets: '../out'}};\n");
|
|
267
|
-
return iconNewDefinition('
|
|
274
|
+
return iconNewDefinition('random', {cwd: dir, ...DEFINITION});
|
|
268
275
|
},
|
|
269
276
|
ERR_WRITE_FAILED: () => {
|
|
270
277
|
const dir = pkg();
|
|
271
278
|
lock(path.join(dir, 'icon-sets', 'glyphs', 'definitions'));
|
|
272
|
-
return iconNewDefinition('
|
|
279
|
+
return iconNewDefinition('random', {cwd: dir, ...DEFINITION});
|
|
273
280
|
},
|
|
274
281
|
},
|
|
275
282
|
};
|
package/api/icon/icon.d.mts
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* @experimental
|
|
10
10
|
* @param {string} [query] words to search for, or `<set>/<id>`
|
|
11
11
|
* @param {import('./icon.type.mjs').IconOptions} [options]
|
|
12
|
-
* @returns {Promise<import('./icon.type.mjs').IconSearchResponse | import('./icon.type.mjs').IconDetailResponse | import('./icon.type.mjs').IconListResponse>}
|
|
12
|
+
* @returns {Promise<import('./icon.type.mjs').IconSearchResponse | import('./icon.type.mjs').IconDetailResponse | import('./icon.type.mjs').IconListResponse | import('./icon.type.mjs').IconSetIconsResponse | import('./icon.type.mjs').IconDefinitionsResponse>}
|
|
13
13
|
*/
|
|
14
|
-
export function icon(query?: string, options?: import("./icon.type.mjs").IconOptions): Promise<import("./icon.type.mjs").IconSearchResponse | import("./icon.type.mjs").IconDetailResponse | import("./icon.type.mjs").IconListResponse>;
|
|
14
|
+
export function icon(query?: string, options?: import("./icon.type.mjs").IconOptions): Promise<import("./icon.type.mjs").IconSearchResponse | import("./icon.type.mjs").IconDetailResponse | import("./icon.type.mjs").IconListResponse | import("./icon.type.mjs").IconSetIconsResponse | import("./icon.type.mjs").IconDefinitionsResponse>;
|
|
15
15
|
/** The default `limit` for `icon.search`. */
|
|
16
16
|
export const DEFAULT_ICON_LIMIT: 10;
|
package/api/icon/icon.doc.mjs
CHANGED
|
@@ -44,6 +44,20 @@ export const doc = {
|
|
|
44
44
|
description:
|
|
45
45
|
'Max matches, a positive integer (default 10). `matchCount` counts every match.',
|
|
46
46
|
},
|
|
47
|
+
{
|
|
48
|
+
name: 'options.allIcons',
|
|
49
|
+
type: 'boolean',
|
|
50
|
+
description:
|
|
51
|
+
'With options.set and no query: every icon of that set, by id.',
|
|
52
|
+
default: 'false',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'options.definitions',
|
|
56
|
+
type: 'boolean',
|
|
57
|
+
description:
|
|
58
|
+
'Every Astryx icon definition: name, whether it is built in, description, and words. Takes no query or other option.',
|
|
59
|
+
default: 'false',
|
|
60
|
+
},
|
|
47
61
|
{
|
|
48
62
|
name: 'options.cwd',
|
|
49
63
|
type: 'string',
|
|
@@ -61,6 +75,16 @@ export const doc = {
|
|
|
61
75
|
description:
|
|
62
76
|
"One icon's fields, as a match names them, with every variant's import line. The envelope names the set's package.",
|
|
63
77
|
},
|
|
78
|
+
{
|
|
79
|
+
type: 'icon.definitions',
|
|
80
|
+
description:
|
|
81
|
+
'With definitions: every Astryx icon definition, with whether it is built in, its description, and its words.',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: 'icon.setIcons',
|
|
85
|
+
description:
|
|
86
|
+
'With set and all: every icon of that set by id, with its export, words, and the definitions it draws.',
|
|
87
|
+
},
|
|
64
88
|
{
|
|
65
89
|
type: 'icon.list',
|
|
66
90
|
description:
|
|
@@ -74,11 +98,15 @@ export const doc = {
|
|
|
74
98
|
},
|
|
75
99
|
{
|
|
76
100
|
code: 'ERR_INVALID_ARGUMENT',
|
|
77
|
-
when: '
|
|
101
|
+
when: '`limit` is not a positive integer, `allIcons` is given without `set`, or a set name two packages share is not qualified with its package',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
code: 'ERR_INVALID_OPTION',
|
|
105
|
+
when: 'two options are given that the call cannot both honor: `list`, `definitions`, or `allIcons` with any other listing, a query, `set` (not `allIcons`), or `limit`; or a `<set>/<id>` query with `set` or `limit`',
|
|
78
106
|
},
|
|
79
107
|
{
|
|
80
108
|
code: 'ERR_NOT_FOUND',
|
|
81
|
-
when: 'the set named by `<set>/<id>` or `options.set` is not installed, or the set has no such icon; suggestions name the closest',
|
|
109
|
+
when: 'the set named by `<set>/<id>` or `options.set` (with words or `allIcons`) is not installed or is withdrawn (the message says which, and why), or the set has no such icon; suggestions name the closest',
|
|
82
110
|
},
|
|
83
111
|
],
|
|
84
112
|
examples: [
|
package/api/icon/icon.mjs
CHANGED
|
@@ -21,6 +21,9 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
|
21
21
|
import {iconSearch} from './search/search.mjs';
|
|
22
22
|
import {iconDetail} from './detail/detail.mjs';
|
|
23
23
|
import {iconList} from './list/list.mjs';
|
|
24
|
+
import {iconSetIcons} from './search/search.mjs';
|
|
25
|
+
import {astryxIconDefinitions} from './_adapter.mjs';
|
|
26
|
+
import {passed, refuseIgnoredPairs} from './_options.mjs';
|
|
24
27
|
|
|
25
28
|
/** The default `limit` for `icon.search`. */
|
|
26
29
|
export const DEFAULT_ICON_LIMIT = 10;
|
|
@@ -36,15 +39,47 @@ const REFERENCE_RE = /^[^\s/][^\s]*\/[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
|
36
39
|
* @experimental
|
|
37
40
|
* @param {string} [query] words to search for, or `<set>/<id>`
|
|
38
41
|
* @param {import('./icon.type.mjs').IconOptions} [options]
|
|
39
|
-
* @returns {Promise<import('./icon.type.mjs').IconSearchResponse | import('./icon.type.mjs').IconDetailResponse | import('./icon.type.mjs').IconListResponse>}
|
|
42
|
+
* @returns {Promise<import('./icon.type.mjs').IconSearchResponse | import('./icon.type.mjs').IconDetailResponse | import('./icon.type.mjs').IconListResponse | import('./icon.type.mjs').IconSetIconsResponse | import('./icon.type.mjs').IconDefinitionsResponse>}
|
|
40
43
|
*/
|
|
41
44
|
export async function icon(query, options = {}) {
|
|
42
45
|
const {
|
|
43
46
|
cwd = process.cwd(),
|
|
44
47
|
list = false,
|
|
45
48
|
set,
|
|
46
|
-
limit
|
|
49
|
+
limit: givenLimit,
|
|
50
|
+
allIcons = false,
|
|
51
|
+
definitions = false,
|
|
47
52
|
} = options;
|
|
53
|
+
const given = typeof query === 'string' ? query.trim() : '';
|
|
54
|
+
// Every listing takes nothing the others take, and a query or one icon
|
|
55
|
+
// takes no listing (spec:AST-042 FR5).
|
|
56
|
+
refuseIgnoredPairs(
|
|
57
|
+
{
|
|
58
|
+
'a query': given !== '',
|
|
59
|
+
'--list': passed(list),
|
|
60
|
+
'--definitions': passed(definitions),
|
|
61
|
+
'--all-icons': passed(allIcons),
|
|
62
|
+
'--set': passed(set),
|
|
63
|
+
'--limit': passed(givenLimit),
|
|
64
|
+
'a <set>/<id> query': REFERENCE_RE.test(given),
|
|
65
|
+
},
|
|
66
|
+
[
|
|
67
|
+
['--list', 'a query'],
|
|
68
|
+
['--list', '--definitions'],
|
|
69
|
+
['--list', '--all-icons'],
|
|
70
|
+
['--list', '--set'],
|
|
71
|
+
['--list', '--limit'],
|
|
72
|
+
['--definitions', 'a query'],
|
|
73
|
+
['--definitions', '--all-icons'],
|
|
74
|
+
['--definitions', '--set'],
|
|
75
|
+
['--definitions', '--limit'],
|
|
76
|
+
['--all-icons', 'a query'],
|
|
77
|
+
['--all-icons', '--limit'],
|
|
78
|
+
['a <set>/<id> query', '--set'],
|
|
79
|
+
['a <set>/<id> query', '--limit'],
|
|
80
|
+
],
|
|
81
|
+
);
|
|
82
|
+
const limit = givenLimit ?? DEFAULT_ICON_LIMIT;
|
|
48
83
|
if (query != null && typeof query !== 'string') {
|
|
49
84
|
throw new AstryxError(
|
|
50
85
|
`Invalid icon query: ${String(query)}`,
|
|
@@ -53,20 +88,34 @@ export async function icon(query, options = {}) {
|
|
|
53
88
|
);
|
|
54
89
|
}
|
|
55
90
|
const term = (query ?? '').trim();
|
|
56
|
-
if (list) {
|
|
57
|
-
|
|
91
|
+
if (list) return iconList({cwd});
|
|
92
|
+
if (definitions) {
|
|
93
|
+
return {
|
|
94
|
+
type: /** @type {const} */ ('icon.definitions'),
|
|
95
|
+
data: {
|
|
96
|
+
definitions: astryxIconDefinitions().definitions.map(({doc}) => ({
|
|
97
|
+
name: doc.name,
|
|
98
|
+
builtIn: doc.builtIn === true,
|
|
99
|
+
description: doc.description,
|
|
100
|
+
words: doc.words,
|
|
101
|
+
})),
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (allIcons) {
|
|
106
|
+
if (set == null) {
|
|
58
107
|
throw new AstryxError(
|
|
59
|
-
'--
|
|
108
|
+
'--all-icons lists every icon of one set: pass --set',
|
|
60
109
|
[
|
|
61
110
|
{
|
|
62
|
-
name: 'astryx experimental icon --
|
|
63
|
-
reason:
|
|
111
|
+
name: 'astryx experimental icon --set <name> --all-icons',
|
|
112
|
+
reason: "list one set's icons",
|
|
64
113
|
},
|
|
65
114
|
],
|
|
66
115
|
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
67
116
|
);
|
|
68
117
|
}
|
|
69
|
-
return
|
|
118
|
+
return iconSetIcons({cwd, set});
|
|
70
119
|
}
|
|
71
120
|
if (!term) {
|
|
72
121
|
throw new AstryxError(
|