@modern-js/plugin-devtools 2.46.1 → 2.47.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/dist/cli.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import type { AppTools, CliPlugin } from '@modern-js/app-tools';
2
- import { DevtoolsPluginOptions, DevtoolsPluginInlineOptions } from './config';
3
- export type { DevtoolsPluginOptions, DevtoolsPluginInlineOptions };
4
- export declare const devtoolsPlugin: (inlineOptions?: DevtoolsPluginInlineOptions) => CliPlugin<AppTools>;
2
+ import { ClientDefinition } from '@modern-js/devtools-kit/node';
3
+ import { DevtoolsPluginOptions } from './config';
4
+ export type { DevtoolsPluginOptions };
5
+ export type DevtoolsPlugin = CliPlugin<AppTools> & {
6
+ setClientDefinition: (def: ClientDefinition) => void;
7
+ };
8
+ export declare const devtoolsPlugin: (inlineOptions?: DevtoolsPluginOptions) => DevtoolsPlugin;
5
9
  export default devtoolsPlugin;
package/dist/cli.js CHANGED
@@ -34,95 +34,127 @@ __export(cli_exports, {
34
34
  module.exports = __toCommonJS(cli_exports);
35
35
  var import_http = __toESM(require("http"));
36
36
  var import_path = __toESM(require("path"));
37
+ var import_assert = __toESM(require("assert"));
37
38
  var import_utils = require("@modern-js/utils");
38
39
  var import_serve_static = __toESM(require("serve-static"));
39
- var import_devtools_kit = require("@modern-js/devtools-kit");
40
- var import_ufo = require("ufo");
40
+ var import_node = require("@modern-js/devtools-kit/node");
41
41
  var import_config = require("./config");
42
42
  var import_rpc = require("./rpc");
43
43
  var import_socket = require("./utils/socket");
44
- const devtoolsPlugin = (inlineOptions = {}) => ({
45
- name: "@modern-js/plugin-devtools",
46
- usePlugins: [],
47
- setup: async (api) => {
48
- const ctx = (0, import_config.resolveContext)(inlineOptions);
49
- if (!ctx.enable) {
50
- return {};
51
- }
52
- const httpServer = await setupHttpServer();
53
- const socketServer = new import_socket.SocketServer({
54
- server: httpServer.instance,
55
- path: "/rpc"
56
- });
57
- const rpc = await (0, import_rpc.setupClientConnection)({
58
- api,
59
- server: socketServer
60
- });
61
- return {
62
- prepare: rpc.hooks.prepare,
63
- modifyFileSystemRoutes: rpc.hooks.modifyFileSystemRoutes,
64
- beforeRestart() {
65
- return new Promise((resolve, reject) => httpServer.instance.close((err) => err ? reject(err) : resolve()));
66
- },
67
- modifyServerRoutes({ routes }) {
68
- routes.push({
69
- urlPath: "/sw-proxy.js",
70
- isSPA: true,
71
- isSSR: false,
72
- entryPath: "public/sw-proxy.js"
73
- });
74
- return {
75
- routes
76
- };
77
- },
78
- config() {
79
- var _api_useConfigContext_devtools;
80
- const config = (_api_useConfigContext_devtools = api.useConfigContext().devtools) !== null && _api_useConfigContext_devtools !== void 0 ? _api_useConfigContext_devtools : {};
81
- Object.assign(ctx, (0, import_config.resolveContext)(ctx, config), {
82
- __keep: true
83
- });
84
- import_utils.logger.info(`${ctx.def.name.formalName} Devtools is enabled`);
85
- const runtimeEntry = require.resolve("@modern-js/devtools-client/mount");
86
- const swProxyEntry = require.resolve("@modern-js/devtools-client/sw-proxy");
87
- return {
88
- builderPlugins: [
89
- rpc.builderPlugin
90
- ],
91
- source: {
92
- preEntry: [
93
- (0, import_ufo.withQuery)(runtimeEntry, ctx)
44
+ const devtoolsPlugin = (inlineOptions = {}) => {
45
+ const ctx = (0, import_config.resolveContext)(inlineOptions);
46
+ return {
47
+ name: "@modern-js/plugin-devtools",
48
+ usePlugins: [],
49
+ setClientDefinition(def) {
50
+ Object.assign(ctx.def, def);
51
+ },
52
+ async setup(api) {
53
+ if (!ctx.enable)
54
+ return {};
55
+ const httpServer = await setupHttpServer();
56
+ const socketServer = new import_socket.SocketServer({
57
+ server: httpServer.instance,
58
+ path: "/rpc"
59
+ });
60
+ const rpc = await (0, import_rpc.setupClientConnection)({
61
+ api,
62
+ server: socketServer,
63
+ def: ctx.def
64
+ });
65
+ return {
66
+ prepare: rpc.hooks.prepare,
67
+ modifyFileSystemRoutes: rpc.hooks.modifyFileSystemRoutes,
68
+ beforeRestart() {
69
+ return new Promise((resolve, reject) => httpServer.instance.close((err) => err ? reject(err) : resolve()));
70
+ },
71
+ modifyServerRoutes({ routes }) {
72
+ routes.push({
73
+ urlPath: "/sw-proxy.js",
74
+ isSPA: true,
75
+ isSSR: false,
76
+ entryPath: "public/sw-proxy.js"
77
+ });
78
+ return {
79
+ routes
80
+ };
81
+ },
82
+ config() {
83
+ var _api_useConfigContext_devtools;
84
+ const config = (_api_useConfigContext_devtools = api.useConfigContext().devtools) !== null && _api_useConfigContext_devtools !== void 0 ? _api_useConfigContext_devtools : {};
85
+ Object.assign(ctx, (0, import_config.resolveContext)(ctx, config));
86
+ import_utils.logger.info(`${ctx.def.name.formalName} DevTools is enabled`);
87
+ const swProxyEntry = require.resolve("@modern-js/devtools-client/sw-proxy");
88
+ const serializedOptions = JSON.stringify(ctx);
89
+ const tags = [
90
+ {
91
+ tag: "script",
92
+ children: `window.__MODERN_JS_DEVTOOLS_OPTIONS__ = ${serializedOptions};`,
93
+ head: true,
94
+ append: false
95
+ }
96
+ ];
97
+ const styles = [];
98
+ const manifest = require("@modern-js/devtools-client/manifest");
99
+ for (const src of manifest.routeAssets.mount.assets) {
100
+ (0, import_assert.default)(typeof src === "string");
101
+ if (src.endsWith(".js")) {
102
+ tags.push({
103
+ tag: "script",
104
+ attrs: {
105
+ src
106
+ },
107
+ head: true,
108
+ append: false
109
+ });
110
+ } else if (src.endsWith(".css")) {
111
+ styles.push(src);
112
+ }
113
+ }
114
+ tags.push({
115
+ tag: "template",
116
+ attrs: {
117
+ id: "_modern_js_devtools_styles"
118
+ },
119
+ append: true,
120
+ head: false,
121
+ children: styles.map((src) => `<link rel="stylesheet" href="${src}">`).join("")
122
+ });
123
+ return {
124
+ builderPlugins: [
125
+ rpc.builderPlugin
94
126
  ],
95
- include: [
96
- runtimeEntry
97
- ]
98
- },
99
- output: {
100
- copy: [
101
- {
102
- from: swProxyEntry,
103
- to: "public"
104
- }
105
- ]
106
- },
107
- html: {},
108
- tools: {
109
- devServer: {
110
- proxy: {
111
- [import_devtools_kit.ROUTE_BASENAME]: {
112
- target: `http://localhost:${httpServer.port}`,
113
- pathRewrite: {
114
- [`^${import_devtools_kit.ROUTE_BASENAME}`]: ""
115
- },
116
- ws: true
127
+ source: {},
128
+ output: {
129
+ copy: [
130
+ {
131
+ from: swProxyEntry,
132
+ to: "public"
133
+ }
134
+ ]
135
+ },
136
+ html: {
137
+ tags
138
+ },
139
+ tools: {
140
+ devServer: {
141
+ proxy: {
142
+ [import_node.ROUTE_BASENAME]: {
143
+ target: `http://localhost:${httpServer.port}`,
144
+ pathRewrite: {
145
+ [`^${import_node.ROUTE_BASENAME}`]: ""
146
+ },
147
+ ws: true
148
+ }
117
149
  }
118
150
  }
119
151
  }
120
- }
121
- };
122
- }
123
- };
124
- }
125
- });
152
+ };
153
+ }
154
+ };
155
+ }
156
+ };
157
+ };
126
158
  var cli_default = devtoolsPlugin;
127
159
  const setupHttpServer = async () => {
128
160
  const port = await (0, import_utils.getPort)(8782, {
package/dist/config.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { ClientDefinition, SetupClientParams } from '@modern-js/devtools-kit';
1
+ import { ClientDefinition } from '@modern-js/devtools-kit/node';
2
2
  import type { RequiredDeep } from 'type-fest';
3
- export type DevtoolsPluginOptions = Partial<SetupClientParams>;
4
- export interface DevtoolsPluginInlineOptions extends DevtoolsPluginOptions {
3
+ export interface DevtoolsPluginOptions {
5
4
  enable?: boolean;
5
+ endpoint?: string;
6
+ dataSource?: string;
6
7
  }
7
- export type DevtoolsContext = RequiredDeep<DevtoolsPluginInlineOptions>;
8
- export declare const getDefaultOptions: () => {
8
+ export interface DevtoolsContext extends RequiredDeep<DevtoolsPluginOptions> {
9
9
  def: ClientDefinition;
10
- };
11
- export declare const resolveContext: (...sources: DevtoolsPluginInlineOptions[]) => DevtoolsContext;
10
+ }
11
+ export declare const resolveContext: (...sources: Partial<DevtoolsContext>[]) => DevtoolsContext;
package/dist/config.js CHANGED
@@ -18,21 +18,20 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var config_exports = {};
20
20
  __export(config_exports, {
21
- getDefaultOptions: () => getDefaultOptions,
22
21
  resolveContext: () => resolveContext
23
22
  });
24
23
  module.exports = __toCommonJS(config_exports);
25
- var import_devtools_kit = require("@modern-js/devtools-kit");
26
- const getDefaultOptions = () => ({
27
- def: new import_devtools_kit.ClientDefinition()
28
- });
24
+ var import_node = require("@modern-js/devtools-kit/node");
29
25
  const resolveContext = (...sources) => {
30
26
  const ret = {
31
27
  enable: process.env.NODE_ENV === "development",
32
- dataSource: `${import_devtools_kit.ROUTE_BASENAME}/rpc`,
33
- endpoint: import_devtools_kit.ROUTE_BASENAME,
34
- def: new import_devtools_kit.ClientDefinition()
28
+ dataSource: `${import_node.ROUTE_BASENAME}/rpc`,
29
+ endpoint: import_node.ROUTE_BASENAME,
30
+ def: new import_node.ClientDefinition()
35
31
  };
32
+ Object.assign(ret, {
33
+ __keep: true
34
+ });
36
35
  for (const opts of sources) {
37
36
  var _opts_enable;
38
37
  ret.enable = (_opts_enable = opts.enable) !== null && _opts_enable !== void 0 ? _opts_enable : ret.enable;
@@ -40,25 +39,12 @@ const resolveContext = (...sources) => {
40
39
  ret.dataSource = (_opts_dataSource = opts.dataSource) !== null && _opts_dataSource !== void 0 ? _opts_dataSource : ret.dataSource;
41
40
  var _opts_endpoint;
42
41
  ret.endpoint = (_opts_endpoint = opts.endpoint) !== null && _opts_endpoint !== void 0 ? _opts_endpoint : ret.endpoint;
43
- if (opts.def) {
44
- if (opts.def.announcement) {
45
- Object.assign(ret.def.announcement, opts.def.announcement);
46
- }
47
- if (opts.def.assets) {
48
- Object.assign(ret.def.assets, opts.def.assets);
49
- }
50
- if (opts.def.name) {
51
- Object.assign(ret.def.name, opts.def.name);
52
- }
53
- if (opts.def.packages) {
54
- Object.assign(ret.def.packages, opts.def.packages);
55
- }
56
- }
42
+ var _opts_def;
43
+ ret.def = (_opts_def = opts.def) !== null && _opts_def !== void 0 ? _opts_def : ret.def;
57
44
  }
58
45
  return ret;
59
46
  };
60
47
  // Annotate the CommonJS export names for ESM import in node:
61
48
  0 && (module.exports = {
62
- getDefaultOptions,
63
49
  resolveContext
64
50
  });
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { devtoolsPlugin, default } from './cli';
2
- export type { DevtoolsPluginOptions, DevtoolsPluginInlineOptions } from './cli';
2
+ export type { DevtoolsPluginOptions } from './cli';
@@ -1,15 +1,14 @@
1
- import { ClientDefinition, type ClientFunctions, type ServerFunctions } from '@modern-js/devtools-kit';
2
- import type { PartialDeep } from 'type-fest';
1
+ import { ClientDefinition, type ClientFunctions, type ServerFunctions } from '@modern-js/devtools-kit/node';
3
2
  import type { RsbuildPlugin } from '@modern-js/uni-builder';
4
3
  import { CliPluginAPI, InjectedHooks } from '../types';
5
4
  import { SocketServer } from '../utils/socket';
6
5
  export interface SetupClientConnectionOptions {
7
6
  api: CliPluginAPI;
8
7
  server: SocketServer;
8
+ def: ClientDefinition;
9
9
  }
10
10
  export declare const setupClientConnection: (options: SetupClientConnectionOptions) => Promise<{
11
11
  client: import("birpc").BirpcReturn<ClientFunctions, ServerFunctions>;
12
12
  hooks: InjectedHooks;
13
13
  builderPlugin: RsbuildPlugin;
14
- setDefinition: (definition: PartialDeep<ClientDefinition>) => void;
15
14
  }>;
package/dist/rpc/index.js CHANGED
@@ -32,16 +32,13 @@ __export(rpc_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(rpc_exports);
34
34
  var import_lodash = __toESM(require("@modern-js/utils/lodash"));
35
- var import_devtools_kit = require("@modern-js/devtools-kit");
35
+ var import_node = require("@modern-js/devtools-kit/node");
36
36
  var import_birpc = require("birpc");
37
+ var flatted = __toESM(require("flatted"));
37
38
  var import_p_defer = __toESM(require("p-defer"));
38
39
  var import_module = require("../utils/module");
39
40
  const setupClientConnection = async (options) => {
40
- const { api, server } = options;
41
- let def = {};
42
- const setDefinition = (definition) => {
43
- def = definition;
44
- };
41
+ const { api, server, def } = options;
45
42
  const _fileSystemRoutesMap = {};
46
43
  let handleMessage = null;
47
44
  const onceConnection = new Promise((resolve) => {
@@ -134,6 +131,36 @@ const setupClientConnection = async (options) => {
134
131
  "@modern-js/uni-builder",
135
132
  "@rsbuild/core",
136
133
  "@rspack/core/package.json"
134
+ ],
135
+ "@rsdoctor/rspack-plugin": [
136
+ ctx.rootPath,
137
+ "@rsdoctor/rspack-plugin/package.json"
138
+ ],
139
+ "@rsdoctor/webpack-plugin": [
140
+ ctx.rootPath,
141
+ "@rsdoctor/webpack-plugin/package.json"
142
+ ],
143
+ "@web-doctor/webpack-plugin": [
144
+ ctx.rootPath,
145
+ "@web-doctor/webpack-plugin/package.json"
146
+ ],
147
+ "@web-doctor/rspack-plugin": [
148
+ ctx.rootPath,
149
+ "@web-doctor/rspack-plugin/package.json"
150
+ ],
151
+ "@web-doctor/webpack-plugin(builder)": [
152
+ ctx.rootPath,
153
+ "@edenx/builder-plugin-web-doctor",
154
+ "@web-doctor/webpack-plugin/package.json"
155
+ ],
156
+ "@web-doctor/rspack-plugin(builder)": [
157
+ ctx.rootPath,
158
+ "@edenx/builder-plugin-web-doctor",
159
+ "@web-doctor/rspack-plugin/package.json"
160
+ ],
161
+ "@rsdoctor/core": [
162
+ ctx.rootPath,
163
+ "@rsdoctor/core/package.json"
137
164
  ]
138
165
  };
139
166
  for (const [name, expr] of Object.entries(resolveExprs)) {
@@ -148,12 +175,20 @@ const setupClientConnection = async (options) => {
148
175
  return deferred.compileTimeCost.promise;
149
176
  },
150
177
  async getClientDefinition() {
151
- const ret = new import_devtools_kit.ClientDefinition();
152
- Object.assign(ret.name, def.name);
153
- Object.assign(ret.packages, def.packages);
154
- Object.assign(ret.assets, def.assets);
155
- Object.assign(ret.announcement, def.announcement);
156
- return ret;
178
+ return def;
179
+ },
180
+ async getDoctorOverview() {
181
+ const ctx = api.useAppContext();
182
+ const manifestPath = await (0, import_node.findManifest)(ctx.distDirectory);
183
+ const json = await (0, import_node.parseManifest)(require(manifestPath));
184
+ const data = {
185
+ numModules: json.data.moduleGraph.modules.length,
186
+ numChunks: json.data.chunkGraph.chunks.length,
187
+ numPackages: json.data.packageGraph.packages.length,
188
+ summary: json.data.summary,
189
+ errors: json.data.errors
190
+ };
191
+ return data;
157
192
  },
158
193
  echo(content) {
159
194
  return content;
@@ -162,8 +197,10 @@ const setupClientConnection = async (options) => {
162
197
  const clientRpcOptions = {
163
198
  post: (data) => onceConnection.then(() => server.clients.forEach((ws) => ws.send(data))),
164
199
  on: (cb) => handleMessage = cb,
165
- serialize: (v) => JSON.stringify(v),
166
- deserialize: (v) => JSON.parse(v.toString())
200
+ serialize: (v) => flatted.stringify([
201
+ v
202
+ ]),
203
+ deserialize: (v) => flatted.parse(v.toString())[0]
167
204
  };
168
205
  const clientConn = (0, import_birpc.createBirpc)(serverFunctions, clientRpcOptions);
169
206
  const hooks = {
@@ -186,15 +223,23 @@ const setupClientConnection = async (options) => {
186
223
  deferred.builder.config.resolved.resolve(import_lodash.default.cloneDeep(api2.getRsbuildConfig()));
187
224
  deferred.builder.config.transformed.resolve(import_lodash.default.cloneDeep(api2.getNormalizedConfig()));
188
225
  });
189
- const modifyBundlerConfig = api2.context.bundlerType === "webpack" ? api2.modifyWebpackConfig : api2.modifyRspackConfig;
190
226
  const expectBundlerNum = import_lodash.default.castArray(api2.context.targets).length;
191
227
  const bundlerConfigs = [];
192
- modifyBundlerConfig((config) => {
228
+ const handleBundlerConfig = (config) => {
193
229
  bundlerConfigs.push(config);
194
230
  if (bundlerConfigs.length >= expectBundlerNum) {
195
231
  deferred.bundler.config.resolved.resolve(import_lodash.default.cloneDeep(bundlerConfigs));
196
232
  }
197
- });
233
+ };
234
+ if (api2.context.bundlerType === "webpack") {
235
+ api2.modifyWebpackConfig((config) => {
236
+ handleBundlerConfig(config);
237
+ });
238
+ } else {
239
+ api2.modifyRspackConfig((config) => {
240
+ handleBundlerConfig(config);
241
+ });
242
+ }
198
243
  api2.onBeforeCreateCompiler(({ bundlerConfigs: bundlerConfigs2 }) => {
199
244
  deferred.bundler.config.transformed.resolve(import_lodash.default.cloneDeep(bundlerConfigs2));
200
245
  });
@@ -213,8 +258,7 @@ const setupClientConnection = async (options) => {
213
258
  return {
214
259
  client: clientConn,
215
260
  hooks,
216
- builderPlugin,
217
- setDefinition
261
+ builderPlugin
218
262
  };
219
263
  };
220
264
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.46.1",
18
+ "version": "2.47.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/index.d.ts",
21
21
  "main": "./dist/index.js",
@@ -28,26 +28,30 @@
28
28
  "jsnext:source": "./src/index.ts",
29
29
  "require": "./dist/index.js"
30
30
  },
31
- "default": "./dist/index.js"
31
+ "default": "./dist/index.js",
32
+ "types": "./dist/index.d.ts"
32
33
  },
33
34
  "./cli": {
34
35
  "jsnext:source": "./src/cli.ts",
35
- "default": "./dist/cli.js"
36
+ "default": "./dist/cli.js",
37
+ "types": "./dist/cli.d.ts"
36
38
  },
37
39
  "./runtime": {
38
40
  "jsnext:source": "./src/runtime.ts",
39
- "default": "./dist/runtime.js"
41
+ "default": "./dist/runtime.js",
42
+ "types": "./dist/runtime.d.ts"
40
43
  }
41
44
  },
42
45
  "dependencies": {
43
46
  "birpc": "0.2.13",
47
+ "flatted": "^3.2.9",
44
48
  "serve-static": "^1.14.1",
45
49
  "p-defer": "^3.0.0",
46
50
  "ws": "^8.13.0",
47
51
  "ufo": "^1.3.0",
48
- "@modern-js/devtools-kit": "2.46.1",
49
- "@modern-js/devtools-client": "2.46.1",
50
- "@modern-js/utils": "2.46.1"
52
+ "@modern-js/devtools-kit": "2.47.1",
53
+ "@modern-js/devtools-client": "2.47.1",
54
+ "@modern-js/utils": "2.47.1"
51
55
  },
52
56
  "devDependencies": {
53
57
  "@types/serve-static": "^1.13.10",
@@ -56,17 +60,17 @@
56
60
  "@types/ws": "^8.5.5",
57
61
  "type-fest": "^4.1.0",
58
62
  "typescript": "^5",
59
- "@modern-js/app-tools": "2.46.1",
60
- "@modern-js/core": "2.46.1",
61
- "@modern-js/module-tools": "2.46.1",
62
- "@modern-js/runtime": "2.46.1",
63
- "@modern-js/types": "2.46.1",
64
- "@modern-js/server-core": "2.46.1",
65
- "@modern-js/uni-builder": "2.46.1",
66
- "@scripts/build": "2.46.1"
63
+ "@modern-js/app-tools": "2.47.1",
64
+ "@modern-js/core": "2.47.1",
65
+ "@modern-js/module-tools": "2.47.1",
66
+ "@modern-js/runtime": "2.47.1",
67
+ "@modern-js/types": "2.47.1",
68
+ "@modern-js/server-core": "2.47.1",
69
+ "@modern-js/uni-builder": "2.47.1",
70
+ "@scripts/build": "2.47.1"
67
71
  },
68
72
  "peerDependencies": {
69
- "@modern-js/runtime": "^2.46.1"
73
+ "@modern-js/runtime": "^2.47.1"
70
74
  },
71
75
  "peerDependenciesMeta": {
72
76
  "@modern-js/runtime": {