@rspress/plugin-preview 2.0.0-beta.14 → 2.0.0-beta.15
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.js +11 -11
- package/package.json +6 -6
package/dist/index.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
import
|
2
|
-
import
|
1
|
+
import node_net from "node:net";
|
2
|
+
import node_path, { dirname, join, resolve as external_node_path_resolve } from "node:path";
|
3
3
|
import { createRsbuild, mergeRsbuildConfig } from "@rsbuild/core";
|
4
4
|
import { pluginBabel } from "@rsbuild/plugin-babel";
|
5
5
|
import { pluginReact } from "@rsbuild/plugin-react";
|
6
6
|
import { pluginSolid } from "@rsbuild/plugin-solid";
|
7
7
|
import { RSPRESS_TEMP_DIR, normalizePosixPath, removeTrailingSlash } from "@rspress/shared";
|
8
8
|
import { cloneDeep, isEqual } from "lodash";
|
9
|
-
import
|
10
|
-
const staticPath =
|
11
|
-
const demoBlockComponentPath =
|
12
|
-
const virtualDir =
|
9
|
+
import node_fs, { writeFileSync } from "node:fs";
|
10
|
+
const staticPath = node_path.join(__dirname, '..', 'static');
|
11
|
+
const demoBlockComponentPath = node_path.join(staticPath, 'global-components', 'DemoBlock.tsx');
|
12
|
+
const virtualDir = node_path.join(process.cwd(), 'node_modules', RSPRESS_TEMP_DIR, 'virtual-demo');
|
13
13
|
const toValidVarName = (str)=>{
|
14
14
|
if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(str)) return str;
|
15
15
|
return str.replace(/[^0-9a-zA-Z_$]/g, '_').replace(/^([0-9])/, '_$1');
|
@@ -303,7 +303,7 @@ const getExternalDemoContent = (tempVar)=>({
|
|
303
303
|
const remarkPlugin_demos = {};
|
304
304
|
const remarkCodeToDemo = function({ getRouteMeta, previewMode, defaultRenderMode, position, previewLanguages, previewCodeTransform }) {
|
305
305
|
const routeMeta = getRouteMeta();
|
306
|
-
|
306
|
+
node_fs.mkdirSync(virtualDir, {
|
307
307
|
recursive: true
|
308
308
|
});
|
309
309
|
const data = this.data();
|
@@ -379,11 +379,11 @@ const remarkCodeToDemo = function({ getRouteMeta, previewMode, defaultRenderMode
|
|
379
379
|
const id = generateId(pageName, index++);
|
380
380
|
const virtualModulePath = join(virtualDir, `${id}.${getLangFileExt(node.lang)}`);
|
381
381
|
constructDemoNode(id, virtualModulePath, node, isMobileMode);
|
382
|
-
if (
|
383
|
-
const content =
|
382
|
+
if (node_fs.existsSync(virtualModulePath)) {
|
383
|
+
const content = node_fs.readFileSync(virtualModulePath, 'utf-8');
|
384
384
|
if (content === value) return;
|
385
385
|
}
|
386
|
-
|
386
|
+
node_fs.writeFileSync(virtualModulePath, value);
|
387
387
|
}
|
388
388
|
});
|
389
389
|
tree.children.unshift(...demoMdx);
|
@@ -419,7 +419,7 @@ function pluginPreview(options) {
|
|
419
419
|
async beforeBuild (_, isProd) {
|
420
420
|
if (!isProd) try {
|
421
421
|
await new Promise((resolve, reject)=>{
|
422
|
-
const server =
|
422
|
+
const server = node_net.createServer();
|
423
423
|
server.unref();
|
424
424
|
server.on('error', reject);
|
425
425
|
server.listen({
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspress/plugin-preview",
|
3
|
-
"version": "2.0.0-beta.
|
3
|
+
"version": "2.0.0-beta.15",
|
4
4
|
"description": "A plugin for rspress to preview the code block in markdown/mdx file.",
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
6
6
|
"repository": {
|
@@ -31,15 +31,15 @@
|
|
31
31
|
"@rsbuild/plugin-solid": "~1.0.5",
|
32
32
|
"lodash": "4.17.21",
|
33
33
|
"qrcode.react": "^4.2.0",
|
34
|
-
"@rspress/shared": "2.0.0-beta.
|
35
|
-
"@rspress/theme-default": "2.0.0-beta.
|
34
|
+
"@rspress/shared": "2.0.0-beta.15",
|
35
|
+
"@rspress/theme-default": "2.0.0-beta.15"
|
36
36
|
},
|
37
37
|
"devDependencies": {
|
38
|
-
"@rslib/core": "0.
|
38
|
+
"@rslib/core": "0.10.0",
|
39
39
|
"@types/lodash": "^4.17.17",
|
40
40
|
"@types/mdast": "^4.0.4",
|
41
41
|
"@types/node": "^22.8.1",
|
42
|
-
"@types/react": "^19.1.
|
42
|
+
"@types/react": "^19.1.8",
|
43
43
|
"@types/react-dom": "^19.1.6",
|
44
44
|
"mdast-util-mdx-jsx": "^3.2.0",
|
45
45
|
"mdast-util-mdxjs-esm": "^2.0.1",
|
@@ -52,7 +52,7 @@
|
|
52
52
|
"unist-util-visit": "^5.0.0"
|
53
53
|
},
|
54
54
|
"peerDependencies": {
|
55
|
-
"@rspress/core": "^2.0.0-beta.
|
55
|
+
"@rspress/core": "^2.0.0-beta.15",
|
56
56
|
"react": ">=18.0.0",
|
57
57
|
"react-router-dom": "^6.8.1"
|
58
58
|
},
|