@vivliostyle/cli 10.3.0 → 10.4.0

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.
Files changed (47) hide show
  1. package/README.md +7 -4
  2. package/dist/{chunk-RBKPG6VU.js → chunk-4DTPH2XX.js} +2 -2
  3. package/dist/{chunk-QLK3XMQI.js → chunk-DEJL63H2.js} +195 -130
  4. package/dist/chunk-DEJL63H2.js.map +1 -0
  5. package/dist/{chunk-ZEBXHUJX.js → chunk-DK3HFVHX.js} +27 -51
  6. package/dist/chunk-DK3HFVHX.js.map +1 -0
  7. package/dist/{chunk-3QOSSWIX.js → chunk-J2YGULSR.js} +58 -10
  8. package/dist/chunk-J2YGULSR.js.map +1 -0
  9. package/dist/{chunk-ALY3QX7K.js → chunk-L4PJ2SP3.js} +22 -25
  10. package/dist/chunk-L4PJ2SP3.js.map +1 -0
  11. package/dist/{chunk-WIGLU3EK.js → chunk-LE3QOQ5F.js} +11 -9
  12. package/dist/{chunk-WIGLU3EK.js.map → chunk-LE3QOQ5F.js.map} +1 -1
  13. package/dist/{chunk-YNX6D2I6.js → chunk-P33ELNYE.js} +342 -383
  14. package/dist/chunk-P33ELNYE.js.map +1 -0
  15. package/dist/chunk-Q4EIXB5V.js +330 -0
  16. package/dist/chunk-Q4EIXB5V.js.map +1 -0
  17. package/dist/{chunk-NVNEYZ3J.js → chunk-RLV2H3QB.js} +11 -11
  18. package/dist/chunk-RLV2H3QB.js.map +1 -0
  19. package/dist/{chunk-RILZCPJE.js → chunk-VAPIKX4A.js} +308 -503
  20. package/dist/chunk-VAPIKX4A.js.map +1 -0
  21. package/dist/cli.js +2 -1
  22. package/dist/cli.js.map +1 -1
  23. package/dist/commands/build.js +17 -10
  24. package/dist/commands/build.js.map +1 -1
  25. package/dist/commands/create.js +14 -7
  26. package/dist/commands/create.js.map +1 -1
  27. package/dist/commands/init.js +7 -6
  28. package/dist/commands/init.js.map +1 -1
  29. package/dist/commands/preview.js +16 -9
  30. package/dist/commands/preview.js.map +1 -1
  31. package/dist/config/schema.d.ts +13293 -1796
  32. package/dist/config/schema.js +7 -2
  33. package/dist/constants.d.ts +250 -0
  34. package/dist/constants.js +60 -0
  35. package/dist/constants.js.map +1 -0
  36. package/dist/index.js +13 -12
  37. package/dist/index.js.map +1 -1
  38. package/dist/vite-adapter.js +6 -5
  39. package/package.json +16 -12
  40. package/dist/chunk-3QOSSWIX.js.map +0 -1
  41. package/dist/chunk-ALY3QX7K.js.map +0 -1
  42. package/dist/chunk-NVNEYZ3J.js.map +0 -1
  43. package/dist/chunk-QLK3XMQI.js.map +0 -1
  44. package/dist/chunk-RILZCPJE.js.map +0 -1
  45. package/dist/chunk-YNX6D2I6.js.map +0 -1
  46. package/dist/chunk-ZEBXHUJX.js.map +0 -1
  47. /package/dist/{chunk-RBKPG6VU.js.map → chunk-4DTPH2XX.js.map} +0 -0
@@ -1,317 +1,35 @@
1
- import {
2
- VivliostyleInlineConfig
3
- } from "./chunk-3QOSSWIX.js";
4
1
  import {
5
2
  DEFAULT_BROWSER_VERSIONS,
6
- EMPTY_DATA_URI,
7
- languages
8
- } from "./chunk-ZEBXHUJX.js";
3
+ LANGUAGES
4
+ } from "./chunk-DK3HFVHX.js";
9
5
 
10
- // src/commands/cli-flags.ts
11
- import "commander";
12
- import * as v from "valibot";
13
- function createParserProgram({
14
- setupProgram,
15
- parseArgs
16
- }) {
17
- return (argv) => {
18
- const program = setupProgram();
19
- program.parse(argv);
20
- let options = program.opts();
21
- options = parseArgs?.(options, program.args ?? []) || options;
22
- options = warnDeprecatedFlags(options);
23
- return v.parse(VivliostyleInlineConfig, options);
24
- };
25
- }
26
- function setupConfigFromFlags(flags) {
27
- if (!flags.input) {
28
- if (flags.enableViewerStartPage) {
29
- return {
30
- tasks: [{ entry: [] }],
31
- inlineOptions: {
32
- input: { format: "webbook", entry: EMPTY_DATA_URI }
33
- }
34
- };
35
- } else {
36
- throw new Error(
37
- "No input is set. Please set an appropriate entry or a Vivliostyle config file."
38
- );
39
- }
40
- }
41
- return {
42
- tasks: [{ entry: [] }],
43
- inlineOptions: { ...flags }
44
- };
45
- }
46
- function warnDeprecatedFlags(options) {
47
- const modifiedOptions = { ...options };
48
- return modifiedOptions;
49
- }
6
+ // src/logger.ts
7
+ import debug from "debug";
8
+ import { Console } from "node:console";
9
+ import yoctoSpinner from "yocto-spinner";
10
+ import { blueBright, greenBright, redBright as redBright2, yellowBright } from "yoctocolors";
50
11
 
51
12
  // src/util.ts
52
13
  import { codeFrameColumns } from "@babel/code-frame";
53
14
  import {
54
15
  evaluate,
55
- parse as parse2
16
+ parse
56
17
  } from "@humanwhocodes/momoa";
57
18
  import { Ajv } from "ajv";
58
19
  import formatsPlugin from "ajv-formats";
59
20
  import { XMLParser } from "fast-xml-parser";
60
- import lcid from "lcid";
61
21
  import StreamZip from "node-stream-zip";
62
22
  import childProcess from "node:child_process";
63
23
  import fs from "node:fs";
64
24
  import os from "node:os";
65
- import readline from "node:readline";
25
+ import { fileURLToPath } from "node:url";
66
26
  import util from "node:util";
67
- import { osLocale } from "os-locale";
27
+ import osLocale from "os-locale";
28
+ import resolvePkg from "resolve-pkg";
68
29
  import { titleCase } from "title-case";
69
30
  import tmp from "tmp";
70
31
  import upath from "upath";
71
- import { gray, red, redBright as redBright2 } from "yoctocolors";
72
-
73
- // src/logger.ts
74
- import debug from "debug";
75
- import { Console } from "node:console";
76
- import yoctoSpinner from "yocto-spinner";
77
- import { blueBright, greenBright, redBright, yellowBright } from "yoctocolors";
78
- var isUnicodeSupported = process.platform !== "win32" || Boolean(process.env.WT_SESSION);
79
- var randomBookSymbol = ["\u{1F4D5}", "\u{1F4D7}", "\u{1F4D8}", "\u{1F4D9}"][Math.floor(Math.random() * 4)];
80
- var spinnerFrames = isUnicodeSupported ? ["\u2581\u2581\u2571 ", "\u2581\u2551\u2581 ", "\u2572\u2581\u2581 ", "\u2581\u2581\u2581 ", "\u2581\u2581\u2581 ", "\u2581\u2581\u2581 "] : ["- ", "\\ ", "| ", "/ "];
81
- var spinnerInterval = 80;
82
- var infoSymbol = blueBright("INFO");
83
- var successSymbol = greenBright("SUCCESS");
84
- var warnSymbol = yellowBright("WARN");
85
- var errorSymbol = redBright("ERROR");
86
- var Logger = class _Logger {
87
- /**
88
- * 0: silent 1: info 2: verbose 3: debug
89
- */
90
- static #logLevel = 0;
91
- static #loggerInstance;
92
- static #nonBlockingLogPrinted = false;
93
- static #customLogger;
94
- static #logPrefix;
95
- static #stdin = process.stdin;
96
- static #stdout = process.stdout;
97
- static #stderr = process.stderr;
98
- static #signal;
99
- static debug = debug("vs-cli");
100
- static get #console() {
101
- if (this.#customLogger) {
102
- return {
103
- ...this.#customLogger,
104
- log: () => {
105
- }
106
- };
107
- }
108
- return new Console({
109
- stdout: this.#stdout,
110
- stderr: this.#stderr
111
- });
112
- }
113
- static get #spinner() {
114
- return this.#loggerInstance && this.#loggerInstance.#_spinner;
115
- }
116
- static get stdin() {
117
- return this.#stdin;
118
- }
119
- static get stdout() {
120
- return this.#stdout;
121
- }
122
- static get stderr() {
123
- return this.#stderr;
124
- }
125
- static get signal() {
126
- return this.#signal;
127
- }
128
- static get isInteractive() {
129
- return Boolean(
130
- !this.#customLogger && this.#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
131
- !isInContainer()
132
- );
133
- }
134
- static startLogging(text) {
135
- if (this.#logLevel === 0) {
136
- return;
137
- }
138
- if (!this.isInteractive) {
139
- this.logInfo(text);
140
- return;
141
- }
142
- if (this.#loggerInstance) {
143
- this.#loggerInstance.#_spinner.text = text;
144
- return this.#loggerInstance;
145
- }
146
- this.#loggerInstance = new _Logger(this.#stderr);
147
- this.#loggerInstance.#start(text);
148
- return this.#loggerInstance;
149
- }
150
- static suspendLogging(text) {
151
- if (this.#logLevel === 0) {
152
- return;
153
- }
154
- if (!this.#spinner || !this.isInteractive) {
155
- this.logInfo(text);
156
- return;
157
- }
158
- const currentMsg = this.#spinner?.text;
159
- this.logUpdate(currentMsg);
160
- this.#spinner.stop(`${infoSymbol} ${text}
161
- `);
162
- return {
163
- [Symbol.dispose]() {
164
- if (_Logger.isInteractive) {
165
- _Logger.#console.log("");
166
- _Logger.#spinner?.start(currentMsg);
167
- _Logger.#nonBlockingLogPrinted = true;
168
- }
169
- }
170
- };
171
- }
172
- static log(...messages) {
173
- if (this.#logLevel < 1) {
174
- return;
175
- }
176
- _Logger.#console.log(...messages);
177
- }
178
- static logUpdate(...messages) {
179
- if (!this.#spinner || !this.isInteractive) {
180
- this.logInfo(...messages);
181
- return;
182
- }
183
- this.#spinner.stop(
184
- this.#nonBlockingLogPrinted ? void 0 : `${infoSymbol} ${this.#spinner.text}`
185
- );
186
- this.#spinner.start(messages.join(" "));
187
- this.#nonBlockingLogPrinted = false;
188
- }
189
- static getMessage(message, symbol) {
190
- return !this.#customLogger && symbol ? `${symbol} ${message}` : message;
191
- }
192
- static #nonBlockingLog(logMethod, message) {
193
- if (!this.#spinner || !this.isInteractive) {
194
- if (this.#logPrefix) {
195
- message = `${this.#logPrefix} ${message}`;
196
- }
197
- this.#logLevel >= 3 ? this.debug(message) : this.#console[logMethod](message);
198
- return;
199
- }
200
- this.logUpdate(this.#spinner.text);
201
- this.#nonBlockingLogPrinted = true;
202
- this.#spinner.stop(message);
203
- this.#spinner.start();
204
- }
205
- static logSuccess(...messages) {
206
- if (this.#logLevel < 1) {
207
- return;
208
- }
209
- this.#nonBlockingLog(
210
- "info",
211
- this.getMessage(messages.join(" "), successSymbol)
212
- );
213
- }
214
- static logError(...messages) {
215
- if (this.#logLevel < 1) {
216
- return;
217
- }
218
- this.#nonBlockingLog(
219
- "error",
220
- this.getMessage(messages.join(" "), errorSymbol)
221
- );
222
- }
223
- static logWarn(...messages) {
224
- if (this.#logLevel < 1) {
225
- return;
226
- }
227
- this.#nonBlockingLog(
228
- "warn",
229
- this.getMessage(messages.join(" "), warnSymbol)
230
- );
231
- }
232
- static logInfo(...messages) {
233
- if (this.#logLevel < 1) {
234
- return;
235
- }
236
- this.#nonBlockingLog(
237
- "info",
238
- this.getMessage(messages.join(" "), infoSymbol)
239
- );
240
- }
241
- static logVerbose(...messages) {
242
- if (this.#logLevel < 2) {
243
- return;
244
- }
245
- this.#nonBlockingLog("info", this.getMessage(messages.join(" ")));
246
- }
247
- static setLogOptions({
248
- logLevel,
249
- logger,
250
- stdin,
251
- stdout,
252
- stderr,
253
- signal
254
- }) {
255
- if (logLevel) {
256
- this.#logLevel = {
257
- silent: 0,
258
- info: 1,
259
- verbose: 2,
260
- debug: 3
261
- }[logLevel];
262
- if (this.#logLevel >= 3) {
263
- debug.enable("vs-cli");
264
- }
265
- }
266
- if (logger) {
267
- this.#customLogger = logger;
268
- }
269
- if (stdin) {
270
- this.#stdin = stdin;
271
- }
272
- if (stdout) {
273
- this.#stdout = stdout;
274
- }
275
- if (stderr) {
276
- this.#stderr = stderr;
277
- }
278
- if (signal) {
279
- this.#signal = signal;
280
- }
281
- }
282
- static setLogPrefix(prefix) {
283
- this.#logPrefix = prefix;
284
- }
285
- #_spinner;
286
- #_disposeSpinnerExitHandler;
287
- constructor(stream) {
288
- this.#_spinner = yoctoSpinner({
289
- spinner: {
290
- frames: spinnerFrames,
291
- interval: spinnerInterval
292
- },
293
- color: "gray",
294
- stream
295
- });
296
- return this;
297
- }
298
- #start(text) {
299
- this.#_spinner.start(text);
300
- this.#_disposeSpinnerExitHandler = registerExitHandler(
301
- "Stopping spinner",
302
- () => {
303
- this.#_spinner.stop();
304
- }
305
- );
306
- }
307
- [Symbol.dispose]() {
308
- this.#_disposeSpinnerExitHandler?.();
309
- this.#_spinner.stop(
310
- _Logger.#nonBlockingLogPrinted ? void 0 : `${infoSymbol} ${this.#_spinner.text}`
311
- );
312
- _Logger.#loggerInstance = void 0;
313
- }
314
- };
32
+ import { gray, red, redBright } from "yoctocolors";
315
33
 
316
34
  // schemas/pub-manifest/module/bcp.schema.json
317
35
  var bcp_schema_default = {
@@ -884,10 +602,11 @@ async function exec(command, args = [], options = {}) {
884
602
  return subprocess;
885
603
  }
886
604
  var beforeExitHandlers = [];
605
+ var exitHandlersRun = false;
887
606
  var registerExitHandler = (debugMessage, handler) => {
888
607
  const callback = () => {
889
608
  Logger.debug(debugMessage);
890
- handler();
609
+ return handler();
891
610
  };
892
611
  beforeExitHandlers.push(callback);
893
612
  return () => {
@@ -897,39 +616,35 @@ var registerExitHandler = (debugMessage, handler) => {
897
616
  }
898
617
  };
899
618
  };
900
- function runExitHandlers() {
619
+ async function runExitHandlers() {
620
+ if (exitHandlersRun) return;
621
+ exitHandlersRun = true;
901
622
  while (beforeExitHandlers.length) {
902
623
  try {
903
- beforeExitHandlers.shift()?.();
624
+ await beforeExitHandlers.shift()?.();
904
625
  } catch (e) {
905
626
  }
906
627
  }
907
628
  }
908
- var exitSignals = ["exit", "SIGINT", "SIGTERM"];
909
- exitSignals.forEach((sig) => {
910
- process.once(sig, (signal, exitCode) => {
911
- runExitHandlers();
912
- if (process.exitCode === void 0) {
913
- process.exitCode = exitCode !== void 0 ? 128 + exitCode : Number(signal);
914
- }
915
- if (sig !== "exit") {
916
- process.exit();
629
+ var terminating = false;
630
+ async function terminate(exitCode) {
631
+ if (terminating) return;
632
+ terminating = true;
633
+ try {
634
+ if (exitCode === 130 || exitCode === 143) {
635
+ await runExitHandlers();
636
+ } else {
637
+ runExitHandlers();
917
638
  }
918
- });
919
- });
920
- if (process.platform === "win32") {
921
- const rl = readline.createInterface({
922
- input: process.stdin,
923
- output: process.stdout
924
- });
925
- rl.on("SIGINT", () => {
926
- runExitHandlers();
927
- process.exit(1);
928
- });
929
- registerExitHandler("Closing readline interface", () => {
930
- rl.close();
931
- });
639
+ } finally {
640
+ process.exit(exitCode);
641
+ }
932
642
  }
643
+ process.once("SIGINT", () => void terminate(130));
644
+ process.once("SIGTERM", () => void terminate(143));
645
+ process.once("exit", (code) => {
646
+ void runExitHandlers();
647
+ });
933
648
  var DetailError = class extends Error {
934
649
  detail;
935
650
  constructor(message, detail) {
@@ -942,7 +657,7 @@ function getFormattedError(err) {
942
657
  ${err.detail}` : err.stack || `${err.message}`;
943
658
  }
944
659
  function gracefulError(err) {
945
- console.log(`${redBright2("ERROR")} ${getFormattedError(err)}
660
+ console.log(`${redBright("ERROR")} ${getFormattedError(err)}
946
661
 
947
662
  ${gray("If you think this is a bug, please report at https://github.com/vivliostyle/vivliostyle-cli/issues")}`);
948
663
  process.exit(1);
@@ -1096,7 +811,7 @@ var assertPubManifestSchema = getAjvValidatorFunction(
1096
811
  publicationSchemas
1097
812
  );
1098
813
  function parseJsonc(rawJsonc) {
1099
- const ast = parse2(rawJsonc, {
814
+ const ast = parse(rawJsonc, {
1100
815
  mode: "jsonc",
1101
816
  ranges: false,
1102
817
  tokens: false
@@ -1104,7 +819,7 @@ function parseJsonc(rawJsonc) {
1104
819
  return evaluate(ast);
1105
820
  }
1106
821
  function prettifySchemaError(rawJsonc, issues) {
1107
- const parsed = parse2(rawJsonc, {
822
+ const parsed = parse(rawJsonc, {
1108
823
  mode: "jsonc",
1109
824
  ranges: false,
1110
825
  tokens: false
@@ -1125,7 +840,7 @@ function prettifySchemaError(rawJsonc, issues) {
1125
840
  const maxDepth = Math.max(...all.map(([, d]) => d));
1126
841
  const issuesTraversed = all.find(([, d]) => d === maxDepth)[0];
1127
842
  let jsonValue = parsed.body;
1128
- for (const p of issuesTraversed.flatMap((v2) => v2.path ?? [])) {
843
+ for (const p of issuesTraversed.flatMap((v) => v.path ?? [])) {
1129
844
  let childValue;
1130
845
  if (p.type === "object" && jsonValue.type === "Object") {
1131
846
  childValue = jsonValue.members.find(
@@ -1159,36 +874,15 @@ function writeFileIfChanged(filePath, content) {
1159
874
  var cachedLocale;
1160
875
  async function getOsLocale() {
1161
876
  if (import.meta.env?.VITEST) {
1162
- return process.env.TEST_LOCALE || "en";
1163
- }
1164
- if (cachedLocale) {
1165
- return cachedLocale;
1166
- }
1167
- let locale;
1168
- if (process.platform === "win32") {
1169
- const { stdout } = await exec("wmic", ["os", "get", "locale"]);
1170
- const lcidCode = Number.parseInt(stdout.replace("Locale", ""), 16);
1171
- locale = lcid.from(lcidCode);
1172
- }
1173
- if (process.platform === "darwin") {
1174
- const results = await Promise.all([
1175
- exec("defaults", ["read", "-globalDomain", "AppleLocale"]).then(
1176
- ({ stdout }) => stdout
1177
- ),
1178
- exec("locale", ["-a"]).then(({ stdout }) => stdout)
1179
- ]);
1180
- if (results[1].includes(results[0])) {
1181
- locale = results[0];
1182
- }
877
+ return process.env.TEST_LOCALE || "en";
1183
878
  }
1184
- if (locale) {
1185
- locale = locale.replace(/_/, "-");
1186
- } else {
1187
- locale = await osLocale();
879
+ if (cachedLocale) {
880
+ return cachedLocale;
1188
881
  }
1189
- const langs = Object.keys(languages);
1190
- locale = langs.includes(locale) ? locale : langs.includes(locale.split("-")[0]) ? locale.split("-")[0] : "en";
1191
- return cachedLocale = locale.replace(/_/, "-");
882
+ const locale = osLocale();
883
+ const langs = Object.keys(LANGUAGES);
884
+ cachedLocale = langs.includes(locale) ? locale : langs.includes(locale.split("-")[0]) ? locale.split("-")[0] : "en";
885
+ return cachedLocale;
1192
886
  }
1193
887
  function toTitleCase(input) {
1194
888
  if (typeof input !== "string") {
@@ -1281,161 +975,275 @@ function whichPm() {
1281
975
  const name = pmSpec.substring(0, separatorPos);
1282
976
  return name;
1283
977
  }
978
+ var cliRoot = upath.join(fileURLToPath(import.meta.url), "../..");
979
+ var cliVersion = (() => {
980
+ if (import.meta.env?.VITEST) {
981
+ return "0.0.1";
982
+ }
983
+ const pkg = JSON.parse(
984
+ fs.readFileSync(upath.join(cliRoot, "package.json"), "utf8")
985
+ );
986
+ return pkg.version;
987
+ })();
988
+ var viewerRoot = resolvePkg("@vivliostyle/viewer", { cwd: cliRoot });
989
+ var coreVersion = (() => {
990
+ if (import.meta.env?.VITEST) {
991
+ return "0.0.1";
992
+ }
993
+ if (!viewerRoot) {
994
+ return "Unknown";
995
+ }
996
+ const pkg = JSON.parse(
997
+ fs.readFileSync(upath.join(viewerRoot, "package.json"), "utf8")
998
+ );
999
+ return pkg.version;
1000
+ })();
1001
+ var versionForDisplay = `cli: ${cliVersion}
1002
+ core: ${coreVersion}`;
1284
1003
 
1285
- // src/processor/asset.ts
1286
- import { copy } from "fs-extra/esm";
1287
- import fs2 from "node:fs";
1288
- import picomatch from "picomatch";
1289
- import { glob } from "tinyglobby";
1290
- import upath2 from "upath";
1291
- var GlobMatcher = class {
1292
- matcherConfig;
1293
- #_matchers;
1294
- constructor(matcherConfig) {
1295
- this.matcherConfig = matcherConfig;
1296
- this.#_matchers = matcherConfig.map(
1297
- ({ patterns, ...options }) => picomatch(patterns, options)
1004
+ // src/logger.ts
1005
+ var isUnicodeSupported = process.platform !== "win32" || Boolean(process.env.WT_SESSION);
1006
+ var randomBookSymbol = ["\u{1F4D5}", "\u{1F4D7}", "\u{1F4D8}", "\u{1F4D9}"][Math.floor(Math.random() * 4)];
1007
+ var spinnerFrames = isUnicodeSupported ? ["\u2581\u2581\u2571 ", "\u2581\u2551\u2581 ", "\u2572\u2581\u2581 ", "\u2581\u2581\u2581 ", "\u2581\u2581\u2581 ", "\u2581\u2581\u2581 "] : ["- ", "\\ ", "| ", "/ "];
1008
+ var spinnerInterval = 80;
1009
+ var infoSymbol = blueBright("INFO");
1010
+ var successSymbol = greenBright("SUCCESS");
1011
+ var warnSymbol = yellowBright("WARN");
1012
+ var errorSymbol = redBright2("ERROR");
1013
+ var Logger = class _Logger {
1014
+ /**
1015
+ * 0: silent 1: info 2: verbose 3: debug
1016
+ */
1017
+ static #logLevel = 0;
1018
+ static #loggerInstance;
1019
+ static #nonBlockingLogPrinted = false;
1020
+ static #customLogger;
1021
+ static #logPrefix;
1022
+ static #stdin = process.stdin;
1023
+ static #stdout = process.stdout;
1024
+ static #stderr = process.stderr;
1025
+ static #signal;
1026
+ static debug = debug("vs-cli");
1027
+ static get #console() {
1028
+ if (this.#customLogger) {
1029
+ return {
1030
+ ...this.#customLogger,
1031
+ log: () => {
1032
+ }
1033
+ };
1034
+ }
1035
+ return new Console({
1036
+ stdout: this.#stdout,
1037
+ stderr: this.#stderr
1038
+ });
1039
+ }
1040
+ static get #spinner() {
1041
+ return this.#loggerInstance && this.#loggerInstance.#_spinner;
1042
+ }
1043
+ static get stdin() {
1044
+ return this.#stdin;
1045
+ }
1046
+ static get stdout() {
1047
+ return this.#stdout;
1048
+ }
1049
+ static get stderr() {
1050
+ return this.#stderr;
1051
+ }
1052
+ static get signal() {
1053
+ return this.#signal;
1054
+ }
1055
+ static get isInteractive() {
1056
+ return Boolean(
1057
+ !this.#customLogger && this.#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
1058
+ !isInContainer()
1298
1059
  );
1299
1060
  }
1300
- match(test) {
1301
- return this.#_matchers.some((matcher) => matcher(test));
1061
+ static startLogging(text) {
1062
+ if (this.#logLevel === 0) {
1063
+ return;
1064
+ }
1065
+ if (!this.isInteractive) {
1066
+ this.logInfo(text);
1067
+ return;
1068
+ }
1069
+ if (this.#loggerInstance) {
1070
+ this.#loggerInstance.#_spinner.text = text;
1071
+ return this.#loggerInstance;
1072
+ }
1073
+ this.#loggerInstance = new _Logger(this.#stderr);
1074
+ this.#loggerInstance.#start(text);
1075
+ return this.#loggerInstance;
1076
+ }
1077
+ static suspendLogging(text) {
1078
+ if (this.#logLevel === 0) {
1079
+ return;
1080
+ }
1081
+ if (!this.#spinner || !this.isInteractive) {
1082
+ this.logInfo(text);
1083
+ return;
1084
+ }
1085
+ const currentMsg = this.#spinner?.text;
1086
+ this.logUpdate(currentMsg);
1087
+ this.#spinner.stop(`${infoSymbol} ${text}
1088
+ `);
1089
+ return {
1090
+ [Symbol.dispose]() {
1091
+ if (_Logger.isInteractive) {
1092
+ _Logger.#console.log("");
1093
+ _Logger.#spinner?.start(currentMsg);
1094
+ _Logger.#nonBlockingLogPrinted = true;
1095
+ }
1096
+ }
1097
+ };
1098
+ }
1099
+ static log(...messages) {
1100
+ if (this.#logLevel < 1) {
1101
+ return;
1102
+ }
1103
+ _Logger.#console.log(...messages);
1302
1104
  }
1303
- async glob(globOptions = {}) {
1304
- return new Set(
1305
- (await Promise.all(
1306
- this.matcherConfig.map(
1307
- (config) => glob({ ...config, ...globOptions })
1308
- )
1309
- )).flat()
1105
+ static logUpdate(...messages) {
1106
+ if (!this.#spinner || !this.isInteractive) {
1107
+ this.logInfo(...messages);
1108
+ return;
1109
+ }
1110
+ this.#spinner.stop(
1111
+ this.#nonBlockingLogPrinted ? void 0 : `${infoSymbol} ${this.#spinner.text}`
1310
1112
  );
1113
+ this.#spinner.start(messages.join(" "));
1114
+ this.#nonBlockingLogPrinted = false;
1311
1115
  }
1312
- };
1313
- function getIgnoreThemeDirectoryPatterns({
1314
- themesDir,
1315
- cwd: cwd2
1316
- }) {
1317
- return pathContains(cwd2, themesDir) ? [
1318
- `${upath2.relative(cwd2, themesDir)}/node_modules/*/example`,
1319
- `${upath2.relative(cwd2, themesDir)}/node_modules/*/*/example`
1320
- ] : [];
1321
- }
1322
- function getIgnoreAssetPatterns({
1323
- outputs,
1324
- entries,
1325
- cwd: cwd2
1326
- }) {
1327
- return [
1328
- ...outputs.flatMap(
1329
- ({ format, path: p }) => !pathContains(cwd2, p) ? [] : format === "webpub" ? upath2.join(upath2.relative(cwd2, p), "**") : upath2.relative(cwd2, p)
1330
- ),
1331
- ...entries.flatMap(({ template }) => {
1332
- return template?.type === "file" && pathContains(cwd2, template.pathname) ? upath2.relative(cwd2, template.pathname) : [];
1333
- })
1334
- ];
1335
- }
1336
- function getWebPubResourceMatcher({
1337
- outputs,
1338
- themesDir,
1339
- entries,
1340
- cwd: cwd2,
1341
- manifestPath,
1342
- copyAsset: { fileExtensions }
1343
- }) {
1344
- return new GlobMatcher([
1345
- {
1346
- patterns: [
1347
- `**/${upath2.relative(cwd2, manifestPath)}`,
1348
- "**/*.{html,htm,xhtml,xht}",
1349
- `**/*.{${fileExtensions.join(",")}}`
1350
- ],
1351
- ignore: [
1352
- ...getIgnoreAssetPatterns({
1353
- cwd: cwd2,
1354
- outputs,
1355
- entries
1356
- }),
1357
- ...getIgnoreThemeDirectoryPatterns({
1358
- cwd: cwd2,
1359
- themesDir
1360
- }),
1361
- // Ignore node_modules in the root directory
1362
- "node_modules/**",
1363
- // only include dotfiles starting with `.vs-`
1364
- "**/.!(vs-*)/**"
1365
- ],
1366
- dot: true,
1367
- cwd: cwd2
1116
+ static getMessage(message, symbol) {
1117
+ return !this.#customLogger && symbol ? `${symbol} ${message}` : message;
1118
+ }
1119
+ static #nonBlockingLog(logMethod, message) {
1120
+ if (!this.#spinner || !this.isInteractive) {
1121
+ if (this.#logPrefix) {
1122
+ message = `${this.#logPrefix} ${message}`;
1123
+ }
1124
+ this.#logLevel >= 3 ? this.debug(message) : this.#console[logMethod](message);
1125
+ return;
1368
1126
  }
1369
- ]);
1370
- }
1371
- function getAssetMatcher({
1372
- copyAsset: { fileExtensions, includes, excludes },
1373
- outputs,
1374
- themesDir,
1375
- entries,
1376
- cwd: cwd2,
1377
- ignore = []
1378
- }) {
1379
- const ignorePatterns = [
1380
- ...ignore,
1381
- ...excludes,
1382
- ...getIgnoreAssetPatterns({ outputs, entries, cwd: cwd2 })
1383
- ];
1384
- return new GlobMatcher([
1385
- // Step 1: Glob files with an extension in `fileExtension`
1386
- // Ignore files in node_modules directory, theme example files and files matched `excludes`
1387
- {
1388
- patterns: fileExtensions.map((ext) => `**/*.${ext}`),
1389
- ignore: [
1390
- "**/node_modules/**",
1391
- ...ignorePatterns,
1392
- ...getIgnoreThemeDirectoryPatterns({ themesDir, cwd: cwd2 })
1393
- ],
1394
- cwd: cwd2
1395
- },
1396
- // Step 2: Glob files matched with `includes`
1397
- // Ignore only files matched `excludes`
1398
- {
1399
- patterns: includes,
1400
- ignore: ignorePatterns,
1401
- cwd: cwd2
1127
+ this.logUpdate(this.#spinner.text);
1128
+ this.#nonBlockingLogPrinted = true;
1129
+ this.#spinner.stop(message);
1130
+ this.#spinner.start();
1131
+ }
1132
+ static logSuccess(...messages) {
1133
+ if (this.#logLevel < 1) {
1134
+ return;
1402
1135
  }
1403
- ]);
1404
- }
1405
- async function copyAssets({
1406
- entryContextDir,
1407
- workspaceDir,
1408
- copyAsset,
1409
- outputs,
1410
- themesDir,
1411
- entries
1412
- }) {
1413
- if (pathEquals(entryContextDir, workspaceDir)) {
1414
- return;
1136
+ this.#nonBlockingLog(
1137
+ "info",
1138
+ this.getMessage(messages.join(" "), successSymbol)
1139
+ );
1415
1140
  }
1416
- const relWorkspaceDir = upath2.relative(entryContextDir, workspaceDir);
1417
- const assets = await getAssetMatcher({
1418
- copyAsset,
1419
- cwd: entryContextDir,
1420
- outputs,
1421
- themesDir,
1422
- entries,
1423
- ignore: [
1424
- // don't copy workspace itself
1425
- ...relWorkspaceDir ? [upath2.join(relWorkspaceDir, "**")] : []
1426
- ]
1427
- }).glob({ followSymbolicLinks: true });
1428
- Logger.debug("assets", assets);
1429
- for (const asset of assets) {
1430
- const target = upath2.join(workspaceDir, asset);
1431
- fs2.mkdirSync(upath2.dirname(target), { recursive: true });
1432
- await copy(upath2.resolve(entryContextDir, asset), target);
1141
+ static logError(...messages) {
1142
+ if (this.#logLevel < 1) {
1143
+ return;
1144
+ }
1145
+ this.#nonBlockingLog(
1146
+ "error",
1147
+ this.getMessage(messages.join(" "), errorSymbol)
1148
+ );
1433
1149
  }
1434
- }
1150
+ static logWarn(...messages) {
1151
+ if (this.#logLevel < 1) {
1152
+ return;
1153
+ }
1154
+ this.#nonBlockingLog(
1155
+ "warn",
1156
+ this.getMessage(messages.join(" "), warnSymbol)
1157
+ );
1158
+ }
1159
+ static logInfo(...messages) {
1160
+ if (this.#logLevel < 1) {
1161
+ return;
1162
+ }
1163
+ this.#nonBlockingLog(
1164
+ "info",
1165
+ this.getMessage(messages.join(" "), infoSymbol)
1166
+ );
1167
+ }
1168
+ static logVerbose(...messages) {
1169
+ if (this.#logLevel < 2) {
1170
+ return;
1171
+ }
1172
+ this.#nonBlockingLog("info", this.getMessage(messages.join(" ")));
1173
+ }
1174
+ static setLogOptions({
1175
+ logLevel,
1176
+ logger,
1177
+ stdin,
1178
+ stdout,
1179
+ stderr,
1180
+ signal
1181
+ }) {
1182
+ if (logLevel) {
1183
+ this.#logLevel = {
1184
+ silent: 0,
1185
+ info: 1,
1186
+ verbose: 2,
1187
+ debug: 3
1188
+ }[logLevel];
1189
+ if (this.#logLevel >= 3) {
1190
+ debug.enable("vs-cli");
1191
+ }
1192
+ }
1193
+ if (logger) {
1194
+ this.#customLogger = logger;
1195
+ }
1196
+ if (stdin) {
1197
+ this.#stdin = stdin;
1198
+ }
1199
+ if (stdout) {
1200
+ this.#stdout = stdout;
1201
+ }
1202
+ if (stderr) {
1203
+ this.#stderr = stderr;
1204
+ }
1205
+ if (signal) {
1206
+ this.#signal = signal;
1207
+ }
1208
+ }
1209
+ static setLogPrefix(prefix) {
1210
+ this.#logPrefix = prefix;
1211
+ }
1212
+ #_spinner;
1213
+ #_disposeSpinnerExitHandler;
1214
+ constructor(stream) {
1215
+ this.#_spinner = yoctoSpinner({
1216
+ spinner: {
1217
+ frames: spinnerFrames,
1218
+ interval: spinnerInterval
1219
+ },
1220
+ color: "gray",
1221
+ stream
1222
+ });
1223
+ return this;
1224
+ }
1225
+ #start(text) {
1226
+ this.#_spinner.start(text);
1227
+ this.#_disposeSpinnerExitHandler = registerExitHandler(
1228
+ "Stopping spinner",
1229
+ () => {
1230
+ this.#_spinner.stop();
1231
+ }
1232
+ );
1233
+ }
1234
+ [Symbol.dispose]() {
1235
+ this.#_disposeSpinnerExitHandler?.();
1236
+ this.#_spinner.stop(
1237
+ _Logger.#nonBlockingLogPrinted ? void 0 : `${infoSymbol} ${this.#_spinner.text}`
1238
+ );
1239
+ _Logger.#loggerInstance = void 0;
1240
+ }
1241
+ };
1435
1242
 
1436
1243
  export {
1437
- createParserProgram,
1438
- setupConfigFromFlags,
1244
+ isUnicodeSupported,
1245
+ randomBookSymbol,
1246
+ Logger,
1439
1247
  cwd,
1440
1248
  exec,
1441
1249
  registerExitHandler,
@@ -1466,12 +1274,9 @@ export {
1466
1274
  detectBrowserPlatform,
1467
1275
  getDefaultBrowserTag,
1468
1276
  whichPm,
1469
- isUnicodeSupported,
1470
- randomBookSymbol,
1471
- Logger,
1472
- GlobMatcher,
1473
- getWebPubResourceMatcher,
1474
- getAssetMatcher,
1475
- copyAssets
1277
+ cliVersion,
1278
+ viewerRoot,
1279
+ coreVersion,
1280
+ versionForDisplay
1476
1281
  };
1477
- //# sourceMappingURL=chunk-RILZCPJE.js.map
1282
+ //# sourceMappingURL=chunk-VAPIKX4A.js.map