@slidev/cli 51.5.0 → 51.6.2
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 +1 -1
- package/dist/build-oRYT3yXD.js +62 -0
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +518 -594
- package/dist/export-D1Zqc-n1.js +433 -0
- package/dist/index.d.ts +12 -7
- package/dist/index.js +5 -17
- package/dist/resolver-BShaA6qw.js +155 -0
- package/dist/serve-D6FyjIir.js +14 -0
- package/dist/shared-D3tuRsUE.js +2475 -0
- package/package.json +30 -30
- package/dist/build-C2XVOCCA.js +0 -77
- package/dist/chunk-7TKX73CW.js +0 -2761
- package/dist/chunk-HD7KRKPM.js +0 -29
- package/dist/chunk-TJFRPB4N.js +0 -190
- package/dist/export-5TR5BGLG.js +0 -520
package/dist/chunk-HD7KRKPM.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveViteConfigs
|
|
3
|
-
} from "./chunk-7TKX73CW.js";
|
|
4
|
-
|
|
5
|
-
// node/commands/serve.ts
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import process from "node:process";
|
|
8
|
-
import { createServer as createViteServer } from "vite";
|
|
9
|
-
async function createServer(options, viteConfig = {}, serverOptions) {
|
|
10
|
-
process.env.EDITOR = process.env.EDITOR || "code";
|
|
11
|
-
const inlineConfig = await resolveViteConfigs(
|
|
12
|
-
options,
|
|
13
|
-
{
|
|
14
|
-
optimizeDeps: {
|
|
15
|
-
entries: [
|
|
16
|
-
join(options.clientRoot, "main.ts")
|
|
17
|
-
]
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
viteConfig,
|
|
21
|
-
"serve",
|
|
22
|
-
serverOptions
|
|
23
|
-
);
|
|
24
|
-
return await createViteServer(inlineConfig);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export {
|
|
28
|
-
createServer
|
|
29
|
-
};
|
package/dist/chunk-TJFRPB4N.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
// node/resolver.ts
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import { dirname, join, relative, resolve } from "node:path";
|
|
4
|
-
import process from "node:process";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { parseNi, run } from "@antfu/ni";
|
|
7
|
-
import { ensurePrefix, slash } from "@antfu/utils";
|
|
8
|
-
import { underline, yellow } from "ansis";
|
|
9
|
-
import globalDirs from "global-directory";
|
|
10
|
-
import { resolvePath } from "mlly";
|
|
11
|
-
import prompts from "prompts";
|
|
12
|
-
import { resolveGlobal } from "resolve-global";
|
|
13
|
-
import { findClosestPkgJsonPath, findDepPkgJsonPath } from "vitefu";
|
|
14
|
-
var cliRoot = fileURLToPath(new URL("..", import.meta.url));
|
|
15
|
-
var isInstalledGlobally = {};
|
|
16
|
-
async function resolveImportUrl(id) {
|
|
17
|
-
return toAtFS(await resolveImportPath(id, true));
|
|
18
|
-
}
|
|
19
|
-
function toAtFS(path) {
|
|
20
|
-
return `/@fs${ensurePrefix("/", slash(path))}`;
|
|
21
|
-
}
|
|
22
|
-
async function resolveImportPath(importName, ensure = false) {
|
|
23
|
-
try {
|
|
24
|
-
return await resolvePath(importName, {
|
|
25
|
-
url: import.meta.url
|
|
26
|
-
});
|
|
27
|
-
} catch {
|
|
28
|
-
}
|
|
29
|
-
if (isInstalledGlobally.value) {
|
|
30
|
-
try {
|
|
31
|
-
return resolveGlobal(importName);
|
|
32
|
-
} catch {
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (ensure)
|
|
36
|
-
throw new Error(`Failed to resolve package "${importName}"`);
|
|
37
|
-
}
|
|
38
|
-
async function findPkgRoot(dep, parent, ensure = false) {
|
|
39
|
-
const pkgJsonPath = await findDepPkgJsonPath(dep, parent);
|
|
40
|
-
const path = pkgJsonPath ? dirname(pkgJsonPath) : isInstalledGlobally.value ? await findGlobalPkgRoot(dep, false) : void 0;
|
|
41
|
-
if (ensure && !path)
|
|
42
|
-
throw new Error(`Failed to resolve package "${dep}"`);
|
|
43
|
-
return path;
|
|
44
|
-
}
|
|
45
|
-
async function findGlobalPkgRoot(name, ensure = false) {
|
|
46
|
-
const yarnPath = join(globalDirs.yarn.packages, name);
|
|
47
|
-
if (fs.existsSync(`${yarnPath}/package.json`))
|
|
48
|
-
return yarnPath;
|
|
49
|
-
const npmPath = join(globalDirs.npm.packages, name);
|
|
50
|
-
if (fs.existsSync(`${npmPath}/package.json`))
|
|
51
|
-
return npmPath;
|
|
52
|
-
if (ensure)
|
|
53
|
-
throw new Error(`Failed to resolve global package "${name}"`);
|
|
54
|
-
}
|
|
55
|
-
async function resolveEntry(entryRaw) {
|
|
56
|
-
if (!fs.existsSync(entryRaw) && !entryRaw.endsWith(".md") && !/[/\\]/.test(entryRaw))
|
|
57
|
-
entryRaw += ".md";
|
|
58
|
-
const entry = resolve(entryRaw);
|
|
59
|
-
if (!fs.existsSync(entry)) {
|
|
60
|
-
const { create } = await prompts({
|
|
61
|
-
name: "create",
|
|
62
|
-
type: "confirm",
|
|
63
|
-
initial: "Y",
|
|
64
|
-
message: `Entry file ${yellow(`"${entry}"`)} does not exist, do you want to create it?`
|
|
65
|
-
});
|
|
66
|
-
if (create)
|
|
67
|
-
fs.copyFileSync(resolve(cliRoot, "template.md"), entry);
|
|
68
|
-
else
|
|
69
|
-
process.exit(0);
|
|
70
|
-
}
|
|
71
|
-
return slash(entry);
|
|
72
|
-
}
|
|
73
|
-
function createResolver(type, officials) {
|
|
74
|
-
async function promptForInstallation(pkgName) {
|
|
75
|
-
const { confirm } = await prompts({
|
|
76
|
-
name: "confirm",
|
|
77
|
-
initial: "Y",
|
|
78
|
-
type: "confirm",
|
|
79
|
-
message: `The ${type} "${pkgName}" was not found ${underline(isInstalledGlobally.value ? "globally" : "in your project")}, do you want to install it now?`
|
|
80
|
-
});
|
|
81
|
-
if (!confirm)
|
|
82
|
-
process.exit(1);
|
|
83
|
-
if (isInstalledGlobally.value)
|
|
84
|
-
await run(parseNi, ["-g", pkgName]);
|
|
85
|
-
else
|
|
86
|
-
await run(parseNi, [pkgName]);
|
|
87
|
-
}
|
|
88
|
-
return async function(name, importer) {
|
|
89
|
-
const { userRoot } = await getRoots();
|
|
90
|
-
if (name === "none")
|
|
91
|
-
return ["", null];
|
|
92
|
-
if (name[0] === "/")
|
|
93
|
-
return [name, name];
|
|
94
|
-
if (name.startsWith("@/"))
|
|
95
|
-
return [name, resolve(userRoot, name.slice(2))];
|
|
96
|
-
if (name[0] === "." || name[0] !== "@" && name.includes("/"))
|
|
97
|
-
return [name, resolve(dirname(importer), name)];
|
|
98
|
-
if (name.startsWith(`@slidev/${type}-`) || name.startsWith(`slidev-${type}-`)) {
|
|
99
|
-
const pkgRoot = await findPkgRoot(name, importer);
|
|
100
|
-
if (!pkgRoot)
|
|
101
|
-
await promptForInstallation(name);
|
|
102
|
-
return [name, await findPkgRoot(name, importer, true)];
|
|
103
|
-
}
|
|
104
|
-
{
|
|
105
|
-
const possiblePkgNames = [
|
|
106
|
-
`@slidev/${type}-${name}`,
|
|
107
|
-
`slidev-${type}-${name}`,
|
|
108
|
-
name
|
|
109
|
-
];
|
|
110
|
-
for (const pkgName2 of possiblePkgNames) {
|
|
111
|
-
const pkgRoot = await findPkgRoot(pkgName2, importer);
|
|
112
|
-
if (pkgRoot)
|
|
113
|
-
return [pkgName2, pkgRoot];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const pkgName = officials[name] ?? (name[0] === "@" ? name : `slidev-${type}-${name}`);
|
|
117
|
-
await promptForInstallation(pkgName);
|
|
118
|
-
return [pkgName, await findPkgRoot(pkgName, importer, true)];
|
|
119
|
-
};
|
|
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(entry) {
|
|
162
|
-
if (rootsInfo)
|
|
163
|
-
return rootsInfo;
|
|
164
|
-
if (!entry)
|
|
165
|
-
throw new Error("[slidev] Cannot find roots without entry");
|
|
166
|
-
const userRoot = dirname(entry);
|
|
167
|
-
isInstalledGlobally.value = slash(relative(userRoot, process.argv[1])).includes("/.pnpm/") || (await import("is-installed-globally")).default;
|
|
168
|
-
const clientRoot = await findPkgRoot("@slidev/client", cliRoot, true);
|
|
169
|
-
const closestPkgRoot = dirname(await findClosestPkgJsonPath(userRoot) || userRoot);
|
|
170
|
-
const userPkgJson = getUserPkgJson(closestPkgRoot);
|
|
171
|
-
const userWorkspaceRoot = searchForWorkspaceRoot(closestPkgRoot);
|
|
172
|
-
rootsInfo = {
|
|
173
|
-
cliRoot,
|
|
174
|
-
clientRoot,
|
|
175
|
-
userRoot,
|
|
176
|
-
userPkgJson,
|
|
177
|
-
userWorkspaceRoot
|
|
178
|
-
};
|
|
179
|
-
return rootsInfo;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export {
|
|
183
|
-
isInstalledGlobally,
|
|
184
|
-
resolveImportUrl,
|
|
185
|
-
toAtFS,
|
|
186
|
-
resolveImportPath,
|
|
187
|
-
resolveEntry,
|
|
188
|
-
createResolver,
|
|
189
|
-
getRoots
|
|
190
|
-
};
|