@modern-js/plugin-devtools 2.52.0 → 2.54.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.
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var state_exports = {};
30
+ __export(state_exports, {
31
+ pluginState: () => pluginState
32
+ });
33
+ module.exports = __toCommonJS(state_exports);
34
+ var import_node = require("@modern-js/devtools-kit/node");
35
+ var import_lodash = __toESM(require("@modern-js/utils/lodash"));
36
+ var import_valtio = require("valtio");
37
+ var import_module = require("../utils/module");
38
+ const resolveDependencies = async (rootPath) => {
39
+ const ret = {};
40
+ const resolveExprs = {
41
+ react: [
42
+ rootPath,
43
+ "react/package.json"
44
+ ],
45
+ "@modern-js/app-tools": [
46
+ rootPath,
47
+ "@modern-js/app-tools/package.json"
48
+ ],
49
+ "@edenx/app-tools": [
50
+ rootPath,
51
+ "@edenx/app-tools/package.json"
52
+ ],
53
+ webpack: [
54
+ rootPath,
55
+ "@modern-js/app-tools",
56
+ "@modern-js/uni-builder",
57
+ "@rsbuild/webpack",
58
+ "webpack/package.json"
59
+ ],
60
+ "@rspack/core": [
61
+ rootPath,
62
+ "@modern-js/uni-builder",
63
+ "@rsbuild/core",
64
+ "@rspack/core/package.json"
65
+ ],
66
+ "@rsdoctor/rspack-plugin": [
67
+ rootPath,
68
+ "@rsdoctor/rspack-plugin/package.json"
69
+ ],
70
+ "@rsdoctor/webpack-plugin": [
71
+ rootPath,
72
+ "@rsdoctor/webpack-plugin/package.json"
73
+ ],
74
+ "@web-doctor/webpack-plugin": [
75
+ rootPath,
76
+ "@web-doctor/webpack-plugin/package.json"
77
+ ],
78
+ "@web-doctor/rspack-plugin": [
79
+ rootPath,
80
+ "@web-doctor/rspack-plugin/package.json"
81
+ ],
82
+ "@web-doctor/webpack-plugin(builder)": [
83
+ rootPath,
84
+ "@edenx/builder-plugin-web-doctor",
85
+ "@web-doctor/webpack-plugin/package.json"
86
+ ],
87
+ "@web-doctor/rspack-plugin(builder)": [
88
+ rootPath,
89
+ "@edenx/builder-plugin-web-doctor",
90
+ "@web-doctor/rspack-plugin/package.json"
91
+ ],
92
+ "@rsdoctor/core": [
93
+ rootPath,
94
+ "@rsdoctor/core/package.json"
95
+ ]
96
+ };
97
+ for (const [name, expr] of Object.entries(resolveExprs)) {
98
+ try {
99
+ ret[name] = (0, import_module.requireModule)(expr).version;
100
+ } catch {
101
+ }
102
+ }
103
+ return ret;
104
+ };
105
+ const getDoctorOverview = async (ctx) => {
106
+ const manifestPath = await (0, import_node.findManifest)(ctx.distDirectory);
107
+ const json = await (0, import_node.parseManifest)(require(manifestPath));
108
+ return {
109
+ numModules: json.data.moduleGraph.modules.length,
110
+ numChunks: json.data.chunkGraph.chunks.length,
111
+ numPackages: json.data.packageGraph.packages.length,
112
+ summary: json.data.summary,
113
+ errors: json.data.errors
114
+ };
115
+ };
116
+ const pluginState = {
117
+ async setup(api) {
118
+ api.vars.state = (0, import_valtio.proxy)({
119
+ framework: {
120
+ config: {}
121
+ },
122
+ builder: {
123
+ config: {}
124
+ },
125
+ bundler: {
126
+ configs: {}
127
+ },
128
+ context: api.context,
129
+ dependencies: {},
130
+ fileSystemRoutes: {}
131
+ });
132
+ api.frameworkHooks.hook("modifyFileSystemRoutes", ({ entrypoint, routes }) => {
133
+ api.vars.state.fileSystemRoutes[entrypoint.entryName] = import_lodash.default.cloneDeep(routes);
134
+ });
135
+ const builderApi = await api.setupBuilder();
136
+ api.vars.state.builder.context = builderApi.context;
137
+ resolveDependencies(builderApi.context.rootPath).then((deps) => {
138
+ api.vars.state.dependencies = deps;
139
+ });
140
+ api.builderHooks.hook("modifyBundlerChain", () => {
141
+ api.vars.state.builder.config = {
142
+ resolved: import_lodash.default.cloneDeep(builderApi.getRsbuildConfig()),
143
+ transformed: import_lodash.default.cloneDeep(builderApi.getNormalizedConfig())
144
+ };
145
+ });
146
+ const expectBundlerNum = import_lodash.default.castArray(builderApi.context.targets).length;
147
+ const bundlerConfigs = [];
148
+ const handleBundlerConfig = (config) => {
149
+ bundlerConfigs.push(config);
150
+ if (bundlerConfigs.length >= expectBundlerNum) {
151
+ api.vars.state.bundler.configs.resolved = import_lodash.default.cloneDeep(bundlerConfigs);
152
+ }
153
+ };
154
+ if (builderApi.context.bundlerType === "webpack") {
155
+ api.builderHooks.hook("modifyWebpackConfig", handleBundlerConfig);
156
+ } else {
157
+ api.builderHooks.hook("modifyRspackConfig", handleBundlerConfig);
158
+ }
159
+ api.builderHooks.hook("onBeforeCreateCompiler", ({ bundlerConfigs: bundlerConfigs2 }) => {
160
+ api.vars.state.bundler.configs.transformed = import_lodash.default.cloneDeep(bundlerConfigs2);
161
+ });
162
+ let buildStartedAt = NaN;
163
+ api.builderHooks.hook("onAfterCreateCompiler", () => {
164
+ buildStartedAt = Date.now();
165
+ });
166
+ api.builderHooks.hook("onDevCompileDone", () => {
167
+ api.vars.state.performance = {
168
+ compileDuration: Date.now() - buildStartedAt
169
+ };
170
+ });
171
+ api.builderHooks.hook("onAfterBuild", () => {
172
+ api.vars.state.performance = {
173
+ compileDuration: Date.now() - buildStartedAt
174
+ };
175
+ });
176
+ api.hooks.hook("settleState", async () => {
177
+ try {
178
+ api.vars.state.doctor = await getDoctorOverview(frameworkContext);
179
+ } catch (err) {
180
+ }
181
+ });
182
+ const frameworkApi = await api.setupFramework();
183
+ const frameworkContext = {
184
+ ...frameworkApi.useAppContext(),
185
+ builder: null,
186
+ serverInternalPlugins: null
187
+ };
188
+ api.vars.state.framework = {
189
+ context: frameworkContext,
190
+ config: {
191
+ resolved: frameworkApi.useConfigContext(),
192
+ transformed: frameworkApi.useResolvedConfigContext()
193
+ }
194
+ };
195
+ }
196
+ };
197
+ // Annotate the CommonJS export names for ESM import in node:
198
+ 0 && (module.exports = {
199
+ pluginState
200
+ });
@@ -0,0 +1,2 @@
1
+ import { Plugin } from '../types';
2
+ export declare const pluginWatcher: Plugin;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var watcher_exports = {};
20
+ __export(watcher_exports, {
21
+ pluginWatcher: () => pluginWatcher
22
+ });
23
+ module.exports = __toCommonJS(watcher_exports);
24
+ var import_utils = require("@modern-js/utils");
25
+ var import_config = require("../utils/config");
26
+ var import_options = require("../options");
27
+ const pluginWatcher = {
28
+ async setup(api) {
29
+ const basename = `${api.context.def.name.shortName}.runtime.json`;
30
+ const frameworkApi = await api.setupFramework();
31
+ const appCtx = frameworkApi.useAppContext();
32
+ const watcher = import_utils.chokidar.watch((0, import_config.getConfigFilenames)(basename), {
33
+ cwd: appCtx.appDirectory,
34
+ ignorePermissionErrors: true
35
+ });
36
+ const refreshStoragePreset = async () => {
37
+ const configs = await (0, import_config.loadConfigFiles)(basename, appCtx.appDirectory);
38
+ if (!configs)
39
+ return;
40
+ api.context.storagePresets = [];
41
+ (0, import_options.updateContext)(api.context, ...configs);
42
+ };
43
+ watcher.on("add", refreshStoragePreset);
44
+ watcher.on("change", refreshStoragePreset);
45
+ watcher.on("unlink", refreshStoragePreset);
46
+ api.hooks.hook("cleanup", () => {
47
+ watcher.close();
48
+ });
49
+ }
50
+ };
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ pluginWatcher
54
+ });
@@ -0,0 +1,2 @@
1
+ /// <reference lib="dom" />
2
+ export {};
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var import_runtime = require("@modern-js/devtools-kit/runtime");
3
+ const fetchSync = (url, body) => {
4
+ const xhr = new XMLHttpRequest();
5
+ xhr.open("GET", url, false);
6
+ xhr.send(body);
7
+ return {
8
+ text() {
9
+ return xhr.responseText;
10
+ },
11
+ json(reviver2) {
12
+ return JSON.parse(xhr.responseText, reviver2);
13
+ },
14
+ blob() {
15
+ return new Blob([
16
+ xhr.response
17
+ ]);
18
+ }
19
+ };
20
+ };
21
+ const importScript = (url) => {
22
+ const script = document.createElement("script");
23
+ script.setAttribute("src", url);
24
+ document.head.appendChild(script);
25
+ };
26
+ const importStyle = (url, parent = document.head) => {
27
+ const link = document.createElement("link");
28
+ link.setAttribute("rel", "stylesheet");
29
+ link.setAttribute("href", url.toString());
30
+ parent.appendChild(link);
31
+ };
32
+ const GLOBAL_MANIFEST = "window.__modern_js_devtools_manifest";
33
+ const setup = () => {
34
+ var _document_cookie_match;
35
+ const injectedManifestUrl = process.env.__USE_MODERNJS_DEVTOOLS__;
36
+ const cookieManifestUrl = (_document_cookie_match = document.cookie.match(/use_modernjs_devtools=([^;]+)/)) === null || _document_cookie_match === void 0 ? void 0 : _document_cookie_match[1];
37
+ const devtoolsUrl = cookieManifestUrl || injectedManifestUrl;
38
+ if (!devtoolsUrl)
39
+ return;
40
+ const manifest = fetchSync(devtoolsUrl).json((0, import_runtime.reviver)());
41
+ manifest.source = devtoolsUrl;
42
+ const template = document.createElement("template");
43
+ template.id = "_modern_js_devtools_styles";
44
+ document.body.appendChild(template);
45
+ const setupScript = document.createElement("script");
46
+ setupScript.textContent = `${GLOBAL_MANIFEST} = ${JSON.stringify(manifest)};`;
47
+ document.head.appendChild(setupScript);
48
+ for (const src of manifest.routeAssets.mount.assets) {
49
+ if (src.endsWith(".js")) {
50
+ importScript(src);
51
+ } else if (src.endsWith(".css")) {
52
+ importStyle(src, template.content);
53
+ }
54
+ }
55
+ };
56
+ try {
57
+ setup();
58
+ } catch (e) {
59
+ const err = new Error("Failed to setup Modern.js DevTools.");
60
+ err.cause = e;
61
+ console.error(err);
62
+ }
@@ -2,6 +2,9 @@
2
2
  import { BaseHooks } from '@modern-js/core';
3
3
  import type { AppTools, AppToolsHooks, CliPlugin } from '@modern-js/app-tools';
4
4
  import type { ServerPlugin, ToThreads } from '@modern-js/server-core';
5
+ import type { RsbuildPluginAPI } from '@rsbuild/core';
6
+ import { Hookable } from 'hookable';
7
+ import { DevtoolsContext } from '@modern-js/devtools-kit/node';
5
8
  export type CliPluginAPI = Parameters<NonNullable<CliPlugin<AppTools>['setup']>>[0];
6
9
  export type ServerPluginAPI = Parameters<NonNullable<ServerPlugin['setup']>>[0];
7
10
  export type BufferLike = string | Buffer | DataView | number | ArrayBufferView | Uint8Array | ArrayBuffer | SharedArrayBuffer | ReadonlyArray<any> | ReadonlyArray<number> | {
@@ -17,5 +20,37 @@ export type BufferLike = string | Buffer | DataView | number | ArrayBufferView |
17
20
  } | {
18
21
  [Symbol.toPrimitive]: (hint: string) => string;
19
22
  };
20
- export type Hooks = BaseHooks<any> & AppToolsHooks<any>;
21
- export type InjectedHooks = Pick<ToThreads<Hooks>, 'prepare' | 'modifyFileSystemRoutes' | 'afterCreateCompiler'>;
23
+ export type CleanHooks<T> = {
24
+ [K in keyof T]: T[K] extends (...args: [...infer Params]) => any ? (...args: [...Params]) => void : never;
25
+ };
26
+ export type $FrameworkHooks = CleanHooks<Pick<ToThreads<BaseHooks<any> & AppToolsHooks<any>>, 'prepare' | 'modifyFileSystemRoutes' | 'modifyServerRoutes' | 'afterCreateCompiler' | 'afterDev' | 'beforeRestart' | 'beforeExit' | 'afterBuild'>>;
27
+ export interface FrameworkHooks extends $FrameworkHooks {
28
+ config: () => void;
29
+ }
30
+ type UnwrapBuilderHooks<T> = {
31
+ [K in keyof T]: T[K] extends (...args: any) => any ? (...params: [...Parameters<Parameters<T[K]>[0]>]) => void : never;
32
+ };
33
+ export type $BuilderHooks = UnwrapBuilderHooks<Pick<RsbuildPluginAPI, 'modifyBundlerChain' | 'modifyWebpackConfig' | 'modifyRspackConfig' | 'onBeforeCreateCompiler' | 'onAfterCreateCompiler' | 'onDevCompileDone' | 'onAfterBuild' | 'onExit'>>;
34
+ export interface BuilderHooks extends $BuilderHooks {
35
+ }
36
+ export interface DevtoolsHooks {
37
+ cleanup: () => Promise<void> | void;
38
+ settleState: () => Promise<void> | void;
39
+ }
40
+ declare global {
41
+ interface DevtoolsPluginVars extends Record<string, unknown> {
42
+ }
43
+ }
44
+ export interface PluginApi {
45
+ builderHooks: Hookable<BuilderHooks>;
46
+ frameworkHooks: Hookable<FrameworkHooks>;
47
+ hooks: Hookable<DevtoolsHooks>;
48
+ setupFramework: () => Promise<CliPluginAPI>;
49
+ setupBuilder: () => Promise<RsbuildPluginAPI>;
50
+ context: DevtoolsContext;
51
+ vars: DevtoolsPluginVars;
52
+ }
53
+ export interface Plugin {
54
+ setup: (api: PluginApi) => Promise<void>;
55
+ }
56
+ export {};
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.52.0",
18
+ "version": "2.54.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/index.d.ts",
21
21
  "main": "./dist/index.js",
@@ -43,7 +43,7 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@hono/node-server": "^1.8.2",
46
+ "@hono/node-server": "^1.11.2",
47
47
  "birpc": "0.2.13",
48
48
  "clipboardy": "^4.0.0",
49
49
  "cookie-es": "^1.0.0",
@@ -54,9 +54,10 @@
54
54
  "ufo": "^1.3.0",
55
55
  "valtio": "^1.11.1",
56
56
  "ws": "^8.13.0",
57
- "@modern-js/devtools-client": "2.52.0",
58
- "@modern-js/devtools-kit": "2.52.0",
59
- "@modern-js/utils": "2.52.0"
57
+ "hookable": "^5.5.3",
58
+ "@modern-js/devtools-client": "2.54.0",
59
+ "@modern-js/utils": "2.54.0",
60
+ "@modern-js/devtools-kit": "2.54.0"
60
61
  },
61
62
  "devDependencies": {
62
63
  "@swc/helpers": "0.5.3",
@@ -64,17 +65,18 @@
64
65
  "@types/ws": "^8.5.5",
65
66
  "type-fest": "^4.1.0",
66
67
  "typescript": "^5",
67
- "@modern-js/app-tools": "2.52.0",
68
- "@modern-js/module-tools": "2.52.0",
69
- "@modern-js/runtime": "2.52.0",
70
- "@modern-js/core": "2.52.0",
71
- "@modern-js/server-core": "2.52.0",
72
- "@modern-js/types": "2.52.0",
73
- "@modern-js/uni-builder": "2.52.0",
74
- "@scripts/build": "2.52.0"
68
+ "@rsbuild/core": "0.7.9",
69
+ "@modern-js/app-tools": "2.54.0",
70
+ "@modern-js/core": "2.54.0",
71
+ "@modern-js/module-tools": "2.54.0",
72
+ "@modern-js/runtime": "2.54.0",
73
+ "@modern-js/server-core": "2.54.0",
74
+ "@modern-js/types": "2.54.0",
75
+ "@modern-js/uni-builder": "2.54.0",
76
+ "@scripts/build": "2.54.0"
75
77
  },
76
78
  "peerDependencies": {
77
- "@modern-js/runtime": "^2.52.0"
79
+ "@modern-js/runtime": "^2.54.0"
78
80
  },
79
81
  "peerDependenciesMeta": {
80
82
  "@modern-js/runtime": {
@@ -1,14 +0,0 @@
1
- import { type ClientFunctions, type ServerFunctions, DevtoolsContext } from '@modern-js/devtools-kit/node';
2
- import type { RsbuildPlugin } from '@modern-js/uni-builder';
3
- import { CliPluginAPI, InjectedHooks } from '../types';
4
- import { SocketServer } from '../utils/socket';
5
- export interface SetupClientConnectionOptions {
6
- api: CliPluginAPI;
7
- server: SocketServer;
8
- ctx: DevtoolsContext;
9
- }
10
- export declare const setupClientConnection: (options: SetupClientConnectionOptions) => Promise<{
11
- client: import("birpc").BirpcReturn<ClientFunctions, ServerFunctions>;
12
- hooks: InjectedHooks;
13
- builderPlugin: RsbuildPlugin;
14
- }>;