@modern-js/plugin-devtools 0.0.0-nightly-20240220170629 → 0.0.0-nightly-20240221170640

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
@@ -41,117 +41,120 @@ 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 swProxyEntry = require.resolve("@modern-js/devtools-client/sw-proxy");
86
- const serializedOptions = JSON.stringify(ctx);
87
- const tags = [
88
- {
89
- tag: "script",
90
- children: `window.__MODERN_JS_DEVTOOLS_OPTIONS__ = ${serializedOptions};`,
91
- head: true,
92
- append: false
93
- }
94
- ];
95
- const styles = [];
96
- const manifest = require("@modern-js/devtools-client/manifest");
97
- for (const src of manifest.routeAssets.mount.assets) {
98
- (0, import_assert.default)(typeof src === "string");
99
- if (src.endsWith(".js")) {
100
- tags.push({
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
+ {
101
91
  tag: "script",
102
- attrs: {
103
- src
104
- },
92
+ children: `window.__MODERN_JS_DEVTOOLS_OPTIONS__ = ${serializedOptions};`,
105
93
  head: true,
106
94
  append: false
107
- });
108
- } else if (src.endsWith(".css")) {
109
- styles.push(src);
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
+ }
110
113
  }
111
- }
112
- tags.push({
113
- tag: "template",
114
- attrs: {
115
- id: "_modern_js_devtools_styles"
116
- },
117
- append: true,
118
- head: false,
119
- children: styles.map((src) => `<link rel="stylesheet" href="${src}">`).join("")
120
- });
121
- return {
122
- builderPlugins: [
123
- rpc.builderPlugin
124
- ],
125
- source: {},
126
- output: {
127
- copy: [
128
- {
129
- from: swProxyEntry,
130
- to: "public"
131
- }
132
- ]
133
- },
134
- html: {
135
- tags
136
- },
137
- tools: {
138
- devServer: {
139
- proxy: {
140
- [import_node.ROUTE_BASENAME]: {
141
- target: `http://localhost:${httpServer.port}`,
142
- pathRewrite: {
143
- [`^${import_node.ROUTE_BASENAME}`]: ""
144
- },
145
- ws: true
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
126
+ ],
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
+ }
146
149
  }
147
150
  }
148
151
  }
149
- }
150
- };
151
- }
152
- };
153
- }
154
- });
152
+ };
153
+ }
154
+ };
155
+ }
156
+ };
157
+ };
155
158
  var cli_default = devtoolsPlugin;
156
159
  const setupHttpServer = async () => {
157
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/node';
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,14 +18,10 @@ 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
24
  var import_node = require("@modern-js/devtools-kit/node");
26
- const getDefaultOptions = () => ({
27
- def: new import_node.ClientDefinition()
28
- });
29
25
  const resolveContext = (...sources) => {
30
26
  const ret = {
31
27
  enable: process.env.NODE_ENV === "development",
@@ -33,6 +29,9 @@ const resolveContext = (...sources) => {
33
29
  endpoint: import_node.ROUTE_BASENAME,
34
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
1
  import { ClientDefinition, type ClientFunctions, type ServerFunctions } from '@modern-js/devtools-kit/node';
2
- import type { PartialDeep } from 'type-fest';
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
@@ -38,11 +38,7 @@ var flatted = __toESM(require("flatted"));
38
38
  var import_p_defer = __toESM(require("p-defer"));
39
39
  var import_module = require("../utils/module");
40
40
  const setupClientConnection = async (options) => {
41
- const { api, server } = options;
42
- let def = {};
43
- const setDefinition = (definition) => {
44
- def = definition;
45
- };
41
+ const { api, server, def } = options;
46
42
  const _fileSystemRoutesMap = {};
47
43
  let handleMessage = null;
48
44
  const onceConnection = new Promise((resolve) => {
@@ -135,6 +131,36 @@ const setupClientConnection = async (options) => {
135
131
  "@modern-js/uni-builder",
136
132
  "@rsbuild/core",
137
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"
138
164
  ]
139
165
  };
140
166
  for (const [name, expr] of Object.entries(resolveExprs)) {
@@ -149,12 +175,20 @@ const setupClientConnection = async (options) => {
149
175
  return deferred.compileTimeCost.promise;
150
176
  },
151
177
  async getClientDefinition() {
152
- const ret = new import_node.ClientDefinition();
153
- Object.assign(ret.name, def.name);
154
- Object.assign(ret.packages, def.packages);
155
- Object.assign(ret.assets, def.assets);
156
- Object.assign(ret.announcement, def.announcement);
157
- 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;
158
192
  },
159
193
  echo(content) {
160
194
  return content;
@@ -189,15 +223,23 @@ const setupClientConnection = async (options) => {
189
223
  deferred.builder.config.resolved.resolve(import_lodash.default.cloneDeep(api2.getRsbuildConfig()));
190
224
  deferred.builder.config.transformed.resolve(import_lodash.default.cloneDeep(api2.getNormalizedConfig()));
191
225
  });
192
- const modifyBundlerConfig = api2.context.bundlerType === "webpack" ? api2.modifyWebpackConfig : api2.modifyRspackConfig;
193
226
  const expectBundlerNum = import_lodash.default.castArray(api2.context.targets).length;
194
227
  const bundlerConfigs = [];
195
- modifyBundlerConfig((config) => {
228
+ const handleBundlerConfig = (config) => {
196
229
  bundlerConfigs.push(config);
197
230
  if (bundlerConfigs.length >= expectBundlerNum) {
198
231
  deferred.bundler.config.resolved.resolve(import_lodash.default.cloneDeep(bundlerConfigs));
199
232
  }
200
- });
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
+ }
201
243
  api2.onBeforeCreateCompiler(({ bundlerConfigs: bundlerConfigs2 }) => {
202
244
  deferred.bundler.config.transformed.resolve(import_lodash.default.cloneDeep(bundlerConfigs2));
203
245
  });
@@ -216,8 +258,7 @@ const setupClientConnection = async (options) => {
216
258
  return {
217
259
  client: clientConn,
218
260
  hooks,
219
- builderPlugin,
220
- setDefinition
261
+ builderPlugin
221
262
  };
222
263
  };
223
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": "0.0.0-nightly-20240220170629",
18
+ "version": "0.0.0-nightly-20240221170640",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/index.d.ts",
21
21
  "main": "./dist/index.js",
@@ -28,15 +28,18 @@
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": {
@@ -46,9 +49,9 @@
46
49
  "p-defer": "^3.0.0",
47
50
  "ws": "^8.13.0",
48
51
  "ufo": "^1.3.0",
49
- "@modern-js/devtools-kit": "0.0.0-nightly-20240220170629",
50
- "@modern-js/devtools-client": "0.0.0-nightly-20240220170629",
51
- "@modern-js/utils": "0.0.0-nightly-20240220170629"
52
+ "@modern-js/devtools-kit": "0.0.0-nightly-20240221170640",
53
+ "@modern-js/devtools-client": "0.0.0-nightly-20240221170640",
54
+ "@modern-js/utils": "0.0.0-nightly-20240221170640"
52
55
  },
53
56
  "devDependencies": {
54
57
  "@types/serve-static": "^1.13.10",
@@ -57,17 +60,17 @@
57
60
  "@types/ws": "^8.5.5",
58
61
  "type-fest": "^4.1.0",
59
62
  "typescript": "^5",
60
- "@modern-js/app-tools": "0.0.0-nightly-20240220170629",
61
- "@modern-js/core": "0.0.0-nightly-20240220170629",
62
- "@modern-js/module-tools": "0.0.0-nightly-20240220170629",
63
- "@modern-js/server-core": "0.0.0-nightly-20240220170629",
64
- "@modern-js/types": "0.0.0-nightly-20240220170629",
65
- "@scripts/build": "0.0.0-nightly-20240220170629",
66
- "@modern-js/runtime": "0.0.0-nightly-20240220170629",
67
- "@modern-js/uni-builder": "0.0.0-nightly-20240220170629"
63
+ "@modern-js/core": "0.0.0-nightly-20240221170640",
64
+ "@modern-js/app-tools": "0.0.0-nightly-20240221170640",
65
+ "@modern-js/module-tools": "0.0.0-nightly-20240221170640",
66
+ "@modern-js/server-core": "0.0.0-nightly-20240221170640",
67
+ "@modern-js/runtime": "0.0.0-nightly-20240221170640",
68
+ "@modern-js/types": "0.0.0-nightly-20240221170640",
69
+ "@modern-js/uni-builder": "0.0.0-nightly-20240221170640",
70
+ "@scripts/build": "0.0.0-nightly-20240221170640"
68
71
  },
69
72
  "peerDependencies": {
70
- "@modern-js/runtime": "0.0.0-nightly-20240220170629"
73
+ "@modern-js/runtime": "0.0.0-nightly-20240221170640"
71
74
  },
72
75
  "peerDependenciesMeta": {
73
76
  "@modern-js/runtime": {