rsbuild-plugin-devtools-json 0.2.0
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/LICENSE +21 -0
- package/README.md +78 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +55 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Rspack Contrib
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# rsbuild-plugin-devtools-json
|
|
2
|
+
|
|
3
|
+
Rsbuild plugin for generating the Chrome DevTools project settings file on-the-fly in the dev server.
|
|
4
|
+
|
|
5
|
+
<p>
|
|
6
|
+
<a href="https://npmjs.com/package/rsbuild-plugin-devtools-json">
|
|
7
|
+
<img src="https://img.shields.io/npm/v/rsbuild-plugin-devtools-json?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
|
|
8
|
+
</a>
|
|
9
|
+
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
This enables seamless integration with the new Chrome DevTools features:
|
|
13
|
+
|
|
14
|
+
1. [DevTools Project Settings (devtools.json)](https://goo.gle/devtools-json-design)
|
|
15
|
+
2. [Automatic Workspace folders](http://goo.gle/devtools-automatic-workspace-folders)
|
|
16
|
+
|
|
17
|
+
<img width="800" alt="Screenshot 2025-06-22 at 21 45 26" src="https://github.com/user-attachments/assets/daae3e57-f0fc-43c1-b191-8f916bc542ae" />
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm i -D rsbuild-plugin-devtools-json
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
Add it to your Rsbuild config:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import { defineConfig } from "@rsbuild/core";
|
|
31
|
+
import { pluginDevtoolsJson } from "rsbuild-plugin-devtools-json";
|
|
32
|
+
|
|
33
|
+
export default defineConfig({
|
|
34
|
+
plugins: [
|
|
35
|
+
pluginDevtoolsJson(),
|
|
36
|
+
// ...
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
While the plugin can generate a UUID and save it in Rsbuild cache, you can also specify it in the options like in the following:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
pluginDevtoolsJson({
|
|
45
|
+
uuid: "6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b",
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
You can also specify a custom root path for the DevTools project settings:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
pluginDevtoolsJson({
|
|
53
|
+
rootPath: "/path/to/custom/root",
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
This is particularly useful in monorepo setups, where you might want to set the root path to the monorepo root directory, especially when used with [rsbuild-plugin-source-build](https://github.com/rspack-contrib/rsbuild-plugin-source-build). If not provided, the default root path from Rsbuild context will be used.
|
|
58
|
+
|
|
59
|
+
The `/.well-known/appspecific/com.chrome.devtools.json` endpoint will serve the project settings as JSON with the following structure:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"workspace": {
|
|
64
|
+
"root": "/path/to/project/root",
|
|
65
|
+
"uuid": "6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Here `root` is the absolute path to your `{projectRoot}` folder, and `uuid` is a random v4 UUID, generated the first time that you start the Rsbuild dev server with the plugin installed (it is henceforth cached in the Rsbuild cache folder).
|
|
71
|
+
|
|
72
|
+
## Credits
|
|
73
|
+
|
|
74
|
+
This plugin is inspired by [vite-plugin-devtools-json](https://github.com/ChromeDevTools/vite-plugin-devtools-json). Both the implementation and documentation have been adapted and referenced from the original Vite plugin.
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
The code is under [MIT License](LICENSE).
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
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 };
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rsbuild-plugin-devtools-json",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"uuid": "^11.1.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@biomejs/biome": "2.0.4",
|
|
21
|
+
"@rslib/core": "0.10.2",
|
|
22
|
+
"@types/node": "24.0.3",
|
|
23
|
+
"typescript": "5.8.3"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@rsbuild/core": "^1"
|
|
27
|
+
},
|
|
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
|
+
}
|