rsbuild-plugin-devtools-json 0.2.0 → 0.2.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 CHANGED
@@ -1,5 +1,15 @@
1
- import type { RsbuildPlugin } from '@rsbuild/core';
2
- declare const plugin: (options?: {
3
- uuid: string;
4
- }) => RsbuildPlugin;
5
- export default plugin;
1
+ import { type RsbuildPlugin } from '@rsbuild/core';
2
+ export type PluginDevtoolsJsonOptions = {
3
+ /**
4
+ * The UUID to use for the DevTools project settings.
5
+ * If not provided, a new UUID will be generated.
6
+ */
7
+ uuid?: string;
8
+ /**
9
+ * The root path for the DevTools project settings.
10
+ * In monorepo, you can set this to the monorepo root directory, especially when used with [rsbuild-plugin-source-build](https://github.com/rspack-contrib/rsbuild-plugin-source-build).
11
+ * If not provided, the default root path from Rsbuild context will be used.
12
+ */
13
+ rootPath?: string;
14
+ };
15
+ export declare const pluginDevtoolsJson: (options?: PluginDevtoolsJsonOptions) => RsbuildPlugin;
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import node_fs from "node:fs";
2
2
  import node_path from "node:path";
3
+ import { logger } from "@rsbuild/core";
3
4
  import { v4, validate } from "uuid";
4
5
  const ENDPOINT = '/.well-known/appspecific/com.chrome.devtools.json';
5
- const src_plugin = (options)=>({
6
+ const pluginDevtoolsJson = (options)=>({
6
7
  name: 'rsbuild-plugin-devtools-json',
7
8
  setup (api) {
8
- if ('development' !== process.env.NODE_ENV) return;
9
9
  const getOrCreateUUID = ()=>{
10
10
  if (options?.uuid) return options.uuid;
11
11
  const cacheDir = api.context.cachePath;
@@ -23,33 +23,25 @@ const src_plugin = (options)=>({
23
23
  node_fs.writeFileSync(uuidPath, uuid, {
24
24
  encoding: 'utf-8'
25
25
  });
26
- console.log(`[rsbuild-plugin-devtools-json] Generated UUID '${uuid}' for DevTools project settings.`);
26
+ logger.info(`[rsbuild-plugin-devtools-json] Generated UUID '${uuid}' for DevTools project settings.`);
27
27
  return uuid;
28
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
- }));
29
+ api.onBeforeStartDevServer(({ server })=>{
30
+ server.middlewares.use((req, res, next)=>{
31
+ if (req.url !== ENDPOINT) return next();
32
+ let root = options?.rootPath || api.context.rootPath;
33
+ if (!options?.rootPath && process.env.WSL_DISTRO_NAME) root = node_path.join('\\\\wsl.localhost', process.env.WSL_DISTRO_NAME, root).replace(/\//g, '\\');
34
+ const uuid = getOrCreateUUID();
35
+ const devtoolsJson = {
36
+ workspace: {
37
+ root,
38
+ uuid
39
+ }
40
+ };
41
+ res.setHeader('Content-Type', 'application/json');
42
+ res.end(JSON.stringify(devtoolsJson, null, 2));
43
+ });
44
+ });
52
45
  }
53
46
  });
54
- const src = src_plugin;
55
- export { src as default };
47
+ export { pluginDevtoolsJson };
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.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -13,6 +13,23 @@
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
+ "prepare": "simple-git-hooks && npm run build",
22
+ "format": "biome format --write",
23
+ "bump": "npx bumpp"
24
+ },
25
+ "simple-git-hooks": {
26
+ "pre-commit": "npx nano-staged"
27
+ },
28
+ "nano-staged": {
29
+ "*.{js,jsx,ts,tsx,mjs,cjs}": [
30
+ "biome check --write --no-errors-on-unmatched"
31
+ ]
32
+ },
16
33
  "dependencies": {
17
34
  "uuid": "^11.1.0"
18
35
  },
@@ -20,17 +37,17 @@
20
37
  "@biomejs/biome": "2.0.4",
21
38
  "@rslib/core": "0.10.2",
22
39
  "@types/node": "24.0.3",
40
+ "nano-staged": "^0.8.0",
41
+ "simple-git-hooks": "^2.13.0",
23
42
  "typescript": "5.8.3"
24
43
  },
25
44
  "peerDependencies": {
26
45
  "@rsbuild/core": "^1"
27
46
  },
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
- }
47
+ "peerDependenciesMeta": {
48
+ "@rsbuild/core": {
49
+ "optional": true
50
+ }
51
+ },
52
+ "packageManager": "pnpm@9.15.2"
53
+ }