@modern-js/plugin-devtools 0.0.0-next-20240617070535 → 0.0.0-next-20240617090621
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 +3 -1
- package/dist/cli.js +101 -216
- package/dist/plugins/debug.d.ts +2 -0
- package/dist/plugins/debug.js +45 -0
- package/dist/plugins/html.d.ts +2 -0
- package/dist/plugins/html.js +102 -0
- package/dist/plugins/http.d.ts +9 -0
- package/dist/plugins/http.js +151 -0
- package/dist/plugins/rpc.d.ts +9 -0
- package/dist/plugins/rpc.js +333 -0
- package/dist/plugins/service-worker.d.ts +2 -0
- package/dist/plugins/service-worker.js +63 -0
- package/dist/plugins/state.d.ts +9 -0
- package/dist/{state.js → plugins/state.js} +10 -10
- package/dist/plugins/watcher.d.ts +2 -0
- package/dist/plugins/watcher.js +59 -0
- package/dist/types/common.d.ts +32 -2
- package/package.json +16 -14
- package/dist/rpc/index.d.ts +0 -14
- package/dist/rpc/index.js +0 -341
- package/dist/state.d.ts +0 -4
|
@@ -0,0 +1,151 @@
|
|
|
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 app = new import_hono.Hono();
|
|
45
|
+
app.all("/api/cookies", async (c) => {
|
|
46
|
+
const raw = c.req.header("Cookie");
|
|
47
|
+
const { parse } = await import("cookie-es");
|
|
48
|
+
const cookies = raw ? parse(raw) : {};
|
|
49
|
+
const body = await c.req.json().catch(() => null);
|
|
50
|
+
if (body === null || body === void 0 ? void 0 : body.setCookies) {
|
|
51
|
+
const { setCookies } = body;
|
|
52
|
+
(0, import_assert.default)(typeof setCookies === "object", "setCookies should be object");
|
|
53
|
+
for (const [k, v] of Object.entries(setCookies)) {
|
|
54
|
+
(0, import_assert.default)(typeof v === "string");
|
|
55
|
+
const expires = new Date(Date.now() + 30 * 24 * 36e5).toUTCString();
|
|
56
|
+
cookies[k] = v;
|
|
57
|
+
c.header("Set-Cookie", `${k}=${v}; Expires=${expires}; Path=/`, {
|
|
58
|
+
append: true
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return c.json({
|
|
63
|
+
cookies
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
app.use(
|
|
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) => {
|
|
74
|
+
if (process.env.NODE_ENV !== "development") {
|
|
75
|
+
return c.text("Not found", 404);
|
|
76
|
+
}
|
|
77
|
+
const filename = c.req.param("filename");
|
|
78
|
+
const target = new import_url.URL(filename, "http://127.0.0.1:8780");
|
|
79
|
+
const { body, headers, status } = await fetch(target.href);
|
|
80
|
+
const newResp = c.newResponse(body, {
|
|
81
|
+
headers,
|
|
82
|
+
status
|
|
83
|
+
});
|
|
84
|
+
if (newResp.headers.get("content-encoding") === "gzip") {
|
|
85
|
+
newResp.headers.delete("content-encoding");
|
|
86
|
+
}
|
|
87
|
+
return newResp;
|
|
88
|
+
});
|
|
89
|
+
app.get("*", async (c) => {
|
|
90
|
+
const filename = import_path.default.resolve(CLIENT_SERVE_DIR, "html/client/index.html");
|
|
91
|
+
const content = await import_utils.fs.readFile(filename, "utf-8");
|
|
92
|
+
return c.html(content);
|
|
93
|
+
});
|
|
94
|
+
const pluginHttp = {
|
|
95
|
+
async setup(api) {
|
|
96
|
+
if (process.env.NODE_ENV === "production")
|
|
97
|
+
return;
|
|
98
|
+
const server = (0, import_node_server.createAdaptorServer)({
|
|
99
|
+
fetch: app.fetch,
|
|
100
|
+
hostname: "127.0.0.1",
|
|
101
|
+
serverOptions: {
|
|
102
|
+
allowHTTP1: true
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
(0, import_assert.default)(server instanceof import_http.default.Server, "instance should be http.Server");
|
|
106
|
+
api.vars.http = server;
|
|
107
|
+
api.frameworkHooks.hook("config", async () => {
|
|
108
|
+
const port = await (0, import_utils.getPort)(8782, {
|
|
109
|
+
slient: true
|
|
110
|
+
});
|
|
111
|
+
server.listen(port);
|
|
112
|
+
const proxy = {
|
|
113
|
+
[import_node.ROUTE_BASENAME]: {
|
|
114
|
+
target: `http://127.0.0.1:${port}`,
|
|
115
|
+
pathRewrite: {
|
|
116
|
+
[`^${import_node.ROUTE_BASENAME}`]: ""
|
|
117
|
+
},
|
|
118
|
+
ws: true,
|
|
119
|
+
onProxyReq(proxyReq, req) {
|
|
120
|
+
const addrInfo = req.socket.address();
|
|
121
|
+
if ("address" in addrInfo) {
|
|
122
|
+
const { address } = addrInfo;
|
|
123
|
+
proxyReq.setHeader("X-Forwarded-For", address);
|
|
124
|
+
} else {
|
|
125
|
+
proxyReq.removeHeader("X-Forwarded-For");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
tools: {
|
|
132
|
+
devServer: {
|
|
133
|
+
proxy
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
let _open = true;
|
|
139
|
+
const cleanup = () => {
|
|
140
|
+
_open && server.close();
|
|
141
|
+
_open = false;
|
|
142
|
+
};
|
|
143
|
+
api.frameworkHooks.hook("beforeExit", cleanup);
|
|
144
|
+
api.frameworkHooks.hook("beforeRestart", cleanup);
|
|
145
|
+
api.frameworkHooks.hook("afterBuild", cleanup);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
149
|
+
0 && (module.exports = {
|
|
150
|
+
pluginHttp
|
|
151
|
+
});
|
|
@@ -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,333 @@
|
|
|
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_assert = __toESM(require("assert"));
|
|
35
|
+
var import_buffer = require("buffer");
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_node = require("@modern-js/devtools-kit/node");
|
|
38
|
+
var import_utils = require("@modern-js/utils");
|
|
39
|
+
var import_lodash = __toESM(require("@modern-js/utils/lodash"));
|
|
40
|
+
var import_birpc = require("birpc");
|
|
41
|
+
var flatted = __toESM(require("flatted"));
|
|
42
|
+
var import_valtio = require("valtio");
|
|
43
|
+
var import_module = require("../utils/module");
|
|
44
|
+
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
|
+
const pluginRpc = {
|
|
124
|
+
async setup(api) {
|
|
125
|
+
const httpServer = api.vars.http;
|
|
126
|
+
(0, import_assert.default)(httpServer, "http server is required for rpc plugin");
|
|
127
|
+
const server = new import_socket.SocketServer({
|
|
128
|
+
server: httpServer,
|
|
129
|
+
path: "/rpc"
|
|
130
|
+
});
|
|
131
|
+
let handleMessage = null;
|
|
132
|
+
const onceConnection = new Promise((resolve) => {
|
|
133
|
+
server.on("connection", (ws) => {
|
|
134
|
+
resolve();
|
|
135
|
+
ws.on("message", (data, isBinary) => handleMessage === null || handleMessage === void 0 ? void 0 : handleMessage(data, isBinary));
|
|
136
|
+
});
|
|
137
|
+
});
|
|
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
|
+
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
|
+
const validateSafeToOpen = (filename) => {
|
|
219
|
+
const { appDirectory } = frameworkApi.useAppContext();
|
|
220
|
+
const resolved = import_path.default.resolve(appDirectory, filename);
|
|
221
|
+
for (const preset of api.context.storagePresets) {
|
|
222
|
+
if (import_path.default.resolve(appDirectory, preset.filename) === resolved) {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return false;
|
|
227
|
+
};
|
|
228
|
+
const serverFunctions = {
|
|
229
|
+
echo(content) {
|
|
230
|
+
return content;
|
|
231
|
+
},
|
|
232
|
+
async pullExportedState() {
|
|
233
|
+
(0, import_node.extractSettledOperations)(api.vars.state).then((ops) => {
|
|
234
|
+
clientConn.applyStateOperations.asEvent(ops);
|
|
235
|
+
});
|
|
236
|
+
return api.vars.state;
|
|
237
|
+
},
|
|
238
|
+
async createTemporaryStoragePreset() {
|
|
239
|
+
var _config;
|
|
240
|
+
const appCtx = frameworkApi.useAppContext();
|
|
241
|
+
const basename = `${api.context.def.name.shortName}.runtime.json`;
|
|
242
|
+
const filename = import_path.default.resolve(appCtx.appDirectory, basename);
|
|
243
|
+
const id = (0, import_utils.nanoid)();
|
|
244
|
+
const name = `New Preset ${id.slice(0, 6)}`;
|
|
245
|
+
const config = {};
|
|
246
|
+
if (await import_utils.fs.pathExists(filename)) {
|
|
247
|
+
Object.assign(config, await import_utils.fs.readJSON(filename));
|
|
248
|
+
}
|
|
249
|
+
const newPreset = {
|
|
250
|
+
name,
|
|
251
|
+
id,
|
|
252
|
+
cookie: {},
|
|
253
|
+
localStorage: {},
|
|
254
|
+
sessionStorage: {}
|
|
255
|
+
};
|
|
256
|
+
(_config = config).storagePresets || (_config.storagePresets = []);
|
|
257
|
+
config.storagePresets.push(newPreset);
|
|
258
|
+
await import_utils.fs.outputJSON(filename, config, {
|
|
259
|
+
spaces: 2
|
|
260
|
+
});
|
|
261
|
+
return newPreset;
|
|
262
|
+
},
|
|
263
|
+
async pasteStoragePreset(target) {
|
|
264
|
+
var _config;
|
|
265
|
+
const { default: clipboardy } = await import("clipboardy");
|
|
266
|
+
const raw = clipboardy.readSync();
|
|
267
|
+
const HEAD = `data:application/json;base64,`;
|
|
268
|
+
if (!raw.startsWith(HEAD)) {
|
|
269
|
+
throw new Error("Failed to parse data URL");
|
|
270
|
+
}
|
|
271
|
+
const encoded = raw.slice(HEAD.length);
|
|
272
|
+
const preset = JSON.parse(import_buffer.Buffer.from(encoded, "base64").toString("utf-8"));
|
|
273
|
+
if (typeof preset !== "object" || preset === null) {
|
|
274
|
+
throw new Error("Failed to parse data URL");
|
|
275
|
+
}
|
|
276
|
+
if (typeof preset.name !== "string") {
|
|
277
|
+
throw new Error("Failed to parse data URL");
|
|
278
|
+
}
|
|
279
|
+
const appCtx = frameworkApi.useAppContext();
|
|
280
|
+
const filename = import_path.default.resolve(appCtx.appDirectory, target.filename);
|
|
281
|
+
const config = {};
|
|
282
|
+
if (await import_utils.fs.pathExists(filename)) {
|
|
283
|
+
Object.assign(config, await import_utils.fs.readJSON(filename));
|
|
284
|
+
}
|
|
285
|
+
(_config = config).storagePresets || (_config.storagePresets = []);
|
|
286
|
+
const diff = import_lodash.default.pick(preset, [
|
|
287
|
+
"cookie",
|
|
288
|
+
"localStorage",
|
|
289
|
+
"sessionStorage"
|
|
290
|
+
]);
|
|
291
|
+
const matched = import_lodash.default.find(config.storagePresets, {
|
|
292
|
+
id: target.id
|
|
293
|
+
});
|
|
294
|
+
if (matched) {
|
|
295
|
+
import_lodash.default.merge(matched, diff);
|
|
296
|
+
} else {
|
|
297
|
+
config.storagePresets.push(preset);
|
|
298
|
+
}
|
|
299
|
+
await import_utils.fs.outputJSON(filename, config, {
|
|
300
|
+
spaces: 2
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
async open(filename) {
|
|
304
|
+
const name = import_path.default.resolve(frameworkApi.useAppContext().appDirectory, filename);
|
|
305
|
+
const validated = validateSafeToOpen(name);
|
|
306
|
+
if (!validated) {
|
|
307
|
+
throw new Error("Failed to validate the file.");
|
|
308
|
+
}
|
|
309
|
+
const { default: open } = await import("open");
|
|
310
|
+
await open(name);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
const clientRpcOptions = {
|
|
314
|
+
post: (data) => onceConnection.then(() => server.clients.forEach((ws) => ws.send(data))),
|
|
315
|
+
on: (cb) => handleMessage = cb,
|
|
316
|
+
serialize: (v) => flatted.stringify([
|
|
317
|
+
v
|
|
318
|
+
], import_node.replacer),
|
|
319
|
+
deserialize: (v) => {
|
|
320
|
+
const msg = flatted.parse(v.toString(), import_node.reviver)[0];
|
|
321
|
+
return msg;
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
const clientConn = (0, import_birpc.createBirpc)(serverFunctions, clientRpcOptions);
|
|
325
|
+
(0, import_valtio.subscribe)(api.vars.state, (ops) => {
|
|
326
|
+
clientConn.applyStateOperations.asEvent(ops);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
331
|
+
0 && (module.exports = {
|
|
332
|
+
pluginRpc
|
|
333
|
+
});
|
|
@@ -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,9 @@
|
|
|
1
|
+
import { ServerExportedState, ServerExportedStateResolvers } from '@modern-js/devtools-kit/node';
|
|
2
|
+
import { Plugin } from '../types';
|
|
3
|
+
declare global {
|
|
4
|
+
interface DevtoolsPluginVars {
|
|
5
|
+
state: ServerExportedState;
|
|
6
|
+
resolver: ServerExportedStateResolvers;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare const pluginState: Plugin;
|
|
@@ -18,19 +18,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var state_exports = {};
|
|
20
20
|
__export(state_exports, {
|
|
21
|
-
|
|
22
|
-
$serverExportedState: () => $serverExportedState,
|
|
23
|
-
$state: () => $state
|
|
21
|
+
pluginState: () => pluginState
|
|
24
22
|
});
|
|
25
23
|
module.exports = __toCommonJS(state_exports);
|
|
26
|
-
var import_valtio = require("valtio");
|
|
27
24
|
var import_node = require("@modern-js/devtools-kit/node");
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
25
|
+
var import_valtio = require("valtio");
|
|
26
|
+
const pluginState = {
|
|
27
|
+
async setup(api) {
|
|
28
|
+
const $serverExportedState = (0, import_node.createServerExportedState)();
|
|
29
|
+
api.vars.state = (0, import_valtio.proxy)($serverExportedState.state);
|
|
30
|
+
api.vars.resolver = $serverExportedState.resolvers;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
31
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
34
|
0 && (module.exports = {
|
|
33
|
-
|
|
34
|
-
$serverExportedState,
|
|
35
|
-
$state
|
|
35
|
+
pluginState
|
|
36
36
|
});
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
let _open = true;
|
|
47
|
+
const cleanup = () => {
|
|
48
|
+
_open && watcher.close();
|
|
49
|
+
_open = false;
|
|
50
|
+
};
|
|
51
|
+
api.frameworkHooks.hook("beforeExit", cleanup);
|
|
52
|
+
api.frameworkHooks.hook("beforeRestart", cleanup);
|
|
53
|
+
api.frameworkHooks.hook("afterBuild", cleanup);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
pluginWatcher
|
|
59
|
+
});
|