@modern-js/plugin-devtools 0.0.0-nightly-20240617170645 → 0.0.0-nightly-20240619170730
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.js +14 -8
- package/dist/options.js +1 -7
- package/dist/plugins/cleanup.d.ts +2 -0
- package/dist/plugins/cleanup.js +39 -0
- package/dist/plugins/debug.js +6 -3
- package/dist/plugins/html.js +11 -52
- package/dist/plugins/http.js +26 -22
- package/dist/plugins/manifest.d.ts +11 -0
- package/dist/plugins/manifest.js +77 -0
- package/dist/plugins/rpc.js +15 -166
- package/dist/plugins/settle.d.ts +2 -0
- package/dist/plugins/settle.js +52 -0
- package/dist/plugins/state.d.ts +2 -3
- package/dist/plugins/state.js +167 -3
- package/dist/plugins/watcher.js +3 -8
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.js +62 -0
- package/dist/types/common.d.ts +7 -2
- package/package.json +14 -14
package/dist/cli.js
CHANGED
@@ -46,6 +46,9 @@ var import_watcher = require("./plugins/watcher");
|
|
46
46
|
var import_service_worker = require("./plugins/service-worker");
|
47
47
|
var import_html = require("./plugins/html");
|
48
48
|
var import_rpc = require("./plugins/rpc");
|
49
|
+
var import_cleanup = require("./plugins/cleanup");
|
50
|
+
var import_settle = require("./plugins/settle");
|
51
|
+
var import_manifest = require("./plugins/manifest");
|
49
52
|
const BUILTIN_PLUGINS = [
|
50
53
|
import_debug.pluginDebug,
|
51
54
|
import_watcher.pluginWatcher,
|
@@ -54,7 +57,11 @@ const BUILTIN_PLUGINS = [
|
|
54
57
|
// --- //
|
55
58
|
import_state.pluginState,
|
56
59
|
import_http.pluginHttp,
|
57
|
-
import_rpc.pluginRpc
|
60
|
+
import_rpc.pluginRpc,
|
61
|
+
import_settle.pluginSettleState,
|
62
|
+
import_manifest.pluginManifest,
|
63
|
+
// --- //
|
64
|
+
import_cleanup.pluginCleanup
|
58
65
|
];
|
59
66
|
const devtoolsPlugin = (inlineOptions = {}) => {
|
60
67
|
const ctx = (0, import_valtio.proxy)((0, import_options.resolveContext)(inlineOptions));
|
@@ -64,6 +71,7 @@ const devtoolsPlugin = (inlineOptions = {}) => {
|
|
64
71
|
const api = {
|
65
72
|
builderHooks: (0, import_hookable.createHooks)(),
|
66
73
|
frameworkHooks: (0, import_hookable.createHooks)(),
|
74
|
+
hooks: (0, import_hookable.createHooks)(),
|
67
75
|
setupBuilder: () => setupBuilder.promise,
|
68
76
|
setupFramework: () => setupFramework.promise,
|
69
77
|
get context() {
|
@@ -73,12 +81,10 @@ const devtoolsPlugin = (inlineOptions = {}) => {
|
|
73
81
|
return _sharedVars;
|
74
82
|
}
|
75
83
|
};
|
76
|
-
|
84
|
+
api.hooks.hook("cleanup", () => {
|
77
85
|
setupBuilder.reject(new Error("Devtools Plugin is disabled"));
|
78
86
|
setupFramework.reject(new Error("Devtools Plugin is disabled"));
|
79
|
-
|
80
|
-
api.frameworkHooks.removeAllHooks();
|
81
|
-
};
|
87
|
+
});
|
82
88
|
for (const plugin of BUILTIN_PLUGINS) {
|
83
89
|
plugin.setup(api);
|
84
90
|
}
|
@@ -109,15 +115,15 @@ const devtoolsPlugin = (inlineOptions = {}) => {
|
|
109
115
|
},
|
110
116
|
async beforeRestart() {
|
111
117
|
await api.frameworkHooks.callHook("beforeRestart");
|
112
|
-
cleanup();
|
113
118
|
},
|
114
119
|
beforeExit() {
|
115
120
|
api.frameworkHooks.callHookWith((hooks) => hooks.forEach((hook) => hook()), "beforeExit");
|
116
|
-
|
121
|
+
},
|
122
|
+
async afterDev(params) {
|
123
|
+
await api.frameworkHooks.callHook("afterDev", params);
|
117
124
|
},
|
118
125
|
async afterBuild(params) {
|
119
126
|
api.frameworkHooks.callHook("afterBuild", params);
|
120
|
-
cleanup();
|
121
127
|
},
|
122
128
|
async config() {
|
123
129
|
import_utils.logger.info(`${ctx.def.name.formalName} DevTools is enabled`);
|
package/dist/options.js
CHANGED
@@ -25,19 +25,13 @@ module.exports = __toCommonJS(options_exports);
|
|
25
25
|
var import_node = require("@modern-js/devtools-kit/node");
|
26
26
|
const resolveContext = (...sources) => {
|
27
27
|
const ret = {
|
28
|
-
enable:
|
29
|
-
dataSource: `${import_node.ROUTE_BASENAME}/rpc`,
|
30
|
-
endpoint: import_node.ROUTE_BASENAME,
|
28
|
+
enable: true,
|
31
29
|
def: new import_node.ClientDefinition(),
|
32
30
|
storagePresets: []
|
33
31
|
};
|
34
32
|
for (const opts of sources) {
|
35
33
|
var _opts_enable;
|
36
34
|
ret.enable = (_opts_enable = opts.enable) !== null && _opts_enable !== void 0 ? _opts_enable : ret.enable;
|
37
|
-
var _opts_dataSource;
|
38
|
-
ret.dataSource = (_opts_dataSource = opts.dataSource) !== null && _opts_dataSource !== void 0 ? _opts_dataSource : ret.dataSource;
|
39
|
-
var _opts_endpoint;
|
40
|
-
ret.endpoint = (_opts_endpoint = opts.endpoint) !== null && _opts_endpoint !== void 0 ? _opts_endpoint : ret.endpoint;
|
41
35
|
var _opts_def;
|
42
36
|
ret.def = (_opts_def = opts.def) !== null && _opts_def !== void 0 ? _opts_def : ret.def;
|
43
37
|
opts.storagePresets && ret.storagePresets.push(...opts.storagePresets);
|
@@ -0,0 +1,39 @@
|
|
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 cleanup_exports = {};
|
20
|
+
__export(cleanup_exports, {
|
21
|
+
pluginCleanup: () => pluginCleanup
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(cleanup_exports);
|
24
|
+
const pluginCleanup = {
|
25
|
+
async setup(api) {
|
26
|
+
let _done = false;
|
27
|
+
const cleanup = async () => {
|
28
|
+
!_done && await api.hooks.callHook("cleanup");
|
29
|
+
_done = true;
|
30
|
+
};
|
31
|
+
api.frameworkHooks.hook("beforeExit", cleanup);
|
32
|
+
api.frameworkHooks.hook("beforeRestart", cleanup);
|
33
|
+
api.frameworkHooks.hook("afterBuild", cleanup);
|
34
|
+
}
|
35
|
+
};
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
37
|
+
0 && (module.exports = {
|
38
|
+
pluginCleanup
|
39
|
+
});
|
package/dist/plugins/debug.js
CHANGED
@@ -31,11 +31,14 @@ const pluginDebug = {
|
|
31
31
|
logger.debug("setup framework api");
|
32
32
|
await api.setupBuilder();
|
33
33
|
logger.debug("setup builder api");
|
34
|
-
api.
|
34
|
+
api.builderHooks.beforeEach((e) => {
|
35
|
+
logger.debug("after builder hook:", e.name);
|
36
|
+
});
|
37
|
+
api.frameworkHooks.beforeEach((e) => {
|
35
38
|
logger.debug("after framework hook:", e.name);
|
36
39
|
});
|
37
|
-
api.
|
38
|
-
logger.debug("after
|
40
|
+
api.hooks.beforeEach((e) => {
|
41
|
+
logger.debug("after hook:", e.name);
|
39
42
|
});
|
40
43
|
}
|
41
44
|
};
|
package/dist/plugins/html.js
CHANGED
@@ -31,65 +31,24 @@ __export(html_exports, {
|
|
31
31
|
pluginHtml: () => pluginHtml
|
32
32
|
});
|
33
33
|
module.exports = __toCommonJS(html_exports);
|
34
|
-
var import_assert = __toESM(require("assert"));
|
35
|
-
var import_lodash = __toESM(require("@modern-js/utils/lodash"));
|
36
34
|
const pluginHtml = {
|
37
35
|
async setup(api) {
|
38
|
-
api.frameworkHooks.hook("modifyServerRoutes", ({ routes }) => {
|
39
|
-
routes.push({
|
40
|
-
urlPath: "/sw-proxy.js",
|
41
|
-
isSPA: true,
|
42
|
-
isSSR: false,
|
43
|
-
entryPath: "public/sw-proxy.js"
|
44
|
-
});
|
45
|
-
});
|
46
36
|
api.frameworkHooks.hook("config", async () => {
|
47
|
-
const clientOptions =
|
48
|
-
|
49
|
-
"
|
50
|
-
|
51
|
-
]);
|
37
|
+
const clientOptions = {
|
38
|
+
def: api.context.def,
|
39
|
+
src: "/__devtools"
|
40
|
+
};
|
52
41
|
Object.assign(clientOptions, {
|
53
42
|
__keep: true
|
54
43
|
});
|
55
|
-
const serializedOptions = JSON.stringify(clientOptions);
|
56
|
-
const tags = [
|
57
|
-
{
|
58
|
-
tag: "script",
|
59
|
-
children: `window.__MODERN_JS_DEVTOOLS_OPTIONS__ = ${serializedOptions};`,
|
60
|
-
head: true,
|
61
|
-
append: false
|
62
|
-
}
|
63
|
-
];
|
64
|
-
const styles = [];
|
65
|
-
const manifest = require("@modern-js/devtools-client/manifest");
|
66
|
-
for (const src of manifest.routeAssets.mount.assets) {
|
67
|
-
(0, import_assert.default)(typeof src === "string");
|
68
|
-
if (src.endsWith(".js")) {
|
69
|
-
tags.push({
|
70
|
-
tag: "script",
|
71
|
-
attrs: {
|
72
|
-
src
|
73
|
-
},
|
74
|
-
head: true,
|
75
|
-
append: false
|
76
|
-
});
|
77
|
-
} else if (src.endsWith(".css")) {
|
78
|
-
styles.push(src);
|
79
|
-
}
|
80
|
-
}
|
81
|
-
tags.push({
|
82
|
-
tag: "template",
|
83
|
-
attrs: {
|
84
|
-
id: "_modern_js_devtools_styles"
|
85
|
-
},
|
86
|
-
append: true,
|
87
|
-
head: false,
|
88
|
-
children: styles.map((src) => `<link rel="stylesheet" href="${src}">`).join("")
|
89
|
-
});
|
90
44
|
const config = {
|
91
|
-
|
92
|
-
|
45
|
+
source: {
|
46
|
+
preEntry: [
|
47
|
+
require.resolve("../runtime")
|
48
|
+
],
|
49
|
+
globalVars: {
|
50
|
+
"process.env.__USE_MODERNJS_DEVTOOLS__": "/__devtools/manifest"
|
51
|
+
}
|
93
52
|
}
|
94
53
|
};
|
95
54
|
return config;
|
package/dist/plugins/http.js
CHANGED
@@ -41,8 +41,7 @@ var import_node_server = require("@hono/node-server");
|
|
41
41
|
var import_serve_static = require("@hono/node-server/serve-static");
|
42
42
|
var import_node = require("@modern-js/devtools-kit/node");
|
43
43
|
const CLIENT_SERVE_DIR = import_path.default.resolve(require.resolve("@modern-js/devtools-client/package.json"), "../dist");
|
44
|
-
const
|
45
|
-
app.all("/api/cookies", async (c) => {
|
44
|
+
const cookiesServiceHandler = async (c) => {
|
46
45
|
const raw = c.req.header("Cookie");
|
47
46
|
const { parse } = await import("cookie-es");
|
48
47
|
const cookies = raw ? parse(raw) : {};
|
@@ -62,15 +61,8 @@ app.all("/api/cookies", async (c) => {
|
|
62
61
|
return c.json({
|
63
62
|
cookies
|
64
63
|
});
|
65
|
-
}
|
66
|
-
|
67
|
-
"/static/*",
|
68
|
-
// Workaround for https://github.com/honojs/node-server/blob/dd0e0cd160b0b8f18abbcb28c5f5c39b72105d98/src/serve-static.ts#L56
|
69
|
-
(0, import_serve_static.serveStatic)({
|
70
|
-
root: import_path.default.relative(process.cwd(), CLIENT_SERVE_DIR)
|
71
|
-
})
|
72
|
-
);
|
73
|
-
app.get(":filename{.+\\.hot-update\\.\\w+$}", async (c) => {
|
64
|
+
};
|
65
|
+
const hotUpdateHandler = async (c) => {
|
74
66
|
if (process.env.NODE_ENV !== "development") {
|
75
67
|
return c.text("Not found", 404);
|
76
68
|
}
|
@@ -85,16 +77,33 @@ app.get(":filename{.+\\.hot-update\\.\\w+$}", async (c) => {
|
|
85
77
|
newResp.headers.delete("content-encoding");
|
86
78
|
}
|
87
79
|
return newResp;
|
88
|
-
}
|
89
|
-
|
80
|
+
};
|
81
|
+
const fallbackHtmlHandler = async (c) => {
|
90
82
|
const filename = import_path.default.resolve(CLIENT_SERVE_DIR, "html/client/index.html");
|
91
83
|
const content = await import_utils.fs.readFile(filename, "utf-8");
|
92
84
|
return c.html(content);
|
93
|
-
}
|
85
|
+
};
|
94
86
|
const pluginHttp = {
|
95
87
|
async setup(api) {
|
96
88
|
if (process.env.NODE_ENV === "production")
|
97
89
|
return;
|
90
|
+
const app = new import_hono.Hono();
|
91
|
+
app.all("/api/cookies", cookiesServiceHandler);
|
92
|
+
app.use(
|
93
|
+
"/static/*",
|
94
|
+
// Workaround for https://github.com/honojs/node-server/blob/dd0e0cd160b0b8f18abbcb28c5f5c39b72105d98/src/serve-static.ts#L56
|
95
|
+
(0, import_serve_static.serveStatic)({
|
96
|
+
root: import_path.default.relative(process.cwd(), CLIENT_SERVE_DIR)
|
97
|
+
})
|
98
|
+
);
|
99
|
+
app.get(":filename{.+\\.hot-update\\.\\w+$}", hotUpdateHandler);
|
100
|
+
app.get("/manifest", async (c) => {
|
101
|
+
const json = await api.vars.useManifestJson;
|
102
|
+
return c.newResponse(json, 200, {
|
103
|
+
"Content-Type": "application/json"
|
104
|
+
});
|
105
|
+
});
|
106
|
+
app.get("*", fallbackHtmlHandler);
|
98
107
|
const server = (0, import_node_server.createAdaptorServer)({
|
99
108
|
fetch: app.fetch,
|
100
109
|
hostname: "127.0.0.1",
|
@@ -135,14 +144,9 @@ const pluginHttp = {
|
|
135
144
|
}
|
136
145
|
};
|
137
146
|
});
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
_open = false;
|
142
|
-
};
|
143
|
-
api.frameworkHooks.hook("beforeExit", cleanup);
|
144
|
-
api.frameworkHooks.hook("beforeRestart", cleanup);
|
145
|
-
api.frameworkHooks.hook("afterBuild", cleanup);
|
147
|
+
api.hooks.hook("cleanup", () => {
|
148
|
+
server.close();
|
149
|
+
});
|
146
150
|
}
|
147
151
|
};
|
148
152
|
// Annotate the CommonJS export names for ESM import in node:
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { type ServerManifest } from '@modern-js/devtools-kit/node';
|
2
|
+
import { Plugin } from '../types';
|
3
|
+
declare global {
|
4
|
+
interface DevtoolsPluginVars {
|
5
|
+
manifest?: ServerManifest;
|
6
|
+
manifestJson?: string;
|
7
|
+
useManifest: Promise<ServerManifest>;
|
8
|
+
useManifestJson: Promise<string>;
|
9
|
+
}
|
10
|
+
}
|
11
|
+
export declare const pluginManifest: Plugin;
|
@@ -0,0 +1,77 @@
|
|
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 manifest_exports = {};
|
30
|
+
__export(manifest_exports, {
|
31
|
+
pluginManifest: () => pluginManifest
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(manifest_exports);
|
34
|
+
var import_path = __toESM(require("path"));
|
35
|
+
var import_node = require("@modern-js/devtools-kit/node");
|
36
|
+
var import_utils = require("@modern-js/utils");
|
37
|
+
var import_p_defer = __toESM(require("p-defer"));
|
38
|
+
const pluginManifest = {
|
39
|
+
async setup(api) {
|
40
|
+
const deferredManifest = (0, import_p_defer.default)();
|
41
|
+
const deferredManifestJson = (0, import_p_defer.default)();
|
42
|
+
api.vars.useManifest = deferredManifest.promise;
|
43
|
+
api.vars.useManifestJson = deferredManifestJson.promise;
|
44
|
+
api.hooks.hook("settleState", async () => {
|
45
|
+
const routesManifestName = require.resolve("@modern-js/devtools-client/manifest");
|
46
|
+
const routesManifest = await import_utils.fs.readJSON(routesManifestName);
|
47
|
+
const manifest = {
|
48
|
+
...api.vars.state,
|
49
|
+
client: "/__devtools",
|
50
|
+
websocket: "/__devtools/rpc",
|
51
|
+
routeAssets: routesManifest.routeAssets
|
52
|
+
};
|
53
|
+
api.vars.manifest = manifest;
|
54
|
+
deferredManifest.resolve(manifest);
|
55
|
+
const stringified = JSON.stringify(manifest, (0, import_node.replacer)());
|
56
|
+
api.vars.manifestJson = stringified;
|
57
|
+
deferredManifestJson.resolve(stringified);
|
58
|
+
});
|
59
|
+
const frameworkApi = await api.setupFramework();
|
60
|
+
const outputManifest = async () => {
|
61
|
+
const { nodeModulesDirectory } = frameworkApi.useAppContext();
|
62
|
+
const name = `.cache/devtools/manifest-${(0, import_utils.nanoid)(6)}.json`;
|
63
|
+
const resolvedName = import_path.default.resolve(nodeModulesDirectory, name);
|
64
|
+
const json = await api.vars.useManifestJson;
|
65
|
+
await import_utils.fs.outputFile(resolvedName, json, "utf-8");
|
66
|
+
if (process.env.NODE_ENV === "production") {
|
67
|
+
import_utils.logger.info(`${api.context.def.name.formalName} DevTools output manifest to node_modules/${name}`);
|
68
|
+
}
|
69
|
+
};
|
70
|
+
api.frameworkHooks.hook("afterDev", outputManifest);
|
71
|
+
api.frameworkHooks.hook("afterBuild", outputManifest);
|
72
|
+
}
|
73
|
+
};
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
75
|
+
0 && (module.exports = {
|
76
|
+
pluginManifest
|
77
|
+
});
|
package/dist/plugins/rpc.js
CHANGED
@@ -31,7 +31,6 @@ __export(rpc_exports, {
|
|
31
31
|
pluginRpc: () => pluginRpc
|
32
32
|
});
|
33
33
|
module.exports = __toCommonJS(rpc_exports);
|
34
|
-
var import_assert = __toESM(require("assert"));
|
35
34
|
var import_buffer = require("buffer");
|
36
35
|
var import_path = __toESM(require("path"));
|
37
36
|
var import_node = require("@modern-js/devtools-kit/node");
|
@@ -40,90 +39,12 @@ var import_lodash = __toESM(require("@modern-js/utils/lodash"));
|
|
40
39
|
var import_birpc = require("birpc");
|
41
40
|
var flatted = __toESM(require("flatted"));
|
42
41
|
var import_valtio = require("valtio");
|
43
|
-
var import_module = require("../utils/module");
|
44
42
|
var import_socket = require("../utils/socket");
|
45
|
-
const resolveDependencies = async (rootPath) => {
|
46
|
-
const ret = {};
|
47
|
-
const resolveExprs = {
|
48
|
-
react: [
|
49
|
-
rootPath,
|
50
|
-
"react/package.json"
|
51
|
-
],
|
52
|
-
"@modern-js/app-tools": [
|
53
|
-
rootPath,
|
54
|
-
"@modern-js/app-tools/package.json"
|
55
|
-
],
|
56
|
-
"@edenx/app-tools": [
|
57
|
-
rootPath,
|
58
|
-
"@edenx/app-tools/package.json"
|
59
|
-
],
|
60
|
-
webpack: [
|
61
|
-
rootPath,
|
62
|
-
"@modern-js/app-tools",
|
63
|
-
"@modern-js/uni-builder",
|
64
|
-
"@rsbuild/webpack",
|
65
|
-
"webpack/package.json"
|
66
|
-
],
|
67
|
-
"@rspack/core": [
|
68
|
-
rootPath,
|
69
|
-
"@modern-js/uni-builder",
|
70
|
-
"@rsbuild/core",
|
71
|
-
"@rspack/core/package.json"
|
72
|
-
],
|
73
|
-
"@rsdoctor/rspack-plugin": [
|
74
|
-
rootPath,
|
75
|
-
"@rsdoctor/rspack-plugin/package.json"
|
76
|
-
],
|
77
|
-
"@rsdoctor/webpack-plugin": [
|
78
|
-
rootPath,
|
79
|
-
"@rsdoctor/webpack-plugin/package.json"
|
80
|
-
],
|
81
|
-
"@web-doctor/webpack-plugin": [
|
82
|
-
rootPath,
|
83
|
-
"@web-doctor/webpack-plugin/package.json"
|
84
|
-
],
|
85
|
-
"@web-doctor/rspack-plugin": [
|
86
|
-
rootPath,
|
87
|
-
"@web-doctor/rspack-plugin/package.json"
|
88
|
-
],
|
89
|
-
"@web-doctor/webpack-plugin(builder)": [
|
90
|
-
rootPath,
|
91
|
-
"@edenx/builder-plugin-web-doctor",
|
92
|
-
"@web-doctor/webpack-plugin/package.json"
|
93
|
-
],
|
94
|
-
"@web-doctor/rspack-plugin(builder)": [
|
95
|
-
rootPath,
|
96
|
-
"@edenx/builder-plugin-web-doctor",
|
97
|
-
"@web-doctor/rspack-plugin/package.json"
|
98
|
-
],
|
99
|
-
"@rsdoctor/core": [
|
100
|
-
rootPath,
|
101
|
-
"@rsdoctor/core/package.json"
|
102
|
-
]
|
103
|
-
};
|
104
|
-
for (const [name, expr] of Object.entries(resolveExprs)) {
|
105
|
-
try {
|
106
|
-
ret[name] = (0, import_module.requireModule)(expr).version;
|
107
|
-
} catch {
|
108
|
-
}
|
109
|
-
}
|
110
|
-
return ret;
|
111
|
-
};
|
112
|
-
const getDoctorOverview = async (ctx) => {
|
113
|
-
const manifestPath = await (0, import_node.findManifest)(ctx.distDirectory);
|
114
|
-
const json = await (0, import_node.parseManifest)(require(manifestPath));
|
115
|
-
return {
|
116
|
-
numModules: json.data.moduleGraph.modules.length,
|
117
|
-
numChunks: json.data.chunkGraph.chunks.length,
|
118
|
-
numPackages: json.data.packageGraph.packages.length,
|
119
|
-
summary: json.data.summary,
|
120
|
-
errors: json.data.errors
|
121
|
-
};
|
122
|
-
};
|
123
43
|
const pluginRpc = {
|
124
44
|
async setup(api) {
|
125
45
|
const httpServer = api.vars.http;
|
126
|
-
|
46
|
+
if (!httpServer)
|
47
|
+
return;
|
127
48
|
const server = new import_socket.SocketServer({
|
128
49
|
server: httpServer,
|
129
50
|
path: "/rpc"
|
@@ -135,86 +56,7 @@ const pluginRpc = {
|
|
135
56
|
ws.on("message", (data, isBinary) => handleMessage === null || handleMessage === void 0 ? void 0 : handleMessage(data, isBinary));
|
136
57
|
});
|
137
58
|
});
|
138
|
-
if ("resolve" in api.vars.resolver.context) {
|
139
|
-
api.vars.resolver.context.resolve(api.context);
|
140
|
-
}
|
141
|
-
api.vars.state.context = api.context;
|
142
|
-
api.frameworkHooks.hook("modifyFileSystemRoutes", ({ entrypoint, routes }) => {
|
143
|
-
api.vars.state.fileSystemRoutes[entrypoint.entryName] = import_lodash.default.cloneDeep(routes);
|
144
|
-
});
|
145
|
-
const builderApi = await api.setupBuilder();
|
146
|
-
api.vars.resolver.builder.context.resolve(builderApi.context);
|
147
|
-
resolveDependencies(builderApi.context.rootPath).then((deps) => {
|
148
|
-
api.vars.state.dependencies = deps;
|
149
|
-
});
|
150
|
-
api.builderHooks.hook("modifyBundlerChain", () => {
|
151
|
-
api.vars.resolver.builder.config.resolved.resolve(import_lodash.default.cloneDeep(builderApi.getRsbuildConfig()));
|
152
|
-
api.vars.resolver.builder.config.transformed.resolve(import_lodash.default.cloneDeep(builderApi.getNormalizedConfig()));
|
153
|
-
});
|
154
|
-
const expectBundlerNum = import_lodash.default.castArray(builderApi.context.targets).length;
|
155
|
-
const bundlerConfigs = [];
|
156
|
-
const handleBundlerConfig = (config) => {
|
157
|
-
bundlerConfigs.push(config);
|
158
|
-
if (bundlerConfigs.length >= expectBundlerNum) {
|
159
|
-
api.vars.state.bundler.configs.resolved = import_lodash.default.cloneDeep(bundlerConfigs);
|
160
|
-
}
|
161
|
-
};
|
162
|
-
if (builderApi.context.bundlerType === "webpack") {
|
163
|
-
api.builderHooks.hook("modifyWebpackConfig", (config) => {
|
164
|
-
handleBundlerConfig(config);
|
165
|
-
});
|
166
|
-
} else {
|
167
|
-
api.builderHooks.hook("modifyRspackConfig", (config) => {
|
168
|
-
handleBundlerConfig(config);
|
169
|
-
});
|
170
|
-
}
|
171
|
-
api.builderHooks.hook("onBeforeCreateCompiler", ({ bundlerConfigs: bundlerConfigs2 }) => {
|
172
|
-
api.vars.resolver.bundler.configs.transformed.resolve(import_lodash.default.cloneDeep(bundlerConfigs2));
|
173
|
-
});
|
174
|
-
let buildStartedAt = NaN;
|
175
|
-
api.builderHooks.hook("onAfterCreateCompiler", () => {
|
176
|
-
buildStartedAt = Date.now();
|
177
|
-
});
|
178
|
-
api.builderHooks.hook("onDevCompileDone", () => {
|
179
|
-
api.vars.resolver.performance.resolve({
|
180
|
-
compileDuration: Date.now() - buildStartedAt
|
181
|
-
});
|
182
|
-
});
|
183
|
-
api.builderHooks.hook("onAfterBuild", () => {
|
184
|
-
api.vars.resolver.performance.resolve({
|
185
|
-
compileDuration: Date.now() - buildStartedAt
|
186
|
-
});
|
187
|
-
});
|
188
|
-
let _pendingCompiler = 0;
|
189
|
-
const resolveRsdoctorManifest = async () => {
|
190
|
-
_pendingCompiler -= 1;
|
191
|
-
if (_pendingCompiler === 0) {
|
192
|
-
try {
|
193
|
-
const doctor = await getDoctorOverview(await api.vars.state.framework.context);
|
194
|
-
api.vars.resolver.doctor.resolve(doctor);
|
195
|
-
} catch (err) {
|
196
|
-
api.vars.resolver.doctor.resolve(void 0);
|
197
|
-
}
|
198
|
-
}
|
199
|
-
};
|
200
|
-
api.frameworkHooks.hook("afterCreateCompiler", ({ compiler }) => {
|
201
|
-
if (!compiler)
|
202
|
-
return;
|
203
|
-
_pendingCompiler += 1;
|
204
|
-
compiler.hooks.done.tap({
|
205
|
-
name: "@modern-js/plugin-devtools",
|
206
|
-
stage: 4e3
|
207
|
-
}, () => resolveRsdoctorManifest());
|
208
|
-
});
|
209
59
|
const frameworkApi = await api.setupFramework();
|
210
|
-
const frameworkContext = {
|
211
|
-
...frameworkApi.useAppContext(),
|
212
|
-
builder: null,
|
213
|
-
serverInternalPlugins: null
|
214
|
-
};
|
215
|
-
api.vars.resolver.framework.context.resolve(frameworkContext);
|
216
|
-
api.vars.resolver.framework.config.resolved.resolve(frameworkApi.useConfigContext());
|
217
|
-
api.vars.resolver.framework.config.transformed.resolve(frameworkApi.useResolvedConfigContext());
|
218
60
|
const validateSafeToOpen = (filename) => {
|
219
61
|
const { appDirectory } = frameworkApi.useAppContext();
|
220
62
|
const resolved = import_path.default.resolve(appDirectory, filename);
|
@@ -230,10 +72,12 @@ const pluginRpc = {
|
|
230
72
|
return content;
|
231
73
|
},
|
232
74
|
async pullExportedState() {
|
233
|
-
|
234
|
-
|
235
|
-
})
|
236
|
-
|
75
|
+
try {
|
76
|
+
return api.vars.state;
|
77
|
+
} catch (e) {
|
78
|
+
console.error(e);
|
79
|
+
throw e;
|
80
|
+
}
|
237
81
|
},
|
238
82
|
async createTemporaryStoragePreset() {
|
239
83
|
var _config;
|
@@ -315,10 +159,15 @@ const pluginRpc = {
|
|
315
159
|
on: (cb) => handleMessage = cb,
|
316
160
|
serialize: (v) => flatted.stringify([
|
317
161
|
v
|
318
|
-
], import_node.replacer),
|
162
|
+
], (0, import_node.replacer)()),
|
319
163
|
deserialize: (v) => {
|
320
|
-
const msg = flatted.parse(v.toString(), import_node.reviver)[0];
|
164
|
+
const msg = flatted.parse(v.toString(), (0, import_node.reviver)())[0];
|
321
165
|
return msg;
|
166
|
+
},
|
167
|
+
onError(error, functionName, args) {
|
168
|
+
const stringifiedArgs = args.map((arg) => JSON.stringify(arg)).join(", ");
|
169
|
+
console.error(new Error(`DevTools failed to execute RPC function: ${functionName}(${stringifiedArgs})`));
|
170
|
+
console.error(error);
|
322
171
|
}
|
323
172
|
};
|
324
173
|
const clientConn = (0, import_birpc.createBirpc)(serverFunctions, clientRpcOptions);
|
@@ -0,0 +1,52 @@
|
|
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 settle_exports = {};
|
20
|
+
__export(settle_exports, {
|
21
|
+
pluginSettleState: () => pluginSettleState
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(settle_exports);
|
24
|
+
const pluginSettleState = {
|
25
|
+
async setup(api) {
|
26
|
+
let _pendingCompiler = 0;
|
27
|
+
const handleSettle = async () => {
|
28
|
+
_pendingCompiler -= 1;
|
29
|
+
if (_pendingCompiler === 0) {
|
30
|
+
await api.hooks.callHook("settleState");
|
31
|
+
}
|
32
|
+
};
|
33
|
+
const handleDone = (compiler) => {
|
34
|
+
if ("compilers" in compiler) {
|
35
|
+
compiler.compilers.forEach(handleDone);
|
36
|
+
} else {
|
37
|
+
_pendingCompiler += 1;
|
38
|
+
compiler.hooks.done.tapPromise({
|
39
|
+
name: "@modern-js/plugin-devtools",
|
40
|
+
stage: 4e3
|
41
|
+
}, () => handleSettle());
|
42
|
+
}
|
43
|
+
};
|
44
|
+
api.frameworkHooks.hook("afterCreateCompiler", ({ compiler }) => {
|
45
|
+
compiler && handleDone(compiler);
|
46
|
+
});
|
47
|
+
}
|
48
|
+
};
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
50
|
+
0 && (module.exports = {
|
51
|
+
pluginSettleState
|
52
|
+
});
|
package/dist/plugins/state.d.ts
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { ServerState } from '@modern-js/devtools-kit/node';
|
2
2
|
import { Plugin } from '../types';
|
3
3
|
declare global {
|
4
4
|
interface DevtoolsPluginVars {
|
5
|
-
state:
|
6
|
-
resolver: ServerExportedStateResolvers;
|
5
|
+
state: ServerState;
|
7
6
|
}
|
8
7
|
}
|
9
8
|
export declare const pluginState: Plugin;
|
package/dist/plugins/state.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __create = Object.create;
|
2
3
|
var __defProp = Object.defineProperty;
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
8
|
var __export = (target, all) => {
|
7
9
|
for (var name in all)
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
15
17
|
}
|
16
18
|
return to;
|
17
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
|
+
));
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
29
|
var state_exports = {};
|
20
30
|
__export(state_exports, {
|
@@ -22,12 +32,166 @@ __export(state_exports, {
|
|
22
32
|
});
|
23
33
|
module.exports = __toCommonJS(state_exports);
|
24
34
|
var import_node = require("@modern-js/devtools-kit/node");
|
35
|
+
var import_lodash = __toESM(require("@modern-js/utils/lodash"));
|
25
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
|
+
};
|
26
116
|
const pluginState = {
|
27
117
|
async setup(api) {
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
+
};
|
31
195
|
}
|
32
196
|
};
|
33
197
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/plugins/watcher.js
CHANGED
@@ -43,14 +43,9 @@ const pluginWatcher = {
|
|
43
43
|
watcher.on("add", refreshStoragePreset);
|
44
44
|
watcher.on("change", refreshStoragePreset);
|
45
45
|
watcher.on("unlink", refreshStoragePreset);
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
_open = false;
|
50
|
-
};
|
51
|
-
api.frameworkHooks.hook("beforeExit", cleanup);
|
52
|
-
api.frameworkHooks.hook("beforeRestart", cleanup);
|
53
|
-
api.frameworkHooks.hook("afterBuild", cleanup);
|
46
|
+
api.hooks.hook("cleanup", () => {
|
47
|
+
watcher.close();
|
48
|
+
});
|
54
49
|
}
|
55
50
|
};
|
56
51
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/runtime.js
ADDED
@@ -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
|
+
}
|
package/dist/types/common.d.ts
CHANGED
@@ -23,7 +23,7 @@ export type BufferLike = string | Buffer | DataView | number | ArrayBufferView |
|
|
23
23
|
export type CleanHooks<T> = {
|
24
24
|
[K in keyof T]: T[K] extends (...args: [...infer Params]) => any ? (...args: [...Params]) => void : never;
|
25
25
|
};
|
26
|
-
export type $FrameworkHooks = CleanHooks<Pick<ToThreads<BaseHooks<any> & AppToolsHooks<any>>, 'prepare' | 'modifyFileSystemRoutes' | 'modifyServerRoutes' | 'afterCreateCompiler' | 'beforeRestart' | 'beforeExit' | 'afterBuild'>>;
|
26
|
+
export type $FrameworkHooks = CleanHooks<Pick<ToThreads<BaseHooks<any> & AppToolsHooks<any>>, 'prepare' | 'modifyFileSystemRoutes' | 'modifyServerRoutes' | 'afterCreateCompiler' | 'afterDev' | 'beforeRestart' | 'beforeExit' | 'afterBuild'>>;
|
27
27
|
export interface FrameworkHooks extends $FrameworkHooks {
|
28
28
|
config: () => void;
|
29
29
|
}
|
@@ -33,13 +33,18 @@ type UnwrapBuilderHooks<T> = {
|
|
33
33
|
export type $BuilderHooks = UnwrapBuilderHooks<Pick<RsbuildPluginAPI, 'modifyBundlerChain' | 'modifyWebpackConfig' | 'modifyRspackConfig' | 'onBeforeCreateCompiler' | 'onAfterCreateCompiler' | 'onDevCompileDone' | 'onAfterBuild' | 'onExit'>>;
|
34
34
|
export interface BuilderHooks extends $BuilderHooks {
|
35
35
|
}
|
36
|
+
export interface DevtoolsHooks {
|
37
|
+
cleanup: () => Promise<void> | void;
|
38
|
+
settleState: () => Promise<void> | void;
|
39
|
+
}
|
36
40
|
declare global {
|
37
41
|
interface DevtoolsPluginVars extends Record<string, unknown> {
|
38
42
|
}
|
39
43
|
}
|
40
44
|
export interface PluginApi {
|
41
|
-
frameworkHooks: Hookable<FrameworkHooks>;
|
42
45
|
builderHooks: Hookable<BuilderHooks>;
|
46
|
+
frameworkHooks: Hookable<FrameworkHooks>;
|
47
|
+
hooks: Hookable<DevtoolsHooks>;
|
43
48
|
setupFramework: () => Promise<CliPluginAPI>;
|
44
49
|
setupBuilder: () => Promise<RsbuildPluginAPI>;
|
45
50
|
context: DevtoolsContext;
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "0.0.0-nightly-
|
18
|
+
"version": "0.0.0-nightly-20240619170730",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/index.d.ts",
|
21
21
|
"main": "./dist/index.js",
|
@@ -55,9 +55,9 @@
|
|
55
55
|
"valtio": "^1.11.1",
|
56
56
|
"ws": "^8.13.0",
|
57
57
|
"hookable": "^5.5.3",
|
58
|
-
"@modern-js/devtools-
|
59
|
-
"@modern-js/
|
60
|
-
"@modern-js/
|
58
|
+
"@modern-js/devtools-client": "0.0.0-nightly-20240619170730",
|
59
|
+
"@modern-js/devtools-kit": "0.0.0-nightly-20240619170730",
|
60
|
+
"@modern-js/utils": "0.0.0-nightly-20240619170730"
|
61
61
|
},
|
62
62
|
"devDependencies": {
|
63
63
|
"@swc/helpers": "0.5.3",
|
@@ -65,18 +65,18 @@
|
|
65
65
|
"@types/ws": "^8.5.5",
|
66
66
|
"type-fest": "^4.1.0",
|
67
67
|
"typescript": "^5",
|
68
|
-
"@rsbuild/core": "0.7.
|
69
|
-
"@modern-js/app-tools": "0.0.0-nightly-
|
70
|
-
"@modern-js/core": "0.0.0-nightly-
|
71
|
-
"@modern-js/module-tools": "0.0.0-nightly-
|
72
|
-
"@modern-js/runtime": "0.0.0-nightly-
|
73
|
-
"@modern-js/
|
74
|
-
"@modern-js/
|
75
|
-
"@modern-js/uni-builder": "0.0.0-nightly-
|
76
|
-
"@scripts/build": "0.0.0-nightly-
|
68
|
+
"@rsbuild/core": "0.7.9",
|
69
|
+
"@modern-js/app-tools": "0.0.0-nightly-20240619170730",
|
70
|
+
"@modern-js/core": "0.0.0-nightly-20240619170730",
|
71
|
+
"@modern-js/module-tools": "0.0.0-nightly-20240619170730",
|
72
|
+
"@modern-js/runtime": "0.0.0-nightly-20240619170730",
|
73
|
+
"@modern-js/server-core": "0.0.0-nightly-20240619170730",
|
74
|
+
"@modern-js/types": "0.0.0-nightly-20240619170730",
|
75
|
+
"@modern-js/uni-builder": "0.0.0-nightly-20240619170730",
|
76
|
+
"@scripts/build": "0.0.0-nightly-20240619170730"
|
77
77
|
},
|
78
78
|
"peerDependencies": {
|
79
|
-
"@modern-js/runtime": "0.0.0-nightly-
|
79
|
+
"@modern-js/runtime": "0.0.0-nightly-20240619170730"
|
80
80
|
},
|
81
81
|
"peerDependenciesMeta": {
|
82
82
|
"@modern-js/runtime": {
|