@modern-js/plugin-devtools 0.0.0-next-20240522095407 → 0.0.0-next-20240522113137
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 +1 -1
- package/dist/cli.js +26 -125
- package/dist/config.d.ts +11 -0
- package/dist/{options.js → config.js} +9 -13
- package/dist/rpc/index.d.ts +2 -2
- package/dist/rpc/index.js +151 -205
- package/package.json +16 -20
- package/dist/options.d.ts +0 -8
- package/dist/state.d.ts +0 -4
- package/dist/state.js +0 -36
- package/dist/types/common.js +0 -16
- package/dist/types/config.d.ts +0 -4
- package/dist/types/config.js +0 -16
- package/dist/types/index.d.ts +0 -2
- package/dist/utils/config.d.ts +0 -8
- package/dist/utils/config.js +0 -111
- /package/dist/{types/common.d.ts → types.d.ts} +0 -0
- /package/dist/{types/index.js → types.js} +0 -0
package/dist/cli.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AppTools, CliPlugin } from '@modern-js/app-tools';
|
|
2
2
|
import { ClientDefinition } from '@modern-js/devtools-kit/node';
|
|
3
|
-
import { DevtoolsPluginOptions } from './
|
|
3
|
+
import { DevtoolsPluginOptions } from './config';
|
|
4
4
|
export type { DevtoolsPluginOptions };
|
|
5
5
|
export type DevtoolsPlugin = CliPlugin<AppTools> & {
|
|
6
6
|
setClientDefinition: (def: ClientDefinition) => void;
|
package/dist/cli.js
CHANGED
|
@@ -35,27 +35,14 @@ module.exports = __toCommonJS(cli_exports);
|
|
|
35
35
|
var import_http = __toESM(require("http"));
|
|
36
36
|
var import_path = __toESM(require("path"));
|
|
37
37
|
var import_assert = __toESM(require("assert"));
|
|
38
|
-
var import_url = require("url");
|
|
39
|
-
var import_lodash = __toESM(require("@modern-js/utils/lodash"));
|
|
40
38
|
var import_utils = require("@modern-js/utils");
|
|
41
|
-
var
|
|
42
|
-
var import_node_server = require("@hono/node-server");
|
|
43
|
-
var import_serve_static = require("@hono/node-server/serve-static");
|
|
39
|
+
var import_serve_static = __toESM(require("serve-static"));
|
|
44
40
|
var import_node = require("@modern-js/devtools-kit/node");
|
|
45
|
-
var
|
|
46
|
-
var import_options = require("./options");
|
|
41
|
+
var import_config = require("./config");
|
|
47
42
|
var import_rpc = require("./rpc");
|
|
48
43
|
var import_socket = require("./utils/socket");
|
|
49
|
-
var import_config = require("./utils/config");
|
|
50
44
|
const devtoolsPlugin = (inlineOptions = {}) => {
|
|
51
|
-
const ctx = (0,
|
|
52
|
-
let watcher = null;
|
|
53
|
-
const closeWatcher = () => {
|
|
54
|
-
if (!watcher)
|
|
55
|
-
return;
|
|
56
|
-
watcher.close();
|
|
57
|
-
watcher = null;
|
|
58
|
-
};
|
|
45
|
+
const ctx = (0, import_config.resolveContext)(inlineOptions);
|
|
59
46
|
return {
|
|
60
47
|
name: "@modern-js/plugin-devtools",
|
|
61
48
|
usePlugins: [],
|
|
@@ -72,40 +59,15 @@ const devtoolsPlugin = (inlineOptions = {}) => {
|
|
|
72
59
|
});
|
|
73
60
|
const rpc = await (0, import_rpc.setupClientConnection)({
|
|
74
61
|
api,
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
server: socketServer,
|
|
63
|
+
def: ctx.def
|
|
77
64
|
});
|
|
78
65
|
return {
|
|
79
|
-
|
|
80
|
-
await rpc.hooks.prepare();
|
|
81
|
-
const appConfig = api.useConfigContext();
|
|
82
|
-
const appCtx = api.useAppContext();
|
|
83
|
-
const { devtools: options = {} } = appConfig;
|
|
84
|
-
(0, import_options.updateContext)(ctx, options);
|
|
85
|
-
const basename = `${ctx.def.name.shortName}.runtime.json`;
|
|
86
|
-
const watcher2 = import_utils.chokidar.watch((0, import_config.getConfigFilenames)(basename), {
|
|
87
|
-
cwd: appCtx.appDirectory,
|
|
88
|
-
ignorePermissionErrors: true
|
|
89
|
-
});
|
|
90
|
-
const refreshStoragePreset = async () => {
|
|
91
|
-
const configs = await (0, import_config.loadConfigFiles)(basename, appCtx.appDirectory);
|
|
92
|
-
if (!configs)
|
|
93
|
-
return;
|
|
94
|
-
ctx.storagePresets = [];
|
|
95
|
-
(0, import_options.updateContext)(ctx, ...configs);
|
|
96
|
-
};
|
|
97
|
-
watcher2.on("add", refreshStoragePreset);
|
|
98
|
-
watcher2.on("change", refreshStoragePreset);
|
|
99
|
-
watcher2.on("unlink", refreshStoragePreset);
|
|
100
|
-
},
|
|
66
|
+
prepare: rpc.hooks.prepare,
|
|
101
67
|
modifyFileSystemRoutes: rpc.hooks.modifyFileSystemRoutes,
|
|
102
68
|
beforeRestart() {
|
|
103
|
-
closeWatcher();
|
|
104
69
|
return new Promise((resolve, reject) => httpServer.instance.close((err) => err ? reject(err) : resolve()));
|
|
105
70
|
},
|
|
106
|
-
beforeExit() {
|
|
107
|
-
closeWatcher();
|
|
108
|
-
},
|
|
109
71
|
modifyServerRoutes({ routes }) {
|
|
110
72
|
routes.push({
|
|
111
73
|
urlPath: "/sw-proxy.js",
|
|
@@ -117,18 +79,13 @@ const devtoolsPlugin = (inlineOptions = {}) => {
|
|
|
117
79
|
routes
|
|
118
80
|
};
|
|
119
81
|
},
|
|
120
|
-
|
|
82
|
+
config() {
|
|
83
|
+
var _api_useConfigContext_devtools;
|
|
84
|
+
const config = (_api_useConfigContext_devtools = api.useConfigContext().devtools) !== null && _api_useConfigContext_devtools !== void 0 ? _api_useConfigContext_devtools : {};
|
|
85
|
+
Object.assign(ctx, (0, import_config.resolveContext)(ctx, config));
|
|
121
86
|
import_utils.logger.info(`${ctx.def.name.formalName} DevTools is enabled`);
|
|
122
87
|
const swProxyEntry = require.resolve("@modern-js/devtools-client/sw-proxy");
|
|
123
|
-
const
|
|
124
|
-
"def",
|
|
125
|
-
"endpoint",
|
|
126
|
-
"dataSource"
|
|
127
|
-
]);
|
|
128
|
-
Object.assign(clientOptions, {
|
|
129
|
-
__keep: true
|
|
130
|
-
});
|
|
131
|
-
const serializedOptions = JSON.stringify(clientOptions);
|
|
88
|
+
const serializedOptions = JSON.stringify(ctx);
|
|
132
89
|
const tags = [
|
|
133
90
|
{
|
|
134
91
|
tag: "script",
|
|
@@ -183,20 +140,11 @@ const devtoolsPlugin = (inlineOptions = {}) => {
|
|
|
183
140
|
devServer: {
|
|
184
141
|
proxy: {
|
|
185
142
|
[import_node.ROUTE_BASENAME]: {
|
|
186
|
-
target: `http://
|
|
143
|
+
target: `http://localhost:${httpServer.port}`,
|
|
187
144
|
pathRewrite: {
|
|
188
145
|
[`^${import_node.ROUTE_BASENAME}`]: ""
|
|
189
146
|
},
|
|
190
|
-
ws: true
|
|
191
|
-
onProxyReq(proxyReq, req) {
|
|
192
|
-
const addrInfo = req.socket.address();
|
|
193
|
-
if ("address" in addrInfo) {
|
|
194
|
-
const { address } = addrInfo;
|
|
195
|
-
proxyReq.setHeader("X-Forwarded-For", address);
|
|
196
|
-
} else {
|
|
197
|
-
proxyReq.removeHeader("X-Forwarded-For");
|
|
198
|
-
}
|
|
199
|
-
}
|
|
147
|
+
ws: true
|
|
200
148
|
}
|
|
201
149
|
}
|
|
202
150
|
}
|
|
@@ -209,71 +157,24 @@ const devtoolsPlugin = (inlineOptions = {}) => {
|
|
|
209
157
|
};
|
|
210
158
|
var cli_default = devtoolsPlugin;
|
|
211
159
|
const setupHttpServer = async () => {
|
|
212
|
-
const app = new import_hono.Hono();
|
|
213
160
|
const port = await (0, import_utils.getPort)(8782, {
|
|
214
161
|
slient: true
|
|
215
162
|
});
|
|
216
163
|
const clientServeDir = import_path.default.resolve(require.resolve("@modern-js/devtools-client/package.json"), "../dist");
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
c.header("Set-Cookie", `${k}=${v}; Expires=${expires}; Path=/`, {
|
|
230
|
-
append: true
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return c.json({
|
|
235
|
-
cookies
|
|
236
|
-
});
|
|
237
|
-
};
|
|
238
|
-
app.get("/api/cookies", handleCookieApi);
|
|
239
|
-
app.post("/api/cookies", handleCookieApi);
|
|
240
|
-
app.use(
|
|
241
|
-
"/static/*",
|
|
242
|
-
// Workaround for https://github.com/honojs/node-server/blob/dd0e0cd160b0b8f18abbcb28c5f5c39b72105d98/src/serve-static.ts#L56
|
|
243
|
-
(0, import_serve_static.serveStatic)({
|
|
244
|
-
root: import_path.default.relative(process.cwd(), clientServeDir)
|
|
245
|
-
})
|
|
246
|
-
);
|
|
247
|
-
app.get(":filename{.+\\.hot-update\\.\\w+$}", async (c) => {
|
|
248
|
-
if (process.env.NODE_ENV !== "development") {
|
|
249
|
-
return c.text("Not found", 404);
|
|
250
|
-
}
|
|
251
|
-
const filename = c.req.param("filename");
|
|
252
|
-
const target = new import_url.URL(filename, "http://127.0.0.1:8780");
|
|
253
|
-
const { body, headers, status } = await fetch(target.href);
|
|
254
|
-
const newResp = c.newResponse(body, {
|
|
255
|
-
headers,
|
|
256
|
-
status
|
|
257
|
-
});
|
|
258
|
-
if (newResp.headers.get("content-encoding") === "gzip") {
|
|
259
|
-
newResp.headers.delete("content-encoding");
|
|
260
|
-
}
|
|
261
|
-
return newResp;
|
|
262
|
-
});
|
|
263
|
-
app.get("*", async (c) => {
|
|
264
|
-
const filename = import_path.default.resolve(clientServeDir, "html/client/index.html");
|
|
265
|
-
const content = await import_utils.fs.readFile(filename, "utf-8");
|
|
266
|
-
return c.html(content);
|
|
267
|
-
});
|
|
268
|
-
const instance = (0, import_node_server.serve)({
|
|
269
|
-
fetch: app.fetch,
|
|
270
|
-
port,
|
|
271
|
-
hostname: "127.0.0.1",
|
|
272
|
-
serverOptions: {
|
|
273
|
-
allowHTTP1: true
|
|
274
|
-
}
|
|
164
|
+
const serveMiddleware = (0, import_serve_static.default)(clientServeDir);
|
|
165
|
+
const instance = import_http.default.createServer((req, res) => {
|
|
166
|
+
const usePageNotFound = () => {
|
|
167
|
+
res.write("404");
|
|
168
|
+
res.statusCode = 404;
|
|
169
|
+
res.end();
|
|
170
|
+
};
|
|
171
|
+
const useMainRoute = () => {
|
|
172
|
+
req.url = "/html/client/index.html";
|
|
173
|
+
serveMiddleware(req, res, usePageNotFound);
|
|
174
|
+
};
|
|
175
|
+
serveMiddleware(req, res, useMainRoute);
|
|
275
176
|
});
|
|
276
|
-
|
|
177
|
+
instance.listen(port);
|
|
277
178
|
return {
|
|
278
179
|
instance,
|
|
279
180
|
port
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ClientDefinition } from '@modern-js/devtools-kit/node';
|
|
2
|
+
import type { RequiredDeep } from 'type-fest';
|
|
3
|
+
export interface DevtoolsPluginOptions {
|
|
4
|
+
enable?: boolean;
|
|
5
|
+
endpoint?: string;
|
|
6
|
+
dataSource?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface DevtoolsContext extends RequiredDeep<DevtoolsPluginOptions> {
|
|
9
|
+
def: ClientDefinition;
|
|
10
|
+
}
|
|
11
|
+
export declare const resolveContext: (...sources: Partial<DevtoolsContext>[]) => DevtoolsContext;
|
|
@@ -16,21 +16,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
resolveContext: () => resolveContext
|
|
22
|
-
updateContext: () => updateContext
|
|
19
|
+
var config_exports = {};
|
|
20
|
+
__export(config_exports, {
|
|
21
|
+
resolveContext: () => resolveContext
|
|
23
22
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(config_exports);
|
|
25
24
|
var import_node = require("@modern-js/devtools-kit/node");
|
|
26
25
|
const resolveContext = (...sources) => {
|
|
27
26
|
const ret = {
|
|
28
27
|
enable: process.env.NODE_ENV === "development",
|
|
29
28
|
dataSource: `${import_node.ROUTE_BASENAME}/rpc`,
|
|
30
29
|
endpoint: import_node.ROUTE_BASENAME,
|
|
31
|
-
def: new import_node.ClientDefinition()
|
|
32
|
-
storagePresets: []
|
|
30
|
+
def: new import_node.ClientDefinition()
|
|
33
31
|
};
|
|
32
|
+
Object.assign(ret, {
|
|
33
|
+
__keep: true
|
|
34
|
+
});
|
|
34
35
|
for (const opts of sources) {
|
|
35
36
|
var _opts_enable;
|
|
36
37
|
ret.enable = (_opts_enable = opts.enable) !== null && _opts_enable !== void 0 ? _opts_enable : ret.enable;
|
|
@@ -40,15 +41,10 @@ const resolveContext = (...sources) => {
|
|
|
40
41
|
ret.endpoint = (_opts_endpoint = opts.endpoint) !== null && _opts_endpoint !== void 0 ? _opts_endpoint : ret.endpoint;
|
|
41
42
|
var _opts_def;
|
|
42
43
|
ret.def = (_opts_def = opts.def) !== null && _opts_def !== void 0 ? _opts_def : ret.def;
|
|
43
|
-
opts.storagePresets && ret.storagePresets.push(...opts.storagePresets);
|
|
44
44
|
}
|
|
45
45
|
return ret;
|
|
46
46
|
};
|
|
47
|
-
const updateContext = (context, ...sources) => {
|
|
48
|
-
Object.assign(context, resolveContext(context, ...sources));
|
|
49
|
-
};
|
|
50
47
|
// Annotate the CommonJS export names for ESM import in node:
|
|
51
48
|
0 && (module.exports = {
|
|
52
|
-
resolveContext
|
|
53
|
-
updateContext
|
|
49
|
+
resolveContext
|
|
54
50
|
});
|
package/dist/rpc/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type ClientFunctions, type ServerFunctions
|
|
1
|
+
import { ClientDefinition, type ClientFunctions, type ServerFunctions } from '@modern-js/devtools-kit/node';
|
|
2
2
|
import type { RsbuildPlugin } from '@modern-js/uni-builder';
|
|
3
3
|
import { CliPluginAPI, InjectedHooks } from '../types';
|
|
4
4
|
import { SocketServer } from '../utils/socket';
|
|
5
5
|
export interface SetupClientConnectionOptions {
|
|
6
6
|
api: CliPluginAPI;
|
|
7
7
|
server: SocketServer;
|
|
8
|
-
|
|
8
|
+
def: ClientDefinition;
|
|
9
9
|
}
|
|
10
10
|
export declare const setupClientConnection: (options: SetupClientConnectionOptions) => Promise<{
|
|
11
11
|
client: import("birpc").BirpcReturn<ClientFunctions, ServerFunctions>;
|
package/dist/rpc/index.js
CHANGED
|
@@ -31,96 +31,15 @@ __export(rpc_exports, {
|
|
|
31
31
|
setupClientConnection: () => setupClientConnection
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(rpc_exports);
|
|
34
|
-
var import_path = __toESM(require("path"));
|
|
35
|
-
var import_buffer = require("buffer");
|
|
36
|
-
var import_node = require("@modern-js/devtools-kit/node");
|
|
37
34
|
var import_lodash = __toESM(require("@modern-js/utils/lodash"));
|
|
35
|
+
var import_node = require("@modern-js/devtools-kit/node");
|
|
38
36
|
var import_birpc = require("birpc");
|
|
39
37
|
var flatted = __toESM(require("flatted"));
|
|
40
|
-
var
|
|
41
|
-
var import_utils = require("@modern-js/utils");
|
|
38
|
+
var import_p_defer = __toESM(require("p-defer"));
|
|
42
39
|
var import_module = require("../utils/module");
|
|
43
|
-
var import_state = require("../state");
|
|
44
|
-
const resolveDependencies = async (rootPath) => {
|
|
45
|
-
const ret = {};
|
|
46
|
-
const resolveExprs = {
|
|
47
|
-
react: [
|
|
48
|
-
rootPath,
|
|
49
|
-
"react/package.json"
|
|
50
|
-
],
|
|
51
|
-
"@modern-js/app-tools": [
|
|
52
|
-
rootPath,
|
|
53
|
-
"@modern-js/app-tools/package.json"
|
|
54
|
-
],
|
|
55
|
-
"@edenx/app-tools": [
|
|
56
|
-
rootPath,
|
|
57
|
-
"@edenx/app-tools/package.json"
|
|
58
|
-
],
|
|
59
|
-
webpack: [
|
|
60
|
-
rootPath,
|
|
61
|
-
"@modern-js/app-tools",
|
|
62
|
-
"@modern-js/uni-builder",
|
|
63
|
-
"@rsbuild/webpack",
|
|
64
|
-
"webpack/package.json"
|
|
65
|
-
],
|
|
66
|
-
"@rspack/core": [
|
|
67
|
-
rootPath,
|
|
68
|
-
"@modern-js/uni-builder",
|
|
69
|
-
"@rsbuild/core",
|
|
70
|
-
"@rspack/core/package.json"
|
|
71
|
-
],
|
|
72
|
-
"@rsdoctor/rspack-plugin": [
|
|
73
|
-
rootPath,
|
|
74
|
-
"@rsdoctor/rspack-plugin/package.json"
|
|
75
|
-
],
|
|
76
|
-
"@rsdoctor/webpack-plugin": [
|
|
77
|
-
rootPath,
|
|
78
|
-
"@rsdoctor/webpack-plugin/package.json"
|
|
79
|
-
],
|
|
80
|
-
"@web-doctor/webpack-plugin": [
|
|
81
|
-
rootPath,
|
|
82
|
-
"@web-doctor/webpack-plugin/package.json"
|
|
83
|
-
],
|
|
84
|
-
"@web-doctor/rspack-plugin": [
|
|
85
|
-
rootPath,
|
|
86
|
-
"@web-doctor/rspack-plugin/package.json"
|
|
87
|
-
],
|
|
88
|
-
"@web-doctor/webpack-plugin(builder)": [
|
|
89
|
-
rootPath,
|
|
90
|
-
"@edenx/builder-plugin-web-doctor",
|
|
91
|
-
"@web-doctor/webpack-plugin/package.json"
|
|
92
|
-
],
|
|
93
|
-
"@web-doctor/rspack-plugin(builder)": [
|
|
94
|
-
rootPath,
|
|
95
|
-
"@edenx/builder-plugin-web-doctor",
|
|
96
|
-
"@web-doctor/rspack-plugin/package.json"
|
|
97
|
-
],
|
|
98
|
-
"@rsdoctor/core": [
|
|
99
|
-
rootPath,
|
|
100
|
-
"@rsdoctor/core/package.json"
|
|
101
|
-
]
|
|
102
|
-
};
|
|
103
|
-
for (const [name, expr] of Object.entries(resolveExprs)) {
|
|
104
|
-
try {
|
|
105
|
-
ret[name] = (0, import_module.requireModule)(expr).version;
|
|
106
|
-
} catch {
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return ret;
|
|
110
|
-
};
|
|
111
|
-
const getDoctorOverview = async (ctx) => {
|
|
112
|
-
const manifestPath = await (0, import_node.findManifest)(ctx.distDirectory);
|
|
113
|
-
const json = await (0, import_node.parseManifest)(require(manifestPath));
|
|
114
|
-
return {
|
|
115
|
-
numModules: json.data.moduleGraph.modules.length,
|
|
116
|
-
numChunks: json.data.chunkGraph.chunks.length,
|
|
117
|
-
numPackages: json.data.packageGraph.packages.length,
|
|
118
|
-
summary: json.data.summary,
|
|
119
|
-
errors: json.data.errors
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
40
|
const setupClientConnection = async (options) => {
|
|
123
|
-
const { api, server,
|
|
41
|
+
const { api, server, def } = options;
|
|
42
|
+
const _fileSystemRoutesMap = {};
|
|
124
43
|
let handleMessage = null;
|
|
125
44
|
const onceConnection = new Promise((resolve) => {
|
|
126
45
|
server.on("connection", (ws) => {
|
|
@@ -128,106 +47,151 @@ const setupClientConnection = async (options) => {
|
|
|
128
47
|
ws.on("message", (data, isBinary) => handleMessage === null || handleMessage === void 0 ? void 0 : handleMessage(data, isBinary));
|
|
129
48
|
});
|
|
130
49
|
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const validateSafeToOpen = (filename) => {
|
|
139
|
-
const { appDirectory } = api.useAppContext();
|
|
140
|
-
const resolved = import_path.default.resolve(appDirectory, filename);
|
|
141
|
-
for (const preset of ctx.storagePresets) {
|
|
142
|
-
if (import_path.default.resolve(appDirectory, preset.filename) === resolved) {
|
|
143
|
-
return true;
|
|
50
|
+
const deferred = {
|
|
51
|
+
prepare: (0, import_p_defer.default)(),
|
|
52
|
+
builder: {
|
|
53
|
+
context: (0, import_p_defer.default)(),
|
|
54
|
+
config: {
|
|
55
|
+
resolved: (0, import_p_defer.default)(),
|
|
56
|
+
transformed: (0, import_p_defer.default)()
|
|
144
57
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
58
|
+
},
|
|
59
|
+
bundler: {
|
|
60
|
+
config: {
|
|
61
|
+
resolved: (0, import_p_defer.default)(),
|
|
62
|
+
transformed: (0, import_p_defer.default)()
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
compileTimeCost: (0, import_p_defer.default)()
|
|
147
66
|
};
|
|
148
67
|
const serverFunctions = {
|
|
149
|
-
|
|
150
|
-
|
|
68
|
+
async getFrameworkConfig() {
|
|
69
|
+
await deferred.prepare.promise;
|
|
70
|
+
return api.useConfigContext();
|
|
151
71
|
},
|
|
152
|
-
async
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
});
|
|
156
|
-
return import_state.$state;
|
|
72
|
+
async getTransformedFrameworkConfig() {
|
|
73
|
+
await deferred.prepare.promise;
|
|
74
|
+
return api.useResolvedConfigContext();
|
|
157
75
|
},
|
|
158
|
-
async
|
|
159
|
-
|
|
160
|
-
const appCtx = api.useAppContext();
|
|
161
|
-
const basename = `${ctx.def.name.shortName}.runtime.json`;
|
|
162
|
-
const filename = import_path.default.resolve(appCtx.appDirectory, basename);
|
|
163
|
-
const id = (0, import_utils.nanoid)();
|
|
164
|
-
const name = `New Preset ${id.slice(0, 6)}`;
|
|
165
|
-
const config = {};
|
|
166
|
-
if (await import_utils.fs.pathExists(filename)) {
|
|
167
|
-
Object.assign(config, await import_utils.fs.readJSON(filename));
|
|
168
|
-
}
|
|
169
|
-
const newPreset = {
|
|
170
|
-
name,
|
|
171
|
-
id,
|
|
172
|
-
cookie: {},
|
|
173
|
-
localStorage: {},
|
|
174
|
-
sessionStorage: {}
|
|
175
|
-
};
|
|
176
|
-
(_config = config).storagePresets || (_config.storagePresets = []);
|
|
177
|
-
config.storagePresets.push(newPreset);
|
|
178
|
-
await import_utils.fs.outputJSON(filename, config, {
|
|
179
|
-
spaces: 2
|
|
180
|
-
});
|
|
181
|
-
return newPreset;
|
|
76
|
+
async getBuilderConfig() {
|
|
77
|
+
return deferred.builder.config.resolved.promise;
|
|
182
78
|
},
|
|
183
|
-
async
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const filename = import_path.default.resolve(appCtx.appDirectory, target.filename);
|
|
201
|
-
const config = {};
|
|
202
|
-
if (await import_utils.fs.pathExists(filename)) {
|
|
203
|
-
Object.assign(config, await import_utils.fs.readJSON(filename));
|
|
204
|
-
}
|
|
205
|
-
(_config = config).storagePresets || (_config.storagePresets = []);
|
|
206
|
-
const diff = import_lodash.default.pick(preset, [
|
|
207
|
-
"cookie",
|
|
208
|
-
"localStorage",
|
|
209
|
-
"sessionStorage"
|
|
79
|
+
async getTransformedBuilderConfig() {
|
|
80
|
+
return deferred.builder.config.transformed.promise;
|
|
81
|
+
},
|
|
82
|
+
async getBundlerConfigs() {
|
|
83
|
+
return deferred.bundler.config.resolved.promise;
|
|
84
|
+
},
|
|
85
|
+
async getTransformedBundlerConfigs() {
|
|
86
|
+
return deferred.bundler.config.transformed.promise;
|
|
87
|
+
},
|
|
88
|
+
async getAppContext() {
|
|
89
|
+
await deferred.prepare.promise;
|
|
90
|
+
const ctx = {
|
|
91
|
+
...api.useAppContext()
|
|
92
|
+
};
|
|
93
|
+
return import_lodash.default.omit(ctx, [
|
|
94
|
+
"builder",
|
|
95
|
+
"serverInternalPlugins"
|
|
210
96
|
]);
|
|
211
|
-
const matched = import_lodash.default.find(config.storagePresets, {
|
|
212
|
-
id: target.id
|
|
213
|
-
});
|
|
214
|
-
if (matched) {
|
|
215
|
-
import_lodash.default.merge(matched, diff);
|
|
216
|
-
} else {
|
|
217
|
-
config.storagePresets.push(preset);
|
|
218
|
-
}
|
|
219
|
-
await import_utils.fs.outputJSON(filename, config, {
|
|
220
|
-
spaces: 2
|
|
221
|
-
});
|
|
222
97
|
},
|
|
223
|
-
async
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
98
|
+
async getFileSystemRoutes(entryName) {
|
|
99
|
+
var _fileSystemRoutesMap_entryName;
|
|
100
|
+
return (_fileSystemRoutesMap_entryName = _fileSystemRoutesMap[entryName]) !== null && _fileSystemRoutesMap_entryName !== void 0 ? _fileSystemRoutesMap_entryName : [];
|
|
101
|
+
},
|
|
102
|
+
async getBuilderContext() {
|
|
103
|
+
const ctx = await deferred.builder.context.promise;
|
|
104
|
+
return ctx;
|
|
105
|
+
},
|
|
106
|
+
async getDependencies() {
|
|
107
|
+
const ctx = await deferred.builder.context.promise;
|
|
108
|
+
const ret = {};
|
|
109
|
+
const resolveExprs = {
|
|
110
|
+
react: [
|
|
111
|
+
ctx.rootPath,
|
|
112
|
+
"react/package.json"
|
|
113
|
+
],
|
|
114
|
+
"@modern-js/app-tools": [
|
|
115
|
+
ctx.rootPath,
|
|
116
|
+
"@modern-js/app-tools/package.json"
|
|
117
|
+
],
|
|
118
|
+
"@edenx/app-tools": [
|
|
119
|
+
ctx.rootPath,
|
|
120
|
+
"@edenx/app-tools/package.json"
|
|
121
|
+
],
|
|
122
|
+
webpack: [
|
|
123
|
+
ctx.rootPath,
|
|
124
|
+
"@modern-js/app-tools",
|
|
125
|
+
"@modern-js/uni-builder",
|
|
126
|
+
"@rsbuild/webpack",
|
|
127
|
+
"webpack/package.json"
|
|
128
|
+
],
|
|
129
|
+
"@rspack/core": [
|
|
130
|
+
ctx.rootPath,
|
|
131
|
+
"@modern-js/uni-builder",
|
|
132
|
+
"@rsbuild/core",
|
|
133
|
+
"@rspack/core/package.json"
|
|
134
|
+
],
|
|
135
|
+
"@rsdoctor/rspack-plugin": [
|
|
136
|
+
ctx.rootPath,
|
|
137
|
+
"@rsdoctor/rspack-plugin/package.json"
|
|
138
|
+
],
|
|
139
|
+
"@rsdoctor/webpack-plugin": [
|
|
140
|
+
ctx.rootPath,
|
|
141
|
+
"@rsdoctor/webpack-plugin/package.json"
|
|
142
|
+
],
|
|
143
|
+
"@web-doctor/webpack-plugin": [
|
|
144
|
+
ctx.rootPath,
|
|
145
|
+
"@web-doctor/webpack-plugin/package.json"
|
|
146
|
+
],
|
|
147
|
+
"@web-doctor/rspack-plugin": [
|
|
148
|
+
ctx.rootPath,
|
|
149
|
+
"@web-doctor/rspack-plugin/package.json"
|
|
150
|
+
],
|
|
151
|
+
"@web-doctor/webpack-plugin(builder)": [
|
|
152
|
+
ctx.rootPath,
|
|
153
|
+
"@edenx/builder-plugin-web-doctor",
|
|
154
|
+
"@web-doctor/webpack-plugin/package.json"
|
|
155
|
+
],
|
|
156
|
+
"@web-doctor/rspack-plugin(builder)": [
|
|
157
|
+
ctx.rootPath,
|
|
158
|
+
"@edenx/builder-plugin-web-doctor",
|
|
159
|
+
"@web-doctor/rspack-plugin/package.json"
|
|
160
|
+
],
|
|
161
|
+
"@rsdoctor/core": [
|
|
162
|
+
ctx.rootPath,
|
|
163
|
+
"@rsdoctor/core/package.json"
|
|
164
|
+
]
|
|
165
|
+
};
|
|
166
|
+
for (const [name, expr] of Object.entries(resolveExprs)) {
|
|
167
|
+
try {
|
|
168
|
+
ret[name] = (0, import_module.requireModule)(expr).version;
|
|
169
|
+
} catch {
|
|
170
|
+
}
|
|
228
171
|
}
|
|
229
|
-
|
|
230
|
-
|
|
172
|
+
return ret;
|
|
173
|
+
},
|
|
174
|
+
async getCompileTimeCost() {
|
|
175
|
+
return deferred.compileTimeCost.promise;
|
|
176
|
+
},
|
|
177
|
+
async getClientDefinition() {
|
|
178
|
+
return def;
|
|
179
|
+
},
|
|
180
|
+
async getDoctorOverview() {
|
|
181
|
+
const ctx = api.useAppContext();
|
|
182
|
+
const manifestPath = await (0, import_node.findManifest)(ctx.distDirectory);
|
|
183
|
+
const json = await (0, import_node.parseManifest)(require(manifestPath));
|
|
184
|
+
const data = {
|
|
185
|
+
numModules: json.data.moduleGraph.modules.length,
|
|
186
|
+
numChunks: json.data.chunkGraph.chunks.length,
|
|
187
|
+
numPackages: json.data.packageGraph.packages.length,
|
|
188
|
+
summary: json.data.summary,
|
|
189
|
+
errors: json.data.errors
|
|
190
|
+
};
|
|
191
|
+
return data;
|
|
192
|
+
},
|
|
193
|
+
echo(content) {
|
|
194
|
+
return content;
|
|
231
195
|
}
|
|
232
196
|
};
|
|
233
197
|
const clientRpcOptions = {
|
|
@@ -235,27 +199,16 @@ const setupClientConnection = async (options) => {
|
|
|
235
199
|
on: (cb) => handleMessage = cb,
|
|
236
200
|
serialize: (v) => flatted.stringify([
|
|
237
201
|
v
|
|
238
|
-
]
|
|
239
|
-
deserialize: (v) =>
|
|
240
|
-
const msg = flatted.parse(v.toString(), import_node.reviver)[0];
|
|
241
|
-
return msg;
|
|
242
|
-
}
|
|
202
|
+
]),
|
|
203
|
+
deserialize: (v) => flatted.parse(v.toString())[0]
|
|
243
204
|
};
|
|
244
205
|
const clientConn = (0, import_birpc.createBirpc)(serverFunctions, clientRpcOptions);
|
|
245
206
|
const hooks = {
|
|
246
207
|
prepare() {
|
|
247
|
-
|
|
248
|
-
...api.useAppContext(),
|
|
249
|
-
builder: null,
|
|
250
|
-
serverInternalPlugins: null
|
|
251
|
-
};
|
|
252
|
-
import_state.$resolvers.framework.context.resolve(frameworkContext);
|
|
253
|
-
import_state.$resolvers.framework.config.resolved.resolve(api.useConfigContext());
|
|
254
|
-
import_state.$resolvers.framework.config.transformed.resolve(api.useResolvedConfigContext());
|
|
255
|
-
getDoctorOverview(frameworkContext).then((doctor) => import_state.$resolvers.doctor.resolve(doctor)).catch(() => import_state.$resolvers.doctor.resolve(void 0));
|
|
208
|
+
deferred.prepare.resolve();
|
|
256
209
|
},
|
|
257
210
|
modifyFileSystemRoutes({ entrypoint, routes }) {
|
|
258
|
-
|
|
211
|
+
_fileSystemRoutesMap[entrypoint.entryName] = import_lodash.default.cloneDeep(routes);
|
|
259
212
|
return {
|
|
260
213
|
entrypoint,
|
|
261
214
|
routes
|
|
@@ -265,20 +218,17 @@ const setupClientConnection = async (options) => {
|
|
|
265
218
|
const builderPlugin = {
|
|
266
219
|
name: "builder-plugin-devtools",
|
|
267
220
|
setup(api2) {
|
|
268
|
-
|
|
269
|
-
resolveDependencies(api2.context.rootPath).then((deps) => {
|
|
270
|
-
import_state.$state.dependencies = deps;
|
|
271
|
-
});
|
|
221
|
+
deferred.builder.context.resolve(import_lodash.default.cloneDeep(api2.context));
|
|
272
222
|
api2.modifyBundlerChain(() => {
|
|
273
|
-
|
|
274
|
-
|
|
223
|
+
deferred.builder.config.resolved.resolve(import_lodash.default.cloneDeep(api2.getRsbuildConfig()));
|
|
224
|
+
deferred.builder.config.transformed.resolve(import_lodash.default.cloneDeep(api2.getNormalizedConfig()));
|
|
275
225
|
});
|
|
276
226
|
const expectBundlerNum = import_lodash.default.castArray(api2.context.targets).length;
|
|
277
227
|
const bundlerConfigs = [];
|
|
278
228
|
const handleBundlerConfig = (config) => {
|
|
279
229
|
bundlerConfigs.push(config);
|
|
280
230
|
if (bundlerConfigs.length >= expectBundlerNum) {
|
|
281
|
-
|
|
231
|
+
deferred.bundler.config.resolved.resolve(import_lodash.default.cloneDeep(bundlerConfigs));
|
|
282
232
|
}
|
|
283
233
|
};
|
|
284
234
|
if (api2.context.bundlerType === "webpack") {
|
|
@@ -291,21 +241,17 @@ const setupClientConnection = async (options) => {
|
|
|
291
241
|
});
|
|
292
242
|
}
|
|
293
243
|
api2.onBeforeCreateCompiler(({ bundlerConfigs: bundlerConfigs2 }) => {
|
|
294
|
-
|
|
244
|
+
deferred.bundler.config.transformed.resolve(import_lodash.default.cloneDeep(bundlerConfigs2));
|
|
295
245
|
});
|
|
296
246
|
let buildStartedAt = NaN;
|
|
297
247
|
api2.onAfterCreateCompiler(() => {
|
|
298
248
|
buildStartedAt = Date.now();
|
|
299
249
|
});
|
|
300
250
|
api2.onDevCompileDone(() => {
|
|
301
|
-
|
|
302
|
-
compileDuration: Date.now() - buildStartedAt
|
|
303
|
-
});
|
|
251
|
+
deferred.compileTimeCost.resolve(Date.now() - buildStartedAt);
|
|
304
252
|
});
|
|
305
253
|
api2.onAfterBuild(() => {
|
|
306
|
-
|
|
307
|
-
compileDuration: Date.now() - buildStartedAt
|
|
308
|
-
});
|
|
254
|
+
deferred.compileTimeCost.resolve(Date.now() - buildStartedAt);
|
|
309
255
|
});
|
|
310
256
|
}
|
|
311
257
|
};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "0.0.0-next-
|
|
18
|
+
"version": "0.0.0-next-20240522113137",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
21
|
"main": "./dist/index.js",
|
|
@@ -43,38 +43,34 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@hono/node-server": "^1.8.2",
|
|
47
46
|
"birpc": "0.2.13",
|
|
48
|
-
"clipboardy": "^4.0.0",
|
|
49
|
-
"cookie-es": "^1.0.0",
|
|
50
47
|
"flatted": "^3.2.9",
|
|
51
|
-
"
|
|
52
|
-
"open": "^10.1.0",
|
|
48
|
+
"serve-static": "^1.14.1",
|
|
53
49
|
"p-defer": "^3.0.0",
|
|
54
|
-
"ufo": "^1.3.0",
|
|
55
|
-
"valtio": "^1.11.1",
|
|
56
50
|
"ws": "^8.13.0",
|
|
57
|
-
"
|
|
58
|
-
"@modern-js/devtools-kit": "0.0.0-next-
|
|
59
|
-
"@modern-js/
|
|
51
|
+
"ufo": "^1.3.0",
|
|
52
|
+
"@modern-js/devtools-kit": "0.0.0-next-20240522113137",
|
|
53
|
+
"@modern-js/devtools-client": "0.0.0-next-20240522113137",
|
|
54
|
+
"@modern-js/utils": "0.0.0-next-20240522113137"
|
|
60
55
|
},
|
|
61
56
|
"devDependencies": {
|
|
57
|
+
"@types/serve-static": "^1.13.10",
|
|
62
58
|
"@swc/helpers": "0.5.3",
|
|
63
59
|
"@types/node": "^14",
|
|
64
60
|
"@types/ws": "^8.5.5",
|
|
65
61
|
"type-fest": "^4.1.0",
|
|
66
62
|
"typescript": "^5",
|
|
67
|
-
"@modern-js/app-tools": "0.0.0-next-
|
|
68
|
-
"@modern-js/core": "0.0.0-next-
|
|
69
|
-
"@modern-js/module-tools": "0.0.0-next-
|
|
70
|
-
"@modern-js/
|
|
71
|
-
"@modern-js/
|
|
72
|
-
"@modern-js/
|
|
73
|
-
"@modern-js/uni-builder": "0.0.0-next-
|
|
74
|
-
"@scripts/build": "0.0.0-next-
|
|
63
|
+
"@modern-js/app-tools": "0.0.0-next-20240522113137",
|
|
64
|
+
"@modern-js/core": "0.0.0-next-20240522113137",
|
|
65
|
+
"@modern-js/module-tools": "0.0.0-next-20240522113137",
|
|
66
|
+
"@modern-js/types": "0.0.0-next-20240522113137",
|
|
67
|
+
"@modern-js/runtime": "0.0.0-next-20240522113137",
|
|
68
|
+
"@modern-js/server-core": "0.0.0-next-20240522113137",
|
|
69
|
+
"@modern-js/uni-builder": "0.0.0-next-20240522113137",
|
|
70
|
+
"@scripts/build": "0.0.0-next-20240522113137"
|
|
75
71
|
},
|
|
76
72
|
"peerDependencies": {
|
|
77
|
-
"@modern-js/runtime": "0.0.0-next-
|
|
73
|
+
"@modern-js/runtime": "0.0.0-next-20240522113137"
|
|
78
74
|
},
|
|
79
75
|
"peerDependenciesMeta": {
|
|
80
76
|
"@modern-js/runtime": {
|
package/dist/options.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { DevtoolsContext } from '@modern-js/devtools-kit/node';
|
|
2
|
-
export interface DevtoolsPluginOptions {
|
|
3
|
-
enable?: boolean;
|
|
4
|
-
endpoint?: string;
|
|
5
|
-
dataSource?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare const resolveContext: (...sources: Partial<DevtoolsContext>[]) => DevtoolsContext;
|
|
8
|
-
export declare const updateContext: (context: DevtoolsContext, ...sources: Partial<DevtoolsContext>[]) => void;
|
package/dist/state.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ServerExportedStateResolvers } from '@modern-js/devtools-kit/node';
|
|
2
|
-
export declare const $serverExportedState: import("@modern-js/devtools-kit/node").ServerExportedStateResult;
|
|
3
|
-
export declare const $resolvers: ServerExportedStateResolvers;
|
|
4
|
-
export declare const $state: import("@modern-js/devtools-kit/node").ServerExportedState;
|
package/dist/state.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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 state_exports = {};
|
|
20
|
-
__export(state_exports, {
|
|
21
|
-
$resolvers: () => $resolvers,
|
|
22
|
-
$serverExportedState: () => $serverExportedState,
|
|
23
|
-
$state: () => $state
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(state_exports);
|
|
26
|
-
var import_valtio = require("valtio");
|
|
27
|
-
var import_node = require("@modern-js/devtools-kit/node");
|
|
28
|
-
const $serverExportedState = (0, import_node.createServerExportedState)();
|
|
29
|
-
const $resolvers = $serverExportedState.resolvers;
|
|
30
|
-
const $state = (0, import_valtio.proxy)($serverExportedState.state);
|
|
31
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
-
0 && (module.exports = {
|
|
33
|
-
$resolvers,
|
|
34
|
-
$serverExportedState,
|
|
35
|
-
$state
|
|
36
|
-
});
|
package/dist/types/common.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var common_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(common_exports);
|
package/dist/types/config.d.ts
DELETED
package/dist/types/config.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var config_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(config_exports);
|
package/dist/types/index.d.ts
DELETED
package/dist/utils/config.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { DevtoolsContext, StoragePresetContext } from '@modern-js/devtools-kit';
|
|
2
|
-
export declare function getConfigFilenames(base: string, dir?: string): string[];
|
|
3
|
-
/** Resolve all config files from target directory upward to the root path. */
|
|
4
|
-
export declare function resolveConfigFiles(base: string, dir?: string): Promise<string[]>;
|
|
5
|
-
export declare function loadConfigFile(filename: string): Promise<{
|
|
6
|
-
storagePresets: StoragePresetContext[];
|
|
7
|
-
} | null>;
|
|
8
|
-
export declare function loadConfigFiles(base: string, dir?: string): Promise<Partial<DevtoolsContext>[] | null>;
|
package/dist/utils/config.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
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 config_exports = {};
|
|
30
|
-
__export(config_exports, {
|
|
31
|
-
getConfigFilenames: () => getConfigFilenames,
|
|
32
|
-
loadConfigFile: () => loadConfigFile,
|
|
33
|
-
loadConfigFiles: () => loadConfigFiles,
|
|
34
|
-
resolveConfigFiles: () => resolveConfigFiles
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(config_exports);
|
|
37
|
-
var import_path = __toESM(require("path"));
|
|
38
|
-
var import_fs_extra = __toESM(require("@modern-js/utils/fs-extra"));
|
|
39
|
-
var import_utils = require("@modern-js/utils");
|
|
40
|
-
function getConfigFilenames(base, dir = process.cwd()) {
|
|
41
|
-
const files = [];
|
|
42
|
-
let curr = dir;
|
|
43
|
-
while (import_path.default.dirname(curr) !== curr) {
|
|
44
|
-
files.push(import_path.default.join(curr, base));
|
|
45
|
-
curr = import_path.default.dirname(curr);
|
|
46
|
-
}
|
|
47
|
-
return files;
|
|
48
|
-
}
|
|
49
|
-
async function resolveConfigFiles(base, dir = process.cwd()) {
|
|
50
|
-
const files = getConfigFilenames(base, dir);
|
|
51
|
-
const ret = [];
|
|
52
|
-
await Promise.all(files.map(async (file) => await import_fs_extra.default.pathExists(file) && ret.push(file)));
|
|
53
|
-
return ret;
|
|
54
|
-
}
|
|
55
|
-
async function loadConfigFile(filename) {
|
|
56
|
-
const storagePresets = [];
|
|
57
|
-
try {
|
|
58
|
-
const config = await import_fs_extra.default.readJSON(filename);
|
|
59
|
-
config.storagePresets && storagePresets.push(...config.storagePresets);
|
|
60
|
-
} catch (e) {
|
|
61
|
-
import_utils.logger.error(e);
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const presets = [];
|
|
65
|
-
let _validated = true;
|
|
66
|
-
for (const preset of storagePresets) {
|
|
67
|
-
if (typeof preset.id !== "string") {
|
|
68
|
-
preset.id = (0, import_utils.nanoid)();
|
|
69
|
-
_validated = false;
|
|
70
|
-
}
|
|
71
|
-
presets.push(preset);
|
|
72
|
-
}
|
|
73
|
-
if (!_validated) {
|
|
74
|
-
await import_fs_extra.default.outputJSON(filename, {
|
|
75
|
-
storagePresets: presets
|
|
76
|
-
}, {
|
|
77
|
-
spaces: 2
|
|
78
|
-
});
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
const ret = [];
|
|
82
|
-
for (const preset of presets) {
|
|
83
|
-
ret.push({
|
|
84
|
-
...preset,
|
|
85
|
-
filename
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
storagePresets: ret
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
async function loadConfigFiles(base, dir = process.cwd()) {
|
|
93
|
-
const filenames = await resolveConfigFiles(base, dir);
|
|
94
|
-
const resolved = await Promise.all(filenames.map(loadConfigFile));
|
|
95
|
-
const ret = [];
|
|
96
|
-
for (const config of resolved) {
|
|
97
|
-
if (config) {
|
|
98
|
-
ret.push(config);
|
|
99
|
-
} else {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return ret;
|
|
104
|
-
}
|
|
105
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
-
0 && (module.exports = {
|
|
107
|
-
getConfigFilenames,
|
|
108
|
-
loadConfigFile,
|
|
109
|
-
loadConfigFiles,
|
|
110
|
-
resolveConfigFiles
|
|
111
|
-
});
|
|
File without changes
|
|
File without changes
|