rspress 1.37.1 → 1.37.3

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 @@
1
-
2
- export { }
1
+ export { }
package/dist/index.js CHANGED
@@ -1,213 +1,191 @@
1
- // src/index.ts
2
- import { createRequire } from "module";
3
- import path3 from "path";
4
- import { cac } from "cac";
5
- import { build, dev, serve } from "@rspress/core";
6
- import { logger as logger3 } from "@rspress/shared/logger";
7
- import chokidar from "chokidar";
8
- import chalk from "chalk";
9
-
10
- // src/config/loadConfigFile.ts
11
- import fs from "fs";
12
- import path from "path";
13
- import { logger } from "@rspress/shared/logger";
14
-
15
- // src/constants.ts
16
- var DEFAULT_CONFIG_NAME = "rspress.config";
17
- var DEFAULT_EXTENSIONS = [
18
- ".js",
19
- ".ts",
20
- ".mjs",
21
- ".mts",
22
- ".cjs",
23
- ".cts"
1
+ import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
3
+ import * as __WEBPACK_EXTERNAL_MODULE_cac__ from "cac";
4
+ import * as __WEBPACK_EXTERNAL_MODULE__rspress_core__ from "@rspress/core";
5
+ import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger__ from "@rspress/shared/logger";
6
+ import * as __WEBPACK_EXTERNAL_MODULE_chokidar__ from "chokidar";
7
+ import * as __WEBPACK_EXTERNAL_MODULE_chalk__ from "chalk";
8
+ import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
9
+ import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises__ from "node:fs/promises";
10
+ import * as __WEBPACK_EXTERNAL_MODULE_node_child_process__ from "node:child_process";
11
+ import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__ from "@rspress/shared/fs-extra";
12
+ const DEFAULT_CONFIG_NAME = 'rspress.config';
13
+ const DEFAULT_EXTENSIONS = [
14
+ '.js',
15
+ '.ts',
16
+ '.mjs',
17
+ '.mts',
18
+ '.cjs',
19
+ '.cts'
24
20
  ];
25
-
26
- // src/config/loadConfigFile.ts
27
- var findConfig = (basePath) => {
28
- return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
29
- };
21
+ const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync);
30
22
  async function loadConfigFile(customConfigFile) {
31
- const baseDir = process.cwd();
32
- let configFilePath = "";
33
- if (customConfigFile) {
34
- if (path.isAbsolute(customConfigFile)) {
35
- configFilePath = customConfigFile;
36
- } else {
37
- configFilePath = path.join(baseDir, customConfigFile);
23
+ const baseDir = process.cwd();
24
+ let configFilePath = '';
25
+ configFilePath = customConfigFile ? __WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(customConfigFile) ? customConfigFile : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(baseDir, customConfigFile) : findConfig(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(baseDir, DEFAULT_CONFIG_NAME));
26
+ if (!configFilePath) {
27
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger__.logger.info(`No config file found in ${baseDir}`);
28
+ return {};
38
29
  }
39
- } else {
40
- configFilePath = findConfig(path.join(baseDir, DEFAULT_CONFIG_NAME));
41
- }
42
- if (!configFilePath) {
43
- logger.info(`No config file found in ${baseDir}`);
44
- return {};
45
- }
46
- const { loadConfig } = await import("@rsbuild/core");
47
- const { content } = await loadConfig({
48
- cwd: path.dirname(configFilePath),
49
- path: configFilePath
50
- });
51
- return content;
30
+ const { loadConfig } = await import("@rsbuild/core");
31
+ const { content } = await loadConfig({
32
+ cwd: __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(configFilePath),
33
+ path: configFilePath
34
+ });
35
+ return content;
52
36
  }
53
37
  function resolveDocRoot(cwd, cliRoot, configRoot) {
54
- if (cliRoot) {
55
- return path.join(cwd, cliRoot);
56
- }
57
- if (configRoot) {
58
- return path.isAbsolute(configRoot) ? configRoot : path.join(cwd, configRoot);
59
- }
60
- return path.join(cwd, "docs");
38
+ // CLI root has highest priority
39
+ if (cliRoot) return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(cwd, cliRoot);
40
+ // Config root is next in priority
41
+ if (configRoot) return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(configRoot) ? configRoot : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(cwd, configRoot);
42
+ // Default to 'docs' if no root is specified
43
+ return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(cwd, 'docs');
61
44
  }
62
-
63
- // src/update.ts
64
- import path2 from "path";
65
- import fs2 from "fs/promises";
66
- import { spawn } from "child_process";
67
- import { pathExists } from "@rspress/shared/fs-extra";
68
- import { logger as logger2 } from "@rspress/shared/logger";
69
- var lockfileMap = {
70
- "package-lock.json": "npm",
71
- "yarn.lock": "yarn",
72
- "pnpm-lock.yaml": "pnpm",
73
- "bun.lockb": "bun"
45
+ const lockfileMap = {
46
+ 'package-lock.json': 'npm',
47
+ 'yarn.lock': 'yarn',
48
+ 'pnpm-lock.yaml': 'pnpm',
49
+ 'bun.lockb': 'bun'
74
50
  };
75
51
  async function getPackageManager(rootPath) {
76
- let packageManager = "npm";
77
- for (const file of Object.keys(lockfileMap)) {
78
- if (await pathExists(path2.join(rootPath, file))) {
79
- packageManager = lockfileMap[file];
80
- break;
52
+ let packageManager = 'npm';
53
+ for (const file of Object.keys(lockfileMap))if (await (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_fs_extra__.pathExists)(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(rootPath, file))) {
54
+ packageManager = lockfileMap[file];
55
+ break;
81
56
  }
82
- }
83
- return packageManager;
57
+ return packageManager;
84
58
  }
85
59
  async function getRspressDependencies(rootPath) {
86
- const packageJson2 = JSON.parse(
87
- await fs2.readFile(path2.join(rootPath, "package.json"), {
88
- encoding: "utf-8"
89
- })
90
- );
91
- const dependencies = packageJson2?.dependencies ? Object.keys(packageJson2.dependencies) : [];
92
- const devDependencies = packageJson2?.devDependencies ? Object.keys(packageJson2.devDependencies) : [];
93
- return dependencies.concat(devDependencies).filter((item) => item.startsWith("@rspress") || item.startsWith("rspress"));
60
+ const packageJson = JSON.parse(await __WEBPACK_EXTERNAL_MODULE_node_fs_promises__["default"].readFile(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(rootPath, 'package.json'), {
61
+ encoding: 'utf-8'
62
+ }));
63
+ const dependencies = packageJson?.dependencies ? Object.keys(packageJson.dependencies) : [];
64
+ const devDependencies = packageJson?.devDependencies ? Object.keys(packageJson.devDependencies) : [];
65
+ return dependencies.concat(devDependencies).filter((item)=>item.startsWith('@rspress') || item.startsWith('rspress'));
94
66
  }
95
67
  async function update() {
96
- const cwd = process.cwd();
97
- const packageManager = await getPackageManager(cwd);
98
- const rspressDependencies = await getRspressDependencies(cwd);
99
- logger2.greet(
100
- `Using ${packageManager} to update ${rspressDependencies.join(" ")}`
101
- );
102
- if (packageManager === "npm" || packageManager === "bun") {
103
- const dependencies = rspressDependencies.map((item) => `${item}@latest`);
104
- spawn(packageManager, ["install", "--save", ...dependencies], {
105
- stdio: "inherit"
106
- });
107
- } else {
108
- const subCommand = packageManager === "yarn" ? "upgrade" : "update";
109
- spawn(packageManager, [subCommand, "--latest", ...rspressDependencies], {
110
- stdio: "inherit"
111
- });
112
- }
68
+ const cwd = process.cwd();
69
+ const packageManager = await getPackageManager(cwd);
70
+ const rspressDependencies = await getRspressDependencies(cwd);
71
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger__.logger.greet(`Using ${packageManager} to update ${rspressDependencies.join(' ')}`);
72
+ if ('npm' === packageManager || 'bun' === packageManager) {
73
+ const dependencies = rspressDependencies.map((item)=>`${item}@latest`);
74
+ (0, __WEBPACK_EXTERNAL_MODULE_node_child_process__.spawn)(packageManager, [
75
+ 'install',
76
+ '--save',
77
+ ...dependencies
78
+ ], {
79
+ stdio: 'inherit'
80
+ });
81
+ } else {
82
+ const subCommand = 'yarn' === packageManager ? 'upgrade' : 'update';
83
+ (0, __WEBPACK_EXTERNAL_MODULE_node_child_process__.spawn)(packageManager, [
84
+ subCommand,
85
+ '--latest',
86
+ ...rspressDependencies
87
+ ], {
88
+ stdio: 'inherit'
89
+ });
90
+ }
113
91
  }
114
-
115
- // src/index.ts
116
- var CONFIG_FILES = ["rspress.config.ts", "rspress.config.js", "i18n.json"];
117
- var META_FILE = "_meta.json";
118
- var require2 = createRequire(import.meta.url);
119
- var packageJson = require2("../package.json");
120
- var cli = cac("rspress").version(packageJson.version).help();
121
- var landingMessage = `🔥 Rspress v${packageJson.version}
122
- `;
123
- logger3.greet(landingMessage);
124
- var setNodeEnv = (env) => {
125
- process.env.NODE_ENV = env;
92
+ const CONFIG_FILES = [
93
+ 'rspress.config.ts',
94
+ 'rspress.config.js',
95
+ 'i18n.json'
96
+ ];
97
+ const META_FILE = '_meta.json';
98
+ const src_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url);
99
+ // eslint-disable-next-line import/no-commonjs
100
+ const src_packageJson = src_require('../package.json');
101
+ const cli = (0, __WEBPACK_EXTERNAL_MODULE_cac__.cac)('rspress').version(src_packageJson.version).help();
102
+ const landingMessage = `🔥 Rspress v${src_packageJson.version}\n`;
103
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger__.logger.greet(landingMessage);
104
+ const setNodeEnv = (env)=>{
105
+ process.env.NODE_ENV = env;
126
106
  };
127
- cli.option("-c,--config [config]", "Specify the path to the config file");
128
- cli.command("[root]", "start dev server").alias("dev").option("--port [port]", "port number").option("--host [host]", "hostname").action(
129
- async (root, options) => {
130
- setNodeEnv("development");
107
+ cli.option('-c,--config [config]', 'Specify the path to the config file');
108
+ cli.command('[root]', 'start dev server') // default command
109
+ .alias('dev').option('--port [port]', 'port number').option('--host [host]', 'hostname').action(async (root, options)=>{
110
+ setNodeEnv('development');
131
111
  let isRestarting = false;
132
112
  const cwd = process.cwd();
133
113
  let cliWatcher;
134
114
  let devServer;
135
- const startDevServer = async () => {
136
- const { port, host } = options || {};
137
- const config = await loadConfigFile(options?.config);
138
- config.root = resolveDocRoot(cwd, root, config.root);
139
- const docDirectory = config.root;
140
- devServer = await dev({
141
- appDirectory: cwd,
142
- docDirectory,
143
- config,
144
- extraBuilderConfig: { server: { port, host } }
145
- });
146
- cliWatcher = chokidar.watch(
147
- [`${cwd}/**/{${CONFIG_FILES.join(",")}}`, docDirectory],
148
- {
149
- ignoreInitial: true,
150
- ignored: ["**/node_modules/**", "**/.git/**", "**/.DS_Store/**"]
151
- }
152
- );
153
- cliWatcher.on("all", async (eventName, filepath) => {
154
- if (eventName === "add" || eventName === "unlink" || eventName === "change" && (CONFIG_FILES.includes(path3.basename(filepath)) || path3.basename(filepath) === META_FILE)) {
155
- if (isRestarting) {
156
- return;
157
- }
158
- isRestarting = true;
159
- console.log(
160
- `
161
- ✨ ${eventName} ${chalk.green(
162
- path3.relative(cwd, filepath)
163
- )}, dev server will restart...
164
- `
165
- );
166
- await devServer.close();
167
- await cliWatcher.close();
168
- await startDevServer();
169
- isRestarting = false;
170
- }
171
- });
115
+ const startDevServer = async ()=>{
116
+ const { port, host } = options || {};
117
+ const config = await loadConfigFile(options?.config);
118
+ config.root = resolveDocRoot(cwd, root, config.root);
119
+ const docDirectory = config.root;
120
+ devServer = await (0, __WEBPACK_EXTERNAL_MODULE__rspress_core__.dev)({
121
+ appDirectory: cwd,
122
+ docDirectory,
123
+ config,
124
+ extraBuilderConfig: {
125
+ server: {
126
+ port,
127
+ host
128
+ }
129
+ }
130
+ });
131
+ cliWatcher = __WEBPACK_EXTERNAL_MODULE_chokidar__["default"].watch([
132
+ `${cwd}/**/{${CONFIG_FILES.join(',')}}`,
133
+ docDirectory
134
+ ], {
135
+ ignoreInitial: true,
136
+ ignored: [
137
+ '**/node_modules/**',
138
+ '**/.git/**',
139
+ '**/.DS_Store/**'
140
+ ]
141
+ });
142
+ cliWatcher.on('all', async (eventName, filepath)=>{
143
+ if ('add' === eventName || 'unlink' === eventName || 'change' === eventName && (CONFIG_FILES.includes(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].basename(filepath)) || __WEBPACK_EXTERNAL_MODULE_node_path__["default"].basename(filepath) === META_FILE)) {
144
+ if (isRestarting) return;
145
+ isRestarting = true;
146
+ console.log(`\n✨ ${eventName} ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].green(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].relative(cwd, filepath))}, dev server will restart...\n`);
147
+ await devServer.close();
148
+ await cliWatcher.close();
149
+ await startDevServer();
150
+ isRestarting = false;
151
+ }
152
+ });
172
153
  };
173
154
  await startDevServer();
174
- const exitProcess = async () => {
175
- try {
176
- await devServer.close();
177
- await cliWatcher.close();
178
- } finally {
179
- process.exit(0);
180
- }
155
+ const exitProcess = async ()=>{
156
+ try {
157
+ await devServer.close();
158
+ await cliWatcher.close();
159
+ } finally{
160
+ process.exit(0);
161
+ }
181
162
  };
182
- process.on("SIGINT", exitProcess);
183
- process.on("SIGTERM", exitProcess);
184
- }
185
- );
186
- cli.command("build [root]").action(async (root, options) => {
187
- setNodeEnv("production");
188
- const cwd = process.cwd();
189
- const config = await loadConfigFile(options.config);
190
- config.root = resolveDocRoot(cwd, root, config.root);
191
- const docDirectory = config.root;
192
- await build({
193
- appDirectory: cwd,
194
- docDirectory,
195
- config
196
- });
163
+ process.on('SIGINT', exitProcess);
164
+ process.on('SIGTERM', exitProcess);
197
165
  });
198
- cli.command("preview [root]").alias("serve").option("--port [port]", "port number").option("--host [host]", "hostname").action(
199
- async (root, options) => {
200
- setNodeEnv("production");
166
+ cli.command('build [root]').action(async (root, options)=>{
167
+ setNodeEnv('production');
168
+ const cwd = process.cwd();
169
+ const config = await loadConfigFile(options.config);
170
+ config.root = resolveDocRoot(cwd, root, config.root);
171
+ const docDirectory = config.root;
172
+ await (0, __WEBPACK_EXTERNAL_MODULE__rspress_core__.build)({
173
+ appDirectory: cwd,
174
+ docDirectory,
175
+ config
176
+ });
177
+ });
178
+ cli.command('preview [root]').alias('serve').option('--port [port]', 'port number').option('--host [host]', 'hostname').action(async (root, options)=>{
179
+ setNodeEnv('production');
201
180
  const cwd = process.cwd();
202
181
  const { port, host } = options || {};
203
182
  const config = await loadConfigFile(options?.config);
204
183
  config.root = resolveDocRoot(cwd, root, config.root);
205
- await serve({
206
- config,
207
- host,
208
- port
184
+ await (0, __WEBPACK_EXTERNAL_MODULE__rspress_core__.serve)({
185
+ config,
186
+ host,
187
+ port
209
188
  });
210
- }
211
- );
212
- cli.command("update", "update relevant packages about rspress").action(update);
189
+ });
190
+ cli.command('update', 'update relevant packages about rspress').action(update);
213
191
  cli.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rspress",
3
- "version": "1.37.1",
3
+ "version": "1.37.3",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -28,14 +28,16 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@rsbuild/core": "~1.1.3",
31
+ "@rsbuild/core": "~1.1.4",
32
32
  "cac": "^6.7.14",
33
33
  "chalk": "5.3.0",
34
34
  "chokidar": "^3.6.0",
35
- "@rspress/core": "1.37.1",
36
- "@rspress/shared": "1.37.1"
35
+ "@rspress/core": "1.37.3",
36
+ "@rspress/shared": "1.37.3"
37
37
  },
38
38
  "devDependencies": {
39
+ "@microsoft/api-extractor": "^7.48.0",
40
+ "@rslib/core": "0.1.0",
39
41
  "@types/jest": "~29.5.14",
40
42
  "@types/node": "^18.11.17",
41
43
  "@types/react": "^18.3.12",
@@ -57,12 +59,9 @@
57
59
  "config.ts"
58
60
  ],
59
61
  "scripts": {
60
- "dev": "modern build -w",
61
- "build": "modern build",
62
- "build:watch": "modern build -w",
62
+ "dev": "rslib build -w",
63
+ "build": "rslib build",
63
64
  "test": "vitest run",
64
- "reset": "rimraf ./**/node_modules",
65
- "new": "modern new",
66
- "upgrade": "modern upgrade"
65
+ "reset": "rimraf ./**/node_modules"
67
66
  }
68
67
  }