@modern-js/plugin-devtools 0.0.0-next-20240221082844 → 0.0.0-next-20240221105230

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,9 +1,5 @@
1
1
  import type { AppTools, CliPlugin } from '@modern-js/app-tools';
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;
2
+ import { DevtoolsPluginOptions, DevtoolsPluginInlineOptions } from './config';
3
+ export type { DevtoolsPluginOptions, DevtoolsPluginInlineOptions };
4
+ export declare const devtoolsPlugin: (inlineOptions?: DevtoolsPluginInlineOptions) => CliPlugin<AppTools>;
9
5
  export default devtoolsPlugin;
package/dist/cli.js CHANGED
@@ -41,120 +41,117 @@ 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
- 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
- {
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({
91
101
  tag: "script",
92
- children: `window.__MODERN_JS_DEVTOOLS_OPTIONS__ = ${serializedOptions};`,
102
+ attrs: {
103
+ src
104
+ },
93
105
  head: true,
94
106
  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
- }
107
+ });
108
+ } else if (src.endsWith(".css")) {
109
+ styles.push(src);
113
110
  }
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
- }
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
149
146
  }
150
147
  }
151
148
  }
152
- };
153
- }
154
- };
155
- }
156
- };
157
- };
149
+ }
150
+ };
151
+ }
152
+ };
153
+ }
154
+ });
158
155
  var cli_default = devtoolsPlugin;
159
156
  const setupHttpServer = async () => {
160
157
  const port = await (0, import_utils.getPort)(8782, {
package/dist/config.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { ClientDefinition } from '@modern-js/devtools-kit/node';
1
+ import { ClientDefinition, SetupClientParams } from '@modern-js/devtools-kit/node';
2
2
  import type { RequiredDeep } from 'type-fest';
3
- export interface DevtoolsPluginOptions {
3
+ export type DevtoolsPluginOptions = Partial<SetupClientParams>;
4
+ export interface DevtoolsPluginInlineOptions extends DevtoolsPluginOptions {
4
5
  enable?: boolean;
5
- endpoint?: string;
6
- dataSource?: string;
7
6
  }
8
- export interface DevtoolsContext extends RequiredDeep<DevtoolsPluginOptions> {
7
+ export type DevtoolsContext = RequiredDeep<DevtoolsPluginInlineOptions>;
8
+ export declare const getDefaultOptions: () => {
9
9
  def: ClientDefinition;
10
- }
11
- export declare const resolveContext: (...sources: Partial<DevtoolsContext>[]) => DevtoolsContext;
10
+ };
11
+ export declare const resolveContext: (...sources: DevtoolsPluginInlineOptions[]) => DevtoolsContext;
package/dist/config.js CHANGED
@@ -18,10 +18,14 @@ 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,
21
22
  resolveContext: () => resolveContext
22
23
  });
23
24
  module.exports = __toCommonJS(config_exports);
24
25
  var import_node = require("@modern-js/devtools-kit/node");
26
+ const getDefaultOptions = () => ({
27
+ def: new import_node.ClientDefinition()
28
+ });
25
29
  const resolveContext = (...sources) => {
26
30
  const ret = {
27
31
  enable: process.env.NODE_ENV === "development",
@@ -29,9 +33,6 @@ const resolveContext = (...sources) => {
29
33
  endpoint: import_node.ROUTE_BASENAME,
30
34
  def: new import_node.ClientDefinition()
31
35
  };
32
- Object.assign(ret, {
33
- __keep: true
34
- });
35
36
  for (const opts of sources) {
36
37
  var _opts_enable;
37
38
  ret.enable = (_opts_enable = opts.enable) !== null && _opts_enable !== void 0 ? _opts_enable : ret.enable;
@@ -39,12 +40,25 @@ const resolveContext = (...sources) => {
39
40
  ret.dataSource = (_opts_dataSource = opts.dataSource) !== null && _opts_dataSource !== void 0 ? _opts_dataSource : ret.dataSource;
40
41
  var _opts_endpoint;
41
42
  ret.endpoint = (_opts_endpoint = opts.endpoint) !== null && _opts_endpoint !== void 0 ? _opts_endpoint : ret.endpoint;
42
- var _opts_def;
43
- ret.def = (_opts_def = opts.def) !== null && _opts_def !== void 0 ? _opts_def : ret.def;
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
+ }
44
57
  }
45
58
  return ret;
46
59
  };
47
60
  // Annotate the CommonJS export names for ESM import in node:
48
61
  0 && (module.exports = {
62
+ getDefaultOptions,
49
63
  resolveContext
50
64
  });
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { devtoolsPlugin, default } from './cli';
2
- export type { DevtoolsPluginOptions } from './cli';
2
+ export type { DevtoolsPluginOptions, DevtoolsPluginInlineOptions } from './cli';
@@ -1,14 +1,15 @@
1
1
  import { ClientDefinition, type ClientFunctions, type ServerFunctions } from '@modern-js/devtools-kit/node';
2
+ import type { PartialDeep } from 'type-fest';
2
3
  import type { RsbuildPlugin } from '@modern-js/uni-builder';
3
4
  import { CliPluginAPI, InjectedHooks } from '../types';
4
5
  import { SocketServer } from '../utils/socket';
5
6
  export interface SetupClientConnectionOptions {
6
7
  api: CliPluginAPI;
7
8
  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;
14
15
  }>;
package/dist/rpc/index.js CHANGED
@@ -38,7 +38,11 @@ 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, def } = options;
41
+ const { api, server } = options;
42
+ let def = {};
43
+ const setDefinition = (definition) => {
44
+ def = definition;
45
+ };
42
46
  const _fileSystemRoutesMap = {};
43
47
  let handleMessage = null;
44
48
  const onceConnection = new Promise((resolve) => {
@@ -131,36 +135,6 @@ const setupClientConnection = async (options) => {
131
135
  "@modern-js/uni-builder",
132
136
  "@rsbuild/core",
133
137
  "@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"
164
138
  ]
165
139
  };
166
140
  for (const [name, expr] of Object.entries(resolveExprs)) {
@@ -175,20 +149,12 @@ const setupClientConnection = async (options) => {
175
149
  return deferred.compileTimeCost.promise;
176
150
  },
177
151
  async getClientDefinition() {
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;
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;
192
158
  },
193
159
  echo(content) {
194
160
  return content;
@@ -223,23 +189,15 @@ const setupClientConnection = async (options) => {
223
189
  deferred.builder.config.resolved.resolve(import_lodash.default.cloneDeep(api2.getRsbuildConfig()));
224
190
  deferred.builder.config.transformed.resolve(import_lodash.default.cloneDeep(api2.getNormalizedConfig()));
225
191
  });
192
+ const modifyBundlerConfig = api2.context.bundlerType === "webpack" ? api2.modifyWebpackConfig : api2.modifyRspackConfig;
226
193
  const expectBundlerNum = import_lodash.default.castArray(api2.context.targets).length;
227
194
  const bundlerConfigs = [];
228
- const handleBundlerConfig = (config) => {
195
+ modifyBundlerConfig((config) => {
229
196
  bundlerConfigs.push(config);
230
197
  if (bundlerConfigs.length >= expectBundlerNum) {
231
198
  deferred.bundler.config.resolved.resolve(import_lodash.default.cloneDeep(bundlerConfigs));
232
199
  }
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
- }
200
+ });
243
201
  api2.onBeforeCreateCompiler(({ bundlerConfigs: bundlerConfigs2 }) => {
244
202
  deferred.bundler.config.transformed.resolve(import_lodash.default.cloneDeep(bundlerConfigs2));
245
203
  });
@@ -258,7 +216,8 @@ const setupClientConnection = async (options) => {
258
216
  return {
259
217
  client: clientConn,
260
218
  hooks,
261
- builderPlugin
219
+ builderPlugin,
220
+ setDefinition
262
221
  };
263
222
  };
264
223
  // 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-next-20240221082844",
18
+ "version": "0.0.0-next-20240221105230",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/index.d.ts",
21
21
  "main": "./dist/index.js",
@@ -28,18 +28,15 @@
28
28
  "jsnext:source": "./src/index.ts",
29
29
  "require": "./dist/index.js"
30
30
  },
31
- "default": "./dist/index.js",
32
- "types": "./dist/index.d.ts"
31
+ "default": "./dist/index.js"
33
32
  },
34
33
  "./cli": {
35
34
  "jsnext:source": "./src/cli.ts",
36
- "default": "./dist/cli.js",
37
- "types": "./dist/cli.d.ts"
35
+ "default": "./dist/cli.js"
38
36
  },
39
37
  "./runtime": {
40
38
  "jsnext:source": "./src/runtime.ts",
41
- "default": "./dist/runtime.js",
42
- "types": "./dist/runtime.d.ts"
39
+ "default": "./dist/runtime.js"
43
40
  }
44
41
  },
45
42
  "dependencies": {
@@ -49,9 +46,9 @@
49
46
  "p-defer": "^3.0.0",
50
47
  "ws": "^8.13.0",
51
48
  "ufo": "^1.3.0",
52
- "@modern-js/devtools-kit": "0.0.0-next-20240221082844",
53
- "@modern-js/devtools-client": "0.0.0-next-20240221082844",
54
- "@modern-js/utils": "0.0.0-next-20240221082844"
49
+ "@modern-js/devtools-client": "0.0.0-next-20240221105230",
50
+ "@modern-js/utils": "0.0.0-next-20240221105230",
51
+ "@modern-js/devtools-kit": "0.0.0-next-20240221105230"
55
52
  },
56
53
  "devDependencies": {
57
54
  "@types/serve-static": "^1.13.10",
@@ -60,17 +57,17 @@
60
57
  "@types/ws": "^8.5.5",
61
58
  "type-fest": "^4.1.0",
62
59
  "typescript": "^5",
63
- "@modern-js/core": "0.0.0-next-20240221082844",
64
- "@modern-js/app-tools": "0.0.0-next-20240221082844",
65
- "@modern-js/module-tools": "0.0.0-next-20240221082844",
66
- "@modern-js/server-core": "0.0.0-next-20240221082844",
67
- "@modern-js/runtime": "0.0.0-next-20240221082844",
68
- "@modern-js/types": "0.0.0-next-20240221082844",
69
- "@modern-js/uni-builder": "0.0.0-next-20240221082844",
70
- "@scripts/build": "0.0.0-next-20240221082844"
60
+ "@modern-js/app-tools": "0.0.0-next-20240221105230",
61
+ "@modern-js/core": "0.0.0-next-20240221105230",
62
+ "@modern-js/module-tools": "0.0.0-next-20240221105230",
63
+ "@modern-js/runtime": "0.0.0-next-20240221105230",
64
+ "@modern-js/server-core": "0.0.0-next-20240221105230",
65
+ "@modern-js/types": "0.0.0-next-20240221105230",
66
+ "@scripts/build": "0.0.0-next-20240221105230",
67
+ "@modern-js/uni-builder": "0.0.0-next-20240221105230"
71
68
  },
72
69
  "peerDependencies": {
73
- "@modern-js/runtime": "0.0.0-next-20240221082844"
70
+ "@modern-js/runtime": "0.0.0-next-20240221105230"
74
71
  },
75
72
  "peerDependenciesMeta": {
76
73
  "@modern-js/runtime": {