@modern-js/plugin-devtools 0.0.0-nightly-20231107170721 → 0.0.0-nightly-20231108170733
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 +38 -36
- package/dist/config.d.ts +5 -9
- package/dist/config.js +32 -17
- package/package.json +15 -15
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/client/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)({
|
@@ -80,34 +62,30 @@ const devtoolsPlugin = (options) => ({
|
|
80
62
|
prepare: rpc.hooks.prepare,
|
81
63
|
modifyFileSystemRoutes: rpc.hooks.modifyFileSystemRoutes,
|
82
64
|
beforeRestart() {
|
83
|
-
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()));
|
84
66
|
},
|
85
67
|
config() {
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
const mountOpts = {
|
90
|
-
dataSource: `${import_devtools_kit.ROUTE_BASENAME}/rpc`,
|
91
|
-
endpoint: import_devtools_kit.ROUTE_BASENAME,
|
92
|
-
def: new import_devtools_kit.ClientDefinition(),
|
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), {
|
93
71
|
__keep: true
|
94
|
-
};
|
95
|
-
|
96
|
-
runtimeEntry =
|
72
|
+
});
|
73
|
+
import_utils.logger.info(`${ctx.def.name.formalName} Devtools is enabled`);
|
74
|
+
const runtimeEntry = require.resolve("@modern-js/devtools-client/mount");
|
97
75
|
return {
|
98
76
|
builderPlugins: [
|
99
77
|
rpc.builderPlugin
|
100
78
|
],
|
101
79
|
source: {
|
102
80
|
preEntry: [
|
103
|
-
runtimeEntry
|
81
|
+
(0, import_ufo.withQuery)(runtimeEntry, ctx)
|
104
82
|
]
|
105
83
|
},
|
106
84
|
tools: {
|
107
85
|
devServer: {
|
108
86
|
proxy: {
|
109
87
|
[import_devtools_kit.ROUTE_BASENAME]: {
|
110
|
-
target: `http://localhost:${port}`,
|
88
|
+
target: `http://localhost:${httpServer.port}`,
|
111
89
|
pathRewrite: {
|
112
90
|
[`^${import_devtools_kit.ROUTE_BASENAME}`]: ""
|
113
91
|
},
|
@@ -122,6 +100,30 @@ const devtoolsPlugin = (options) => ({
|
|
122
100
|
}
|
123
101
|
});
|
124
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
|
+
};
|
125
127
|
// Annotate the CommonJS export names for ESM import in node:
|
126
128
|
0 && (module.exports = {
|
127
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": "0.0.0-nightly-
|
18
|
+
"version": "0.0.0-nightly-20231108170733",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/index.d.ts",
|
21
21
|
"main": "./dist/index.js",
|
@@ -45,9 +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": "0.0.0-nightly-
|
49
|
-
"@modern-js/devtools-client": "0.0.0-nightly-
|
50
|
-
"@modern-js/utils": "0.0.0-nightly-
|
48
|
+
"@modern-js/devtools-kit": "0.0.0-nightly-20231108170733",
|
49
|
+
"@modern-js/devtools-client": "0.0.0-nightly-20231108170733",
|
50
|
+
"@modern-js/utils": "0.0.0-nightly-20231108170733"
|
51
51
|
},
|
52
52
|
"devDependencies": {
|
53
53
|
"@types/serve-static": "^1.13.10",
|
@@ -56,19 +56,19 @@
|
|
56
56
|
"@types/ws": "^8.5.5",
|
57
57
|
"type-fest": "^4.1.0",
|
58
58
|
"typescript": "^5",
|
59
|
-
"@modern-js/app-tools": "0.0.0-nightly-
|
60
|
-
"@modern-js/core": "0.0.0-nightly-
|
61
|
-
"@modern-js/module-tools": "0.0.0-nightly-
|
62
|
-
"@modern-js/runtime": "0.0.0-nightly-
|
63
|
-
"@modern-js/server-core": "0.0.0-nightly-
|
64
|
-
"@modern-js/types": "0.0.0-nightly-
|
65
|
-
"@modern-js/builder-webpack-provider": "0.0.0-nightly-
|
66
|
-
"@modern-js/builder-rspack-provider": "0.0.0-nightly-
|
67
|
-
"@modern-js/builder-shared": "0.0.0-nightly-
|
68
|
-
"@scripts/build": "0.0.0-nightly-
|
59
|
+
"@modern-js/app-tools": "0.0.0-nightly-20231108170733",
|
60
|
+
"@modern-js/core": "0.0.0-nightly-20231108170733",
|
61
|
+
"@modern-js/module-tools": "0.0.0-nightly-20231108170733",
|
62
|
+
"@modern-js/runtime": "0.0.0-nightly-20231108170733",
|
63
|
+
"@modern-js/server-core": "0.0.0-nightly-20231108170733",
|
64
|
+
"@modern-js/types": "0.0.0-nightly-20231108170733",
|
65
|
+
"@modern-js/builder-webpack-provider": "0.0.0-nightly-20231108170733",
|
66
|
+
"@modern-js/builder-rspack-provider": "0.0.0-nightly-20231108170733",
|
67
|
+
"@modern-js/builder-shared": "0.0.0-nightly-20231108170733",
|
68
|
+
"@scripts/build": "0.0.0-nightly-20231108170733"
|
69
69
|
},
|
70
70
|
"peerDependencies": {
|
71
|
-
"@modern-js/runtime": "0.0.0-nightly-
|
71
|
+
"@modern-js/runtime": "0.0.0-nightly-20231108170733"
|
72
72
|
},
|
73
73
|
"peerDependenciesMeta": {
|
74
74
|
"@modern-js/runtime": {
|