@rspress/shared 1.41.0 → 1.41.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/dist/index.d.ts +938 -51
- package/dist/index.js +192 -242
- package/dist/index.mjs +132 -189
- package/dist/logger.d.ts +5 -2
- package/dist/logger.js +33 -27
- package/dist/logger.mjs +3 -5
- package/dist/node-utils.d.ts +703 -12
- package/dist/node-utils.js +97 -77
- package/dist/node-utils.mjs +32 -40
- package/package.json +6 -14
- package/dist/chalk.d.ts +0 -2
- package/dist/chalk.js +0 -42
- package/dist/chalk.mjs +0 -6
- package/dist/index-ba0faa42.d.ts +0 -805
package/dist/index.js
CHANGED
@@ -1,273 +1,223 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
4
|
-
|
5
|
-
var
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
};
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
2
|
+
var __webpack_require__ = {};
|
3
|
+
(()=>{
|
4
|
+
__webpack_require__.d = function(exports1, definition) {
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
6
|
+
enumerable: true,
|
7
|
+
get: definition[key]
|
8
|
+
});
|
9
|
+
};
|
10
|
+
})();
|
11
|
+
(()=>{
|
12
|
+
__webpack_require__.o = function(obj, prop) {
|
13
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
14
|
+
};
|
15
|
+
})();
|
16
|
+
(()=>{
|
17
|
+
__webpack_require__.r = function(exports1) {
|
18
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
19
|
+
value: 'Module'
|
20
|
+
});
|
21
|
+
Object.defineProperty(exports1, '__esModule', {
|
22
|
+
value: true
|
23
|
+
});
|
24
|
+
};
|
25
|
+
})();
|
26
|
+
var __webpack_exports__ = {};
|
27
|
+
__webpack_require__.r(__webpack_exports__);
|
28
|
+
__webpack_require__.d(__webpack_exports__, {
|
29
|
+
SEARCH_INDEX_NAME: ()=>SEARCH_INDEX_NAME,
|
30
|
+
RSPRESS_TEMP_DIR: ()=>RSPRESS_TEMP_DIR,
|
31
|
+
QUERY_REGEXP: ()=>QUERY_REGEXP,
|
32
|
+
isDebugMode: ()=>isDebugMode,
|
33
|
+
addTrailingSlash: ()=>addTrailingSlash,
|
34
|
+
slash: ()=>slash,
|
35
|
+
removeLeadingSlash: ()=>removeLeadingSlash,
|
36
|
+
withoutBase: ()=>withoutBase,
|
37
|
+
replaceVersion: ()=>replaceVersion,
|
38
|
+
MDX_REGEXP: ()=>MDX_REGEXP,
|
39
|
+
HASH_REGEXP: ()=>HASH_REGEXP,
|
40
|
+
isSCM: ()=>isSCM,
|
41
|
+
normalizeHref: ()=>normalizeHref,
|
42
|
+
normalizeSlash: ()=>normalizeSlash,
|
43
|
+
normalizePosixPath: ()=>normalizePosixPath,
|
44
|
+
inBrowser: ()=>inBrowser,
|
45
|
+
isDataUrl: ()=>isDataUrl,
|
46
|
+
replaceLang: ()=>replaceLang,
|
47
|
+
removeHash: ()=>removeHash,
|
48
|
+
cleanUrl: ()=>runtime_utils_cleanUrl,
|
49
|
+
withBase: ()=>withBase,
|
50
|
+
isDevDebugMode: ()=>isDevDebugMode,
|
51
|
+
removeTrailingSlash: ()=>removeTrailingSlash,
|
52
|
+
APPEARANCE_KEY: ()=>APPEARANCE_KEY,
|
53
|
+
isExternalUrl: ()=>isExternalUrl,
|
54
|
+
removeBase: ()=>removeBase,
|
55
|
+
DEFAULT_HIGHLIGHT_LANGUAGES: ()=>DEFAULT_HIGHLIGHT_LANGUAGES,
|
56
|
+
parseUrl: ()=>parseUrl,
|
57
|
+
withoutLang: ()=>withoutLang,
|
58
|
+
isProduction: ()=>isProduction,
|
59
|
+
addLeadingSlash: ()=>addLeadingSlash
|
54
60
|
});
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
61
|
+
const QUERY_REGEXP = /\?.*$/s;
|
62
|
+
const HASH_REGEXP = /#.*$/s;
|
63
|
+
const MDX_REGEXP = /\.mdx?$/;
|
64
|
+
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
65
|
+
const SEARCH_INDEX_NAME = 'search_index';
|
66
|
+
const RSPRESS_TEMP_DIR = '.rspress';
|
67
|
+
const DEFAULT_HIGHLIGHT_LANGUAGES = [
|
68
|
+
[
|
69
|
+
'js',
|
70
|
+
"javascript"
|
71
|
+
],
|
72
|
+
[
|
73
|
+
'ts',
|
74
|
+
"typescript"
|
75
|
+
],
|
76
|
+
[
|
77
|
+
'jsx',
|
78
|
+
'tsx'
|
79
|
+
],
|
80
|
+
[
|
81
|
+
'xml',
|
82
|
+
'xml-doc'
|
83
|
+
],
|
84
|
+
[
|
85
|
+
'md',
|
86
|
+
'markdown'
|
87
|
+
],
|
88
|
+
[
|
89
|
+
'mdx',
|
90
|
+
'tsx'
|
91
|
+
]
|
71
92
|
];
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
93
|
+
const isSCM = ()=>Boolean(process.env.BUILD_VERSION);
|
94
|
+
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
95
|
+
const isDebugMode = ()=>{
|
96
|
+
if (!process.env.DEBUG) return false;
|
97
|
+
const values = process.env.DEBUG?.toLocaleLowerCase().split(',') ?? [];
|
98
|
+
return [
|
99
|
+
'rsbuild',
|
100
|
+
'builder',
|
101
|
+
'*'
|
102
|
+
].some((key)=>values.includes(key));
|
80
103
|
};
|
81
|
-
|
82
|
-
|
104
|
+
const isDevDebugMode = ()=>'rspress-dev' === process.env.DEBUG;
|
105
|
+
const runtime_utils_cleanUrl = (url)=>url.replace(HASH_REGEXP, '').replace(QUERY_REGEXP, '');
|
83
106
|
function slash(str) {
|
84
|
-
|
107
|
+
return str.replace(/\\/g, '/');
|
85
108
|
}
|
86
109
|
function removeHash(str) {
|
87
|
-
|
110
|
+
return str.replace(/#.*$/, '');
|
88
111
|
}
|
89
112
|
function normalizePosixPath(id) {
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
if (
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
}
|
105
|
-
}
|
106
|
-
let normalizedPath = normalizedParts.join("/");
|
107
|
-
if (isAbsolutePath) {
|
108
|
-
normalizedPath = `/${normalizedPath}`;
|
109
|
-
}
|
110
|
-
return normalizedPath;
|
111
|
-
}
|
112
|
-
var inBrowser = () => !process.env.__SSR__;
|
113
|
+
const path = slash(id);
|
114
|
+
const isAbsolutePath = path.startsWith('/');
|
115
|
+
const parts = path.split('/');
|
116
|
+
const normalizedParts = [];
|
117
|
+
for (const part of parts)if ('.' === part || '' === part) ;
|
118
|
+
else if ('..' === part) {
|
119
|
+
if (normalizedParts.length > 0 && '..' !== normalizedParts[normalizedParts.length - 1]) normalizedParts.pop();
|
120
|
+
else if (isAbsolutePath) normalizedParts.push('..');
|
121
|
+
} else normalizedParts.push(part);
|
122
|
+
let normalizedPath = normalizedParts.join('/');
|
123
|
+
if (isAbsolutePath) normalizedPath = `/${normalizedPath}`;
|
124
|
+
return normalizedPath;
|
125
|
+
}
|
126
|
+
const inBrowser = ()=>!process.env.__SSR__;
|
113
127
|
function addLeadingSlash(url) {
|
114
|
-
|
128
|
+
return '/' === url.charAt(0) || isExternalUrl(url) ? url : `/${url}`;
|
115
129
|
}
|
116
130
|
function removeLeadingSlash(url) {
|
117
|
-
|
131
|
+
return '/' === url.charAt(0) ? url.slice(1) : url;
|
118
132
|
}
|
119
133
|
function addTrailingSlash(url) {
|
120
|
-
|
134
|
+
return '/' === url.charAt(url.length - 1) ? url : `${url}/`;
|
121
135
|
}
|
122
136
|
function removeTrailingSlash(url) {
|
123
|
-
|
137
|
+
return '/' === url.charAt(url.length - 1) ? url.slice(0, -1) : url;
|
124
138
|
}
|
125
139
|
function normalizeSlash(url) {
|
126
|
-
|
127
|
-
}
|
128
|
-
function isExternalUrl(url =
|
129
|
-
|
130
|
-
}
|
131
|
-
function isDataUrl(url =
|
132
|
-
|
133
|
-
}
|
134
|
-
function replaceLang(rawUrl, lang, version, base =
|
135
|
-
|
136
|
-
|
137
|
-
url
|
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
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
if (version.current !== version.default) {
|
178
|
-
parts.shift();
|
179
|
-
}
|
180
|
-
} else {
|
181
|
-
parts.shift();
|
182
|
-
}
|
183
|
-
let restPart = parts.join("/") || "";
|
184
|
-
if (versionPart && !restPart) {
|
185
|
-
restPart = cleanUrls ? "index" : "index.html";
|
186
|
-
}
|
187
|
-
return withBase(
|
188
|
-
addLeadingSlash([versionPart, restPart].filter(Boolean).join("/")),
|
189
|
-
base
|
190
|
-
);
|
191
|
-
}
|
192
|
-
var parseUrl = (url) => {
|
193
|
-
const [withoutHash, hash = ""] = url.split("#");
|
194
|
-
return {
|
195
|
-
url: withoutHash,
|
196
|
-
hash
|
197
|
-
};
|
140
|
+
return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
|
141
|
+
}
|
142
|
+
function isExternalUrl(url = '') {
|
143
|
+
return url.startsWith('http://') || url.startsWith('https://') || url.startsWith('mailto:') || url.startsWith('tel:');
|
144
|
+
}
|
145
|
+
function isDataUrl(url = '') {
|
146
|
+
return /^\s*data:/i.test(url);
|
147
|
+
}
|
148
|
+
function replaceLang(rawUrl, lang, version, base = '', cleanUrls = false, isPageNotFound = false) {
|
149
|
+
let url = removeBase(rawUrl, base);
|
150
|
+
if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
|
151
|
+
if (url.endsWith('/')) url += cleanUrls ? '/index' : '/index.html';
|
152
|
+
let versionPart = '';
|
153
|
+
let langPart = '';
|
154
|
+
let purePathPart = '';
|
155
|
+
const parts = url.split('/').filter(Boolean);
|
156
|
+
if (version.current && version.current !== version.default) versionPart = parts.shift() || '';
|
157
|
+
if (lang.target !== lang.default) {
|
158
|
+
langPart = lang.target;
|
159
|
+
if (lang.current !== lang.default) parts.shift();
|
160
|
+
} else parts.shift();
|
161
|
+
purePathPart = parts.join('/') || '';
|
162
|
+
if ((versionPart || langPart) && !purePathPart) purePathPart = cleanUrls ? 'index' : 'index.html';
|
163
|
+
return withBase(addLeadingSlash([
|
164
|
+
versionPart,
|
165
|
+
langPart,
|
166
|
+
purePathPart
|
167
|
+
].filter(Boolean).join('/')), base);
|
168
|
+
}
|
169
|
+
function replaceVersion(rawUrl, version, base = '', cleanUrls = false, isPageNotFound = false) {
|
170
|
+
let url = removeBase(rawUrl, base);
|
171
|
+
if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
|
172
|
+
let versionPart = '';
|
173
|
+
const parts = url.split('/').filter(Boolean);
|
174
|
+
if (version.target !== version.default) {
|
175
|
+
versionPart = version.target;
|
176
|
+
if (version.current !== version.default) parts.shift();
|
177
|
+
} else parts.shift();
|
178
|
+
let restPart = parts.join('/') || '';
|
179
|
+
if (versionPart && !restPart) restPart = cleanUrls ? 'index' : 'index.html';
|
180
|
+
return withBase(addLeadingSlash([
|
181
|
+
versionPart,
|
182
|
+
restPart
|
183
|
+
].filter(Boolean).join('/')), base);
|
184
|
+
}
|
185
|
+
const parseUrl = (url)=>{
|
186
|
+
const [withoutHash, hash = ''] = url.split('#');
|
187
|
+
return {
|
188
|
+
url: withoutHash,
|
189
|
+
hash
|
190
|
+
};
|
198
191
|
};
|
199
192
|
function normalizeHref(url, cleanUrls = false) {
|
200
|
-
|
201
|
-
return
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
let { url: cleanUrl2, hash } = parseUrl(decodeURIComponent(url));
|
207
|
-
if (!cleanUrls && !cleanUrl2.endsWith(".html")) {
|
208
|
-
if (cleanUrl2.endsWith("/")) {
|
209
|
-
cleanUrl2 += "index.html";
|
210
|
-
} else {
|
211
|
-
cleanUrl2 += ".html";
|
193
|
+
if (!url) return '/';
|
194
|
+
if (isExternalUrl(url)) return url;
|
195
|
+
let { url: cleanUrl, hash } = parseUrl(decodeURIComponent(url));
|
196
|
+
if (!cleanUrls && !cleanUrl.endsWith('.html')) {
|
197
|
+
if (cleanUrl.endsWith('/')) cleanUrl += 'index.html';
|
198
|
+
else cleanUrl += '.html';
|
212
199
|
}
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
}
|
217
|
-
if (cleanUrls && cleanUrl2.endsWith(".html")) {
|
218
|
-
cleanUrl2 = cleanUrl2.replace(/\.html$/, "");
|
219
|
-
}
|
220
|
-
return addLeadingSlash(hash ? `${cleanUrl2}#${hash}` : cleanUrl2);
|
200
|
+
if (cleanUrls && cleanUrl.endsWith('/')) cleanUrl += 'index';
|
201
|
+
if (cleanUrls && cleanUrl.endsWith('.html')) cleanUrl = cleanUrl.replace(/\.html$/, '');
|
202
|
+
return addLeadingSlash(hash ? `${cleanUrl}#${hash}` : cleanUrl);
|
221
203
|
}
|
222
204
|
function withoutLang(path, langs) {
|
223
|
-
|
224
|
-
|
205
|
+
const langRegexp = new RegExp(`^\\/(${langs.join('|')})`);
|
206
|
+
return addLeadingSlash(path.replace(langRegexp, ''));
|
225
207
|
}
|
226
208
|
function withoutBase(path, base) {
|
227
|
-
|
209
|
+
return addLeadingSlash(path).replace(normalizeSlash(base), '');
|
228
210
|
}
|
229
211
|
function withBase(url, base) {
|
230
|
-
|
231
|
-
|
232
|
-
|
212
|
+
const normalizedUrl = addLeadingSlash(url);
|
213
|
+
const normalizedBase = normalizeSlash(base);
|
214
|
+
return normalizedUrl.startsWith(normalizedBase) ? normalizedUrl : `${normalizedBase}${normalizedUrl}`;
|
233
215
|
}
|
234
216
|
function removeBase(url, base) {
|
235
|
-
|
236
|
-
new RegExp(`^${normalizeSlash(base)}`),
|
237
|
-
""
|
238
|
-
);
|
217
|
+
return addLeadingSlash(url).replace(new RegExp(`^${normalizeSlash(base)}`), '');
|
239
218
|
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
HASH_REGEXP,
|
245
|
-
MDX_REGEXP,
|
246
|
-
QUERY_REGEXP,
|
247
|
-
RSPRESS_TEMP_DIR,
|
248
|
-
SEARCH_INDEX_NAME,
|
249
|
-
addLeadingSlash,
|
250
|
-
addTrailingSlash,
|
251
|
-
cleanUrl,
|
252
|
-
inBrowser,
|
253
|
-
isDataUrl,
|
254
|
-
isDebugMode,
|
255
|
-
isDevDebugMode,
|
256
|
-
isExternalUrl,
|
257
|
-
isProduction,
|
258
|
-
isSCM,
|
259
|
-
normalizeHref,
|
260
|
-
normalizePosixPath,
|
261
|
-
normalizeSlash,
|
262
|
-
parseUrl,
|
263
|
-
removeBase,
|
264
|
-
removeHash,
|
265
|
-
removeLeadingSlash,
|
266
|
-
removeTrailingSlash,
|
267
|
-
replaceLang,
|
268
|
-
replaceVersion,
|
269
|
-
slash,
|
270
|
-
withBase,
|
271
|
-
withoutBase,
|
272
|
-
withoutLang
|
219
|
+
var __webpack_export_target__ = exports;
|
220
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
221
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
222
|
+
value: true
|
273
223
|
});
|