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
package/dist/profiles.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pw profiles` (https://plans.inkylabs.com/pulpweaver#colour-and-prepress):
|
|
3
|
+
* the standard output intents' ICC profiles in pw's cache
|
|
4
|
+
* (`~/.cache/pulpweaver4/icc`), where `pw build` finds them. A shareable
|
|
5
|
+
* one is fetched from the ICC's registry, as a build would fetch it. One
|
|
6
|
+
* whose owner forbids redistribution but gives it to each user to download
|
|
7
|
+
* (FOGRA51's, `PSOcoated_v3.icc`, from ECI) is downloaded only here, from
|
|
8
|
+
* the owner's own file, after the user has read and accepted the owner's
|
|
9
|
+
* licence: the user downloads it, on their own machine, and pulpweaver4
|
|
10
|
+
* never hosts or ships it.
|
|
11
|
+
*/
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
13
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
14
|
+
import { homedir } from 'node:os';
|
|
15
|
+
import { dirname, join } from 'node:path';
|
|
16
|
+
import { createInterface } from 'node:readline/promises';
|
|
17
|
+
import { STANDARD_OUTPUT_INTENTS, ZipFS, } from 'pulpweaver4';
|
|
18
|
+
/** Where pw keeps what it fetches: `$XDG_CACHE_HOME/pulpweaver4`, else `~/.cache/pulpweaver4`. */
|
|
19
|
+
export function cacheDir(env = process.env) {
|
|
20
|
+
return join(env['XDG_CACHE_HOME'] || join(homedir(), '.cache'), 'pulpweaver4');
|
|
21
|
+
}
|
|
22
|
+
/** Where the cache keeps a profile's file. */
|
|
23
|
+
export function cachedProfilePath(file, env = process.env) {
|
|
24
|
+
if (!/^[\w.-]+$/.test(file))
|
|
25
|
+
throw new Error(`${file} isn't a profile's file name`);
|
|
26
|
+
return join(cacheDir(env), 'icc', file);
|
|
27
|
+
}
|
|
28
|
+
/** A profile's file from the cache, if it is there. */
|
|
29
|
+
export async function cachedProfile(file, env = process.env) {
|
|
30
|
+
const data = await readFile(cachedProfilePath(file, env)).catch(() => undefined);
|
|
31
|
+
return data && new Uint8Array(data);
|
|
32
|
+
}
|
|
33
|
+
async function cacheProfile(file, data, env) {
|
|
34
|
+
const cached = cachedProfilePath(file, env);
|
|
35
|
+
await mkdir(dirname(cached), { recursive: true });
|
|
36
|
+
const partial = `${cached}.${process.pid}.part`;
|
|
37
|
+
await writeFile(partial, data);
|
|
38
|
+
await rename(partial, cached);
|
|
39
|
+
return cached;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A shareable standard profile, from pw's cache or fetched from the ICC's
|
|
43
|
+
* registry into it. The core checks its hash, so a bad file in the cache
|
|
44
|
+
* fails the build rather than printing in the wrong colours.
|
|
45
|
+
*/
|
|
46
|
+
export async function standardProfile(url, file, env = process.env) {
|
|
47
|
+
const have = await cachedProfile(file, env);
|
|
48
|
+
if (have)
|
|
49
|
+
return have;
|
|
50
|
+
const res = await fetch(url);
|
|
51
|
+
if (!res.ok)
|
|
52
|
+
throw new Error(`${url}: ${res.status} ${res.statusText}`);
|
|
53
|
+
const data = new Uint8Array(await res.arrayBuffer());
|
|
54
|
+
await cacheProfile(file, data, env);
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
function sha256(data) {
|
|
58
|
+
return createHash('sha256').update(data).digest('hex');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Puts a standard output intent's profile in pw's cache, checked against
|
|
62
|
+
* its pinned SHA-256: from the ICC's registry if it may be shared, or, if
|
|
63
|
+
* its owner gives it to each user to download, from the owner's own zip
|
|
64
|
+
* once the user accepts the owner's licence. Returns the exit status: 0 when
|
|
65
|
+
* the profile is in the cache, 1 when it couldn't be put there or the user
|
|
66
|
+
* declined, 2 when no one was there to accept the licence.
|
|
67
|
+
*/
|
|
68
|
+
export async function getProfile(intent, options) {
|
|
69
|
+
const { out, env = process.env } = options;
|
|
70
|
+
const { profile } = intent;
|
|
71
|
+
if (!profile) {
|
|
72
|
+
out(`pw profiles: ${intent.name} needs no profile: the PDF writer has its own`);
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
const have = await cachedProfile(profile.file, env);
|
|
76
|
+
if (have && sha256(have) === profile.sha256) {
|
|
77
|
+
out(`pw profiles: ${intent.name}: ${cachedProfilePath(profile.file, env)} (already there)`);
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
const { download } = profile;
|
|
81
|
+
if (!profile.shareable && !download) {
|
|
82
|
+
out(`pw profiles: ${intent.name}'s profile, ${profile.file} (${profile.provider}), ${profile.terms}; download it from ${profile.url} into the project and set output-intent = "${profile.file}"`);
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
if (download) {
|
|
86
|
+
const accepted = await accept({ ...intent, profile: { ...profile, download } }, options);
|
|
87
|
+
if (accepted !== 0)
|
|
88
|
+
return accepted;
|
|
89
|
+
}
|
|
90
|
+
const from = download?.url ?? profile.url;
|
|
91
|
+
let data;
|
|
92
|
+
try {
|
|
93
|
+
data = download ? await fetchFromOwner(download, options.fetch ?? fetch) : await fetchFile(from, options.fetch ?? fetch);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
out(`pw profiles: ${intent.name}: ${e.message}`);
|
|
97
|
+
if (download)
|
|
98
|
+
out(`pw profiles: download it from ${download.page} into the project instead, and set output-intent = "${profile.file}"`);
|
|
99
|
+
return 1;
|
|
100
|
+
}
|
|
101
|
+
const sha = sha256(data);
|
|
102
|
+
if (sha !== profile.sha256) {
|
|
103
|
+
out(`pw profiles: ${intent.name}: ${from} gave a ${profile.file} that isn't the registered profile (its SHA-256 is ${sha}, not ${profile.sha256}), so it isn't kept`);
|
|
104
|
+
return 1;
|
|
105
|
+
}
|
|
106
|
+
out(`pw profiles: ${intent.name}: ${await cacheProfile(profile.file, data, env)}`);
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
/** Shows the owner's licence and asks the user to accept it, unless they did beforehand. */
|
|
110
|
+
async function accept(intent, options) {
|
|
111
|
+
const { out } = options;
|
|
112
|
+
const { profile } = intent;
|
|
113
|
+
const { download } = profile;
|
|
114
|
+
out(`${intent.name}'s profile, ${profile.file}, is ${download.owner}'s. pulpweaver4 may not ship it, but ${download.owner} lets you download it yourself, under this licence (its words, from the profile):`);
|
|
115
|
+
out('');
|
|
116
|
+
out(` ${download.licence}`);
|
|
117
|
+
out('');
|
|
118
|
+
out(`${download.owner}'s page for it: ${download.page}`);
|
|
119
|
+
out(`pw downloads ${download.url}, unpacks ${download.entry}, checks its SHA-256 and keeps it in ${dirname(cachedProfilePath(profile.file, options.env))}, for your builds alone.`);
|
|
120
|
+
if (options.accepted) {
|
|
121
|
+
out(`You accepted ${download.owner}'s licence (--accept-licence).`);
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
const answer = await options.ask?.(`Do you accept ${download.owner}'s licence? [y/N] `);
|
|
125
|
+
if (answer === undefined) {
|
|
126
|
+
out(`pw profiles: no one here to accept ${download.owner}'s licence; pass --accept-licence to accept it`);
|
|
127
|
+
return 2;
|
|
128
|
+
}
|
|
129
|
+
if (!/^\s*y(es)?\s*$/i.test(answer)) {
|
|
130
|
+
out(`pw profiles: not downloaded: you didn't accept ${download.owner}'s licence`);
|
|
131
|
+
return 1;
|
|
132
|
+
}
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
async function fetchFile(url, fetcher) {
|
|
136
|
+
const res = await fetcher(url);
|
|
137
|
+
if (!res.ok)
|
|
138
|
+
throw new Error(`${url}: ${res.status} ${res.statusText}`);
|
|
139
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
140
|
+
}
|
|
141
|
+
/** The profile, from the owner's own zip: never a redirect elsewhere. */
|
|
142
|
+
async function fetchFromOwner(download, fetcher) {
|
|
143
|
+
let res;
|
|
144
|
+
try {
|
|
145
|
+
res = await fetcher(download.url, { redirect: 'error' });
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
throw new Error(`${download.url}: ${e.message}${e.cause ? ` (${String(e.cause)})` : ''}`);
|
|
149
|
+
}
|
|
150
|
+
if (!res.ok)
|
|
151
|
+
throw new Error(`${download.url}: ${res.status} ${res.statusText}`);
|
|
152
|
+
let zip;
|
|
153
|
+
try {
|
|
154
|
+
zip = new ZipFS(new Uint8Array(await res.arrayBuffer()));
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
throw new Error(`${download.url} isn't a zip: ${e.message}`);
|
|
158
|
+
}
|
|
159
|
+
return zip.readFile(download.entry).catch(() => {
|
|
160
|
+
throw new Error(`${download.url} has no ${download.entry}`);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/** Asks on the terminal, if there is one. */
|
|
164
|
+
async function askTerminal(question) {
|
|
165
|
+
if (!process.stdin.isTTY)
|
|
166
|
+
return undefined;
|
|
167
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
168
|
+
try {
|
|
169
|
+
return await rl.question(question);
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
rl.close();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* `pw profiles get <name>… [--accept-licence]` and `pw profiles list`.
|
|
177
|
+
* `io` stands in for the terminal and the network in the tests.
|
|
178
|
+
*/
|
|
179
|
+
export async function profilesCommand(args, out, env, io = {}) {
|
|
180
|
+
const [sub, ...rest] = args;
|
|
181
|
+
const names = Object.keys(STANDARD_OUTPUT_INTENTS);
|
|
182
|
+
if (sub === 'list') {
|
|
183
|
+
for (const intent of Object.values(STANDARD_OUTPUT_INTENTS)) {
|
|
184
|
+
const { profile } = intent;
|
|
185
|
+
if (!profile) {
|
|
186
|
+
out(`${intent.name}: no profile needed`);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const have = await cachedProfile(profile.file, env);
|
|
190
|
+
const state = !have ? 'not in the cache' : sha256(have) === profile.sha256 ? cachedProfilePath(profile.file, env) : `${cachedProfilePath(profile.file, env)}, not the registered profile`;
|
|
191
|
+
const how = profile.shareable ? 'fetched when a build needs it' : profile.download ? `downloaded from ${profile.download.owner} by pw profiles get ${intent.name}` : 'downloaded by you';
|
|
192
|
+
out(`${intent.name}: ${profile.file} (${how}): ${state}`);
|
|
193
|
+
}
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
if (sub !== 'get') {
|
|
197
|
+
out(sub === undefined ? 'pw profiles: get <name>… or list' : `pw profiles: unknown command ${JSON.stringify(sub)}; get <name>… or list`);
|
|
198
|
+
return 2;
|
|
199
|
+
}
|
|
200
|
+
const accepted = rest.includes('--accept-licence') || rest.includes('--accept-license');
|
|
201
|
+
const unknownOption = rest.find((a) => a.startsWith('-') && a !== '--accept-licence' && a !== '--accept-license');
|
|
202
|
+
if (unknownOption !== undefined) {
|
|
203
|
+
out(`pw profiles get: unknown option ${unknownOption}`);
|
|
204
|
+
return 2;
|
|
205
|
+
}
|
|
206
|
+
const wanted = rest.filter((a) => !a.startsWith('-'));
|
|
207
|
+
if (!wanted.length) {
|
|
208
|
+
out(`pw profiles get: name an output intent: ${names.join(', ')}`);
|
|
209
|
+
return 2;
|
|
210
|
+
}
|
|
211
|
+
const unknown = wanted.find((n) => !Object.hasOwn(STANDARD_OUTPUT_INTENTS, n));
|
|
212
|
+
if (unknown !== undefined) {
|
|
213
|
+
const near = names.find((n) => n.toLowerCase() === unknown.toLowerCase());
|
|
214
|
+
out(`pw profiles get: no output intent ${JSON.stringify(unknown)}; ${near ? `did you mean ${near}?` : `one of ${names.join(', ')}`}`);
|
|
215
|
+
return 2;
|
|
216
|
+
}
|
|
217
|
+
let status = 0;
|
|
218
|
+
for (const name of wanted) {
|
|
219
|
+
const s = await getProfile(STANDARD_OUTPUT_INTENTS[name], { env, out, accepted, ask: io.ask ?? askTerminal, ...(io.fetch ? { fetch: io.fetch } : {}) });
|
|
220
|
+
status = Math.max(status, s);
|
|
221
|
+
}
|
|
222
|
+
return status;
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=profiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EACwC,uBAAuB,EAAmD,KAAK,GAC7H,MAAM,aAAa,CAAA;AAEpB,kGAAkG;AAClG,MAAM,UAAU,QAAQ,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG;IA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I,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA"}
|
package/dist/spike.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** `pw spike`: phase 0's spike page, laid out in headless Chromium (#8) and painted to PDF (#10). */
|
|
2
|
+
import type { LineSignature, PdfDateTime } from 'pulpweaver4';
|
|
3
|
+
import { type ChromiumHostOptions } from './chromium.js';
|
|
4
|
+
/** Lays the spike page out in headless Chromium and returns its signature. */
|
|
5
|
+
export declare function spikeSignature(opts: ChromiumHostOptions): Promise<LineSignature[]>;
|
|
6
|
+
/** How to write the spike page. */
|
|
7
|
+
export interface SpikePdfOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The bytes of GRACoL 2013's profile (`GRACoL2013_CRPC6.icc`): write our
|
|
10
|
+
* PDF as a CMYK edition for it, in PDF/X-4, instead of in sRGB.
|
|
11
|
+
*/
|
|
12
|
+
cmyk?: Uint8Array;
|
|
13
|
+
/**
|
|
14
|
+
* The PDF's date (`buildDate`): none in sRGB if absent, and for PDF/X,
|
|
15
|
+
* which needs one, `SPIKE_DATE`.
|
|
16
|
+
*/
|
|
17
|
+
date?: PdfDateTime;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The spike page as two PDFs: ours, painted and written by the core in the
|
|
21
|
+
* page, and Chromium's print-to-PDF of the same page, the test oracle
|
|
22
|
+
* (https://plans.inkylabs.com/pulpweaver#writing-pdfs).
|
|
23
|
+
*/
|
|
24
|
+
export declare function spikePdfs(opts: ChromiumHostOptions, pdf?: SpikePdfOptions): Promise<{
|
|
25
|
+
ours: Uint8Array;
|
|
26
|
+
chromium: Uint8Array;
|
|
27
|
+
}>;
|
package/dist/spike.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ChromiumHost } from './chromium.js';
|
|
2
|
+
/** Lays the spike page out in a host's page, with its font registered. */
|
|
3
|
+
async function layOut(host) {
|
|
4
|
+
await host.page.evaluate(async () => {
|
|
5
|
+
// The core, as the page loaded it (chromium.ts).
|
|
6
|
+
const pw = globalThis.pw;
|
|
7
|
+
const fonts = new pw.FontRegistry(await pw.Measurer.create());
|
|
8
|
+
const font = pw.SPIKE_FONT;
|
|
9
|
+
await fonts.add(font.family, await (await fetch(`/fonts/${font.file}`)).arrayBuffer(), { weight: font.weight });
|
|
10
|
+
document.body.replaceChildren();
|
|
11
|
+
const { page } = pw.renderSpikePage(document.body, fonts);
|
|
12
|
+
await page.querySelector('img')?.decode();
|
|
13
|
+
globalThis.spike = { page, fonts };
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** Lays the spike page out in headless Chromium and returns its signature. */
|
|
17
|
+
export async function spikeSignature(opts) {
|
|
18
|
+
const host = await ChromiumHost.launch(opts);
|
|
19
|
+
try {
|
|
20
|
+
await layOut(host);
|
|
21
|
+
return await host.page.evaluate(() => {
|
|
22
|
+
const pw = globalThis.pw;
|
|
23
|
+
const { page } = globalThis.spike;
|
|
24
|
+
return pw.pageSignature(page);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
await host.close();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The spike page as two PDFs: ours, painted and written by the core in the
|
|
33
|
+
* page, and Chromium's print-to-PDF of the same page, the test oracle
|
|
34
|
+
* (https://plans.inkylabs.com/pulpweaver#writing-pdfs).
|
|
35
|
+
*/
|
|
36
|
+
export async function spikePdfs(opts, pdf = {}) {
|
|
37
|
+
const host = await ChromiumHost.launch(opts);
|
|
38
|
+
try {
|
|
39
|
+
await layOut(host);
|
|
40
|
+
// The profile crosses into the page as base64, the cheapest form evaluate() carries.
|
|
41
|
+
const profile = pdf.cmyk ? Buffer.from(pdf.cmyk).toString('base64') : undefined;
|
|
42
|
+
const ours = await host.page.evaluate(async ({ profile, date }) => {
|
|
43
|
+
const pw = globalThis.pw;
|
|
44
|
+
const { page, fonts } = globalThis.spike;
|
|
45
|
+
await pw.initPdfWriter();
|
|
46
|
+
if (!profile) {
|
|
47
|
+
const doc = await pw.paintDocument([page], fonts);
|
|
48
|
+
doc.metadata = { ...doc.metadata, title: pw.SPIKE_TITLE, ...(date ? { creationDate: date } : {}) };
|
|
49
|
+
return [...pw.writePdf(doc)];
|
|
50
|
+
}
|
|
51
|
+
const bytes = Uint8Array.from(atob(profile), (c) => c.charCodeAt(0));
|
|
52
|
+
const doc = await pw.paintDocument([page], fonts, { colour: { cmyk: { profile: bytes } } });
|
|
53
|
+
pw.asPdfX(doc, {
|
|
54
|
+
outputIntent: { profile: bytes, ...pw.SPIKE_OUTPUT_CONDITION },
|
|
55
|
+
title: pw.SPIKE_TITLE,
|
|
56
|
+
creationDate: date ?? pw.SPIKE_DATE,
|
|
57
|
+
});
|
|
58
|
+
return [...pw.writePdf(doc)];
|
|
59
|
+
}, { profile, date: pdf.date });
|
|
60
|
+
// The page alone, at the paper's size, as Chromium prints it.
|
|
61
|
+
const { width, height } = await host.page.evaluate(() => {
|
|
62
|
+
const pw = globalThis.pw;
|
|
63
|
+
const style = document.createElement('style');
|
|
64
|
+
style.textContent = `@page { size: ${pw.SPIKE_GEOMETRY.width}px ${pw.SPIKE_GEOMETRY.height}px; margin: 0 }
|
|
65
|
+
html, body { margin: 0; padding: 0 }`;
|
|
66
|
+
document.head.append(style);
|
|
67
|
+
return pw.SPIKE_GEOMETRY;
|
|
68
|
+
});
|
|
69
|
+
const chromium = await host.page.pdf({
|
|
70
|
+
width: `${width}px`, height: `${height}px`, printBackground: true, preferCSSPageSize: true,
|
|
71
|
+
margin: { top: '0', right: '0', bottom: '0', left: '0' },
|
|
72
|
+
});
|
|
73
|
+
return { ours: new Uint8Array(ours), chromium: new Uint8Array(chromium) };
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await host.close();
|
|
77
|
+
}
|
|
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AO,CAAC,CAAA;YAC7C,KAAK,CAAC,WAAW,GAAG,iBAAiB,EAAE,CAAC,cAAc,CAAC,KAAK,MAAM,EAAE,CAAC,cAAc,CAAC,MAAM;6CACnD,CAAA;YACvC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAC3B,OAAO,EAAE,CAAC,cAAc,CAAA;QAC1B,CAAC,CAAC,CAAA;QACF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;YACnC,KAAK,EAAE,GAAG,KAAK,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI;YAC1F,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE;SACzD,CAAC,CAAA;QACF,OAAO,EAAE,IAAI,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAA;IAC3E,CAAC;YAAS,CAAC;QACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;AACH,CAAC"}
|
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type BrowserContext } from 'playwright';
|
|
2
|
+
import { type ChromiumHostOptions } from './chromium.js';
|
|
3
|
+
/** The tests `pw test` runs, from the project's folder. */
|
|
4
|
+
export declare const TEST_FILES: string[];
|
|
5
|
+
/**
|
|
6
|
+
* `pw test`'s arguments: the first plain one is the project's folder if it
|
|
7
|
+
* is one (has `pulpweaver4.toml`), and every other is a filter, as
|
|
8
|
+
* Vitest's are, so `pw test layout` in a project runs its layout tests
|
|
9
|
+
* (#101). `dir` is absent when none names a project: the current folder's.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseTestArgs(args: readonly string[], project?: (dir: string) => Promise<boolean>): Promise<{
|
|
12
|
+
dir?: string;
|
|
13
|
+
update: boolean;
|
|
14
|
+
filters: string[];
|
|
15
|
+
} | {
|
|
16
|
+
usage: string;
|
|
17
|
+
}>;
|
|
18
|
+
/** Whether a request is to this machine's loopback, where Vitest's server listens. */
|
|
19
|
+
export declare function isLoopback(url: URL): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Has Playwright fetch and fulfil the context's requests to loopback, out
|
|
22
|
+
* of reach of Chromium's network changes. A page so fulfilled has no
|
|
23
|
+
* address, and Chromium's Local Network Access checks would block its
|
|
24
|
+
* WebSockets to localhost (Vitest's own) without the permission.
|
|
25
|
+
*/
|
|
26
|
+
export declare function fetchLoopback(context: BrowserContext): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Runs the project's tests; returns whether they all passed. Vitest reports
|
|
29
|
+
* to the terminal as it does for any project.
|
|
30
|
+
*/
|
|
31
|
+
export declare function runTests(dir: string, options?: {
|
|
32
|
+
update?: boolean;
|
|
33
|
+
filters?: readonly string[];
|
|
34
|
+
}, host?: ChromiumHostOptions, env?: NodeJS.ProcessEnv): Promise<boolean>;
|
|
35
|
+
export declare function testCommand(args: readonly string[], out: (line: string) => void, host: ChromiumHostOptions, env: NodeJS.ProcessEnv): Promise<number>;
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pw test [<dir>] [<filter>…] [--update]` (https://plans.inkylabs.com/pulpweaver#testing):
|
|
3
|
+
* the project's tests, `tests/**\/*.test.ts`, run by Vitest in browser mode
|
|
4
|
+
* in the pinned Chromium, new headless, with the test API's globals and
|
|
5
|
+
* matchers, as the core's own tests run. `build()` builds the project
|
|
6
|
+
* (`page/test-setup.ts` reads it through the CLI), and snapshots are kept
|
|
7
|
+
* beside the tests; `--update` writes them anew.
|
|
8
|
+
*
|
|
9
|
+
* `pulpweaver4` and `pulpweaver4/test` are the CLI's own core, so a
|
|
10
|
+
* project needs nothing installed but `pw`.
|
|
11
|
+
*
|
|
12
|
+
* Chromium fails every request it has queued when the host's addresses
|
|
13
|
+
* change (`ERR_NETWORK_CHANGED`: an IPv6 router advertisement, a VPN, a
|
|
14
|
+
* container starting), its requests to Vitest's server on localhost too,
|
|
15
|
+
* and a test file then fails to import (#140). So Playwright fetches the
|
|
16
|
+
* page's requests to localhost and fulfils them, and they never reach
|
|
17
|
+
* Chromium's network stack (#141).
|
|
18
|
+
*/
|
|
19
|
+
import { stat } from 'node:fs/promises';
|
|
20
|
+
import { dirname, extname, join, resolve, sep } from 'node:path';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
import { playwright } from '@vitest/browser-playwright';
|
|
23
|
+
import { chromium } from 'playwright';
|
|
24
|
+
import { startVitest } from 'vitest/node';
|
|
25
|
+
import { bundlePlugin, projectCalls, sibling } from './bridge.js';
|
|
26
|
+
import { browserEnvironment, checkChromium, CHROMIUM, coreDependency, ChromiumError, PAGE_LOCALE, PAGE_TIME_ZONE } from './chromium.js';
|
|
27
|
+
/** The tests `pw test` runs, from the project's folder. */
|
|
28
|
+
export const TEST_FILES = ['tests/**/*.test.ts', 'tests/**/*.test.js'];
|
|
29
|
+
/** Whether a folder is a project's: it has `pulpweaver4.toml`. */
|
|
30
|
+
async function isProject(dir) {
|
|
31
|
+
return (await stat(join(resolve(dir), 'pulpweaver4.toml')).catch(() => undefined))?.isFile() ?? false;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `pw test`'s arguments: the first plain one is the project's folder if it
|
|
35
|
+
* is one (has `pulpweaver4.toml`), and every other is a filter, as
|
|
36
|
+
* Vitest's are, so `pw test layout` in a project runs its layout tests
|
|
37
|
+
* (#101). `dir` is absent when none names a project: the current folder's.
|
|
38
|
+
*/
|
|
39
|
+
export async function parseTestArgs(args, project = isProject) {
|
|
40
|
+
let update = false;
|
|
41
|
+
const plain = [];
|
|
42
|
+
for (const a of args) {
|
|
43
|
+
if (a === '--update' || a === '-u')
|
|
44
|
+
update = true;
|
|
45
|
+
else if (a.startsWith('-'))
|
|
46
|
+
return { usage: `unknown option ${a}` };
|
|
47
|
+
else
|
|
48
|
+
plain.push(a);
|
|
49
|
+
}
|
|
50
|
+
const dir = plain[0] !== undefined && (await project(plain[0])) ? plain.shift() : undefined;
|
|
51
|
+
return { ...(dir !== undefined ? { dir } : {}), update, filters: plain };
|
|
52
|
+
}
|
|
53
|
+
/** The core's modules as the tests import them: the given core's, the CLI's own by default. */
|
|
54
|
+
function coreAliases(coreEntry) {
|
|
55
|
+
const dir = dirname(coreEntry);
|
|
56
|
+
const ext = extname(coreEntry);
|
|
57
|
+
return [
|
|
58
|
+
{ find: /^pulpweaver4$/, replacement: coreEntry },
|
|
59
|
+
{ find: /^pulpweaver4\/test$/, replacement: join(dir, 'test', `index${ext}`) },
|
|
60
|
+
{ find: /^pulpweaver4\/test\/(runner|vitest)$/, replacement: join(dir, 'test', `$1${ext}`) },
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
/** The folders packages are installed in: each file's outermost `node_modules`, else its package's folder. */
|
|
64
|
+
function installed(files) {
|
|
65
|
+
return [...new Set(files.map((f) => {
|
|
66
|
+
const i = f.indexOf(`${sep}node_modules${sep}`);
|
|
67
|
+
return i >= 0 ? f.slice(0, i + `${sep}node_modules`.length) : dirname(dirname(f));
|
|
68
|
+
}))];
|
|
69
|
+
}
|
|
70
|
+
/** Where Vite serves the project's npm plugins (`page/test-setup.ts` imports them), out of the way of the project's own files. */
|
|
71
|
+
const NPM_PLUGINS = '/@pw-plugins/';
|
|
72
|
+
/** Serves the project's npm plugins, each bundled from `node_modules` as `pw build` bundles them; Vite resolves their imports of the core to the tests' own. */
|
|
73
|
+
function npmPlugins(dir) {
|
|
74
|
+
return {
|
|
75
|
+
name: 'pw-npm-plugins',
|
|
76
|
+
resolveId: (id) => (id.startsWith(NPM_PLUGINS) ? id : undefined),
|
|
77
|
+
async load(id) {
|
|
78
|
+
if (!id.startsWith(NPM_PLUGINS))
|
|
79
|
+
return undefined;
|
|
80
|
+
return bundlePlugin(dir, decodeURIComponent(id.slice(NPM_PLUGINS.length, -'.js'.length)));
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Whether a request is to this machine's loopback, where Vitest's server listens. */
|
|
85
|
+
export function isLoopback(url) {
|
|
86
|
+
return /^https?:$/.test(url.protocol) && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Has Playwright fetch and fulfil the context's requests to loopback, out
|
|
90
|
+
* of reach of Chromium's network changes. A page so fulfilled has no
|
|
91
|
+
* address, and Chromium's Local Network Access checks would block its
|
|
92
|
+
* WebSockets to localhost (Vitest's own) without the permission.
|
|
93
|
+
*/
|
|
94
|
+
export async function fetchLoopback(context) {
|
|
95
|
+
await context.grantPermissions(['local-network-access']);
|
|
96
|
+
await context.route(isLoopback, async (route) => {
|
|
97
|
+
let response;
|
|
98
|
+
// Playwright's own fetch can find a kept-alive connection the server has
|
|
99
|
+
// just closed (ECONNRESET); it is safe to ask again, as the browser would.
|
|
100
|
+
for (let attempt = 1; !response; attempt++) {
|
|
101
|
+
try {
|
|
102
|
+
response = await route.fetch();
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
if (attempt === 3)
|
|
106
|
+
return route.abort('failed').catch(() => { });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
await route.fulfill({ response }).catch(() => { });
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Vitest's Playwright provider, with {@link fetchLoopback} on each browser
|
|
114
|
+
* context it makes. Routes added later (Vitest's module mocks) come first.
|
|
115
|
+
*/
|
|
116
|
+
function provider(options) {
|
|
117
|
+
const base = playwright(options);
|
|
118
|
+
return {
|
|
119
|
+
...base,
|
|
120
|
+
providerFactory(project) {
|
|
121
|
+
const p = base.providerFactory(project);
|
|
122
|
+
// The one place it makes a context (and reuses it for a session).
|
|
123
|
+
const internal = p;
|
|
124
|
+
const create = internal.createContext.bind(p);
|
|
125
|
+
const routed = new WeakSet();
|
|
126
|
+
internal.createContext = async (...args) => {
|
|
127
|
+
const context = await create(...args);
|
|
128
|
+
if (!routed.has(context)) {
|
|
129
|
+
routed.add(context);
|
|
130
|
+
await fetchLoopback(context);
|
|
131
|
+
}
|
|
132
|
+
return context;
|
|
133
|
+
};
|
|
134
|
+
return p;
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** Checks the installed Chromium is the pinned one, as `ChromiumHost` does, before Vitest launches it. */
|
|
139
|
+
async function checkInstalledChromium(host) {
|
|
140
|
+
let browser;
|
|
141
|
+
try {
|
|
142
|
+
browser = await chromium.launch({ channel: 'chromium' });
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
if (e instanceof Error && /Executable doesn't exist/.test(e.message)) {
|
|
146
|
+
throw new ChromiumError(`Chromium ${CHROMIUM.version} isn't installed; install it with: npx playwright@${CHROMIUM.playwright} install chromium`);
|
|
147
|
+
}
|
|
148
|
+
throw e;
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
checkChromium(browser.version(), host);
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
await browser.close();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Runs the project's tests; returns whether they all passed. Vitest reports
|
|
159
|
+
* to the terminal as it does for any project.
|
|
160
|
+
*/
|
|
161
|
+
export async function runTests(dir, options = {}, host = {}, env = process.env) {
|
|
162
|
+
await checkInstalledChromium(host);
|
|
163
|
+
const coreEntry = host.coreEntry ?? fileURLToPath(import.meta.resolve('pulpweaver4'));
|
|
164
|
+
const setup = sibling('./page/test-setup');
|
|
165
|
+
const calls = projectCalls(dir, env, host.fetch);
|
|
166
|
+
const exitCode = process.exitCode;
|
|
167
|
+
const cli = {
|
|
168
|
+
root: dir,
|
|
169
|
+
// The project's own tests only, never a vitest.config the folder might have.
|
|
170
|
+
config: false,
|
|
171
|
+
run: true,
|
|
172
|
+
watch: false,
|
|
173
|
+
...(options.update ? { update: true } : {}),
|
|
174
|
+
};
|
|
175
|
+
const vite = {
|
|
176
|
+
// Vite's warnings are about pw's own packages (the dependencies Vitest pre-bundles, which it looks for in the
|
|
177
|
+
// project's folder), never the author's to act on.
|
|
178
|
+
logLevel: 'error',
|
|
179
|
+
// The core's own imports of `vitest` (`pulpweaver4/test/vitest`, its optional peer) are the CLI's Vitest, which npm
|
|
180
|
+
// may not have hoisted where the core can see it (a global install, pnpm; #103).
|
|
181
|
+
resolve: { alias: [...coreAliases(coreEntry), { find: /^vitest$/, replacement: fileURLToPath(import.meta.resolve('vitest')) }] },
|
|
182
|
+
plugins: [npmPlugins(dir)],
|
|
183
|
+
// The project, and the core, the CLI and the packages they load files from (HarfBuzz's WebAssembly), wherever npm put them.
|
|
184
|
+
server: { fs: { allow: [dir, ...installed([coreEntry, setup, coreDependency(coreEntry, 'harfbuzzjs')])] } },
|
|
185
|
+
test: {
|
|
186
|
+
include: TEST_FILES,
|
|
187
|
+
globals: true,
|
|
188
|
+
setupFiles: [setup],
|
|
189
|
+
// A book's build takes a while: a test's own time is its business.
|
|
190
|
+
testTimeout: 120_000,
|
|
191
|
+
hookTimeout: 120_000,
|
|
192
|
+
browser: {
|
|
193
|
+
enabled: true,
|
|
194
|
+
headless: true,
|
|
195
|
+
// The full browser in the new headless mode, in a fixed locale and time zone (chromium.ts), its requests
|
|
196
|
+
// to Vitest's server fetched by Playwright.
|
|
197
|
+
provider: provider({
|
|
198
|
+
launchOptions: { channel: 'chromium', args: [`--lang=${PAGE_LOCALE}`], env: browserEnvironment(env) },
|
|
199
|
+
contextOptions: { locale: PAGE_LOCALE, timezoneId: PAGE_TIME_ZONE },
|
|
200
|
+
}),
|
|
201
|
+
instances: [{ browser: 'chromium' }],
|
|
202
|
+
screenshotFailures: false,
|
|
203
|
+
commands: { pwHostCall: (_ctx, op, args) => calls(op, args) },
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
const vitest = await startVitest([...(options.filters ?? [])], cli, vite);
|
|
208
|
+
const passed = process.exitCode === undefined || process.exitCode === 0;
|
|
209
|
+
process.exitCode = exitCode;
|
|
210
|
+
await vitest.close();
|
|
211
|
+
return passed && vitest.state.getCountOfFailedTests() === 0;
|
|
212
|
+
}
|
|
213
|
+
export async function testCommand(args, out, host, env) {
|
|
214
|
+
const parsed = await parseTestArgs(args);
|
|
215
|
+
if ('usage' in parsed) {
|
|
216
|
+
out(`pw test: ${parsed.usage}`);
|
|
217
|
+
return 2;
|
|
218
|
+
}
|
|
219
|
+
if (parsed.dir === undefined && !(await isProject('.'))) {
|
|
220
|
+
const [first] = parsed.filters;
|
|
221
|
+
out(first === undefined
|
|
222
|
+
? 'pw test: . has no pulpweaver4.toml; run it in a project\'s folder, or start a project with pw new <dir>'
|
|
223
|
+
: `pw test: neither . nor ${first} has pulpweaver4.toml; run it in a project's folder, or name the folder first`);
|
|
224
|
+
return 2;
|
|
225
|
+
}
|
|
226
|
+
return (await runTests(resolve(parsed.dir ?? '.'), { update: parsed.update, filters: parsed.filters }, host, env)) ? 0 : 1;
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=test.js.map
|
package/dist/test.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EA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