@astryxdesign/cli 0.7.5-canary.2a50a80 → 0.7.5-canary.50df977
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/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/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/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/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/docs/tree/render-pages.doc.mjs +94 -0
- package/authoring/debug/parse.d.mts +2 -2
- package/clients/cli/commands/experimental/index.mjs +2 -0
- package/clients/cli/commands/experimental/render.mjs +113 -0
- package/clients/cli/commands/experimental-render.doc.mjs +60 -0
- package/clients/cli/commands/experimental.doc.mjs +2 -1
- package/clients/cli/commands/text-json-parity.test.mjs +46 -0
- package/clients/cli/index.mjs +1 -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/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 +13 -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
|
@@ -49,12 +49,16 @@ import {
|
|
|
49
49
|
synonymMatches,
|
|
50
50
|
} from '../../foundation/text/suggest-order.mjs';
|
|
51
51
|
import {AstryxError, coreDirOrThrow} from '../error.mjs';
|
|
52
|
+
import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
|
|
52
53
|
import {
|
|
53
54
|
componentLinkProvider,
|
|
54
55
|
linkComponentDoc,
|
|
55
56
|
loadDocsCatalog,
|
|
56
57
|
} from '../docs/_adapter.mjs';
|
|
57
58
|
|
|
59
|
+
/** How far below the first suggestion's score a later one may be. */
|
|
60
|
+
const NEAR_FIRST = 10;
|
|
61
|
+
|
|
58
62
|
/** @type {Record<string, {synonyms?: string[]}> | undefined} */
|
|
59
63
|
let cards;
|
|
60
64
|
/**
|
|
@@ -503,9 +507,20 @@ export async function resolveUnscopedDoc(dirName, {coreDir, cwd, name}) {
|
|
|
503
507
|
Object.values(components).flat(),
|
|
504
508
|
synonymMatches(dirName, searchCards()),
|
|
505
509
|
).slice(0, count);
|
|
510
|
+
// Past the first two suggestions, only the ones about as close as
|
|
511
|
+
// the first (within NEAR_FIRST points), or a close spelling of the
|
|
512
|
+
// whole typed name (a typo): a weaker match after a strong one reads
|
|
513
|
+
// as noise. The list only gets shorter and keeps at least two.
|
|
514
|
+
const typed = dirName.toLowerCase();
|
|
515
|
+
const nearFirst = candidates.filter(
|
|
516
|
+
(c, i) =>
|
|
517
|
+
i < 2 ||
|
|
518
|
+
c.score >= candidates[0].score - NEAR_FIRST ||
|
|
519
|
+
levenshteinDistance(c.name.toLowerCase(), typed) <= 2,
|
|
520
|
+
);
|
|
506
521
|
throw new AstryxError(
|
|
507
522
|
`No component named "${name}"`,
|
|
508
|
-
|
|
523
|
+
nearFirst.map(c => ({name: c.name, reason: c.reason})),
|
|
509
524
|
ERROR_CODES.ERR_UNKNOWN_COMPONENT,
|
|
510
525
|
);
|
|
511
526
|
}
|
|
@@ -499,3 +499,34 @@ describe('component dispatcher — detail levels on single component (text only)
|
|
|
499
499
|
SLOW,
|
|
500
500
|
);
|
|
501
501
|
});
|
|
502
|
+
|
|
503
|
+
describe('component not-found suggestions', () => {
|
|
504
|
+
const suggested = async (/** @type {string} */ name) => {
|
|
505
|
+
const error = await component(name, {cwd}).catch(e => e);
|
|
506
|
+
expect(error).toBeInstanceOf(AstryxError);
|
|
507
|
+
expect(error.code).toBe('ERR_UNKNOWN_COMPONENT');
|
|
508
|
+
return error.suggestions.map((/** @type {{name: string}} */ s) => s.name);
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
it(
|
|
512
|
+
'leaves out a weaker match after a strong first suggestion',
|
|
513
|
+
async () => {
|
|
514
|
+
// FieldLabel is another name for it; past the second suggestion, the
|
|
515
|
+
// matches on one word of the name ("input", "label") are weaker and add
|
|
516
|
+
// only noise.
|
|
517
|
+
const names = await suggested('InputLabel');
|
|
518
|
+
expect(names[0]).toBe('FieldLabel');
|
|
519
|
+
expect(names).toHaveLength(2);
|
|
520
|
+
},
|
|
521
|
+
SLOW,
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
it(
|
|
525
|
+
'keeps a close spelling of the whole name after a stronger first match',
|
|
526
|
+
async () => {
|
|
527
|
+
expect(await suggested('Blockqoute')).toContain('Blockquote');
|
|
528
|
+
expect(await suggested('TextrAea')).toContain('TextArea');
|
|
529
|
+
},
|
|
530
|
+
SLOW,
|
|
531
|
+
);
|
|
532
|
+
});
|
|
@@ -216,7 +216,7 @@ export const OFFICIAL_LIST_FILE: string;
|
|
|
216
216
|
*/
|
|
217
217
|
export const EXPERIMENTAL_KINDS: readonly ["icon-set"];
|
|
218
218
|
/** The item kinds every project reads: the catalog kinds, less experimental ones. */
|
|
219
|
-
export const STABLE_KINDS: ("component" | "theme" | "codemod" | "agent-doc" | "doc" | "
|
|
219
|
+
export const STABLE_KINDS: ("template" | "component" | "theme" | "codemod" | "agent-doc" | "doc" | "icon-set")[];
|
|
220
220
|
/** The list and detail entry fields for each item kind, in display order. */
|
|
221
221
|
export const KIND_FIELDS: readonly [readonly ["component", "components"], readonly ["template", "templates"], readonly ["doc", "docs"], readonly ["theme", "themes"], readonly ["codemod", "codemods"], readonly ["agent-doc", "agentDocs"], readonly ["icon-set", "iconSets"]];
|
|
222
222
|
export type ScannedPackage = import("./_package-scanner.mjs").ScannedPackage;
|
package/api/docs/_adapter.d.mts
CHANGED
|
@@ -335,8 +335,11 @@ export function holdsOwnName(tree: DocsTree, catalog: DocsCatalog, entry: import
|
|
|
335
335
|
export function routeOwner(tree: DocsTree, entry: import("../../foundation/discovery/docs-discovery.mjs").DocsTopicEntry): TreeNode | null;
|
|
336
336
|
/**
|
|
337
337
|
* The error for a docs argument that names nothing. For a route, it suggests
|
|
338
|
-
*
|
|
339
|
-
*
|
|
338
|
+
* every child of the deepest namespace the route reaches, closest first.
|
|
339
|
+
* Otherwise it suggests the docs the argument names in another spelling, or
|
|
340
|
+
* failing that the topics and top-level namespaces, closest first and cut
|
|
341
|
+
* where the matches get weaker (every one of them when none shares a word
|
|
342
|
+
* with the argument).
|
|
340
343
|
* @param {unknown} topic
|
|
341
344
|
* @param {DocsCatalog} catalog
|
|
342
345
|
* @returns {Promise<AstryxError>}
|
package/api/docs/_adapter.mjs
CHANGED
|
@@ -77,6 +77,7 @@ import {
|
|
|
77
77
|
discoverIntegrationTemplatesForOne,
|
|
78
78
|
} from '../../foundation/discovery/template-adapter.mjs';
|
|
79
79
|
import {findCoreDir} from '../../foundation/fs/paths.mjs';
|
|
80
|
+
import {reusedWhileUnchanged} from '../../foundation/fs/read-record.mjs';
|
|
80
81
|
import {AstryxError} from '../error.mjs';
|
|
81
82
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
82
83
|
import {orderRouteSuggestions} from '../../foundation/text/suggest-order.mjs';
|
|
@@ -393,8 +394,8 @@ export function projectTree(catalog, {fresh = false} = {}) {
|
|
|
393
394
|
return tree;
|
|
394
395
|
}
|
|
395
396
|
|
|
396
|
-
/**
|
|
397
|
-
|
|
397
|
+
/** The CLI's own tree files, loaded again after one of them changes. */
|
|
398
|
+
const cliTreeInputs = reusedWhileUnchanged(() => loadTreeInputs());
|
|
398
399
|
|
|
399
400
|
/**
|
|
400
401
|
* Every flat topic in the catalog, as the tree's topic levels read it.
|
|
@@ -441,8 +442,7 @@ async function flatTopicInputs(catalog) {
|
|
|
441
442
|
*/
|
|
442
443
|
async function buildProjectTree(catalog, fresh) {
|
|
443
444
|
const added = catalog.treeInputs;
|
|
444
|
-
|
|
445
|
-
const cli = await cliTreeInputs;
|
|
445
|
+
const cli = await cliTreeInputs({fresh});
|
|
446
446
|
const result = buildDocsTree({
|
|
447
447
|
namespaces: [...cli.namespaces, ...added.flatMap(each => each.namespaces)],
|
|
448
448
|
docs: [...cli.docs, ...added.flatMap(each => each.guides)],
|
|
@@ -573,11 +573,15 @@ function identitiesOf(tree) {
|
|
|
573
573
|
/**
|
|
574
574
|
* The CLI's authoring docs, by kind and name. The field reference under
|
|
575
575
|
* `astryx docs authoring` reads each as one section keyed by its name, so a
|
|
576
|
-
* link to one opens that section. Loaded
|
|
577
|
-
* tree files.
|
|
578
|
-
* @type {Promise<Map<string, any>> | undefined}
|
|
576
|
+
* link to one opens that section. Loaded again after one of them changes,
|
|
577
|
+
* like the CLI's tree files.
|
|
579
578
|
*/
|
|
580
|
-
|
|
579
|
+
const authoringDocs = reusedWhileUnchanged(() =>
|
|
580
|
+
loadAuthoringSelfDocs().then(
|
|
581
|
+
({loaded}) =>
|
|
582
|
+
new Map(loaded.map(({doc}) => [`${doc.type}\u0000${doc.name}`, doc])),
|
|
583
|
+
),
|
|
584
|
+
);
|
|
581
585
|
|
|
582
586
|
/**
|
|
583
587
|
* The CLI authoring doc a link names. The `authoring` namespace is the CLI's
|
|
@@ -587,11 +591,7 @@ let authoringDocs;
|
|
|
587
591
|
* @returns {Promise<any | null>}
|
|
588
592
|
*/
|
|
589
593
|
async function authoringDoc(kind, name) {
|
|
590
|
-
|
|
591
|
-
({loaded}) =>
|
|
592
|
-
new Map(loaded.map(({doc}) => [`${doc.type}\u0000${doc.name}`, doc])),
|
|
593
|
-
);
|
|
594
|
-
return (await authoringDocs).get(`${kind}\u0000${name}`) ?? null;
|
|
594
|
+
return (await authoringDocs()).get(`${kind}\u0000${name}`) ?? null;
|
|
595
595
|
}
|
|
596
596
|
|
|
597
597
|
/**
|
|
@@ -1844,8 +1844,11 @@ function movedRoute(topic, tree) {
|
|
|
1844
1844
|
|
|
1845
1845
|
/**
|
|
1846
1846
|
* The error for a docs argument that names nothing. For a route, it suggests
|
|
1847
|
-
*
|
|
1848
|
-
*
|
|
1847
|
+
* every child of the deepest namespace the route reaches, closest first.
|
|
1848
|
+
* Otherwise it suggests the docs the argument names in another spelling, or
|
|
1849
|
+
* failing that the topics and top-level namespaces, closest first and cut
|
|
1850
|
+
* where the matches get weaker (every one of them when none shares a word
|
|
1851
|
+
* with the argument).
|
|
1849
1852
|
* @param {unknown} topic
|
|
1850
1853
|
* @param {DocsCatalog} catalog
|
|
1851
1854
|
* @returns {Promise<AstryxError>}
|
|
@@ -1854,6 +1857,8 @@ export async function unknownTopicError(topic, catalog) {
|
|
|
1854
1857
|
const tree = await projectTree(catalog);
|
|
1855
1858
|
/** @type {Array<{name: string, reason: string}>} */
|
|
1856
1859
|
let suggestions = [];
|
|
1860
|
+
// Route children stay whole (spec:AST-046); only the other lists are cut.
|
|
1861
|
+
let routeChildren = false;
|
|
1857
1862
|
if (typeof topic === 'string' && topic.includes('/')) {
|
|
1858
1863
|
const parts = topic.split('/');
|
|
1859
1864
|
for (
|
|
@@ -1863,6 +1868,7 @@ export async function unknownTopicError(topic, catalog) {
|
|
|
1863
1868
|
) {
|
|
1864
1869
|
const near = tree.get(parts.slice(0, depth).join('/'));
|
|
1865
1870
|
if (near) {
|
|
1871
|
+
routeChildren = true;
|
|
1866
1872
|
suggestions = near.slots.flatMap(slot =>
|
|
1867
1873
|
slot.children.map(route => ({
|
|
1868
1874
|
name: route,
|
|
@@ -1894,7 +1900,9 @@ export async function unknownTopicError(topic, catalog) {
|
|
|
1894
1900
|
];
|
|
1895
1901
|
}
|
|
1896
1902
|
if (typeof topic === 'string') {
|
|
1897
|
-
suggestions = orderRouteSuggestions(topic, suggestions
|
|
1903
|
+
suggestions = orderRouteSuggestions(topic, suggestions, {
|
|
1904
|
+
closest: !routeChildren,
|
|
1905
|
+
});
|
|
1898
1906
|
}
|
|
1899
1907
|
// A route that moved names where it went, ahead of the usual suggestions
|
|
1900
1908
|
// (spec:AST-046 FR9, FR6).
|
package/api/docs/docs.test.mjs
CHANGED
|
@@ -254,6 +254,24 @@ describe('docs() dispatcher routing', () => {
|
|
|
254
254
|
);
|
|
255
255
|
}, SLOW);
|
|
256
256
|
|
|
257
|
+
it('an unknown route keeps every child of its namespace, closest first', async () => {
|
|
258
|
+
const error = await docs('tokens/usage').catch(e => e);
|
|
259
|
+
expect(error.code).toBe('ERR_UNKNOWN_TOPIC');
|
|
260
|
+
const names = error.suggestions.map(s => s.name);
|
|
261
|
+
expect(names[0]).toBe('tokens/tokens-usage');
|
|
262
|
+
const none = await docs('tokens/zzzz-nope').catch(e => e);
|
|
263
|
+
expect([...names].sort()).toEqual(none.suggestions.map(s => s.name).sort());
|
|
264
|
+
}, SLOW);
|
|
265
|
+
|
|
266
|
+
it('an unknown flat topic is cut where the matches get weaker', async () => {
|
|
267
|
+
const error = await docs('authoring-at-meta').catch(e => e);
|
|
268
|
+
expect(error.suggestions.map(s => s.name)).toEqual(['authoring']);
|
|
269
|
+
// One-letter words do not narrow it: `a11y` keeps the whole browse list.
|
|
270
|
+
const browse = await docs('zzzz-nope').catch(e => e);
|
|
271
|
+
const a11y = await docs('a11y').catch(e => e);
|
|
272
|
+
expect(a11y.suggestions.length).toBe(browse.suggestions.length);
|
|
273
|
+
}, SLOW);
|
|
274
|
+
|
|
257
275
|
it('a section no guide of a namespace has -> ERR_UNKNOWN_SECTION, naming its guides', async () => {
|
|
258
276
|
const err = await docs('cli', 'zzzz-nope').catch(e => e);
|
|
259
277
|
expect(err).toBeInstanceOf(AstryxError);
|
|
@@ -450,11 +450,11 @@ describe('integration-contributed topics', () => {
|
|
|
450
450
|
|
|
451
451
|
it('offers the contributed topics as suggestions on an unknown one', async () => {
|
|
452
452
|
scaffold({'deploying.doc.mjs': topic()});
|
|
453
|
-
await expect(docs('
|
|
453
|
+
await expect(docs('zzqx-qqzz', undefined, {cwd: tmpDir, full: true})).rejects.toBeInstanceOf(
|
|
454
454
|
AstryxError,
|
|
455
455
|
);
|
|
456
456
|
try {
|
|
457
|
-
await docs('
|
|
457
|
+
await docs('zzqx-qqzz', undefined, {cwd: tmpDir, full: true});
|
|
458
458
|
} catch (err) {
|
|
459
459
|
expect(err.suggestions.map(s => s.name)).toContain('deploying');
|
|
460
460
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `@astryxdesign/cli/api/experimental`: the CLI's experimental
|
|
5
|
+
* functions (spec:AST-017 FR21, FR27). Nothing here is part of the stable
|
|
6
|
+
* `@astryxdesign/cli/api`; each function and type may change or be removed in
|
|
7
|
+
* a patch release.
|
|
8
|
+
*
|
|
9
|
+
* @position api — the experimental entry beside api/index.mjs
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export {render} from './render/render.mjs';
|
|
13
|
+
|
|
14
|
+
// Types (runtime no-ops; tsc carries them into api/experimental.d.mts).
|
|
15
|
+
export * from './render/render.type.mjs';
|
package/api/hook/list/list.d.mts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
export function list({ cwd, category, detail, zh, lang, }?: {
|
|
14
14
|
cwd?: string | undefined;
|
|
15
15
|
category?: string | undefined;
|
|
16
|
-
detail?: "
|
|
16
|
+
detail?: "names" | "compact" | "full" | "brief" | undefined;
|
|
17
17
|
zh?: boolean | undefined;
|
|
18
18
|
lang?: string | null | undefined;
|
|
19
19
|
}): Promise<import("../hook.type.mjs").HookListResponse>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
|
-
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
3
|
+
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
|
4
4
|
import {spawnSync} from 'node:child_process';
|
|
5
5
|
import * as fs from 'node:fs';
|
|
6
6
|
import * as path from 'node:path';
|
|
@@ -123,4 +123,27 @@ describe('integrationPackCheck with lifecycle script output', () => {
|
|
|
123
123
|
expect(failure?.message).toContain('npm pack failed (exit 3)');
|
|
124
124
|
expect(failure?.message).toContain('prepack exploded');
|
|
125
125
|
});
|
|
126
|
+
|
|
127
|
+
it.skipIf(process.platform === 'win32')(
|
|
128
|
+
'packs with npm itself when an earlier npm on the PATH refuses every command',
|
|
129
|
+
async () => {
|
|
130
|
+
writeThemePackage({});
|
|
131
|
+
const refusing = path.join(tmpDir, '.refusing-bin');
|
|
132
|
+
fs.mkdirSync(refusing);
|
|
133
|
+
fs.writeFileSync(
|
|
134
|
+
path.join(refusing, 'npm'),
|
|
135
|
+
"#!/bin/sh\necho 'npm commands are not allowed on this machine'\nexit 1\n",
|
|
136
|
+
{mode: 0o755},
|
|
137
|
+
);
|
|
138
|
+
vi.stubEnv('PATH', `${refusing}${path.delimiter}${process.env.PATH}`);
|
|
139
|
+
try {
|
|
140
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
141
|
+
|
|
142
|
+
expect(result.data.issues).toEqual([]);
|
|
143
|
+
expect(result.data.packable).toBe(true);
|
|
144
|
+
} finally {
|
|
145
|
+
vi.unstubAllEnvs();
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
);
|
|
126
149
|
});
|
|
@@ -25,6 +25,7 @@ import * as os from 'node:os';
|
|
|
25
25
|
import {fileURLToPath} from 'node:url';
|
|
26
26
|
import {spawnSync} from 'node:child_process';
|
|
27
27
|
import {assertWithin} from '../../foundation/fs/path-safety.mjs';
|
|
28
|
+
import {npmCommand} from '../../foundation/release/cache.mjs';
|
|
28
29
|
import {commandTokensIn} from '../../foundation/doc-compiler/doc-syntax.mjs';
|
|
29
30
|
import {resolvePackageDir} from '../../foundation/integrations/integrations.mjs';
|
|
30
31
|
import {
|
|
@@ -265,17 +266,22 @@ function npmPackErrorDetail(output) {
|
|
|
265
266
|
/**
|
|
266
267
|
* Run `npm pack --json` with output directed to `destDir` so no preexisting
|
|
267
268
|
* tgz is overwritten. This intentionally runs the package lifecycle, matching
|
|
268
|
-
* the artifact `npm publish` would produce.
|
|
269
|
-
*
|
|
269
|
+
* the artifact `npm publish` would produce. npm starts the way the CLI starts
|
|
270
|
+
* it everywhere else (`npmCommand`): npm's own entry file run with this Node
|
|
271
|
+
* when one is found, so an `npm` earlier on the PATH that is not npm itself
|
|
272
|
+
* cannot answer for it. Uses spawnSync with an args array — no shell — so
|
|
273
|
+
* paths with metacharacters cannot inject.
|
|
270
274
|
*
|
|
271
275
|
* @param {string} packageDir
|
|
272
276
|
* @param {string} destDir
|
|
273
277
|
* @returns {{filename: string, fileCount: number, size: number, unpackedSize: number, packedPaths: Set<string>}}
|
|
274
278
|
*/
|
|
275
279
|
function runNpmPack(packageDir, destDir) {
|
|
280
|
+
const npm = npmCommand();
|
|
276
281
|
const result = spawnSync(
|
|
277
|
-
|
|
282
|
+
npm.command,
|
|
278
283
|
[
|
|
284
|
+
...npm.prefix,
|
|
279
285
|
'pack',
|
|
280
286
|
'--json',
|
|
281
287
|
'--silent',
|
|
@@ -284,7 +290,7 @@ function runNpmPack(packageDir, destDir) {
|
|
|
284
290
|
'--foreground-scripts=false',
|
|
285
291
|
`--pack-destination=${destDir}`,
|
|
286
292
|
],
|
|
287
|
-
{cwd: packageDir, encoding: 'utf-8', timeout: 60_000},
|
|
293
|
+
{cwd: packageDir, encoding: 'utf-8', shell: false, timeout: 60_000},
|
|
288
294
|
);
|
|
289
295
|
if (result.error) {
|
|
290
296
|
throw new Error(`Could not start npm pack: ${result.error.message}`);
|
|
@@ -2125,10 +2125,13 @@ describe('integrationPackCheck', () => {
|
|
|
2125
2125
|
).toThrow(/without a files array/);
|
|
2126
2126
|
});
|
|
2127
2127
|
|
|
2128
|
-
it('reports
|
|
2128
|
+
it('reports pack_failed when no npm can be found', async () => {
|
|
2129
2129
|
writePackage({files: ['astryx.integration.mjs', 'themes']});
|
|
2130
2130
|
const originalPath = process.env.PATH;
|
|
2131
|
+
const originalExecPath = process.execPath;
|
|
2131
2132
|
process.env.PATH = '';
|
|
2133
|
+
// A Node with no npm beside it, and no npm on the PATH.
|
|
2134
|
+
process.execPath = path.join(tmpDir, 'no-npm', 'bin', 'node');
|
|
2132
2135
|
try {
|
|
2133
2136
|
const result = await integrationPackCheck({cwd: tmpDir});
|
|
2134
2137
|
expect(result.data.packable).toBe(false);
|
|
@@ -2140,6 +2143,7 @@ describe('integrationPackCheck', () => {
|
|
|
2140
2143
|
);
|
|
2141
2144
|
} finally {
|
|
2142
2145
|
process.env.PATH = originalPath;
|
|
2146
|
+
process.execPath = originalExecPath;
|
|
2143
2147
|
}
|
|
2144
2148
|
});
|
|
2145
2149
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Render a page module to one HTML file and write it.
|
|
6
|
+
* @param {{cwd: string, input: string, output: string, title?: string}} args absolute paths
|
|
7
|
+
* @returns {Promise<import('./render.type.mjs').RenderPageResponse['data']>}
|
|
8
|
+
*/
|
|
9
|
+
export function renderToFile({ cwd, input, output, title }: {
|
|
10
|
+
cwd: string;
|
|
11
|
+
input: string;
|
|
12
|
+
output: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
}): Promise<import("./render.type.mjs").RenderPageResponse["data"]>;
|
|
15
|
+
/**
|
|
16
|
+
* Turn a rendered HTML file back into a page module.
|
|
17
|
+
* @param {{cwd: string, input: string, output: string | undefined, overwrite: boolean}} args absolute paths
|
|
18
|
+
* @returns {import('./render.type.mjs').RenderReverseResponse['data']}
|
|
19
|
+
*/
|
|
20
|
+
export function reverseToFile({ cwd, input, output, overwrite }: {
|
|
21
|
+
cwd: string;
|
|
22
|
+
input: string;
|
|
23
|
+
output: string | undefined;
|
|
24
|
+
overwrite: boolean;
|
|
25
|
+
}): import("./render.type.mjs").RenderReverseResponse["data"];
|
|
26
|
+
import { PAGE_EXTENSIONS } from '../../foundation/render/render-page.mjs';
|
|
27
|
+
import { embeddedPathProblem } from '../../foundation/render/embedded-files.mjs';
|
|
28
|
+
export { PAGE_EXTENSIONS, embeddedPathProblem };
|