@astryxdesign/cli 0.7.4 → 0.7.5-canary.0026f37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -18
- package/api/component/_adapter.mjs +16 -1
- package/api/component/component.test.mjs +31 -0
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +5 -2
- package/api/docs/_adapter.mjs +24 -16
- package/api/docs/docs.test.mjs +18 -0
- package/api/docs/integrationDocs.test.mjs +2 -2
- package/api/experimental.d.mts +5 -0
- package/api/experimental.mjs +15 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +16 -3
- package/api/icon/_authoring.d.mts +5 -1
- package/api/icon/_authoring.mjs +478 -63
- package/api/icon/_options.d.mts +11 -0
- package/api/icon/_options.mjs +39 -4
- package/api/icon/_records.d.mts +19 -0
- package/api/icon/_records.mjs +25 -0
- package/api/icon/add/add.d.mts +3 -3
- package/api/icon/add/add.mjs +227 -14
- package/api/icon/all-or-nothing.test.mjs +283 -0
- package/api/icon/detail/detail.mjs +2 -13
- package/api/icon/error-codes.test.mjs +14 -7
- package/api/icon/icon.d.mts +2 -2
- package/api/icon/icon.doc.mjs +30 -2
- package/api/icon/icon.mjs +57 -8
- package/api/icon/icon.test.mjs +133 -1
- package/api/icon/icon.type.d.mts +126 -1
- package/api/icon/icon.type.mjs +67 -3
- package/api/icon/iconAdd.doc.mjs +22 -6
- package/api/icon/iconMap.doc.mjs +24 -8
- package/api/icon/iconNewDefinition.doc.mjs +2 -2
- package/api/icon/iconNewSet.doc.mjs +30 -2
- package/api/icon/iconUse.doc.mjs +4 -1
- package/api/icon/map/map.d.mts +4 -4
- package/api/icon/map/map.mjs +134 -9
- package/api/icon/new-definition/new-definition.mjs +6 -2
- package/api/icon/new-set/new-set.mjs +2 -2
- package/api/icon/new-set/new-set.test.mjs +60 -10
- package/api/icon/option-pairs.test.mjs +368 -0
- package/api/icon/search/search.d.mts +10 -0
- package/api/icon/search/search.mjs +55 -14
- package/api/icon/use/use.mjs +2 -13
- package/api/integration/add-helpers.d.mts +15 -1
- package/api/integration/add-helpers.mjs +1 -1
- package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
- package/api/integration/pack-check.mjs +10 -4
- package/api/integration/pack-check.test.mjs +5 -1
- package/api/integration/validate-integration.type.d.mts +3 -2
- package/api/integration/validate-integration.type.mjs +3 -2
- package/api/render/_adapter.d.mts +28 -0
- package/api/render/_adapter.mjs +540 -0
- package/api/render/render.d.mts +15 -0
- package/api/render/render.doc.d.mts +9 -0
- package/api/render/render.doc.mjs +112 -0
- package/api/render/render.mjs +113 -0
- package/api/render/render.test.mjs +1155 -0
- package/api/render/render.type.d.mts +74 -0
- package/api/render/render.type.mjs +64 -0
- package/api/search/_adapter.test.mjs +21 -2
- package/api/search/_result.d.mts +5 -5
- package/api/search/search.d.mts +1 -1
- package/api/template/template.mjs +3 -1
- package/api/template/template.type.d.mts +2 -1
- package/api/template/template.type.mjs +1 -1
- package/api/template/unknown-name.test.mjs +63 -0
- package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +123 -70
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +19 -77
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
- package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +50 -20
- package/assets/docs/tree/render-pages.doc.mjs +94 -0
- package/assets/icons/definitions/activity.doc.mjs +1 -1
- package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
- package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
- package/assets/icons/definitions/alignStart.doc.mjs +10 -0
- package/assets/icons/definitions/archive.doc.mjs +1 -1
- package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
- package/assets/icons/definitions/attach.doc.mjs +1 -1
- package/assets/icons/definitions/audio.doc.mjs +1 -1
- package/assets/icons/definitions/cart.doc.mjs +1 -1
- package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
- package/assets/icons/definitions/close.doc.mjs +1 -1
- package/assets/icons/definitions/collapse.doc.mjs +1 -1
- package/assets/icons/definitions/compose.doc.mjs +1 -1
- package/assets/icons/definitions/conversation.doc.mjs +1 -1
- package/assets/icons/definitions/copy.doc.mjs +1 -1
- package/assets/icons/definitions/cpu.doc.mjs +9 -0
- package/assets/icons/definitions/database.doc.mjs +1 -1
- package/assets/icons/definitions/desktop.doc.mjs +1 -1
- package/assets/icons/definitions/discount.doc.mjs +1 -1
- package/assets/icons/definitions/download.doc.mjs +1 -1
- package/assets/icons/definitions/emoji.doc.mjs +1 -1
- package/assets/icons/definitions/error.doc.mjs +1 -1
- package/assets/icons/definitions/expand.doc.mjs +1 -1
- package/assets/icons/definitions/experiment.doc.mjs +1 -1
- package/assets/icons/definitions/externalLink.doc.mjs +7 -1
- package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
- package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
- package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
- package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
- package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
- package/assets/icons/definitions/gitFork.doc.mjs +9 -0
- package/assets/icons/definitions/info.doc.mjs +1 -1
- package/assets/icons/definitions/location.doc.mjs +1 -1
- package/assets/icons/definitions/mention.doc.mjs +1 -1
- package/assets/icons/definitions/menu.doc.mjs +1 -1
- package/assets/icons/definitions/microphone.doc.mjs +1 -1
- package/assets/icons/definitions/mobile.doc.mjs +1 -1
- package/assets/icons/definitions/money.doc.mjs +1 -1
- package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
- package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
- package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
- package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
- package/assets/icons/definitions/panelRight.doc.mjs +10 -0
- package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
- package/assets/icons/definitions/redo.doc.mjs +1 -1
- package/assets/icons/definitions/refresh.doc.mjs +1 -1
- package/assets/icons/definitions/rotate.doc.mjs +9 -0
- package/assets/icons/definitions/scale.doc.mjs +10 -0
- package/assets/icons/definitions/search.doc.mjs +1 -1
- package/assets/icons/definitions/send.doc.mjs +1 -1
- package/assets/icons/definitions/settings.doc.mjs +1 -1
- package/assets/icons/definitions/star.doc.mjs +1 -1
- package/assets/icons/definitions/stop.doc.mjs +1 -1
- package/assets/icons/definitions/success.doc.mjs +1 -1
- package/assets/icons/definitions/textCase.doc.mjs +9 -0
- package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
- package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
- package/assets/icons/definitions/trendDown.doc.mjs +7 -1
- package/assets/icons/definitions/trendUp.doc.mjs +1 -1
- package/assets/icons/definitions/undo.doc.mjs +1 -1
- package/assets/icons/definitions/upload.doc.mjs +1 -1
- package/assets/icons/definitions/userAdd.doc.mjs +1 -1
- package/assets/icons/definitions/warning.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +9 -8
- package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
- package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
- package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
- package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
- package/authoring/debug/parse.d.mts +2 -2
- package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
- package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
- package/authoring/doctypes/icon-set/parse.d.mts +1 -0
- package/authoring/doctypes/icon-set/parse.mjs +1 -0
- package/authoring/doctypes/icon-set/type.ts +5 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +2 -1
- package/clients/cli/commands/doctor.mjs +16 -17
- package/clients/cli/commands/experimental/icon.mjs +167 -35
- package/clients/cli/commands/experimental/index.mjs +2 -0
- package/clients/cli/commands/experimental/render.mjs +113 -0
- package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
- package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
- package/clients/cli/commands/experimental-render.doc.mjs +60 -0
- package/clients/cli/commands/experimental.doc.mjs +4 -2
- package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
- package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
- package/clients/cli/commands/icon.test.mjs +1 -1
- package/clients/cli/commands/template.mjs +4 -1
- package/clients/cli/commands/text-json-parity.test.mjs +46 -0
- package/clients/cli/index.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +2 -1
- package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
- package/foundation/discovery/component-discovery.mjs +13 -7
- package/foundation/discovery/icon-set-checks.d.mts +43 -9
- package/foundation/discovery/icon-set-checks.mjs +296 -21
- package/foundation/discovery/icon-set-checks.test.mjs +125 -12
- package/foundation/discovery/icon-set-writer.d.mts +192 -3
- package/foundation/discovery/icon-set-writer.mjs +608 -34
- package/foundation/discovery/icon-set-writer.test.mjs +26 -0
- package/foundation/discovery/module-exports.mjs +82 -25
- package/foundation/discovery/module-exports.test.mjs +38 -1
- package/foundation/discovery/package-exports.d.mts +13 -0
- package/foundation/discovery/package-exports.mjs +40 -1
- package/foundation/discovery/template-icons.d.mts +6 -0
- package/foundation/discovery/template-icons.mjs +98 -10
- package/foundation/discovery/template-icons.test.mjs +103 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +20 -5
- package/foundation/doc-compiler/import.mjs +81 -8
- package/foundation/doc-compiler/read.d.mts +4 -3
- package/foundation/doc-compiler/read.mjs +15 -10
- package/foundation/doc-compiler/read.test.mjs +59 -1
- package/foundation/doc-compiler/tree.mjs +3 -1
- package/foundation/fs/module-loader.d.mts +3 -2
- package/foundation/fs/module-loader.mjs +3 -2
- package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
- package/foundation/fs/read-record.d.mts +27 -0
- package/foundation/fs/read-record.mjs +83 -15
- package/foundation/fs/read-record.test.mjs +88 -1
- package/foundation/render/assets.d.mts +31 -0
- package/foundation/render/assets.mjs +102 -0
- package/foundation/render/component-map.d.mts +52 -0
- package/foundation/render/component-map.mjs +141 -0
- package/foundation/render/css-cut.d.mts +29 -0
- package/foundation/render/css-cut.mjs +144 -0
- package/foundation/render/embedded-files.d.mts +28 -0
- package/foundation/render/embedded-files.mjs +108 -0
- package/foundation/render/embedded-imports.d.mts +61 -0
- package/foundation/render/embedded-imports.mjs +315 -0
- package/foundation/render/html-reader.d.mts +37 -0
- package/foundation/render/html-reader.mjs +121 -0
- package/foundation/render/page-worker.d.mts +7 -0
- package/foundation/render/page-worker.mjs +519 -0
- package/foundation/render/rebuild.d.mts +19 -0
- package/foundation/render/rebuild.mjs +269 -0
- package/foundation/render/render-page.d.mts +85 -0
- package/foundation/render/render-page.mjs +612 -0
- package/foundation/render/render.test.mjs +117 -0
- package/foundation/render/source-block.d.mts +52 -0
- package/foundation/render/source-block.mjs +106 -0
- package/foundation/response/error-codes.d.mts +10 -1
- package/foundation/response/error-codes.doc.mjs +56 -0
- package/foundation/response/error-codes.mjs +61 -0
- package/foundation/response/response-types.doc.mjs +38 -1
- package/foundation/text/string-utils.mjs +33 -0
- package/foundation/text/string-utils.test.mjs +17 -0
- package/foundation/text/suggest-order.d.mts +17 -3
- package/foundation/text/suggest-order.mjs +58 -13
- package/foundation/text/suggest-order.test.mjs +53 -0
- package/package.json +14 -9
|
@@ -115,8 +115,14 @@ describe('experimental icon new-set --from', () => {
|
|
|
115
115
|
]);
|
|
116
116
|
expect(code).toBe(0);
|
|
117
117
|
expect(body.data).toMatchObject({kind: 'icon-set', icons: 2});
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
// The package's entry is the author's: the receipt names the exact line
|
|
119
|
+
// and the entry stays as it was (architecture:cli-surface INV16).
|
|
120
|
+
expect(body.data.files).not.toContain('index.js');
|
|
121
|
+
expect(fs.readFileSync(path.join(pkg, 'index.js'), 'utf-8')).toBe(
|
|
122
|
+
'export {};\n',
|
|
123
|
+
);
|
|
124
|
+
expect(body.data.notes).toContain(
|
|
125
|
+
"Add `export * from './icon-sets/outline/outline.generated.js';` to index.js, so the icons import from @acme/icons.",
|
|
120
126
|
);
|
|
121
127
|
const data = dataOf('outline');
|
|
122
128
|
expect(data.generated).toBe('./icon-sets/outline/outline.generated.js');
|
|
@@ -124,8 +130,19 @@ describe('experimental icon new-set --from', () => {
|
|
|
124
130
|
{id: 'bin', export: 'BinIcon', words: ['bin']},
|
|
125
131
|
{id: 'cross', export: 'CrossIcon', words: ['cross']},
|
|
126
132
|
]);
|
|
127
|
-
// `delete` has the word bin
|
|
128
|
-
|
|
133
|
+
// `delete` has the word bin, but a word alone is only a suggestion: a
|
|
134
|
+
// library's bin may not mean delete. Nothing is written for it.
|
|
135
|
+
expect(data.map).toEqual({});
|
|
136
|
+
expect(body.data.suggestions).toContainEqual({
|
|
137
|
+
definition: 'delete',
|
|
138
|
+
icon: 'bin',
|
|
139
|
+
word: 'bin',
|
|
140
|
+
});
|
|
141
|
+
// The installed library and version are the set's source.
|
|
142
|
+
expect(data.source).toEqual({
|
|
143
|
+
package: '@acme/glyph-library',
|
|
144
|
+
version: '2.0.0',
|
|
145
|
+
});
|
|
129
146
|
const generated = fs.readFileSync(
|
|
130
147
|
path.join(pkg, 'icon-sets', 'outline', 'outline.generated.js'),
|
|
131
148
|
'utf-8',
|
|
@@ -146,7 +163,121 @@ describe('experimental icon new-set --from', () => {
|
|
|
146
163
|
'@acme/glyph-library',
|
|
147
164
|
]);
|
|
148
165
|
expect(again.code).toBe(0);
|
|
149
|
-
expect(dataOf('outline').map).
|
|
166
|
+
expect(dataOf('outline').map).toEqual({});
|
|
167
|
+
expect(again.body.data.suggestions).toContainEqual({
|
|
168
|
+
definition: 'delete',
|
|
169
|
+
icon: 'bin',
|
|
170
|
+
word: 'bin',
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('maps a definition only by its exact name, and prints the rest as suggestions', async () => {
|
|
175
|
+
// A library icon named after a definition (`close`) maps; a word (`bin`)
|
|
176
|
+
// does not.
|
|
177
|
+
fs.writeFileSync(
|
|
178
|
+
path.join(
|
|
179
|
+
pkg,
|
|
180
|
+
'node_modules',
|
|
181
|
+
'@acme',
|
|
182
|
+
'glyph-library',
|
|
183
|
+
'icons',
|
|
184
|
+
'close.js',
|
|
185
|
+
),
|
|
186
|
+
'export const Close = props => null;\n',
|
|
187
|
+
);
|
|
188
|
+
fs.appendFileSync(
|
|
189
|
+
path.join(pkg, 'node_modules', '@acme', 'glyph-library', 'index.js'),
|
|
190
|
+
"export {Close} from './icons/close.js';\n",
|
|
191
|
+
);
|
|
192
|
+
const res = await runCli(
|
|
193
|
+
[
|
|
194
|
+
'experimental',
|
|
195
|
+
'icon',
|
|
196
|
+
'new-set',
|
|
197
|
+
'outline',
|
|
198
|
+
'--from',
|
|
199
|
+
'@acme/glyph-library',
|
|
200
|
+
],
|
|
201
|
+
pkg,
|
|
202
|
+
);
|
|
203
|
+
expect(res.code).toBe(0);
|
|
204
|
+
expect(dataOf('outline').map).toEqual({close: 'close'});
|
|
205
|
+
expect(res.stdout).toContain('Suggestions');
|
|
206
|
+
expect(res.stdout).toContain('experimental icon map delete bin');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('--variants and --default-variant declare the variants; the library license notice is copied', async () => {
|
|
210
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
211
|
+
fs.writeFileSync(path.join(lib, 'LICENSE'), 'MIT License\n');
|
|
212
|
+
const pkgJson = JSON.parse(
|
|
213
|
+
fs.readFileSync(path.join(lib, 'package.json'), 'utf-8'),
|
|
214
|
+
);
|
|
215
|
+
fs.writeFileSync(
|
|
216
|
+
path.join(lib, 'package.json'),
|
|
217
|
+
JSON.stringify({...pkgJson, license: 'ISC'}),
|
|
218
|
+
);
|
|
219
|
+
const {code, body} = await json([
|
|
220
|
+
'experimental',
|
|
221
|
+
'icon',
|
|
222
|
+
'new-set',
|
|
223
|
+
'glyphs',
|
|
224
|
+
'--from',
|
|
225
|
+
'@acme/glyph-library',
|
|
226
|
+
'--variants',
|
|
227
|
+
'outline,solid',
|
|
228
|
+
'--default-variant',
|
|
229
|
+
'outline',
|
|
230
|
+
]);
|
|
231
|
+
expect(code).toBe(0);
|
|
232
|
+
const data = dataOf('glyphs');
|
|
233
|
+
expect(data.variants).toEqual(['outline', 'solid']);
|
|
234
|
+
expect(data.default).toEqual({variant: 'outline'});
|
|
235
|
+
expect(body.data.files).toContain('icon-sets/glyphs/LICENSE');
|
|
236
|
+
// No TypeScript here: the receipt says the strict check needs one.
|
|
237
|
+
expect(body.data.notes.join(' ')).toContain('npm install -D typescript@6');
|
|
238
|
+
expect(
|
|
239
|
+
fs.readFileSync(
|
|
240
|
+
path.join(pkg, 'icon-sets', 'glyphs', 'LICENSE'),
|
|
241
|
+
'utf-8',
|
|
242
|
+
),
|
|
243
|
+
).toBe('MIT License\n');
|
|
244
|
+
expect(
|
|
245
|
+
fs.readFileSync(
|
|
246
|
+
path.join(pkg, 'icon-sets', 'glyphs', 'glyphs.doc.mjs'),
|
|
247
|
+
'utf-8',
|
|
248
|
+
),
|
|
249
|
+
).toContain("license: 'ISC'");
|
|
250
|
+
const check = JSON.stringify(
|
|
251
|
+
JSON.parse(
|
|
252
|
+
(await runCli(['integration', 'check', '--json'], pkg)).stdout,
|
|
253
|
+
),
|
|
254
|
+
);
|
|
255
|
+
expect(check).not.toContain('icon_license_notice_missing');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('refuses a --default-variant that is not a variant, and --default-variant without --variants', async () => {
|
|
259
|
+
const bad = await json([
|
|
260
|
+
'experimental',
|
|
261
|
+
'icon',
|
|
262
|
+
'new-set',
|
|
263
|
+
'glyphs',
|
|
264
|
+
'--variants',
|
|
265
|
+
'outline,solid',
|
|
266
|
+
'--default-variant',
|
|
267
|
+
'mini',
|
|
268
|
+
]);
|
|
269
|
+
expect(bad.code).toBe(1);
|
|
270
|
+
expect(bad.body.error).toContain('not one of --variants');
|
|
271
|
+
const lone = await json([
|
|
272
|
+
'experimental',
|
|
273
|
+
'icon',
|
|
274
|
+
'new-set',
|
|
275
|
+
'glyphs',
|
|
276
|
+
'--default-variant',
|
|
277
|
+
'outline',
|
|
278
|
+
]);
|
|
279
|
+
expect(lone.code).toBe(1);
|
|
280
|
+
expect(lone.body.error).toContain('needs --variants');
|
|
150
281
|
});
|
|
151
282
|
|
|
152
283
|
it('the theme map reads each re-exported icon through an import, so the generated module loads', async () => {
|
|
@@ -239,7 +370,14 @@ describe('icon add', () => {
|
|
|
239
370
|
definition: 'delete',
|
|
240
371
|
changed: true,
|
|
241
372
|
});
|
|
242
|
-
|
|
373
|
+
// The entry is not wired yet: the note names the line, and the entry
|
|
374
|
+
// stays the author's.
|
|
375
|
+
expect(first.body.data.note).toBe(
|
|
376
|
+
"Add `export * from './icon-sets/outline/outline.generated.js';` to index.js, so the icons import from @acme/icons.",
|
|
377
|
+
);
|
|
378
|
+
expect(fs.readFileSync(path.join(pkg, 'index.js'), 'utf-8')).toBe(
|
|
379
|
+
'export {};\n',
|
|
380
|
+
);
|
|
243
381
|
const data = dataOf('outline');
|
|
244
382
|
expect(data.map).toEqual({delete: 'bin'});
|
|
245
383
|
expect(data.icons[0]).toMatchObject({id: 'bin', export: 'BinIcon'});
|
|
@@ -555,13 +693,13 @@ describe('experimental icon map and new-definition', () => {
|
|
|
555
693
|
'experimental',
|
|
556
694
|
'icon',
|
|
557
695
|
'map',
|
|
558
|
-
'
|
|
696
|
+
'orbit',
|
|
559
697
|
'cross',
|
|
560
698
|
]);
|
|
561
699
|
expect(unknown.code).toBe(1);
|
|
562
700
|
expect(unknown.body.suggestions).toContainEqual(
|
|
563
701
|
expect.objectContaining({
|
|
564
|
-
name: 'astryx experimental icon new-definition
|
|
702
|
+
name: 'astryx experimental icon new-definition orbit --set outline',
|
|
565
703
|
}),
|
|
566
704
|
);
|
|
567
705
|
const noIcon = await json([
|
|
@@ -943,13 +1081,29 @@ describe('the library prefix ignores constants', () => {
|
|
|
943
1081
|
'GlyphXIcon',
|
|
944
1082
|
'MetaIcon',
|
|
945
1083
|
]);
|
|
946
|
-
|
|
947
|
-
|
|
1084
|
+
// Excluding meta lets the prefix come off the new ids; each existing icon
|
|
1085
|
+
// is the same icon (the same library export), so it keeps its public
|
|
1086
|
+
// export, and only meta leaves the module.
|
|
1087
|
+
const excluded = await wrap(['--exclude', 'meta']);
|
|
1088
|
+
expect(excluded.code).toBe(0);
|
|
1089
|
+
expect(exportsOf()).toEqual([
|
|
1090
|
+
'GlyphEyeIcon',
|
|
1091
|
+
'GlyphTrashIcon',
|
|
1092
|
+
'GlyphXIcon',
|
|
1093
|
+
]);
|
|
1094
|
+
expect(dataOf('outline').icons.map((/** @type {any} */ i) => i.id)).toEqual(
|
|
1095
|
+
['eye', 'trash', 'x'],
|
|
1096
|
+
);
|
|
1097
|
+
expect(excluded.body.data.renamed).toEqual([
|
|
1098
|
+
{from: 'glyph-eye', to: 'eye'},
|
|
1099
|
+
{from: 'glyph-trash', to: 'trash'},
|
|
1100
|
+
{from: 'glyph-x', to: 'x'},
|
|
1101
|
+
]);
|
|
948
1102
|
const generated = fs.readFileSync(
|
|
949
1103
|
path.join(pkg, 'icon-sets', 'outline', 'outline.generated.js'),
|
|
950
1104
|
'utf-8',
|
|
951
1105
|
);
|
|
952
|
-
expect(generated).not.toContain('
|
|
1106
|
+
expect(generated).not.toContain('MetaIcon');
|
|
953
1107
|
expect(generated).not.toContain('README');
|
|
954
1108
|
expect(generated).not.toContain('notes');
|
|
955
1109
|
// icon add reuses the icon the wrap already made for an export, even
|
|
@@ -967,9 +1121,13 @@ describe('the library prefix ignores constants', () => {
|
|
|
967
1121
|
expect(added.code).toBe(0);
|
|
968
1122
|
expect(added.body.data.icon).toMatchObject({
|
|
969
1123
|
id: 'trash',
|
|
970
|
-
export: '
|
|
1124
|
+
export: 'GlyphTrashIcon',
|
|
971
1125
|
});
|
|
972
|
-
expect(exportsOf()).toEqual([
|
|
1126
|
+
expect(exportsOf()).toEqual([
|
|
1127
|
+
'GlyphEyeIcon',
|
|
1128
|
+
'GlyphTrashIcon',
|
|
1129
|
+
'GlyphXIcon',
|
|
1130
|
+
]);
|
|
973
1131
|
});
|
|
974
1132
|
|
|
975
1133
|
it('--exclude needs --from', async () => {
|
|
@@ -1033,3 +1191,1655 @@ describe('module resolution', () => {
|
|
|
1033
1191
|
expect(check.stdout).not.toContain('icon_export_missing');
|
|
1034
1192
|
}, 60_000);
|
|
1035
1193
|
});
|
|
1194
|
+
|
|
1195
|
+
describe('experimental icon add --variant --all', () => {
|
|
1196
|
+
beforeEach(() => {
|
|
1197
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
1198
|
+
const pkgJson = JSON.parse(
|
|
1199
|
+
fs.readFileSync(path.join(lib, 'package.json'), 'utf-8'),
|
|
1200
|
+
);
|
|
1201
|
+
fs.writeFileSync(
|
|
1202
|
+
path.join(lib, 'package.json'),
|
|
1203
|
+
JSON.stringify({
|
|
1204
|
+
...pkgJson,
|
|
1205
|
+
exports: {...pkgJson.exports, './solid': './solid.js'},
|
|
1206
|
+
}),
|
|
1207
|
+
);
|
|
1208
|
+
// The solid module exports the same names; it has no Cross.
|
|
1209
|
+
fs.writeFileSync(
|
|
1210
|
+
path.join(lib, 'solid.js'),
|
|
1211
|
+
'export function BinIcon(props) { return null; }\n',
|
|
1212
|
+
);
|
|
1213
|
+
});
|
|
1214
|
+
|
|
1215
|
+
it('adds the variant for every icon the module exports by the same id, in one run', async () => {
|
|
1216
|
+
expect(
|
|
1217
|
+
(
|
|
1218
|
+
await json([
|
|
1219
|
+
'experimental',
|
|
1220
|
+
'icon',
|
|
1221
|
+
'new-set',
|
|
1222
|
+
'glyphs',
|
|
1223
|
+
'--from',
|
|
1224
|
+
'@acme/glyph-library',
|
|
1225
|
+
'--variants',
|
|
1226
|
+
'outline,solid',
|
|
1227
|
+
])
|
|
1228
|
+
).code,
|
|
1229
|
+
).toBe(0);
|
|
1230
|
+
const {code, body} = await json([
|
|
1231
|
+
'experimental',
|
|
1232
|
+
'icon',
|
|
1233
|
+
'add',
|
|
1234
|
+
'--variant',
|
|
1235
|
+
'solid',
|
|
1236
|
+
'--from',
|
|
1237
|
+
'@acme/glyph-library/solid',
|
|
1238
|
+
'--all',
|
|
1239
|
+
]);
|
|
1240
|
+
expect(code).toBe(0);
|
|
1241
|
+
expect(body.type).toBe('icon.addVariants');
|
|
1242
|
+
expect(body.data).toMatchObject({added: 1, already: 0, missing: ['cross']});
|
|
1243
|
+
const bin = dataOf('glyphs').icons.find(
|
|
1244
|
+
(/** @type {{id: string}} */ each) => each.id === 'bin',
|
|
1245
|
+
);
|
|
1246
|
+
expect(bin.variants).toEqual([{variant: 'solid', export: 'BinSolidIcon'}]);
|
|
1247
|
+
const generated = fs.readFileSync(
|
|
1248
|
+
path.join(pkg, 'icon-sets', 'glyphs', 'glyphs.generated.js'),
|
|
1249
|
+
'utf-8',
|
|
1250
|
+
);
|
|
1251
|
+
expect(generated).toContain(
|
|
1252
|
+
"export {BinIcon as BinSolidIcon} from '@acme/glyph-library/solid';",
|
|
1253
|
+
);
|
|
1254
|
+
// Again: nothing changes.
|
|
1255
|
+
const again = await json([
|
|
1256
|
+
'experimental',
|
|
1257
|
+
'icon',
|
|
1258
|
+
'add',
|
|
1259
|
+
'--variant',
|
|
1260
|
+
'solid',
|
|
1261
|
+
'--from',
|
|
1262
|
+
'@acme/glyph-library/solid',
|
|
1263
|
+
'--all',
|
|
1264
|
+
]);
|
|
1265
|
+
expect(again.body.data).toMatchObject({
|
|
1266
|
+
added: 0,
|
|
1267
|
+
already: 1,
|
|
1268
|
+
changed: false,
|
|
1269
|
+
});
|
|
1270
|
+
});
|
|
1271
|
+
|
|
1272
|
+
it('refuses an undeclared variant, and an export name with --all', async () => {
|
|
1273
|
+
await json([
|
|
1274
|
+
'experimental',
|
|
1275
|
+
'icon',
|
|
1276
|
+
'new-set',
|
|
1277
|
+
'glyphs',
|
|
1278
|
+
'--from',
|
|
1279
|
+
'@acme/glyph-library',
|
|
1280
|
+
]);
|
|
1281
|
+
const undeclared = await json([
|
|
1282
|
+
'experimental',
|
|
1283
|
+
'icon',
|
|
1284
|
+
'add',
|
|
1285
|
+
'--variant',
|
|
1286
|
+
'solid',
|
|
1287
|
+
'--from',
|
|
1288
|
+
'@acme/glyph-library/solid',
|
|
1289
|
+
'--all',
|
|
1290
|
+
]);
|
|
1291
|
+
expect(undeclared.code).toBe(1);
|
|
1292
|
+
expect(undeclared.body.error).toContain('declares no variant "solid"');
|
|
1293
|
+
const named = await json([
|
|
1294
|
+
'experimental',
|
|
1295
|
+
'icon',
|
|
1296
|
+
'add',
|
|
1297
|
+
'BinIcon',
|
|
1298
|
+
'--variant',
|
|
1299
|
+
'solid',
|
|
1300
|
+
'--from',
|
|
1301
|
+
'@acme/glyph-library/solid',
|
|
1302
|
+
'--all',
|
|
1303
|
+
]);
|
|
1304
|
+
expect(named.code).toBe(1);
|
|
1305
|
+
expect(named.body.error).toBe(
|
|
1306
|
+
'--all and an export name cannot be used together',
|
|
1307
|
+
);
|
|
1308
|
+
expect(named.body.code).toBe('ERR_INVALID_OPTION');
|
|
1309
|
+
});
|
|
1310
|
+
});
|
|
1311
|
+
|
|
1312
|
+
describe('experimental icon map --pairs', () => {
|
|
1313
|
+
it('writes many entries in one write, all or none', async () => {
|
|
1314
|
+
await json([
|
|
1315
|
+
'experimental',
|
|
1316
|
+
'icon',
|
|
1317
|
+
'new-set',
|
|
1318
|
+
'outline',
|
|
1319
|
+
'--from',
|
|
1320
|
+
'@acme/glyph-library',
|
|
1321
|
+
]);
|
|
1322
|
+
const bad = await json([
|
|
1323
|
+
'experimental',
|
|
1324
|
+
'icon',
|
|
1325
|
+
'map',
|
|
1326
|
+
'--pairs',
|
|
1327
|
+
'close=cross,delete=nope',
|
|
1328
|
+
]);
|
|
1329
|
+
expect(bad.code).toBe(1);
|
|
1330
|
+
expect(bad.body.error).toContain('no icon "nope"');
|
|
1331
|
+
expect(dataOf('outline').map).toEqual({});
|
|
1332
|
+
const {code, body} = await json([
|
|
1333
|
+
'experimental',
|
|
1334
|
+
'icon',
|
|
1335
|
+
'map',
|
|
1336
|
+
'--pairs',
|
|
1337
|
+
'close=cross,delete=bin',
|
|
1338
|
+
]);
|
|
1339
|
+
expect(code).toBe(0);
|
|
1340
|
+
expect(body.type).toBe('icon.mapMany');
|
|
1341
|
+
expect(body.data.entries).toEqual([
|
|
1342
|
+
{definition: 'close', icon: 'cross', previous: null, changed: true},
|
|
1343
|
+
{definition: 'delete', icon: 'bin', previous: null, changed: true},
|
|
1344
|
+
]);
|
|
1345
|
+
expect(dataOf('outline').map).toEqual({close: 'cross', delete: 'bin'});
|
|
1346
|
+
// The theme map follows: close is built in.
|
|
1347
|
+
expect(
|
|
1348
|
+
fs.readFileSync(
|
|
1349
|
+
path.join(pkg, 'icon-sets', 'outline', 'outline.generated.js'),
|
|
1350
|
+
'utf-8',
|
|
1351
|
+
),
|
|
1352
|
+
).toContain('close: createElement(CrossIcon,');
|
|
1353
|
+
});
|
|
1354
|
+
});
|
|
1355
|
+
|
|
1356
|
+
describe('experimental icon new-set receipt', () => {
|
|
1357
|
+
it('takes --display-name and --description, and suggests icons by name words, never one map already names', async () => {
|
|
1358
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
1359
|
+
fs.writeFileSync(
|
|
1360
|
+
path.join(lib, 'icons', 'video.js'),
|
|
1361
|
+
'export const VideoCamera = props => null;\nexport const Camera = props => null;\nexport const Clipboard = props => null;\n',
|
|
1362
|
+
);
|
|
1363
|
+
fs.appendFileSync(
|
|
1364
|
+
path.join(lib, 'index.js'),
|
|
1365
|
+
"export {VideoCamera, Camera, Clipboard} from './icons/video.js';\n",
|
|
1366
|
+
);
|
|
1367
|
+
const {code, body} = await json([
|
|
1368
|
+
'experimental',
|
|
1369
|
+
'icon',
|
|
1370
|
+
'new-set',
|
|
1371
|
+
'outline',
|
|
1372
|
+
'--from',
|
|
1373
|
+
'@acme/glyph-library',
|
|
1374
|
+
'--display-name',
|
|
1375
|
+
'Acme Outline',
|
|
1376
|
+
'--description',
|
|
1377
|
+
'Outline icons from the Acme glyph library.',
|
|
1378
|
+
]);
|
|
1379
|
+
expect(code).toBe(0);
|
|
1380
|
+
const doc = fs.readFileSync(
|
|
1381
|
+
path.join(pkg, 'icon-sets', 'outline', 'outline.doc.mjs'),
|
|
1382
|
+
'utf-8',
|
|
1383
|
+
);
|
|
1384
|
+
expect(doc).toContain("displayName: 'Acme Outline'");
|
|
1385
|
+
expect(doc).toContain(
|
|
1386
|
+
"description: 'Outline icons from the Acme glyph library.'",
|
|
1387
|
+
);
|
|
1388
|
+
// `video` gets video-camera (its name's words) before camera (a word);
|
|
1389
|
+
// clipboard is mapped to the clipboard definition, so copy never gets it.
|
|
1390
|
+
const video = body.data.suggestions.filter(
|
|
1391
|
+
(/** @type {{definition: string}} */ each) => each.definition === 'video',
|
|
1392
|
+
);
|
|
1393
|
+
expect(
|
|
1394
|
+
video.map((/** @type {{icon: string}} */ each) => each.icon),
|
|
1395
|
+
).toEqual(['video-camera', 'camera']);
|
|
1396
|
+
expect(dataOf('outline').map).toMatchObject({clipboard: 'clipboard'});
|
|
1397
|
+
expect(
|
|
1398
|
+
body.data.suggestions.some(
|
|
1399
|
+
(/** @type {{icon: string}} */ each) => each.icon === 'clipboard',
|
|
1400
|
+
),
|
|
1401
|
+
).toBe(false);
|
|
1402
|
+
});
|
|
1403
|
+
});
|
|
1404
|
+
|
|
1405
|
+
describe('experimental icon new-set: aliases, providers, exclude, peers', () => {
|
|
1406
|
+
beforeEach(() => {
|
|
1407
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
1408
|
+
fs.writeFileSync(
|
|
1409
|
+
path.join(lib, 'icons', 'extra.js'),
|
|
1410
|
+
[
|
|
1411
|
+
'export const Trash = props => null;',
|
|
1412
|
+
'export const PanelLeftClose = props => null;',
|
|
1413
|
+
'export function GlyphProvider(props) { return props.children; }',
|
|
1414
|
+
'export const Meta = props => null;',
|
|
1415
|
+
'',
|
|
1416
|
+
].join('\n'),
|
|
1417
|
+
);
|
|
1418
|
+
fs.appendFileSync(
|
|
1419
|
+
path.join(lib, 'index.js'),
|
|
1420
|
+
"export {Trash, Trash as Trash2, PanelLeftClose, GlyphProvider, Meta} from './icons/extra.js';\n",
|
|
1421
|
+
);
|
|
1422
|
+
});
|
|
1423
|
+
|
|
1424
|
+
it('records other names as words, skips providers, keeps --exclude, and declares peers', async () => {
|
|
1425
|
+
fs.writeFileSync(
|
|
1426
|
+
path.join(pkg, 'package.json'),
|
|
1427
|
+
JSON.stringify({
|
|
1428
|
+
...JSON.parse(fs.readFileSync(path.join(pkg, 'package.json'), 'utf-8')),
|
|
1429
|
+
dependencies: {'@acme/glyph-library': '^2.0.0', react: '^19.0.0'},
|
|
1430
|
+
}),
|
|
1431
|
+
);
|
|
1432
|
+
const first = await json([
|
|
1433
|
+
'experimental',
|
|
1434
|
+
'icon',
|
|
1435
|
+
'new-set',
|
|
1436
|
+
'outline',
|
|
1437
|
+
'--from',
|
|
1438
|
+
'@acme/glyph-library',
|
|
1439
|
+
'--exclude',
|
|
1440
|
+
'Meta',
|
|
1441
|
+
]);
|
|
1442
|
+
expect(first.code).toBe(0);
|
|
1443
|
+
let data = dataOf('outline');
|
|
1444
|
+
const ids = data.icons.map((/** @type {{id: string}} */ each) => each.id);
|
|
1445
|
+
expect(ids).toContain('trash');
|
|
1446
|
+
expect(ids).not.toContain('trash-2');
|
|
1447
|
+
expect(ids).not.toContain('glyph-provider');
|
|
1448
|
+
expect(ids).not.toContain('meta');
|
|
1449
|
+
expect(data.exclude).toEqual(['Meta']);
|
|
1450
|
+
// The receipt names the exports it left out.
|
|
1451
|
+
expect(first.body.data.notes.join(' ')).toMatch(
|
|
1452
|
+
/Left out \d+ exports that are not icons: .*GlyphProvider/u,
|
|
1453
|
+
);
|
|
1454
|
+
expect(
|
|
1455
|
+
data.icons.find((/** @type {{id: string}} */ each) => each.id === 'trash')
|
|
1456
|
+
.words,
|
|
1457
|
+
).toContain('trash-2');
|
|
1458
|
+
// close is never suggested panel-left-close: a suggestion starts with
|
|
1459
|
+
// the definition's name.
|
|
1460
|
+
expect(
|
|
1461
|
+
first.body.data.suggestions.some(
|
|
1462
|
+
(/** @type {{definition: string, icon: string}} */ each) =>
|
|
1463
|
+
each.definition === 'close' && each.icon === 'panel-left-close',
|
|
1464
|
+
),
|
|
1465
|
+
).toBe(false);
|
|
1466
|
+
// Peers: the receipt names the exact JSON to add; package.json keeps its
|
|
1467
|
+
// dependencies as they were (architecture:cli-surface INV16).
|
|
1468
|
+
const manifest = JSON.parse(
|
|
1469
|
+
fs.readFileSync(path.join(pkg, 'package.json'), 'utf-8'),
|
|
1470
|
+
);
|
|
1471
|
+
expect(manifest).not.toHaveProperty('peerDependencies');
|
|
1472
|
+
expect(manifest.dependencies).toEqual({
|
|
1473
|
+
'@acme/glyph-library': '^2.0.0',
|
|
1474
|
+
react: '^19.0.0',
|
|
1475
|
+
});
|
|
1476
|
+
expect(first.body.data.notes).toContainEqual(
|
|
1477
|
+
expect.stringMatching(
|
|
1478
|
+
/^Declare the peers your set needs; add to package\.json "peerDependencies": `\{"react": ">=18", "@types\/react": ">=18", "@astryxdesign\/cli": ">=[^"]+"\}` and to "peerDependenciesMeta": `\{"@types\/react": \{"optional": true\}, "@astryxdesign\/cli": \{"optional": true\}\}`\.$/u,
|
|
1479
|
+
),
|
|
1480
|
+
);
|
|
1481
|
+
|
|
1482
|
+
// A refresh without --exclude still leaves Meta out, and says it refreshed.
|
|
1483
|
+
const again = await runCli(
|
|
1484
|
+
[
|
|
1485
|
+
'experimental',
|
|
1486
|
+
'icon',
|
|
1487
|
+
'new-set',
|
|
1488
|
+
'outline',
|
|
1489
|
+
'--from',
|
|
1490
|
+
'@acme/glyph-library',
|
|
1491
|
+
],
|
|
1492
|
+
pkg,
|
|
1493
|
+
);
|
|
1494
|
+
expect(again.code).toBe(0);
|
|
1495
|
+
expect(again.stdout).toContain('Icon set refreshed');
|
|
1496
|
+
expect(again.stdout).not.toContain('New icon set added');
|
|
1497
|
+
data = dataOf('outline');
|
|
1498
|
+
expect(
|
|
1499
|
+
data.icons.some((/** @type {{id: string}} */ each) => each.id === 'meta'),
|
|
1500
|
+
).toBe(false);
|
|
1501
|
+
|
|
1502
|
+
// map takes the kebab id of a definition and another name of an icon.
|
|
1503
|
+
const mapped = await json([
|
|
1504
|
+
'experimental',
|
|
1505
|
+
'icon',
|
|
1506
|
+
'map',
|
|
1507
|
+
'eye-slash',
|
|
1508
|
+
'cross',
|
|
1509
|
+
]);
|
|
1510
|
+
expect(mapped.code).toBe(0);
|
|
1511
|
+
expect(mapped.body.data).toMatchObject({
|
|
1512
|
+
definition: 'eyeSlash',
|
|
1513
|
+
icon: 'cross',
|
|
1514
|
+
});
|
|
1515
|
+
const alias = await json([
|
|
1516
|
+
'experimental',
|
|
1517
|
+
'icon',
|
|
1518
|
+
'map',
|
|
1519
|
+
'delete',
|
|
1520
|
+
'trash-2',
|
|
1521
|
+
]);
|
|
1522
|
+
expect(alias.code).toBe(0);
|
|
1523
|
+
expect(alias.body.data.icon).toBe('trash');
|
|
1524
|
+
// The same other name as the library exports it.
|
|
1525
|
+
const libraryName = await json([
|
|
1526
|
+
'experimental',
|
|
1527
|
+
'icon',
|
|
1528
|
+
'map',
|
|
1529
|
+
'delete',
|
|
1530
|
+
'Trash2',
|
|
1531
|
+
]);
|
|
1532
|
+
expect(libraryName.code, JSON.stringify(libraryName.body)).toBe(0);
|
|
1533
|
+
expect(libraryName.body.data.icon).toBe('trash');
|
|
1534
|
+
const pairs = await json([
|
|
1535
|
+
'experimental',
|
|
1536
|
+
'icon',
|
|
1537
|
+
'map',
|
|
1538
|
+
'--pairs',
|
|
1539
|
+
'more-horizontal=bin,delete=trash-2',
|
|
1540
|
+
]);
|
|
1541
|
+
expect(pairs.code).toBe(0);
|
|
1542
|
+
expect(dataOf('outline').map).toMatchObject({
|
|
1543
|
+
moreHorizontal: 'bin',
|
|
1544
|
+
delete: 'trash',
|
|
1545
|
+
});
|
|
1546
|
+
});
|
|
1547
|
+
});
|
|
1548
|
+
|
|
1549
|
+
describe('blind run 3 fixes', () => {
|
|
1550
|
+
it('refreshes a set whose icons have variants', async () => {
|
|
1551
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
1552
|
+
const pkgJson = JSON.parse(
|
|
1553
|
+
fs.readFileSync(path.join(lib, 'package.json'), 'utf-8'),
|
|
1554
|
+
);
|
|
1555
|
+
fs.writeFileSync(
|
|
1556
|
+
path.join(lib, 'package.json'),
|
|
1557
|
+
JSON.stringify({
|
|
1558
|
+
...pkgJson,
|
|
1559
|
+
exports: {...pkgJson.exports, './solid': './solid.js'},
|
|
1560
|
+
}),
|
|
1561
|
+
);
|
|
1562
|
+
fs.writeFileSync(
|
|
1563
|
+
path.join(lib, 'solid.js'),
|
|
1564
|
+
'export function BinIcon(props) { return null; }\n',
|
|
1565
|
+
);
|
|
1566
|
+
const create = [
|
|
1567
|
+
'experimental',
|
|
1568
|
+
'icon',
|
|
1569
|
+
'new-set',
|
|
1570
|
+
'glyphs',
|
|
1571
|
+
'--from',
|
|
1572
|
+
'@acme/glyph-library',
|
|
1573
|
+
'--variants',
|
|
1574
|
+
'outline,solid',
|
|
1575
|
+
];
|
|
1576
|
+
expect((await json(create)).code).toBe(0);
|
|
1577
|
+
expect(
|
|
1578
|
+
(
|
|
1579
|
+
await json([
|
|
1580
|
+
'experimental',
|
|
1581
|
+
'icon',
|
|
1582
|
+
'add',
|
|
1583
|
+
'--variant',
|
|
1584
|
+
'solid',
|
|
1585
|
+
'--from',
|
|
1586
|
+
'@acme/glyph-library/solid',
|
|
1587
|
+
'--all',
|
|
1588
|
+
])
|
|
1589
|
+
).code,
|
|
1590
|
+
).toBe(0);
|
|
1591
|
+
const again = await json(create);
|
|
1592
|
+
expect(again.code).toBe(0);
|
|
1593
|
+
expect(again.body.data.refreshed).toBe(true);
|
|
1594
|
+
const bin = dataOf('glyphs').icons.find(
|
|
1595
|
+
(/** @type {{id: string}} */ each) => each.id === 'bin',
|
|
1596
|
+
);
|
|
1597
|
+
expect(bin.variants).toEqual([{variant: 'solid', export: 'BinSolidIcon'}]);
|
|
1598
|
+
});
|
|
1599
|
+
|
|
1600
|
+
it('suggests the export with its Icon suffix, lists a set by id, and says what new-set did', async () => {
|
|
1601
|
+
const created = await runCli(
|
|
1602
|
+
[
|
|
1603
|
+
'experimental',
|
|
1604
|
+
'icon',
|
|
1605
|
+
'new-set',
|
|
1606
|
+
'outline',
|
|
1607
|
+
'--from',
|
|
1608
|
+
'@acme/glyph-library',
|
|
1609
|
+
],
|
|
1610
|
+
pkg,
|
|
1611
|
+
);
|
|
1612
|
+
expect(created.stdout).toContain(
|
|
1613
|
+
'Declared the experimental.iconSets root ./icon-sets in astryx.integration.mjs.',
|
|
1614
|
+
);
|
|
1615
|
+
expect(created.stdout).toContain(
|
|
1616
|
+
"Add `export * from './icon-sets/outline/outline.generated.js';` to index.js, so the icons import from @acme/icons.",
|
|
1617
|
+
);
|
|
1618
|
+
const missing = await json([
|
|
1619
|
+
'experimental',
|
|
1620
|
+
'icon',
|
|
1621
|
+
'add',
|
|
1622
|
+
'Rocket',
|
|
1623
|
+
'--from',
|
|
1624
|
+
'@acme/glyph-library',
|
|
1625
|
+
]);
|
|
1626
|
+
expect(missing.code).toBe(1);
|
|
1627
|
+
const bin = await json([
|
|
1628
|
+
'experimental',
|
|
1629
|
+
'icon',
|
|
1630
|
+
'add',
|
|
1631
|
+
'Bi',
|
|
1632
|
+
'--from',
|
|
1633
|
+
'@acme/glyph-library',
|
|
1634
|
+
]);
|
|
1635
|
+
expect(bin.code).toBe(1);
|
|
1636
|
+
fs.appendFileSync(
|
|
1637
|
+
path.join(pkg, 'node_modules', '@acme', 'glyph-library', 'index.js'),
|
|
1638
|
+
"export {Bin as XMarkIcon} from './icons/bin.js';\n",
|
|
1639
|
+
);
|
|
1640
|
+
const suffix = await json([
|
|
1641
|
+
'experimental',
|
|
1642
|
+
'icon',
|
|
1643
|
+
'add',
|
|
1644
|
+
'XMark',
|
|
1645
|
+
'--from',
|
|
1646
|
+
'@acme/glyph-library',
|
|
1647
|
+
]);
|
|
1648
|
+
expect(suffix.code).toBe(1);
|
|
1649
|
+
expect(suffix.body.suggestions[0]).toMatchObject({name: 'XMarkIcon'});
|
|
1650
|
+
const listed = await json([
|
|
1651
|
+
'experimental',
|
|
1652
|
+
'icon',
|
|
1653
|
+
'--set',
|
|
1654
|
+
'outline',
|
|
1655
|
+
'--all-icons',
|
|
1656
|
+
]);
|
|
1657
|
+
expect(listed.code).toBe(0);
|
|
1658
|
+
expect(listed.body.type).toBe('icon.setIcons');
|
|
1659
|
+
expect(
|
|
1660
|
+
listed.body.data.icons.map((/** @type {{id: string}} */ each) => each.id),
|
|
1661
|
+
).toEqual(['bin', 'cross']);
|
|
1662
|
+
const text = await runCli(
|
|
1663
|
+
['experimental', 'icon', '--set', 'outline', '--all-icons'],
|
|
1664
|
+
pkg,
|
|
1665
|
+
);
|
|
1666
|
+
expect(text.stdout).toContain('Icons in outline (2)');
|
|
1667
|
+
expect(text.stdout).toMatch(/^- bin: bin$/mu);
|
|
1668
|
+
});
|
|
1669
|
+
});
|
|
1670
|
+
|
|
1671
|
+
describe('blind run 4 fixes', () => {
|
|
1672
|
+
it('names a ./ file icon as written', async () => {
|
|
1673
|
+
await json(['experimental', 'icon', 'new-set', 'outline']);
|
|
1674
|
+
fs.mkdirSync(path.join(pkg, 'src', 'icons'), {recursive: true});
|
|
1675
|
+
fs.writeFileSync(
|
|
1676
|
+
path.join(pkg, 'src', 'icons', 'check-double.js'),
|
|
1677
|
+
'export const CheckDouble = props => null;\nexport const CheckDoubleSolid = props => null;\n',
|
|
1678
|
+
);
|
|
1679
|
+
const added = await json([
|
|
1680
|
+
'experimental',
|
|
1681
|
+
'icon',
|
|
1682
|
+
'add',
|
|
1683
|
+
'CheckDouble',
|
|
1684
|
+
'--from',
|
|
1685
|
+
'./src/icons/check-double.js',
|
|
1686
|
+
'--definition',
|
|
1687
|
+
'checkDouble',
|
|
1688
|
+
]);
|
|
1689
|
+
expect(added.code).toBe(0);
|
|
1690
|
+
expect(added.body.data.icon).toMatchObject({
|
|
1691
|
+
id: 'check-double',
|
|
1692
|
+
export: 'CheckDoubleIcon',
|
|
1693
|
+
});
|
|
1694
|
+
});
|
|
1695
|
+
|
|
1696
|
+
it('--definitions lists every definition, marking built-ins', async () => {
|
|
1697
|
+
const {code, body} = await json(['experimental', 'icon', '--definitions']);
|
|
1698
|
+
expect(code).toBe(0);
|
|
1699
|
+
expect(body.type).toBe('icon.definitions');
|
|
1700
|
+
const close = body.data.definitions.find(
|
|
1701
|
+
(/** @type {{name: string}} */ each) => each.name === 'close',
|
|
1702
|
+
);
|
|
1703
|
+
expect(close).toMatchObject({builtIn: true});
|
|
1704
|
+
expect(close.words).toContain('x');
|
|
1705
|
+
const text = await runCli(['experimental', 'icon', '--definitions'], pkg);
|
|
1706
|
+
expect(text.stdout).toMatch(/^- close \[built-in\]: /mu);
|
|
1707
|
+
});
|
|
1708
|
+
|
|
1709
|
+
it('suggests an icon by another name its library gives it, and new-set names the typecheck script and a description note', async () => {
|
|
1710
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
1711
|
+
fs.writeFileSync(
|
|
1712
|
+
path.join(lib, 'icons', 'face.js'),
|
|
1713
|
+
'export const FaceSlightlySmiling = props => null;\n',
|
|
1714
|
+
);
|
|
1715
|
+
fs.appendFileSync(
|
|
1716
|
+
path.join(lib, 'index.js'),
|
|
1717
|
+
"export {FaceSlightlySmiling, FaceSlightlySmiling as Smile} from './icons/face.js';\n",
|
|
1718
|
+
);
|
|
1719
|
+
const {code, body} = await json([
|
|
1720
|
+
'experimental',
|
|
1721
|
+
'icon',
|
|
1722
|
+
'new-set',
|
|
1723
|
+
'outline',
|
|
1724
|
+
'--from',
|
|
1725
|
+
'@acme/glyph-library',
|
|
1726
|
+
]);
|
|
1727
|
+
expect(code).toBe(0);
|
|
1728
|
+
expect(body.data.suggestions).toContainEqual({
|
|
1729
|
+
definition: 'emoji',
|
|
1730
|
+
icon: 'face-slightly-smiling',
|
|
1731
|
+
word: 'smile',
|
|
1732
|
+
});
|
|
1733
|
+
expect(body.data.notes.join(' ')).toContain('description is a placeholder');
|
|
1734
|
+
const manifest = JSON.parse(
|
|
1735
|
+
fs.readFileSync(path.join(pkg, 'package.json'), 'utf-8'),
|
|
1736
|
+
);
|
|
1737
|
+
// The script is the author's to add: the receipt names the exact line.
|
|
1738
|
+
expect(manifest).not.toHaveProperty('scripts');
|
|
1739
|
+
expect(body.data.notes).toContain(
|
|
1740
|
+
'Run `integration check --strict` in your build; add to package.json "scripts": `"typecheck": "astryx integration check --strict"`.',
|
|
1741
|
+
);
|
|
1742
|
+
});
|
|
1743
|
+
});
|
|
1744
|
+
|
|
1745
|
+
describe('blind run 5 fixes', () => {
|
|
1746
|
+
it('names the ./ source folder files needs, maps by export name, and suggests by spelling and stem', async () => {
|
|
1747
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
1748
|
+
fs.writeFileSync(
|
|
1749
|
+
path.join(lib, 'icons', 'more.js'),
|
|
1750
|
+
[
|
|
1751
|
+
'export const LightBulb = props => null;',
|
|
1752
|
+
'export const TrendingUp = props => null;',
|
|
1753
|
+
'export const LockOpen = props => null;',
|
|
1754
|
+
'',
|
|
1755
|
+
].join('\n'),
|
|
1756
|
+
);
|
|
1757
|
+
fs.appendFileSync(
|
|
1758
|
+
path.join(lib, 'index.js'),
|
|
1759
|
+
"export {LightBulb, TrendingUp, LockOpen, LockOpen as Unlock} from './icons/more.js';\n",
|
|
1760
|
+
);
|
|
1761
|
+
fs.writeFileSync(
|
|
1762
|
+
path.join(pkg, 'package.json'),
|
|
1763
|
+
JSON.stringify({
|
|
1764
|
+
...JSON.parse(fs.readFileSync(path.join(pkg, 'package.json'), 'utf-8')),
|
|
1765
|
+
files: ['index.js', 'icon-sets', 'astryx.integration.mjs'],
|
|
1766
|
+
}),
|
|
1767
|
+
);
|
|
1768
|
+
const {body} = await json([
|
|
1769
|
+
'experimental',
|
|
1770
|
+
'icon',
|
|
1771
|
+
'new-set',
|
|
1772
|
+
'outline',
|
|
1773
|
+
'--from',
|
|
1774
|
+
'@acme/glyph-library',
|
|
1775
|
+
]);
|
|
1776
|
+
const pairs = body.data.suggestions.map(
|
|
1777
|
+
(/** @type {{definition: string, icon: string}} */ each) =>
|
|
1778
|
+
`${each.definition}>${each.icon}`,
|
|
1779
|
+
);
|
|
1780
|
+
expect(pairs).toContain('lightbulb>light-bulb');
|
|
1781
|
+
expect(pairs).toContain('trendUp>trending-up');
|
|
1782
|
+
expect(pairs).toContain('unlock>lock-open');
|
|
1783
|
+
// map takes the export name, in any case.
|
|
1784
|
+
const byExport = await json([
|
|
1785
|
+
'experimental',
|
|
1786
|
+
'icon',
|
|
1787
|
+
'map',
|
|
1788
|
+
'close',
|
|
1789
|
+
'CrossIcon',
|
|
1790
|
+
]);
|
|
1791
|
+
expect(byExport.body.data).toMatchObject({
|
|
1792
|
+
definition: 'close',
|
|
1793
|
+
icon: 'cross',
|
|
1794
|
+
});
|
|
1795
|
+
// A ./ file's folder is named for files, so the icon ships; files stays
|
|
1796
|
+
// the author's (architecture:cli-surface INV16).
|
|
1797
|
+
fs.mkdirSync(path.join(pkg, 'art'), {recursive: true});
|
|
1798
|
+
fs.writeFileSync(
|
|
1799
|
+
path.join(pkg, 'art', 'check-double.js'),
|
|
1800
|
+
'export const CheckDouble = props => null;\n',
|
|
1801
|
+
);
|
|
1802
|
+
const added = await json([
|
|
1803
|
+
'experimental',
|
|
1804
|
+
'icon',
|
|
1805
|
+
'add',
|
|
1806
|
+
'CheckDouble',
|
|
1807
|
+
'--from',
|
|
1808
|
+
'./art/check-double.js',
|
|
1809
|
+
'--definition',
|
|
1810
|
+
'checkDouble',
|
|
1811
|
+
]);
|
|
1812
|
+
expect(added.code).toBe(0);
|
|
1813
|
+
expect(added.body.data.files).not.toContain('package.json');
|
|
1814
|
+
expect(
|
|
1815
|
+
JSON.parse(fs.readFileSync(path.join(pkg, 'package.json'), 'utf-8'))
|
|
1816
|
+
.files,
|
|
1817
|
+
).toEqual(['index.js', 'icon-sets', 'astryx.integration.mjs']);
|
|
1818
|
+
expect(added.body.data.note).toContain(
|
|
1819
|
+
'./art/check-double.js is not in package.json "files", so it would not be published; set "files" to `["index.js","icon-sets","astryx.integration.mjs","art"]`.',
|
|
1820
|
+
);
|
|
1821
|
+
const text = await runCli(['experimental', 'icon', '--definitions'], pkg);
|
|
1822
|
+
expect(text.stdout).toMatch(/^- activity \[optional\]: /mu);
|
|
1823
|
+
});
|
|
1824
|
+
});
|
|
1825
|
+
|
|
1826
|
+
describe('blind run 6 fixes', () => {
|
|
1827
|
+
it('never suggests the opposite direction, and names only a ./ file folder for files', async () => {
|
|
1828
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
1829
|
+
fs.writeFileSync(
|
|
1830
|
+
path.join(lib, 'icons', 'dots.js'),
|
|
1831
|
+
'export const EllipsisHorizontal = props => null;\nexport const EllipsisVertical = props => null;\n',
|
|
1832
|
+
);
|
|
1833
|
+
fs.appendFileSync(
|
|
1834
|
+
path.join(lib, 'index.js'),
|
|
1835
|
+
"export {EllipsisHorizontal, EllipsisVertical} from './icons/dots.js';\n",
|
|
1836
|
+
);
|
|
1837
|
+
const {body} = await json([
|
|
1838
|
+
'experimental',
|
|
1839
|
+
'icon',
|
|
1840
|
+
'new-set',
|
|
1841
|
+
'outline',
|
|
1842
|
+
'--from',
|
|
1843
|
+
'@acme/glyph-library',
|
|
1844
|
+
]);
|
|
1845
|
+
const more = body.data.suggestions
|
|
1846
|
+
.filter(
|
|
1847
|
+
(/** @type {{definition: string}} */ each) =>
|
|
1848
|
+
each.definition === 'moreHorizontal',
|
|
1849
|
+
)
|
|
1850
|
+
.map((/** @type {{icon: string}} */ each) => each.icon);
|
|
1851
|
+
expect(more).toEqual(['ellipsis-horizontal']);
|
|
1852
|
+
const manifestFile = path.join(pkg, 'package.json');
|
|
1853
|
+
fs.writeFileSync(
|
|
1854
|
+
manifestFile,
|
|
1855
|
+
JSON.stringify({
|
|
1856
|
+
...JSON.parse(fs.readFileSync(manifestFile, 'utf-8')),
|
|
1857
|
+
files: ['index.js', 'icon-sets'],
|
|
1858
|
+
}),
|
|
1859
|
+
);
|
|
1860
|
+
fs.mkdirSync(path.join(pkg, 'src', 'icons'), {recursive: true});
|
|
1861
|
+
fs.writeFileSync(
|
|
1862
|
+
path.join(pkg, 'src', 'icons', 'check-double.js'),
|
|
1863
|
+
'export const CheckDouble = props => null;\n',
|
|
1864
|
+
);
|
|
1865
|
+
const added = await json([
|
|
1866
|
+
'experimental',
|
|
1867
|
+
'icon',
|
|
1868
|
+
'add',
|
|
1869
|
+
'CheckDouble',
|
|
1870
|
+
'--from',
|
|
1871
|
+
'./src/icons/check-double.js',
|
|
1872
|
+
'--definition',
|
|
1873
|
+
'checkDouble',
|
|
1874
|
+
]);
|
|
1875
|
+
expect(added.body.data.note).toContain(
|
|
1876
|
+
'set "files" to `["index.js","icon-sets","src/icons"]`.',
|
|
1877
|
+
);
|
|
1878
|
+
});
|
|
1879
|
+
});
|
|
1880
|
+
|
|
1881
|
+
describe('blind run 7 fixes', () => {
|
|
1882
|
+
it('a refresh rewrites the description, lists only files it changes, and words leave out bare numbers', async () => {
|
|
1883
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
1884
|
+
fs.writeFileSync(
|
|
1885
|
+
path.join(lib, 'icons', 'volume.js'),
|
|
1886
|
+
'export const Volume2 = props => null;\n',
|
|
1887
|
+
);
|
|
1888
|
+
fs.appendFileSync(
|
|
1889
|
+
path.join(lib, 'index.js'),
|
|
1890
|
+
"export {Volume2} from './icons/volume.js';\n",
|
|
1891
|
+
);
|
|
1892
|
+
const args = [
|
|
1893
|
+
'experimental',
|
|
1894
|
+
'icon',
|
|
1895
|
+
'new-set',
|
|
1896
|
+
'outline',
|
|
1897
|
+
'--from',
|
|
1898
|
+
'@acme/glyph-library',
|
|
1899
|
+
];
|
|
1900
|
+
await json(args);
|
|
1901
|
+
const volume = dataOf('outline').icons.find(
|
|
1902
|
+
(/** @type {{id: string}} */ each) => each.id === 'volume-2',
|
|
1903
|
+
);
|
|
1904
|
+
expect(volume.words).toEqual(['volume']);
|
|
1905
|
+
const dry = await json([...args, '--dry-run']);
|
|
1906
|
+
expect(dry.body.data.files).toEqual([]);
|
|
1907
|
+
const described = await json([
|
|
1908
|
+
...args,
|
|
1909
|
+
'--description',
|
|
1910
|
+
"Acme's outline icons.",
|
|
1911
|
+
]);
|
|
1912
|
+
expect(described.body.data.files).toEqual([
|
|
1913
|
+
'icon-sets/outline/outline.doc.mjs',
|
|
1914
|
+
]);
|
|
1915
|
+
expect(
|
|
1916
|
+
fs.readFileSync(
|
|
1917
|
+
path.join(pkg, 'icon-sets', 'outline', 'outline.doc.mjs'),
|
|
1918
|
+
'utf-8',
|
|
1919
|
+
),
|
|
1920
|
+
).toContain("description: 'Acme\\'s outline icons.',");
|
|
1921
|
+
});
|
|
1922
|
+
});
|
|
1923
|
+
|
|
1924
|
+
describe('blind run 8 fixes', () => {
|
|
1925
|
+
it('a refresh lists every exact-name entry for review again', async () => {
|
|
1926
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
1927
|
+
fs.writeFileSync(
|
|
1928
|
+
path.join(lib, 'icons', 'close.js'),
|
|
1929
|
+
'export const Close = props => null;\n',
|
|
1930
|
+
);
|
|
1931
|
+
fs.appendFileSync(
|
|
1932
|
+
path.join(lib, 'index.js'),
|
|
1933
|
+
"export {Close} from './icons/close.js';\n",
|
|
1934
|
+
);
|
|
1935
|
+
const args = [
|
|
1936
|
+
'experimental',
|
|
1937
|
+
'icon',
|
|
1938
|
+
'new-set',
|
|
1939
|
+
'outline',
|
|
1940
|
+
'--from',
|
|
1941
|
+
'@acme/glyph-library',
|
|
1942
|
+
];
|
|
1943
|
+
expect((await json(args)).body.data.mapped).toEqual([
|
|
1944
|
+
{definition: 'close', icon: 'close'},
|
|
1945
|
+
]);
|
|
1946
|
+
const again = await json([...args, '--dry-run']);
|
|
1947
|
+
expect(again.body.data.mapped).toEqual([
|
|
1948
|
+
{definition: 'close', icon: 'close'},
|
|
1949
|
+
]);
|
|
1950
|
+
});
|
|
1951
|
+
});
|
|
1952
|
+
|
|
1953
|
+
describe('package wiring stays the author’s', () => {
|
|
1954
|
+
/**
|
|
1955
|
+
* Every issue the check reports, by code and message.
|
|
1956
|
+
* @returns {Promise<Array<{code: string, message: string}>>}
|
|
1957
|
+
*/
|
|
1958
|
+
async function checkIssues() {
|
|
1959
|
+
const body = JSON.parse(
|
|
1960
|
+
(await runCli(['integration', 'check', '--json'], pkg)).stdout,
|
|
1961
|
+
);
|
|
1962
|
+
/** @type {Array<{code: string, message: string}>} */
|
|
1963
|
+
const found = [];
|
|
1964
|
+
/** @param {unknown} node */
|
|
1965
|
+
const walk = node => {
|
|
1966
|
+
if (Array.isArray(node)) node.forEach(walk);
|
|
1967
|
+
else if (node && typeof node === 'object') {
|
|
1968
|
+
const each = /** @type {Record<string, unknown>} */ (node);
|
|
1969
|
+
if (typeof each.code === 'string' && typeof each.message === 'string') {
|
|
1970
|
+
found.push({code: each.code, message: each.message});
|
|
1971
|
+
}
|
|
1972
|
+
Object.values(each).forEach(walk);
|
|
1973
|
+
}
|
|
1974
|
+
};
|
|
1975
|
+
walk(body.data);
|
|
1976
|
+
return found;
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
it('integration check names the same entry change as the new-set receipt, once, until the author makes it', async () => {
|
|
1980
|
+
const {body} = await json([
|
|
1981
|
+
'experimental',
|
|
1982
|
+
'icon',
|
|
1983
|
+
'new-set',
|
|
1984
|
+
'outline',
|
|
1985
|
+
'--from',
|
|
1986
|
+
'@acme/glyph-library',
|
|
1987
|
+
]);
|
|
1988
|
+
const note =
|
|
1989
|
+
"Add `export * from './icon-sets/outline/outline.generated.js';` to index.js, so the icons import from @acme/icons.";
|
|
1990
|
+
expect(body.data.notes).toContain(note);
|
|
1991
|
+
const missing = (await checkIssues()).filter(
|
|
1992
|
+
each => each.code === 'icon_export_missing',
|
|
1993
|
+
);
|
|
1994
|
+
expect([...new Set(missing.map(each => each.message))]).toEqual([
|
|
1995
|
+
`Icon set "outline": its icons are not exported from "@acme/icons" yet. ${note}`,
|
|
1996
|
+
]);
|
|
1997
|
+
// The author adds the line; the finding is gone.
|
|
1998
|
+
fs.appendFileSync(
|
|
1999
|
+
path.join(pkg, 'index.js'),
|
|
2000
|
+
"export * from './icon-sets/outline/outline.generated.js';\n",
|
|
2001
|
+
);
|
|
2002
|
+
expect(
|
|
2003
|
+
(await checkIssues()).filter(each => each.code === 'icon_export_missing'),
|
|
2004
|
+
).toEqual([]);
|
|
2005
|
+
});
|
|
2006
|
+
|
|
2007
|
+
it('integration check never fails a built or CommonJS entry over the wiring it cannot read', async () => {
|
|
2008
|
+
fs.writeFileSync(
|
|
2009
|
+
path.join(pkg, 'package.json'),
|
|
2010
|
+
JSON.stringify({
|
|
2011
|
+
...JSON.parse(fs.readFileSync(path.join(pkg, 'package.json'), 'utf-8')),
|
|
2012
|
+
exports: {'.': './dist/index.cjs'},
|
|
2013
|
+
}),
|
|
2014
|
+
);
|
|
2015
|
+
fs.mkdirSync(path.join(pkg, 'dist'));
|
|
2016
|
+
fs.writeFileSync(
|
|
2017
|
+
path.join(pkg, 'dist', 'index.cjs'),
|
|
2018
|
+
'module.exports = {};\n',
|
|
2019
|
+
);
|
|
2020
|
+
await json([
|
|
2021
|
+
'experimental',
|
|
2022
|
+
'icon',
|
|
2023
|
+
'new-set',
|
|
2024
|
+
'outline',
|
|
2025
|
+
'--from',
|
|
2026
|
+
'@acme/glyph-library',
|
|
2027
|
+
]);
|
|
2028
|
+
expect(fs.readFileSync(path.join(pkg, 'dist', 'index.cjs'), 'utf-8')).toBe(
|
|
2029
|
+
'module.exports = {};\n',
|
|
2030
|
+
);
|
|
2031
|
+
expect(
|
|
2032
|
+
(await checkIssues()).filter(each =>
|
|
2033
|
+
each.message.includes('are not exported from'),
|
|
2034
|
+
),
|
|
2035
|
+
).toEqual([]);
|
|
2036
|
+
});
|
|
2037
|
+
});
|
|
2038
|
+
|
|
2039
|
+
describe('a refresh that first records the source', () => {
|
|
2040
|
+
it('copies the library notices and takes its license, as new-set --from does', async () => {
|
|
2041
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
2042
|
+
fs.writeFileSync(path.join(lib, 'LICENSE'), 'ISC License\n');
|
|
2043
|
+
fs.writeFileSync(
|
|
2044
|
+
path.join(lib, 'package.json'),
|
|
2045
|
+
JSON.stringify({
|
|
2046
|
+
...JSON.parse(fs.readFileSync(path.join(lib, 'package.json'), 'utf-8')),
|
|
2047
|
+
license: 'ISC',
|
|
2048
|
+
}),
|
|
2049
|
+
);
|
|
2050
|
+
expect(
|
|
2051
|
+
(await json(['experimental', 'icon', 'new-set', 'glyphs'])).code,
|
|
2052
|
+
).toBe(0);
|
|
2053
|
+
const doc = path.join(pkg, 'icon-sets', 'glyphs', 'glyphs.doc.mjs');
|
|
2054
|
+
expect(fs.readFileSync(doc, 'utf-8')).toContain("license: 'MIT'");
|
|
2055
|
+
const pkgBefore = fs.readFileSync(path.join(pkg, 'package.json'), 'utf-8');
|
|
2056
|
+
|
|
2057
|
+
const refreshed = await json([
|
|
2058
|
+
'experimental',
|
|
2059
|
+
'icon',
|
|
2060
|
+
'new-set',
|
|
2061
|
+
'glyphs',
|
|
2062
|
+
'--from',
|
|
2063
|
+
'@acme/glyph-library',
|
|
2064
|
+
]);
|
|
2065
|
+
expect(refreshed.code).toBe(0);
|
|
2066
|
+
expect(refreshed.body.data.refreshed).toBe(true);
|
|
2067
|
+
expect(refreshed.body.data.files).toEqual(
|
|
2068
|
+
expect.arrayContaining([
|
|
2069
|
+
'icon-sets/glyphs/glyphs.doc.mjs',
|
|
2070
|
+
'icon-sets/glyphs/LICENSE',
|
|
2071
|
+
]),
|
|
2072
|
+
);
|
|
2073
|
+
expect(dataOf('glyphs').source).toEqual({
|
|
2074
|
+
package: '@acme/glyph-library',
|
|
2075
|
+
version: '2.0.0',
|
|
2076
|
+
});
|
|
2077
|
+
expect(
|
|
2078
|
+
fs.readFileSync(
|
|
2079
|
+
path.join(pkg, 'icon-sets', 'glyphs', 'LICENSE'),
|
|
2080
|
+
'utf-8',
|
|
2081
|
+
),
|
|
2082
|
+
).toBe('ISC License\n');
|
|
2083
|
+
expect(fs.readFileSync(doc, 'utf-8')).toContain("license: 'ISC'");
|
|
2084
|
+
expect(refreshed.body.data.notes).toContain(
|
|
2085
|
+
'The set\'s license in icon-sets/glyphs/glyphs.doc.mjs changed from "MIT" to "ISC", the license of @acme/glyph-library, whose artwork it now wraps. Edit it if the artwork\'s license differs.',
|
|
2086
|
+
);
|
|
2087
|
+
// The package's own license is the author's (INV16).
|
|
2088
|
+
expect(fs.readFileSync(path.join(pkg, 'package.json'), 'utf-8')).toBe(
|
|
2089
|
+
pkgBefore,
|
|
2090
|
+
);
|
|
2091
|
+
const strict = await runCli(
|
|
2092
|
+
['integration', 'check', '--strict', '--json'],
|
|
2093
|
+
pkg,
|
|
2094
|
+
);
|
|
2095
|
+
expect(strict.stdout).not.toContain('icon_license_notice_missing');
|
|
2096
|
+
|
|
2097
|
+
// A later refresh keeps the author's license.
|
|
2098
|
+
fs.writeFileSync(
|
|
2099
|
+
doc,
|
|
2100
|
+
fs
|
|
2101
|
+
.readFileSync(doc, 'utf-8')
|
|
2102
|
+
.replace("license: 'ISC'", "license: 'ISC AND CC-BY-4.0'"),
|
|
2103
|
+
);
|
|
2104
|
+
await json([
|
|
2105
|
+
'experimental',
|
|
2106
|
+
'icon',
|
|
2107
|
+
'new-set',
|
|
2108
|
+
'glyphs',
|
|
2109
|
+
'--from',
|
|
2110
|
+
'@acme/glyph-library',
|
|
2111
|
+
]);
|
|
2112
|
+
expect(fs.readFileSync(doc, 'utf-8')).toContain(
|
|
2113
|
+
"license: 'ISC AND CC-BY-4.0'",
|
|
2114
|
+
);
|
|
2115
|
+
});
|
|
2116
|
+
});
|
|
2117
|
+
|
|
2118
|
+
describe('a first-source refresh over a license the author chose', () => {
|
|
2119
|
+
it('keeps it, and the receipt names both licenses', async () => {
|
|
2120
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
2121
|
+
fs.writeFileSync(
|
|
2122
|
+
path.join(lib, 'package.json'),
|
|
2123
|
+
JSON.stringify({
|
|
2124
|
+
...JSON.parse(fs.readFileSync(path.join(lib, 'package.json'), 'utf-8')),
|
|
2125
|
+
license: 'ISC',
|
|
2126
|
+
}),
|
|
2127
|
+
);
|
|
2128
|
+
await json(['experimental', 'icon', 'new-set', 'glyphs']);
|
|
2129
|
+
const doc = path.join(pkg, 'icon-sets', 'glyphs', 'glyphs.doc.mjs');
|
|
2130
|
+
fs.writeFileSync(
|
|
2131
|
+
doc,
|
|
2132
|
+
fs
|
|
2133
|
+
.readFileSync(doc, 'utf-8')
|
|
2134
|
+
.replace("license: 'MIT'", "license: 'CC-BY-4.0'"),
|
|
2135
|
+
);
|
|
2136
|
+
const refreshed = await json([
|
|
2137
|
+
'experimental',
|
|
2138
|
+
'icon',
|
|
2139
|
+
'new-set',
|
|
2140
|
+
'glyphs',
|
|
2141
|
+
'--from',
|
|
2142
|
+
'@acme/glyph-library',
|
|
2143
|
+
]);
|
|
2144
|
+
expect(refreshed.code).toBe(0);
|
|
2145
|
+
expect(fs.readFileSync(doc, 'utf-8')).toContain("license: 'CC-BY-4.0'");
|
|
2146
|
+
expect(refreshed.body.data.notes).toContain(
|
|
2147
|
+
'The set\'s license in icon-sets/glyphs/glyphs.doc.mjs stays "CC-BY-4.0", which you set; @acme/glyph-library is licensed "ISC". Change it if the artwork is the library\'s.',
|
|
2148
|
+
);
|
|
2149
|
+
});
|
|
2150
|
+
});
|
|
2151
|
+
|
|
2152
|
+
describe('map names an icon only by its id, export name, or another library name', () => {
|
|
2153
|
+
beforeEach(() => {
|
|
2154
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
2155
|
+
fs.writeFileSync(
|
|
2156
|
+
path.join(lib, 'icons', 'glass.js'),
|
|
2157
|
+
'export const MagnifyingGlass = props => null;\n',
|
|
2158
|
+
);
|
|
2159
|
+
fs.appendFileSync(
|
|
2160
|
+
path.join(lib, 'index.js'),
|
|
2161
|
+
"export {MagnifyingGlass, MagnifyingGlass as Search} from './icons/glass.js';\n",
|
|
2162
|
+
);
|
|
2163
|
+
});
|
|
2164
|
+
|
|
2165
|
+
it('refuses a word an icon carries, with the icons that carry it, and writes nothing', async () => {
|
|
2166
|
+
await json([
|
|
2167
|
+
'experimental',
|
|
2168
|
+
'icon',
|
|
2169
|
+
'new-set',
|
|
2170
|
+
'outline',
|
|
2171
|
+
'--from',
|
|
2172
|
+
'@acme/glyph-library',
|
|
2173
|
+
]);
|
|
2174
|
+
const dataFile = path.join(
|
|
2175
|
+
pkg,
|
|
2176
|
+
'icon-sets',
|
|
2177
|
+
'outline',
|
|
2178
|
+
'outline.icons.json',
|
|
2179
|
+
);
|
|
2180
|
+
const before = fs.readFileSync(dataFile, 'utf-8');
|
|
2181
|
+
|
|
2182
|
+
const word = await json([
|
|
2183
|
+
'experimental',
|
|
2184
|
+
'icon',
|
|
2185
|
+
'map',
|
|
2186
|
+
'moreHorizontal',
|
|
2187
|
+
'glass',
|
|
2188
|
+
]);
|
|
2189
|
+
expect(word.code).toBe(1);
|
|
2190
|
+
expect(word.body.error).toContain('has no icon "glass"');
|
|
2191
|
+
expect(word.body.error).toContain('a word it carries is not its name');
|
|
2192
|
+
expect(
|
|
2193
|
+
word.body.suggestions.map(
|
|
2194
|
+
(/** @type {{name: string}} */ each) => each.name,
|
|
2195
|
+
),
|
|
2196
|
+
).toContain('magnifying-glass');
|
|
2197
|
+
|
|
2198
|
+
const pairs = await json([
|
|
2199
|
+
'experimental',
|
|
2200
|
+
'icon',
|
|
2201
|
+
'map',
|
|
2202
|
+
'--pairs',
|
|
2203
|
+
'close=cross,moreHorizontal=glass',
|
|
2204
|
+
]);
|
|
2205
|
+
expect(pairs.code).toBe(1);
|
|
2206
|
+
expect(pairs.body.error).toContain('Nothing was written');
|
|
2207
|
+
expect(fs.readFileSync(dataFile, 'utf-8')).toBe(before);
|
|
2208
|
+
|
|
2209
|
+
// The id, the export name in any case, and another library name map.
|
|
2210
|
+
for (const [given, id] of [
|
|
2211
|
+
['magnifying-glass', 'magnifying-glass'],
|
|
2212
|
+
['magnifyingglassicon', 'magnifying-glass'],
|
|
2213
|
+
['MagnifyingGlass', 'magnifying-glass'],
|
|
2214
|
+
['search', 'magnifying-glass'],
|
|
2215
|
+
['Search', 'magnifying-glass'],
|
|
2216
|
+
]) {
|
|
2217
|
+
const ok = await json(['experimental', 'icon', 'map', 'search', given]);
|
|
2218
|
+
expect(ok.code, given).toBe(0);
|
|
2219
|
+
expect(ok.body.data.icon, given).toBe(id);
|
|
2220
|
+
}
|
|
2221
|
+
});
|
|
2222
|
+
});
|
|
2223
|
+
|
|
2224
|
+
describe('a refresh after the id rule changes', () => {
|
|
2225
|
+
it('carries a renamed icon’s map entries, variants, and words, matched by its export, and reports the rename', async () => {
|
|
2226
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
2227
|
+
fs.writeFileSync(
|
|
2228
|
+
path.join(lib, 'icons', 'squares.js'),
|
|
2229
|
+
'export const Squares2X2Icon = props => null;\n',
|
|
2230
|
+
);
|
|
2231
|
+
fs.appendFileSync(
|
|
2232
|
+
path.join(lib, 'index.js'),
|
|
2233
|
+
"export {Squares2X2Icon} from './icons/squares.js';\n",
|
|
2234
|
+
);
|
|
2235
|
+
const args = [
|
|
2236
|
+
'experimental',
|
|
2237
|
+
'icon',
|
|
2238
|
+
'new-set',
|
|
2239
|
+
'outline',
|
|
2240
|
+
'--from',
|
|
2241
|
+
'@acme/glyph-library',
|
|
2242
|
+
'--variants',
|
|
2243
|
+
'outline,solid',
|
|
2244
|
+
];
|
|
2245
|
+
expect((await json(args)).code).toBe(0);
|
|
2246
|
+
// Rewrite the data file as the old id rule wrote it: `squares-2-x2`,
|
|
2247
|
+
// with that rule's words, a word the author added, a variant, and a map
|
|
2248
|
+
// entry.
|
|
2249
|
+
const dataFile = path.join(
|
|
2250
|
+
pkg,
|
|
2251
|
+
'icon-sets',
|
|
2252
|
+
'outline',
|
|
2253
|
+
'outline.icons.json',
|
|
2254
|
+
);
|
|
2255
|
+
const data = dataOf('outline');
|
|
2256
|
+
const icon = data.icons.find(
|
|
2257
|
+
(/** @type {{export: string}} */ each) =>
|
|
2258
|
+
each.export === 'Squares2X2Icon',
|
|
2259
|
+
);
|
|
2260
|
+
Object.assign(icon, {
|
|
2261
|
+
id: 'squares-2-x2',
|
|
2262
|
+
words: ['squares', 'x2', 'tiles'],
|
|
2263
|
+
variants: [{variant: 'solid', export: 'Squares2X2SolidIcon'}],
|
|
2264
|
+
});
|
|
2265
|
+
data.map = {...data.map, moreHorizontal: 'squares-2-x2'};
|
|
2266
|
+
fs.writeFileSync(dataFile, `${JSON.stringify(data, null, 2)}\n`);
|
|
2267
|
+
|
|
2268
|
+
const refreshed = await json(args);
|
|
2269
|
+
expect(refreshed.code).toBe(0);
|
|
2270
|
+
expect(refreshed.body.data.renamed).toEqual([
|
|
2271
|
+
{from: 'squares-2-x2', to: 'squares-2x2'},
|
|
2272
|
+
]);
|
|
2273
|
+
const notes = refreshed.body.data.notes.join(' ');
|
|
2274
|
+
expect(notes).toContain('squares-2-x2 -> squares-2x2');
|
|
2275
|
+
expect(notes).not.toContain('no longer exports');
|
|
2276
|
+
const after = dataOf('outline');
|
|
2277
|
+
expect(after.map.moreHorizontal).toBe('squares-2x2');
|
|
2278
|
+
const renamed = after.icons.find(
|
|
2279
|
+
(/** @type {{export: string}} */ each) =>
|
|
2280
|
+
each.export === 'Squares2X2Icon',
|
|
2281
|
+
);
|
|
2282
|
+
expect(renamed).toMatchObject({
|
|
2283
|
+
id: 'squares-2x2',
|
|
2284
|
+
variants: [{variant: 'solid', export: 'Squares2X2SolidIcon'}],
|
|
2285
|
+
});
|
|
2286
|
+
expect(renamed.words).toContain('tiles');
|
|
2287
|
+
expect(renamed.words).not.toContain('x2');
|
|
2288
|
+
expect(
|
|
2289
|
+
after.icons.some(
|
|
2290
|
+
(/** @type {{id: string}} */ each) => each.id === 'squares-2-x2',
|
|
2291
|
+
),
|
|
2292
|
+
).toBe(false);
|
|
2293
|
+
// The export stays in the generated module.
|
|
2294
|
+
expect(
|
|
2295
|
+
fs.readFileSync(
|
|
2296
|
+
path.join(pkg, 'icon-sets', 'outline', 'outline.generated.js'),
|
|
2297
|
+
'utf-8',
|
|
2298
|
+
),
|
|
2299
|
+
).toContain('Squares2X2Icon');
|
|
2300
|
+
});
|
|
2301
|
+
});
|
|
2302
|
+
|
|
2303
|
+
describe('add --variant --all after the id rule changes', () => {
|
|
2304
|
+
it('meets an icon whose id an older rule wrote by its export name', async () => {
|
|
2305
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
2306
|
+
fs.writeFileSync(
|
|
2307
|
+
path.join(lib, 'package.json'),
|
|
2308
|
+
JSON.stringify({
|
|
2309
|
+
...JSON.parse(fs.readFileSync(path.join(lib, 'package.json'), 'utf-8')),
|
|
2310
|
+
exports: {'.': './index.js', './solid': './solid.js'},
|
|
2311
|
+
}),
|
|
2312
|
+
);
|
|
2313
|
+
fs.writeFileSync(
|
|
2314
|
+
path.join(lib, 'icons', 'squares.js'),
|
|
2315
|
+
'export const Squares2X2Icon = props => null;\n',
|
|
2316
|
+
);
|
|
2317
|
+
fs.appendFileSync(
|
|
2318
|
+
path.join(lib, 'index.js'),
|
|
2319
|
+
"export {Squares2X2Icon} from './icons/squares.js';\n",
|
|
2320
|
+
);
|
|
2321
|
+
fs.writeFileSync(
|
|
2322
|
+
path.join(lib, 'solid.js'),
|
|
2323
|
+
'export const Squares2X2Icon = props => null;\n',
|
|
2324
|
+
);
|
|
2325
|
+
await json([
|
|
2326
|
+
'experimental',
|
|
2327
|
+
'icon',
|
|
2328
|
+
'new-set',
|
|
2329
|
+
'outline',
|
|
2330
|
+
'--from',
|
|
2331
|
+
'@acme/glyph-library',
|
|
2332
|
+
'--variants',
|
|
2333
|
+
'outline,solid',
|
|
2334
|
+
]);
|
|
2335
|
+
const dataFile = path.join(
|
|
2336
|
+
pkg,
|
|
2337
|
+
'icon-sets',
|
|
2338
|
+
'outline',
|
|
2339
|
+
'outline.icons.json',
|
|
2340
|
+
);
|
|
2341
|
+
const data = dataOf('outline');
|
|
2342
|
+
data.icons.find(
|
|
2343
|
+
(/** @type {{export: string}} */ each) =>
|
|
2344
|
+
each.export === 'Squares2X2Icon',
|
|
2345
|
+
).id = 'squares-2-x2';
|
|
2346
|
+
fs.writeFileSync(dataFile, `${JSON.stringify(data, null, 2)}\n`);
|
|
2347
|
+
const added = await json([
|
|
2348
|
+
'experimental',
|
|
2349
|
+
'icon',
|
|
2350
|
+
'add',
|
|
2351
|
+
'--variant',
|
|
2352
|
+
'solid',
|
|
2353
|
+
'--from',
|
|
2354
|
+
'@acme/glyph-library/solid',
|
|
2355
|
+
'--all',
|
|
2356
|
+
]);
|
|
2357
|
+
expect(added.code).toBe(0);
|
|
2358
|
+
expect(added.body.data.missing).not.toContain('squares-2-x2');
|
|
2359
|
+
expect(
|
|
2360
|
+
dataOf('outline').icons.find(
|
|
2361
|
+
(/** @type {{id: string}} */ each) => each.id === 'squares-2-x2',
|
|
2362
|
+
).variants,
|
|
2363
|
+
).toEqual([{variant: 'solid', export: 'Squares2X2SolidIcon'}]);
|
|
2364
|
+
});
|
|
2365
|
+
});
|
|
2366
|
+
|
|
2367
|
+
describe('--set through the CLI selects the set add, map, and new-definition edit', () => {
|
|
2368
|
+
beforeEach(async () => {
|
|
2369
|
+
for (const set of ['one', 'two']) {
|
|
2370
|
+
await json([
|
|
2371
|
+
'experimental',
|
|
2372
|
+
'icon',
|
|
2373
|
+
'new-set',
|
|
2374
|
+
set,
|
|
2375
|
+
'--from',
|
|
2376
|
+
'@acme/glyph-library',
|
|
2377
|
+
]);
|
|
2378
|
+
}
|
|
2379
|
+
// A third set that is withdrawn: its data file is not JSON.
|
|
2380
|
+
const broken = path.join(pkg, 'icon-sets', 'lines');
|
|
2381
|
+
fs.mkdirSync(broken, {recursive: true});
|
|
2382
|
+
fs.writeFileSync(
|
|
2383
|
+
path.join(broken, 'lines.doc.mjs'),
|
|
2384
|
+
fs
|
|
2385
|
+
.readFileSync(path.join(pkg, 'icon-sets', 'one', 'one.doc.mjs'), 'utf8')
|
|
2386
|
+
.replace("name: 'one'", "name: 'lines'"),
|
|
2387
|
+
);
|
|
2388
|
+
fs.writeFileSync(path.join(broken, 'lines.icons.json'), '{nope');
|
|
2389
|
+
});
|
|
2390
|
+
|
|
2391
|
+
/** @type {Array<[string, (set: string) => string[], string]>} the command, its words, the icon it maps */
|
|
2392
|
+
const COMMANDS = [
|
|
2393
|
+
[
|
|
2394
|
+
'map',
|
|
2395
|
+
set => ['experimental', 'icon', 'map', 'delete', 'bin', '--set', set],
|
|
2396
|
+
'bin',
|
|
2397
|
+
],
|
|
2398
|
+
[
|
|
2399
|
+
'add',
|
|
2400
|
+
set => [
|
|
2401
|
+
'experimental',
|
|
2402
|
+
'icon',
|
|
2403
|
+
'add',
|
|
2404
|
+
'Rocket',
|
|
2405
|
+
'--from',
|
|
2406
|
+
'@acme/glyph-library/rocket',
|
|
2407
|
+
'--default',
|
|
2408
|
+
'--definition',
|
|
2409
|
+
'delete',
|
|
2410
|
+
'--set',
|
|
2411
|
+
set,
|
|
2412
|
+
],
|
|
2413
|
+
'rocket',
|
|
2414
|
+
],
|
|
2415
|
+
[
|
|
2416
|
+
'new-definition',
|
|
2417
|
+
set => [
|
|
2418
|
+
'experimental',
|
|
2419
|
+
'icon',
|
|
2420
|
+
'new-definition',
|
|
2421
|
+
'binIt',
|
|
2422
|
+
'--description',
|
|
2423
|
+
'Put something in the bin.',
|
|
2424
|
+
'--words',
|
|
2425
|
+
'bin',
|
|
2426
|
+
'--icon',
|
|
2427
|
+
'bin',
|
|
2428
|
+
'--set',
|
|
2429
|
+
set,
|
|
2430
|
+
],
|
|
2431
|
+
'bin',
|
|
2432
|
+
],
|
|
2433
|
+
];
|
|
2434
|
+
|
|
2435
|
+
it.each(COMMANDS)(
|
|
2436
|
+
'%s --set edits that set and leaves the other',
|
|
2437
|
+
async (_name, args, id) => {
|
|
2438
|
+
const before = fs.readFileSync(
|
|
2439
|
+
path.join(pkg, 'icon-sets', 'one', 'one.icons.json'),
|
|
2440
|
+
'utf-8',
|
|
2441
|
+
);
|
|
2442
|
+
const res = await json(args('two'));
|
|
2443
|
+
expect(res.code, JSON.stringify(res.body)).toBe(0);
|
|
2444
|
+
expect(
|
|
2445
|
+
fs.readFileSync(
|
|
2446
|
+
path.join(pkg, 'icon-sets', 'one', 'one.icons.json'),
|
|
2447
|
+
'utf-8',
|
|
2448
|
+
),
|
|
2449
|
+
).toBe(before);
|
|
2450
|
+
expect(Object.values(dataOf('two').map)).toContain(id);
|
|
2451
|
+
},
|
|
2452
|
+
);
|
|
2453
|
+
|
|
2454
|
+
it.each(COMMANDS)('%s --set with a missing set', async (_name, args) => {
|
|
2455
|
+
const res = await json(args('nope'));
|
|
2456
|
+
expect(res.code).toBe(1);
|
|
2457
|
+
expect(res.body).toMatchObject({
|
|
2458
|
+
code: 'ERR_NOT_FOUND',
|
|
2459
|
+
error: 'No icon set named "nope" in this package',
|
|
2460
|
+
});
|
|
2461
|
+
});
|
|
2462
|
+
|
|
2463
|
+
it.each(COMMANDS)('%s --set with a withdrawn set', async (_name, args) => {
|
|
2464
|
+
const res = await json(args('lines'));
|
|
2465
|
+
expect(res.code).toBe(1);
|
|
2466
|
+
expect(res.body.code).toBe('ERR_NOT_FOUND');
|
|
2467
|
+
expect(res.body.error).toMatch(
|
|
2468
|
+
/^Icon set "lines" is in this package but withdrawn: .*not valid JSON/u,
|
|
2469
|
+
);
|
|
2470
|
+
});
|
|
2471
|
+
});
|
|
2472
|
+
|
|
2473
|
+
describe('a refresh of a set wrapped from a prefixed library by an older id rule', () => {
|
|
2474
|
+
it('matches each icon by the library export it re-exports, and keeps its public export byte for byte', async () => {
|
|
2475
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'hero');
|
|
2476
|
+
fs.mkdirSync(lib, {recursive: true});
|
|
2477
|
+
fs.writeFileSync(
|
|
2478
|
+
path.join(lib, 'package.json'),
|
|
2479
|
+
JSON.stringify({
|
|
2480
|
+
name: '@acme/hero',
|
|
2481
|
+
version: '1.0.0',
|
|
2482
|
+
type: 'module',
|
|
2483
|
+
exports: {'.': './index.js'},
|
|
2484
|
+
}),
|
|
2485
|
+
);
|
|
2486
|
+
fs.writeFileSync(
|
|
2487
|
+
path.join(lib, 'index.js'),
|
|
2488
|
+
[
|
|
2489
|
+
'export const HiSquares2X2Icon = props => null;',
|
|
2490
|
+
'export const HiTrashIcon = props => null;',
|
|
2491
|
+
'export const HiXMarkIcon = props => null;',
|
|
2492
|
+
'',
|
|
2493
|
+
].join('\n'),
|
|
2494
|
+
);
|
|
2495
|
+
const args = [
|
|
2496
|
+
'experimental',
|
|
2497
|
+
'icon',
|
|
2498
|
+
'new-set',
|
|
2499
|
+
'hero',
|
|
2500
|
+
'--from',
|
|
2501
|
+
'@acme/hero',
|
|
2502
|
+
];
|
|
2503
|
+
expect((await json(args)).code).toBe(0);
|
|
2504
|
+
const setDir = path.join(pkg, 'icon-sets', 'hero');
|
|
2505
|
+
const generatedFile = path.join(setDir, 'hero.generated.js');
|
|
2506
|
+
const typesFile = path.join(setDir, 'hero.generated.d.ts');
|
|
2507
|
+
// Rewrite the set as an older id rule wrote it: id `squares-2-x2`,
|
|
2508
|
+
// public export `Squares2X2Icon`, re-exporting `HiSquares2X2Icon`, with
|
|
2509
|
+
// a map entry and an author's word.
|
|
2510
|
+
const data = dataOf('hero');
|
|
2511
|
+
const squares = data.icons.find(
|
|
2512
|
+
(/** @type {{id: string}} */ each) => each.id === 'squares-2x2',
|
|
2513
|
+
);
|
|
2514
|
+
const newName = squares.export;
|
|
2515
|
+
Object.assign(squares, {
|
|
2516
|
+
id: 'squares-2-x2',
|
|
2517
|
+
export: 'Squares2X2Icon',
|
|
2518
|
+
words: ['squares', 'x2', 'grid-view'],
|
|
2519
|
+
});
|
|
2520
|
+
data.map = {...data.map, moreHorizontal: 'squares-2-x2'};
|
|
2521
|
+
fs.writeFileSync(
|
|
2522
|
+
path.join(setDir, 'hero.icons.json'),
|
|
2523
|
+
`${JSON.stringify(data, null, 2)}\n`,
|
|
2524
|
+
);
|
|
2525
|
+
for (const file of [generatedFile, typesFile]) {
|
|
2526
|
+
fs.writeFileSync(
|
|
2527
|
+
file,
|
|
2528
|
+
fs.readFileSync(file, 'utf-8').replaceAll(newName, 'Squares2X2Icon'),
|
|
2529
|
+
);
|
|
2530
|
+
}
|
|
2531
|
+
expect(fs.readFileSync(generatedFile, 'utf-8')).toContain(
|
|
2532
|
+
"export {HiSquares2X2Icon as Squares2X2Icon} from '@acme/hero';",
|
|
2533
|
+
);
|
|
2534
|
+
|
|
2535
|
+
const refreshed = await json(args);
|
|
2536
|
+
expect(refreshed.code).toBe(0);
|
|
2537
|
+
expect(refreshed.body.data.renamed).toEqual([
|
|
2538
|
+
{from: 'squares-2-x2', to: 'squares-2x2'},
|
|
2539
|
+
]);
|
|
2540
|
+
expect(refreshed.body.data.notes.join(' ')).not.toContain(
|
|
2541
|
+
'no longer exports',
|
|
2542
|
+
);
|
|
2543
|
+
const after = dataOf('hero');
|
|
2544
|
+
expect(after.map.moreHorizontal).toBe('squares-2x2');
|
|
2545
|
+
const kept = after.icons.find(
|
|
2546
|
+
(/** @type {{id: string}} */ each) => each.id === 'squares-2x2',
|
|
2547
|
+
);
|
|
2548
|
+
expect(kept.export).toBe('Squares2X2Icon');
|
|
2549
|
+
expect(kept.words).toContain('grid-view');
|
|
2550
|
+
const generated = fs.readFileSync(generatedFile, 'utf-8');
|
|
2551
|
+
expect(generated).toContain(
|
|
2552
|
+
"export {HiSquares2X2Icon as Squares2X2Icon} from '@acme/hero';",
|
|
2553
|
+
);
|
|
2554
|
+
expect(generated).not.toContain(
|
|
2555
|
+
newName === 'Squares2X2Icon' ? '\0' : newName,
|
|
2556
|
+
);
|
|
2557
|
+
// The set still checks: its types match its module, and, once the entry
|
|
2558
|
+
// re-exports it, every icon export resolves.
|
|
2559
|
+
fs.appendFileSync(
|
|
2560
|
+
path.join(pkg, 'index.js'),
|
|
2561
|
+
"export * from './icon-sets/hero/hero.generated.js';\n",
|
|
2562
|
+
);
|
|
2563
|
+
const check = await runCli(['integration', 'check', '--json'], pkg);
|
|
2564
|
+
expect(check.stdout).not.toContain('icon_generated_types_mismatch');
|
|
2565
|
+
expect(check.stdout).not.toContain('icon_export_missing');
|
|
2566
|
+
});
|
|
2567
|
+
});
|
|
2568
|
+
|
|
2569
|
+
describe('add --variant --all on a set an older id rule wrote from a prefixed library', () => {
|
|
2570
|
+
it('meets each icon by the library export it re-exports', async () => {
|
|
2571
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'hero');
|
|
2572
|
+
fs.mkdirSync(lib, {recursive: true});
|
|
2573
|
+
fs.writeFileSync(
|
|
2574
|
+
path.join(lib, 'package.json'),
|
|
2575
|
+
JSON.stringify({
|
|
2576
|
+
name: '@acme/hero',
|
|
2577
|
+
version: '1.0.0',
|
|
2578
|
+
type: 'module',
|
|
2579
|
+
exports: {'.': './index.js', './solid': './solid.js'},
|
|
2580
|
+
}),
|
|
2581
|
+
);
|
|
2582
|
+
const source =
|
|
2583
|
+
'export const HiSquares2X2Icon = props => null;\nexport const HiTrashIcon = props => null;\n';
|
|
2584
|
+
fs.writeFileSync(path.join(lib, 'index.js'), source);
|
|
2585
|
+
fs.writeFileSync(path.join(lib, 'solid.js'), source);
|
|
2586
|
+
await json([
|
|
2587
|
+
'experimental',
|
|
2588
|
+
'icon',
|
|
2589
|
+
'new-set',
|
|
2590
|
+
'hero',
|
|
2591
|
+
'--from',
|
|
2592
|
+
'@acme/hero',
|
|
2593
|
+
'--variants',
|
|
2594
|
+
'outline,solid',
|
|
2595
|
+
]);
|
|
2596
|
+
const setDir = path.join(pkg, 'icon-sets', 'hero');
|
|
2597
|
+
const data = dataOf('hero');
|
|
2598
|
+
const squares = data.icons.find(
|
|
2599
|
+
(/** @type {{id: string}} */ each) => each.id === 'squares-2x2',
|
|
2600
|
+
);
|
|
2601
|
+
const newName = squares.export;
|
|
2602
|
+
Object.assign(squares, {id: 'squares-2-x2', export: 'Squares2X2Icon'});
|
|
2603
|
+
fs.writeFileSync(
|
|
2604
|
+
path.join(setDir, 'hero.icons.json'),
|
|
2605
|
+
`${JSON.stringify(data, null, 2)}\n`,
|
|
2606
|
+
);
|
|
2607
|
+
for (const file of ['hero.generated.js', 'hero.generated.d.ts']) {
|
|
2608
|
+
const full = path.join(setDir, file);
|
|
2609
|
+
fs.writeFileSync(
|
|
2610
|
+
full,
|
|
2611
|
+
fs.readFileSync(full, 'utf-8').replaceAll(newName, 'Squares2X2Icon'),
|
|
2612
|
+
);
|
|
2613
|
+
}
|
|
2614
|
+
const added = await json([
|
|
2615
|
+
'experimental',
|
|
2616
|
+
'icon',
|
|
2617
|
+
'add',
|
|
2618
|
+
'--variant',
|
|
2619
|
+
'solid',
|
|
2620
|
+
'--from',
|
|
2621
|
+
'@acme/hero/solid',
|
|
2622
|
+
'--all',
|
|
2623
|
+
]);
|
|
2624
|
+
expect(added.code, JSON.stringify(added.body)).toBe(0);
|
|
2625
|
+
expect(added.body.data.missing).toEqual([]);
|
|
2626
|
+
expect(
|
|
2627
|
+
dataOf('hero').icons.find(
|
|
2628
|
+
(/** @type {{id: string}} */ each) => each.id === 'squares-2-x2',
|
|
2629
|
+
).variants,
|
|
2630
|
+
).toEqual([{variant: 'solid', export: 'Squares2X2SolidIcon'}]);
|
|
2631
|
+
});
|
|
2632
|
+
});
|
|
2633
|
+
|
|
2634
|
+
describe('a refresh after the library drops an icon', () => {
|
|
2635
|
+
it('names the icon it removed and the map entry that lost it', async () => {
|
|
2636
|
+
const args = [
|
|
2637
|
+
'experimental',
|
|
2638
|
+
'icon',
|
|
2639
|
+
'new-set',
|
|
2640
|
+
'outline',
|
|
2641
|
+
'--from',
|
|
2642
|
+
'@acme/glyph-library',
|
|
2643
|
+
];
|
|
2644
|
+
await json(args);
|
|
2645
|
+
await json(['experimental', 'icon', 'map', 'close', 'cross']);
|
|
2646
|
+
const index = path.join(
|
|
2647
|
+
pkg,
|
|
2648
|
+
'node_modules',
|
|
2649
|
+
'@acme',
|
|
2650
|
+
'glyph-library',
|
|
2651
|
+
'index.js',
|
|
2652
|
+
);
|
|
2653
|
+
fs.writeFileSync(
|
|
2654
|
+
index,
|
|
2655
|
+
fs
|
|
2656
|
+
.readFileSync(index, 'utf-8')
|
|
2657
|
+
.replace("export {Cross} from './icons/cross.js';\n", ''),
|
|
2658
|
+
);
|
|
2659
|
+
const refreshed = await json(args);
|
|
2660
|
+
expect(refreshed.code).toBe(0);
|
|
2661
|
+
expect(refreshed.body.data.notes).toEqual(
|
|
2662
|
+
expect.arrayContaining([
|
|
2663
|
+
'These map entries named those icons and were removed: close -> "cross".',
|
|
2664
|
+
'1 icons the library no longer exports were removed from the set: cross.',
|
|
2665
|
+
]),
|
|
2666
|
+
);
|
|
2667
|
+
});
|
|
2668
|
+
});
|
|
2669
|
+
|
|
2670
|
+
describe('a refresh changes only the icons the refreshed module supplies', () => {
|
|
2671
|
+
beforeEach(() => {
|
|
2672
|
+
// A second library, and your own artwork.
|
|
2673
|
+
const other = path.join(pkg, 'node_modules', '@acme', 'other-library');
|
|
2674
|
+
fs.mkdirSync(other, {recursive: true});
|
|
2675
|
+
fs.writeFileSync(
|
|
2676
|
+
path.join(other, 'package.json'),
|
|
2677
|
+
JSON.stringify({
|
|
2678
|
+
name: '@acme/other-library',
|
|
2679
|
+
version: '1.0.0',
|
|
2680
|
+
type: 'module',
|
|
2681
|
+
exports: {'.': './index.js'},
|
|
2682
|
+
}),
|
|
2683
|
+
);
|
|
2684
|
+
fs.writeFileSync(
|
|
2685
|
+
path.join(other, 'index.js'),
|
|
2686
|
+
'export const Rocket = props => null;\n',
|
|
2687
|
+
);
|
|
2688
|
+
fs.mkdirSync(path.join(pkg, 'art'), {recursive: true});
|
|
2689
|
+
fs.writeFileSync(
|
|
2690
|
+
path.join(pkg, 'art', 'spark.js'),
|
|
2691
|
+
'export const Spark = props => null;\n',
|
|
2692
|
+
);
|
|
2693
|
+
fs.writeFileSync(
|
|
2694
|
+
path.join(pkg, 'art', 'spark.d.ts'),
|
|
2695
|
+
'export declare const Spark: (props: object) => null;\n',
|
|
2696
|
+
);
|
|
2697
|
+
});
|
|
2698
|
+
|
|
2699
|
+
it('keeps your ./ artwork and another library’s icon, with their map entries and module lines, and still removes a library icon that went away', async () => {
|
|
2700
|
+
const args = [
|
|
2701
|
+
'experimental',
|
|
2702
|
+
'icon',
|
|
2703
|
+
'new-set',
|
|
2704
|
+
'outline',
|
|
2705
|
+
'--from',
|
|
2706
|
+
'@acme/glyph-library',
|
|
2707
|
+
];
|
|
2708
|
+
expect((await json(args)).code).toBe(0);
|
|
2709
|
+
for (const add of [
|
|
2710
|
+
['Spark', '--from', './art/spark.js', '--definition', 'sparkles'],
|
|
2711
|
+
['Rocket', '--from', '@acme/other-library', '--definition', 'rocket'],
|
|
2712
|
+
]) {
|
|
2713
|
+
const added = await json(['experimental', 'icon', 'add', ...add]);
|
|
2714
|
+
expect(added.code, JSON.stringify(added.body)).toBe(0);
|
|
2715
|
+
}
|
|
2716
|
+
await json(['experimental', 'icon', 'map', 'close', 'cross']);
|
|
2717
|
+
const generatedFile = path.join(
|
|
2718
|
+
pkg,
|
|
2719
|
+
'icon-sets',
|
|
2720
|
+
'outline',
|
|
2721
|
+
'outline.generated.js',
|
|
2722
|
+
);
|
|
2723
|
+
const before = fs.readFileSync(generatedFile, 'utf-8');
|
|
2724
|
+
const sparkLine = before
|
|
2725
|
+
.split('\n')
|
|
2726
|
+
.find(line => line.includes('SparkIcon') && line.includes('art/spark'));
|
|
2727
|
+
const rocketLine = before
|
|
2728
|
+
.split('\n')
|
|
2729
|
+
.find(
|
|
2730
|
+
line => line.includes('RocketIcon') && line.includes('other-library'),
|
|
2731
|
+
);
|
|
2732
|
+
expect(sparkLine).toBeTruthy();
|
|
2733
|
+
expect(rocketLine).toBeTruthy();
|
|
2734
|
+
// The library drops Cross.
|
|
2735
|
+
const index = path.join(
|
|
2736
|
+
pkg,
|
|
2737
|
+
'node_modules',
|
|
2738
|
+
'@acme',
|
|
2739
|
+
'glyph-library',
|
|
2740
|
+
'index.js',
|
|
2741
|
+
);
|
|
2742
|
+
fs.writeFileSync(
|
|
2743
|
+
index,
|
|
2744
|
+
fs
|
|
2745
|
+
.readFileSync(index, 'utf-8')
|
|
2746
|
+
.replace("export {Cross} from './icons/cross.js';\n", ''),
|
|
2747
|
+
);
|
|
2748
|
+
|
|
2749
|
+
const refreshed = await json(args);
|
|
2750
|
+
expect(refreshed.code).toBe(0);
|
|
2751
|
+
const data = dataOf('outline');
|
|
2752
|
+
const ids = data.icons.map((/** @type {{id: string}} */ each) => each.id);
|
|
2753
|
+
expect(ids).toEqual(expect.arrayContaining(['bin', 'spark', 'rocket']));
|
|
2754
|
+
expect(ids).not.toContain('cross');
|
|
2755
|
+
expect(data.map).toMatchObject({sparkles: 'spark', rocket: 'rocket'});
|
|
2756
|
+
expect(data.map).not.toHaveProperty('close');
|
|
2757
|
+
const after = fs.readFileSync(generatedFile, 'utf-8');
|
|
2758
|
+
expect(after).toContain(/** @type {string} */ (sparkLine));
|
|
2759
|
+
expect(after).toContain(/** @type {string} */ (rocketLine));
|
|
2760
|
+
const notes = refreshed.body.data.notes.join('\n');
|
|
2761
|
+
expect(notes).toContain(
|
|
2762
|
+
'1 icons the library no longer exports were removed from the set: cross.',
|
|
2763
|
+
);
|
|
2764
|
+
expect(notes).toContain('close -> "cross"');
|
|
2765
|
+
expect(notes).not.toMatch(/spark|rocket/u);
|
|
2766
|
+
});
|
|
2767
|
+
|
|
2768
|
+
it('add --variant --all leaves icons from other modules alone and never lists them as missing', async () => {
|
|
2769
|
+
const lib = path.join(pkg, 'node_modules', '@acme', 'glyph-library');
|
|
2770
|
+
fs.writeFileSync(
|
|
2771
|
+
path.join(lib, 'package.json'),
|
|
2772
|
+
JSON.stringify({
|
|
2773
|
+
...JSON.parse(fs.readFileSync(path.join(lib, 'package.json'), 'utf-8')),
|
|
2774
|
+
exports: {'.': './index.js', './solid': './solid.js'},
|
|
2775
|
+
}),
|
|
2776
|
+
);
|
|
2777
|
+
// The solid module also exports a Spark: it is not your Spark.
|
|
2778
|
+
fs.writeFileSync(
|
|
2779
|
+
path.join(lib, 'solid.js'),
|
|
2780
|
+
'export const Bin = props => null;\nexport const Spark = props => null;\n',
|
|
2781
|
+
);
|
|
2782
|
+
await json([
|
|
2783
|
+
'experimental',
|
|
2784
|
+
'icon',
|
|
2785
|
+
'new-set',
|
|
2786
|
+
'outline',
|
|
2787
|
+
'--from',
|
|
2788
|
+
'@acme/glyph-library',
|
|
2789
|
+
'--variants',
|
|
2790
|
+
'outline,solid',
|
|
2791
|
+
]);
|
|
2792
|
+
await json([
|
|
2793
|
+
'experimental',
|
|
2794
|
+
'icon',
|
|
2795
|
+
'add',
|
|
2796
|
+
'Spark',
|
|
2797
|
+
'--from',
|
|
2798
|
+
'./art/spark.js',
|
|
2799
|
+
'--definition',
|
|
2800
|
+
'sparkles',
|
|
2801
|
+
]);
|
|
2802
|
+
const added = await json([
|
|
2803
|
+
'experimental',
|
|
2804
|
+
'icon',
|
|
2805
|
+
'add',
|
|
2806
|
+
'--variant',
|
|
2807
|
+
'solid',
|
|
2808
|
+
'--from',
|
|
2809
|
+
'@acme/glyph-library/solid',
|
|
2810
|
+
'--all',
|
|
2811
|
+
]);
|
|
2812
|
+
expect(added.code, JSON.stringify(added.body)).toBe(0);
|
|
2813
|
+
expect(added.body.data.missing).toEqual(['cross']);
|
|
2814
|
+
const spark = dataOf('outline').icons.find(
|
|
2815
|
+
(/** @type {{id: string}} */ each) => each.id === 'spark',
|
|
2816
|
+
);
|
|
2817
|
+
expect(spark.variants).toBeUndefined();
|
|
2818
|
+
});
|
|
2819
|
+
});
|
|
2820
|
+
|
|
2821
|
+
describe('a refresh with --exclude', () => {
|
|
2822
|
+
it('names the icons --exclude left out, never as ones the library no longer exports', async () => {
|
|
2823
|
+
const args = [
|
|
2824
|
+
'experimental',
|
|
2825
|
+
'icon',
|
|
2826
|
+
'new-set',
|
|
2827
|
+
'outline',
|
|
2828
|
+
'--from',
|
|
2829
|
+
'@acme/glyph-library',
|
|
2830
|
+
];
|
|
2831
|
+
await json(args);
|
|
2832
|
+
await json(['experimental', 'icon', 'map', 'close', 'cross']);
|
|
2833
|
+
const refreshed = await json([...args, '--exclude', 'Cross']);
|
|
2834
|
+
expect(refreshed.code).toBe(0);
|
|
2835
|
+
const notes = refreshed.body.data.notes;
|
|
2836
|
+
expect(notes).toEqual(
|
|
2837
|
+
expect.arrayContaining([
|
|
2838
|
+
'Left out by --exclude, and removed from the set: cross.',
|
|
2839
|
+
'These map entries named icons --exclude left out and were removed: close -> "cross".',
|
|
2840
|
+
]),
|
|
2841
|
+
);
|
|
2842
|
+
expect(notes.join('\n')).not.toContain('no longer exports');
|
|
2843
|
+
expect(dataOf('outline').exclude).toEqual(['Cross']);
|
|
2844
|
+
});
|
|
2845
|
+
});
|