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 +1 -2
- package/dist/index.js +162 -184
- package/package.json +9 -10
package/dist/index.d.ts
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
export { }
|
1
|
+
export { }
|
package/dist/index.js
CHANGED
@@ -1,213 +1,191 @@
|
|
1
|
-
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import
|
8
|
-
import
|
9
|
-
|
10
|
-
|
11
|
-
import
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
if (
|
35
|
-
|
36
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
55
|
-
return
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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(
|
128
|
-
cli.command(
|
129
|
-
|
130
|
-
setNodeEnv(
|
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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
)
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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(
|
183
|
-
process.on(
|
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(
|
199
|
-
|
200
|
-
|
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
|
-
|
207
|
-
|
208
|
-
|
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.
|
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.
|
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.
|
36
|
-
"@rspress/shared": "1.37.
|
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": "
|
61
|
-
"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
|
}
|