@slidev/cli 52.14.1 → 52.15.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.
package/README.md CHANGED
@@ -62,7 +62,7 @@ Presentation <b>slide</b>s for <b>dev</b>elopers 🧑‍💻👩‍💻👨‍
62
62
 
63
63
  ### Init Project Locally
64
64
 
65
- Install [Node.js >=18](https://nodejs.org/) and run the following command:
65
+ Install [Node.js >= 20.12.0](https://nodejs.org/) and run the following command:
66
66
 
67
67
  ```bash
68
68
  npm init slidev
@@ -1,5 +1,5 @@
1
- import "./resolver-B4CxEjJF.mjs";
2
- import { t as resolveViteConfigs } from "./shared-CjLi-sXO.mjs";
1
+ import "./resolver-XedCEhxI.mjs";
2
+ import { t as resolveViteConfigs } from "./shared-DDjOjYqG.mjs";
3
3
  import { join, resolve } from "node:path";
4
4
  import { build as build$1 } from "vite";
5
5
  import { existsSync } from "node:fs";
@@ -10,25 +10,33 @@ import sirv from "sirv";
10
10
 
11
11
  //#region node/commands/build.ts
12
12
  async function build(options, viteConfig = {}, args) {
13
- const indexPath = resolve(options.userRoot, "index.html");
14
- let originalIndexHTML;
15
- if (existsSync(indexPath)) originalIndexHTML = await fs$1.readFile(indexPath, "utf-8");
16
- await fs$1.writeFile(indexPath, options.utils.indexHtml, "utf-8");
13
+ const indexHtmlId = resolve(options.userRoot, "index.html");
17
14
  let config = void 0;
18
- try {
19
- await build$1(await resolveViteConfigs(options, {
20
- plugins: [{
21
- name: "resolve-config",
22
- configResolved(_config) {
23
- config = _config;
15
+ await build$1(await resolveViteConfigs(options, {
16
+ plugins: [{
17
+ name: "slidev:build",
18
+ configResolved(_config) {
19
+ config = _config;
20
+ },
21
+ resolveId: {
22
+ order: "pre",
23
+ handler(id) {
24
+ if (id === indexHtmlId) return id;
25
+ return null;
24
26
  }
25
- }],
26
- build: { chunkSizeWarningLimit: 2e3 }
27
- }, viteConfig, "build"));
28
- } finally {
29
- if (originalIndexHTML != null) await fs$1.writeFile(indexPath, originalIndexHTML, "utf-8");
30
- else await fs$1.unlink(indexPath);
31
- }
27
+ },
28
+ load: {
29
+ order: "pre",
30
+ handler(id) {
31
+ if (id === indexHtmlId) return options.utils.indexHtml;
32
+ }
33
+ }
34
+ }],
35
+ build: {
36
+ chunkSizeWarningLimit: 2e3,
37
+ rollupOptions: { input: { index: indexHtmlId } }
38
+ }
39
+ }, viteConfig, "build"));
32
40
  const outDir = resolve(options.userRoot, config.build.outDir);
33
41
  if (options.data.config.seoMeta?.ogImage === "auto" || options.data.config.seoMeta?.ogImage?.startsWith(".")) {
34
42
  const filename = options.data.config.seoMeta?.ogImage === "auto" ? "og-image.png" : options.data.config.seoMeta.ogImage;
@@ -45,7 +53,7 @@ async function build(options, viteConfig = {}, args) {
45
53
  dev: true
46
54
  }));
47
55
  server.listen(port);
48
- const { exportSlides } = await import("./export-C4evmDwN.mjs");
56
+ const { exportSlides } = await import("./export-Dv3OTWhO.mjs");
49
57
  const tempDir = resolve(outDir, "temp");
50
58
  await fs$1.mkdir(tempDir, { recursive: true });
51
59
  await exportSlides({
@@ -86,7 +94,7 @@ async function build(options, viteConfig = {}, args) {
86
94
  "true",
87
95
  "auto"
88
96
  ].includes(options.data.config.download)) {
89
- const { exportSlides, getExportOptions } = await import("./export-C4evmDwN.mjs");
97
+ const { exportSlides, getExportOptions } = await import("./export-Dv3OTWhO.mjs");
90
98
  const port = 12445;
91
99
  const app = connect();
92
100
  const server = http.createServer(app);
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { i as resolveEntry, n as getRoots, r as isInstalledGlobally } from "./resolver-B4CxEjJF.mjs";
2
- import { a as parser, c as resolveAddons, d as updateFrontmatterPatch, i as resolveOptions, l as version, o as getThemeMeta, s as resolveTheme, u as loadSetups } from "./shared-CjLi-sXO.mjs";
3
- import { t as createServer } from "./serve-BFKmdoYb.mjs";
1
+ import { i as resolveEntry, n as getRoots, r as isInstalledGlobally } from "./resolver-XedCEhxI.mjs";
2
+ import { a as parser, c as resolveAddons, d as updateFrontmatterPatch, i as resolveOptions, l as version, o as getThemeMeta, s as resolveTheme, u as loadSetups } from "./shared-DDjOjYqG.mjs";
3
+ import { t as createServer } from "./serve-BSv6omQ6.mjs";
4
4
  import path from "node:path";
5
5
  import process from "node:process";
6
6
  import fs from "node:fs/promises";
@@ -31,6 +31,7 @@ function setupPreparser() {
31
31
 
32
32
  //#endregion
33
33
  //#region node/cli.ts
34
+ const RE_NODE_MODULES_OR_GIT = /node_modules|\.git/;
34
35
  const CONFIG_RESTART_FIELDS = [
35
36
  "monaco",
36
37
  "routerMode",
@@ -229,6 +230,7 @@ cli.command("* [entry]", "Start a local server for Slidev", (args) => commonOpti
229
230
  }
230
231
  ];
231
232
  function bindShortcut() {
233
+ if (!process.stdin.isTTY) return;
232
234
  process.stdin.resume();
233
235
  process.stdin.setEncoding("utf8");
234
236
  readline.emitKeypressEvents(process.stdin);
@@ -282,13 +284,17 @@ cli.command("build [entry..]", "Build hostable SPA", (args) => exportOptions(com
282
284
  }).option("without-notes", {
283
285
  type: "boolean",
284
286
  describe: "exclude speaker notes from the built output"
287
+ }).option("router-mode", {
288
+ type: "string",
289
+ choices: ["hash", "history"],
290
+ describe: "override routerMode in the built output (hash for subdirectory deploys like GitHub Pages)"
285
291
  }).option("inspect", {
286
292
  default: false,
287
293
  type: "boolean",
288
294
  describe: "enable the inspect plugin for debugging"
289
295
  }).strict().help(), async (args) => {
290
- const { entry, theme, base, download, out, inspect, "without-notes": withoutNotes } = args;
291
- const { build } = await import("./build-XXSytKPK.mjs");
296
+ const { entry, theme, base, download, out, inspect, "without-notes": withoutNotes, "router-mode": routerMode } = args;
297
+ const { build } = await import("./build-BiWc4dXo.mjs");
292
298
  for (const entryFile of entry) {
293
299
  const options = await resolveOptions({
294
300
  entry: entryFile,
@@ -296,7 +302,8 @@ cli.command("build [entry..]", "Build hostable SPA", (args) => exportOptions(com
296
302
  inspect,
297
303
  download,
298
304
  base,
299
- withoutNotes
305
+ withoutNotes,
306
+ routerMode
300
307
  }, "build");
301
308
  printInfo(options);
302
309
  await build(options, {
@@ -337,7 +344,7 @@ cli.command("theme [subcommand]", "Theme related operations", (command) => {
337
344
  await fs.mkdir(path.resolve(dir), { recursive: true });
338
345
  await fs.cp(root, path.resolve(dir), {
339
346
  recursive: true,
340
- filter: (i) => !/node_modules|\.git/.test(path.relative(root, i))
347
+ filter: (i) => !RE_NODE_MODULES_OR_GIT.test(path.relative(root, i))
341
348
  });
342
349
  const dirPath = `./${dir}`;
343
350
  const firstSlide = data.entry.slides[0];
@@ -352,7 +359,7 @@ cli.command("theme [subcommand]", "Theme related operations", (command) => {
352
359
  });
353
360
  cli.command("export [entry..]", "Export slides to PDF", (args) => exportOptions(commonOptions(args)).strict().help(), async (args) => {
354
361
  const { entry, theme } = args;
355
- const { exportSlides, getExportOptions } = await import("./export-C4evmDwN.mjs");
362
+ const { exportSlides, getExportOptions } = await import("./export-Dv3OTWhO.mjs");
356
363
  const candidatePort = await getPort(12445);
357
364
  let warned = false;
358
365
  for (const entryFile of entry) {
@@ -404,7 +411,7 @@ cli.command("export-notes [entry..]", "Export slide notes to PDF", (args) => arg
404
411
  type: "number",
405
412
  describe: "wait for the specified ms before exporting"
406
413
  }).strict().help(), async ({ entry, output, timeout, wait }) => {
407
- const { exportNotes } = await import("./export-C4evmDwN.mjs");
414
+ const { exportNotes } = await import("./export-Dv3OTWhO.mjs");
408
415
  const candidatePort = await getPort(12445);
409
416
  for (const entryFile of entry) {
410
417
  const options = await resolveOptions({ entry: entryFile }, "export");
@@ -1,4 +1,4 @@
1
- import { n as getRoots } from "./resolver-B4CxEjJF.mjs";
1
+ import { n as getRoots } from "./resolver-XedCEhxI.mjs";
2
2
  import path, { dirname, relative } from "node:path";
3
3
  import process from "node:process";
4
4
  import fs from "node:fs/promises";
@@ -13,6 +13,7 @@ import * as pdfLib from "pdf-lib";
13
13
  import { PDFDocument } from "pdf-lib";
14
14
 
15
15
  //#region node/commands/export.ts
16
+ const RE_CLICKS_PARAM = /clicks=([1-9]\d*)/;
16
17
  function addToTree(tree, info, slideIndexes, level = 1) {
17
18
  const titleLevel = info.level;
18
19
  if (titleLevel && titleLevel > level && tree.length > 0 && tree[tree.length - 1].titleLevel < titleLevel) addToTree(tree[tree.length - 1].children, info, slideIndexes, level + 1);
@@ -194,7 +195,7 @@ async function exportSlides({ port = 18724, total = 0, range: range$1, format =
194
195
  }, []));
195
196
  }
196
197
  function getClicksFromUrl(url) {
197
- return url.match(/clicks=([1-9]\d*)/)?.[1];
198
+ return url.match(RE_CLICKS_PARAM)?.[1];
198
199
  }
199
200
  async function genPageWithClicks(fn, no, clicks) {
200
201
  await fn(no, clicks);
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import "./resolver-B4CxEjJF.mjs";
2
- import { a as parser, i as resolveOptions, n as ViteSlidevPlugin, r as createDataUtils } from "./shared-CjLi-sXO.mjs";
3
- import { t as createServer } from "./serve-BFKmdoYb.mjs";
1
+ import "./resolver-XedCEhxI.mjs";
2
+ import { a as parser, i as resolveOptions, n as ViteSlidevPlugin, r as createDataUtils } from "./shared-DDjOjYqG.mjs";
3
+ import { t as createServer } from "./serve-BSv6omQ6.mjs";
4
4
 
5
5
  export { ViteSlidevPlugin, createDataUtils, createServer, parser, resolveOptions };
@@ -13,6 +13,7 @@ import { resolveGlobal } from "resolve-global";
13
13
  import { findClosestPkgJsonPath, findDepPkgJsonPath } from "vitefu";
14
14
 
15
15
  //#region node/resolver.ts
16
+ const RE_PATH_SEPARATOR = /[/\\]/;
16
17
  const cliRoot = fileURLToPath(new URL("..", import.meta.url));
17
18
  const isInstalledGlobally = {};
18
19
  /**
@@ -49,7 +50,7 @@ async function findGlobalPkgRoot(name, ensure = false) {
49
50
  if (ensure) throw new Error(`Failed to resolve global package "${name}"`);
50
51
  }
51
52
  async function resolveEntry(entryRaw) {
52
- if (!existsSync(entryRaw) && !entryRaw.endsWith(".md") && !/[/\\]/.test(entryRaw)) entryRaw += ".md";
53
+ if (!existsSync(entryRaw) && !entryRaw.endsWith(".md") && !RE_PATH_SEPARATOR.test(entryRaw)) entryRaw += ".md";
53
54
  const entry = resolve(entryRaw);
54
55
  if (!existsSync(entry)) {
55
56
  if (!process.stdin.isTTY) {
@@ -1,4 +1,4 @@
1
- import { t as resolveViteConfigs } from "./shared-CjLi-sXO.mjs";
1
+ import { t as resolveViteConfigs } from "./shared-DDjOjYqG.mjs";
2
2
  import { join } from "node:path";
3
3
  import process from "node:process";
4
4
  import { createServer } from "vite";