pulpweaver4-cli 0.0.0-stage → 0.0.91
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/dist/bridge.d.ts +25 -0
- package/dist/bridge.js +109 -0
- package/dist/bridge.js.map +1 -0
- package/dist/build.d.ts +12 -0
- package/dist/build.js +95 -0
- package/dist/build.js.map +1 -0
- package/dist/chromium.d.ts +83 -0
- package/dist/chromium.js +213 -0
- package/dist/chromium.js.map +1 -0
- package/dist/commands.d.ts +217 -0
- package/dist/commands.js +162 -0
- package/dist/commands.js.map +1 -0
- package/dist/csl.d.ts +8 -0
- package/dist/csl.js +53 -0
- package/dist/csl.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +135 -0
- package/dist/index.js.map +1 -0
- package/dist/lint.d.ts +13 -0
- package/dist/lint.js +80 -0
- package/dist/lint.js.map +1 -0
- package/dist/new.d.ts +12 -0
- package/dist/new.js +92 -0
- package/dist/new.js.map +1 -0
- package/dist/node-fs.d.ts +17 -0
- package/dist/node-fs.js +78 -0
- package/dist/node-fs.js.map +1 -0
- package/dist/page/host.d.ts +111 -0
- package/dist/page/host.js +202 -0
- package/dist/page/host.js.map +1 -0
- package/dist/page/test-setup.d.ts +11 -0
- package/dist/page/test-setup.js +24 -0
- package/dist/page/test-setup.js.map +1 -0
- package/dist/paint-corpus.d.ts +8 -0
- package/dist/paint-corpus.js +89 -0
- package/dist/paint-corpus.js.map +1 -0
- package/dist/plugin-commands.d.ts +26 -0
- package/dist/plugin-commands.js +49 -0
- package/dist/plugin-commands.js.map +1 -0
- package/dist/plugins.d.ts +23 -0
- package/dist/plugins.js +85 -0
- package/dist/plugins.js.map +1 -0
- package/dist/problems.d.ts +29 -0
- package/dist/problems.js +28 -0
- package/dist/problems.js.map +1 -0
- package/dist/profiles.d.ts +37 -0
- package/dist/profiles.js +224 -0
- package/dist/profiles.js.map +1 -0
- package/dist/pw.d.ts +2 -0
- package/dist/pw.js +4 -0
- package/dist/pw.js.map +1 -0
- package/dist/spike.d.ts +27 -0
- package/dist/spike.js +79 -0
- package/dist/spike.js.map +1 -0
- package/dist/test.d.ts +35 -0
- package/dist/test.js +228 -0
- package/dist/test.js.map +1 -0
- package/docs/README.md +9 -0
- package/docs/reference/commands/build.md +40 -0
- package/docs/reference/commands/index.md +42 -0
- package/docs/reference/commands/lint.md +35 -0
- package/docs/reference/commands/new.md +34 -0
- package/docs/reference/commands/preflight.md +35 -0
- package/docs/reference/commands/profiles.md +57 -0
- package/docs/reference/commands/spike.md +30 -0
- package/docs/reference/commands/test.md +47 -0
- package/package.json +40 -4
- package/template/chapters/01-beginning.dj +14 -0
- package/template/chapters/02-writing.dj +16 -0
- package/template/fonts/CrimsonPro-Italic-VF.ttf +0 -0
- package/template/fonts/CrimsonPro-VF.ttf +0 -0
- package/template/fonts/NotoSansSymbols2-Boxes.ttf +0 -0
- package/template/fonts/OFL.txt +94 -0
- package/template/gitignore +2 -0
- package/template/pulpweaver4.toml +23 -0
- package/template/styles/book.css +109 -0
- package/template/tests/book.test.ts +23 -0
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,OAAO,EACL,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,GAC9D,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAoB,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAA4B,MAAM,eAAe,CAAA;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,kB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AC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,QAAQ,aAAa,EAAE,CAAC,CAAA;IACpH,OAAO,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACzC,CAAC"}
|
package/dist/lint.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ChromiumHostOptions } from './chromium.js';
|
|
2
|
+
import type { LintReport, LintRequest } from './page/host.js';
|
|
3
|
+
/** Lints the project in `dir` in the core's Chromium host: what `pw lint` prints and returns, without printing. */
|
|
4
|
+
export declare function lintProjectIn(dir: string, request: LintRequest, host?: ChromiumHostOptions, env?: NodeJS.ProcessEnv): Promise<LintReport>;
|
|
5
|
+
/** `pw lint`'s arguments: the project's folder, the edition and `--fix`. */
|
|
6
|
+
export declare function parseLintArgs(args: readonly string[]): {
|
|
7
|
+
dir: string;
|
|
8
|
+
edition?: string;
|
|
9
|
+
fix: boolean;
|
|
10
|
+
} | {
|
|
11
|
+
usage: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function lintCommand(args: readonly string[], out: (line: string) => void, host: ChromiumHostOptions, env: NodeJS.ProcessEnv): Promise<number>;
|
package/dist/lint.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pw lint [<dir>] [--fix] [--edition <name>]`
|
|
3
|
+
* (https://plans.inkylabs.com/pulpweaver#commands): the edition's lint
|
|
4
|
+
* rules, every level its settings turn on, run by the core in headless
|
|
5
|
+
* Chromium (`page/host.ts`'s `lint`), where the project's plugins load as
|
|
6
|
+
* `pw build` loads them and the book is built for the `html` and `layout`
|
|
7
|
+
* rules; with `--fix`, the source rules' fixes written back. Any error
|
|
8
|
+
* fails it.
|
|
9
|
+
*/
|
|
10
|
+
import { stat } from 'node:fs/promises';
|
|
11
|
+
import { join, resolve } from 'node:path';
|
|
12
|
+
import { hasErrors } from 'pulpweaver4';
|
|
13
|
+
import { exposeProject, PAGE_HOST_MODULE, pluginRoutes } from './bridge.js';
|
|
14
|
+
import { ChromiumHost } from './chromium.js';
|
|
15
|
+
import { printProblems } from './problems.js';
|
|
16
|
+
/** Lints the project in `dir` in the core's Chromium host: what `pw lint` prints and returns, without printing. */
|
|
17
|
+
export async function lintProjectIn(dir, request, host = {}, env = process.env) {
|
|
18
|
+
const chromium = await ChromiumHost.launch({ ...host, extra: { ...host.extra, host: PAGE_HOST_MODULE }, routes: pluginRoutes(dir) });
|
|
19
|
+
try {
|
|
20
|
+
await exposeProject(chromium.page, dir, env, host.fetch);
|
|
21
|
+
return await chromium.page.evaluate((req) => globalThis.pw.host.lint(req), request);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
await chromium.close();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** `pw lint`'s arguments: the project's folder, the edition and `--fix`. */
|
|
28
|
+
export function parseLintArgs(args) {
|
|
29
|
+
let dir;
|
|
30
|
+
let edition;
|
|
31
|
+
let fix = false;
|
|
32
|
+
for (let i = 0; i < args.length; i++) {
|
|
33
|
+
const a = args[i];
|
|
34
|
+
if (a === '--fix') {
|
|
35
|
+
fix = true;
|
|
36
|
+
}
|
|
37
|
+
else if (a === '--edition') {
|
|
38
|
+
edition = args[++i];
|
|
39
|
+
if (!edition)
|
|
40
|
+
return { usage: '--edition names an edition' };
|
|
41
|
+
}
|
|
42
|
+
else if (a.startsWith('--edition=')) {
|
|
43
|
+
edition = a.slice('--edition='.length);
|
|
44
|
+
}
|
|
45
|
+
else if (a.startsWith('-')) {
|
|
46
|
+
return { usage: `unknown option ${a}` };
|
|
47
|
+
}
|
|
48
|
+
else if (dir === undefined) {
|
|
49
|
+
dir = a;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return { usage: `one project at a time, not ${dir} and ${a}` };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { dir: dir ?? '.', fix, ...(edition !== undefined ? { edition } : {}) };
|
|
56
|
+
}
|
|
57
|
+
export async function lintCommand(args, out, host, env) {
|
|
58
|
+
const parsed = parseLintArgs(args);
|
|
59
|
+
if ('usage' in parsed) {
|
|
60
|
+
out(`pw lint: ${parsed.usage}`);
|
|
61
|
+
return 2;
|
|
62
|
+
}
|
|
63
|
+
const dir = resolve(parsed.dir);
|
|
64
|
+
if (!(await stat(join(dir, 'pulpweaver4.toml')).catch(() => undefined))) {
|
|
65
|
+
out(`pw lint: ${parsed.dir} has no pulpweaver4.toml; start a project there with pw new ${parsed.dir}`);
|
|
66
|
+
return 2;
|
|
67
|
+
}
|
|
68
|
+
const report = await lintProjectIn(dir, { fix: parsed.fix, ...(parsed.edition !== undefined ? { edition: parsed.edition } : {}) }, host, env);
|
|
69
|
+
if (report.unknown !== undefined) {
|
|
70
|
+
out(`pw lint: pulpweaver4.toml has no edition ${JSON.stringify(report.unknown)}`);
|
|
71
|
+
return 2;
|
|
72
|
+
}
|
|
73
|
+
if (report.fixed)
|
|
74
|
+
out(`pw lint: fixed ${report.fixed} problem${report.fixed === 1 ? '' : 's'} in ${report.changed.join(', ')}`);
|
|
75
|
+
printProblems(report.problems, new Map(Object.entries(report.sources)), out, { env });
|
|
76
|
+
if (!report.problems.length)
|
|
77
|
+
out('pw lint: no problems');
|
|
78
|
+
return hasErrors(report.problems) ? 1 : 0;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=lint.js.map
|
package/dist/lint.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAC3C,CAAC"}
|
package/dist/new.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The starter project, beside `dist/` in the package. */
|
|
2
|
+
export declare const TEMPLATE_DIR: string;
|
|
3
|
+
/** A book's title from its folder's name: `my-first-book` is “My First Book”. */
|
|
4
|
+
export declare function titleOf(dir: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Makes the starter project in `dir`, which must not exist or be empty,
|
|
7
|
+
* titled after the folder; returns the files made, as paths in it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function newProject(dir: string, options?: {
|
|
10
|
+
title?: string;
|
|
11
|
+
}): Promise<string[]>;
|
|
12
|
+
export declare function newCommand(args: readonly string[], out: (line: string) => void): Promise<number>;
|
package/dist/new.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pw new <dir> [--theme book]` (https://plans.inkylabs.com/pulpweaver#commands):
|
|
3
|
+
* a starter project, copied from the package's `template/`: a
|
|
4
|
+
* `pulpweaver4.toml` with a web, a paperback, a letter and a text edition, two
|
|
5
|
+
* chapters, a stylesheet, Crimson Pro (SIL Open Font License) in roman and
|
|
6
|
+
* italic with Noto Sans Symbols 2 (likewise) for the task list's boxes, and
|
|
7
|
+
* a test. Everything in it but the fonts is CC0, so the author
|
|
8
|
+
* may do anything with it. `book` is the one theme, and the default.
|
|
9
|
+
*/
|
|
10
|
+
import { cp, mkdir, readdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
11
|
+
import { basename, join, resolve } from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
/** The starter project, beside `dist/` in the package. */
|
|
14
|
+
export const TEMPLATE_DIR = fileURLToPath(new URL('../template/', import.meta.url));
|
|
15
|
+
/** The themes `--theme` takes. */
|
|
16
|
+
const THEMES = ['book'];
|
|
17
|
+
/** A book's title from its folder's name: `my-first-book` is “My First Book”. */
|
|
18
|
+
export function titleOf(dir) {
|
|
19
|
+
const words = basename(resolve(dir)).split(/[-_\s]+/).filter(Boolean);
|
|
20
|
+
return words.length ? words.map((w) => w[0].toUpperCase() + w.slice(1)).join(' ') : 'Untitled';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Makes the starter project in `dir`, which must not exist or be empty,
|
|
24
|
+
* titled after the folder; returns the files made, as paths in it.
|
|
25
|
+
*/
|
|
26
|
+
export async function newProject(dir, options = {}) {
|
|
27
|
+
const entries = await readdir(dir).catch((e) => {
|
|
28
|
+
if (e.code === 'ENOENT')
|
|
29
|
+
return [];
|
|
30
|
+
throw e;
|
|
31
|
+
});
|
|
32
|
+
if (entries.length)
|
|
33
|
+
throw new Error(`${dir} isn't empty`);
|
|
34
|
+
await mkdir(dir, { recursive: true });
|
|
35
|
+
await cp(TEMPLATE_DIR, dir, { recursive: true });
|
|
36
|
+
// npm leaves out a package's .gitignore, so the template's is gitignore.
|
|
37
|
+
await rename(join(dir, 'gitignore'), join(dir, '.gitignore'));
|
|
38
|
+
const config = join(dir, 'pulpweaver4.toml');
|
|
39
|
+
const title = (options.title ?? titleOf(dir)).replaceAll('\\', '\\\\').replaceAll('"', '\\"');
|
|
40
|
+
await writeFile(config, (await readFile(config, 'utf8')).replace('title = "Untitled"', `title = "${title}"`));
|
|
41
|
+
return list(dir);
|
|
42
|
+
}
|
|
43
|
+
async function list(dir, prefix = '') {
|
|
44
|
+
const out = [];
|
|
45
|
+
for (const e of (await readdir(join(dir, prefix), { withFileTypes: true })).sort((a, b) => (a.name < b.name ? -1 : 1))) {
|
|
46
|
+
const path = prefix ? `${prefix}/${e.name}` : e.name;
|
|
47
|
+
if (e.isDirectory())
|
|
48
|
+
out.push(...(await list(dir, path)));
|
|
49
|
+
else
|
|
50
|
+
out.push(path);
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
export async function newCommand(args, out) {
|
|
55
|
+
let dir;
|
|
56
|
+
let theme = 'book';
|
|
57
|
+
for (let i = 0; i < args.length; i++) {
|
|
58
|
+
const a = args[i];
|
|
59
|
+
if (a === '--theme')
|
|
60
|
+
theme = args[++i] ?? '';
|
|
61
|
+
else if (a.startsWith('--theme='))
|
|
62
|
+
theme = a.slice('--theme='.length);
|
|
63
|
+
else if (a.startsWith('-'))
|
|
64
|
+
return usage(out, `unknown option ${a}`);
|
|
65
|
+
else if (dir === undefined)
|
|
66
|
+
dir = a;
|
|
67
|
+
else
|
|
68
|
+
return usage(out, `one folder, not ${dir} and ${a}`);
|
|
69
|
+
}
|
|
70
|
+
if (dir === undefined)
|
|
71
|
+
return usage(out, 'name the folder to make the project in: pw new <dir>');
|
|
72
|
+
if (!THEMES.includes(theme))
|
|
73
|
+
return usage(out, `unknown theme ${JSON.stringify(theme)}; the themes are ${THEMES.join(', ')}`);
|
|
74
|
+
let files;
|
|
75
|
+
try {
|
|
76
|
+
files = await newProject(dir);
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
out(`pw new: ${e instanceof Error ? e.message : String(e)}`);
|
|
80
|
+
return 1;
|
|
81
|
+
}
|
|
82
|
+
out(`pw new: made ${dir}, with ${files.length} files:`);
|
|
83
|
+
for (const f of files)
|
|
84
|
+
out(` ${f}`);
|
|
85
|
+
out(`\nThen: cd ${dir}, and pw build, pw lint, pw test.`);
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
function usage(out, message) {
|
|
89
|
+
out(`pw new: ${message}`);
|
|
90
|
+
return 2;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=new.js.map
|
package/dist/new.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new.js","sourceRoot":"","sources":["../src/new.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,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S,CAAC,KAAK,CAAC,oBAAoB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACpJ,IAAI,KAAe,CAAA;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,CAAA;IAC/B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,GAAG,CAAC,WAAW,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QAC5D,OAAO,CAAC,CAAA;IACV,CAAC;IACD,GAAG,CAAC,gBAAgB,GAAG,UAAU,KAAK,CAAC,MAAM,SAAS,CAAC,CAAA;IACvD,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACpC,GAAG,CAAC,cAAc,GAAG,mCAAmC,CAAC,CAAA;IACzD,OAAO,CAAC,CAAA;AACV,CAAC;AAED,SAAS,KAAK,CAAC,GAA2B,EAAE,OAAe;IACzD,GAAG,CAAC,WAAW,OAAO,EAAE,CAAC,CAAA;IACzB,OAAO,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseVFS, type Entry, type Stat } from 'pulpweaver4';
|
|
2
|
+
/**
|
|
3
|
+
* A folder on disk as a file system. Paths can't climb out of it with `..`;
|
|
4
|
+
* a symbolic link inside it is followed wherever it points, as the author's
|
|
5
|
+
* own tools would.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NodeFS extends BaseVFS {
|
|
8
|
+
#private;
|
|
9
|
+
readonly root: string;
|
|
10
|
+
constructor(root: string);
|
|
11
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
12
|
+
writeFile(path: string, data: Uint8Array | string): Promise<void>;
|
|
13
|
+
readDir(path: string): Promise<Entry[]>;
|
|
14
|
+
stat(path: string): Promise<Stat>;
|
|
15
|
+
mkdir(path: string): Promise<void>;
|
|
16
|
+
remove(path: string): Promise<void>;
|
|
17
|
+
}
|
package/dist/node-fs.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** The core's virtual file system over `node:fs`: how the CLI hands it a project's folder. */
|
|
2
|
+
import { mkdir, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join as joinNative, resolve } from 'node:path';
|
|
4
|
+
import { BaseVFS, path as vfsPath, VFSError } from 'pulpweaver4';
|
|
5
|
+
const CODES = new Set(['ENOENT', 'EEXIST', 'ENOTDIR', 'EISDIR', 'EINVAL']);
|
|
6
|
+
/** Rethrows Node's errors with the codes the core knows as VFSErrors, with the project-relative path. */
|
|
7
|
+
function rethrow(e, path, override) {
|
|
8
|
+
const code = e?.code;
|
|
9
|
+
if (typeof code === 'string' && CODES.has(code)) {
|
|
10
|
+
throw new VFSError(override?.[code] ?? code, path);
|
|
11
|
+
}
|
|
12
|
+
throw e;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A folder on disk as a file system. Paths can't climb out of it with `..`;
|
|
16
|
+
* a symbolic link inside it is followed wherever it points, as the author's
|
|
17
|
+
* own tools would.
|
|
18
|
+
*/
|
|
19
|
+
export class NodeFS extends BaseVFS {
|
|
20
|
+
root;
|
|
21
|
+
constructor(root) {
|
|
22
|
+
super();
|
|
23
|
+
this.root = resolve(root);
|
|
24
|
+
}
|
|
25
|
+
async readFile(path) {
|
|
26
|
+
const buffer = await readFile(this.#native(path)).catch((e) => rethrow(e, path));
|
|
27
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
28
|
+
}
|
|
29
|
+
async writeFile(path, data) {
|
|
30
|
+
const parent = vfsPath.dirname(path);
|
|
31
|
+
if (vfsPath.normalize(path) === '')
|
|
32
|
+
throw new VFSError('EISDIR', path);
|
|
33
|
+
// mkdir -p reports a file in the way as EEXIST (or ENOTDIR); for a write it is ENOTDIR.
|
|
34
|
+
await mkdir(this.#native(parent), { recursive: true }).catch((e) => rethrow(e, path, { EEXIST: 'ENOTDIR' }));
|
|
35
|
+
await writeFile(this.#native(path), data).catch((e) => rethrow(e, path));
|
|
36
|
+
}
|
|
37
|
+
async readDir(path) {
|
|
38
|
+
const dirents = await readdir(this.#native(path), { withFileTypes: true }).catch((e) => rethrow(e, path));
|
|
39
|
+
const entries = [];
|
|
40
|
+
for (const d of dirents) {
|
|
41
|
+
// A symbolic link counts as what it points to; sockets and the like don't count.
|
|
42
|
+
const s = d.isSymbolicLink() ? await stat(joinNative(d.parentPath, d.name)).catch(() => undefined) : d;
|
|
43
|
+
if (s?.isFile())
|
|
44
|
+
entries.push({ name: d.name, kind: 'file' });
|
|
45
|
+
else if (s?.isDirectory())
|
|
46
|
+
entries.push({ name: d.name, kind: 'directory' });
|
|
47
|
+
}
|
|
48
|
+
return entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
49
|
+
}
|
|
50
|
+
async stat(path) {
|
|
51
|
+
const s = await stat(this.#native(path), { bigint: true }).catch((e) => rethrow(e, path));
|
|
52
|
+
if (s.isDirectory())
|
|
53
|
+
return { kind: 'directory', size: 0, token: '' };
|
|
54
|
+
// Nanoseconds and the inode, so a file replaced within the same millisecond still counts as changed.
|
|
55
|
+
return { kind: 'file', size: Number(s.size), mtime: Number(s.mtimeMs), token: `${s.mtimeNs}:${s.size}:${s.ino}` };
|
|
56
|
+
}
|
|
57
|
+
async mkdir(path) {
|
|
58
|
+
const native = this.#native(path);
|
|
59
|
+
await mkdir(native, { recursive: true }).catch((e) => rethrow(e, path));
|
|
60
|
+
// mkdir -p over a file passes on some systems; Node's own mkdir calls it EEXIST.
|
|
61
|
+
if (!(await stat(native)).isDirectory())
|
|
62
|
+
throw new VFSError('EEXIST', path);
|
|
63
|
+
}
|
|
64
|
+
async remove(path) {
|
|
65
|
+
if (vfsPath.normalize(path) === '')
|
|
66
|
+
throw new VFSError('EINVAL', path, 'cannot remove the root');
|
|
67
|
+
await rm(this.#native(path), { recursive: true, force: true }).catch((e) => {
|
|
68
|
+
// rm -rf of a path under a file: nothing there to remove.
|
|
69
|
+
if (e?.code !== 'ENOTDIR')
|
|
70
|
+
throw e;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** The native path of a project path, which normalize keeps inside the root. */
|
|
74
|
+
#native(path) {
|
|
75
|
+
return joinNative(this.root, ...vfsPath.split(path));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=node-fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-fs.js","sourceRoot":"","sources":["../src/node-fs.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAChF,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,QAAQ,EAA4C,MAAM,aAAa,CAAA;AAE1G,MAAM,KAAK,GAAG,IAAI,GAAG,CAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAA0B,CAAC,CAAA;AAE3G,yGAAyG;AACzG,SAAS,OAAO,CAAC,CAAU,EAAE,IAAY,EAAE,QAAsD;IAC/F,MAAM,IAAI,GAAI,CAA+B,EAAE,IAAI,CAAA;IACnD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAoB,CAAC,IAAK,IAAqB,EAAE,IAAI,CAAC,CAAA;IACtF,CAAC;IACD,MAAM,CAAC,CAAA;AACT,CAAC;AAED;;;;GA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,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;YAClF,0DAA0D;YAC1D,IAAK,CAA+B,EAAE,IAAI,KAAK,SAAS;gBAAE,MAAM,CAAC,CAAA;QACnE,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,gFAAgF;IAChF,OAAO,CAAC,IAAY;QAClB,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's side of `pw build` and `pw lint`: what runs in headless Chromium, bundled
|
|
3
|
+
* with the core (`ChromiumHost`'s `extra`, as `pw.host`). The project's
|
|
4
|
+
* folder is a VFS whose every call goes to the CLI in Node
|
|
5
|
+
* (`bridge.ts`, through Playwright's `exposeFunction`), so the core reads
|
|
6
|
+
* the author's files and writes `dist/` where they are, and plugins are
|
|
7
|
+
* imported from the CLI's server (`pluginImporter`), `pulpweaver4` in them
|
|
8
|
+
* resolved by the page's import map.
|
|
9
|
+
*/
|
|
10
|
+
import { BaseVFS, type Entry, type PluginImporter, type Problem, type Stat } from 'pulpweaver4';
|
|
11
|
+
/** A call to the CLI: its value, or the error it threw, as data. */
|
|
12
|
+
export type HostReply = {
|
|
13
|
+
value: unknown;
|
|
14
|
+
} | {
|
|
15
|
+
error: {
|
|
16
|
+
message: string;
|
|
17
|
+
code?: string;
|
|
18
|
+
path?: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
declare global {
|
|
22
|
+
/** Exposed by the CLI (`bridge.ts`). */
|
|
23
|
+
var pwHostCall: (op: string, args: unknown[]) => Promise<HostReply>;
|
|
24
|
+
}
|
|
25
|
+
/** Bytes as base64, and back, for the trip to Node and back. */
|
|
26
|
+
export declare function toBase64(data: Uint8Array): string;
|
|
27
|
+
/** The project's folder on the CLI's machine. */
|
|
28
|
+
export declare class HostFS extends BaseVFS {
|
|
29
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
30
|
+
writeFile(path: string, data: Uint8Array | string): Promise<void>;
|
|
31
|
+
readDir(path: string): Promise<Entry[]>;
|
|
32
|
+
stat(path: string): Promise<Stat>;
|
|
33
|
+
mkdir(path: string): Promise<void>;
|
|
34
|
+
remove(path: string): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The CSL project's styles and locales through the CLI, which keeps each in
|
|
38
|
+
* its cache once fetched (`csl.ts`), for `Project.fetchText`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function hostFetchText(url: string): Promise<string | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* How every pw host imports a project's plugins (#148, #151): a module in
|
|
43
|
+
* the project from its file, served at `<project><path>` (so its imports
|
|
44
|
+
* of `pulpweaver4` resolve to the host's core, and of `./` beside it to the
|
|
45
|
+
* project's files, as a browser's would from a server), and an npm package
|
|
46
|
+
* from the CLI's server, which bundles it from the project's `node_modules`
|
|
47
|
+
* and serves it at `<packages><name>.js`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function pluginImporter(urls: {
|
|
50
|
+
project: string;
|
|
51
|
+
packages: string;
|
|
52
|
+
}): PluginImporter;
|
|
53
|
+
/** `pw build`'s and `pw lint`'s, from `ChromiumHost`'s server (`pluginRoutes`). */
|
|
54
|
+
export declare const hostPluginImporter: PluginImporter;
|
|
55
|
+
export interface BuildRequest {
|
|
56
|
+
/** The editions to build, by name; all of them if absent. */
|
|
57
|
+
editions?: readonly string[];
|
|
58
|
+
/** `SOURCE_DATE_EPOCH`, the build's date when the project has none. */
|
|
59
|
+
sourceDateEpoch?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface BuildReport {
|
|
62
|
+
/**
|
|
63
|
+
* Every problem, the project's and each edition's, once: one found in
|
|
64
|
+
* some of several editions names them (`editions`).
|
|
65
|
+
*/
|
|
66
|
+
problems: Problem[];
|
|
67
|
+
/** The text of each file a problem is in, for showing its lines. */
|
|
68
|
+
sources: Record<string, string>;
|
|
69
|
+
/** What each edition wrote, under `dist/<edition>/`. */
|
|
70
|
+
editions: {
|
|
71
|
+
name: string;
|
|
72
|
+
files: readonly string[];
|
|
73
|
+
}[];
|
|
74
|
+
/** An edition named that the project doesn't have. */
|
|
75
|
+
unknown?: string;
|
|
76
|
+
/** Why nothing was built, if the environment is wrong: a bad `SOURCE_DATE_EPOCH`. */
|
|
77
|
+
refused?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Builds the project's editions into `dist/<edition>/`, each folder emptied
|
|
81
|
+
* first, as `pw build` does: the project and its plugins loaded, then each
|
|
82
|
+
* edition through `writeEdition`, every problem collected and the build
|
|
83
|
+
* going on past them. Nothing is built if the project's configuration or
|
|
84
|
+
* plugins have errors.
|
|
85
|
+
*/
|
|
86
|
+
export declare function buildProject(request: BuildRequest): Promise<BuildReport>;
|
|
87
|
+
export interface LintRequest {
|
|
88
|
+
/** The edition whose settings hold; the project's first, if absent. */
|
|
89
|
+
edition?: string;
|
|
90
|
+
/** Apply the source rules' fixes, and write the files they change. */
|
|
91
|
+
fix?: boolean;
|
|
92
|
+
}
|
|
93
|
+
export interface LintReport {
|
|
94
|
+
/** The project's problems, then what the rules report. */
|
|
95
|
+
problems: Problem[];
|
|
96
|
+
/** The text of each file a problem is in, for showing its lines. */
|
|
97
|
+
sources: Record<string, string>;
|
|
98
|
+
/** How many edits the fixes applied, and to which files. */
|
|
99
|
+
fixed: number;
|
|
100
|
+
changed: readonly string[];
|
|
101
|
+
/** An edition named that the project doesn't have. */
|
|
102
|
+
unknown?: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Lints the project as `pw lint [--fix]` does: the project and its plugins
|
|
106
|
+
* loaded as `pw build` loads them, then the edition's rules at every level
|
|
107
|
+
* its settings turn on (`lintProject`), the book built where an `html` or
|
|
108
|
+
* `layout` rule is on. Nothing is linted if the project's configuration or
|
|
109
|
+
* plugins have errors.
|
|
110
|
+
*/
|
|
111
|
+
export declare function lint(request: LintRequest): Promise<LintReport>;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's side of `pw build` and `pw lint`: what runs in headless Chromium, bundled
|
|
3
|
+
* with the core (`ChromiumHost`'s `extra`, as `pw.host`). The project's
|
|
4
|
+
* folder is a VFS whose every call goes to the CLI in Node
|
|
5
|
+
* (`bridge.ts`, through Playwright's `exposeFunction`), so the core reads
|
|
6
|
+
* the author's files and writes `dist/` where they are, and plugins are
|
|
7
|
+
* imported from the CLI's server (`pluginImporter`), `pulpweaver4` in them
|
|
8
|
+
* resolved by the page's import map.
|
|
9
|
+
*/
|
|
10
|
+
import { BaseVFS, buildDate, lintProject, OutputIntentError, epochMilliseconds, hasErrors, loadPlugins, loadProject, problemKey, subFS, TomlDocument, CONFIG_FILE, VFSError, writeEdition, } from 'pulpweaver4';
|
|
11
|
+
async function call(op, ...args) {
|
|
12
|
+
const reply = await globalThis.pwHostCall(op, args);
|
|
13
|
+
if ('value' in reply)
|
|
14
|
+
return reply.value;
|
|
15
|
+
const { code, path, message } = reply.error;
|
|
16
|
+
if (code !== undefined && path !== undefined)
|
|
17
|
+
throw new VFSError(code, path);
|
|
18
|
+
throw new Error(message);
|
|
19
|
+
}
|
|
20
|
+
/** Bytes as base64, and back, for the trip to Node and back. */
|
|
21
|
+
export function toBase64(data) {
|
|
22
|
+
let s = '';
|
|
23
|
+
for (let i = 0; i < data.length; i += 0x8000)
|
|
24
|
+
s += String.fromCharCode(...data.subarray(i, i + 0x8000));
|
|
25
|
+
return btoa(s);
|
|
26
|
+
}
|
|
27
|
+
function fromBase64(text) {
|
|
28
|
+
return Uint8Array.from(atob(text), (c) => c.charCodeAt(0));
|
|
29
|
+
}
|
|
30
|
+
/** The project's folder on the CLI's machine. */
|
|
31
|
+
export class HostFS extends BaseVFS {
|
|
32
|
+
async readFile(path) {
|
|
33
|
+
return fromBase64(await call('readFile', path));
|
|
34
|
+
}
|
|
35
|
+
async writeFile(path, data) {
|
|
36
|
+
await call('writeFile', path, typeof data === 'string' ? { text: data } : { base64: toBase64(data) });
|
|
37
|
+
}
|
|
38
|
+
readDir(path) {
|
|
39
|
+
return call('readDir', path);
|
|
40
|
+
}
|
|
41
|
+
stat(path) {
|
|
42
|
+
return call('stat', path);
|
|
43
|
+
}
|
|
44
|
+
async mkdir(path) {
|
|
45
|
+
await call('mkdir', path);
|
|
46
|
+
}
|
|
47
|
+
async remove(path) {
|
|
48
|
+
await call('remove', path);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The CSL project's styles and locales through the CLI, which keeps each in
|
|
53
|
+
* its cache once fetched (`csl.ts`), for `Project.fetchText`.
|
|
54
|
+
*/
|
|
55
|
+
export async function hostFetchText(url) {
|
|
56
|
+
return (await call('cslText', url)) ?? undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* How every pw host imports a project's plugins (#148, #151): a module in
|
|
60
|
+
* the project from its file, served at `<project><path>` (so its imports
|
|
61
|
+
* of `pulpweaver4` resolve to the host's core, and of `./` beside it to the
|
|
62
|
+
* project's files, as a browser's would from a server), and an npm package
|
|
63
|
+
* from the CLI's server, which bundles it from the project's `node_modules`
|
|
64
|
+
* and serves it at `<packages><name>.js`.
|
|
65
|
+
*/
|
|
66
|
+
export function pluginImporter(urls) {
|
|
67
|
+
return {
|
|
68
|
+
text: (_source, path) => import(/* @vite-ignore */ `${urls.project}${path.split('/').map(encodeURIComponent).join('/')}`),
|
|
69
|
+
package: (name) => import(/* @vite-ignore */ `${urls.packages}${encodeURIComponent(name)}.js`),
|
|
70
|
+
packageFile: (name, path) => call('packageFile', name, path),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** `pw build`'s and `pw lint`'s, from `ChromiumHost`'s server (`pluginRoutes`). */
|
|
74
|
+
export const hostPluginImporter = pluginImporter({ project: '/project/', packages: '/plugins/' });
|
|
75
|
+
/**
|
|
76
|
+
* Builds the project's editions into `dist/<edition>/`, each folder emptied
|
|
77
|
+
* first, as `pw build` does: the project and its plugins loaded, then each
|
|
78
|
+
* edition through `writeEdition`, every problem collected and the build
|
|
79
|
+
* going on past them. Nothing is built if the project's configuration or
|
|
80
|
+
* plugins have errors.
|
|
81
|
+
*/
|
|
82
|
+
export async function buildProject(request) {
|
|
83
|
+
const fs = new HostFS();
|
|
84
|
+
const problems = [];
|
|
85
|
+
const editions = [];
|
|
86
|
+
const loaded = await loadProject(fs, { fetchText: hostFetchText });
|
|
87
|
+
const report = async () => ({ problems, sources: await sourcesOf(loaded.fs, problems), editions });
|
|
88
|
+
problems.push(...loaded.problems);
|
|
89
|
+
if (!loaded.config)
|
|
90
|
+
return report();
|
|
91
|
+
let date;
|
|
92
|
+
try {
|
|
93
|
+
date = buildDate({ ...(loaded.config.date ? { date: loaded.config.date } : {}), ...(request.sourceDateEpoch !== undefined ? { sourceDateEpoch: request.sourceDateEpoch } : {}) });
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
if (!(e instanceof RangeError))
|
|
97
|
+
throw e;
|
|
98
|
+
return { ...(await report()), refused: e.message };
|
|
99
|
+
}
|
|
100
|
+
const withPlugins = await loadPlugins(loaded, { importer: hostPluginImporter, ...(date ? { now: epochMilliseconds(date) } : {}) });
|
|
101
|
+
problems.splice(0, problems.length, ...withPlugins.project.problems, ...withPlugins.problems);
|
|
102
|
+
const { project, registry } = withPlugins;
|
|
103
|
+
if (!project.config || hasErrors(problems))
|
|
104
|
+
return report();
|
|
105
|
+
const names = request.editions ?? Object.keys(project.config.editions);
|
|
106
|
+
const unknown = names.find((n) => !project.config.editions[n]);
|
|
107
|
+
if (unknown !== undefined)
|
|
108
|
+
return { ...(await report()), unknown };
|
|
109
|
+
const profiles = outputIntentHost();
|
|
110
|
+
// Each edition's problems, once each, with the editions that found it.
|
|
111
|
+
const found = new Map();
|
|
112
|
+
for (const name of names) {
|
|
113
|
+
const dir = `dist/${name}`;
|
|
114
|
+
await project.fs.remove(dir);
|
|
115
|
+
let result;
|
|
116
|
+
try {
|
|
117
|
+
result = await writeEdition(project, name, subFS(project.fs, dir), { registry, ...(date ? { date } : {}), outputIntents: profiles });
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
// An output the core doesn't write yet, say: the edition is left out, at its key.
|
|
121
|
+
const message = `the edition ${name} can't be built: ${e instanceof Error ? e.message : String(e)}`;
|
|
122
|
+
problems.push(TomlDocument.parse(project.configText, CONFIG_FILE).problem(['editions', name, 'output'], 'value', 'edition-failed', message));
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
editions.push({ name, files: result.files.map((f) => `${dir}/${f}`) });
|
|
126
|
+
// What the lint rules that see the built book find, but nothing the edition's build has said already.
|
|
127
|
+
const said = new Set(result.problems.map(key));
|
|
128
|
+
for (const p of [...result.problems, ...(await lintBuilt(project, registry, name, profiles)).filter((p) => !said.has(key(p)))]) {
|
|
129
|
+
const k = problemKey(p);
|
|
130
|
+
const entry = found.get(k) ?? found.set(k, { problem: p, editions: [] }).get(k);
|
|
131
|
+
if (!entry.editions.includes(name))
|
|
132
|
+
entry.editions.push(name);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const projectWide = new Set(problems.map(problemKey));
|
|
136
|
+
for (const [k, { problem, editions }] of found) {
|
|
137
|
+
if (projectWide.has(k))
|
|
138
|
+
continue;
|
|
139
|
+
// Found in every edition, it is the book's; in some of several, it names them.
|
|
140
|
+
problems.push(names.length > 1 && editions.length < names.length ? { ...problem, editions } : problem);
|
|
141
|
+
}
|
|
142
|
+
return report();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The standard profiles from the CLI's cache: a shareable one fetched into
|
|
146
|
+
* it as needed, and one its owner forbids redistributing only if the user
|
|
147
|
+
* downloaded it with `pw profiles get`, which a build never does for them.
|
|
148
|
+
*/
|
|
149
|
+
function outputIntentHost() {
|
|
150
|
+
return {
|
|
151
|
+
standardProfile: async (intent) => fromBase64(await call('standardProfile', intent.profile.url, intent.profile.file)),
|
|
152
|
+
downloadedProfile: async (intent) => {
|
|
153
|
+
const { file, download } = intent.profile;
|
|
154
|
+
const data = await call('downloadedProfile', file);
|
|
155
|
+
if (data !== null)
|
|
156
|
+
return fromBase64(data);
|
|
157
|
+
throw new OutputIntentError('profile-not-downloaded', `output-intent ${intent.name}: its profile, ${file}, is ${download.owner}'s, which pulpweaver4 may not ship, and it isn't in pw's cache: run pw profiles get ${intent.name} to download it from ${download.owner}`, `run pw profiles get ${intent.name}, which shows ${download.owner}'s licence and, once you accept it, downloads the profile; or download it from ${download.page} into the project and set output-intent = "${file}"`);
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const key = (p) => [p.file, p.line, p.column, p.message].join('\u0000');
|
|
162
|
+
/** The edition's lint rules, every level its settings turn on, as `pw lint` runs them (`lintProject`). */
|
|
163
|
+
async function lintBuilt(project, registry, name, profiles) {
|
|
164
|
+
return [...(await lintProject(project, { registry, edition: name, outputIntents: profiles })).problems];
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Lints the project as `pw lint [--fix]` does: the project and its plugins
|
|
168
|
+
* loaded as `pw build` loads them, then the edition's rules at every level
|
|
169
|
+
* its settings turn on (`lintProject`), the book built where an `html` or
|
|
170
|
+
* `layout` rule is on. Nothing is linted if the project's configuration or
|
|
171
|
+
* plugins have errors.
|
|
172
|
+
*/
|
|
173
|
+
export async function lint(request) {
|
|
174
|
+
const loaded = await loadProject(new HostFS(), { fetchText: hostFetchText });
|
|
175
|
+
const withPlugins = loaded.config ? await loadPlugins(loaded, { importer: hostPluginImporter }) : undefined;
|
|
176
|
+
const problems = withPlugins ? [...withPlugins.project.problems, ...withPlugins.problems] : [...loaded.problems];
|
|
177
|
+
const report = async (rest = {}) => ({ problems, sources: await sourcesOf(loaded.fs, problems), fixed: 0, changed: [], ...rest });
|
|
178
|
+
if (!withPlugins?.project.config || hasErrors(problems))
|
|
179
|
+
return report();
|
|
180
|
+
const { project, registry } = withPlugins;
|
|
181
|
+
if (request.edition !== undefined && !project.config.editions[request.edition])
|
|
182
|
+
return report({ unknown: request.edition });
|
|
183
|
+
const result = await lintProject(project, {
|
|
184
|
+
registry, outputIntents: outputIntentHost(), ...(request.edition !== undefined ? { edition: request.edition } : {}), ...(request.fix ? { fix: true } : {}),
|
|
185
|
+
});
|
|
186
|
+
problems.push(...result.problems);
|
|
187
|
+
return report({ fixed: result.fixed, changed: result.changed });
|
|
188
|
+
}
|
|
189
|
+
/** The text of each project file a problem is in. */
|
|
190
|
+
async function sourcesOf(fs, problems) {
|
|
191
|
+
const out = {};
|
|
192
|
+
for (const file of new Set(problems.map((p) => p.file))) {
|
|
193
|
+
if (!file)
|
|
194
|
+
continue;
|
|
195
|
+
try {
|
|
196
|
+
out[file] = await fs.readText(file);
|
|
197
|
+
}
|
|
198
|
+
catch { /* not a project file: the core's own stylesheet, say */ }
|
|
199
|
+
}
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=host.js.map
|