@modern-js/plugin-devtools 2.39.1 → 2.40.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.
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +39 -52
- package/dist/config.d.ts +5 -9
- package/dist/config.js +32 -17
- package/package.json +15 -16
- package/dist/runtime.d.ts +0 -1
- package/dist/runtime.js +0 -11
package/dist/cli.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { AppTools, CliPlugin } from '@modern-js/app-tools';
|
2
2
|
import { DevtoolsPluginOptions, DevtoolsPluginInlineOptions } from './config';
|
3
3
|
export type { DevtoolsPluginOptions, DevtoolsPluginInlineOptions };
|
4
|
-
export declare const devtoolsPlugin: (
|
4
|
+
export declare const devtoolsPlugin: (inlineOptions?: DevtoolsPluginInlineOptions) => CliPlugin<AppTools>;
|
5
5
|
export default devtoolsPlugin;
|
package/dist/cli.js
CHANGED
@@ -41,35 +41,17 @@ var import_ufo = require("ufo");
|
|
41
41
|
var import_config = require("./config");
|
42
42
|
var import_rpc = require("./rpc");
|
43
43
|
var import_socket = require("./utils/socket");
|
44
|
-
const devtoolsPlugin = (
|
44
|
+
const devtoolsPlugin = (inlineOptions = {}) => ({
|
45
45
|
name: "@modern-js/plugin-devtools",
|
46
46
|
usePlugins: [],
|
47
47
|
setup: async (api) => {
|
48
|
-
|
49
|
-
|
50
|
-
if (!enablePlugin) {
|
48
|
+
const ctx = (0, import_config.resolveContext)(inlineOptions);
|
49
|
+
if (!ctx.enable) {
|
51
50
|
return {};
|
52
51
|
}
|
53
|
-
const
|
54
|
-
slient: true
|
55
|
-
});
|
56
|
-
const clientServeDir = import_path.default.resolve(require.resolve("@modern-js/devtools-client/package.json"), "../dist");
|
57
|
-
const serveMiddleware = (0, import_serve_static.default)(clientServeDir);
|
58
|
-
const httpServer = import_http.default.createServer((req, res) => {
|
59
|
-
const usePageNotFound = () => {
|
60
|
-
res.write("404");
|
61
|
-
res.statusCode = 404;
|
62
|
-
res.end();
|
63
|
-
};
|
64
|
-
const useMainRoute = () => {
|
65
|
-
req.url = "/html/main/index.html";
|
66
|
-
serveMiddleware(req, res, usePageNotFound);
|
67
|
-
};
|
68
|
-
serveMiddleware(req, res, useMainRoute);
|
69
|
-
});
|
70
|
-
httpServer.listen(port);
|
52
|
+
const httpServer = await setupHttpServer();
|
71
53
|
const socketServer = new import_socket.SocketServer({
|
72
|
-
server: httpServer,
|
54
|
+
server: httpServer.instance,
|
73
55
|
path: "/rpc"
|
74
56
|
});
|
75
57
|
const rpc = await (0, import_rpc.setupClientConnection)({
|
@@ -79,50 +61,31 @@ const devtoolsPlugin = (options) => ({
|
|
79
61
|
return {
|
80
62
|
prepare: rpc.hooks.prepare,
|
81
63
|
modifyFileSystemRoutes: rpc.hooks.modifyFileSystemRoutes,
|
82
|
-
validateSchema() {
|
83
|
-
return [
|
84
|
-
{
|
85
|
-
target: "devtools",
|
86
|
-
schema: {
|
87
|
-
typeof: [
|
88
|
-
"boolean",
|
89
|
-
"object"
|
90
|
-
]
|
91
|
-
}
|
92
|
-
}
|
93
|
-
];
|
94
|
-
},
|
95
64
|
beforeRestart() {
|
96
|
-
return new Promise((resolve, reject) => httpServer.close((err) => err ? reject(err) : resolve()));
|
65
|
+
return new Promise((resolve, reject) => httpServer.instance.close((err) => err ? reject(err) : resolve()));
|
97
66
|
},
|
98
67
|
config() {
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
const mountOpts = {
|
103
|
-
dataSource: `${import_devtools_kit.ROUTE_BASENAME}/rpc`,
|
104
|
-
endpoint: import_devtools_kit.ROUTE_BASENAME,
|
68
|
+
var _api_useConfigContext_devtools;
|
69
|
+
const config = (_api_useConfigContext_devtools = api.useConfigContext().devtools) !== null && _api_useConfigContext_devtools !== void 0 ? _api_useConfigContext_devtools : {};
|
70
|
+
Object.assign(ctx, (0, import_config.resolveContext)(ctx, config), {
|
105
71
|
__keep: true
|
106
|
-
};
|
107
|
-
|
108
|
-
runtimeEntry =
|
72
|
+
});
|
73
|
+
import_utils.logger.info(`${ctx.def.name.formalName} Devtools is enabled`);
|
74
|
+
const runtimeEntry = require.resolve("@modern-js/devtools-client/mount");
|
109
75
|
return {
|
110
76
|
builderPlugins: [
|
111
77
|
rpc.builderPlugin
|
112
78
|
],
|
113
79
|
source: {
|
114
80
|
preEntry: [
|
115
|
-
runtimeEntry
|
116
|
-
]
|
117
|
-
globalVars: {
|
118
|
-
"process.env._MODERN_DEVTOOLS_LOGO_SRC": new import_devtools_kit.ClientDefinition().assets.logo
|
119
|
-
}
|
81
|
+
(0, import_ufo.withQuery)(runtimeEntry, ctx)
|
82
|
+
]
|
120
83
|
},
|
121
84
|
tools: {
|
122
85
|
devServer: {
|
123
86
|
proxy: {
|
124
87
|
[import_devtools_kit.ROUTE_BASENAME]: {
|
125
|
-
target: `http://localhost:${port}`,
|
88
|
+
target: `http://localhost:${httpServer.port}`,
|
126
89
|
pathRewrite: {
|
127
90
|
[`^${import_devtools_kit.ROUTE_BASENAME}`]: ""
|
128
91
|
},
|
@@ -137,6 +100,30 @@ const devtoolsPlugin = (options) => ({
|
|
137
100
|
}
|
138
101
|
});
|
139
102
|
var cli_default = devtoolsPlugin;
|
103
|
+
const setupHttpServer = async () => {
|
104
|
+
const port = await (0, import_utils.getPort)(8782, {
|
105
|
+
slient: true
|
106
|
+
});
|
107
|
+
const clientServeDir = import_path.default.resolve(require.resolve("@modern-js/devtools-client/package.json"), "../dist");
|
108
|
+
const serveMiddleware = (0, import_serve_static.default)(clientServeDir);
|
109
|
+
const instance = import_http.default.createServer((req, res) => {
|
110
|
+
const usePageNotFound = () => {
|
111
|
+
res.write("404");
|
112
|
+
res.statusCode = 404;
|
113
|
+
res.end();
|
114
|
+
};
|
115
|
+
const useMainRoute = () => {
|
116
|
+
req.url = "/html/client/index.html";
|
117
|
+
serveMiddleware(req, res, usePageNotFound);
|
118
|
+
};
|
119
|
+
serveMiddleware(req, res, useMainRoute);
|
120
|
+
});
|
121
|
+
instance.listen(port);
|
122
|
+
return {
|
123
|
+
instance,
|
124
|
+
port
|
125
|
+
};
|
126
|
+
};
|
140
127
|
// Annotate the CommonJS export names for ESM import in node:
|
141
128
|
0 && (module.exports = {
|
142
129
|
devtoolsPlugin
|
package/dist/config.d.ts
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
import { ClientDefinition } from '@modern-js/devtools-kit';
|
2
|
-
import {
|
3
|
-
|
4
|
-
export interface DevtoolsPluginOptions {
|
5
|
-
def?: PartialDeep<ClientDefinition>;
|
6
|
-
}
|
1
|
+
import { ClientDefinition, SetupClientParams } from '@modern-js/devtools-kit';
|
2
|
+
import type { RequiredDeep } from 'type-fest';
|
3
|
+
export type DevtoolsPluginOptions = Partial<SetupClientParams>;
|
7
4
|
export interface DevtoolsPluginInlineOptions extends DevtoolsPluginOptions {
|
8
5
|
enable?: boolean;
|
9
6
|
}
|
7
|
+
export type DevtoolsContext = RequiredDeep<DevtoolsPluginInlineOptions>;
|
10
8
|
export declare const getDefaultOptions: () => {
|
11
9
|
def: ClientDefinition;
|
12
10
|
};
|
13
|
-
export declare const
|
14
|
-
def: ClientDefinition;
|
15
|
-
};
|
11
|
+
export declare const resolveContext: (...sources: DevtoolsPluginInlineOptions[]) => DevtoolsContext;
|
package/dist/config.js
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __create = Object.create;
|
3
2
|
var __defProp = Object.defineProperty;
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
6
|
var __export = (target, all) => {
|
9
7
|
for (var name in all)
|
@@ -17,33 +15,50 @@ var __copyProps = (to, from, except, desc) => {
|
|
17
15
|
}
|
18
16
|
return to;
|
19
17
|
};
|
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
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
19
|
var config_exports = {};
|
30
20
|
__export(config_exports, {
|
31
21
|
getDefaultOptions: () => getDefaultOptions,
|
32
|
-
|
22
|
+
resolveContext: () => resolveContext
|
33
23
|
});
|
34
24
|
module.exports = __toCommonJS(config_exports);
|
35
25
|
var import_devtools_kit = require("@modern-js/devtools-kit");
|
36
|
-
var import_lodash = __toESM(require("@modern-js/utils/lodash"));
|
37
26
|
const getDefaultOptions = () => ({
|
38
27
|
def: new import_devtools_kit.ClientDefinition()
|
39
28
|
});
|
40
|
-
const
|
41
|
-
const
|
42
|
-
|
43
|
-
|
29
|
+
const resolveContext = (...sources) => {
|
30
|
+
const ret = {
|
31
|
+
enable: process.env.NODE_ENV === "development",
|
32
|
+
dataSource: `${import_devtools_kit.ROUTE_BASENAME}/rpc`,
|
33
|
+
endpoint: import_devtools_kit.ROUTE_BASENAME,
|
34
|
+
def: new import_devtools_kit.ClientDefinition()
|
35
|
+
};
|
36
|
+
for (const opts of sources) {
|
37
|
+
var _opts_enable;
|
38
|
+
ret.enable = (_opts_enable = opts.enable) !== null && _opts_enable !== void 0 ? _opts_enable : ret.enable;
|
39
|
+
var _opts_dataSource;
|
40
|
+
ret.dataSource = (_opts_dataSource = opts.dataSource) !== null && _opts_dataSource !== void 0 ? _opts_dataSource : ret.dataSource;
|
41
|
+
var _opts_endpoint;
|
42
|
+
ret.endpoint = (_opts_endpoint = opts.endpoint) !== null && _opts_endpoint !== void 0 ? _opts_endpoint : ret.endpoint;
|
43
|
+
if (opts.def) {
|
44
|
+
if (opts.def.announcement) {
|
45
|
+
Object.assign(ret.def.announcement, opts.def.announcement);
|
46
|
+
}
|
47
|
+
if (opts.def.assets) {
|
48
|
+
Object.assign(ret.def.assets, opts.def.assets);
|
49
|
+
}
|
50
|
+
if (opts.def.name) {
|
51
|
+
Object.assign(ret.def.name, opts.def.name);
|
52
|
+
}
|
53
|
+
if (opts.def.packages) {
|
54
|
+
Object.assign(ret.def.packages, opts.def.packages);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
return ret;
|
44
59
|
};
|
45
60
|
// Annotate the CommonJS export names for ESM import in node:
|
46
61
|
0 && (module.exports = {
|
47
62
|
getDefaultOptions,
|
48
|
-
|
63
|
+
resolveContext
|
49
64
|
});
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.40.0",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/index.d.ts",
|
21
21
|
"main": "./dist/index.js",
|
@@ -45,10 +45,9 @@
|
|
45
45
|
"p-defer": "^3.0.0",
|
46
46
|
"ws": "^8.13.0",
|
47
47
|
"ufo": "^1.3.0",
|
48
|
-
"@modern-js/devtools-kit": "2.
|
49
|
-
"@modern-js/devtools-
|
50
|
-
"@modern-js/
|
51
|
-
"@modern-js/utils": "2.39.1"
|
48
|
+
"@modern-js/devtools-kit": "2.40.0",
|
49
|
+
"@modern-js/devtools-client": "2.40.0",
|
50
|
+
"@modern-js/utils": "2.40.0"
|
52
51
|
},
|
53
52
|
"devDependencies": {
|
54
53
|
"@types/serve-static": "^1.13.10",
|
@@ -57,19 +56,19 @@
|
|
57
56
|
"@types/ws": "^8.5.5",
|
58
57
|
"type-fest": "^4.1.0",
|
59
58
|
"typescript": "^5",
|
60
|
-
"@modern-js/app-tools": "2.
|
61
|
-
"@modern-js/core": "2.
|
62
|
-
"@modern-js/module-tools": "2.
|
63
|
-
"@modern-js/runtime": "2.
|
64
|
-
"@modern-js/server-core": "2.
|
65
|
-
"@modern-js/types": "2.
|
66
|
-
"@modern-js/builder-webpack-provider": "2.
|
67
|
-
"@modern-js/builder-rspack-provider": "2.
|
68
|
-
"@modern-js/builder-shared": "2.
|
69
|
-
"@scripts/build": "2.
|
59
|
+
"@modern-js/app-tools": "2.40.0",
|
60
|
+
"@modern-js/core": "2.40.0",
|
61
|
+
"@modern-js/module-tools": "2.40.0",
|
62
|
+
"@modern-js/runtime": "2.40.0",
|
63
|
+
"@modern-js/server-core": "2.40.0",
|
64
|
+
"@modern-js/types": "2.40.0",
|
65
|
+
"@modern-js/builder-webpack-provider": "2.40.0",
|
66
|
+
"@modern-js/builder-rspack-provider": "2.40.0",
|
67
|
+
"@modern-js/builder-shared": "2.40.0",
|
68
|
+
"@scripts/build": "2.40.0"
|
70
69
|
},
|
71
70
|
"peerDependencies": {
|
72
|
-
"@modern-js/runtime": "^2.
|
71
|
+
"@modern-js/runtime": "^2.40.0"
|
73
72
|
},
|
74
73
|
"peerDependenciesMeta": {
|
75
74
|
"@modern-js/runtime": {
|
package/dist/runtime.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/dist/runtime.js
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var import_devtools_mount = require("@modern-js/devtools-mount");
|
3
|
-
var import_ufo = require("ufo");
|
4
|
-
try {
|
5
|
-
const opts = (0, import_ufo.parseQuery)(__resourceQuery);
|
6
|
-
(0, import_devtools_mount.mountDevTools)(opts);
|
7
|
-
} catch (err) {
|
8
|
-
const e = new Error("Failed to execute mount point of DevTools.");
|
9
|
-
e.cause = err;
|
10
|
-
console.error(e);
|
11
|
-
}
|