@slidev/cli 0.31.4 → 0.32.3

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.
@@ -1,3 +1,6 @@
1
+ import {
2
+ ViteSlidevPlugin
3
+ } from "./chunk-WZ6OPJJF.mjs";
1
4
  import {
2
5
  __commonJS,
3
6
  __dirname,
@@ -10,8 +13,9 @@ import {
10
13
  __spreadValues,
11
14
  __toESM,
12
15
  init_esm_shims,
16
+ packageExists,
13
17
  resolveImportPath
14
- } from "./chunk-25USV2L5.mjs";
18
+ } from "./chunk-NOFZO6W4.mjs";
15
19
 
16
20
  // ../../node_modules/.pnpm/semver@7.3.7/node_modules/semver/internal/constants.js
17
21
  var require_constants = __commonJS({
@@ -1850,7 +1854,7 @@ var require_satisfies = __commonJS({
1850
1854
  "../../node_modules/.pnpm/semver@7.3.7/node_modules/semver/functions/satisfies.js"(exports, module) {
1851
1855
  init_esm_shims();
1852
1856
  var Range = require_range();
1853
- var satisfies2 = (version3, range, options) => {
1857
+ var satisfies3 = (version3, range, options) => {
1854
1858
  try {
1855
1859
  range = new Range(range, options);
1856
1860
  } catch (er) {
@@ -1858,7 +1862,7 @@ var require_satisfies = __commonJS({
1858
1862
  }
1859
1863
  return range.test(version3);
1860
1864
  };
1861
- module.exports = satisfies2;
1865
+ module.exports = satisfies3;
1862
1866
  }
1863
1867
  });
1864
1868
 
@@ -2011,7 +2015,7 @@ var require_outside = __commonJS({
2011
2015
  var Comparator = require_comparator();
2012
2016
  var { ANY } = Comparator;
2013
2017
  var Range = require_range();
2014
- var satisfies2 = require_satisfies();
2018
+ var satisfies3 = require_satisfies();
2015
2019
  var gt = require_gt();
2016
2020
  var lt = require_lt();
2017
2021
  var lte = require_lte();
@@ -2038,7 +2042,7 @@ var require_outside = __commonJS({
2038
2042
  default:
2039
2043
  throw new TypeError('Must provide a hilo val of "<" or ">"');
2040
2044
  }
2041
- if (satisfies2(version3, range, options)) {
2045
+ if (satisfies3(version3, range, options)) {
2042
2046
  return false;
2043
2047
  }
2044
2048
  for (let i = 0; i < range.set.length; ++i) {
@@ -2110,7 +2114,7 @@ var require_intersects = __commonJS({
2110
2114
  var require_simplify = __commonJS({
2111
2115
  "../../node_modules/.pnpm/semver@7.3.7/node_modules/semver/ranges/simplify.js"(exports, module) {
2112
2116
  init_esm_shims();
2113
- var satisfies2 = require_satisfies();
2117
+ var satisfies3 = require_satisfies();
2114
2118
  var compare = require_compare();
2115
2119
  module.exports = (versions, range, options) => {
2116
2120
  const set = [];
@@ -2118,7 +2122,7 @@ var require_simplify = __commonJS({
2118
2122
  let prev = null;
2119
2123
  const v = versions.sort((a, b) => compare(a, b, options));
2120
2124
  for (const version3 of v) {
2121
- const included = satisfies2(version3, range, options);
2125
+ const included = satisfies3(version3, range, options);
2122
2126
  if (included) {
2123
2127
  prev = version3;
2124
2128
  if (!first) {
@@ -2163,7 +2167,7 @@ var require_subset = __commonJS({
2163
2167
  var Range = require_range();
2164
2168
  var Comparator = require_comparator();
2165
2169
  var { ANY } = Comparator;
2166
- var satisfies2 = require_satisfies();
2170
+ var satisfies3 = require_satisfies();
2167
2171
  var compare = require_compare();
2168
2172
  var subset = (sub, dom, options = {}) => {
2169
2173
  if (sub === dom) {
@@ -2231,14 +2235,14 @@ var require_subset = __commonJS({
2231
2235
  }
2232
2236
  }
2233
2237
  for (const eq of eqSet) {
2234
- if (gt && !satisfies2(eq, String(gt), options)) {
2238
+ if (gt && !satisfies3(eq, String(gt), options)) {
2235
2239
  return null;
2236
2240
  }
2237
- if (lt && !satisfies2(eq, String(lt), options)) {
2241
+ if (lt && !satisfies3(eq, String(lt), options)) {
2238
2242
  return null;
2239
2243
  }
2240
2244
  for (const c2 of dom) {
2241
- if (!satisfies2(eq, String(c2), options)) {
2245
+ if (!satisfies3(eq, String(c2), options)) {
2242
2246
  return false;
2243
2247
  }
2244
2248
  }
@@ -2265,7 +2269,7 @@ var require_subset = __commonJS({
2265
2269
  if (higher === c2 && higher !== gt) {
2266
2270
  return false;
2267
2271
  }
2268
- } else if (gt.operator === ">=" && !satisfies2(gt.semver, String(c2), options)) {
2272
+ } else if (gt.operator === ">=" && !satisfies3(gt.semver, String(c2), options)) {
2269
2273
  return false;
2270
2274
  }
2271
2275
  }
@@ -2280,7 +2284,7 @@ var require_subset = __commonJS({
2280
2284
  if (lower === c2 && lower !== lt) {
2281
2285
  return false;
2282
2286
  }
2283
- } else if (lt.operator === "<=" && !satisfies2(lt.semver, String(c2), options)) {
2287
+ } else if (lt.operator === "<=" && !satisfies3(lt.semver, String(c2), options)) {
2284
2288
  return false;
2285
2289
  }
2286
2290
  }
@@ -2371,12 +2375,33 @@ var require_semver2 = __commonJS({
2371
2375
  }
2372
2376
  });
2373
2377
 
2378
+ // node/server.ts
2379
+ init_esm_shims();
2380
+ import { join } from "path";
2381
+ import { createServer as createViteServer, mergeConfig, resolveConfig } from "vite";
2382
+ async function createServer(options, viteConfig = {}, serverOptions = {}) {
2383
+ const rawConfig = await resolveConfig({}, "serve");
2384
+ const pluginOptions = rawConfig.slidev || {};
2385
+ process.env.EDITOR = process.env.EDITOR || "code";
2386
+ const server = await createViteServer(mergeConfig(viteConfig, {
2387
+ optimizeDeps: {
2388
+ entries: [
2389
+ join(options.clientRoot, "main.ts")
2390
+ ]
2391
+ },
2392
+ plugins: [
2393
+ await ViteSlidevPlugin(options, pluginOptions, serverOptions)
2394
+ ]
2395
+ }));
2396
+ return server;
2397
+ }
2398
+
2374
2399
  // node/parser.ts
2375
2400
  init_esm_shims();
2376
2401
  import * as parser from "@slidev/parser/fs";
2377
2402
 
2378
2403
  // package.json
2379
- var version = "0.31.4";
2404
+ var version = "0.32.3";
2380
2405
 
2381
2406
  // node/themes.ts
2382
2407
  init_esm_shims();
@@ -9463,16 +9488,57 @@ async function run(fn, args, options = {}) {
9463
9488
  }
9464
9489
 
9465
9490
  // node/themes.ts
9466
- var import_semver = __toESM(require_semver2());
9491
+ var import_semver2 = __toESM(require_semver2());
9467
9492
  import isInstalledGlobally from "is-installed-globally";
9468
9493
  import { underline } from "kolorist";
9469
- import fs2 from "fs-extra";
9494
+ import fs3 from "fs-extra";
9470
9495
 
9471
9496
  // node/options.ts
9472
9497
  init_esm_shims();
9473
- import { dirname, join, resolve as resolve2 } from "path";
9498
+ import { dirname, join as join2, resolve as resolve2 } from "path";
9474
9499
  import { uniq } from "@antfu/utils";
9475
9500
  import _debug from "debug";
9501
+
9502
+ // node/addons.ts
9503
+ init_esm_shims();
9504
+ var import_semver = __toESM(require_semver2());
9505
+ import fs2 from "fs-extra";
9506
+ function getPackageJson(root) {
9507
+ return fs2.readJSON(resolveImportPath(`${root}/package.json`, true));
9508
+ }
9509
+ async function getAddons(userRoot, config2) {
9510
+ const { slidev = {} } = await getPackageJson(userRoot);
9511
+ const configAddons = config2.addons instanceof Array ? config2.addons : [];
9512
+ const addons = configAddons.concat(slidev.addons instanceof Array ? slidev.addons : []);
9513
+ return getRecursivePlugins(addons.map(resolvePluginName));
9514
+ }
9515
+ async function getRecursivePlugins(addons) {
9516
+ const addonsArray = await Promise.all(addons.map(async (addon) => {
9517
+ const { slidev = {}, engines = {} } = await getPackageJson(addon);
9518
+ checkEngine(addon, engines);
9519
+ let addons2 = slidev.addons instanceof Array ? slidev.addons : [];
9520
+ if (addons2.length > 0)
9521
+ addons2 = await getRecursivePlugins(addons2.map(resolvePluginName));
9522
+ addons2.push(addon);
9523
+ return addons2;
9524
+ }));
9525
+ return addonsArray.flat();
9526
+ }
9527
+ async function checkEngine(name, engines) {
9528
+ if (engines.slidev && !(0, import_semver.satisfies)(version, engines.slidev))
9529
+ throw new Error(`[slidev] addon "${name}" requires Slidev version range "${engines.slidev}" but found "${version}"`);
9530
+ }
9531
+ function resolvePluginName(name) {
9532
+ if (!name)
9533
+ return "";
9534
+ if (isPath(name))
9535
+ return name;
9536
+ if (packageExists(`slidev-addon-${name}`))
9537
+ return `slidev-addon-${name}`;
9538
+ return name;
9539
+ }
9540
+
9541
+ // node/options.ts
9476
9542
  var debug = _debug("slidev:options");
9477
9543
  function getClientRoot() {
9478
9544
  return dirname(resolveImportPath("@slidev/client/package.json", true));
@@ -9486,15 +9552,17 @@ function isPath(name) {
9486
9552
  function getThemeRoots(name, entry) {
9487
9553
  if (!name)
9488
9554
  return [];
9489
- if (isPath(name)) {
9490
- return [
9491
- resolve2(dirname(entry), name)
9492
- ];
9493
- } else {
9494
- return [
9495
- dirname(resolveImportPath(`${name}/package.json`, true))
9496
- ];
9497
- }
9555
+ return [getRoot(name, entry)];
9556
+ }
9557
+ function getAddonRoots(addons, entry) {
9558
+ if (addons.length === 0)
9559
+ return [];
9560
+ return addons.map((name) => getRoot(name, entry));
9561
+ }
9562
+ function getRoot(name, entry) {
9563
+ if (isPath(name))
9564
+ return resolve2(dirname(entry), name);
9565
+ return dirname(resolveImportPath(`${name}/package.json`, true));
9498
9566
  }
9499
9567
  function getUserRoot(options) {
9500
9568
  const { entry: rawEntry = "slides.md", userRoot = process.cwd() } = options;
@@ -9521,9 +9589,11 @@ async function resolveOptions(options, mode2, promptForInstallation = true) {
9521
9589
  const clientRoot = getClientRoot();
9522
9590
  const cliRoot = getCLIRoot();
9523
9591
  const themeRoots = getThemeRoots(theme, entry);
9592
+ const addons = await getAddons(userRoot, data.config);
9593
+ const addonRoots = getAddonRoots(addons, entry);
9524
9594
  const roots = uniq([clientRoot, ...themeRoots, userRoot]);
9525
9595
  if (themeRoots.length) {
9526
- const themeMeta = await getThemeMeta(theme, join(themeRoots[0], "package.json"));
9596
+ const themeMeta = await getThemeMeta(theme, join2(themeRoots[0], "package.json"));
9527
9597
  data.themeMeta = themeMeta;
9528
9598
  if (themeMeta)
9529
9599
  data.config = parser.resolveConfig(data.headmatter, themeMeta);
@@ -9537,6 +9607,7 @@ async function resolveOptions(options, mode2, promptForInstallation = true) {
9537
9607
  clientRoot,
9538
9608
  cliRoot,
9539
9609
  themeRoots,
9610
+ addonRoots,
9540
9611
  roots,
9541
9612
  remote
9542
9613
  });
@@ -9549,6 +9620,7 @@ async function resolveOptions(options, mode2, promptForInstallation = true) {
9549
9620
  clientRoot,
9550
9621
  cliRoot,
9551
9622
  themeRoots,
9623
+ addonRoots,
9552
9624
  roots,
9553
9625
  remote
9554
9626
  };
@@ -9563,17 +9635,12 @@ var officialThemes = {
9563
9635
  "shibainu": "@slidev/theme-shibainu",
9564
9636
  "bricks": "@slidev/theme-bricks"
9565
9637
  };
9566
- function packageExists(name) {
9567
- if (resolveImportPath(`${name}/package.json`))
9568
- return true;
9569
- return false;
9570
- }
9571
9638
  async function getThemeMeta(name, path2) {
9572
- if (!fs2.existsSync(path2))
9639
+ if (!fs3.existsSync(path2))
9573
9640
  return {};
9574
9641
  if (path2) {
9575
- const { slidev = {}, engines = {} } = await fs2.readJSON(path2);
9576
- if (engines.slidev && !(0, import_semver.satisfies)(version, engines.slidev))
9642
+ const { slidev = {}, engines = {} } = await fs3.readJSON(path2);
9643
+ if (engines.slidev && !(0, import_semver2.satisfies)(version, engines.slidev))
9577
9644
  throw new Error(`[slidev] theme "${name}" requires Slidev version range "${engines.slidev}" but found "${version}"`);
9578
9645
  return slidev;
9579
9646
  }
@@ -9590,6 +9657,8 @@ function resolveThemeName(name) {
9590
9657
  return `@slidev/theme-${name}`;
9591
9658
  if (packageExists(`slidev-theme-${name}`))
9592
9659
  return `slidev-theme-${name}`;
9660
+ if (packageExists(name))
9661
+ return name;
9593
9662
  if (officialThemes[name] != null)
9594
9663
  return officialThemes[name];
9595
9664
  return `slidev-theme-${name}`;
@@ -9616,14 +9685,16 @@ async function promptForThemeInstallation(name) {
9616
9685
  }
9617
9686
 
9618
9687
  export {
9688
+ createServer,
9619
9689
  parser,
9620
9690
  version,
9621
- packageExists,
9622
9691
  resolveThemeName,
9623
9692
  getClientRoot,
9624
9693
  getCLIRoot,
9625
9694
  isPath,
9626
9695
  getThemeRoots,
9696
+ getAddonRoots,
9697
+ getRoot,
9627
9698
  getUserRoot,
9628
9699
  resolveOptions
9629
9700
  };