@vivliostyle/cli 9.0.1 → 9.0.2
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/{chunk-4Y2QIRBA.js → chunk-3WXABIMT.js} +7 -4
- package/dist/chunk-3WXABIMT.js.map +1 -0
- package/dist/{chunk-EX7EA34F.js → chunk-4IIM6RSG.js} +7 -0
- package/dist/chunk-4IIM6RSG.js.map +1 -0
- package/dist/{chunk-XRR6RKA6.js → chunk-FIAUNKIE.js} +7 -3
- package/dist/chunk-FIAUNKIE.js.map +1 -0
- package/dist/{chunk-WX6JHPSL.js → chunk-FXUEYQRY.js} +1 -0
- package/dist/chunk-FXUEYQRY.js.map +1 -0
- package/dist/{chunk-BIEQXUOY.js → chunk-I7BWSAN6.js} +1 -0
- package/dist/chunk-I7BWSAN6.js.map +1 -0
- package/dist/{chunk-QZWMJ4L2.js → chunk-JX7KVV6O.js} +11 -8
- package/dist/chunk-JX7KVV6O.js.map +1 -0
- package/dist/{chunk-PY4J4NG6.js → chunk-KSGAS7XH.js} +437 -1634
- package/dist/chunk-KSGAS7XH.js.map +1 -0
- package/dist/{chunk-FQMQ7BWY.js → chunk-MUCV2MI5.js} +7 -4
- package/dist/chunk-MUCV2MI5.js.map +1 -0
- package/dist/chunk-S2Q2FDUM.js +1138 -0
- package/dist/chunk-S2Q2FDUM.js.map +1 -0
- package/dist/{chunk-DMARNPN5.js → chunk-WFLNEE7C.js} +14 -0
- package/dist/chunk-WFLNEE7C.js.map +1 -0
- package/dist/{chunk-5AUWIYEK.js → chunk-WQC3S32F.js} +172 -35
- package/dist/chunk-WQC3S32F.js.map +1 -0
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -0
- package/dist/commands/build.js +9 -7
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/init.js +6 -6
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/preview.js +9 -7
- package/dist/commands/preview.js.map +1 -0
- package/dist/config/schema.d.ts +1650 -1650
- package/dist/config/schema.js +4 -2
- package/dist/config/schema.js.map +1 -0
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -0
- package/dist/node-modules.js +3 -2
- package/dist/node-modules.js.map +1 -0
- package/dist/vite-adapter.js +8 -6
- package/dist/vite-adapter.js.map +1 -0
- package/package.json +3 -1
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
+
importNodeModule
|
|
3
|
+
} from "./chunk-FXUEYQRY.js";
|
|
4
|
+
import {
|
|
5
|
+
DetailError,
|
|
6
|
+
Logger,
|
|
7
|
+
assertPubManifestSchema,
|
|
8
|
+
cwd,
|
|
9
|
+
getDefaultEpubOpfPath,
|
|
10
|
+
getEpubRootDir,
|
|
11
|
+
getFormattedError,
|
|
12
|
+
isInContainer,
|
|
13
|
+
isRunningOnWSL,
|
|
14
|
+
isValidUri,
|
|
15
|
+
openEpub,
|
|
16
|
+
parseJsonc,
|
|
17
|
+
pathContains,
|
|
18
|
+
pathEquals,
|
|
19
|
+
prettifySchemaError,
|
|
20
|
+
readJSON,
|
|
21
|
+
registerExitHandler,
|
|
22
|
+
runExitHandlers,
|
|
23
|
+
setupConfigFromFlags,
|
|
24
|
+
statFileSync,
|
|
25
|
+
touchTmpFile,
|
|
26
|
+
useTmpDirectory,
|
|
27
|
+
writeFileIfChanged
|
|
28
|
+
} from "./chunk-S2Q2FDUM.js";
|
|
29
|
+
import {
|
|
30
|
+
VivliostyleConfigSchema
|
|
31
|
+
} from "./chunk-WFLNEE7C.js";
|
|
32
|
+
import {
|
|
33
|
+
CONTAINER_LOCAL_HOSTNAME,
|
|
34
|
+
CONTAINER_URL,
|
|
2
35
|
COVER_HTML_FILENAME,
|
|
3
36
|
COVER_HTML_IMAGE_ALT,
|
|
4
37
|
EMPTY_DATA_URI,
|
|
@@ -15,1117 +48,27 @@ import {
|
|
|
15
48
|
XML_DECLARATION,
|
|
16
49
|
cliVersion,
|
|
17
50
|
viewerRoot
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import {
|
|
20
|
-
importNodeModule
|
|
21
|
-
} from "./chunk-WX6JHPSL.js";
|
|
22
|
-
import {
|
|
23
|
-
VivliostyleConfigSchema,
|
|
24
|
-
VivliostyleInlineConfig
|
|
25
|
-
} from "./chunk-DMARNPN5.js";
|
|
51
|
+
} from "./chunk-4IIM6RSG.js";
|
|
26
52
|
import {
|
|
27
53
|
__callDispose,
|
|
28
54
|
__using
|
|
29
|
-
} from "./chunk-
|
|
30
|
-
|
|
31
|
-
// src/util.ts
|
|
32
|
-
import { codeFrameColumns } from "@babel/code-frame";
|
|
33
|
-
import {
|
|
34
|
-
evaluate,
|
|
35
|
-
parse
|
|
36
|
-
} from "@humanwhocodes/momoa";
|
|
37
|
-
import { Ajv } from "ajv";
|
|
38
|
-
import formatsPlugin from "ajv-formats";
|
|
39
|
-
import { XMLParser } from "fast-xml-parser";
|
|
40
|
-
import StreamZip from "node-stream-zip";
|
|
41
|
-
import fs from "node:fs";
|
|
42
|
-
import readline from "node:readline";
|
|
43
|
-
import util from "node:util";
|
|
44
|
-
import tmp from "tmp";
|
|
45
|
-
import upath from "upath";
|
|
46
|
-
import { gray as gray2, red, redBright as redBright2 } from "yoctocolors";
|
|
47
|
-
|
|
48
|
-
// src/logger.ts
|
|
49
|
-
import debug from "debug";
|
|
50
|
-
import yoctoSpinner from "yocto-spinner";
|
|
51
|
-
import {
|
|
52
|
-
blueBright,
|
|
53
|
-
gray,
|
|
54
|
-
greenBright,
|
|
55
|
-
redBright,
|
|
56
|
-
yellowBright
|
|
57
|
-
} from "yoctocolors";
|
|
58
|
-
var isUnicodeSupported = process.platform !== "win32" || Boolean(process.env.WT_SESSION);
|
|
59
|
-
var randomBookSymbol = ["\u{1F4D5}", "\u{1F4D7}", "\u{1F4D8}", "\u{1F4D9}"][Math.floor(Math.random() * 4)];
|
|
60
|
-
var infoSymbol = blueBright("INFO");
|
|
61
|
-
var successSymbol = greenBright("SUCCESS");
|
|
62
|
-
var warnSymbol = yellowBright("WARN");
|
|
63
|
-
var errorSymbol = redBright("ERROR");
|
|
64
|
-
var Logger = class _Logger {
|
|
65
|
-
/**
|
|
66
|
-
* 0: silent 1: info 2: verbose 3: debug
|
|
67
|
-
*/
|
|
68
|
-
static #logLevel = 0;
|
|
69
|
-
static #loggerInstance;
|
|
70
|
-
static #nonBlockingLogPrinted = false;
|
|
71
|
-
static #customLogger;
|
|
72
|
-
static debug = debug("vs-cli");
|
|
73
|
-
static get #spinner() {
|
|
74
|
-
return this.#loggerInstance && this.#loggerInstance.#_spinner;
|
|
75
|
-
}
|
|
76
|
-
static get isInteractive() {
|
|
77
|
-
return Boolean(
|
|
78
|
-
!this.#customLogger && process.stderr.isTTY && process.env.TERM !== "dumb" && !("CI" in process.env) && !import.meta.env?.VITEST && !debug.enabled("vs-cli") && // Prevent stream output in docker container so that not to spawn process
|
|
79
|
-
!isInContainer()
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
static startLogging(text) {
|
|
83
|
-
if (this.#logLevel === 0) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
if (!this.isInteractive) {
|
|
87
|
-
this.logInfo(text);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (this.#loggerInstance) {
|
|
91
|
-
this.#loggerInstance.#_spinner.text = text;
|
|
92
|
-
return this.#loggerInstance;
|
|
93
|
-
}
|
|
94
|
-
this.#loggerInstance = new _Logger();
|
|
95
|
-
this.#loggerInstance.#_spinner.start(text);
|
|
96
|
-
return this.#loggerInstance;
|
|
97
|
-
}
|
|
98
|
-
static suspendLogging(text) {
|
|
99
|
-
if (this.#logLevel === 0) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (!this.#spinner || !this.isInteractive) {
|
|
103
|
-
this.logInfo(text);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const currentMsg = this.#spinner?.text;
|
|
107
|
-
this.logUpdate(currentMsg);
|
|
108
|
-
this.#spinner.stop(`${infoSymbol} ${text}
|
|
109
|
-
`);
|
|
110
|
-
return {
|
|
111
|
-
[Symbol.dispose]() {
|
|
112
|
-
if (_Logger.isInteractive) {
|
|
113
|
-
console.log("");
|
|
114
|
-
_Logger.#spinner?.start(currentMsg);
|
|
115
|
-
_Logger.#nonBlockingLogPrinted = true;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
static log(...messages) {
|
|
121
|
-
if (this.#logLevel < 1) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
console.log(...messages);
|
|
125
|
-
}
|
|
126
|
-
static logUpdate(...messages) {
|
|
127
|
-
if (!this.#spinner || !this.isInteractive) {
|
|
128
|
-
this.logInfo(...messages);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
this.#spinner.stop(
|
|
132
|
-
this.#nonBlockingLogPrinted ? void 0 : `${infoSymbol} ${this.#spinner.text}`
|
|
133
|
-
);
|
|
134
|
-
this.#spinner.start(messages.join(" "));
|
|
135
|
-
this.#nonBlockingLogPrinted = false;
|
|
136
|
-
}
|
|
137
|
-
static getMessage(message, symbol) {
|
|
138
|
-
return !this.#customLogger && symbol ? `${symbol} ${message}` : message;
|
|
139
|
-
}
|
|
140
|
-
static #nonBlockingLog(logMethod, message) {
|
|
141
|
-
if (!this.#spinner || !this.isInteractive) {
|
|
142
|
-
if (isInContainer()) {
|
|
143
|
-
message = `${gray("[Docker]")} ${message}`;
|
|
144
|
-
}
|
|
145
|
-
this.#logLevel >= 3 ? this.debug(message) : (this.#customLogger || console)[logMethod](message);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
this.logUpdate(this.#spinner.text);
|
|
149
|
-
this.#nonBlockingLogPrinted = true;
|
|
150
|
-
this.#spinner.stop(message);
|
|
151
|
-
this.#spinner.start();
|
|
152
|
-
}
|
|
153
|
-
static logSuccess(...messages) {
|
|
154
|
-
if (this.#logLevel < 1) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
this.#nonBlockingLog(
|
|
158
|
-
"info",
|
|
159
|
-
this.getMessage(messages.join(" "), successSymbol)
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
static logError(...messages) {
|
|
163
|
-
if (this.#logLevel < 1) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
this.#nonBlockingLog(
|
|
167
|
-
"error",
|
|
168
|
-
this.getMessage(messages.join(" "), errorSymbol)
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
static logWarn(...messages) {
|
|
172
|
-
if (this.#logLevel < 1) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
this.#nonBlockingLog(
|
|
176
|
-
"warn",
|
|
177
|
-
this.getMessage(messages.join(" "), warnSymbol)
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
static logInfo(...messages) {
|
|
181
|
-
if (this.#logLevel < 1) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
this.#nonBlockingLog(
|
|
185
|
-
"info",
|
|
186
|
-
this.getMessage(messages.join(" "), infoSymbol)
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
static logVerbose(...messages) {
|
|
190
|
-
if (this.#logLevel < 2) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
this.#nonBlockingLog("info", this.getMessage(messages.join(" ")));
|
|
194
|
-
}
|
|
195
|
-
static setLogLevel(level) {
|
|
196
|
-
if (!level) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
this.#logLevel = {
|
|
200
|
-
silent: 0,
|
|
201
|
-
info: 1,
|
|
202
|
-
verbose: 2,
|
|
203
|
-
debug: 3
|
|
204
|
-
}[level];
|
|
205
|
-
if (this.#logLevel >= 3) {
|
|
206
|
-
debug.enable("vs-cli");
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
static setCustomLogger(logger) {
|
|
210
|
-
this.#customLogger = logger;
|
|
211
|
-
}
|
|
212
|
-
#_spinner;
|
|
213
|
-
constructor() {
|
|
214
|
-
this.#_spinner = yoctoSpinner({
|
|
215
|
-
spinner: {
|
|
216
|
-
frames: isUnicodeSupported ? ["\u2581\u2581\u2571 ", "\u2581\u2551\u2581 ", "\u2572\u2581\u2581 ", "\u2581\u2581\u2581 ", "\u2581\u2581\u2581 ", "\u2581\u2581\u2581 "] : ["- ", "\\ ", "| ", "/ "],
|
|
217
|
-
interval: 80
|
|
218
|
-
},
|
|
219
|
-
color: "gray"
|
|
220
|
-
});
|
|
221
|
-
return this;
|
|
222
|
-
}
|
|
223
|
-
[Symbol.dispose]() {
|
|
224
|
-
this.#_spinner.stop(
|
|
225
|
-
_Logger.#nonBlockingLogPrinted ? void 0 : `${infoSymbol} ${this.#_spinner.text}`
|
|
226
|
-
);
|
|
227
|
-
_Logger.#loggerInstance = void 0;
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
// schemas/pub-manifest/module/bcp.schema.json
|
|
232
|
-
var bcp_schema_default = {
|
|
233
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
234
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/bcp.schema.json",
|
|
235
|
-
title: "BCP47 Language tag",
|
|
236
|
-
type: "string",
|
|
237
|
-
pattern: "^((?:(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?:([A-Za-z]{2,3}(-(?:[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?:[A-Za-z]{4}))?(-(?:[A-Za-z]{2}|[0-9]{3}))?(-(?:[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?:[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?:x(-[A-Za-z0-9]{1,8})+))?)|(?:x(-[A-Za-z0-9]{1,8})+))$"
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
// schemas/pub-manifest/module/context.schema.json
|
|
241
|
-
var context_schema_default = {
|
|
242
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
243
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/context.schema.json",
|
|
244
|
-
title: "Publication Contexts",
|
|
245
|
-
type: "array",
|
|
246
|
-
items: [
|
|
247
|
-
{
|
|
248
|
-
const: "https://schema.org"
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
const: "https://www.w3.org/ns/pub-context"
|
|
252
|
-
}
|
|
253
|
-
],
|
|
254
|
-
additionalItems: {
|
|
255
|
-
anyOf: [
|
|
256
|
-
{
|
|
257
|
-
type: "string"
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
type: "object",
|
|
261
|
-
properties: {
|
|
262
|
-
language: {
|
|
263
|
-
$ref: "bcp.schema.json"
|
|
264
|
-
},
|
|
265
|
-
direction: false
|
|
266
|
-
},
|
|
267
|
-
required: ["language"]
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
type: "object",
|
|
271
|
-
properties: {
|
|
272
|
-
direction: {
|
|
273
|
-
type: "string",
|
|
274
|
-
enum: ["ltr", "rtl"]
|
|
275
|
-
},
|
|
276
|
-
language: false
|
|
277
|
-
},
|
|
278
|
-
required: ["direction"]
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
type: "object",
|
|
282
|
-
properties: {
|
|
283
|
-
language: {
|
|
284
|
-
$ref: "bcp.schema.json"
|
|
285
|
-
},
|
|
286
|
-
direction: {
|
|
287
|
-
type: "string",
|
|
288
|
-
enum: ["ltr", "rtl"]
|
|
289
|
-
}
|
|
290
|
-
},
|
|
291
|
-
required: ["language", "direction"]
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
type: "object",
|
|
295
|
-
properties: {
|
|
296
|
-
language: false,
|
|
297
|
-
direction: false
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
]
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
// schemas/pub-manifest/module/contributor-object.schema.json
|
|
305
|
-
var contributor_object_schema_default = {
|
|
306
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
307
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/contributor-object.schema.json",
|
|
308
|
-
title: "Contributor Object",
|
|
309
|
-
type: "object",
|
|
310
|
-
properties: {
|
|
311
|
-
name: {
|
|
312
|
-
$ref: "localizable.schema.json"
|
|
313
|
-
},
|
|
314
|
-
id: {
|
|
315
|
-
$ref: "url.schema.json"
|
|
316
|
-
},
|
|
317
|
-
type: {
|
|
318
|
-
oneOf: [
|
|
319
|
-
{
|
|
320
|
-
type: "string",
|
|
321
|
-
enum: ["Person", "Organization"],
|
|
322
|
-
default: "Person"
|
|
323
|
-
},
|
|
324
|
-
{
|
|
325
|
-
type: "array",
|
|
326
|
-
items: {
|
|
327
|
-
type: "string"
|
|
328
|
-
},
|
|
329
|
-
contains: {
|
|
330
|
-
enum: ["Person", "Organization"]
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
]
|
|
334
|
-
},
|
|
335
|
-
url: {
|
|
336
|
-
$ref: "url.schema.json"
|
|
337
|
-
},
|
|
338
|
-
identifier: {
|
|
339
|
-
type: "array",
|
|
340
|
-
items: {
|
|
341
|
-
type: "string"
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
},
|
|
345
|
-
required: ["name"]
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
// schemas/pub-manifest/module/contributor.schema.json
|
|
349
|
-
var contributor_schema_default = {
|
|
350
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
351
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/contributor.schema.json",
|
|
352
|
-
title: "Contributor",
|
|
353
|
-
anyOf: [
|
|
354
|
-
{
|
|
355
|
-
type: "string"
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
type: "array",
|
|
359
|
-
items: {
|
|
360
|
-
anyOf: [
|
|
361
|
-
{
|
|
362
|
-
type: "string"
|
|
363
|
-
},
|
|
364
|
-
{
|
|
365
|
-
$ref: "contributor-object.schema.json"
|
|
366
|
-
}
|
|
367
|
-
]
|
|
368
|
-
}
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
$ref: "contributor-object.schema.json"
|
|
372
|
-
}
|
|
373
|
-
]
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
// schemas/pub-manifest/module/date.schema.json
|
|
377
|
-
var date_schema_default = {
|
|
378
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
379
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/date.schema.json",
|
|
380
|
-
title: "Dates",
|
|
381
|
-
type: "string",
|
|
382
|
-
format: "date-time"
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
// schemas/pub-manifest/module/duration.schema.json
|
|
386
|
-
var duration_schema_default = {
|
|
387
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
388
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/duration.schema.json",
|
|
389
|
-
title: "Duration",
|
|
390
|
-
type: "string",
|
|
391
|
-
pattern: "^P(?!$)((\\d+Y)|(\\d+\\.\\d+Y$))?((\\d+M)|(\\d+\\.\\d+M$))?((\\d+W)|(\\d+\\.\\d+W$))?((\\d+D)|(\\d+\\.\\d+D$))?(T(?=\\d)((\\d+H)|(\\d+\\.\\d+H$))?((\\d+M)|(\\d+\\.\\d+M$))?(\\d+(\\.\\d+)?S)?)??$"
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
// schemas/pub-manifest/module/item-lists.schema.json
|
|
395
|
-
var item_lists_schema_default = {
|
|
396
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
397
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/item-lists.schema.json",
|
|
398
|
-
title: "Lists of ItemList",
|
|
399
|
-
oneOf: [
|
|
400
|
-
{
|
|
401
|
-
$ref: "ItemList.schema.json"
|
|
402
|
-
},
|
|
403
|
-
{
|
|
404
|
-
type: "array",
|
|
405
|
-
items: {
|
|
406
|
-
$ref: "ItemList.schema.json"
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
]
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
// schemas/pub-manifest/module/ItemList.schema.json
|
|
413
|
-
var ItemList_schema_default = {
|
|
414
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
415
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/ItemList.schema.json",
|
|
416
|
-
title: "schema.org ItemList object",
|
|
417
|
-
type: "object",
|
|
418
|
-
properties: {
|
|
419
|
-
type: {
|
|
420
|
-
oneOf: [
|
|
421
|
-
{
|
|
422
|
-
type: "string",
|
|
423
|
-
const: "ItemList"
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
type: "array",
|
|
427
|
-
items: {
|
|
428
|
-
type: "string"
|
|
429
|
-
},
|
|
430
|
-
contains: {
|
|
431
|
-
const: "ItemList"
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
]
|
|
435
|
-
},
|
|
436
|
-
itemListElement: {
|
|
437
|
-
type: ["array"],
|
|
438
|
-
items: {
|
|
439
|
-
type: "string"
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
},
|
|
443
|
-
required: ["type", "itemListElement"]
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
// schemas/pub-manifest/module/language.schema.json
|
|
447
|
-
var language_schema_default = {
|
|
448
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
449
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/language.schema.json",
|
|
450
|
-
title: "Languages",
|
|
451
|
-
oneOf: [
|
|
452
|
-
{
|
|
453
|
-
$ref: "bcp.schema.json"
|
|
454
|
-
},
|
|
455
|
-
{
|
|
456
|
-
type: "array",
|
|
457
|
-
items: {
|
|
458
|
-
$ref: "bcp.schema.json"
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
]
|
|
462
|
-
};
|
|
463
|
-
|
|
464
|
-
// schemas/pub-manifest/module/link.schema.json
|
|
465
|
-
var link_schema_default = {
|
|
466
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
467
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/link.schema.json",
|
|
468
|
-
title: "Publication Links",
|
|
469
|
-
type: "object",
|
|
470
|
-
properties: {
|
|
471
|
-
type: {
|
|
472
|
-
oneOf: [
|
|
473
|
-
{
|
|
474
|
-
type: "string",
|
|
475
|
-
const: "LinkedResource"
|
|
476
|
-
},
|
|
477
|
-
{
|
|
478
|
-
type: "array",
|
|
479
|
-
items: {
|
|
480
|
-
type: "string"
|
|
481
|
-
},
|
|
482
|
-
contains: {
|
|
483
|
-
const: "LinkedResource"
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
]
|
|
487
|
-
},
|
|
488
|
-
url: {
|
|
489
|
-
$ref: "url.schema.json"
|
|
490
|
-
},
|
|
491
|
-
encodingFormat: {
|
|
492
|
-
type: "string"
|
|
493
|
-
},
|
|
494
|
-
name: {
|
|
495
|
-
$ref: "localizable.schema.json"
|
|
496
|
-
},
|
|
497
|
-
description: {
|
|
498
|
-
anyOf: [
|
|
499
|
-
{
|
|
500
|
-
type: "string"
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
$ref: "localizable-object.schema.json"
|
|
504
|
-
}
|
|
505
|
-
]
|
|
506
|
-
},
|
|
507
|
-
rel: {
|
|
508
|
-
type: ["string", "array"],
|
|
509
|
-
items: {
|
|
510
|
-
type: "string"
|
|
511
|
-
}
|
|
512
|
-
},
|
|
513
|
-
integrity: {
|
|
514
|
-
type: "string"
|
|
515
|
-
},
|
|
516
|
-
duration: {
|
|
517
|
-
$ref: "duration.schema.json"
|
|
518
|
-
},
|
|
519
|
-
alternate: {
|
|
520
|
-
$ref: "resource.categorization.schema.json"
|
|
521
|
-
}
|
|
522
|
-
},
|
|
523
|
-
required: ["url"]
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
// schemas/pub-manifest/module/localizable-object.schema.json
|
|
527
|
-
var localizable_object_schema_default = {
|
|
528
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
529
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/localizable-object.schema.json",
|
|
530
|
-
title: "Localizable String Object",
|
|
531
|
-
type: "object",
|
|
532
|
-
properties: {
|
|
533
|
-
value: {
|
|
534
|
-
type: "string"
|
|
535
|
-
},
|
|
536
|
-
language: {
|
|
537
|
-
$ref: "bcp.schema.json"
|
|
538
|
-
}
|
|
539
|
-
},
|
|
540
|
-
required: ["value"]
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
// schemas/pub-manifest/module/localizable.schema.json
|
|
544
|
-
var localizable_schema_default = {
|
|
545
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
546
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/localizable.schema.json",
|
|
547
|
-
title: "Localizable String or Object",
|
|
548
|
-
anyOf: [
|
|
549
|
-
{
|
|
550
|
-
type: "string"
|
|
551
|
-
},
|
|
552
|
-
{
|
|
553
|
-
type: "array",
|
|
554
|
-
items: {
|
|
555
|
-
anyOf: [
|
|
556
|
-
{
|
|
557
|
-
type: "string"
|
|
558
|
-
},
|
|
559
|
-
{
|
|
560
|
-
$ref: "localizable-object.schema.json"
|
|
561
|
-
}
|
|
562
|
-
]
|
|
563
|
-
}
|
|
564
|
-
},
|
|
565
|
-
{
|
|
566
|
-
$ref: "localizable-object.schema.json"
|
|
567
|
-
}
|
|
568
|
-
]
|
|
569
|
-
};
|
|
570
|
-
|
|
571
|
-
// schemas/pub-manifest/module/resource.categorization.schema.json
|
|
572
|
-
var resource_categorization_schema_default = {
|
|
573
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
574
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/resource.categorization.schema.json",
|
|
575
|
-
title: "Resource Categorization",
|
|
576
|
-
oneOf: [
|
|
577
|
-
{
|
|
578
|
-
oneOf: [
|
|
579
|
-
{
|
|
580
|
-
$ref: "url.schema.json"
|
|
581
|
-
},
|
|
582
|
-
{
|
|
583
|
-
$ref: "link.schema.json"
|
|
584
|
-
}
|
|
585
|
-
]
|
|
586
|
-
},
|
|
587
|
-
{
|
|
588
|
-
type: "array",
|
|
589
|
-
items: {
|
|
590
|
-
anyOf: [
|
|
591
|
-
{
|
|
592
|
-
$ref: "url.schema.json"
|
|
593
|
-
},
|
|
594
|
-
{
|
|
595
|
-
$ref: "link.schema.json"
|
|
596
|
-
}
|
|
597
|
-
]
|
|
598
|
-
},
|
|
599
|
-
uniqueItems: true
|
|
600
|
-
}
|
|
601
|
-
]
|
|
602
|
-
};
|
|
603
|
-
|
|
604
|
-
// schemas/pub-manifest/module/strings.schema.json
|
|
605
|
-
var strings_schema_default = {
|
|
606
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
607
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/strings.schema.json",
|
|
608
|
-
title: "Unique strings",
|
|
609
|
-
type: ["string", "array"],
|
|
610
|
-
items: {
|
|
611
|
-
type: "string"
|
|
612
|
-
}
|
|
613
|
-
};
|
|
614
|
-
|
|
615
|
-
// schemas/pub-manifest/module/url.schema.json
|
|
616
|
-
var url_schema_default = {
|
|
617
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
618
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/url.schema.json",
|
|
619
|
-
title: "URL",
|
|
620
|
-
type: "string",
|
|
621
|
-
format: "uri-reference"
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
// schemas/pub-manifest/module/urls.schema.json
|
|
625
|
-
var urls_schema_default = {
|
|
626
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
627
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/module/urls.schema.json",
|
|
628
|
-
title: "URLs",
|
|
629
|
-
oneOf: [
|
|
630
|
-
{
|
|
631
|
-
type: "string",
|
|
632
|
-
format: "uri-reference"
|
|
633
|
-
},
|
|
634
|
-
{
|
|
635
|
-
type: "array",
|
|
636
|
-
items: {
|
|
637
|
-
type: "string",
|
|
638
|
-
format: "uri-reference"
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
]
|
|
642
|
-
};
|
|
643
|
-
|
|
644
|
-
// schemas/pub-manifest/publication.schema.json
|
|
645
|
-
var publication_schema_default = {
|
|
646
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
647
|
-
$id: "https://www.w3.org/ns/pub-schema/manifest/publication.schema.json",
|
|
648
|
-
title: "Publication Manifest",
|
|
649
|
-
type: "object",
|
|
650
|
-
properties: {
|
|
651
|
-
"@context": {
|
|
652
|
-
$ref: "module/context.schema.json"
|
|
653
|
-
},
|
|
654
|
-
type: {
|
|
655
|
-
type: ["string", "array"],
|
|
656
|
-
items: {
|
|
657
|
-
type: "string"
|
|
658
|
-
}
|
|
659
|
-
},
|
|
660
|
-
conformsTo: {
|
|
661
|
-
oneOf: [
|
|
662
|
-
{
|
|
663
|
-
$ref: "module/url.schema.json"
|
|
664
|
-
},
|
|
665
|
-
{
|
|
666
|
-
type: "array",
|
|
667
|
-
items: {
|
|
668
|
-
$ref: "module/url.schema.json"
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
]
|
|
672
|
-
},
|
|
673
|
-
id: {
|
|
674
|
-
type: "string"
|
|
675
|
-
},
|
|
676
|
-
abridged: {
|
|
677
|
-
type: "boolean"
|
|
678
|
-
},
|
|
679
|
-
accessMode: {
|
|
680
|
-
$ref: "module/strings.schema.json"
|
|
681
|
-
},
|
|
682
|
-
accessModeSufficient: {
|
|
683
|
-
$ref: "module/item-lists.schema.json"
|
|
684
|
-
},
|
|
685
|
-
accessibilityFeature: {
|
|
686
|
-
$ref: "module/strings.schema.json"
|
|
687
|
-
},
|
|
688
|
-
accessibilityHazard: {
|
|
689
|
-
$ref: "module/strings.schema.json"
|
|
690
|
-
},
|
|
691
|
-
accessibilitySummary: {
|
|
692
|
-
$ref: "module/localizable.schema.json"
|
|
693
|
-
},
|
|
694
|
-
artist: {
|
|
695
|
-
$ref: "module/contributor.schema.json"
|
|
696
|
-
},
|
|
697
|
-
author: {
|
|
698
|
-
$ref: "module/contributor.schema.json"
|
|
699
|
-
},
|
|
700
|
-
colorist: {
|
|
701
|
-
$ref: "module/contributor.schema.json"
|
|
702
|
-
},
|
|
703
|
-
contributor: {
|
|
704
|
-
$ref: "module/contributor.schema.json"
|
|
705
|
-
},
|
|
706
|
-
creator: {
|
|
707
|
-
$ref: "module/contributor.schema.json"
|
|
708
|
-
},
|
|
709
|
-
editor: {
|
|
710
|
-
$ref: "module/contributor.schema.json"
|
|
711
|
-
},
|
|
712
|
-
illustrator: {
|
|
713
|
-
$ref: "module/contributor.schema.json"
|
|
714
|
-
},
|
|
715
|
-
inker: {
|
|
716
|
-
$ref: "module/contributor.schema.json"
|
|
717
|
-
},
|
|
718
|
-
letterer: {
|
|
719
|
-
$ref: "module/contributor.schema.json"
|
|
720
|
-
},
|
|
721
|
-
penciler: {
|
|
722
|
-
$ref: "module/contributor.schema.json"
|
|
723
|
-
},
|
|
724
|
-
publisher: {
|
|
725
|
-
$ref: "module/contributor.schema.json"
|
|
726
|
-
},
|
|
727
|
-
readBy: {
|
|
728
|
-
$ref: "module/contributor.schema.json"
|
|
729
|
-
},
|
|
730
|
-
translator: {
|
|
731
|
-
$ref: "module/contributor.schema.json"
|
|
732
|
-
},
|
|
733
|
-
url: {
|
|
734
|
-
$ref: "module/urls.schema.json"
|
|
735
|
-
},
|
|
736
|
-
duration: {
|
|
737
|
-
$ref: "module/duration.schema.json"
|
|
738
|
-
},
|
|
739
|
-
inLanguage: {
|
|
740
|
-
$ref: "module/language.schema.json"
|
|
741
|
-
},
|
|
742
|
-
dateModified: {
|
|
743
|
-
$ref: "module/date.schema.json"
|
|
744
|
-
},
|
|
745
|
-
datePublished: {
|
|
746
|
-
$ref: "module/date.schema.json"
|
|
747
|
-
},
|
|
748
|
-
name: {
|
|
749
|
-
$ref: "module/localizable.schema.json"
|
|
750
|
-
},
|
|
751
|
-
readingOrder: {
|
|
752
|
-
$ref: "module/resource.categorization.schema.json"
|
|
753
|
-
},
|
|
754
|
-
resources: {
|
|
755
|
-
$ref: "module/resource.categorization.schema.json"
|
|
756
|
-
},
|
|
757
|
-
links: {
|
|
758
|
-
$ref: "module/resource.categorization.schema.json"
|
|
759
|
-
},
|
|
760
|
-
readingProgression: {
|
|
761
|
-
type: "string",
|
|
762
|
-
enum: ["ltr", "rtl"],
|
|
763
|
-
default: "ltr"
|
|
764
|
-
}
|
|
765
|
-
},
|
|
766
|
-
required: ["@context", "conformsTo"]
|
|
767
|
-
};
|
|
768
|
-
|
|
769
|
-
// src/schema/pub-manifest.ts
|
|
770
|
-
var publicationSchemas = [
|
|
771
|
-
bcp_schema_default,
|
|
772
|
-
context_schema_default,
|
|
773
|
-
contributor_object_schema_default,
|
|
774
|
-
contributor_schema_default,
|
|
775
|
-
date_schema_default,
|
|
776
|
-
duration_schema_default,
|
|
777
|
-
item_lists_schema_default,
|
|
778
|
-
ItemList_schema_default,
|
|
779
|
-
language_schema_default,
|
|
780
|
-
link_schema_default,
|
|
781
|
-
localizable_object_schema_default,
|
|
782
|
-
localizable_schema_default,
|
|
783
|
-
resource_categorization_schema_default,
|
|
784
|
-
strings_schema_default,
|
|
785
|
-
url_schema_default,
|
|
786
|
-
urls_schema_default,
|
|
787
|
-
publication_schema_default
|
|
788
|
-
];
|
|
789
|
-
|
|
790
|
-
// src/util.ts
|
|
791
|
-
var cwd = upath.normalize(process.cwd());
|
|
792
|
-
var beforeExitHandlers = [];
|
|
793
|
-
var registerExitHandler = (debugMessage, handler) => {
|
|
794
|
-
beforeExitHandlers.push(() => {
|
|
795
|
-
Logger.debug(debugMessage);
|
|
796
|
-
handler();
|
|
797
|
-
});
|
|
798
|
-
};
|
|
799
|
-
function runExitHandlers() {
|
|
800
|
-
while (beforeExitHandlers.length) {
|
|
801
|
-
try {
|
|
802
|
-
beforeExitHandlers.shift()?.();
|
|
803
|
-
} catch (e) {
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
var exitSignals = ["exit", "SIGINT", "SIGTERM"];
|
|
808
|
-
exitSignals.forEach((sig) => {
|
|
809
|
-
process.once(sig, (signal, exitCode) => {
|
|
810
|
-
runExitHandlers();
|
|
811
|
-
if (process.exitCode === void 0) {
|
|
812
|
-
process.exitCode = exitCode !== void 0 ? 128 + exitCode : Number(signal);
|
|
813
|
-
}
|
|
814
|
-
process.exit();
|
|
815
|
-
});
|
|
816
|
-
});
|
|
817
|
-
if (process.platform === "win32") {
|
|
818
|
-
const rl = readline.createInterface({
|
|
819
|
-
input: process.stdin,
|
|
820
|
-
output: process.stdout
|
|
821
|
-
});
|
|
822
|
-
rl.on("SIGINT", () => {
|
|
823
|
-
runExitHandlers();
|
|
824
|
-
process.exit(1);
|
|
825
|
-
});
|
|
826
|
-
registerExitHandler("Closing readline interface", () => {
|
|
827
|
-
rl.close();
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
var DetailError = class extends Error {
|
|
831
|
-
constructor(message, detail) {
|
|
832
|
-
super(message);
|
|
833
|
-
this.detail = detail;
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
function getFormattedError(err) {
|
|
837
|
-
return err instanceof DetailError ? `${err.message}
|
|
838
|
-
${err.detail}` : err.stack || `${err.message}`;
|
|
839
|
-
}
|
|
840
|
-
function gracefulError(err) {
|
|
841
|
-
console.log(`${redBright2("ERROR")} ${getFormattedError(err)}
|
|
842
|
-
|
|
843
|
-
${gray2("If you think this is a bug, please report at https://github.com/vivliostyle/vivliostyle-cli/issues")}`);
|
|
844
|
-
process.exit(1);
|
|
845
|
-
}
|
|
846
|
-
function readJSON(path) {
|
|
847
|
-
try {
|
|
848
|
-
return JSON.parse(fs.readFileSync(path, "utf8"));
|
|
849
|
-
} catch (err) {
|
|
850
|
-
return void 0;
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
function statFileSync(filePath, {
|
|
854
|
-
errorMessage = "Specified input does not exist"
|
|
855
|
-
} = {}) {
|
|
856
|
-
try {
|
|
857
|
-
return fs.statSync(filePath);
|
|
858
|
-
} catch (err) {
|
|
859
|
-
if (err.code === "ENOENT") {
|
|
860
|
-
throw new Error(`${errorMessage}: ${filePath}`);
|
|
861
|
-
}
|
|
862
|
-
throw err;
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
async function inflateZip(filePath, dest) {
|
|
866
|
-
return await new Promise((res, rej) => {
|
|
867
|
-
try {
|
|
868
|
-
const zip = new StreamZip({
|
|
869
|
-
file: filePath,
|
|
870
|
-
storeEntries: true
|
|
871
|
-
});
|
|
872
|
-
zip.on("error", (err) => {
|
|
873
|
-
rej(err);
|
|
874
|
-
});
|
|
875
|
-
zip.on("ready", async () => {
|
|
876
|
-
await util.promisify(zip.extract)(null, dest);
|
|
877
|
-
await util.promisify(zip.close)();
|
|
878
|
-
Logger.debug(`Unzipped ${filePath} to ${dest}`);
|
|
879
|
-
res();
|
|
880
|
-
});
|
|
881
|
-
} catch (err) {
|
|
882
|
-
rej(err);
|
|
883
|
-
}
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
function useTmpDirectory() {
|
|
887
|
-
return new Promise((res, rej) => {
|
|
888
|
-
tmp.dir({ unsafeCleanup: true }, (err, path, clear) => {
|
|
889
|
-
if (err) {
|
|
890
|
-
return rej(err);
|
|
891
|
-
}
|
|
892
|
-
Logger.debug(`Created the temporary directory: ${path}`);
|
|
893
|
-
if (import.meta.env?.VITEST) {
|
|
894
|
-
return res([path, () => {
|
|
895
|
-
}]);
|
|
896
|
-
}
|
|
897
|
-
const callback = () => {
|
|
898
|
-
fs.rmSync(path, { force: true, recursive: true });
|
|
899
|
-
};
|
|
900
|
-
registerExitHandler(
|
|
901
|
-
`Removing the temporary directory: ${path}`,
|
|
902
|
-
callback
|
|
903
|
-
);
|
|
904
|
-
res([path, callback]);
|
|
905
|
-
});
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
function touchTmpFile(path) {
|
|
909
|
-
fs.mkdirSync(upath.dirname(path), { recursive: true });
|
|
910
|
-
fs.closeSync(fs.openSync(path, "a"));
|
|
911
|
-
Logger.debug(`Created the temporary file: ${path}`);
|
|
912
|
-
const callback = () => {
|
|
913
|
-
fs.rmSync(path, { force: true, recursive: true });
|
|
914
|
-
};
|
|
915
|
-
registerExitHandler(`Removing the temporary file: ${path}`, callback);
|
|
916
|
-
return callback;
|
|
917
|
-
}
|
|
918
|
-
function pathEquals(path1, path2) {
|
|
919
|
-
return upath.relative(path1, path2) === "";
|
|
920
|
-
}
|
|
921
|
-
function pathContains(parentPath, childPath) {
|
|
922
|
-
const rel = upath.relative(parentPath, childPath);
|
|
923
|
-
return rel !== "" && !rel.startsWith("..");
|
|
924
|
-
}
|
|
925
|
-
function isValidUri(str) {
|
|
926
|
-
return /^(https?|file|data):/i.test(str);
|
|
927
|
-
}
|
|
928
|
-
function isInContainer() {
|
|
929
|
-
return fs.existsSync("/opt/vivliostyle-cli/.vs-cli-version");
|
|
930
|
-
}
|
|
931
|
-
function isRunningOnWSL() {
|
|
932
|
-
return fs.existsSync("/proc/version") && fs.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
|
|
933
|
-
}
|
|
934
|
-
async function openEpub(epubPath, tmpDir) {
|
|
935
|
-
await inflateZip(epubPath, tmpDir);
|
|
936
|
-
Logger.debug(`Created the temporary EPUB directory: ${tmpDir}`);
|
|
937
|
-
const deleteEpub = () => {
|
|
938
|
-
fs.rmSync(tmpDir, { force: true, recursive: true });
|
|
939
|
-
};
|
|
940
|
-
registerExitHandler(
|
|
941
|
-
`Removing the temporary EPUB directory: ${tmpDir}`,
|
|
942
|
-
deleteEpub
|
|
943
|
-
);
|
|
944
|
-
return deleteEpub;
|
|
945
|
-
}
|
|
946
|
-
function getDefaultEpubOpfPath(epubDir) {
|
|
947
|
-
const containerXmlPath = upath.join(epubDir, "META-INF/container.xml");
|
|
948
|
-
const xmlParser = new XMLParser({
|
|
949
|
-
ignoreAttributes: false
|
|
950
|
-
});
|
|
951
|
-
const { container } = xmlParser.parse(
|
|
952
|
-
fs.readFileSync(containerXmlPath, "utf8")
|
|
953
|
-
);
|
|
954
|
-
const rootfile = [container.rootfiles.rootfile].flat()[0];
|
|
955
|
-
const epubOpfPath = upath.join(epubDir, rootfile["@_full-path"]);
|
|
956
|
-
return epubOpfPath;
|
|
957
|
-
}
|
|
958
|
-
function getEpubRootDir(epubOpfPath) {
|
|
959
|
-
function traverse(dir) {
|
|
960
|
-
const files = fs.readdirSync(dir);
|
|
961
|
-
if (files.includes("META-INF") && pathEquals(epubOpfPath, getDefaultEpubOpfPath(dir))) {
|
|
962
|
-
return dir;
|
|
963
|
-
}
|
|
964
|
-
const next = upath.dirname(dir);
|
|
965
|
-
if (pathEquals(dir, next)) {
|
|
966
|
-
return;
|
|
967
|
-
}
|
|
968
|
-
return traverse(next);
|
|
969
|
-
}
|
|
970
|
-
return traverse(upath.dirname(epubOpfPath));
|
|
971
|
-
}
|
|
972
|
-
var getAjvValidatorFunction = (schema, refSchemas) => (obj) => {
|
|
973
|
-
const ajv = new Ajv({ strict: false });
|
|
974
|
-
const addFormats = formatsPlugin;
|
|
975
|
-
addFormats(ajv);
|
|
976
|
-
if (refSchemas) {
|
|
977
|
-
ajv.addSchema(refSchemas);
|
|
978
|
-
}
|
|
979
|
-
const validate = ajv.compile(schema);
|
|
980
|
-
const valid = validate(obj);
|
|
981
|
-
if (!valid) {
|
|
982
|
-
throw validate.errors?.[0] || new Error();
|
|
983
|
-
}
|
|
984
|
-
return true;
|
|
985
|
-
};
|
|
986
|
-
var assertPubManifestSchema = getAjvValidatorFunction(
|
|
987
|
-
publication_schema_default,
|
|
988
|
-
publicationSchemas
|
|
989
|
-
);
|
|
990
|
-
function parseJsonc(rawJsonc) {
|
|
991
|
-
const ast = parse(rawJsonc, {
|
|
992
|
-
mode: "jsonc",
|
|
993
|
-
ranges: false,
|
|
994
|
-
tokens: false
|
|
995
|
-
});
|
|
996
|
-
return evaluate(ast);
|
|
997
|
-
}
|
|
998
|
-
function prettifySchemaError(rawJsonc, issues) {
|
|
999
|
-
const parsed = parse(rawJsonc, {
|
|
1000
|
-
mode: "jsonc",
|
|
1001
|
-
ranges: false,
|
|
1002
|
-
tokens: false
|
|
1003
|
-
});
|
|
1004
|
-
function traverse(issues2, depth) {
|
|
1005
|
-
return issues2.flatMap((issue) => {
|
|
1006
|
-
const p = issue.path?.length || 0;
|
|
1007
|
-
if (!issue.issues) {
|
|
1008
|
-
return [[[issue], depth + p]];
|
|
1009
|
-
}
|
|
1010
|
-
return traverse(issue.issues, depth + p).map(([i, d]) => [
|
|
1011
|
-
[issue, ...i],
|
|
1012
|
-
d
|
|
1013
|
-
]);
|
|
1014
|
-
});
|
|
1015
|
-
}
|
|
1016
|
-
const all = traverse(issues, 0);
|
|
1017
|
-
const maxDepth = Math.max(...all.map(([, d]) => d));
|
|
1018
|
-
const issuesTraversed = all.find(([, d]) => d === maxDepth)[0];
|
|
1019
|
-
let jsonValue = parsed.body;
|
|
1020
|
-
for (const p of issuesTraversed.flatMap((v3) => v3.path ?? [])) {
|
|
1021
|
-
let childValue;
|
|
1022
|
-
if (p.type === "object" && jsonValue.type === "Object") {
|
|
1023
|
-
childValue = jsonValue.members.find(
|
|
1024
|
-
(m) => m.name.type === "Identifier" && m.name.name === p.key || m.name.type === "String" && m.name.value === p.key
|
|
1025
|
-
)?.value;
|
|
1026
|
-
}
|
|
1027
|
-
if (p.type === "array" && jsonValue.type === "Array") {
|
|
1028
|
-
childValue = jsonValue.elements[p.key]?.value;
|
|
1029
|
-
}
|
|
1030
|
-
if (childValue) {
|
|
1031
|
-
jsonValue = childValue;
|
|
1032
|
-
} else {
|
|
1033
|
-
break;
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
let message = `${red(issuesTraversed.at(-1).message)}`;
|
|
1037
|
-
if (jsonValue) {
|
|
1038
|
-
message += `
|
|
1039
|
-
${codeFrameColumns(rawJsonc, jsonValue.loc, {
|
|
1040
|
-
highlightCode: true
|
|
1041
|
-
})}`;
|
|
1042
|
-
}
|
|
1043
|
-
return message;
|
|
1044
|
-
}
|
|
1045
|
-
function writeFileIfChanged(filePath, content) {
|
|
1046
|
-
if (!fs.existsSync(filePath) || !fs.readFileSync(filePath).equals(content)) {
|
|
1047
|
-
fs.mkdirSync(upath.dirname(filePath), { recursive: true });
|
|
1048
|
-
fs.writeFileSync(filePath, content);
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
// src/commands/cli-flags.ts
|
|
1053
|
-
import upath2 from "upath";
|
|
1054
|
-
import * as v from "valibot";
|
|
1055
|
-
function parseFlagsToInlineConfig(argv, setupProgram) {
|
|
1056
|
-
const program = setupProgram();
|
|
1057
|
-
program.parse(argv);
|
|
1058
|
-
let options = program.opts();
|
|
1059
|
-
const input = program.args?.[0];
|
|
1060
|
-
options = warnDeprecatedFlags(options);
|
|
1061
|
-
let inlineConfig = { input, ...options };
|
|
1062
|
-
if (input && !options.config && upath2.basename(input).startsWith("vivliostyle.config")) {
|
|
1063
|
-
inlineConfig = { config: input, ...options };
|
|
1064
|
-
}
|
|
1065
|
-
return v.parse(VivliostyleInlineConfig, inlineConfig);
|
|
1066
|
-
}
|
|
1067
|
-
function setupConfigFromFlags(flags) {
|
|
1068
|
-
if (!flags.input) {
|
|
1069
|
-
if (flags.enableViewerStartPage) {
|
|
1070
|
-
return {
|
|
1071
|
-
tasks: [{ entry: [] }],
|
|
1072
|
-
inlineOptions: {
|
|
1073
|
-
input: { format: "webbook", entry: EMPTY_DATA_URI }
|
|
1074
|
-
}
|
|
1075
|
-
};
|
|
1076
|
-
} else {
|
|
1077
|
-
throw new Error(
|
|
1078
|
-
"No input is set. Please set an appropriate entry or a Vivliostyle config file."
|
|
1079
|
-
);
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
return {
|
|
1083
|
-
tasks: [{ entry: [] }],
|
|
1084
|
-
inlineOptions: {}
|
|
1085
|
-
};
|
|
1086
|
-
}
|
|
1087
|
-
function warnDeprecatedFlags(options) {
|
|
1088
|
-
const modifiedOptions = { ...options };
|
|
1089
|
-
if (options.executableChromium) {
|
|
1090
|
-
Logger.logWarn(
|
|
1091
|
-
"'--executable-chromium' option was deprecated and will be removed in a future release. Please replace with '--executable-browser' option."
|
|
1092
|
-
);
|
|
1093
|
-
modifiedOptions.executableBrowser = options.executableChromium;
|
|
1094
|
-
}
|
|
1095
|
-
if (options.verbose) {
|
|
1096
|
-
Logger.logWarn(
|
|
1097
|
-
"'--verbose' option was deprecated and will be removed in a future release. Please replace with '--log-level verbose' option."
|
|
1098
|
-
);
|
|
1099
|
-
modifiedOptions.logLevel = "verbose";
|
|
1100
|
-
}
|
|
1101
|
-
if (options.sandbox === false) {
|
|
1102
|
-
Logger.logWarn(
|
|
1103
|
-
"'--no-sandbox' option was deprecated and will be removed in a future release. It is no longer necessary because the sandbox is disabled by default."
|
|
1104
|
-
);
|
|
1105
|
-
}
|
|
1106
|
-
if (options.http) {
|
|
1107
|
-
Logger.logWarn(
|
|
1108
|
-
"'--http' option was deprecated and will be removed in a future release. It is unnecessary because the HTTP server starts automatically."
|
|
1109
|
-
);
|
|
1110
|
-
}
|
|
1111
|
-
return modifiedOptions;
|
|
1112
|
-
}
|
|
55
|
+
} from "./chunk-I7BWSAN6.js";
|
|
1113
56
|
|
|
1114
57
|
// src/config/load.ts
|
|
1115
|
-
import
|
|
58
|
+
import fs from "node:fs";
|
|
1116
59
|
import { createRequire } from "node:module";
|
|
1117
60
|
import { pathToFileURL } from "node:url";
|
|
1118
|
-
import
|
|
1119
|
-
import * as
|
|
61
|
+
import upath from "upath";
|
|
62
|
+
import * as v from "valibot";
|
|
1120
63
|
var require2 = createRequire(import.meta.url);
|
|
1121
64
|
function locateVivliostyleConfig({
|
|
1122
65
|
config,
|
|
1123
66
|
cwd: cwd2 = cwd
|
|
1124
67
|
}) {
|
|
1125
68
|
if (config) {
|
|
1126
|
-
return
|
|
69
|
+
return upath.resolve(cwd2, config);
|
|
1127
70
|
}
|
|
1128
|
-
return [".js", ".mjs", ".cjs", ".json"].map((ext) =>
|
|
71
|
+
return [".js", ".mjs", ".cjs", ".json"].map((ext) => upath.join(cwd2, `vivliostyle.config${ext}`)).find((p) => fs.existsSync(p));
|
|
1129
72
|
}
|
|
1130
73
|
async function loadVivliostyleConfig({
|
|
1131
74
|
config,
|
|
@@ -1133,7 +76,7 @@ async function loadVivliostyleConfig({
|
|
|
1133
76
|
cwd: cwd2
|
|
1134
77
|
}) {
|
|
1135
78
|
if (configData) {
|
|
1136
|
-
return
|
|
79
|
+
return v.parse(VivliostyleConfigSchema, configData);
|
|
1137
80
|
}
|
|
1138
81
|
const absPath = locateVivliostyleConfig({ config, cwd: cwd2 });
|
|
1139
82
|
if (!absPath) {
|
|
@@ -1142,8 +85,8 @@ async function loadVivliostyleConfig({
|
|
|
1142
85
|
let parsedConfig;
|
|
1143
86
|
let jsonRaw;
|
|
1144
87
|
try {
|
|
1145
|
-
if (
|
|
1146
|
-
jsonRaw =
|
|
88
|
+
if (upath.extname(absPath) === ".json") {
|
|
89
|
+
jsonRaw = fs.readFileSync(absPath, "utf8");
|
|
1147
90
|
parsedConfig = parseJsonc(jsonRaw);
|
|
1148
91
|
} else {
|
|
1149
92
|
delete require2.cache[require2.resolve(absPath)];
|
|
@@ -1162,7 +105,7 @@ async function loadVivliostyleConfig({
|
|
|
1162
105
|
thrownError.stack ?? thrownError.message
|
|
1163
106
|
);
|
|
1164
107
|
}
|
|
1165
|
-
const result =
|
|
108
|
+
const result = v.safeParse(VivliostyleConfigSchema, parsedConfig);
|
|
1166
109
|
if (result.success) {
|
|
1167
110
|
const { tasks, inlineOptions } = result.output;
|
|
1168
111
|
return {
|
|
@@ -1272,304 +215,30 @@ function mergeInlineConfig({ tasks, inlineOptions }, inlineConfig) {
|
|
|
1272
215
|
server: {
|
|
1273
216
|
...pruneObject(task.server ?? {}),
|
|
1274
217
|
...pruneObject({ host, port })
|
|
1275
|
-
}
|
|
1276
|
-
})),
|
|
1277
|
-
inlineOptions: {
|
|
1278
|
-
...pruneObject(inlineOptions),
|
|
1279
|
-
...pruneObject(
|
|
1280
|
-
overrideInlineOptions
|
|
1281
|
-
)
|
|
1282
|
-
}
|
|
1283
|
-
};
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
// src/browser.ts
|
|
1287
|
-
import fs3 from "node:fs";
|
|
1288
|
-
async function launchBrowser({
|
|
1289
|
-
browserType,
|
|
1290
|
-
proxy,
|
|
1291
|
-
executablePath,
|
|
1292
|
-
headless,
|
|
1293
|
-
noSandbox,
|
|
1294
|
-
disableWebSecurity,
|
|
1295
|
-
disableDevShmUsage
|
|
1296
|
-
}) {
|
|
1297
|
-
const playwright = await importNodeModule("playwright-core");
|
|
1298
|
-
playwright.firefox.executablePath;
|
|
1299
|
-
const options = browserType === "chromium" ? {
|
|
1300
|
-
executablePath,
|
|
1301
|
-
chromiumSandbox: !noSandbox,
|
|
1302
|
-
headless,
|
|
1303
|
-
args: [
|
|
1304
|
-
"--allow-file-access-from-files",
|
|
1305
|
-
...disableWebSecurity ? ["--disable-web-security"] : [],
|
|
1306
|
-
...disableDevShmUsage ? ["--disable-dev-shm-usage"] : [],
|
|
1307
|
-
// #357: Set devicePixelRatio=1 otherwise it causes layout issues in HiDPI displays
|
|
1308
|
-
...headless ? ["--force-device-scale-factor=1"] : [],
|
|
1309
|
-
// #565: Add --disable-gpu option when running on WSL
|
|
1310
|
-
...isRunningOnWSL() ? ["--disable-gpu"] : [],
|
|
1311
|
-
// set Chromium language to English to avoid locale-dependent issues
|
|
1312
|
-
"--lang=en",
|
|
1313
|
-
...!headless && process.platform === "darwin" ? ["", "-AppleLanguages", "(en)"] : []
|
|
1314
|
-
],
|
|
1315
|
-
env: { ...process.env, LANG: "en.UTF-8" },
|
|
1316
|
-
proxy
|
|
1317
|
-
} : (
|
|
1318
|
-
// TODO: Investigate appropriate settings on Firefox & Webkit
|
|
1319
|
-
{ executablePath, headless }
|
|
1320
|
-
);
|
|
1321
|
-
const browser = await playwright[browserType].launch(options);
|
|
1322
|
-
registerExitHandler("Closing browser", () => {
|
|
1323
|
-
browser.close();
|
|
1324
|
-
});
|
|
1325
|
-
return browser;
|
|
1326
|
-
}
|
|
1327
|
-
async function getExecutableBrowserPath(browserType) {
|
|
1328
|
-
const playwright = await importNodeModule("playwright-core");
|
|
1329
|
-
return playwright[browserType].executablePath();
|
|
1330
|
-
}
|
|
1331
|
-
function getFullBrowserName(browserType) {
|
|
1332
|
-
return {
|
|
1333
|
-
chromium: "Chromium",
|
|
1334
|
-
firefox: "Firefox",
|
|
1335
|
-
webkit: "Webkit"
|
|
1336
|
-
}[browserType];
|
|
1337
|
-
}
|
|
1338
|
-
function checkBrowserAvailability(path) {
|
|
1339
|
-
return fs3.existsSync(path);
|
|
1340
|
-
}
|
|
1341
|
-
async function downloadBrowser(browserType) {
|
|
1342
|
-
const { registry } = await importNodeModule("playwright-core/lib/server");
|
|
1343
|
-
const executable = registry.findExecutable(browserType);
|
|
1344
|
-
{
|
|
1345
|
-
var _stack = [];
|
|
1346
|
-
try {
|
|
1347
|
-
const _2 = __using(_stack, Logger.suspendLogging(
|
|
1348
|
-
"Rendering browser is not installed yet. Downloading now."
|
|
1349
|
-
));
|
|
1350
|
-
await registry.install([executable], false);
|
|
1351
|
-
} catch (_) {
|
|
1352
|
-
var _error = _, _hasError = true;
|
|
1353
|
-
} finally {
|
|
1354
|
-
__callDispose(_stack, _error, _hasError);
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
return executable.executablePath();
|
|
1358
|
-
}
|
|
1359
|
-
async function launchPreview({
|
|
1360
|
-
mode,
|
|
1361
|
-
url,
|
|
1362
|
-
onBrowserOpen,
|
|
1363
|
-
onPageOpen,
|
|
1364
|
-
config: { browser: browserConfig, proxy, sandbox, ignoreHttpsErrors }
|
|
1365
|
-
}) {
|
|
1366
|
-
let executableBrowser = browserConfig.executablePath;
|
|
1367
|
-
if (executableBrowser) {
|
|
1368
|
-
if (!checkBrowserAvailability(executableBrowser)) {
|
|
1369
|
-
throw new Error(
|
|
1370
|
-
`Cannot find the browser. Please check the executable browser path: ${executableBrowser}`
|
|
1371
|
-
);
|
|
1372
|
-
}
|
|
1373
|
-
} else {
|
|
1374
|
-
executableBrowser = await getExecutableBrowserPath(browserConfig.type);
|
|
1375
|
-
if (!checkBrowserAvailability(executableBrowser)) {
|
|
1376
|
-
await downloadBrowser(browserConfig.type);
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
Logger.debug(`Executing browser path: ${executableBrowser}`);
|
|
1380
|
-
const browser = await launchBrowser({
|
|
1381
|
-
browserType: browserConfig.type,
|
|
1382
|
-
proxy,
|
|
1383
|
-
executablePath: executableBrowser,
|
|
1384
|
-
headless: mode === "build",
|
|
1385
|
-
noSandbox: !sandbox,
|
|
1386
|
-
disableDevShmUsage: isInContainer()
|
|
1387
|
-
});
|
|
1388
|
-
await onBrowserOpen?.(browser);
|
|
1389
|
-
const page = await browser.newPage({
|
|
1390
|
-
viewport: mode === "build" ? (
|
|
1391
|
-
// This viewport size important to detect headless environment in Vivliostyle viewer
|
|
1392
|
-
// https://github.com/vivliostyle/vivliostyle.js/blob/73bcf323adcad80126b0175630609451ccd09d8a/packages/core/src/vivliostyle/vgen.ts#L2489-L2500
|
|
1393
|
-
{
|
|
1394
|
-
width: 800,
|
|
1395
|
-
height: 600
|
|
1396
|
-
}
|
|
1397
|
-
) : null,
|
|
1398
|
-
ignoreHTTPSErrors: ignoreHttpsErrors
|
|
1399
|
-
});
|
|
1400
|
-
await onPageOpen?.(page);
|
|
1401
|
-
page.on("dialog", () => {
|
|
1402
|
-
});
|
|
1403
|
-
await page.goto(url);
|
|
1404
|
-
return { browser, page };
|
|
218
|
+
}
|
|
219
|
+
})),
|
|
220
|
+
inlineOptions: {
|
|
221
|
+
...pruneObject(inlineOptions),
|
|
222
|
+
...pruneObject(
|
|
223
|
+
overrideInlineOptions
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
};
|
|
1405
227
|
}
|
|
1406
228
|
|
|
1407
|
-
// src/server.ts
|
|
1408
|
-
import fs11 from "node:fs";
|
|
1409
|
-
import { URL as URL2 } from "node:url";
|
|
1410
|
-
import upath13 from "upath";
|
|
1411
|
-
import {
|
|
1412
|
-
createServer,
|
|
1413
|
-
preview
|
|
1414
|
-
} from "vite";
|
|
1415
|
-
|
|
1416
|
-
// src/vite/vite-plugin-dev-server.ts
|
|
1417
|
-
import escapeRe from "escape-string-regexp";
|
|
1418
|
-
import { pathToFileURL as pathToFileURL7 } from "node:url";
|
|
1419
|
-
import picomatch2 from "picomatch";
|
|
1420
|
-
import sirv from "sirv";
|
|
1421
|
-
import upath10 from "upath";
|
|
1422
|
-
|
|
1423
229
|
// src/config/resolve.ts
|
|
1424
230
|
import { VFM } from "@vivliostyle/vfm";
|
|
1425
231
|
import { lookup as mime } from "mime-types";
|
|
1426
|
-
import
|
|
1427
|
-
import { pathToFileURL as
|
|
232
|
+
import fs3 from "node:fs";
|
|
233
|
+
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
1428
234
|
import npa from "npm-package-arg";
|
|
1429
|
-
import
|
|
1430
|
-
|
|
1431
|
-
// src/container.ts
|
|
1432
|
-
import { execFile } from "node:child_process";
|
|
1433
|
-
import process2 from "node:process";
|
|
1434
|
-
import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "node:url";
|
|
1435
|
-
import { promisify } from "node:util";
|
|
1436
|
-
import upath4 from "upath";
|
|
1437
|
-
var execFileAsync = promisify(execFile);
|
|
1438
|
-
var CONTAINER_IMAGE = `ghcr.io/vivliostyle/cli:${cliVersion}`;
|
|
1439
|
-
var CONTAINER_ROOT_DIR = "/data";
|
|
1440
|
-
var CONTAINER_LOCAL_HOSTNAME = "host.docker.internal";
|
|
1441
|
-
function toContainerPath(urlOrAbsPath) {
|
|
1442
|
-
if (isValidUri(urlOrAbsPath)) {
|
|
1443
|
-
if (urlOrAbsPath.toLowerCase().startsWith("file")) {
|
|
1444
|
-
return pathToFileURL2(
|
|
1445
|
-
upath4.posix.join(
|
|
1446
|
-
CONTAINER_ROOT_DIR,
|
|
1447
|
-
upath4.toUnix(fileURLToPath(urlOrAbsPath)).replace(/^\w:/, "")
|
|
1448
|
-
)
|
|
1449
|
-
).href;
|
|
1450
|
-
} else {
|
|
1451
|
-
return urlOrAbsPath;
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
return upath4.posix.join(
|
|
1455
|
-
CONTAINER_ROOT_DIR,
|
|
1456
|
-
upath4.toUnix(urlOrAbsPath).replace(/^\w:/, "")
|
|
1457
|
-
);
|
|
1458
|
-
}
|
|
1459
|
-
function collectVolumeArgs(mountPoints) {
|
|
1460
|
-
return mountPoints.filter((p, i, array) => {
|
|
1461
|
-
if (i !== array.indexOf(p)) {
|
|
1462
|
-
return false;
|
|
1463
|
-
}
|
|
1464
|
-
let parent = p;
|
|
1465
|
-
while (!pathEquals(parent, upath4.dirname(parent))) {
|
|
1466
|
-
parent = upath4.dirname(parent);
|
|
1467
|
-
if (array.includes(parent)) {
|
|
1468
|
-
return false;
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
return true;
|
|
1472
|
-
}).map((p) => `${p}:${toContainerPath(p)}`);
|
|
1473
|
-
}
|
|
1474
|
-
async function runContainer({
|
|
1475
|
-
image,
|
|
1476
|
-
userVolumeArgs,
|
|
1477
|
-
commandArgs,
|
|
1478
|
-
entrypoint,
|
|
1479
|
-
env,
|
|
1480
|
-
workdir
|
|
1481
|
-
}) {
|
|
1482
|
-
const commandExists = await importNodeModule("command-exists");
|
|
1483
|
-
if (!await commandExists("docker")) {
|
|
1484
|
-
throw new Error(
|
|
1485
|
-
`Docker isn't be installed. To use this feature, you'll need to install Docker.`
|
|
1486
|
-
);
|
|
1487
|
-
}
|
|
1488
|
-
const versionCmd = await execFileAsync("docker", [
|
|
1489
|
-
"version",
|
|
1490
|
-
"--format",
|
|
1491
|
-
"{{.Server.Version}}"
|
|
1492
|
-
]);
|
|
1493
|
-
const version = versionCmd.stdout.trim();
|
|
1494
|
-
const [major, minor] = version.split(".").map(Number);
|
|
1495
|
-
if (major < 20 || major === 20 && minor < 10) {
|
|
1496
|
-
throw new Error(
|
|
1497
|
-
`Docker version ${version} is not supported. Please upgrade to Docker 20.10.0 or later.`
|
|
1498
|
-
);
|
|
1499
|
-
}
|
|
1500
|
-
try {
|
|
1501
|
-
var _stack = [];
|
|
1502
|
-
try {
|
|
1503
|
-
const _2 = __using(_stack, Logger.suspendLogging("Launching docker container"));
|
|
1504
|
-
const args = [
|
|
1505
|
-
"run",
|
|
1506
|
-
...Logger.isInteractive ? ["-it"] : [],
|
|
1507
|
-
"--rm",
|
|
1508
|
-
...entrypoint ? ["--entrypoint", entrypoint] : [],
|
|
1509
|
-
...env ? env.flatMap(([k, v3]) => ["-e", `${k}=${v3}`]) : [],
|
|
1510
|
-
...process2.env.DEBUG ? ["-e", `DEBUG=${process2.env.DEBUG}`] : [],
|
|
1511
|
-
...userVolumeArgs.flatMap((arg) => ["-v", arg]),
|
|
1512
|
-
...workdir ? ["-w", workdir] : [],
|
|
1513
|
-
image,
|
|
1514
|
-
...commandArgs
|
|
1515
|
-
];
|
|
1516
|
-
Logger.debug(`docker ${args.join(" ")}`);
|
|
1517
|
-
const { execa } = await importNodeModule("execa");
|
|
1518
|
-
const proc = execa("docker", args, {
|
|
1519
|
-
stdio: "inherit"
|
|
1520
|
-
});
|
|
1521
|
-
await proc;
|
|
1522
|
-
} catch (_) {
|
|
1523
|
-
var _error = _, _hasError = true;
|
|
1524
|
-
} finally {
|
|
1525
|
-
__callDispose(_stack, _error, _hasError);
|
|
1526
|
-
}
|
|
1527
|
-
} catch (error) {
|
|
1528
|
-
throw new Error(
|
|
1529
|
-
"An error occurred on the running container. Please see logs above."
|
|
1530
|
-
);
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
async function buildPDFWithContainer({
|
|
1534
|
-
target,
|
|
1535
|
-
config,
|
|
1536
|
-
inlineConfig
|
|
1537
|
-
}) {
|
|
1538
|
-
const sourceUrl = new URL(await getSourceUrl(config));
|
|
1539
|
-
if (sourceUrl.origin === config.rootUrl) {
|
|
1540
|
-
sourceUrl.hostname = CONTAINER_LOCAL_HOSTNAME;
|
|
1541
|
-
}
|
|
1542
|
-
const bypassedOption = {
|
|
1543
|
-
...inlineConfig,
|
|
1544
|
-
input: {
|
|
1545
|
-
format: "webbook",
|
|
1546
|
-
entry: sourceUrl.href
|
|
1547
|
-
},
|
|
1548
|
-
output: [
|
|
1549
|
-
{
|
|
1550
|
-
...target,
|
|
1551
|
-
path: toContainerPath(target.path)
|
|
1552
|
-
}
|
|
1553
|
-
]
|
|
1554
|
-
};
|
|
1555
|
-
await runContainer({
|
|
1556
|
-
image: config.image,
|
|
1557
|
-
userVolumeArgs: collectVolumeArgs([
|
|
1558
|
-
config.context,
|
|
1559
|
-
upath4.dirname(target.path)
|
|
1560
|
-
]),
|
|
1561
|
-
env: [["VS_CLI_BUILD_PDF_OPTIONS", JSON.stringify(bypassedOption)]],
|
|
1562
|
-
commandArgs: ["build"],
|
|
1563
|
-
workdir: toContainerPath(config.context)
|
|
1564
|
-
});
|
|
1565
|
-
return target.path;
|
|
1566
|
-
}
|
|
235
|
+
import upath2 from "upath";
|
|
1567
236
|
|
|
1568
237
|
// src/processor/markdown.ts
|
|
1569
238
|
import {
|
|
1570
239
|
readMetadata
|
|
1571
240
|
} from "@vivliostyle/vfm";
|
|
1572
|
-
import
|
|
241
|
+
import fs2 from "node:fs";
|
|
1573
242
|
import vfile from "vfile";
|
|
1574
243
|
function safeReadMetadata(content) {
|
|
1575
244
|
try {
|
|
@@ -1579,7 +248,7 @@ function safeReadMetadata(content) {
|
|
|
1579
248
|
}
|
|
1580
249
|
}
|
|
1581
250
|
async function processMarkdown(documentProcessorFactory, filepath, options = {}) {
|
|
1582
|
-
const markdownString =
|
|
251
|
+
const markdownString = fs2.readFileSync(filepath, "utf8");
|
|
1583
252
|
const processor = documentProcessorFactory(
|
|
1584
253
|
options,
|
|
1585
254
|
safeReadMetadata(markdownString)
|
|
@@ -1590,7 +259,7 @@ async function processMarkdown(documentProcessorFactory, filepath, options = {})
|
|
|
1590
259
|
return processed;
|
|
1591
260
|
}
|
|
1592
261
|
function readMarkdownMetadata(filepath) {
|
|
1593
|
-
return safeReadMetadata(
|
|
262
|
+
return safeReadMetadata(fs2.readFileSync(filepath, "utf8"));
|
|
1594
263
|
}
|
|
1595
264
|
|
|
1596
265
|
// src/config/resolve.ts
|
|
@@ -1599,6 +268,7 @@ var manuscriptMediaTypes = [
|
|
|
1599
268
|
"text/html",
|
|
1600
269
|
"application/xhtml+xml"
|
|
1601
270
|
];
|
|
271
|
+
var UseTemporaryServerRoot = Symbol("UseTemporaryServerRoot");
|
|
1602
272
|
var DEFAULT_ASSET_EXTENSIONS = [
|
|
1603
273
|
"png",
|
|
1604
274
|
"jpg",
|
|
@@ -1642,18 +312,18 @@ function parseTheme({
|
|
|
1642
312
|
if (isValidUri(specifier)) {
|
|
1643
313
|
return {
|
|
1644
314
|
type: "uri",
|
|
1645
|
-
name:
|
|
315
|
+
name: upath2.basename(specifier),
|
|
1646
316
|
location: specifier
|
|
1647
317
|
};
|
|
1648
318
|
}
|
|
1649
|
-
const stylePath =
|
|
1650
|
-
if (
|
|
1651
|
-
const sourceRelPath =
|
|
319
|
+
const stylePath = upath2.resolve(context, specifier);
|
|
320
|
+
if (fs3.existsSync(stylePath) && stylePath.endsWith(".css")) {
|
|
321
|
+
const sourceRelPath = upath2.relative(context, stylePath);
|
|
1652
322
|
return {
|
|
1653
323
|
type: "file",
|
|
1654
|
-
name:
|
|
324
|
+
name: upath2.basename(specifier),
|
|
1655
325
|
source: stylePath,
|
|
1656
|
-
location:
|
|
326
|
+
location: upath2.resolve(workspaceDir, sourceRelPath)
|
|
1657
327
|
};
|
|
1658
328
|
}
|
|
1659
329
|
const parsed = parsePackageName(specifier, context);
|
|
@@ -1666,9 +336,9 @@ function parseTheme({
|
|
|
1666
336
|
let name = parsed.name;
|
|
1667
337
|
let resolvedSpecifier = specifier;
|
|
1668
338
|
if (parsed.type === "directory" && parsed.fetchSpec) {
|
|
1669
|
-
const pkgJsonPath =
|
|
1670
|
-
if (
|
|
1671
|
-
const packageJson = JSON.parse(
|
|
339
|
+
const pkgJsonPath = upath2.join(parsed.fetchSpec, "package.json");
|
|
340
|
+
if (fs3.existsSync(pkgJsonPath)) {
|
|
341
|
+
const packageJson = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf8"));
|
|
1672
342
|
name = packageJson.name;
|
|
1673
343
|
resolvedSpecifier = parsed.fetchSpec;
|
|
1674
344
|
}
|
|
@@ -1680,7 +350,7 @@ function parseTheme({
|
|
|
1680
350
|
type: "package",
|
|
1681
351
|
name,
|
|
1682
352
|
specifier: resolvedSpecifier,
|
|
1683
|
-
location:
|
|
353
|
+
location: upath2.join(themesDir, "node_modules", name),
|
|
1684
354
|
importPath
|
|
1685
355
|
};
|
|
1686
356
|
}
|
|
@@ -1705,7 +375,7 @@ function parseFileMetadata({
|
|
|
1705
375
|
workspaceDir,
|
|
1706
376
|
themesDir
|
|
1707
377
|
}) {
|
|
1708
|
-
const sourceDir =
|
|
378
|
+
const sourceDir = upath2.dirname(sourcePath);
|
|
1709
379
|
let title;
|
|
1710
380
|
let themes;
|
|
1711
381
|
if (contentType === "text/markdown") {
|
|
@@ -1724,7 +394,7 @@ function parseFileMetadata({
|
|
|
1724
394
|
);
|
|
1725
395
|
}
|
|
1726
396
|
} else {
|
|
1727
|
-
const content =
|
|
397
|
+
const content = fs3.readFileSync(sourcePath, "utf8");
|
|
1728
398
|
title = content.match(/<title>([^<]*)<\/title>/)?.[1] || void 0;
|
|
1729
399
|
}
|
|
1730
400
|
return { title, themes };
|
|
@@ -1732,7 +402,7 @@ function parseFileMetadata({
|
|
|
1732
402
|
function resolveTaskConfig(config, options) {
|
|
1733
403
|
const context = options.cwd ?? cwd;
|
|
1734
404
|
Logger.debug("resolveTaskConfig > context %s", context);
|
|
1735
|
-
const entryContextDir = config.entryContext ?
|
|
405
|
+
const entryContextDir = config.entryContext ? upath2.resolve(context, config.entryContext) : context;
|
|
1736
406
|
const language = config.language;
|
|
1737
407
|
const readingProgression = config.readingProgression;
|
|
1738
408
|
const size = config.size ? parsePageSize(config.size) : void 0;
|
|
@@ -1740,8 +410,8 @@ function resolveTaskConfig(config, options) {
|
|
|
1740
410
|
const bleed = options.bleed;
|
|
1741
411
|
const cropOffset = options.cropOffset;
|
|
1742
412
|
const css = options.css;
|
|
1743
|
-
const customStyle = options.style && (isValidUri(options.style) ? options.style :
|
|
1744
|
-
const customUserStyle = options.userStyle && (isValidUri(options.userStyle) ? options.userStyle :
|
|
413
|
+
const customStyle = options.style && (isValidUri(options.style) ? options.style : pathToFileURL2(options.style).href);
|
|
414
|
+
const customUserStyle = options.userStyle && (isValidUri(options.userStyle) ? options.userStyle : pathToFileURL2(options.userStyle).href);
|
|
1745
415
|
const singleDoc = options.singleDoc ?? false;
|
|
1746
416
|
const quick = options.quick ?? false;
|
|
1747
417
|
const temporaryFilePrefix = config.temporaryFilePrefix ?? `.vs-${Date.now()}.`;
|
|
@@ -1764,7 +434,7 @@ function resolveTaskConfig(config, options) {
|
|
|
1764
434
|
username: options.proxyUser,
|
|
1765
435
|
password: options.proxyPass
|
|
1766
436
|
} : void 0;
|
|
1767
|
-
const image = config.image ??
|
|
437
|
+
const image = config.image ?? `${CONTAINER_URL}:${cliVersion}`;
|
|
1768
438
|
const viewer = config.viewer ?? void 0;
|
|
1769
439
|
const viewerParam = config.viewerParam ?? void 0;
|
|
1770
440
|
const logLevel = options.logLevel ?? "silent";
|
|
@@ -1782,7 +452,7 @@ function resolveTaskConfig(config, options) {
|
|
|
1782
452
|
};
|
|
1783
453
|
if (config.output) {
|
|
1784
454
|
return config.output.map((target) => {
|
|
1785
|
-
const outputPath =
|
|
455
|
+
const outputPath = upath2.resolve(context, target.path);
|
|
1786
456
|
const format = target.format;
|
|
1787
457
|
switch (format) {
|
|
1788
458
|
case "pdf":
|
|
@@ -1814,7 +484,7 @@ function resolveTaskConfig(config, options) {
|
|
|
1814
484
|
return [
|
|
1815
485
|
{
|
|
1816
486
|
...defaultPdfOptions,
|
|
1817
|
-
path:
|
|
487
|
+
path: upath2.resolve(context, filename)
|
|
1818
488
|
}
|
|
1819
489
|
];
|
|
1820
490
|
})();
|
|
@@ -1837,7 +507,7 @@ function resolveTaskConfig(config, options) {
|
|
|
1837
507
|
};
|
|
1838
508
|
})();
|
|
1839
509
|
const cover = config.cover && {
|
|
1840
|
-
src:
|
|
510
|
+
src: upath2.resolve(entryContextDir, config.cover.src),
|
|
1841
511
|
name: config.cover.name || COVER_HTML_IMAGE_ALT
|
|
1842
512
|
};
|
|
1843
513
|
const copyAsset = {
|
|
@@ -1870,7 +540,7 @@ function resolveTaskConfig(config, options) {
|
|
|
1870
540
|
cover
|
|
1871
541
|
});
|
|
1872
542
|
for (const output of outputs) {
|
|
1873
|
-
const relPath =
|
|
543
|
+
const relPath = upath2.relative(context, output.path);
|
|
1874
544
|
if (pathContains(output.path, entryContextDir) || pathEquals(output.path, entryContextDir)) {
|
|
1875
545
|
throw new Error(
|
|
1876
546
|
`The output path is set to "${relPath}", but this will overwrite the original manuscript file. Please specify a different path.`
|
|
@@ -1884,19 +554,18 @@ function resolveTaskConfig(config, options) {
|
|
|
1884
554
|
}
|
|
1885
555
|
const { entries, workspaceDir } = projectConfig;
|
|
1886
556
|
const duplicatedTarget = entries.find(
|
|
1887
|
-
(v1, i) => entries.findLastIndex((
|
|
557
|
+
(v1, i) => entries.findLastIndex((v2) => v1.target === v2.target) !== i
|
|
1888
558
|
)?.target;
|
|
1889
559
|
if (duplicatedTarget) {
|
|
1890
560
|
const sourceFile = entries.find(
|
|
1891
561
|
(entry) => entry.target === duplicatedTarget && entry.source?.type === "file"
|
|
1892
562
|
)?.source;
|
|
1893
563
|
throw new Error(
|
|
1894
|
-
`The output path "${
|
|
564
|
+
`The output path "${upath2.relative(workspaceDir, duplicatedTarget)}" will overwrite existing content.` + (sourceFile ? ` Please choose a different name for the source file: ${sourceFile.pathname}` : "")
|
|
1895
565
|
);
|
|
1896
566
|
}
|
|
1897
567
|
const resolvedConfig = {
|
|
1898
568
|
...projectConfig,
|
|
1899
|
-
context,
|
|
1900
569
|
entryContextDir,
|
|
1901
570
|
outputs,
|
|
1902
571
|
themeIndexes,
|
|
@@ -1943,6 +612,7 @@ function resolveSingleInputConfig({
|
|
|
1943
612
|
base
|
|
1944
613
|
}) {
|
|
1945
614
|
Logger.debug("entering single entry config mode");
|
|
615
|
+
let serverRootDir;
|
|
1946
616
|
let sourcePath;
|
|
1947
617
|
let workspaceDir;
|
|
1948
618
|
const inputFormat = input.format;
|
|
@@ -1952,16 +622,17 @@ function resolveSingleInputConfig({
|
|
|
1952
622
|
const exportAliases = [];
|
|
1953
623
|
if (isValidUri(input.entry)) {
|
|
1954
624
|
sourcePath = input.entry;
|
|
625
|
+
serverRootDir = UseTemporaryServerRoot;
|
|
1955
626
|
workspaceDir = context;
|
|
1956
627
|
} else {
|
|
1957
|
-
sourcePath =
|
|
628
|
+
sourcePath = upath2.resolve(context, input.entry);
|
|
1958
629
|
statFileSync(sourcePath);
|
|
1959
630
|
switch (input.format) {
|
|
1960
631
|
case "webbook":
|
|
1961
632
|
case "markdown":
|
|
1962
633
|
case "pub-manifest":
|
|
1963
634
|
case "epub":
|
|
1964
|
-
workspaceDir =
|
|
635
|
+
workspaceDir = upath2.dirname(sourcePath);
|
|
1965
636
|
break;
|
|
1966
637
|
case "epub-opf": {
|
|
1967
638
|
const rootDir = getEpubRootDir(sourcePath);
|
|
@@ -1976,8 +647,9 @@ function resolveSingleInputConfig({
|
|
|
1976
647
|
default:
|
|
1977
648
|
return input.format;
|
|
1978
649
|
}
|
|
650
|
+
serverRootDir = workspaceDir;
|
|
1979
651
|
}
|
|
1980
|
-
const themesDir =
|
|
652
|
+
const themesDir = upath2.resolve(workspaceDir, "themes");
|
|
1981
653
|
if (input.format === "markdown") {
|
|
1982
654
|
const contentType = "text/markdown";
|
|
1983
655
|
const metadata = parseFileMetadata({
|
|
@@ -1985,9 +657,9 @@ function resolveSingleInputConfig({
|
|
|
1985
657
|
sourcePath,
|
|
1986
658
|
workspaceDir
|
|
1987
659
|
});
|
|
1988
|
-
const target =
|
|
660
|
+
const target = upath2.resolve(
|
|
1989
661
|
workspaceDir,
|
|
1990
|
-
`${temporaryFilePrefix}${
|
|
662
|
+
`${temporaryFilePrefix}${upath2.basename(sourcePath)}`
|
|
1991
663
|
).replace(/\.md$/, ".html");
|
|
1992
664
|
touchTmpFile(target);
|
|
1993
665
|
const themes = metadata.themes ?? config.theme?.map(
|
|
@@ -2012,25 +684,25 @@ function resolveSingleInputConfig({
|
|
|
2012
684
|
});
|
|
2013
685
|
exportAliases.push({
|
|
2014
686
|
source: target,
|
|
2015
|
-
target:
|
|
2016
|
-
|
|
2017
|
-
|
|
687
|
+
target: upath2.resolve(
|
|
688
|
+
upath2.dirname(target),
|
|
689
|
+
upath2.basename(sourcePath).replace(/\.md$/, ".html")
|
|
2018
690
|
)
|
|
2019
691
|
});
|
|
2020
692
|
}
|
|
2021
693
|
let fallbackTitle;
|
|
2022
694
|
let viewerInput;
|
|
2023
695
|
if (inputFormat === "markdown") {
|
|
2024
|
-
const manifestPath =
|
|
696
|
+
const manifestPath = upath2.resolve(
|
|
2025
697
|
workspaceDir,
|
|
2026
698
|
`${temporaryFilePrefix}${MANIFEST_FILENAME}`
|
|
2027
699
|
);
|
|
2028
700
|
touchTmpFile(manifestPath);
|
|
2029
701
|
exportAliases.push({
|
|
2030
702
|
source: manifestPath,
|
|
2031
|
-
target:
|
|
703
|
+
target: upath2.resolve(workspaceDir, MANIFEST_FILENAME)
|
|
2032
704
|
});
|
|
2033
|
-
fallbackTitle = entries.length === 1 && entries[0].title ? entries[0].title :
|
|
705
|
+
fallbackTitle = entries.length === 1 && entries[0].title ? entries[0].title : upath2.basename(sourcePath);
|
|
2034
706
|
viewerInput = {
|
|
2035
707
|
type: "webpub",
|
|
2036
708
|
manifestPath,
|
|
@@ -2046,8 +718,8 @@ function resolveSingleInputConfig({
|
|
|
2046
718
|
}
|
|
2047
719
|
webbookEntryUrl = url.href;
|
|
2048
720
|
} else {
|
|
2049
|
-
const rootFileUrl =
|
|
2050
|
-
const urlPath =
|
|
721
|
+
const rootFileUrl = pathToFileURL2(workspaceDir).href;
|
|
722
|
+
const urlPath = pathToFileURL2(sourcePath).href.slice(rootFileUrl.length);
|
|
2051
723
|
webbookEntryUrl = `${base}${urlPath}`;
|
|
2052
724
|
webbookPath = sourcePath;
|
|
2053
725
|
}
|
|
@@ -2064,15 +736,16 @@ function resolveSingleInputConfig({
|
|
|
2064
736
|
viewerInput = {
|
|
2065
737
|
type: "epub",
|
|
2066
738
|
epubPath: sourcePath,
|
|
2067
|
-
epubTmpOutputDir:
|
|
739
|
+
epubTmpOutputDir: upath2.join(
|
|
2068
740
|
sourcePath,
|
|
2069
|
-
`../${temporaryFilePrefix}${
|
|
741
|
+
`../${temporaryFilePrefix}${upath2.basename(sourcePath)}`
|
|
2070
742
|
)
|
|
2071
743
|
};
|
|
2072
744
|
} else {
|
|
2073
745
|
return inputFormat;
|
|
2074
746
|
}
|
|
2075
747
|
return {
|
|
748
|
+
serverRootDir,
|
|
2076
749
|
workspaceDir,
|
|
2077
750
|
themesDir,
|
|
2078
751
|
entries,
|
|
@@ -2096,13 +769,13 @@ function resolveComposedProjectConfig({
|
|
|
2096
769
|
cover
|
|
2097
770
|
}) {
|
|
2098
771
|
Logger.debug("entering composed project config mode");
|
|
2099
|
-
const workspaceDir =
|
|
772
|
+
const workspaceDir = upath2.resolve(
|
|
2100
773
|
context,
|
|
2101
774
|
config.workspaceDir ?? ".vivliostyle"
|
|
2102
775
|
);
|
|
2103
|
-
const themesDir =
|
|
2104
|
-
const pkgJsonPath =
|
|
2105
|
-
const pkgJson =
|
|
776
|
+
const themesDir = upath2.resolve(workspaceDir, "themes");
|
|
777
|
+
const pkgJsonPath = upath2.resolve(context, "package.json");
|
|
778
|
+
const pkgJson = fs3.existsSync(pkgJsonPath) ? readJSON(pkgJsonPath) : void 0;
|
|
2106
779
|
if (pkgJson) {
|
|
2107
780
|
Logger.debug("located package.json path", pkgJsonPath);
|
|
2108
781
|
}
|
|
@@ -2118,19 +791,19 @@ function resolveComposedProjectConfig({
|
|
|
2118
791
|
rootThemes.forEach((t) => themeIndexes.add(t));
|
|
2119
792
|
const tocConfig = {
|
|
2120
793
|
tocTitle: config.toc?.title ?? config?.tocTitle ?? TOC_TITLE,
|
|
2121
|
-
target:
|
|
794
|
+
target: upath2.resolve(workspaceDir, config.toc?.htmlPath ?? TOC_FILENAME),
|
|
2122
795
|
sectionDepth: config.toc?.sectionDepth ?? 0,
|
|
2123
796
|
transform: {
|
|
2124
797
|
transformDocumentList: config.toc?.transformDocumentList,
|
|
2125
798
|
transformSectionList: config.toc?.transformSectionList
|
|
2126
799
|
}
|
|
2127
800
|
};
|
|
2128
|
-
const coverHtml = config.cover && ("htmlPath" in config.cover && !config.cover.htmlPath ? void 0 :
|
|
801
|
+
const coverHtml = config.cover && ("htmlPath" in config.cover && !config.cover.htmlPath ? void 0 : upath2.resolve(
|
|
2129
802
|
workspaceDir,
|
|
2130
803
|
config.cover?.htmlPath || COVER_HTML_FILENAME
|
|
2131
804
|
));
|
|
2132
805
|
const ensureCoverImage = (src) => {
|
|
2133
|
-
const absPath = src &&
|
|
806
|
+
const absPath = src && upath2.resolve(entryContextDir, src);
|
|
2134
807
|
if (absPath) {
|
|
2135
808
|
statFileSync(absPath, {
|
|
2136
809
|
errorMessage: "Specified cover image does not exist"
|
|
@@ -2149,16 +822,16 @@ function resolveComposedProjectConfig({
|
|
|
2149
822
|
return {
|
|
2150
823
|
type: "uri",
|
|
2151
824
|
href: entryPath,
|
|
2152
|
-
rootDir:
|
|
825
|
+
rootDir: upath2.join(workspaceDir, new URL(entryPath).host)
|
|
2153
826
|
};
|
|
2154
827
|
} else if (entryPath.startsWith("/")) {
|
|
2155
828
|
return {
|
|
2156
829
|
type: "uri",
|
|
2157
830
|
href: entryPath,
|
|
2158
|
-
rootDir:
|
|
831
|
+
rootDir: upath2.join(workspaceDir, "localhost")
|
|
2159
832
|
};
|
|
2160
833
|
}
|
|
2161
|
-
const pathname =
|
|
834
|
+
const pathname = upath2.resolve(entryContextDir, entryPath);
|
|
2162
835
|
statFileSync(pathname);
|
|
2163
836
|
const contentType = mime(pathname);
|
|
2164
837
|
if (!isManuscriptMediaType(contentType)) {
|
|
@@ -2181,9 +854,9 @@ function resolveComposedProjectConfig({
|
|
|
2181
854
|
const getTargetPath = (source) => {
|
|
2182
855
|
switch (source.type) {
|
|
2183
856
|
case "file":
|
|
2184
|
-
return
|
|
857
|
+
return upath2.resolve(
|
|
2185
858
|
workspaceDir,
|
|
2186
|
-
|
|
859
|
+
upath2.relative(entryContextDir, source.pathname).replace(/\.md$/, ".html")
|
|
2187
860
|
);
|
|
2188
861
|
case "uri": {
|
|
2189
862
|
const url = new URL(source.href, "a://dummy");
|
|
@@ -2191,14 +864,14 @@ function resolveComposedProjectConfig({
|
|
|
2191
864
|
if (!/\.\w+$/.test(pathname)) {
|
|
2192
865
|
pathname = `${pathname.replace(/\/$/, "")}/index.html`;
|
|
2193
866
|
}
|
|
2194
|
-
return
|
|
867
|
+
return upath2.join(source.rootDir, pathname);
|
|
2195
868
|
}
|
|
2196
869
|
default:
|
|
2197
870
|
return source;
|
|
2198
871
|
}
|
|
2199
872
|
};
|
|
2200
873
|
if ((isContentsEntry(entry) || isCoverEntry(entry)) && entry.path) {
|
|
2201
|
-
const source =
|
|
874
|
+
const source = upath2.resolve(entryContextDir, entry.path);
|
|
2202
875
|
try {
|
|
2203
876
|
statFileSync(source);
|
|
2204
877
|
} catch (error) {
|
|
@@ -2213,7 +886,7 @@ Maybe you want to set the "output" field instead.`
|
|
|
2213
886
|
if (isContentsEntry(entry)) {
|
|
2214
887
|
const inputInfo = entry.path ? getInputInfo(entry.path) : void 0;
|
|
2215
888
|
const { metadata, ...template } = inputInfo || {};
|
|
2216
|
-
let target = entry.output ?
|
|
889
|
+
let target = entry.output ? upath2.resolve(workspaceDir, entry.output) : inputInfo && getTargetPath(inputInfo);
|
|
2217
890
|
const themes = entry.theme ? [entry.theme].flat().map(
|
|
2218
891
|
(theme) => parseTheme({
|
|
2219
892
|
theme,
|
|
@@ -2225,9 +898,9 @@ Maybe you want to set the "output" field instead.`
|
|
|
2225
898
|
themes.forEach((t) => themeIndexes.add(t));
|
|
2226
899
|
target ??= tocConfig.target;
|
|
2227
900
|
if (inputInfo?.type === "file" && pathEquals(inputInfo.pathname, target)) {
|
|
2228
|
-
const tmpPath =
|
|
2229
|
-
|
|
2230
|
-
`${temporaryFilePrefix}${
|
|
901
|
+
const tmpPath = upath2.resolve(
|
|
902
|
+
upath2.dirname(target),
|
|
903
|
+
`${temporaryFilePrefix}${upath2.basename(target)}`
|
|
2231
904
|
);
|
|
2232
905
|
exportAliases.push({ source: tmpPath, target });
|
|
2233
906
|
touchTmpFile(tmpPath);
|
|
@@ -2248,7 +921,7 @@ Maybe you want to set the "output" field instead.`
|
|
|
2248
921
|
if (isCoverEntry(entry)) {
|
|
2249
922
|
const inputInfo = entry.path ? getInputInfo(entry.path) : void 0;
|
|
2250
923
|
const { metadata, ...template } = inputInfo || {};
|
|
2251
|
-
let target = entry.output ?
|
|
924
|
+
let target = entry.output ? upath2.resolve(workspaceDir, entry.output) : inputInfo && getTargetPath(inputInfo);
|
|
2252
925
|
const themes = entry.theme ? [entry.theme].flat().map(
|
|
2253
926
|
(theme) => parseTheme({
|
|
2254
927
|
theme,
|
|
@@ -2264,14 +937,14 @@ Maybe you want to set the "output" field instead.`
|
|
|
2264
937
|
`A CoverEntryConfig is set in the entry list but a location of cover file is not set. Please set 'cover' property in your config file.`
|
|
2265
938
|
);
|
|
2266
939
|
}
|
|
2267
|
-
target ??=
|
|
940
|
+
target ??= upath2.resolve(
|
|
2268
941
|
workspaceDir,
|
|
2269
942
|
entry.path || coverHtml || COVER_HTML_FILENAME
|
|
2270
943
|
);
|
|
2271
944
|
if (inputInfo?.type === "file" && pathEquals(inputInfo.pathname, target)) {
|
|
2272
|
-
const tmpPath =
|
|
2273
|
-
|
|
2274
|
-
`${temporaryFilePrefix}${
|
|
945
|
+
const tmpPath = upath2.resolve(
|
|
946
|
+
upath2.dirname(target),
|
|
947
|
+
`${temporaryFilePrefix}${upath2.basename(target)}`
|
|
2275
948
|
);
|
|
2276
949
|
exportAliases.push({ source: tmpPath, target });
|
|
2277
950
|
touchTmpFile(tmpPath);
|
|
@@ -2292,7 +965,7 @@ Maybe you want to set the "output" field instead.`
|
|
|
2292
965
|
if (isArticleEntry(entry)) {
|
|
2293
966
|
const inputInfo = getInputInfo(entry.path);
|
|
2294
967
|
const { metadata, ...source } = inputInfo;
|
|
2295
|
-
const target = entry.output ?
|
|
968
|
+
const target = entry.output ? upath2.resolve(workspaceDir, entry.output) : getTargetPath(inputInfo);
|
|
2296
969
|
const themes = entry.theme ? [entry.theme].flat().map(
|
|
2297
970
|
(theme) => parseTheme({ theme, context, workspaceDir, themesDir })
|
|
2298
971
|
) : metadata?.themes ?? [...rootThemes];
|
|
@@ -2315,7 +988,7 @@ Maybe you want to set the "output" field instead.`
|
|
|
2315
988
|
if (entries.length === 1 && entries[0].title) {
|
|
2316
989
|
fallbackProjectTitle = entries[0].title;
|
|
2317
990
|
} else {
|
|
2318
|
-
fallbackProjectTitle =
|
|
991
|
+
fallbackProjectTitle = upath2.basename(outputs[0].path);
|
|
2319
992
|
}
|
|
2320
993
|
}
|
|
2321
994
|
if (!!config?.toc && !entries.find(({ rel }) => rel === "contents")) {
|
|
@@ -2337,16 +1010,17 @@ Maybe you want to set the "output" field instead.`
|
|
|
2337
1010
|
});
|
|
2338
1011
|
}
|
|
2339
1012
|
return {
|
|
1013
|
+
serverRootDir: context,
|
|
2340
1014
|
workspaceDir,
|
|
2341
1015
|
themesDir,
|
|
2342
1016
|
entries,
|
|
2343
1017
|
input: {
|
|
2344
1018
|
format: "pub-manifest",
|
|
2345
|
-
entry:
|
|
1019
|
+
entry: upath2.join(workspaceDir, MANIFEST_FILENAME)
|
|
2346
1020
|
},
|
|
2347
1021
|
viewerInput: {
|
|
2348
1022
|
type: "webpub",
|
|
2349
|
-
manifestPath:
|
|
1023
|
+
manifestPath: upath2.join(workspaceDir, MANIFEST_FILENAME),
|
|
2350
1024
|
needToGenerateManifest: true
|
|
2351
1025
|
},
|
|
2352
1026
|
exportAliases,
|
|
@@ -2355,23 +1029,159 @@ Maybe you want to set the "output" field instead.`
|
|
|
2355
1029
|
};
|
|
2356
1030
|
}
|
|
2357
1031
|
|
|
1032
|
+
// src/browser.ts
|
|
1033
|
+
import fs4 from "node:fs";
|
|
1034
|
+
async function launchBrowser({
|
|
1035
|
+
browserType,
|
|
1036
|
+
proxy,
|
|
1037
|
+
executablePath,
|
|
1038
|
+
headless,
|
|
1039
|
+
noSandbox,
|
|
1040
|
+
disableDevShmUsage
|
|
1041
|
+
}) {
|
|
1042
|
+
const playwright = await importNodeModule("playwright-core");
|
|
1043
|
+
playwright.firefox.executablePath;
|
|
1044
|
+
const options = browserType === "chromium" ? {
|
|
1045
|
+
executablePath,
|
|
1046
|
+
chromiumSandbox: !noSandbox,
|
|
1047
|
+
headless,
|
|
1048
|
+
args: [
|
|
1049
|
+
// #579: disable web security to allow cross-origin requests
|
|
1050
|
+
"--disable-web-security",
|
|
1051
|
+
...disableDevShmUsage ? ["--disable-dev-shm-usage"] : [],
|
|
1052
|
+
// #357: Set devicePixelRatio=1 otherwise it causes layout issues in HiDPI displays
|
|
1053
|
+
...headless ? ["--force-device-scale-factor=1"] : [],
|
|
1054
|
+
// #565: Add --disable-gpu option when running on WSL
|
|
1055
|
+
...isRunningOnWSL() ? ["--disable-gpu"] : [],
|
|
1056
|
+
// set Chromium language to English to avoid locale-dependent issues
|
|
1057
|
+
"--lang=en",
|
|
1058
|
+
...!headless && process.platform === "darwin" ? ["", "-AppleLanguages", "(en)"] : []
|
|
1059
|
+
],
|
|
1060
|
+
env: { ...process.env, LANG: "en.UTF-8" },
|
|
1061
|
+
proxy
|
|
1062
|
+
} : (
|
|
1063
|
+
// TODO: Investigate appropriate settings on Firefox & Webkit
|
|
1064
|
+
{ executablePath, headless }
|
|
1065
|
+
);
|
|
1066
|
+
const browser = await playwright[browserType].launch(options);
|
|
1067
|
+
registerExitHandler("Closing browser", () => {
|
|
1068
|
+
browser.close();
|
|
1069
|
+
});
|
|
1070
|
+
return browser;
|
|
1071
|
+
}
|
|
1072
|
+
async function getExecutableBrowserPath(browserType) {
|
|
1073
|
+
const playwright = await importNodeModule("playwright-core");
|
|
1074
|
+
return playwright[browserType].executablePath();
|
|
1075
|
+
}
|
|
1076
|
+
function getFullBrowserName(browserType) {
|
|
1077
|
+
return {
|
|
1078
|
+
chromium: "Chromium",
|
|
1079
|
+
firefox: "Firefox",
|
|
1080
|
+
webkit: "Webkit"
|
|
1081
|
+
}[browserType];
|
|
1082
|
+
}
|
|
1083
|
+
function checkBrowserAvailability(path) {
|
|
1084
|
+
return fs4.existsSync(path);
|
|
1085
|
+
}
|
|
1086
|
+
async function downloadBrowser(browserType) {
|
|
1087
|
+
const { registry } = await importNodeModule("playwright-core/lib/server");
|
|
1088
|
+
const executable = registry.findExecutable(browserType);
|
|
1089
|
+
{
|
|
1090
|
+
var _stack = [];
|
|
1091
|
+
try {
|
|
1092
|
+
const _2 = __using(_stack, Logger.suspendLogging(
|
|
1093
|
+
"Rendering browser is not installed yet. Downloading now."
|
|
1094
|
+
));
|
|
1095
|
+
await registry.install([executable], false);
|
|
1096
|
+
} catch (_) {
|
|
1097
|
+
var _error = _, _hasError = true;
|
|
1098
|
+
} finally {
|
|
1099
|
+
__callDispose(_stack, _error, _hasError);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
return executable.executablePath();
|
|
1103
|
+
}
|
|
1104
|
+
async function launchPreview({
|
|
1105
|
+
mode,
|
|
1106
|
+
url,
|
|
1107
|
+
onBrowserOpen,
|
|
1108
|
+
onPageOpen,
|
|
1109
|
+
config: { browser: browserConfig, proxy, sandbox, ignoreHttpsErrors }
|
|
1110
|
+
}) {
|
|
1111
|
+
let executableBrowser = browserConfig.executablePath;
|
|
1112
|
+
if (executableBrowser) {
|
|
1113
|
+
if (!checkBrowserAvailability(executableBrowser)) {
|
|
1114
|
+
throw new Error(
|
|
1115
|
+
`Cannot find the browser. Please check the executable browser path: ${executableBrowser}`
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
} else {
|
|
1119
|
+
executableBrowser = await getExecutableBrowserPath(browserConfig.type);
|
|
1120
|
+
if (!checkBrowserAvailability(executableBrowser)) {
|
|
1121
|
+
await downloadBrowser(browserConfig.type);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
Logger.debug(`Executing browser path: ${executableBrowser}`);
|
|
1125
|
+
const browser = await launchBrowser({
|
|
1126
|
+
browserType: browserConfig.type,
|
|
1127
|
+
proxy,
|
|
1128
|
+
executablePath: executableBrowser,
|
|
1129
|
+
headless: mode === "build",
|
|
1130
|
+
noSandbox: !sandbox,
|
|
1131
|
+
disableDevShmUsage: isInContainer()
|
|
1132
|
+
});
|
|
1133
|
+
await onBrowserOpen?.(browser);
|
|
1134
|
+
const page = await browser.newPage({
|
|
1135
|
+
viewport: mode === "build" ? (
|
|
1136
|
+
// This viewport size important to detect headless environment in Vivliostyle viewer
|
|
1137
|
+
// https://github.com/vivliostyle/vivliostyle.js/blob/73bcf323adcad80126b0175630609451ccd09d8a/packages/core/src/vivliostyle/vgen.ts#L2489-L2500
|
|
1138
|
+
{
|
|
1139
|
+
width: 800,
|
|
1140
|
+
height: 600
|
|
1141
|
+
}
|
|
1142
|
+
) : null,
|
|
1143
|
+
ignoreHTTPSErrors: ignoreHttpsErrors
|
|
1144
|
+
});
|
|
1145
|
+
await onPageOpen?.(page);
|
|
1146
|
+
page.on("dialog", () => {
|
|
1147
|
+
});
|
|
1148
|
+
await page.goto(url);
|
|
1149
|
+
return { browser, page };
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
// src/server.ts
|
|
1153
|
+
import fs10 from "node:fs";
|
|
1154
|
+
import { URL as URL2 } from "node:url";
|
|
1155
|
+
import upath10 from "upath";
|
|
1156
|
+
import {
|
|
1157
|
+
createServer,
|
|
1158
|
+
preview
|
|
1159
|
+
} from "vite";
|
|
1160
|
+
|
|
1161
|
+
// src/vite/vite-plugin-dev-server.ts
|
|
1162
|
+
import escapeRe from "escape-string-regexp";
|
|
1163
|
+
import { pathToFileURL as pathToFileURL6 } from "node:url";
|
|
1164
|
+
import picomatch2 from "picomatch";
|
|
1165
|
+
import sirv from "sirv";
|
|
1166
|
+
import upath7 from "upath";
|
|
1167
|
+
|
|
2358
1168
|
// src/processor/compile.ts
|
|
2359
1169
|
import { copy as copy3, move } from "fs-extra/esm";
|
|
2360
|
-
import
|
|
1170
|
+
import fs8 from "node:fs";
|
|
2361
1171
|
import picomatch from "picomatch";
|
|
2362
1172
|
import prettier from "prettier";
|
|
2363
1173
|
import parserHtml from "prettier/parser-html";
|
|
2364
1174
|
import { glob as glob2 } from "tinyglobby";
|
|
2365
|
-
import
|
|
1175
|
+
import upath6 from "upath";
|
|
2366
1176
|
import MIMEType2 from "whatwg-mimetype";
|
|
2367
1177
|
|
|
2368
1178
|
// src/output/webbook.ts
|
|
2369
1179
|
import { copy as copy2 } from "fs-extra/esm";
|
|
2370
1180
|
import { lookup as mime3 } from "mime-types";
|
|
2371
|
-
import
|
|
2372
|
-
import { pathToFileURL as
|
|
1181
|
+
import fs6 from "node:fs";
|
|
1182
|
+
import { pathToFileURL as pathToFileURL5 } from "node:url";
|
|
2373
1183
|
import { glob } from "tinyglobby";
|
|
2374
|
-
import
|
|
1184
|
+
import upath5 from "upath";
|
|
2375
1185
|
|
|
2376
1186
|
// src/processor/html.tsx
|
|
2377
1187
|
import jsdom, {
|
|
@@ -2380,8 +1190,8 @@ import jsdom, {
|
|
|
2380
1190
|
} from "@vivliostyle/jsdom";
|
|
2381
1191
|
import DOMPurify from "dompurify";
|
|
2382
1192
|
import { toHtml } from "hast-util-to-html";
|
|
2383
|
-
import { fileURLToPath
|
|
2384
|
-
import
|
|
1193
|
+
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "node:url";
|
|
1194
|
+
import upath3 from "upath";
|
|
2385
1195
|
import MIMEType from "whatwg-mimetype";
|
|
2386
1196
|
import { jsx, jsxs } from "hastscript/jsx-runtime";
|
|
2387
1197
|
var createVirtualConsole = (onError) => {
|
|
@@ -2441,7 +1251,7 @@ var ResourceLoader = class extends BaseResourceLoader {
|
|
|
2441
1251
|
if (mimeType === "text/html" && !/\.html?$/.test(url.pathname)) {
|
|
2442
1252
|
url.pathname = `${url.pathname.replace(/\/$/, "")}/index.html`;
|
|
2443
1253
|
}
|
|
2444
|
-
let relTarget =
|
|
1254
|
+
let relTarget = upath3.relative(rootHref, url.href);
|
|
2445
1255
|
return decodeURI(relTarget);
|
|
2446
1256
|
};
|
|
2447
1257
|
const fetchedResources = [];
|
|
@@ -2460,7 +1270,7 @@ var ResourceLoader = class extends BaseResourceLoader {
|
|
|
2460
1270
|
} catch (e) {
|
|
2461
1271
|
}
|
|
2462
1272
|
const relTarget = normalizeToLocalPath(url, encodingFormat);
|
|
2463
|
-
const target =
|
|
1273
|
+
const target = upath3.join(outputDir, relTarget);
|
|
2464
1274
|
fetchedResources.push({ url: relTarget, encodingFormat });
|
|
2465
1275
|
writeFileIfChanged(target, buffer);
|
|
2466
1276
|
}).catch(onError);
|
|
@@ -2476,7 +1286,7 @@ async function getJsdomFromUrlOrFile({
|
|
|
2476
1286
|
throw error;
|
|
2477
1287
|
})
|
|
2478
1288
|
}) {
|
|
2479
|
-
const url = isValidUri(src) ? new URL(src) :
|
|
1289
|
+
const url = isValidUri(src) ? new URL(src) : pathToFileURL3(src);
|
|
2480
1290
|
let dom;
|
|
2481
1291
|
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
2482
1292
|
dom = await JSDOM.fromURL(src, {
|
|
@@ -2485,10 +1295,10 @@ async function getJsdomFromUrlOrFile({
|
|
|
2485
1295
|
});
|
|
2486
1296
|
} else if (url.protocol === "file:") {
|
|
2487
1297
|
if (resourceLoader) {
|
|
2488
|
-
const file = resourceLoader._readFile(
|
|
1298
|
+
const file = resourceLoader._readFile(fileURLToPath(url));
|
|
2489
1299
|
resourceLoader.fetcherMap.set(url.href, file);
|
|
2490
1300
|
}
|
|
2491
|
-
dom = await JSDOM.fromFile(
|
|
1301
|
+
dom = await JSDOM.fromFile(fileURLToPath(url), {
|
|
2492
1302
|
virtualConsole,
|
|
2493
1303
|
resources: resourceLoader,
|
|
2494
1304
|
contentType: "text/html; charset=UTF-8"
|
|
@@ -2623,11 +1433,11 @@ async function generateTocListSection({
|
|
|
2623
1433
|
} = transform;
|
|
2624
1434
|
const structure = await Promise.all(
|
|
2625
1435
|
entries.map(async (entry) => {
|
|
2626
|
-
const href = encodeURI(
|
|
1436
|
+
const href = encodeURI(upath3.relative(distDir, entry.target));
|
|
2627
1437
|
const sections = sectionDepth >= 1 ? await getStructuredSectionFromHtml(entry.target, href) : [];
|
|
2628
1438
|
return {
|
|
2629
|
-
title: entry.title ||
|
|
2630
|
-
href: encodeURI(
|
|
1439
|
+
title: entry.title || upath3.basename(entry.target, ".html"),
|
|
1440
|
+
href: encodeURI(upath3.relative(distDir, entry.target)),
|
|
2631
1441
|
sections,
|
|
2632
1442
|
children: []
|
|
2633
1443
|
// TODO
|
|
@@ -2675,7 +1485,7 @@ async function processTocHtml(dom, {
|
|
|
2675
1485
|
const l = document.createElement("link");
|
|
2676
1486
|
l.setAttribute("rel", "publication");
|
|
2677
1487
|
l.setAttribute("type", "application/ld+json");
|
|
2678
|
-
l.setAttribute("href", encodeURI(
|
|
1488
|
+
l.setAttribute("href", encodeURI(upath3.relative(distDir, manifestPath)));
|
|
2679
1489
|
document.head.appendChild(l);
|
|
2680
1490
|
}
|
|
2681
1491
|
const style = document.querySelector("style[data-vv-style]");
|
|
@@ -2937,9 +1747,9 @@ import { XMLBuilder } from "fast-xml-parser";
|
|
|
2937
1747
|
import { copy } from "fs-extra/esm";
|
|
2938
1748
|
import GithubSlugger from "github-slugger";
|
|
2939
1749
|
import { lookup as mime2 } from "mime-types";
|
|
2940
|
-
import
|
|
2941
|
-
import { pathToFileURL as
|
|
2942
|
-
import
|
|
1750
|
+
import fs5 from "node:fs";
|
|
1751
|
+
import { pathToFileURL as pathToFileURL4 } from "node:url";
|
|
1752
|
+
import upath4 from "upath";
|
|
2943
1753
|
import { v4 as uuid } from "uuid";
|
|
2944
1754
|
import serializeToXml from "w3c-xmlserializer";
|
|
2945
1755
|
var TOC_ID = "toc";
|
|
@@ -2953,21 +1763,21 @@ var COVER_IMAGE_MIMETYPES = [
|
|
|
2953
1763
|
"image/webp"
|
|
2954
1764
|
];
|
|
2955
1765
|
var changeExtname = (filepath, newExt) => {
|
|
2956
|
-
let ext =
|
|
1766
|
+
let ext = upath4.extname(filepath);
|
|
2957
1767
|
return `${filepath.slice(0, -ext.length)}${newExt}`;
|
|
2958
1768
|
};
|
|
2959
1769
|
var getRelativeHref = (target, baseUrl, rootUrl) => {
|
|
2960
|
-
const absBasePath =
|
|
2961
|
-
const absRootPath =
|
|
2962
|
-
const hrefUrl = new URL(encodeURI(target),
|
|
1770
|
+
const absBasePath = upath4.join("/", baseUrl);
|
|
1771
|
+
const absRootPath = upath4.join("/", rootUrl);
|
|
1772
|
+
const hrefUrl = new URL(encodeURI(target), pathToFileURL4(absBasePath));
|
|
2963
1773
|
if (hrefUrl.protocol !== "file:") {
|
|
2964
1774
|
return target;
|
|
2965
1775
|
}
|
|
2966
1776
|
if (/\.html?$/.test(hrefUrl.pathname)) {
|
|
2967
1777
|
hrefUrl.pathname = changeExtname(hrefUrl.pathname, ".xhtml");
|
|
2968
1778
|
}
|
|
2969
|
-
const pathname =
|
|
2970
|
-
|
|
1779
|
+
const pathname = upath4.posix.relative(
|
|
1780
|
+
pathToFileURL4(upath4.dirname(absRootPath)).pathname,
|
|
2971
1781
|
hrefUrl.pathname
|
|
2972
1782
|
);
|
|
2973
1783
|
return `${pathname}${hrefUrl.search}${hrefUrl.hash}`;
|
|
@@ -2978,16 +1788,16 @@ var normalizeLocalizableString = (value, availableLanguages) => {
|
|
|
2978
1788
|
}
|
|
2979
1789
|
const values = [value].flat().map((value2) => typeof value2 === "string" ? { value: value2 } : value2);
|
|
2980
1790
|
const localizedValues = values.filter(
|
|
2981
|
-
(
|
|
1791
|
+
(v2) => !!v2.language
|
|
2982
1792
|
);
|
|
2983
1793
|
const preferredLang = lookupLanguage(
|
|
2984
|
-
localizedValues.map((
|
|
1794
|
+
localizedValues.map((v2) => v2.language),
|
|
2985
1795
|
availableLanguages
|
|
2986
1796
|
);
|
|
2987
1797
|
if (preferredLang) {
|
|
2988
|
-
return localizedValues[localizedValues.findIndex((
|
|
1798
|
+
return localizedValues[localizedValues.findIndex((v2) => v2.language === preferredLang)].value;
|
|
2989
1799
|
}
|
|
2990
|
-
return values.find((
|
|
1800
|
+
return values.find((v2) => !v2.language)?.value;
|
|
2991
1801
|
};
|
|
2992
1802
|
var appendManifestProperty = (entry, newProperty) => {
|
|
2993
1803
|
entry.properties = entry.properties ? Array.from(/* @__PURE__ */ new Set([...entry.properties.split(" "), newProperty])).join(
|
|
@@ -3010,10 +1820,10 @@ async function exportEpub({
|
|
|
3010
1820
|
epubVersion
|
|
3011
1821
|
});
|
|
3012
1822
|
const [tmpDir] = await useTmpDirectory();
|
|
3013
|
-
|
|
3014
|
-
await copy(webpubDir,
|
|
1823
|
+
fs5.mkdirSync(upath4.join(tmpDir, "META-INF"), { recursive: true });
|
|
1824
|
+
await copy(webpubDir, upath4.join(tmpDir, "EPUB"));
|
|
3015
1825
|
const uid = `urn:uuid:${uuid()}`;
|
|
3016
|
-
const entryHtmlRelPath = entryHtmlFile &&
|
|
1826
|
+
const entryHtmlRelPath = entryHtmlFile && upath4.relative(webpubDir, upath4.resolve(webpubDir, entryHtmlFile));
|
|
3017
1827
|
const findPublicationLink = (relType, list, filter) => [list].flat().find(
|
|
3018
1828
|
(e) => typeof e === "object" && e.rel === relType && (!filter || filter(e))
|
|
3019
1829
|
);
|
|
@@ -3050,7 +1860,7 @@ async function exportEpub({
|
|
|
3050
1860
|
return acc;
|
|
3051
1861
|
} catch (e) {
|
|
3052
1862
|
}
|
|
3053
|
-
if (!
|
|
1863
|
+
if (!fs5.existsSync(upath4.join(tmpDir, "EPUB", url))) {
|
|
3054
1864
|
return acc;
|
|
3055
1865
|
}
|
|
3056
1866
|
const mediaType = encodingFormat || mime2(url) || "text/plain";
|
|
@@ -3073,7 +1883,7 @@ async function exportEpub({
|
|
|
3073
1883
|
(url) => /\.html?$/.test(url)
|
|
3074
1884
|
);
|
|
3075
1885
|
let tocHtml = htmlFiles.find((f) => f === tocResource?.url);
|
|
3076
|
-
const readingOrder = [manifest.readingOrder || entryHtmlRelPath].flat().flatMap((
|
|
1886
|
+
const readingOrder = [manifest.readingOrder || entryHtmlRelPath].flat().flatMap((v2) => v2 ? typeof v2 === "string" ? { url: v2 } : v2 : []);
|
|
3077
1887
|
if (!tocHtml) {
|
|
3078
1888
|
Logger.logWarn(
|
|
3079
1889
|
"No table of contents document was found. for EPUB output, we recommend to enable `toc` option in your Vivliostyle config file to generate a table of contents document."
|
|
@@ -3104,7 +1914,7 @@ async function exportEpub({
|
|
|
3104
1914
|
text: EPUB_LANDMARKS_COVER_ENTRY
|
|
3105
1915
|
});
|
|
3106
1916
|
}
|
|
3107
|
-
const contextDir =
|
|
1917
|
+
const contextDir = upath4.join(tmpDir, "EPUB");
|
|
3108
1918
|
const processHtml = async (target2) => {
|
|
3109
1919
|
let parseResult;
|
|
3110
1920
|
try {
|
|
@@ -3141,7 +1951,7 @@ async function exportEpub({
|
|
|
3141
1951
|
processResult[target2] = await processHtml(target2);
|
|
3142
1952
|
}
|
|
3143
1953
|
const { document: entryDocument } = processResult[tocHtml].dom.window;
|
|
3144
|
-
const docLanguages = [manifest.inLanguage].flat().filter((
|
|
1954
|
+
const docLanguages = [manifest.inLanguage].flat().filter((v2) => Boolean(v2));
|
|
3145
1955
|
if (docLanguages.length === 0) {
|
|
3146
1956
|
docLanguages.push(entryDocument.documentElement.lang || "en");
|
|
3147
1957
|
}
|
|
@@ -3166,20 +1976,20 @@ async function exportEpub({
|
|
|
3166
1976
|
});
|
|
3167
1977
|
}
|
|
3168
1978
|
if (relManifestPath) {
|
|
3169
|
-
await
|
|
1979
|
+
await fs5.promises.rm(upath4.join(tmpDir, "EPUB", relManifestPath), {
|
|
3170
1980
|
force: true,
|
|
3171
1981
|
recursive: true
|
|
3172
1982
|
});
|
|
3173
1983
|
delete manifestItem[relManifestPath];
|
|
3174
1984
|
}
|
|
3175
|
-
|
|
3176
|
-
|
|
1985
|
+
fs5.writeFileSync(
|
|
1986
|
+
upath4.join(tmpDir, "META-INF/container.xml"),
|
|
3177
1987
|
EPUB_CONTAINER_XML,
|
|
3178
1988
|
"utf8"
|
|
3179
1989
|
);
|
|
3180
1990
|
Logger.debug(`Generating content.opf`);
|
|
3181
|
-
|
|
3182
|
-
|
|
1991
|
+
fs5.writeFileSync(
|
|
1992
|
+
upath4.join(tmpDir, "EPUB/content.opf"),
|
|
3183
1993
|
buildEpubPackageDocument({
|
|
3184
1994
|
epubVersion,
|
|
3185
1995
|
uid,
|
|
@@ -3196,13 +2006,13 @@ async function exportEpub({
|
|
|
3196
2006
|
async function writeAsXhtml(dom, absPath) {
|
|
3197
2007
|
const xhtml = `${XML_DECLARATION}
|
|
3198
2008
|
${serializeToXml(dom.window.document)}`;
|
|
3199
|
-
await
|
|
2009
|
+
await fs5.promises.writeFile(changeExtname(absPath, ".xhtml"), xhtml, "utf8");
|
|
3200
2010
|
}
|
|
3201
2011
|
async function transpileHtmlToXhtml({
|
|
3202
2012
|
target,
|
|
3203
2013
|
contextDir
|
|
3204
2014
|
}) {
|
|
3205
|
-
const absPath =
|
|
2015
|
+
const absPath = upath4.join(contextDir, target);
|
|
3206
2016
|
const dom = await getJsdomFromUrlOrFile({ src: absPath });
|
|
3207
2017
|
const { document } = dom.window;
|
|
3208
2018
|
document.documentElement.removeAttribute("xmlns");
|
|
@@ -3212,7 +2022,7 @@ async function transpileHtmlToXhtml({
|
|
|
3212
2022
|
el.setAttribute("href", getRelativeHref(href, target, target));
|
|
3213
2023
|
});
|
|
3214
2024
|
await writeAsXhtml(dom, absPath);
|
|
3215
|
-
await
|
|
2025
|
+
await fs5.promises.unlink(absPath);
|
|
3216
2026
|
return {
|
|
3217
2027
|
dom,
|
|
3218
2028
|
// FIXME: Yes, I recognize this implementation is inadequate.
|
|
@@ -3270,7 +2080,7 @@ async function processTocDocument({
|
|
|
3270
2080
|
let name = normalizeLocalizableString(content.name, docLanguages);
|
|
3271
2081
|
if (!name) {
|
|
3272
2082
|
const dom2 = await getJsdomFromUrlOrFile({
|
|
3273
|
-
src:
|
|
2083
|
+
src: upath4.join(contextDir, changeExtname(content.url, ".xhtml"))
|
|
3274
2084
|
});
|
|
3275
2085
|
name = dom2.window.document.title;
|
|
3276
2086
|
}
|
|
@@ -3323,7 +2133,7 @@ async function processTocDocument({
|
|
|
3323
2133
|
}
|
|
3324
2134
|
publicationLinkEl.parentNode?.removeChild(publicationLinkEl);
|
|
3325
2135
|
}
|
|
3326
|
-
const absPath =
|
|
2136
|
+
const absPath = upath4.join(contextDir, target);
|
|
3327
2137
|
await writeAsXhtml(dom, absPath);
|
|
3328
2138
|
return { tocResourceTree };
|
|
3329
2139
|
}
|
|
@@ -3338,7 +2148,7 @@ async function processPagelistDocument({
|
|
|
3338
2148
|
nav.setAttribute("id", PAGELIST_ID);
|
|
3339
2149
|
nav.setAttribute("epub:type", "page-list");
|
|
3340
2150
|
}
|
|
3341
|
-
const absPath =
|
|
2151
|
+
const absPath = upath4.join(contextDir, target);
|
|
3342
2152
|
await writeAsXhtml(dom, absPath);
|
|
3343
2153
|
return { pageListResourceTree };
|
|
3344
2154
|
}
|
|
@@ -3355,7 +2165,7 @@ function buildEpubPackageDocument({
|
|
|
3355
2165
|
slugger.reset();
|
|
3356
2166
|
const bookIdentifier = slugger.slug("bookid");
|
|
3357
2167
|
const normalizeDate = (value) => value && `${new Date(value).toISOString().split(".")[0]}Z`;
|
|
3358
|
-
const transformToGenericTextNode = (value, attributes) => [value].flat().filter(Boolean).map((
|
|
2168
|
+
const transformToGenericTextNode = (value, attributes) => [value].flat().filter(Boolean).map((v2) => ({ ...attributes || {}, "#text": `${value}` }));
|
|
3359
2169
|
const transformContributor = (contributorMap) => Object.entries(contributorMap).flatMap(
|
|
3360
2170
|
([type, contributor]) => contributor ? [contributor].flat().map((entry, index) => ({
|
|
3361
2171
|
_id: slugger.slug(`${type}-${index + 1}`),
|
|
@@ -3457,7 +2267,7 @@ async function compressEpub({
|
|
|
3457
2267
|
sourceDir
|
|
3458
2268
|
}) {
|
|
3459
2269
|
Logger.debug(`Compressing EPUB: ${target}`);
|
|
3460
|
-
const output =
|
|
2270
|
+
const output = fs5.createWriteStream(target);
|
|
3461
2271
|
const archive = archiver("zip", {
|
|
3462
2272
|
zlib: { level: 9 }
|
|
3463
2273
|
// Compression level
|
|
@@ -3477,8 +2287,8 @@ async function compressEpub({
|
|
|
3477
2287
|
// https://www.w3.org/TR/epub-33/#sec-zip-container-mime
|
|
3478
2288
|
store: true
|
|
3479
2289
|
});
|
|
3480
|
-
archive.directory(
|
|
3481
|
-
archive.directory(
|
|
2290
|
+
archive.directory(upath4.join(sourceDir, "META-INF"), "META-INF");
|
|
2291
|
+
archive.directory(upath4.join(sourceDir, "EPUB"), "EPUB");
|
|
3482
2292
|
archive.finalize();
|
|
3483
2293
|
});
|
|
3484
2294
|
}
|
|
@@ -3495,11 +2305,11 @@ function sortManifestResources(manifest) {
|
|
|
3495
2305
|
async function prepareWebPublicationDirectory({
|
|
3496
2306
|
outputDir
|
|
3497
2307
|
}) {
|
|
3498
|
-
if (
|
|
2308
|
+
if (fs6.existsSync(outputDir)) {
|
|
3499
2309
|
Logger.debug("going to remove existing webpub", outputDir);
|
|
3500
|
-
await
|
|
2310
|
+
await fs6.promises.rm(outputDir, { force: true, recursive: true });
|
|
3501
2311
|
}
|
|
3502
|
-
|
|
2312
|
+
fs6.mkdirSync(outputDir, { recursive: true });
|
|
3503
2313
|
}
|
|
3504
2314
|
function transformPublicationManifest(entity, transformer) {
|
|
3505
2315
|
const { url: transformUrl } = transformer;
|
|
@@ -3596,15 +2406,15 @@ function writePublicationManifest(output, options) {
|
|
|
3596
2406
|
typeof thrownError === "string" ? thrownError : thrownError.stack ?? thrownError.message
|
|
3597
2407
|
);
|
|
3598
2408
|
}
|
|
3599
|
-
|
|
3600
|
-
|
|
2409
|
+
fs6.mkdirSync(upath5.dirname(output), { recursive: true });
|
|
2410
|
+
fs6.writeFileSync(output, JSON.stringify(encodedManifest, null, 2));
|
|
3601
2411
|
return publication;
|
|
3602
2412
|
}
|
|
3603
2413
|
async function retrieveWebbookEntry({
|
|
3604
2414
|
viewerInput,
|
|
3605
2415
|
outputDir
|
|
3606
2416
|
}) {
|
|
3607
|
-
const webbookEntryUrl = viewerInput.webbookPath ?
|
|
2417
|
+
const webbookEntryUrl = viewerInput.webbookPath ? pathToFileURL5(viewerInput.webbookPath).href : viewerInput.webbookEntryUrl;
|
|
3608
2418
|
if (/^https?:/i.test(webbookEntryUrl)) {
|
|
3609
2419
|
Logger.logUpdate("Fetching remote contents");
|
|
3610
2420
|
}
|
|
@@ -3613,18 +2423,18 @@ async function retrieveWebbookEntry({
|
|
|
3613
2423
|
src: webbookEntryUrl,
|
|
3614
2424
|
resourceLoader
|
|
3615
2425
|
});
|
|
3616
|
-
const entryHtml = viewerInput.webbookPath ?
|
|
2426
|
+
const entryHtml = viewerInput.webbookPath ? upath5.basename(viewerInput.webbookPath) : decodeURI(dom.window.location.pathname);
|
|
3617
2427
|
const { manifest, manifestUrl } = await fetchLinkedPublicationManifest({
|
|
3618
2428
|
dom,
|
|
3619
2429
|
resourceLoader,
|
|
3620
2430
|
baseUrl: webbookEntryUrl
|
|
3621
2431
|
}) || {};
|
|
3622
2432
|
const rootUrl = /^https?:/i.test(webbookEntryUrl) ? new URL("/", webbookEntryUrl).href : new URL(".", webbookEntryUrl).href;
|
|
3623
|
-
const pathContains2 = (url) => !
|
|
2433
|
+
const pathContains2 = (url) => !upath5.relative(rootUrl, url).startsWith("..");
|
|
3624
2434
|
const retriever = new Map(resourceLoader.fetcherMap);
|
|
3625
2435
|
if (manifest && manifestUrl) {
|
|
3626
|
-
[manifest.resources || []].flat().forEach((
|
|
3627
|
-
const url = typeof
|
|
2436
|
+
[manifest.resources || []].flat().forEach((v2) => {
|
|
2437
|
+
const url = typeof v2 === "string" ? v2 : v2.url;
|
|
3628
2438
|
const fullUrl = new URL(encodeURI(url), manifestUrl).href;
|
|
3629
2439
|
if (!pathContains2(fullUrl) || retriever.has(fullUrl)) {
|
|
3630
2440
|
return;
|
|
@@ -3634,9 +2444,9 @@ async function retrieveWebbookEntry({
|
|
|
3634
2444
|
retriever.set(fullUrl, fetchPromise);
|
|
3635
2445
|
}
|
|
3636
2446
|
});
|
|
3637
|
-
for (const
|
|
3638
|
-
const url = typeof
|
|
3639
|
-
if (!/\.html?$/.test(url) && !(typeof
|
|
2447
|
+
for (const v2 of [manifest.readingOrder || []].flat()) {
|
|
2448
|
+
const url = typeof v2 === "string" ? v2 : v2.url;
|
|
2449
|
+
if (!/\.html?$/.test(url) && !(typeof v2 === "string" || v2.encodingFormat === "text/html")) {
|
|
3640
2450
|
continue;
|
|
3641
2451
|
}
|
|
3642
2452
|
const fullUrl = new URL(encodeURI(url), manifestUrl).href;
|
|
@@ -3652,7 +2462,7 @@ async function retrieveWebbookEntry({
|
|
|
3652
2462
|
})
|
|
3653
2463
|
});
|
|
3654
2464
|
subpathResourceLoader.fetcherMap.forEach(
|
|
3655
|
-
(
|
|
2465
|
+
(v3, k) => !retriever.has(k) && retriever.set(k, v3)
|
|
3656
2466
|
);
|
|
3657
2467
|
}
|
|
3658
2468
|
}
|
|
@@ -3670,7 +2480,7 @@ async function retrieveWebbookEntry({
|
|
|
3670
2480
|
const referencedContents = [
|
|
3671
2481
|
...[manifest.readingOrder || []].flat(),
|
|
3672
2482
|
...[manifest.resources || []].flat()
|
|
3673
|
-
].map((
|
|
2483
|
+
].map((v2) => typeof v2 === "string" ? v2 : v2.url);
|
|
3674
2484
|
manifest.resources = [
|
|
3675
2485
|
...[manifest.resources || []].flat(),
|
|
3676
2486
|
...fetchedResources.filter(
|
|
@@ -3681,14 +2491,14 @@ async function retrieveWebbookEntry({
|
|
|
3681
2491
|
}
|
|
3682
2492
|
Logger.debug(
|
|
3683
2493
|
"Saved webbook resources",
|
|
3684
|
-
fetchedResources.map((
|
|
2494
|
+
fetchedResources.map((v2) => v2.url)
|
|
3685
2495
|
);
|
|
3686
2496
|
Logger.debug(
|
|
3687
2497
|
"Publication manifest from webbook",
|
|
3688
2498
|
manifest && JSON.stringify(manifest, null, 2)
|
|
3689
2499
|
);
|
|
3690
2500
|
return {
|
|
3691
|
-
entryHtmlFile:
|
|
2501
|
+
entryHtmlFile: upath5.join(outputDir, entryHtml),
|
|
3692
2502
|
manifest
|
|
3693
2503
|
};
|
|
3694
2504
|
}
|
|
@@ -3703,12 +2513,12 @@ async function supplyWebPublicationManifestForWebbook({
|
|
|
3703
2513
|
const language = config.language || document.documentElement.lang || void 0;
|
|
3704
2514
|
const title = config.title || document.title || "";
|
|
3705
2515
|
const author = config.author || document.querySelector('meta[name="author"]')?.getAttribute("content") || "";
|
|
3706
|
-
const entry =
|
|
2516
|
+
const entry = upath5.relative(outputDir, entryHtmlFile);
|
|
3707
2517
|
const allFiles = await glob("**", {
|
|
3708
2518
|
cwd: outputDir
|
|
3709
2519
|
});
|
|
3710
2520
|
const manifest = writePublicationManifest(
|
|
3711
|
-
|
|
2521
|
+
upath5.join(outputDir, MANIFEST_FILENAME),
|
|
3712
2522
|
{
|
|
3713
2523
|
title,
|
|
3714
2524
|
author,
|
|
@@ -3725,13 +2535,13 @@ async function supplyWebPublicationManifestForWebbook({
|
|
|
3725
2535
|
link.setAttribute("type", "application/ld+json");
|
|
3726
2536
|
link.setAttribute(
|
|
3727
2537
|
"href",
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
2538
|
+
upath5.relative(
|
|
2539
|
+
upath5.dirname(entryHtmlFile),
|
|
2540
|
+
upath5.join(outputDir, MANIFEST_FILENAME)
|
|
3731
2541
|
)
|
|
3732
2542
|
);
|
|
3733
2543
|
document.head.appendChild(link);
|
|
3734
|
-
await
|
|
2544
|
+
await fs6.promises.writeFile(entryHtmlFile, dom.serialize(), "utf8");
|
|
3735
2545
|
Logger.debug(
|
|
3736
2546
|
"Generated publication manifest from HTML",
|
|
3737
2547
|
JSON.stringify(manifest, null, 2)
|
|
@@ -3749,8 +2559,8 @@ async function copyWebPublicationAssets({
|
|
|
3749
2559
|
entries
|
|
3750
2560
|
}) {
|
|
3751
2561
|
const relExportAliases = exportAliases.map(({ source, target }) => ({
|
|
3752
|
-
source:
|
|
3753
|
-
target:
|
|
2562
|
+
source: upath5.relative(input, source),
|
|
2563
|
+
target: upath5.relative(input, target)
|
|
3754
2564
|
})).filter(({ source }) => !source.startsWith(".."));
|
|
3755
2565
|
const allFiles = /* @__PURE__ */ new Set([
|
|
3756
2566
|
...await globAssetFiles({
|
|
@@ -3762,7 +2572,7 @@ async function copyWebPublicationAssets({
|
|
|
3762
2572
|
}),
|
|
3763
2573
|
...await glob(
|
|
3764
2574
|
[
|
|
3765
|
-
`**/${
|
|
2575
|
+
`**/${upath5.relative(input, manifestPath)}`,
|
|
3766
2576
|
"**/*.{html,htm,xhtml,xht,css}"
|
|
3767
2577
|
],
|
|
3768
2578
|
{
|
|
@@ -3803,24 +2613,24 @@ async function copyWebPublicationAssets({
|
|
|
3803
2613
|
)
|
|
3804
2614
|
);
|
|
3805
2615
|
const resources = [];
|
|
3806
|
-
let actualManifestPath =
|
|
2616
|
+
let actualManifestPath = upath5.join(
|
|
3807
2617
|
outputDir,
|
|
3808
|
-
|
|
2618
|
+
upath5.relative(input, manifestPath)
|
|
3809
2619
|
);
|
|
3810
2620
|
for (const file of allFiles) {
|
|
3811
2621
|
const alias = relExportAliases.find(({ source }) => source === file);
|
|
3812
2622
|
const relTarget = alias?.target || file;
|
|
3813
2623
|
resources.push(relTarget);
|
|
3814
|
-
const target =
|
|
3815
|
-
|
|
3816
|
-
await copy2(
|
|
3817
|
-
if (alias && pathEquals(
|
|
2624
|
+
const target = upath5.join(outputDir, relTarget);
|
|
2625
|
+
fs6.mkdirSync(upath5.dirname(target), { recursive: true });
|
|
2626
|
+
await copy2(upath5.join(input, file), target);
|
|
2627
|
+
if (alias && pathEquals(upath5.join(input, alias.source), manifestPath)) {
|
|
3818
2628
|
actualManifestPath = target;
|
|
3819
2629
|
}
|
|
3820
2630
|
}
|
|
3821
2631
|
Logger.debug("webbook publication.json", actualManifestPath);
|
|
3822
2632
|
const manifest = decodePublicationManifest(
|
|
3823
|
-
JSON.parse(
|
|
2633
|
+
JSON.parse(fs6.readFileSync(actualManifestPath, "utf8"))
|
|
3824
2634
|
);
|
|
3825
2635
|
for (const entry of relExportAliases) {
|
|
3826
2636
|
const rewriteAliasPath = (e) => {
|
|
@@ -3852,14 +2662,14 @@ async function copyWebPublicationAssets({
|
|
|
3852
2662
|
...[manifest.resources || []].flat(),
|
|
3853
2663
|
...resources.flatMap((file) => {
|
|
3854
2664
|
if (preDefinedResources.includes(file) || // Omit publication.json itself
|
|
3855
|
-
pathEquals(file,
|
|
2665
|
+
pathEquals(file, upath5.relative(outputDir, actualManifestPath))) {
|
|
3856
2666
|
return [];
|
|
3857
2667
|
}
|
|
3858
2668
|
return file;
|
|
3859
2669
|
})
|
|
3860
2670
|
];
|
|
3861
2671
|
sortManifestResources(manifest);
|
|
3862
|
-
|
|
2672
|
+
fs6.writeFileSync(
|
|
3863
2673
|
actualManifestPath,
|
|
3864
2674
|
JSON.stringify(encodePublicationManifest(manifest), null, 2)
|
|
3865
2675
|
);
|
|
@@ -3891,7 +2701,7 @@ async function buildWebPublication({
|
|
|
3891
2701
|
if (config.input.format === "markdown") {
|
|
3892
2702
|
const entry = [manifest.readingOrder].flat()[0];
|
|
3893
2703
|
if (entry) {
|
|
3894
|
-
entryHtmlFile =
|
|
2704
|
+
entryHtmlFile = upath5.join(
|
|
3895
2705
|
outputDir,
|
|
3896
2706
|
typeof entry === "string" ? entry : entry.url
|
|
3897
2707
|
);
|
|
@@ -3916,7 +2726,7 @@ async function buildWebPublication({
|
|
|
3916
2726
|
webpubDir: outputDir,
|
|
3917
2727
|
entryHtmlFile,
|
|
3918
2728
|
manifest,
|
|
3919
|
-
relManifestPath: actualManifestPath &&
|
|
2729
|
+
relManifestPath: actualManifestPath && upath5.relative(outputDir, actualManifestPath),
|
|
3920
2730
|
target: target.path,
|
|
3921
2731
|
epubVersion: target.version
|
|
3922
2732
|
});
|
|
@@ -3926,12 +2736,12 @@ async function buildWebPublication({
|
|
|
3926
2736
|
|
|
3927
2737
|
// src/processor/theme.ts
|
|
3928
2738
|
import Arborist from "@npmcli/arborist";
|
|
3929
|
-
import
|
|
2739
|
+
import fs7 from "node:fs";
|
|
3930
2740
|
async function checkThemeInstallationNecessity({
|
|
3931
2741
|
themesDir,
|
|
3932
2742
|
themeIndexes
|
|
3933
2743
|
}) {
|
|
3934
|
-
if (!
|
|
2744
|
+
if (!fs7.existsSync(themesDir)) {
|
|
3935
2745
|
return [...themeIndexes].some((theme) => theme.type === "package");
|
|
3936
2746
|
}
|
|
3937
2747
|
const commonOpt = {
|
|
@@ -3949,7 +2759,7 @@ async function installThemeDependencies({
|
|
|
3949
2759
|
themesDir,
|
|
3950
2760
|
themeIndexes
|
|
3951
2761
|
}) {
|
|
3952
|
-
|
|
2762
|
+
fs7.mkdirSync(themesDir, { recursive: true });
|
|
3953
2763
|
try {
|
|
3954
2764
|
const commonOpt = {
|
|
3955
2765
|
path: themesDir,
|
|
@@ -3964,7 +2774,7 @@ async function installThemeDependencies({
|
|
|
3964
2774
|
)
|
|
3965
2775
|
)
|
|
3966
2776
|
];
|
|
3967
|
-
const rm = existing.filter((
|
|
2777
|
+
const rm = existing.filter((v2) => !add.includes(v2));
|
|
3968
2778
|
const opt = { ...commonOpt, rm, add };
|
|
3969
2779
|
const arb = new Arborist(opt);
|
|
3970
2780
|
await arb.reify(opt);
|
|
@@ -3984,21 +2794,21 @@ function locateThemePath(theme, from) {
|
|
|
3984
2794
|
return theme.location;
|
|
3985
2795
|
}
|
|
3986
2796
|
if (theme.type === "file") {
|
|
3987
|
-
return
|
|
2797
|
+
return upath6.relative(from, theme.location);
|
|
3988
2798
|
}
|
|
3989
2799
|
if (theme.importPath) {
|
|
3990
2800
|
return [theme.importPath].flat().map((locator) => {
|
|
3991
|
-
const resolvedPath =
|
|
3992
|
-
if (!pathContains(theme.location, resolvedPath) || !
|
|
2801
|
+
const resolvedPath = upath6.resolve(theme.location, locator);
|
|
2802
|
+
if (!pathContains(theme.location, resolvedPath) || !fs8.existsSync(resolvedPath)) {
|
|
3993
2803
|
throw new Error(
|
|
3994
2804
|
`Could not find a style path ${theme.importPath} for the theme: ${theme.name}.`
|
|
3995
2805
|
);
|
|
3996
2806
|
}
|
|
3997
|
-
return
|
|
2807
|
+
return upath6.relative(from, resolvedPath);
|
|
3998
2808
|
});
|
|
3999
2809
|
} else {
|
|
4000
|
-
const pkgJsonPath =
|
|
4001
|
-
const packageJson = JSON.parse(
|
|
2810
|
+
const pkgJsonPath = upath6.join(theme.location, "package.json");
|
|
2811
|
+
const packageJson = JSON.parse(fs8.readFileSync(pkgJsonPath, "utf8"));
|
|
4002
2812
|
const maybeStyle = packageJson?.vivliostyle?.theme?.style ?? packageJson.style ?? packageJson.main;
|
|
4003
2813
|
if (!maybeStyle) {
|
|
4004
2814
|
throw new DetailError(
|
|
@@ -4006,7 +2816,7 @@ function locateThemePath(theme, from) {
|
|
|
4006
2816
|
"Please ensure this package satisfies a `vivliostyle.theme.style` property."
|
|
4007
2817
|
);
|
|
4008
2818
|
}
|
|
4009
|
-
return
|
|
2819
|
+
return upath6.relative(from, upath6.join(theme.location, maybeStyle));
|
|
4010
2820
|
}
|
|
4011
2821
|
}
|
|
4012
2822
|
async function cleanupWorkspace({
|
|
@@ -4022,27 +2832,27 @@ async function cleanupWorkspace({
|
|
|
4022
2832
|
}
|
|
4023
2833
|
Logger.debug("cleanup workspace files", workspaceDir);
|
|
4024
2834
|
let movedWorkspacePath;
|
|
4025
|
-
if (pathContains(workspaceDir, themesDir) &&
|
|
4026
|
-
movedWorkspacePath =
|
|
4027
|
-
|
|
2835
|
+
if (pathContains(workspaceDir, themesDir) && fs8.existsSync(themesDir)) {
|
|
2836
|
+
movedWorkspacePath = upath6.join(
|
|
2837
|
+
upath6.dirname(workspaceDir),
|
|
4028
2838
|
`.vs-${Date.now()}`
|
|
4029
2839
|
);
|
|
4030
|
-
const movedThemePath =
|
|
2840
|
+
const movedThemePath = upath6.join(
|
|
4031
2841
|
movedWorkspacePath,
|
|
4032
|
-
|
|
2842
|
+
upath6.relative(workspaceDir, themesDir)
|
|
4033
2843
|
);
|
|
4034
|
-
|
|
2844
|
+
fs8.mkdirSync(upath6.dirname(movedThemePath), { recursive: true });
|
|
4035
2845
|
registerExitHandler(
|
|
4036
2846
|
`Removing the moved workspace directory: ${movedWorkspacePath}`,
|
|
4037
2847
|
() => {
|
|
4038
|
-
if (movedWorkspacePath &&
|
|
4039
|
-
|
|
2848
|
+
if (movedWorkspacePath && fs8.existsSync(movedWorkspacePath)) {
|
|
2849
|
+
fs8.rmSync(movedWorkspacePath, { recursive: true, force: true });
|
|
4040
2850
|
}
|
|
4041
2851
|
}
|
|
4042
2852
|
);
|
|
4043
2853
|
await move(themesDir, movedThemePath);
|
|
4044
2854
|
}
|
|
4045
|
-
await
|
|
2855
|
+
await fs8.promises.rm(workspaceDir, { recursive: true, force: true });
|
|
4046
2856
|
if (movedWorkspacePath) {
|
|
4047
2857
|
await move(movedWorkspacePath, workspaceDir);
|
|
4048
2858
|
}
|
|
@@ -4051,10 +2861,10 @@ async function prepareThemeDirectory({
|
|
|
4051
2861
|
themesDir,
|
|
4052
2862
|
themeIndexes
|
|
4053
2863
|
}) {
|
|
4054
|
-
if (
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
2864
|
+
if (fs8.existsSync(upath6.join(themesDir, "packages")) && !fs8.existsSync(upath6.join(themesDir, "node_modules"))) {
|
|
2865
|
+
fs8.renameSync(
|
|
2866
|
+
upath6.join(themesDir, "packages"),
|
|
2867
|
+
upath6.join(themesDir, "node_modules")
|
|
4058
2868
|
);
|
|
4059
2869
|
}
|
|
4060
2870
|
if (await checkThemeInstallationNecessity({ themesDir, themeIndexes })) {
|
|
@@ -4063,7 +2873,7 @@ async function prepareThemeDirectory({
|
|
|
4063
2873
|
}
|
|
4064
2874
|
for (const theme of themeIndexes) {
|
|
4065
2875
|
if (theme.type === "file" && !pathEquals(theme.source, theme.location)) {
|
|
4066
|
-
|
|
2876
|
+
fs8.mkdirSync(upath6.dirname(theme.location), { recursive: true });
|
|
4067
2877
|
await copy3(theme.source, theme.location);
|
|
4068
2878
|
}
|
|
4069
2879
|
}
|
|
@@ -4084,7 +2894,7 @@ async function transformManuscript(entry, {
|
|
|
4084
2894
|
let resourceLoader;
|
|
4085
2895
|
let resourceUrl;
|
|
4086
2896
|
const style = entry.themes.flatMap(
|
|
4087
|
-
(theme) => locateThemePath(theme,
|
|
2897
|
+
(theme) => locateThemePath(theme, upath6.dirname(entry.target))
|
|
4088
2898
|
);
|
|
4089
2899
|
if (source?.type === "file") {
|
|
4090
2900
|
if (source.contentType === "text/markdown") {
|
|
@@ -4179,7 +2989,7 @@ async function transformManuscript(entry, {
|
|
|
4179
2989
|
content = await processTocHtml(content, {
|
|
4180
2990
|
entries: manuscriptEntries,
|
|
4181
2991
|
manifestPath,
|
|
4182
|
-
distDir:
|
|
2992
|
+
distDir: upath6.dirname(contentsEntry.target),
|
|
4183
2993
|
tocTitle: contentsEntry.tocTitle,
|
|
4184
2994
|
sectionDepth: contentsEntry.sectionDepth,
|
|
4185
2995
|
styleOptions: contentsEntry,
|
|
@@ -4189,10 +2999,10 @@ async function transformManuscript(entry, {
|
|
|
4189
2999
|
if (entry.rel === "cover") {
|
|
4190
3000
|
const coverEntry = entry;
|
|
4191
3001
|
content = await processCoverHtml(content, {
|
|
4192
|
-
imageSrc:
|
|
4193
|
-
|
|
3002
|
+
imageSrc: upath6.relative(
|
|
3003
|
+
upath6.join(
|
|
4194
3004
|
entryContextDir,
|
|
4195
|
-
|
|
3005
|
+
upath6.relative(workspaceDir, coverEntry.target),
|
|
4196
3006
|
".."
|
|
4197
3007
|
),
|
|
4198
3008
|
coverEntry.coverImageSrc
|
|
@@ -4239,7 +3049,7 @@ async function generateManifest({
|
|
|
4239
3049
|
}) {
|
|
4240
3050
|
const manifestEntries = entries.map((entry) => ({
|
|
4241
3051
|
title: entry.rel === "contents" && entry.tocTitle || entry.title,
|
|
4242
|
-
path:
|
|
3052
|
+
path: upath6.relative(workspaceDir, entry.target),
|
|
4243
3053
|
encodingFormat: !("contentType" in entry) || entry.contentType === "text/markdown" || entry.contentType === "text/html" ? void 0 : entry.contentType,
|
|
4244
3054
|
rel: entry.rel
|
|
4245
3055
|
}));
|
|
@@ -4249,7 +3059,7 @@ async function generateManifest({
|
|
|
4249
3059
|
language,
|
|
4250
3060
|
readingProgression,
|
|
4251
3061
|
cover: cover && {
|
|
4252
|
-
url:
|
|
3062
|
+
url: upath6.relative(entryContextDir, cover.src),
|
|
4253
3063
|
name: cover.name
|
|
4254
3064
|
},
|
|
4255
3065
|
entries: manifestEntries,
|
|
@@ -4277,8 +3087,8 @@ function getIgnoreThemeExamplePatterns({
|
|
|
4277
3087
|
cwd: cwd2
|
|
4278
3088
|
}) {
|
|
4279
3089
|
return pathContains(cwd2, themesDir) ? [
|
|
4280
|
-
`${
|
|
4281
|
-
`${
|
|
3090
|
+
`${upath6.relative(cwd2, themesDir)}/node_modules/*/example`,
|
|
3091
|
+
`${upath6.relative(cwd2, themesDir)}/node_modules/*/*/example`
|
|
4282
3092
|
] : [];
|
|
4283
3093
|
}
|
|
4284
3094
|
function getIgnoreAssetPatterns({
|
|
@@ -4288,10 +3098,10 @@ function getIgnoreAssetPatterns({
|
|
|
4288
3098
|
}) {
|
|
4289
3099
|
return [
|
|
4290
3100
|
...outputs.flatMap(
|
|
4291
|
-
({ format, path: p }) => !pathContains(cwd2, p) ? [] : format === "webpub" ?
|
|
3101
|
+
({ format, path: p }) => !pathContains(cwd2, p) ? [] : format === "webpub" ? upath6.join(upath6.relative(cwd2, p), "**") : upath6.relative(cwd2, p)
|
|
4292
3102
|
),
|
|
4293
3103
|
...entries.flatMap(({ template }) => {
|
|
4294
|
-
return template?.type === "file" && pathContains(cwd2, template.pathname) ?
|
|
3104
|
+
return template?.type === "file" && pathContains(cwd2, template.pathname) ? upath6.relative(cwd2, template.pathname) : [];
|
|
4295
3105
|
})
|
|
4296
3106
|
];
|
|
4297
3107
|
}
|
|
@@ -4359,7 +3169,7 @@ async function copyAssets({
|
|
|
4359
3169
|
if (pathEquals(entryContextDir, workspaceDir)) {
|
|
4360
3170
|
return;
|
|
4361
3171
|
}
|
|
4362
|
-
const relWorkspaceDir =
|
|
3172
|
+
const relWorkspaceDir = upath6.relative(entryContextDir, workspaceDir);
|
|
4363
3173
|
const assets = await globAssetFiles({
|
|
4364
3174
|
copyAsset,
|
|
4365
3175
|
cwd: entryContextDir,
|
|
@@ -4368,14 +3178,14 @@ async function copyAssets({
|
|
|
4368
3178
|
entries,
|
|
4369
3179
|
ignore: [
|
|
4370
3180
|
// don't copy workspace itself
|
|
4371
|
-
...relWorkspaceDir ? [
|
|
3181
|
+
...relWorkspaceDir ? [upath6.join(relWorkspaceDir, "**")] : []
|
|
4372
3182
|
]
|
|
4373
3183
|
});
|
|
4374
3184
|
Logger.debug("assets", assets);
|
|
4375
3185
|
for (const asset of assets) {
|
|
4376
|
-
const target =
|
|
4377
|
-
|
|
4378
|
-
await copy3(
|
|
3186
|
+
const target = upath6.join(workspaceDir, asset);
|
|
3187
|
+
fs8.mkdirSync(upath6.dirname(target), { recursive: true });
|
|
3188
|
+
await copy3(upath6.resolve(entryContextDir, asset), target);
|
|
4379
3189
|
}
|
|
4380
3190
|
}
|
|
4381
3191
|
|
|
@@ -4402,16 +3212,16 @@ function createEntriesRouteLookup(entries, cwd2) {
|
|
|
4402
3212
|
if (uri.charCodeAt(len) === 47) {
|
|
4403
3213
|
uri = uri.substring(0, len);
|
|
4404
3214
|
}
|
|
4405
|
-
let arr = [],
|
|
3215
|
+
let arr = [], tmp = `${uri}/index`;
|
|
4406
3216
|
for (; i < extns.length; i++) {
|
|
4407
3217
|
x = extns[i] ? `.${extns[i]}` : "";
|
|
4408
3218
|
if (uri) arr.push(uri + x);
|
|
4409
|
-
arr.push(
|
|
3219
|
+
arr.push(tmp + x);
|
|
4410
3220
|
}
|
|
4411
3221
|
return arr;
|
|
4412
3222
|
};
|
|
4413
3223
|
const cache = entries.reduce((acc, e) => {
|
|
4414
|
-
acc[`/${
|
|
3224
|
+
acc[`/${upath7.relative(cwd2, e.target).normalize().replace(/\\+/g, "/")}`] = e;
|
|
4415
3225
|
return acc;
|
|
4416
3226
|
}, {});
|
|
4417
3227
|
return (uri) => {
|
|
@@ -4430,12 +3240,12 @@ function getWorkspaceMatcher({
|
|
|
4430
3240
|
let entryFiles = [];
|
|
4431
3241
|
switch (viewerInput.type) {
|
|
4432
3242
|
case "webpub":
|
|
4433
|
-
entryFiles = [
|
|
3243
|
+
entryFiles = [upath7.relative(workspaceDir, viewerInput.manifestPath)];
|
|
4434
3244
|
break;
|
|
4435
3245
|
case "epub":
|
|
4436
3246
|
entryFiles = [
|
|
4437
|
-
|
|
4438
|
-
|
|
3247
|
+
upath7.join(
|
|
3248
|
+
upath7.relative(workspaceDir, viewerInput.epubTmpOutputDir),
|
|
4439
3249
|
"**"
|
|
4440
3250
|
)
|
|
4441
3251
|
];
|
|
@@ -4450,9 +3260,9 @@ function getWorkspaceMatcher({
|
|
|
4450
3260
|
return picomatch2(
|
|
4451
3261
|
[
|
|
4452
3262
|
...entryFiles,
|
|
4453
|
-
...pathContains(workspaceDir, themesDir) ? [
|
|
3263
|
+
...pathContains(workspaceDir, themesDir) ? [upath7.join(upath7.relative(workspaceDir, themesDir), "**")] : [],
|
|
4454
3264
|
...[...themeIndexes].flatMap(
|
|
4455
|
-
(theme) => theme.type === "file" && pathContains(workspaceDir, theme.location) ? [
|
|
3265
|
+
(theme) => theme.type === "file" && pathContains(workspaceDir, theme.location) ? [upath7.relative(workspaceDir, theme.location)] : []
|
|
4456
3266
|
)
|
|
4457
3267
|
],
|
|
4458
3268
|
{ dot: true, ignore: ["node_modules/**"] }
|
|
@@ -4542,8 +3352,8 @@ function vsDevServerPlugin({
|
|
|
4542
3352
|
return await promise;
|
|
4543
3353
|
}
|
|
4544
3354
|
async function invalidate(entry, config2) {
|
|
4545
|
-
const cwd2 =
|
|
4546
|
-
const target =
|
|
3355
|
+
const cwd2 = pathToFileURL6(config2.workspaceDir);
|
|
3356
|
+
const target = pathToFileURL6(entry.target);
|
|
4547
3357
|
if (target.href.indexOf(cwd2.href) !== 0) {
|
|
4548
3358
|
return;
|
|
4549
3359
|
}
|
|
@@ -4677,23 +3487,28 @@ function vsDevServerPlugin({
|
|
|
4677
3487
|
|
|
4678
3488
|
// src/vite/vite-plugin-static-serve.ts
|
|
4679
3489
|
import sirv2 from "sirv";
|
|
4680
|
-
import
|
|
3490
|
+
import upath8 from "upath";
|
|
4681
3491
|
function vsStaticServePlugin({
|
|
4682
3492
|
config: _config,
|
|
4683
3493
|
inlineConfig
|
|
4684
3494
|
}) {
|
|
4685
3495
|
let config = _config;
|
|
4686
|
-
const createMiddlewares = () =>
|
|
4687
|
-
(
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
3496
|
+
const createMiddlewares = () => {
|
|
3497
|
+
if (typeof config.serverRootDir !== "string") {
|
|
3498
|
+
return [];
|
|
3499
|
+
}
|
|
3500
|
+
return Object.entries(config.static).flatMap(
|
|
3501
|
+
([base, dirs]) => dirs.map(
|
|
3502
|
+
(dir) => [
|
|
3503
|
+
base,
|
|
3504
|
+
sirv2(upath8.resolve(config.serverRootDir, dir), {
|
|
3505
|
+
dev: true,
|
|
3506
|
+
etag: false
|
|
3507
|
+
})
|
|
3508
|
+
]
|
|
3509
|
+
)
|
|
3510
|
+
);
|
|
3511
|
+
};
|
|
4697
3512
|
return {
|
|
4698
3513
|
name: "vivliostyle:static-serve",
|
|
4699
3514
|
apply: () => Boolean(inlineConfig.enableStaticServe),
|
|
@@ -4715,9 +3530,9 @@ function vsStaticServePlugin({
|
|
|
4715
3530
|
}
|
|
4716
3531
|
|
|
4717
3532
|
// src/vite/vite-plugin-viewer.ts
|
|
4718
|
-
import
|
|
3533
|
+
import fs9 from "node:fs";
|
|
4719
3534
|
import sirv3 from "sirv";
|
|
4720
|
-
import
|
|
3535
|
+
import upath9 from "upath";
|
|
4721
3536
|
var viewerClientId = "@vivliostyle:viewer:client";
|
|
4722
3537
|
var viewerClientRequestPath = `/${viewerClientId}`;
|
|
4723
3538
|
var viewerClientContent = (
|
|
@@ -4730,13 +3545,13 @@ if (import.meta.hot) {
|
|
|
4730
3545
|
}`
|
|
4731
3546
|
);
|
|
4732
3547
|
function vsViewerPlugin(_) {
|
|
4733
|
-
const serveRootDir =
|
|
3548
|
+
const serveRootDir = upath9.join(viewerRoot, "lib");
|
|
4734
3549
|
const serve = sirv3(serveRootDir, { dev: false, etag: true });
|
|
4735
3550
|
let cachedIndexHtml;
|
|
4736
3551
|
const middleware = async function vivliostyleViewerMiddleware(req, res, next) {
|
|
4737
3552
|
if (req.url === "/" || req.url === "/index.html") {
|
|
4738
3553
|
cachedIndexHtml ??= prependToHead(
|
|
4739
|
-
|
|
3554
|
+
fs9.readFileSync(upath9.join(serveRootDir, "index.html"), "utf-8"),
|
|
4740
3555
|
`<script type="module" src="${viewerClientRequestPath}"></script>`
|
|
4741
3556
|
);
|
|
4742
3557
|
res.statusCode = 200;
|
|
@@ -4837,7 +3652,7 @@ async function getSourceUrl({
|
|
|
4837
3652
|
input = viewerInput.epubOpfPath;
|
|
4838
3653
|
break;
|
|
4839
3654
|
case "epub": {
|
|
4840
|
-
if (!
|
|
3655
|
+
if (!fs10.existsSync(viewerInput.epubTmpOutputDir)) {
|
|
4841
3656
|
await openEpub(viewerInput.epubPath, viewerInput.epubTmpOutputDir);
|
|
4842
3657
|
}
|
|
4843
3658
|
input = getDefaultEpubOpfPath(viewerInput.epubTmpOutputDir);
|
|
@@ -4847,7 +3662,7 @@ async function getSourceUrl({
|
|
|
4847
3662
|
input = viewerInput;
|
|
4848
3663
|
}
|
|
4849
3664
|
return (isValidUri(input) ? new URL2(input) : new URL2(
|
|
4850
|
-
|
|
3665
|
+
upath10.posix.join(base, upath10.relative(workspaceDir, input)),
|
|
4851
3666
|
rootUrl
|
|
4852
3667
|
)).href;
|
|
4853
3668
|
}
|
|
@@ -4892,14 +3707,15 @@ async function createViteServer({
|
|
|
4892
3707
|
server: viteConfig.server,
|
|
4893
3708
|
preview: viteConfig.preview,
|
|
4894
3709
|
customLogger: viteConfig.customLogger,
|
|
4895
|
-
cacheDir: viteConfig.cacheDir
|
|
3710
|
+
cacheDir: viteConfig.cacheDir,
|
|
3711
|
+
root: viteConfig.root
|
|
4896
3712
|
};
|
|
4897
3713
|
Logger.debug("createViteServer > viteInlineConfig %O", viteInlineConfig);
|
|
4898
|
-
if (config.
|
|
3714
|
+
if (config.serverRootDir === config.workspaceDir) {
|
|
4899
3715
|
const { cacheDir } = viteInlineConfig;
|
|
4900
3716
|
registerExitHandler("Removing the Vite cacheDir", () => {
|
|
4901
|
-
if (
|
|
4902
|
-
|
|
3717
|
+
if (fs10.existsSync(cacheDir)) {
|
|
3718
|
+
fs10.rmSync(cacheDir, { recursive: true });
|
|
4903
3719
|
}
|
|
4904
3720
|
});
|
|
4905
3721
|
}
|
|
@@ -4963,20 +3779,12 @@ function vsBrowserPlugin({
|
|
|
4963
3779
|
}
|
|
4964
3780
|
|
|
4965
3781
|
export {
|
|
4966
|
-
cwd,
|
|
4967
|
-
runExitHandlers,
|
|
4968
|
-
gracefulError,
|
|
4969
|
-
pathEquals,
|
|
4970
|
-
isInContainer,
|
|
4971
|
-
isUnicodeSupported,
|
|
4972
|
-
randomBookSymbol,
|
|
4973
|
-
Logger,
|
|
4974
|
-
parseFlagsToInlineConfig,
|
|
4975
|
-
setupConfigFromFlags,
|
|
4976
3782
|
loadVivliostyleConfig,
|
|
4977
3783
|
warnDeprecatedConfig,
|
|
4978
3784
|
mergeConfig,
|
|
4979
3785
|
mergeInlineConfig,
|
|
3786
|
+
isWebPubConfig,
|
|
3787
|
+
resolveTaskConfig,
|
|
4980
3788
|
getFullBrowserName,
|
|
4981
3789
|
launchPreview,
|
|
4982
3790
|
vsBrowserPlugin,
|
|
@@ -4988,13 +3796,8 @@ export {
|
|
|
4988
3796
|
vsDevServerPlugin,
|
|
4989
3797
|
vsStaticServePlugin,
|
|
4990
3798
|
vsViewerPlugin,
|
|
3799
|
+
getSourceUrl,
|
|
4991
3800
|
getViewerFullUrl,
|
|
4992
|
-
createViteServer
|
|
4993
|
-
CONTAINER_IMAGE,
|
|
4994
|
-
toContainerPath,
|
|
4995
|
-
collectVolumeArgs,
|
|
4996
|
-
runContainer,
|
|
4997
|
-
buildPDFWithContainer,
|
|
4998
|
-
isWebPubConfig,
|
|
4999
|
-
resolveTaskConfig
|
|
3801
|
+
createViteServer
|
|
5000
3802
|
};
|
|
3803
|
+
//# sourceMappingURL=chunk-KSGAS7XH.js.map
|