@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,158 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Every option an icon CommandDoc declares reaches the API function it
|
|
5
|
+
* names (spec:AST-042 FR1, architecture:cli-surface INV6): for each icon
|
|
6
|
+
* command and each of its options, the CLI runs with that option, and the
|
|
7
|
+
* test asserts the function received the parameter the option's `param`
|
|
8
|
+
* names. The API functions are replaced by recorders, so nothing is read or
|
|
9
|
+
* written. `--set` on a subcommand is also given before the subcommand's own
|
|
10
|
+
* arguments and after them, since `experimental icon` declares `--set` too.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {beforeEach, describe, expect, it, vi} from 'vitest';
|
|
14
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
15
|
+
import {doc as iconCommand} from './experimental-icon.doc.mjs';
|
|
16
|
+
import {doc as addCommand} from './experimental-icon-add.doc.mjs';
|
|
17
|
+
import {doc as mapCommand} from './experimental-icon-map.doc.mjs';
|
|
18
|
+
import {doc as useCommand} from './experimental-icon-use.doc.mjs';
|
|
19
|
+
import {doc as newSetCommand} from './experimental-icon-new-set.doc.mjs';
|
|
20
|
+
import {doc as newDefinitionCommand} from './experimental-icon-new-definition.doc.mjs';
|
|
21
|
+
|
|
22
|
+
const calls = vi.hoisted(
|
|
23
|
+
() => /** @type {Array<{fn: string, args: unknown[]}>} */ ([]),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A recorder for one API function: it records its arguments and fails, so
|
|
28
|
+
* the CLI prints an error and renders no result.
|
|
29
|
+
* @param {string} fn
|
|
30
|
+
*/
|
|
31
|
+
function recorder(fn) {
|
|
32
|
+
return async (/** @type {unknown[]} */ ...args) => {
|
|
33
|
+
calls.push({fn, args});
|
|
34
|
+
throw Object.assign(new Error('recorded'), {code: 'ERR_NOT_FOUND'});
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
vi.mock('../../../api/icon/icon.mjs', async importOriginal => ({
|
|
39
|
+
.../** @type {object} */ (await importOriginal()),
|
|
40
|
+
icon: recorder('icon'),
|
|
41
|
+
}));
|
|
42
|
+
vi.mock('../../../api/icon/add/add.mjs', async importOriginal => ({
|
|
43
|
+
.../** @type {object} */ (await importOriginal()),
|
|
44
|
+
iconAdd: recorder('iconAdd'),
|
|
45
|
+
}));
|
|
46
|
+
vi.mock('../../../api/icon/map/map.mjs', async importOriginal => ({
|
|
47
|
+
.../** @type {object} */ (await importOriginal()),
|
|
48
|
+
iconMap: recorder('iconMap'),
|
|
49
|
+
}));
|
|
50
|
+
vi.mock('../../../api/icon/use/use.mjs', async importOriginal => ({
|
|
51
|
+
.../** @type {object} */ (await importOriginal()),
|
|
52
|
+
iconUse: recorder('iconUse'),
|
|
53
|
+
}));
|
|
54
|
+
vi.mock('../../../api/icon/new-set/new-set.mjs', async importOriginal => ({
|
|
55
|
+
.../** @type {object} */ (await importOriginal()),
|
|
56
|
+
iconNewSet: recorder('iconNewSet'),
|
|
57
|
+
}));
|
|
58
|
+
vi.mock(
|
|
59
|
+
'../../../api/icon/new-definition/new-definition.mjs',
|
|
60
|
+
async importOriginal => ({
|
|
61
|
+
.../** @type {object} */ (await importOriginal()),
|
|
62
|
+
iconNewDefinition: recorder('iconNewDefinition'),
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
calls.length = 0;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/** @type {Array<[string, any, string]>} the command, its doc, its function */
|
|
71
|
+
const COMMANDS = [
|
|
72
|
+
['experimental icon', iconCommand, 'icon'],
|
|
73
|
+
['experimental icon add', addCommand, 'iconAdd'],
|
|
74
|
+
['experimental icon map', mapCommand, 'iconMap'],
|
|
75
|
+
['experimental icon use', useCommand, 'iconUse'],
|
|
76
|
+
['experimental icon new-set', newSetCommand, 'iconNewSet'],
|
|
77
|
+
[
|
|
78
|
+
'experimental icon new-definition',
|
|
79
|
+
newDefinitionCommand,
|
|
80
|
+
'iconNewDefinition',
|
|
81
|
+
],
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The words that run one command with one option: the command, its required
|
|
86
|
+
* arguments, and the option (with a value when it takes one).
|
|
87
|
+
* @param {string} name
|
|
88
|
+
* @param {any} command
|
|
89
|
+
* @param {any} option
|
|
90
|
+
* @param {'after' | 'before'} [where] the option after the arguments, or
|
|
91
|
+
* before them
|
|
92
|
+
*/
|
|
93
|
+
function argv(name, command, option, where = 'after') {
|
|
94
|
+
const required = (command.args ?? [])
|
|
95
|
+
.filter((/** @type {any} */ arg) => arg.required === true)
|
|
96
|
+
.map(() => 'glyphs');
|
|
97
|
+
const [flag, value] = option.flag.split(/\s+/u);
|
|
98
|
+
const given = value ? [flag, flag === '--limit' ? '3' : 'glyphs'] : [flag];
|
|
99
|
+
return [
|
|
100
|
+
...name.split(' '),
|
|
101
|
+
...(where === 'before' ? [...given, ...required] : [...required, ...given]),
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The options object the recorded call passed (its last argument).
|
|
107
|
+
* @param {string} fn
|
|
108
|
+
* @returns {Record<string, unknown>}
|
|
109
|
+
*/
|
|
110
|
+
function received(fn) {
|
|
111
|
+
const call = calls.find(each => each.fn === fn);
|
|
112
|
+
if (!call) throw new Error(`${fn} was not called`);
|
|
113
|
+
return /** @type {Record<string, unknown>} */ (call.args.at(-1));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
describe.each(COMMANDS)('%s', (name, command, fn) => {
|
|
117
|
+
const options = command.options ?? [];
|
|
118
|
+
if (options.length === 0) {
|
|
119
|
+
it('declares no option', () => {
|
|
120
|
+
expect(options).toEqual([]);
|
|
121
|
+
});
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
it.each(options.map((/** @type {any} */ option) => [option.flag, option]))(
|
|
125
|
+
'%s reaches the API',
|
|
126
|
+
async (_flag, option) => {
|
|
127
|
+
await runCli(argv(name, command, option), {cwd: process.cwd()});
|
|
128
|
+
const key = option.param.replace(/^options\./u, '');
|
|
129
|
+
const value = received(fn)[key];
|
|
130
|
+
expect(value, `${option.flag} -> ${option.param}`).not.toBeUndefined();
|
|
131
|
+
expect(value, `${option.flag} -> ${option.param}`).not.toBe(false);
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('--set on a subcommand, which experimental icon declares too', () => {
|
|
137
|
+
it.each([
|
|
138
|
+
['experimental icon add', addCommand, 'iconAdd'],
|
|
139
|
+
['experimental icon map', mapCommand, 'iconMap'],
|
|
140
|
+
[
|
|
141
|
+
'experimental icon new-definition',
|
|
142
|
+
newDefinitionCommand,
|
|
143
|
+
'iconNewDefinition',
|
|
144
|
+
],
|
|
145
|
+
])(
|
|
146
|
+
'%s takes --set before or after its arguments',
|
|
147
|
+
async (name, command, fn) => {
|
|
148
|
+
const option = command.options.find((/** @type {any} */ each) =>
|
|
149
|
+
each.flag.startsWith('--set '),
|
|
150
|
+
);
|
|
151
|
+
for (const where of /** @type {const} */ (['after', 'before'])) {
|
|
152
|
+
calls.length = 0;
|
|
153
|
+
await runCli(argv(name, command, option, where), {cwd: process.cwd()});
|
|
154
|
+
expect(received(fn).set, where).toBe('glyphs');
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
});
|
|
@@ -33,7 +33,7 @@ describe('astryx experimental icon', () => {
|
|
|
33
33
|
/import: +import \{TrashIcon\} from '@acme\/glyphs';/,
|
|
34
34
|
);
|
|
35
35
|
expect(res.stdout).toMatch(/package: +@acme\/glyphs/);
|
|
36
|
-
expect(res.stdout).toMatch(/variant: +solid/);
|
|
36
|
+
expect(res.stdout).toMatch(/variant: +solid \(TrashSolidIcon\)/);
|
|
37
37
|
const many = await runCli(
|
|
38
38
|
['experimental', 'icon', 'magni', 'fier', '--json'],
|
|
39
39
|
cwd,
|
|
@@ -49,7 +49,10 @@ function iconLines(icons) {
|
|
|
49
49
|
return [
|
|
50
50
|
...icons.mapped.map(
|
|
51
51
|
each =>
|
|
52
|
-
`icons: mapped ${each.source.export} (${each.source.module}) -> ${each.target.export} (${each.target.module}) by ${each.by}
|
|
52
|
+
`icons: mapped ${each.source.export} (${each.source.module}) -> ${each.target.export} (${each.target.module}) by ${each.by}` +
|
|
53
|
+
(each.dropped && each.dropped.length > 0
|
|
54
|
+
? `; dropped ${each.dropped.join(', ')} (size comes from CSS)`
|
|
55
|
+
: ''),
|
|
53
56
|
),
|
|
54
57
|
...icons.kept.map(
|
|
55
58
|
each =>
|
|
@@ -29,6 +29,7 @@ import {describe, it, expect, beforeAll, afterAll} from 'vitest';
|
|
|
29
29
|
import * as fs from 'node:fs';
|
|
30
30
|
import * as path from 'node:path';
|
|
31
31
|
import * as os from 'node:os';
|
|
32
|
+
import * as crypto from 'node:crypto';
|
|
32
33
|
import {fileURLToPath} from 'node:url';
|
|
33
34
|
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
34
35
|
import {writeIconPackage} from '../../../test-utils/icon-set-fixture.mjs';
|
|
@@ -420,6 +421,51 @@ const CASES = [
|
|
|
420
421
|
'score — the reason states the tier',
|
|
421
422
|
],
|
|
422
423
|
},
|
|
424
|
+
{
|
|
425
|
+
name: 'experimental render',
|
|
426
|
+
args: ['experimental', 'render', 'page.jsx'],
|
|
427
|
+
cwd: '__TMP__',
|
|
428
|
+
// A page with no imports, in a folder that can resolve React.
|
|
429
|
+
setup: dir => {
|
|
430
|
+
fs.mkdirSync(path.join(dir, 'node_modules'), {recursive: true});
|
|
431
|
+
for (const pkg of ['react', 'react-dom']) {
|
|
432
|
+
fs.symlinkSync(
|
|
433
|
+
path.join(REPO_ROOT, 'node_modules', pkg),
|
|
434
|
+
path.join(dir, 'node_modules', pkg),
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
fs.writeFileSync(
|
|
438
|
+
path.join(dir, 'page.jsx'),
|
|
439
|
+
'export default function Page() { return <h1>Hello</h1>; }\n',
|
|
440
|
+
);
|
|
441
|
+
},
|
|
442
|
+
jsonFieldAllowlist: ['warnings — listed under Warnings when present'],
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
// The --reverse projection (same command, same folder as the case above).
|
|
446
|
+
name: 'experimental render',
|
|
447
|
+
args: ['experimental', 'render', '--reverse', 'carried.html', '--out', 'back.tsx', '--overwrite'],
|
|
448
|
+
cwd: '__TMP__',
|
|
449
|
+
// A rendered file that carries its page.
|
|
450
|
+
setup: dir => {
|
|
451
|
+
const source = Buffer.from('export default function Page() { return <h1>Hello</h1>; }\n');
|
|
452
|
+
const json = JSON.stringify({
|
|
453
|
+
version: 1,
|
|
454
|
+
entry: 'page.jsx',
|
|
455
|
+
files: [
|
|
456
|
+
{
|
|
457
|
+
path: 'page.jsx',
|
|
458
|
+
sha256: crypto.createHash('sha256').update(source).digest('hex'),
|
|
459
|
+
base64: source.toString('base64'),
|
|
460
|
+
},
|
|
461
|
+
],
|
|
462
|
+
});
|
|
463
|
+
fs.writeFileSync(
|
|
464
|
+
path.join(dir, 'carried.html'),
|
|
465
|
+
`<!doctype html><html><body><h1 class="astryx-heading">Hello</h1><script type="application/x-astryx-source">${json}</script></body></html>`,
|
|
466
|
+
);
|
|
467
|
+
},
|
|
468
|
+
},
|
|
423
469
|
{
|
|
424
470
|
name: 'manifest',
|
|
425
471
|
args: ['manifest'],
|
|
@@ -157,6 +157,13 @@ export const doc = {
|
|
|
157
157
|
'it is an installed dependency (such as anything in `node_modules`), is inside `.git`, `.hg`, or `.sl`, is a symbolic link, or is outside the project',
|
|
158
158
|
],
|
|
159
159
|
},
|
|
160
|
+
{
|
|
161
|
+
type: 'prose',
|
|
162
|
+
text:
|
|
163
|
+
'upgrade does not scan installed dependencies or version-control folders at all, including through a symbolic link: ' +
|
|
164
|
+
'a symlinked `node_modules`, or a link whose target is inside one or inside a package store such as `.yarn/cache`, is skipped. ' +
|
|
165
|
+
'Other symbolically linked folders are scanned so a change they need is reported, but nothing is written through them.',
|
|
166
|
+
},
|
|
160
167
|
{
|
|
161
168
|
type: 'prose',
|
|
162
169
|
text:
|
|
@@ -194,5 +201,15 @@ export const doc = {
|
|
|
194
201
|
'`Command:` line in its header, such as `// Command: pnpm run gen:panel`; upgrade prints it as ' +
|
|
195
202
|
'`Regenerate with: <command>` and lists it in `commands`.',
|
|
196
203
|
},
|
|
204
|
+
{type: 'heading', level: 3, text: 'A failed codemod'},
|
|
205
|
+
{
|
|
206
|
+
type: 'prose',
|
|
207
|
+
text:
|
|
208
|
+
'When a codemod or a `hooks.postCodemod` command fails, upgrade still makes every other change, exits 1 with ERR_CODEMOD_FAILED, and does not refresh the agent docs. ' +
|
|
209
|
+
'With --json, the result is the usual error, `{"error": ..., "code": "ERR_CODEMOD_FAILED"}`, plus a `receipt`: the same fields a finished run returns, with `complete: false`, ' +
|
|
210
|
+
'each failure in `errors`, and every file upgrade changed (or would change) in `modifiedFiles`, so a script can review, keep, or revert them. ' +
|
|
211
|
+
'An error that stops the run after codemods have written files, such as an astryx.config that fails validation, carries a `receipt` too. ' +
|
|
212
|
+
'Rerun past a failed codemod with --skip-codemod.',
|
|
213
|
+
},
|
|
197
214
|
],
|
|
198
215
|
};
|
|
@@ -199,6 +199,35 @@ describe('upgrade protected-file contract', () => {
|
|
|
199
199
|
});
|
|
200
200
|
});
|
|
201
201
|
|
|
202
|
+
it('keeps the error and adds the receipt when a hook leaves a protection declaration unreadable', () => {
|
|
203
|
+
seed();
|
|
204
|
+
write(
|
|
205
|
+
'astryx.config.mjs',
|
|
206
|
+
`export default {hooks: {postCodemod: [{name: 'regenerate', buildCommand: () => ({command: process.execPath, args: ['-e', ${JSON.stringify("require('node:fs').writeFileSync('.hgignore', 'syntax: regexp\\n[bad\\n')")}]})}]}};\n`,
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const applied = run([...ARGS, '--apply']);
|
|
210
|
+
|
|
211
|
+
expect(applied.status).toBe(1);
|
|
212
|
+
expect(applied.envelope).not.toHaveProperty('type');
|
|
213
|
+
expect(applied.envelope).toMatchObject({
|
|
214
|
+
code: 'ERR_CODEMOD_PROTECTION_SOURCE',
|
|
215
|
+
error: expect.stringContaining('.hgignore'),
|
|
216
|
+
receipt: {
|
|
217
|
+
complete: false,
|
|
218
|
+
errorCode: 'ERR_CODEMOD_PROTECTION_SOURCE',
|
|
219
|
+
modifiedFiles: ['src/owned.tsx'],
|
|
220
|
+
protectedFiles: [
|
|
221
|
+
expect.objectContaining({file: 'generated/panel.tsx'}),
|
|
222
|
+
],
|
|
223
|
+
errors: [expect.objectContaining({codemod: 'file-protection'})],
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
expect(fs.readFileSync(path.join(root, 'src/owned.tsx'), 'utf8')).toContain(
|
|
227
|
+
'minSize: 200',
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
|
|
202
231
|
it('runs declared regeneration and clears a generated-file block after reevaluation', () => {
|
|
203
232
|
seed({hook: true});
|
|
204
233
|
|
|
@@ -175,6 +175,43 @@ describe('astryx upgrade exit codes', () => {
|
|
|
175
175
|
expect(status).toBe(1);
|
|
176
176
|
expect(envelope.code).toBe('ERR_CODEMOD_FAILED');
|
|
177
177
|
expect(envelope.error).toMatch(/Post-codemod hook failed/);
|
|
178
|
+
// Additive: the receipt names what the run had already changed.
|
|
179
|
+
expect(envelope).toMatchObject({
|
|
180
|
+
receipt: {
|
|
181
|
+
complete: false,
|
|
182
|
+
errorCode: 'ERR_CODEMOD_FAILED',
|
|
183
|
+
modifiedFiles: ['src/panel.tsx'],
|
|
184
|
+
errors: [
|
|
185
|
+
expect.objectContaining({
|
|
186
|
+
codemod: 'post-codemod-hook',
|
|
187
|
+
error: expect.stringMatching(/Post-codemod hook failed/),
|
|
188
|
+
}),
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
}, SLOW);
|
|
193
|
+
|
|
194
|
+
it('reports what core codemods wrote when astryx.config then fails validation', async () => {
|
|
195
|
+
installPackage('@astryxdesign/core', '0.6.0');
|
|
196
|
+
write(
|
|
197
|
+
'src/panel.tsx',
|
|
198
|
+
"import {useResizable} from '@astryxdesign/core';\nexport const r = () => useResizable({minSizePx: 200});\n",
|
|
199
|
+
);
|
|
200
|
+
write('astryx.config.mjs', "export default {theme: 'neutral'};\n");
|
|
201
|
+
const {status, envelope} = await upgradeJson(['--from', '0.5.0', '--apply']);
|
|
202
|
+
expect(status).toBe(1);
|
|
203
|
+
expect(envelope).toMatchObject({
|
|
204
|
+
code: 'ERR_INVALID_ARGUMENT',
|
|
205
|
+
receipt: {
|
|
206
|
+
complete: false,
|
|
207
|
+
errorCode: 'ERR_INVALID_ARGUMENT',
|
|
208
|
+
modifiedFiles: ['src/panel.tsx'],
|
|
209
|
+
errors: [expect.objectContaining({codemod: 'config'})],
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
expect(fs.readFileSync(path.join(tmpDir, 'src/panel.tsx'), 'utf8')).toContain(
|
|
213
|
+
'minSize: 200',
|
|
214
|
+
);
|
|
178
215
|
}, SLOW);
|
|
179
216
|
|
|
180
217
|
it('lists a missing jscodeshift and the refused flag combinations', () => {
|
|
@@ -17,6 +17,7 @@ import * as fs from 'node:fs';
|
|
|
17
17
|
import * as path from 'node:path';
|
|
18
18
|
import {Command} from 'commander';
|
|
19
19
|
import {registerUpgrade} from './upgrade.mjs';
|
|
20
|
+
import {isError} from '../../../api/json/parse.mjs';
|
|
20
21
|
import {Project} from '../../../foundation/config/project.mjs';
|
|
21
22
|
import {
|
|
22
23
|
generateCompressedIndex,
|
|
@@ -47,6 +48,7 @@ beforeEach(() => {
|
|
|
47
48
|
});
|
|
48
49
|
|
|
49
50
|
afterEach(() => {
|
|
51
|
+
process.exitCode = undefined;
|
|
50
52
|
process.chdir(originalCwd);
|
|
51
53
|
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
52
54
|
vi.restoreAllMocks();
|
|
@@ -298,6 +300,13 @@ describe('upgrade integration error policy (skip + warn)', () => {
|
|
|
298
300
|
]);
|
|
299
301
|
|
|
300
302
|
expect(result.code).toBe('ERR_CODEMOD_FAILED');
|
|
303
|
+
expect(result.receipt).toMatchObject({
|
|
304
|
+
complete: false,
|
|
305
|
+
errorCode: 'ERR_CODEMOD_FAILED',
|
|
306
|
+
agentDocsRefreshed: false,
|
|
307
|
+
modifiedFiles: ['src/index.ts'],
|
|
308
|
+
errors: [expect.objectContaining({codemod: 'post-codemod-hook'})],
|
|
309
|
+
});
|
|
301
310
|
expect(fs.readFileSync(path.join(tmpDir, 'AGENTS.md'), 'utf-8')).toBe(
|
|
302
311
|
before,
|
|
303
312
|
);
|
|
@@ -476,3 +485,97 @@ describe('upgrade integration error policy (skip + warn)', () => {
|
|
|
476
485
|
expect(out).not.toContain('bar');
|
|
477
486
|
});
|
|
478
487
|
});
|
|
488
|
+
|
|
489
|
+
describe('upgrade failure receipt when a codemod fails', () => {
|
|
490
|
+
const codemods = {
|
|
491
|
+
'0.2.0/drop-foo.mjs': `export default {type: 'code', title: 'Drop foo', transform: file => file.source.replace(/foo/g, 'bar')};\n`,
|
|
492
|
+
'0.2.0/fail.mjs': `export default {type: 'code', title: 'Fail on boom', transform: file => { if (file.source.includes('boom')) throw new Error('codemod boom'); return undefined; }};\n`,
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
function scaffold() {
|
|
496
|
+
scaffoldIntegration(codemods);
|
|
497
|
+
writeInstalledCore('0.2.0');
|
|
498
|
+
writeSource();
|
|
499
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'broken.ts'), 'const boom = 1;\n');
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const ARGS = ['upgrade', '--from', '0.1.0', '--path', 'src'];
|
|
503
|
+
|
|
504
|
+
it('keeps the error envelope and adds the receipt of what was written', async () => {
|
|
505
|
+
scaffold();
|
|
506
|
+
|
|
507
|
+
const result = await runJson(['--json', ...ARGS, '--apply']);
|
|
508
|
+
|
|
509
|
+
expect(exitCode).toBe(1);
|
|
510
|
+
expect(isError(result)).toBe(true);
|
|
511
|
+
expect(result).not.toHaveProperty('type');
|
|
512
|
+
expect(result).toMatchObject({
|
|
513
|
+
apiVersion: 1,
|
|
514
|
+
code: 'ERR_CODEMOD_FAILED',
|
|
515
|
+
error: 'Upgrade completed with 1 codemod error.',
|
|
516
|
+
receipt: {
|
|
517
|
+
complete: false,
|
|
518
|
+
errorCode: 'ERR_CODEMOD_FAILED',
|
|
519
|
+
filesChanged: 1,
|
|
520
|
+
modifiedFiles: ['src/index.ts'],
|
|
521
|
+
protectedFiles: [],
|
|
522
|
+
errors: [
|
|
523
|
+
{
|
|
524
|
+
file: 'src/broken.ts',
|
|
525
|
+
codemod: '@acme/widgets:fail',
|
|
526
|
+
error: 'codemod boom',
|
|
527
|
+
},
|
|
528
|
+
],
|
|
529
|
+
},
|
|
530
|
+
});
|
|
531
|
+
expect(fs.readFileSync(path.join(tmpDir, 'src', 'index.ts'), 'utf-8')).toBe(
|
|
532
|
+
'const bar = 1;\n',
|
|
533
|
+
);
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
it('previews the same receipt in a dry run without writing', async () => {
|
|
537
|
+
scaffold();
|
|
538
|
+
|
|
539
|
+
const result = await runJson(['--json', ...ARGS]);
|
|
540
|
+
|
|
541
|
+
expect(result.code).toBe('ERR_CODEMOD_FAILED');
|
|
542
|
+
expect(result.receipt).toMatchObject({
|
|
543
|
+
complete: false,
|
|
544
|
+
modifiedFiles: ['src/index.ts'],
|
|
545
|
+
errors: [expect.objectContaining({file: 'src/broken.ts'})],
|
|
546
|
+
});
|
|
547
|
+
expect(fs.readFileSync(path.join(tmpDir, 'src', 'index.ts'), 'utf-8')).toBe(
|
|
548
|
+
'const foo = 1;\n',
|
|
549
|
+
);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
it('still returns the protected-file receipt when a protected file remains', async () => {
|
|
553
|
+
scaffold();
|
|
554
|
+
fs.writeFileSync(
|
|
555
|
+
path.join(tmpDir, 'src', 'gen.ts'),
|
|
556
|
+
'// @generated\nconst foo = 2;\n',
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
const result = await runJson(['--json', ...ARGS, '--apply']);
|
|
560
|
+
|
|
561
|
+
expect(result).toMatchObject({
|
|
562
|
+
type: 'upgrade.run',
|
|
563
|
+
data: {
|
|
564
|
+
complete: false,
|
|
565
|
+
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
566
|
+
protectedFiles: [expect.objectContaining({file: 'src/gen.ts'})],
|
|
567
|
+
errors: [expect.objectContaining({file: 'src/broken.ts'})],
|
|
568
|
+
},
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
it('keeps the human output and exit status in text mode', async () => {
|
|
573
|
+
scaffold();
|
|
574
|
+
|
|
575
|
+
await runJson([...ARGS, '--apply']);
|
|
576
|
+
|
|
577
|
+
expect(process.exitCode).toBe(1);
|
|
578
|
+
expect(logCalls.join('\n')).toMatch(/Upgrade failed/);
|
|
579
|
+
expect(logCalls.join('\n')).not.toMatch(/"receipt"/);
|
|
580
|
+
});
|
|
581
|
+
});
|
|
@@ -57,8 +57,15 @@ export function registerUpgrade(program) {
|
|
|
57
57
|
// already printed the error before throwing.
|
|
58
58
|
logger.setSilent(json);
|
|
59
59
|
if (e instanceof AstryxError) {
|
|
60
|
-
if (json)
|
|
61
|
-
|
|
60
|
+
if (json) {
|
|
61
|
+
// A failed migration still names the files it already changed.
|
|
62
|
+
jsonError(
|
|
63
|
+
e.message,
|
|
64
|
+
undefined,
|
|
65
|
+
e.code,
|
|
66
|
+
/** @type {any} */ (e).receipt,
|
|
67
|
+
);
|
|
68
|
+
} else {
|
|
62
69
|
// The logger was silent only for --list; replay the error there.
|
|
63
70
|
// Non-list failures were already printed by the API.
|
|
64
71
|
if (isList) logger.error(e.message);
|
package/clients/cli/index.mjs
CHANGED
|
@@ -127,7 +127,8 @@ export function docStem(docPath: string): string;
|
|
|
127
127
|
/**
|
|
128
128
|
* The local module a doc's import names: the doc's own `import`, else the
|
|
129
129
|
* subpath its directory publishes, read through the package's `exports` (its
|
|
130
|
-
* `main` when it has none).
|
|
130
|
+
* `main` when it has none). A subpath's `source` condition wins when its file
|
|
131
|
+
* is in the package, so the answer does not depend on a build. Undefined when the package directory is unknown;
|
|
131
132
|
* null when the import names another package or resolves to no file.
|
|
132
133
|
*
|
|
133
134
|
* @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
|
|
@@ -705,6 +705,47 @@ describe('integration components a family doc lists in components', () => {
|
|
|
705
705
|
expect(namesIn(loaded)).toEqual(['AcmeList']);
|
|
706
706
|
});
|
|
707
707
|
|
|
708
|
+
it('reads members through the source condition, the same with or without built output', () => {
|
|
709
|
+
// The family's member is exported only from the root entry, as Lab's
|
|
710
|
+
// TourStep is.
|
|
711
|
+
const loaded = writePackage(
|
|
712
|
+
{
|
|
713
|
+
exports: {
|
|
714
|
+
'.': {
|
|
715
|
+
source: './src/index.ts',
|
|
716
|
+
types: './dist/index.d.ts',
|
|
717
|
+
default: './dist/index.js',
|
|
718
|
+
},
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
'src/index.ts':
|
|
723
|
+
"export {AcmeList} from './list/AcmeList';\nexport {AcmeListRow} from './list/row';\n",
|
|
724
|
+
'src/list/AcmeList.doc.mjs': family(
|
|
725
|
+
'AcmeList',
|
|
726
|
+
"{name: 'AcmeList', description: 'x'}, {name: 'AcmeListRow', description: 'x'}",
|
|
727
|
+
),
|
|
728
|
+
'src/list/AcmeList.tsx':
|
|
729
|
+
'export function AcmeList() { return null; }\n',
|
|
730
|
+
'src/list/row.tsx': 'export function AcmeListRow() { return null; }\n',
|
|
731
|
+
},
|
|
732
|
+
);
|
|
733
|
+
expect(namesIn(loaded)).toEqual(['AcmeList', 'AcmeListRow']);
|
|
734
|
+
expect(findIntegrationComponentSource(loaded, 'AcmeListRow')).toBe(
|
|
735
|
+
path.join(root, 'src', 'list', 'row.tsx'),
|
|
736
|
+
);
|
|
737
|
+
// Built output, even a stale one without the member, changes nothing.
|
|
738
|
+
fs.mkdirSync(path.join(root, 'dist'), {recursive: true});
|
|
739
|
+
fs.writeFileSync(
|
|
740
|
+
path.join(root, 'dist', 'index.js'),
|
|
741
|
+
'export function AcmeList() { return null; }\n',
|
|
742
|
+
);
|
|
743
|
+
expect(namesIn(loaded)).toEqual(['AcmeList', 'AcmeListRow']);
|
|
744
|
+
// A package that does not ship its source reads the built output.
|
|
745
|
+
fs.rmSync(path.join(root, 'src', 'index.ts'));
|
|
746
|
+
expect(namesIn(loaded)).toEqual(['AcmeList']);
|
|
747
|
+
});
|
|
748
|
+
|
|
708
749
|
it('lists a member another folder declares, with no source', async () => {
|
|
709
750
|
const loaded = writePackage(
|
|
710
751
|
{exports: {'./menu': './src/menu/index.ts'}},
|
|
@@ -18,7 +18,10 @@ import {
|
|
|
18
18
|
moduleExportsName,
|
|
19
19
|
staticExportObject,
|
|
20
20
|
} from './module-exports.mjs';
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
inspectPackageExport,
|
|
23
|
+
sourceExportTarget,
|
|
24
|
+
} from './package-exports.mjs';
|
|
22
25
|
|
|
23
26
|
const require = createRequire(import.meta.url);
|
|
24
27
|
|
|
@@ -996,7 +999,8 @@ function packageMain(packageDir) {
|
|
|
996
999
|
/**
|
|
997
1000
|
* The local module a doc's import names: the doc's own `import`, else the
|
|
998
1001
|
* subpath its directory publishes, read through the package's `exports` (its
|
|
999
|
-
* `main` when it has none).
|
|
1002
|
+
* `main` when it has none). A subpath's `source` condition wins when its file
|
|
1003
|
+
* is in the package, so the answer does not depend on a build. Undefined when the package directory is unknown;
|
|
1000
1004
|
* null when the import names another package or resolves to no file.
|
|
1001
1005
|
*
|
|
1002
1006
|
* @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
|
|
@@ -1027,11 +1031,13 @@ export function importedModule(integration, docPath, doc) {
|
|
|
1027
1031
|
specifier === packageName
|
|
1028
1032
|
? '.'
|
|
1029
1033
|
: `./${specifier.slice(packageName.length + 1)}`;
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1034
|
+
const pkg = {name: packageName, exports: exportsMap ?? undefined};
|
|
1035
|
+
// The `source` condition first, when its file is there, so a family lists
|
|
1036
|
+
// the same members whether or not the package has been built.
|
|
1037
|
+
return (
|
|
1038
|
+
sourceExportTarget(pkg, packageDir, subpath) ??
|
|
1039
|
+
inspectPackageExport(pkg, packageDir, subpath).target
|
|
1040
|
+
);
|
|
1035
1041
|
}
|
|
1036
1042
|
|
|
1037
1043
|
/**
|