rspress 1.9.3 → 1.10.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.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { }
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // src/index.ts
2
2
  import { createRequire as createRequire2 } from "module";
3
- import path2 from "path";
3
+ import path3 from "path";
4
4
  import { cac } from "cac";
5
5
  import { build, dev, serve } from "@rspress/core";
6
- import { logger } from "@rspress/shared/logger";
6
+ import { logger as logger2 } from "@rspress/shared/logger";
7
7
  import chokidar from "chokidar";
8
8
  import chalk from "chalk";
9
9
 
@@ -54,6 +54,58 @@ async function loadConfigFile(customConfigFile) {
54
54
  return result;
55
55
  }
56
56
 
57
+ // src/update.ts
58
+ import path2 from "path";
59
+ import fs2 from "fs/promises";
60
+ import { spawn } from "child_process";
61
+ import { pathExists } from "@rspress/shared/fs-extra";
62
+ import { logger } from "@rspress/shared/logger";
63
+ var lockfileMap = {
64
+ "package-lock.json": "npm",
65
+ "yarn.lock": "yarn",
66
+ "pnpm-lock.yaml": "pnpm",
67
+ "bun.lockb": "bun"
68
+ };
69
+ async function getPackageManager(rootPath) {
70
+ let packageManager = "npm";
71
+ for (const file of Object.keys(lockfileMap)) {
72
+ if (await pathExists(path2.join(rootPath, file))) {
73
+ packageManager = lockfileMap[file];
74
+ break;
75
+ }
76
+ }
77
+ return packageManager;
78
+ }
79
+ async function getRspressDependencies(rootPath) {
80
+ const packageJson2 = JSON.parse(
81
+ await fs2.readFile(path2.join(rootPath, "package.json"), {
82
+ encoding: "utf-8"
83
+ })
84
+ );
85
+ const dependencies = packageJson2?.dependencies ? Object.keys(packageJson2.dependencies) : [];
86
+ const devDependencies = packageJson2?.devDependencies ? Object.keys(packageJson2.devDependencies) : [];
87
+ return dependencies.concat(devDependencies).filter((item) => item.startsWith("@rspress") || item.startsWith("rspress"));
88
+ }
89
+ async function update() {
90
+ const cwd = process.cwd();
91
+ const packageManager = await getPackageManager(cwd);
92
+ const rspressDependencies = await getRspressDependencies(cwd);
93
+ logger.greet(
94
+ `Using ${packageManager} to update ${rspressDependencies.join(" ")}`
95
+ );
96
+ if (packageManager === "npm" || packageManager === "bun") {
97
+ const dependencies = rspressDependencies.map((item) => `${item}@latest`);
98
+ spawn(packageManager, ["install", "--save", ...dependencies], {
99
+ stdio: "inherit"
100
+ });
101
+ } else {
102
+ const subCommand = packageManager === "yarn" ? "upgrade" : "update";
103
+ spawn(packageManager, [subCommand, "--latest", ...rspressDependencies], {
104
+ stdio: "inherit"
105
+ });
106
+ }
107
+ }
108
+
57
109
  // src/index.ts
58
110
  var CONFIG_FILES = ["rspress.config.ts", "rspress.config.js", "_meta.json"];
59
111
  var require2 = createRequire2(import.meta.url);
@@ -61,11 +113,11 @@ var packageJson = require2("../package.json");
61
113
  var cli = cac("rspress").version(packageJson.version).help();
62
114
  var landingMessage = `🔥 Rspress v${packageJson.version}
63
115
  `;
64
- logger.greet(landingMessage);
116
+ logger2.greet(landingMessage);
65
117
  var setNodeEnv = (env) => {
66
118
  process.env.NODE_ENV = env;
67
119
  };
68
- cli.option("--config [config]", "Specify the path to the config file");
120
+ cli.option("-c,--config [config]", "Specify the path to the config file");
69
121
  cli.command("[root]", "start dev server").alias("dev").option("--port [port]", "port number").option("--host [host]", "hostname").action(
70
122
  async (root, options) => {
71
123
  setNodeEnv("development");
@@ -77,13 +129,13 @@ cli.command("[root]", "start dev server").alias("dev").option("--port [port]", "
77
129
  const startDevServer = async () => {
78
130
  const { port, host } = options || {};
79
131
  const config = await loadConfigFile(options?.config);
80
- if (config.root && !path2.isAbsolute(config.root)) {
81
- config.root = path2.join(cwd, config.root);
132
+ if (config.root && !path3.isAbsolute(config.root)) {
133
+ config.root = path3.join(cwd, config.root);
82
134
  }
83
135
  if (root) {
84
- config.root = path2.join(cwd, root);
136
+ config.root = path3.join(cwd, root);
85
137
  }
86
- docDirectory = config.root || path2.join(cwd, root ?? "docs");
138
+ docDirectory = config.root || path3.join(cwd, root ?? "docs");
87
139
  devServer = await dev({
88
140
  appDirectory: cwd,
89
141
  docDirectory,
@@ -98,7 +150,7 @@ cli.command("[root]", "start dev server").alias("dev").option("--port [port]", "
98
150
  }
99
151
  );
100
152
  cliWatcher.on("all", async (eventName, filepath) => {
101
- if (eventName === "add" || eventName === "unlink" || eventName === "change" && CONFIG_FILES.includes(path2.basename(filepath))) {
153
+ if (eventName === "add" || eventName === "unlink" || eventName === "change" && CONFIG_FILES.includes(path3.basename(filepath))) {
102
154
  if (isRestarting) {
103
155
  return;
104
156
  }
@@ -106,7 +158,7 @@ cli.command("[root]", "start dev server").alias("dev").option("--port [port]", "
106
158
  console.log(
107
159
  `
108
160
  ✨ ${eventName} ${chalk.green(
109
- path2.relative(cwd, filepath)
161
+ path3.relative(cwd, filepath)
110
162
  )}, dev server will restart...
111
163
  `
112
164
  );
@@ -126,20 +178,20 @@ cli.command("[root]", "start dev server").alias("dev").option("--port [port]", "
126
178
  process.on("SIGTERM", exitProcess);
127
179
  }
128
180
  );
129
- cli.command("build [root]").option("-c --config <config>", "specify config file").action(async (root, options) => {
181
+ cli.command("build [root]").action(async (root, options) => {
130
182
  setNodeEnv("production");
131
183
  const cwd = process.cwd();
132
184
  const config = await loadConfigFile(options.config);
133
185
  if (root) {
134
- config.root = path2.join(cwd, root);
186
+ config.root = path3.join(cwd, root);
135
187
  }
136
188
  await build({
137
189
  appDirectory: cwd,
138
- docDirectory: config.root || path2.join(cwd, root ?? "docs"),
190
+ docDirectory: config.root || path3.join(cwd, root ?? "docs"),
139
191
  config
140
192
  });
141
193
  });
142
- cli.command("preview").alias("serve").option("-c --config <config>", "specify config file").option("--port [port]", "port number").option("--host [host]", "hostname").action(
194
+ cli.command("preview").alias("serve").option("--port [port]", "port number").option("--host [host]", "hostname").action(
143
195
  async (options) => {
144
196
  setNodeEnv("production");
145
197
  const { port, host } = options || {};
@@ -151,4 +203,5 @@ cli.command("preview").alias("serve").option("-c --config <config>", "specify co
151
203
  });
152
204
  }
153
205
  );
206
+ cli.command("update", "update elavant packages about rspress").action(update);
154
207
  cli.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rspress",
3
- "version": "1.9.3",
3
+ "version": "1.10.0",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -28,12 +28,12 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@modern-js/node-bundle-require": "2.45.0",
31
+ "@modern-js/node-bundle-require": "2.46.0",
32
32
  "cac": "^6.7.14",
33
33
  "chokidar": "^3.5.3",
34
34
  "chalk": "5.3.0",
35
- "@rspress/shared": "1.9.3",
36
- "@rspress/core": "1.9.3"
35
+ "@rspress/core": "1.10.0",
36
+ "@rspress/shared": "1.10.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/jest": "~29.2.4",