@slidev/cli 0.48.0-beta.8 → 0.48.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.
@@ -2,21 +2,17 @@ import {
2
2
  ViteSlidevPlugin,
3
3
  getIndexHtml,
4
4
  mergeViteConfigs
5
- } from "./chunk-H6RR7TOW.mjs";
6
- import "./chunk-O6TYYGU6.mjs";
7
- import {
8
- findPkgRoot
9
- } from "./chunk-7HOZGSL4.mjs";
10
- import "./chunk-BXO7ZPPU.mjs";
5
+ } from "./chunk-EAVFHD5X.mjs";
6
+ import "./chunk-LOUKLO2C.mjs";
7
+ import "./chunk-AQQIBD5X.mjs";
11
8
 
12
- // node/build.ts
13
- import { join, resolve } from "node:path";
9
+ // node/commands/build.ts
10
+ import { resolve } from "node:path";
14
11
  import http from "node:http";
15
12
  import fs from "fs-extra";
16
13
  import { mergeConfig, build as viteBuild } from "vite";
17
14
  import connect from "connect";
18
15
  import sirv from "sirv";
19
- import { blue, yellow } from "kolorist";
20
16
  async function build(options, viteConfig = {}, args) {
21
17
  const indexPath = resolve(options.userRoot, "index.html");
22
18
  let originalIndexHTML;
@@ -53,38 +49,6 @@ async function build(options, viteConfig = {}, args) {
53
49
  }
54
50
  );
55
51
  await viteBuild(inlineConfig);
56
- if (options.data.features.monaco) {
57
- if (options.data.config.monaco === "dev") {
58
- console.log(yellow(" Monaco is disabled in the build, to enabled it, set `monaco: true` in the frontmatter"));
59
- } else {
60
- console.log(blue(" building for Monaco...\n"));
61
- const monacoRoot = await findPkgRoot("monaco-editor", options.clientRoot, true);
62
- const getWorkerPath = (path) => [join(monacoRoot, "esm/vs", path)];
63
- await viteBuild({
64
- root: join(options.clientRoot, "iframes/monaco"),
65
- base: `${config.base}iframes/monaco/`,
66
- plugins: [
67
- await ViteSlidevPlugin(options, inlineConfig.slidev || {})
68
- ],
69
- build: {
70
- outDir: resolve(options.userRoot, config.build.outDir, "iframes/monaco"),
71
- // fix for monaco workers
72
- // https://github.com/vitejs/vite/issues/1927#issuecomment-805803918
73
- rollupOptions: {
74
- output: {
75
- manualChunks: {
76
- jsonWorker: getWorkerPath("language/json/json.worker"),
77
- cssWorker: getWorkerPath("language/css/css.worker"),
78
- htmlWorker: getWorkerPath("language/html/html.worker"),
79
- tsWorker: getWorkerPath("language/typescript/ts.worker"),
80
- editorWorker: getWorkerPath("editor/editor.worker")
81
- }
82
- }
83
- }
84
- }
85
- });
86
- }
87
- }
88
52
  } finally {
89
53
  if (originalIndexHTML != null)
90
54
  await fs.writeFile(indexPath, originalIndexHTML, "utf-8");
@@ -98,7 +62,7 @@ async function build(options, viteConfig = {}, args) {
98
62
  await fs.writeFile(redirectsPath, `${config.base}* ${config.base}index.html 200
99
63
  `, "utf-8");
100
64
  if ([true, "true", "auto"].includes(options.data.config.download)) {
101
- const { exportSlides, getExportOptions } = await import("./export-SM2ZATWB.mjs");
65
+ const { exportSlides, getExportOptions } = await import("./export-P7ZNLPWH.mjs");
102
66
  const port = 12445;
103
67
  const app = connect();
104
68
  const server = http.createServer(app);
@@ -0,0 +1,187 @@
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 { 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
+ var cliRoot = fileURLToPath(new URL("..", import.meta.url));
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) {
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 ? 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 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 ? "globally" : "in your project")}, do you want to install it now?`
80
+ });
81
+ if (!confirm)
82
+ process.exit(1);
83
+ if (isInstalledGlobally)
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, join(userRoot, name.slice(2))];
96
+ if (name[0] === "." || name[0] !== "@" && name.includes("/"))
97
+ return [name, join(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 clientRoot = await findPkgRoot("@slidev/client", cliRoot, true);
167
+ const userRoot = dirname(entry);
168
+ const userPkgJson = getUserPkgJson(userRoot);
169
+ const userWorkspaceRoot = searchForWorkspaceRoot(userRoot);
170
+ rootsInfo = {
171
+ cliRoot,
172
+ clientRoot,
173
+ userRoot,
174
+ userPkgJson,
175
+ userWorkspaceRoot
176
+ };
177
+ return rootsInfo;
178
+ }
179
+
180
+ export {
181
+ resolveImportUrl,
182
+ toAtFS,
183
+ resolveImportPath,
184
+ resolveEntry,
185
+ createResolver,
186
+ getRoots
187
+ };