@slidev/cli 0.48.0-beta.3 → 0.48.0-beta.5

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.
@@ -0,0 +1,155 @@
1
+ import {
2
+ ViteSlidevPlugin,
3
+ checkEngine,
4
+ mergeViteConfigs,
5
+ require_semver,
6
+ version
7
+ } from "./chunk-U44GKKNH.mjs";
8
+ import {
9
+ createResolver,
10
+ getRoots,
11
+ resolveEntry
12
+ } from "./chunk-7HOZGSL4.mjs";
13
+ import {
14
+ __toESM
15
+ } from "./chunk-BXO7ZPPU.mjs";
16
+
17
+ // node/server.ts
18
+ import { join } from "node:path";
19
+ import process from "node:process";
20
+ import { createServer as createViteServer, mergeConfig } from "vite";
21
+ async function createServer(options, viteConfig = {}, serverOptions = {}) {
22
+ process.env.EDITOR = process.env.EDITOR || "code";
23
+ const config = await mergeViteConfigs(
24
+ options,
25
+ viteConfig,
26
+ {
27
+ root: options.userRoot,
28
+ optimizeDeps: {
29
+ entries: [
30
+ join(options.clientRoot, "main.ts")
31
+ ]
32
+ }
33
+ },
34
+ "serve"
35
+ );
36
+ const server = await createViteServer(
37
+ mergeConfig(
38
+ config,
39
+ {
40
+ plugins: [
41
+ await ViteSlidevPlugin(options, config.slidev || {}, serverOptions)
42
+ ],
43
+ define: {
44
+ // Fixes Vue production mode breaking PDF Export #1245
45
+ __VUE_PROD_DEVTOOLS__: JSON.stringify(true)
46
+ }
47
+ }
48
+ )
49
+ );
50
+ return server;
51
+ }
52
+
53
+ // node/parser.ts
54
+ import * as parser from "@slidev/parser/fs";
55
+
56
+ // node/themes.ts
57
+ var import_semver = __toESM(require_semver());
58
+ import { join as join2 } from "node:path";
59
+ import fs from "fs-extra";
60
+ var officialThemes = {
61
+ "none": "",
62
+ "default": "@slidev/theme-default",
63
+ "seriph": "@slidev/theme-seriph",
64
+ "apple-basic": "@slidev/theme-apple-basic",
65
+ "shibainu": "@slidev/theme-shibainu",
66
+ "bricks": "@slidev/theme-bricks"
67
+ };
68
+ var resolveTheme = createResolver("theme", officialThemes);
69
+ async function getThemeMeta(name, root) {
70
+ const path = join2(root, "package.json");
71
+ if (!fs.existsSync(path))
72
+ return {};
73
+ const { slidev = {}, engines = {} } = await fs.readJSON(path);
74
+ if (engines.slidev && !(0, import_semver.satisfies)(version, engines.slidev, { includePrerelease: true }))
75
+ throw new Error(`[slidev] theme "${name}" requires Slidev version range "${engines.slidev}" but found "${version}"`);
76
+ return slidev;
77
+ }
78
+
79
+ // node/addons.ts
80
+ import { resolve } from "node:path";
81
+ import fs2 from "fs-extra";
82
+ async function resolveAddons(addonsInConfig) {
83
+ const { userRoot, userPkgJson } = await getRoots();
84
+ const resolved = [];
85
+ const resolveAddonNameAndRoot = createResolver("addon", {});
86
+ async function resolveAddon(name, parent) {
87
+ const [, pkgRoot] = await resolveAddonNameAndRoot(name, parent);
88
+ if (!pkgRoot)
89
+ return;
90
+ resolved.push(pkgRoot);
91
+ const { slidev, engines } = await fs2.readJSON(resolve(pkgRoot, "package.json"));
92
+ checkEngine(name, engines);
93
+ if (Array.isArray(slidev?.addons))
94
+ await Promise.all(slidev.addons.map((addon) => resolveAddon(addon, pkgRoot)));
95
+ }
96
+ if (Array.isArray(addonsInConfig))
97
+ await Promise.all(addonsInConfig.map((addon) => resolveAddon(addon, userRoot)));
98
+ if (Array.isArray(userPkgJson.slidev?.addons))
99
+ await Promise.all(userPkgJson.slidev.addons.map((addon) => resolveAddon(addon, userRoot)));
100
+ return resolved;
101
+ }
102
+
103
+ // node/options.ts
104
+ import { uniq } from "@antfu/utils";
105
+ import _debug from "debug";
106
+ var debug = _debug("slidev:options");
107
+ async function resolveOptions(options, mode) {
108
+ const rootsInfo = await getRoots();
109
+ const entry = await resolveEntry(options.entry || "slides.md", rootsInfo);
110
+ const loaded = await parser.load(rootsInfo.userRoot, entry);
111
+ const themeRaw = options.theme || loaded.headmatter.theme || "default";
112
+ const [theme, themeRoot] = await resolveTheme(themeRaw, entry);
113
+ const themeRoots = themeRoot ? [themeRoot] : [];
114
+ const themeMeta = themeRoot ? await getThemeMeta(theme, themeRoot) : void 0;
115
+ const config = parser.resolveConfig(loaded.headmatter, themeMeta, options.entry);
116
+ const addonRoots = await resolveAddons(config.addons);
117
+ const roots = uniq([...themeRoots, ...addonRoots, rootsInfo.userRoot]);
118
+ debug({
119
+ ...rootsInfo,
120
+ ...options,
121
+ config,
122
+ mode,
123
+ entry,
124
+ themeRaw,
125
+ theme,
126
+ themeRoots,
127
+ addonRoots,
128
+ roots
129
+ });
130
+ return {
131
+ ...rootsInfo,
132
+ ...options,
133
+ data: {
134
+ ...loaded,
135
+ config,
136
+ themeMeta
137
+ },
138
+ mode,
139
+ entry,
140
+ themeRaw,
141
+ theme,
142
+ themeRoots,
143
+ addonRoots,
144
+ roots
145
+ };
146
+ }
147
+
148
+ export {
149
+ createServer,
150
+ parser,
151
+ resolveTheme,
152
+ getThemeMeta,
153
+ resolveAddons,
154
+ resolveOptions
155
+ };
@@ -2,29 +2,17 @@
2
2
  import { resolve } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import fs from "fs-extra";
5
- import { isObject } from "@antfu/utils";
5
+ import { deepMergeWithArray } from "@antfu/utils";
6
6
  import jiti from "jiti";
7
- function deepMerge(a, b, rootPath = "") {
8
- a = { ...a };
9
- Object.keys(b).forEach((key) => {
10
- if (isObject(a[key]))
11
- a[key] = deepMerge(a[key], b[key], rootPath ? `${rootPath}.${key}` : key);
12
- else if (Array.isArray(a[key]))
13
- a[key] = [...a[key], ...b[key]];
14
- else
15
- a[key] = b[key];
16
- });
17
- return a;
18
- }
19
- async function loadSetups(roots, name, arg, initial, merge = true) {
7
+ async function loadSetups(clientRoot, roots, name, arg, initial, merge = true) {
20
8
  let returns = initial;
21
- for (const root of roots) {
9
+ for (const root of [clientRoot, ...roots].reverse()) {
22
10
  const path = resolve(root, "setup", name);
23
11
  if (fs.existsSync(path)) {
24
12
  const { default: setup } = jiti(fileURLToPath(import.meta.url))(path);
25
13
  const result = await setup(arg);
26
14
  if (result !== null) {
27
- returns = typeof merge === "function" ? merge(returns, result) : merge ? deepMerge(returns, result) : result;
15
+ returns = typeof merge === "function" ? merge(returns, result) : merge ? deepMergeWithArray(returns, result) : result;
28
16
  }
29
17
  }
30
18
  }