rsbuild-plugin-devtools-json 0.2.0 → 0.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsbuild-plugin-devtools-json",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -13,6 +13,14 @@
13
13
  "files": [
14
14
  "dist"
15
15
  ],
16
+ "scripts": {
17
+ "build": "rslib build",
18
+ "lint": "biome check",
19
+ "lint:write": "biome check . --write",
20
+ "dev": "rslib build --watch",
21
+ "format": "biome format --write",
22
+ "bump": "npx bumpp"
23
+ },
16
24
  "dependencies": {
17
25
  "uuid": "^11.1.0"
18
26
  },
@@ -25,12 +33,5 @@
25
33
  "peerDependencies": {
26
34
  "@rsbuild/core": "^1"
27
35
  },
28
- "scripts": {
29
- "build": "rslib build",
30
- "lint": "biome check",
31
- "lint:write": "biome check . --write",
32
- "dev": "rslib build --watch",
33
- "format": "biome format --write",
34
- "bump": "npx bumpp"
35
- }
36
- }
36
+ "packageManager": "pnpm@9.15.2"
37
+ }
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import type { RsbuildPlugin } from '@rsbuild/core';
2
- declare const plugin: (options?: {
3
- uuid: string;
4
- }) => RsbuildPlugin;
5
- export default plugin;
package/dist/index.js DELETED
@@ -1,55 +0,0 @@
1
- import node_fs from "node:fs";
2
- import node_path from "node:path";
3
- import { v4, validate } from "uuid";
4
- const ENDPOINT = '/.well-known/appspecific/com.chrome.devtools.json';
5
- const src_plugin = (options)=>({
6
- name: 'rsbuild-plugin-devtools-json',
7
- setup (api) {
8
- if ('development' !== process.env.NODE_ENV) return;
9
- const getOrCreateUUID = ()=>{
10
- if (options?.uuid) return options.uuid;
11
- const cacheDir = api.context.cachePath;
12
- const uuidPath = node_path.resolve(cacheDir, 'uuid.json');
13
- if (node_fs.existsSync(uuidPath)) {
14
- const uuid = node_fs.readFileSync(uuidPath, {
15
- encoding: 'utf-8'
16
- });
17
- if (validate(uuid)) return uuid;
18
- }
19
- if (!node_fs.existsSync(cacheDir)) node_fs.mkdirSync(cacheDir, {
20
- recursive: true
21
- });
22
- const uuid = v4();
23
- node_fs.writeFileSync(uuidPath, uuid, {
24
- encoding: 'utf-8'
25
- });
26
- console.log(`[rsbuild-plugin-devtools-json] Generated UUID '${uuid}' for DevTools project settings.`);
27
- return uuid;
28
- };
29
- api.modifyRsbuildConfig((userConfig, { mergeRsbuildConfig })=>mergeRsbuildConfig(userConfig, {
30
- dev: {
31
- setupMiddlewares: [
32
- (middlewares)=>{
33
- middlewares.push((req, res, next)=>{
34
- if (req.url !== ENDPOINT) return next();
35
- let root = api.context.rootPath;
36
- if (process.env.WSL_DISTRO_NAME) root = node_path.join('\\\\wsl.localhost', process.env.WSL_DISTRO_NAME, root).replace(/\//g, '\\');
37
- const uuid = getOrCreateUUID();
38
- const devtoolsJson = {
39
- workspace: {
40
- root,
41
- uuid
42
- }
43
- };
44
- res.setHeader('Content-Type', 'application/json');
45
- res.end(JSON.stringify(devtoolsJson, null, 2));
46
- });
47
- return middlewares;
48
- }
49
- ]
50
- }
51
- }));
52
- }
53
- });
54
- const src = src_plugin;
55
- export { src as default };