@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.mjs CHANGED
@@ -1,216 +1,159 @@
1
- // src/runtime-utils/index.ts
2
- var QUERY_REGEXP = /\?.*$/s;
3
- var HASH_REGEXP = /#.*$/s;
4
- var MDX_REGEXP = /\.mdx?$/;
5
- var APPEARANCE_KEY = "rspress-theme-appearance";
6
- var SEARCH_INDEX_NAME = "search_index";
7
- var RSPRESS_TEMP_DIR = ".rspress";
8
- var DEFAULT_HIGHLIGHT_LANGUAGES = [
9
- ["js", "javascript"],
10
- ["ts", "typescript"],
11
- ["jsx", "tsx"],
12
- ["xml", "xml-doc"],
13
- ["md", "markdown"],
14
- ["mdx", "tsx"]
1
+ const QUERY_REGEXP = /\?.*$/s;
2
+ const HASH_REGEXP = /#.*$/s;
3
+ const MDX_REGEXP = /\.mdx?$/;
4
+ const APPEARANCE_KEY = 'rspress-theme-appearance';
5
+ const SEARCH_INDEX_NAME = 'search_index';
6
+ const RSPRESS_TEMP_DIR = '.rspress';
7
+ const DEFAULT_HIGHLIGHT_LANGUAGES = [
8
+ [
9
+ 'js',
10
+ "javascript"
11
+ ],
12
+ [
13
+ 'ts',
14
+ "typescript"
15
+ ],
16
+ [
17
+ 'jsx',
18
+ 'tsx'
19
+ ],
20
+ [
21
+ 'xml',
22
+ 'xml-doc'
23
+ ],
24
+ [
25
+ 'md',
26
+ 'markdown'
27
+ ],
28
+ [
29
+ 'mdx',
30
+ 'tsx'
31
+ ]
15
32
  ];
16
- var isSCM = () => Boolean(process.env.BUILD_VERSION);
17
- var isProduction = () => process.env.NODE_ENV === "production";
18
- var isDebugMode = () => {
19
- if (!process.env.DEBUG) {
20
- return false;
21
- }
22
- const values = process.env.DEBUG?.toLocaleLowerCase().split(",") ?? [];
23
- return ["rsbuild", "builder", "*"].some((key) => values.includes(key));
33
+ const isSCM = ()=>Boolean(process.env.BUILD_VERSION);
34
+ const isProduction = ()=>'production' === process.env.NODE_ENV;
35
+ const isDebugMode = ()=>{
36
+ if (!process.env.DEBUG) return false;
37
+ const values = process.env.DEBUG?.toLocaleLowerCase().split(',') ?? [];
38
+ return [
39
+ 'rsbuild',
40
+ 'builder',
41
+ '*'
42
+ ].some((key)=>values.includes(key));
24
43
  };
25
- var isDevDebugMode = () => process.env.DEBUG === "rspress-dev";
26
- var cleanUrl = (url) => url.replace(HASH_REGEXP, "").replace(QUERY_REGEXP, "");
44
+ const isDevDebugMode = ()=>'rspress-dev' === process.env.DEBUG;
45
+ const runtime_utils_cleanUrl = (url)=>url.replace(HASH_REGEXP, '').replace(QUERY_REGEXP, '');
27
46
  function slash(str) {
28
- return str.replace(/\\/g, "/");
47
+ return str.replace(/\\/g, '/');
29
48
  }
30
49
  function removeHash(str) {
31
- return str.replace(/#.*$/, "");
50
+ return str.replace(/#.*$/, '');
32
51
  }
33
52
  function normalizePosixPath(id) {
34
- const path = slash(id);
35
- const isAbsolutePath = path.startsWith("/");
36
- const parts = path.split("/");
37
- const normalizedParts = [];
38
- for (const part of parts) {
39
- if (part === "." || part === "") {
40
- } else if (part === "..") {
41
- if (normalizedParts.length > 0 && normalizedParts[normalizedParts.length - 1] !== "..") {
42
- normalizedParts.pop();
43
- } else if (isAbsolutePath) {
44
- normalizedParts.push("..");
45
- }
46
- } else {
47
- normalizedParts.push(part);
48
- }
49
- }
50
- let normalizedPath = normalizedParts.join("/");
51
- if (isAbsolutePath) {
52
- normalizedPath = `/${normalizedPath}`;
53
- }
54
- return normalizedPath;
55
- }
56
- var inBrowser = () => !process.env.__SSR__;
53
+ const path = slash(id);
54
+ const isAbsolutePath = path.startsWith('/');
55
+ const parts = path.split('/');
56
+ const normalizedParts = [];
57
+ for (const part of parts)if ('.' === part || '' === part) ;
58
+ else if ('..' === part) {
59
+ if (normalizedParts.length > 0 && '..' !== normalizedParts[normalizedParts.length - 1]) normalizedParts.pop();
60
+ else if (isAbsolutePath) normalizedParts.push('..');
61
+ } else normalizedParts.push(part);
62
+ let normalizedPath = normalizedParts.join('/');
63
+ if (isAbsolutePath) normalizedPath = `/${normalizedPath}`;
64
+ return normalizedPath;
65
+ }
66
+ const inBrowser = ()=>!process.env.__SSR__;
57
67
  function addLeadingSlash(url) {
58
- return url.charAt(0) === "/" || isExternalUrl(url) ? url : `/${url}`;
68
+ return '/' === url.charAt(0) || isExternalUrl(url) ? url : `/${url}`;
59
69
  }
60
70
  function removeLeadingSlash(url) {
61
- return url.charAt(0) === "/" ? url.slice(1) : url;
71
+ return '/' === url.charAt(0) ? url.slice(1) : url;
62
72
  }
63
73
  function addTrailingSlash(url) {
64
- return url.charAt(url.length - 1) === "/" ? url : `${url}/`;
74
+ return '/' === url.charAt(url.length - 1) ? url : `${url}/`;
65
75
  }
66
76
  function removeTrailingSlash(url) {
67
- return url.charAt(url.length - 1) === "/" ? url.slice(0, -1) : url;
77
+ return '/' === url.charAt(url.length - 1) ? url.slice(0, -1) : url;
68
78
  }
69
79
  function normalizeSlash(url) {
70
- return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
71
- }
72
- function isExternalUrl(url = "") {
73
- return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:") || url.startsWith("tel:");
74
- }
75
- function isDataUrl(url = "") {
76
- return /^\s*data:/i.test(url);
77
- }
78
- function replaceLang(rawUrl, lang, version, base = "", cleanUrls = false, isPageNotFound = false) {
79
- let url = removeBase(rawUrl, base);
80
- if (!url || isPageNotFound) {
81
- url = cleanUrls ? "/index" : "/index.html";
82
- }
83
- if (url.endsWith("/")) {
84
- url += cleanUrls ? "/index" : "/index.html";
85
- }
86
- let versionPart = "";
87
- let langPart = "";
88
- let purePathPart = "";
89
- const parts = url.split("/").filter(Boolean);
90
- if (version.current && version.current !== version.default) {
91
- versionPart = parts.shift() || "";
92
- }
93
- if (lang.target !== lang.default) {
94
- langPart = lang.target;
95
- if (lang.current !== lang.default) {
96
- parts.shift();
97
- }
98
- } else {
99
- parts.shift();
100
- }
101
- purePathPart = parts.join("/") || "";
102
- if ((versionPart || langPart) && !purePathPart) {
103
- purePathPart = cleanUrls ? "index" : "index.html";
104
- }
105
- return withBase(
106
- addLeadingSlash(
107
- [versionPart, langPart, purePathPart].filter(Boolean).join("/")
108
- ),
109
- base
110
- );
111
- }
112
- function replaceVersion(rawUrl, version, base = "", cleanUrls = false, isPageNotFound = false) {
113
- let url = removeBase(rawUrl, base);
114
- if (!url || isPageNotFound) {
115
- url = cleanUrls ? "/index" : "/index.html";
116
- }
117
- let versionPart = "";
118
- const parts = url.split("/").filter(Boolean);
119
- if (version.target !== version.default) {
120
- versionPart = version.target;
121
- if (version.current !== version.default) {
122
- parts.shift();
123
- }
124
- } else {
125
- parts.shift();
126
- }
127
- let restPart = parts.join("/") || "";
128
- if (versionPart && !restPart) {
129
- restPart = cleanUrls ? "index" : "index.html";
130
- }
131
- return withBase(
132
- addLeadingSlash([versionPart, restPart].filter(Boolean).join("/")),
133
- base
134
- );
135
- }
136
- var parseUrl = (url) => {
137
- const [withoutHash, hash = ""] = url.split("#");
138
- return {
139
- url: withoutHash,
140
- hash
141
- };
80
+ return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
81
+ }
82
+ function isExternalUrl(url = '') {
83
+ return url.startsWith('http://') || url.startsWith('https://') || url.startsWith('mailto:') || url.startsWith('tel:');
84
+ }
85
+ function isDataUrl(url = '') {
86
+ return /^\s*data:/i.test(url);
87
+ }
88
+ function replaceLang(rawUrl, lang, version, base = '', cleanUrls = false, isPageNotFound = false) {
89
+ let url = removeBase(rawUrl, base);
90
+ if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
91
+ if (url.endsWith('/')) url += cleanUrls ? '/index' : '/index.html';
92
+ let versionPart = '';
93
+ let langPart = '';
94
+ let purePathPart = '';
95
+ const parts = url.split('/').filter(Boolean);
96
+ if (version.current && version.current !== version.default) versionPart = parts.shift() || '';
97
+ if (lang.target !== lang.default) {
98
+ langPart = lang.target;
99
+ if (lang.current !== lang.default) parts.shift();
100
+ } else parts.shift();
101
+ purePathPart = parts.join('/') || '';
102
+ if ((versionPart || langPart) && !purePathPart) purePathPart = cleanUrls ? 'index' : 'index.html';
103
+ return withBase(addLeadingSlash([
104
+ versionPart,
105
+ langPart,
106
+ purePathPart
107
+ ].filter(Boolean).join('/')), base);
108
+ }
109
+ function replaceVersion(rawUrl, version, base = '', cleanUrls = false, isPageNotFound = false) {
110
+ let url = removeBase(rawUrl, base);
111
+ if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
112
+ let versionPart = '';
113
+ const parts = url.split('/').filter(Boolean);
114
+ if (version.target !== version.default) {
115
+ versionPart = version.target;
116
+ if (version.current !== version.default) parts.shift();
117
+ } else parts.shift();
118
+ let restPart = parts.join('/') || '';
119
+ if (versionPart && !restPart) restPart = cleanUrls ? 'index' : 'index.html';
120
+ return withBase(addLeadingSlash([
121
+ versionPart,
122
+ restPart
123
+ ].filter(Boolean).join('/')), base);
124
+ }
125
+ const parseUrl = (url)=>{
126
+ const [withoutHash, hash = ''] = url.split('#');
127
+ return {
128
+ url: withoutHash,
129
+ hash
130
+ };
142
131
  };
143
132
  function normalizeHref(url, cleanUrls = false) {
144
- if (!url) {
145
- return "/";
146
- }
147
- if (isExternalUrl(url)) {
148
- return url;
149
- }
150
- let { url: cleanUrl2, hash } = parseUrl(decodeURIComponent(url));
151
- if (!cleanUrls && !cleanUrl2.endsWith(".html")) {
152
- if (cleanUrl2.endsWith("/")) {
153
- cleanUrl2 += "index.html";
154
- } else {
155
- cleanUrl2 += ".html";
133
+ if (!url) return '/';
134
+ if (isExternalUrl(url)) return url;
135
+ let { url: cleanUrl, hash } = parseUrl(decodeURIComponent(url));
136
+ if (!cleanUrls && !cleanUrl.endsWith('.html')) {
137
+ if (cleanUrl.endsWith('/')) cleanUrl += 'index.html';
138
+ else cleanUrl += '.html';
156
139
  }
157
- }
158
- if (cleanUrls && cleanUrl2.endsWith("/")) {
159
- cleanUrl2 += "index";
160
- }
161
- if (cleanUrls && cleanUrl2.endsWith(".html")) {
162
- cleanUrl2 = cleanUrl2.replace(/\.html$/, "");
163
- }
164
- return addLeadingSlash(hash ? `${cleanUrl2}#${hash}` : cleanUrl2);
140
+ if (cleanUrls && cleanUrl.endsWith('/')) cleanUrl += 'index';
141
+ if (cleanUrls && cleanUrl.endsWith('.html')) cleanUrl = cleanUrl.replace(/\.html$/, '');
142
+ return addLeadingSlash(hash ? `${cleanUrl}#${hash}` : cleanUrl);
165
143
  }
166
144
  function withoutLang(path, langs) {
167
- const langRegexp = new RegExp(`^\\/(${langs.join("|")})`);
168
- return addLeadingSlash(path.replace(langRegexp, ""));
145
+ const langRegexp = new RegExp(`^\\/(${langs.join('|')})`);
146
+ return addLeadingSlash(path.replace(langRegexp, ''));
169
147
  }
170
148
  function withoutBase(path, base) {
171
- return addLeadingSlash(path).replace(normalizeSlash(base), "");
149
+ return addLeadingSlash(path).replace(normalizeSlash(base), '');
172
150
  }
173
151
  function withBase(url, base) {
174
- const normalizedUrl = addLeadingSlash(url);
175
- const normalizedBase = normalizeSlash(base);
176
- return normalizedUrl.startsWith(normalizedBase) ? normalizedUrl : `${normalizedBase}${normalizedUrl}`;
152
+ const normalizedUrl = addLeadingSlash(url);
153
+ const normalizedBase = normalizeSlash(base);
154
+ return normalizedUrl.startsWith(normalizedBase) ? normalizedUrl : `${normalizedBase}${normalizedUrl}`;
177
155
  }
178
156
  function removeBase(url, base) {
179
- return addLeadingSlash(url).replace(
180
- new RegExp(`^${normalizeSlash(base)}`),
181
- ""
182
- );
183
- }
184
- export {
185
- APPEARANCE_KEY,
186
- DEFAULT_HIGHLIGHT_LANGUAGES,
187
- HASH_REGEXP,
188
- MDX_REGEXP,
189
- QUERY_REGEXP,
190
- RSPRESS_TEMP_DIR,
191
- SEARCH_INDEX_NAME,
192
- addLeadingSlash,
193
- addTrailingSlash,
194
- cleanUrl,
195
- inBrowser,
196
- isDataUrl,
197
- isDebugMode,
198
- isDevDebugMode,
199
- isExternalUrl,
200
- isProduction,
201
- isSCM,
202
- normalizeHref,
203
- normalizePosixPath,
204
- normalizeSlash,
205
- parseUrl,
206
- removeBase,
207
- removeHash,
208
- removeLeadingSlash,
209
- removeTrailingSlash,
210
- replaceLang,
211
- replaceVersion,
212
- slash,
213
- withBase,
214
- withoutBase,
215
- withoutLang
216
- };
157
+ return addLeadingSlash(url).replace(new RegExp(`^${normalizeSlash(base)}`), '');
158
+ }
159
+ export { APPEARANCE_KEY, DEFAULT_HIGHLIGHT_LANGUAGES, HASH_REGEXP, MDX_REGEXP, QUERY_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, runtime_utils_cleanUrl as cleanUrl, inBrowser, isDataUrl, isDebugMode, isDevDebugMode, isExternalUrl, isProduction, isSCM, normalizeHref, normalizePosixPath, normalizeSlash, parseUrl, removeBase, removeHash, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, withBase, withoutBase, withoutLang };
package/dist/logger.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- export { logger } from '@rsbuild/core';
2
- import 'chalk';
1
+ import { logger } from '@rsbuild/core';
2
+
3
+ export { logger }
4
+
5
+ export { }
package/dist/logger.js CHANGED
@@ -1,30 +1,36 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/logger.ts
21
- var logger_exports = {};
22
- __export(logger_exports, {
23
- logger: () => import_core.logger
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
+ logger: ()=>core_namespaceObject.logger
24
30
  });
25
- module.exports = __toCommonJS(logger_exports);
26
- var import_core = require("@rsbuild/core");
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- logger
31
+ const core_namespaceObject = require("@rsbuild/core");
32
+ var __webpack_export_target__ = exports;
33
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
34
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
35
+ value: true
30
36
  });
package/dist/logger.mjs CHANGED
@@ -1,5 +1,3 @@
1
- // src/logger.ts
2
- import { logger } from "@rsbuild/core";
3
- export {
4
- logger
5
- };
1
+ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
2
+ var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger;
3
+ export { __webpack_exports__logger as logger };