@slidev/cli 0.48.0-beta.17 → 0.48.0-beta.19
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/{build-TRJ6GBCA.mjs → build-V63BEPH2.mjs} +3 -4
- package/dist/{chunk-M42N6HWT.mjs → chunk-BKITU4YJ.mjs} +4 -8
- package/dist/chunk-NOI2WLJK.mjs +185 -0
- package/dist/chunk-XW74EPKM.mjs +2102 -0
- package/dist/cli.mjs +6 -7
- package/dist/{export-JD32O5W6.mjs → export-FEKJLPIJ.mjs} +1 -2
- package/dist/index.mjs +3 -4
- package/dist/{unocss-XALM635U.mjs → unocss-M5KPNI4Z.mjs} +0 -1
- package/package.json +7 -7
- package/dist/chunk-BXO7ZPPU.mjs +0 -30
- package/dist/chunk-G3BP3FUT.mjs +0 -5551
- package/dist/chunk-I5ZCLMQU.mjs +0 -4552
|
@@ -2,10 +2,9 @@ import {
|
|
|
2
2
|
ViteSlidevPlugin,
|
|
3
3
|
getIndexHtml,
|
|
4
4
|
mergeViteConfigs
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-XW74EPKM.mjs";
|
|
6
6
|
import "./chunk-O6TYYGU6.mjs";
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-BXO7ZPPU.mjs";
|
|
7
|
+
import "./chunk-NOI2WLJK.mjs";
|
|
9
8
|
|
|
10
9
|
// node/build.ts
|
|
11
10
|
import { resolve } from "node:path";
|
|
@@ -63,7 +62,7 @@ async function build(options, viteConfig = {}, args) {
|
|
|
63
62
|
await fs.writeFile(redirectsPath, `${config.base}* ${config.base}index.html 200
|
|
64
63
|
`, "utf-8");
|
|
65
64
|
if ([true, "true", "auto"].includes(options.data.config.download)) {
|
|
66
|
-
const { exportSlides, getExportOptions } = await import("./export-
|
|
65
|
+
const { exportSlides, getExportOptions } = await import("./export-FEKJLPIJ.mjs");
|
|
67
66
|
const port = 12445;
|
|
68
67
|
const app = connect();
|
|
69
68
|
const server = http.createServer(app);
|
|
@@ -2,17 +2,13 @@ import {
|
|
|
2
2
|
ViteSlidevPlugin,
|
|
3
3
|
checkEngine,
|
|
4
4
|
mergeViteConfigs,
|
|
5
|
-
require_semver,
|
|
6
5
|
version
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-XW74EPKM.mjs";
|
|
8
7
|
import {
|
|
9
8
|
createResolver,
|
|
10
9
|
getRoots,
|
|
11
10
|
resolveEntry
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import {
|
|
14
|
-
__toESM
|
|
15
|
-
} from "./chunk-BXO7ZPPU.mjs";
|
|
11
|
+
} from "./chunk-NOI2WLJK.mjs";
|
|
16
12
|
|
|
17
13
|
// node/server.ts
|
|
18
14
|
import { join } from "node:path";
|
|
@@ -54,9 +50,9 @@ async function createServer(options, viteConfig = {}, serverOptions = {}) {
|
|
|
54
50
|
import * as parser from "@slidev/parser/fs";
|
|
55
51
|
|
|
56
52
|
// node/themes.ts
|
|
57
|
-
var import_semver = __toESM(require_semver());
|
|
58
53
|
import { join as join2 } from "node:path";
|
|
59
54
|
import fs from "fs-extra";
|
|
55
|
+
import { satisfies } from "semver";
|
|
60
56
|
var officialThemes = {
|
|
61
57
|
"none": "",
|
|
62
58
|
"default": "@slidev/theme-default",
|
|
@@ -71,7 +67,7 @@ async function getThemeMeta(name, root) {
|
|
|
71
67
|
if (!fs.existsSync(path))
|
|
72
68
|
return {};
|
|
73
69
|
const { slidev = {}, engines = {} } = await fs.readJSON(path);
|
|
74
|
-
if (engines.slidev && !
|
|
70
|
+
if (engines.slidev && !satisfies(version, engines.slidev, { includePrerelease: true }))
|
|
75
71
|
throw new Error(`[slidev] theme "${name}" requires Slidev version range "${engines.slidev}" but found "${version}"`);
|
|
76
72
|
return slidev;
|
|
77
73
|
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// node/resolver.ts
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { ensurePrefix, slash } from "@antfu/utils";
|
|
7
|
+
import isInstalledGlobally from "is-installed-globally";
|
|
8
|
+
import { resolveGlobal } from "resolve-global";
|
|
9
|
+
import { findClosestPkgJsonPath, findDepPkgJsonPath } from "vitefu";
|
|
10
|
+
import { resolvePath } from "mlly";
|
|
11
|
+
import globalDirs from "global-directory";
|
|
12
|
+
import prompts from "prompts";
|
|
13
|
+
import { parseNi, run } from "@antfu/ni";
|
|
14
|
+
import { underline, yellow } from "kolorist";
|
|
15
|
+
function toAtFS(path) {
|
|
16
|
+
return `/@fs${ensurePrefix("/", slash(path))}`;
|
|
17
|
+
}
|
|
18
|
+
async function resolveImportPath(importName, ensure = false) {
|
|
19
|
+
try {
|
|
20
|
+
return await resolvePath(importName, {
|
|
21
|
+
url: fileURLToPath(import.meta.url)
|
|
22
|
+
});
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
if (isInstalledGlobally) {
|
|
26
|
+
try {
|
|
27
|
+
return resolveGlobal(importName);
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (ensure)
|
|
32
|
+
throw new Error(`Failed to resolve package "${importName}"`);
|
|
33
|
+
}
|
|
34
|
+
async function findPkgRoot(dep, parent, ensure = false) {
|
|
35
|
+
const pkgJsonPath = await findDepPkgJsonPath(dep, parent);
|
|
36
|
+
const path = pkgJsonPath ? dirname(pkgJsonPath) : isInstalledGlobally ? findGlobalPkgRoot(dep, false) : void 0;
|
|
37
|
+
if (ensure && !path)
|
|
38
|
+
throw new Error(`Failed to resolve package "${dep}"`);
|
|
39
|
+
return path;
|
|
40
|
+
}
|
|
41
|
+
async function findGlobalPkgRoot(name, ensure = false) {
|
|
42
|
+
const yarnPath = join(globalDirs.yarn.packages, name);
|
|
43
|
+
if (fs.existsSync(`${yarnPath}/package.json`))
|
|
44
|
+
return yarnPath;
|
|
45
|
+
const npmPath = join(globalDirs.npm.packages, name);
|
|
46
|
+
if (fs.existsSync(`${npmPath}/package.json`))
|
|
47
|
+
return npmPath;
|
|
48
|
+
if (ensure)
|
|
49
|
+
throw new Error(`Failed to resolve global package "${name}"`);
|
|
50
|
+
}
|
|
51
|
+
async function resolveEntry(entryRaw, roots) {
|
|
52
|
+
if (!fs.existsSync(entryRaw) && !entryRaw.endsWith(".md") && !/\/\\/.test(entryRaw))
|
|
53
|
+
entryRaw += ".md";
|
|
54
|
+
const entry = entryRaw.startsWith("@/") ? join(roots.userRoot, entryRaw.slice(2)) : resolve(process.cwd(), entryRaw);
|
|
55
|
+
if (!fs.existsSync(entry)) {
|
|
56
|
+
const { create } = await prompts({
|
|
57
|
+
name: "create",
|
|
58
|
+
type: "confirm",
|
|
59
|
+
initial: "Y",
|
|
60
|
+
message: `Entry file ${yellow(`"${entry}"`)} does not exist, do you want to create it?`
|
|
61
|
+
});
|
|
62
|
+
if (create)
|
|
63
|
+
fs.copyFileSync(resolve(roots.cliRoot, "template.md"), entry);
|
|
64
|
+
else
|
|
65
|
+
process.exit(0);
|
|
66
|
+
}
|
|
67
|
+
return entry;
|
|
68
|
+
}
|
|
69
|
+
function createResolver(type, officials) {
|
|
70
|
+
async function promptForInstallation(pkgName) {
|
|
71
|
+
const { confirm } = await prompts({
|
|
72
|
+
name: "confirm",
|
|
73
|
+
initial: "Y",
|
|
74
|
+
type: "confirm",
|
|
75
|
+
message: `The ${type} "${pkgName}" was not found ${underline(isInstalledGlobally ? "globally" : "in your project")}, do you want to install it now?`
|
|
76
|
+
});
|
|
77
|
+
if (!confirm)
|
|
78
|
+
process.exit(1);
|
|
79
|
+
if (isInstalledGlobally)
|
|
80
|
+
await run(parseNi, ["-g", pkgName]);
|
|
81
|
+
else
|
|
82
|
+
await run(parseNi, [pkgName]);
|
|
83
|
+
}
|
|
84
|
+
return async function(name, importer) {
|
|
85
|
+
const { userRoot } = await getRoots();
|
|
86
|
+
if (name === "none")
|
|
87
|
+
return ["", null];
|
|
88
|
+
if (name[0] === "/")
|
|
89
|
+
return [name, name];
|
|
90
|
+
if (name.startsWith("@/"))
|
|
91
|
+
return [name, join(userRoot, name.slice(2))];
|
|
92
|
+
if (name[0] === "." || name[0] !== "@" && name.includes("/"))
|
|
93
|
+
return [name, join(dirname(importer), name)];
|
|
94
|
+
if (name.startsWith(`@slidev/${type}-`) || name.startsWith(`slidev-${type}-`)) {
|
|
95
|
+
const pkgRoot = await findPkgRoot(name, importer);
|
|
96
|
+
if (!pkgRoot)
|
|
97
|
+
await promptForInstallation(name);
|
|
98
|
+
return [name, await findPkgRoot(name, importer, true)];
|
|
99
|
+
}
|
|
100
|
+
{
|
|
101
|
+
const possiblePkgNames = [
|
|
102
|
+
`@slidev/${type}-${name}`,
|
|
103
|
+
`slidev-${type}-${name}`,
|
|
104
|
+
name
|
|
105
|
+
];
|
|
106
|
+
for (const pkgName2 of possiblePkgNames) {
|
|
107
|
+
const pkgRoot = await findPkgRoot(pkgName2, importer);
|
|
108
|
+
if (pkgRoot)
|
|
109
|
+
return [pkgName2, pkgRoot];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const pkgName = officials[name] ?? (name[0] === "@" ? name : `slidev-${type}-${name}`);
|
|
113
|
+
await promptForInstallation(pkgName);
|
|
114
|
+
return [pkgName, await findPkgRoot(pkgName, importer, true)];
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function getUserRoot() {
|
|
118
|
+
const pkgJsonPath = await findClosestPkgJsonPath(process.cwd());
|
|
119
|
+
return pkgJsonPath ? dirname(pkgJsonPath) : process.cwd();
|
|
120
|
+
}
|
|
121
|
+
function getUserPkgJson(userRoot) {
|
|
122
|
+
const path = resolve(userRoot, "package.json");
|
|
123
|
+
if (fs.existsSync(path))
|
|
124
|
+
return JSON.parse(fs.readFileSync(path, "utf-8"));
|
|
125
|
+
return {};
|
|
126
|
+
}
|
|
127
|
+
function hasWorkspacePackageJSON(root) {
|
|
128
|
+
const path = join(root, "package.json");
|
|
129
|
+
try {
|
|
130
|
+
fs.accessSync(path, fs.constants.R_OK);
|
|
131
|
+
} catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
const content = JSON.parse(fs.readFileSync(path, "utf-8")) || {};
|
|
135
|
+
return !!content.workspaces;
|
|
136
|
+
}
|
|
137
|
+
function hasRootFile(root) {
|
|
138
|
+
const ROOT_FILES = [
|
|
139
|
+
// '.git',
|
|
140
|
+
// https://pnpm.js.org/workspaces/
|
|
141
|
+
"pnpm-workspace.yaml"
|
|
142
|
+
// https://rushjs.io/pages/advanced/config_files/
|
|
143
|
+
// 'rush.json',
|
|
144
|
+
// https://nx.dev/latest/react/getting-started/nx-setup
|
|
145
|
+
// 'workspace.json',
|
|
146
|
+
// 'nx.json'
|
|
147
|
+
];
|
|
148
|
+
return ROOT_FILES.some((file) => fs.existsSync(join(root, file)));
|
|
149
|
+
}
|
|
150
|
+
function searchForWorkspaceRoot(current, root = current) {
|
|
151
|
+
if (hasRootFile(current))
|
|
152
|
+
return current;
|
|
153
|
+
if (hasWorkspacePackageJSON(current))
|
|
154
|
+
return current;
|
|
155
|
+
const dir = dirname(current);
|
|
156
|
+
if (!dir || dir === current)
|
|
157
|
+
return root;
|
|
158
|
+
return searchForWorkspaceRoot(dir, root);
|
|
159
|
+
}
|
|
160
|
+
var rootsInfo = null;
|
|
161
|
+
async function getRoots() {
|
|
162
|
+
if (rootsInfo)
|
|
163
|
+
return rootsInfo;
|
|
164
|
+
const cliRoot = fileURLToPath(new URL("..", import.meta.url));
|
|
165
|
+
const clientRoot = await findPkgRoot("@slidev/client", cliRoot, true);
|
|
166
|
+
const userRoot = await getUserRoot();
|
|
167
|
+
const userPkgJson = getUserPkgJson(userRoot);
|
|
168
|
+
const userWorkspaceRoot = searchForWorkspaceRoot(userRoot);
|
|
169
|
+
rootsInfo = {
|
|
170
|
+
cliRoot,
|
|
171
|
+
clientRoot,
|
|
172
|
+
userRoot,
|
|
173
|
+
userPkgJson,
|
|
174
|
+
userWorkspaceRoot
|
|
175
|
+
};
|
|
176
|
+
return rootsInfo;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export {
|
|
180
|
+
toAtFS,
|
|
181
|
+
resolveImportPath,
|
|
182
|
+
resolveEntry,
|
|
183
|
+
createResolver,
|
|
184
|
+
getRoots
|
|
185
|
+
};
|