@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,155 @@
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 http_exports = {};
30
+ __export(http_exports, {
31
+ pluginHttp: () => pluginHttp
32
+ });
33
+ module.exports = __toCommonJS(http_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_assert = __toESM(require("assert"));
36
+ var import_http = __toESM(require("http"));
37
+ var import_url = require("url");
38
+ var import_hono = require("hono");
39
+ var import_utils = require("@modern-js/utils");
40
+ var import_node_server = require("@hono/node-server");
41
+ var import_serve_static = require("@hono/node-server/serve-static");
42
+ var import_node = require("@modern-js/devtools-kit/node");
43
+ const CLIENT_SERVE_DIR = import_path.default.resolve(require.resolve("@modern-js/devtools-client/package.json"), "../dist");
44
+ const cookiesServiceHandler = async (c) => {
45
+ const raw = c.req.header("Cookie");
46
+ const { parse } = await import("cookie-es");
47
+ const cookies = raw ? parse(raw) : {};
48
+ const body = await c.req.json().catch(() => null);
49
+ if (body === null || body === void 0 ? void 0 : body.setCookies) {
50
+ const { setCookies } = body;
51
+ (0, import_assert.default)(typeof setCookies === "object", "setCookies should be object");
52
+ for (const [k, v] of Object.entries(setCookies)) {
53
+ (0, import_assert.default)(typeof v === "string");
54
+ const expires = new Date(Date.now() + 30 * 24 * 36e5).toUTCString();
55
+ cookies[k] = v;
56
+ c.header("Set-Cookie", `${k}=${v}; Expires=${expires}; Path=/`, {
57
+ append: true
58
+ });
59
+ }
60
+ }
61
+ return c.json({
62
+ cookies
63
+ });
64
+ };
65
+ const hotUpdateHandler = async (c) => {
66
+ if (process.env.NODE_ENV !== "development") {
67
+ return c.text("Not found", 404);
68
+ }
69
+ const filename = c.req.param("filename");
70
+ const target = new import_url.URL(filename, "http://127.0.0.1:8780");
71
+ const { body, headers, status } = await fetch(target.href);
72
+ const newResp = c.newResponse(body, {
73
+ headers,
74
+ status
75
+ });
76
+ if (newResp.headers.get("content-encoding") === "gzip") {
77
+ newResp.headers.delete("content-encoding");
78
+ }
79
+ return newResp;
80
+ };
81
+ const fallbackHtmlHandler = async (c) => {
82
+ const filename = import_path.default.resolve(CLIENT_SERVE_DIR, "html/client/index.html");
83
+ const content = await import_utils.fs.readFile(filename, "utf-8");
84
+ return c.html(content);
85
+ };
86
+ const pluginHttp = {
87
+ async setup(api) {
88
+ if (process.env.NODE_ENV === "production")
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);
107
+ const server = (0, import_node_server.createAdaptorServer)({
108
+ fetch: app.fetch,
109
+ hostname: "127.0.0.1",
110
+ serverOptions: {
111
+ allowHTTP1: true
112
+ }
113
+ });
114
+ (0, import_assert.default)(server instanceof import_http.default.Server, "instance should be http.Server");
115
+ api.vars.http = server;
116
+ api.frameworkHooks.hook("config", async () => {
117
+ const port = await (0, import_utils.getPort)(8782, {
118
+ slient: true
119
+ });
120
+ server.listen(port);
121
+ const proxy = {
122
+ [import_node.ROUTE_BASENAME]: {
123
+ target: `http://127.0.0.1:${port}`,
124
+ pathRewrite: {
125
+ [`^${import_node.ROUTE_BASENAME}`]: ""
126
+ },
127
+ ws: true,
128
+ onProxyReq(proxyReq, req) {
129
+ const addrInfo = req.socket.address();
130
+ if ("address" in addrInfo) {
131
+ const { address } = addrInfo;
132
+ proxyReq.setHeader("X-Forwarded-For", address);
133
+ } else {
134
+ proxyReq.removeHeader("X-Forwarded-For");
135
+ }
136
+ }
137
+ }
138
+ };
139
+ return {
140
+ tools: {
141
+ devServer: {
142
+ proxy
143
+ }
144
+ }
145
+ };
146
+ });
147
+ api.hooks.hook("cleanup", () => {
148
+ server.close();
149
+ });
150
+ }
151
+ };
152
+ // Annotate the CommonJS export names for ESM import in node:
153
+ 0 && (module.exports = {
154
+ pluginHttp
155
+ });
@@ -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
+ });
@@ -0,0 +1,9 @@
1
+ import { DevtoolsContext } from '@modern-js/devtools-kit/node';
2
+ import { CliPluginAPI, Plugin } from '../types';
3
+ import { SocketServer } from '../utils/socket';
4
+ export interface SetupClientConnectionOptions {
5
+ api: CliPluginAPI;
6
+ server: SocketServer;
7
+ ctx: DevtoolsContext;
8
+ }
9
+ export declare const pluginRpc: Plugin;
@@ -0,0 +1,182 @@
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 rpc_exports = {};
30
+ __export(rpc_exports, {
31
+ pluginRpc: () => pluginRpc
32
+ });
33
+ module.exports = __toCommonJS(rpc_exports);
34
+ var import_buffer = require("buffer");
35
+ var import_path = __toESM(require("path"));
36
+ var import_node = require("@modern-js/devtools-kit/node");
37
+ var import_utils = require("@modern-js/utils");
38
+ var import_lodash = __toESM(require("@modern-js/utils/lodash"));
39
+ var import_birpc = require("birpc");
40
+ var flatted = __toESM(require("flatted"));
41
+ var import_valtio = require("valtio");
42
+ var import_socket = require("../utils/socket");
43
+ const pluginRpc = {
44
+ async setup(api) {
45
+ const httpServer = api.vars.http;
46
+ if (!httpServer)
47
+ return;
48
+ const server = new import_socket.SocketServer({
49
+ server: httpServer,
50
+ path: "/rpc"
51
+ });
52
+ let handleMessage = null;
53
+ const onceConnection = new Promise((resolve) => {
54
+ server.on("connection", (ws) => {
55
+ resolve();
56
+ ws.on("message", (data, isBinary) => handleMessage === null || handleMessage === void 0 ? void 0 : handleMessage(data, isBinary));
57
+ });
58
+ });
59
+ const frameworkApi = await api.setupFramework();
60
+ const validateSafeToOpen = (filename) => {
61
+ const { appDirectory } = frameworkApi.useAppContext();
62
+ const resolved = import_path.default.resolve(appDirectory, filename);
63
+ for (const preset of api.context.storagePresets) {
64
+ if (import_path.default.resolve(appDirectory, preset.filename) === resolved) {
65
+ return true;
66
+ }
67
+ }
68
+ return false;
69
+ };
70
+ const serverFunctions = {
71
+ echo(content) {
72
+ return content;
73
+ },
74
+ async pullExportedState() {
75
+ try {
76
+ return api.vars.state;
77
+ } catch (e) {
78
+ console.error(e);
79
+ throw e;
80
+ }
81
+ },
82
+ async createTemporaryStoragePreset() {
83
+ var _config;
84
+ const appCtx = frameworkApi.useAppContext();
85
+ const basename = `${api.context.def.name.shortName}.runtime.json`;
86
+ const filename = import_path.default.resolve(appCtx.appDirectory, basename);
87
+ const id = (0, import_utils.nanoid)();
88
+ const name = `New Preset ${id.slice(0, 6)}`;
89
+ const config = {};
90
+ if (await import_utils.fs.pathExists(filename)) {
91
+ Object.assign(config, await import_utils.fs.readJSON(filename));
92
+ }
93
+ const newPreset = {
94
+ name,
95
+ id,
96
+ cookie: {},
97
+ localStorage: {},
98
+ sessionStorage: {}
99
+ };
100
+ (_config = config).storagePresets || (_config.storagePresets = []);
101
+ config.storagePresets.push(newPreset);
102
+ await import_utils.fs.outputJSON(filename, config, {
103
+ spaces: 2
104
+ });
105
+ return newPreset;
106
+ },
107
+ async pasteStoragePreset(target) {
108
+ var _config;
109
+ const { default: clipboardy } = await import("clipboardy");
110
+ const raw = clipboardy.readSync();
111
+ const HEAD = `data:application/json;base64,`;
112
+ if (!raw.startsWith(HEAD)) {
113
+ throw new Error("Failed to parse data URL");
114
+ }
115
+ const encoded = raw.slice(HEAD.length);
116
+ const preset = JSON.parse(import_buffer.Buffer.from(encoded, "base64").toString("utf-8"));
117
+ if (typeof preset !== "object" || preset === null) {
118
+ throw new Error("Failed to parse data URL");
119
+ }
120
+ if (typeof preset.name !== "string") {
121
+ throw new Error("Failed to parse data URL");
122
+ }
123
+ const appCtx = frameworkApi.useAppContext();
124
+ const filename = import_path.default.resolve(appCtx.appDirectory, target.filename);
125
+ const config = {};
126
+ if (await import_utils.fs.pathExists(filename)) {
127
+ Object.assign(config, await import_utils.fs.readJSON(filename));
128
+ }
129
+ (_config = config).storagePresets || (_config.storagePresets = []);
130
+ const diff = import_lodash.default.pick(preset, [
131
+ "cookie",
132
+ "localStorage",
133
+ "sessionStorage"
134
+ ]);
135
+ const matched = import_lodash.default.find(config.storagePresets, {
136
+ id: target.id
137
+ });
138
+ if (matched) {
139
+ import_lodash.default.merge(matched, diff);
140
+ } else {
141
+ config.storagePresets.push(preset);
142
+ }
143
+ await import_utils.fs.outputJSON(filename, config, {
144
+ spaces: 2
145
+ });
146
+ },
147
+ async open(filename) {
148
+ const name = import_path.default.resolve(frameworkApi.useAppContext().appDirectory, filename);
149
+ const validated = validateSafeToOpen(name);
150
+ if (!validated) {
151
+ throw new Error("Failed to validate the file.");
152
+ }
153
+ const { default: open } = await import("open");
154
+ await open(name);
155
+ }
156
+ };
157
+ const clientRpcOptions = {
158
+ post: (data) => onceConnection.then(() => server.clients.forEach((ws) => ws.send(data))),
159
+ on: (cb) => handleMessage = cb,
160
+ serialize: (v) => flatted.stringify([
161
+ v
162
+ ], (0, import_node.replacer)()),
163
+ deserialize: (v) => {
164
+ const msg = flatted.parse(v.toString(), (0, import_node.reviver)())[0];
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);
171
+ }
172
+ };
173
+ const clientConn = (0, import_birpc.createBirpc)(serverFunctions, clientRpcOptions);
174
+ (0, import_valtio.subscribe)(api.vars.state, (ops) => {
175
+ clientConn.applyStateOperations.asEvent(ops);
176
+ });
177
+ }
178
+ };
179
+ // Annotate the CommonJS export names for ESM import in node:
180
+ 0 && (module.exports = {
181
+ pluginRpc
182
+ });
@@ -0,0 +1,2 @@
1
+ import { Plugin } from '../types';
2
+ export declare const pluginServiceWorker: Plugin;
@@ -0,0 +1,63 @@
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 service_worker_exports = {};
30
+ __export(service_worker_exports, {
31
+ pluginServiceWorker: () => pluginServiceWorker
32
+ });
33
+ module.exports = __toCommonJS(service_worker_exports);
34
+ const pluginServiceWorker = {
35
+ async setup(api) {
36
+ api.frameworkHooks.hook("modifyServerRoutes", ({ routes }) => {
37
+ routes.push({
38
+ urlPath: "/sw-proxy.js",
39
+ isSPA: true,
40
+ isSSR: false,
41
+ entryPath: "public/sw-proxy.js"
42
+ });
43
+ });
44
+ api.frameworkHooks.hook("config", async () => {
45
+ const swProxyEntry = require.resolve("@modern-js/devtools-client/sw-proxy");
46
+ const config = {
47
+ output: {
48
+ copy: [
49
+ {
50
+ from: swProxyEntry,
51
+ to: "public"
52
+ }
53
+ ]
54
+ }
55
+ };
56
+ return config;
57
+ });
58
+ }
59
+ };
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ pluginServiceWorker
63
+ });
@@ -0,0 +1,2 @@
1
+ import { Plugin } from '../types';
2
+ export declare const pluginSettleState: Plugin;
@@ -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
+ });
@@ -0,0 +1,8 @@
1
+ import { ServerState } from '@modern-js/devtools-kit/node';
2
+ import { Plugin } from '../types';
3
+ declare global {
4
+ interface DevtoolsPluginVars {
5
+ state: ServerState;
6
+ }
7
+ }
8
+ export declare const pluginState: Plugin;