@modern-js/server 2.15.1-alpha.0 → 2.17.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/CHANGELOG.md +25 -0
- package/dist/cjs/constants.js +12 -28
- package/dist/cjs/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +14 -32
- package/dist/cjs/dev-tools/dev-middleware/hmr-client/index.js +24 -42
- package/dist/cjs/dev-tools/dev-middleware/index.js +45 -50
- package/dist/cjs/dev-tools/dev-middleware/socketServer.js +48 -46
- package/dist/cjs/dev-tools/https/index.js +21 -38
- package/dist/cjs/dev-tools/mock/getMockData.js +33 -33
- package/dist/cjs/dev-tools/mock/index.js +67 -47
- package/dist/cjs/dev-tools/register/index.js +59 -70
- package/dist/cjs/dev-tools/watcher/dependencyTree.js +52 -55
- package/dist/cjs/dev-tools/watcher/index.js +52 -53
- package/dist/cjs/dev-tools/watcher/statsCache.js +37 -47
- package/dist/cjs/index.js +16 -28
- package/dist/cjs/server/devServer.js +163 -109
- package/dist/cjs/server/index.js +11 -29
- package/dist/cjs/types.js +4 -15
- package/dist/esm/constants.js +19 -20
- package/dist/esm/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +43 -44
- package/dist/esm/dev-tools/dev-middleware/hmr-client/index.js +148 -157
- package/dist/esm/dev-tools/dev-middleware/index.js +307 -291
- package/dist/esm/dev-tools/dev-middleware/socketServer.js +216 -202
- package/dist/esm/dev-tools/https/index.js +189 -182
- package/dist/esm/dev-tools/mock/getMockData.js +297 -278
- package/dist/esm/dev-tools/mock/index.js +198 -192
- package/dist/esm/dev-tools/register/index.js +141 -141
- package/dist/esm/dev-tools/watcher/dependencyTree.js +153 -138
- package/dist/esm/dev-tools/watcher/index.js +187 -175
- package/dist/esm/dev-tools/watcher/statsCache.js +118 -116
- package/dist/esm/index.js +9 -8
- package/dist/esm/server/devServer.js +803 -766
- package/dist/esm/server/index.js +80 -76
- package/dist/esm/types.js +1 -1
- package/dist/esm-node/constants.js +4 -5
- package/dist/esm-node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +2 -11
- package/dist/esm-node/dev-tools/dev-middleware/hmr-client/index.js +125 -139
- package/dist/esm-node/dev-tools/dev-middleware/index.js +31 -17
- package/dist/esm-node/dev-tools/dev-middleware/socketServer.js +33 -12
- package/dist/esm-node/dev-tools/https/index.js +13 -15
- package/dist/esm-node/dev-tools/mock/getMockData.js +20 -12
- package/dist/esm-node/dev-tools/mock/index.js +7 -7
- package/dist/esm-node/dev-tools/register/index.js +38 -29
- package/dist/esm-node/dev-tools/watcher/dependencyTree.js +32 -21
- package/dist/esm-node/dev-tools/watcher/index.js +31 -18
- package/dist/esm-node/dev-tools/watcher/statsCache.js +18 -8
- package/dist/esm-node/index.js +2 -5
- package/dist/esm-node/server/devServer.js +87 -62
- package/dist/esm-node/server/index.js +1 -4
- package/dist/esm-node/types.js +1 -0
- package/package.json +13 -9
- package/dist/js/modern/constants.js +0 -19
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -41
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +0 -143
- package/dist/js/modern/dev-tools/dev-middleware/index.js +0 -94
- package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +0 -132
- package/dist/js/modern/dev-tools/https/index.js +0 -49
- package/dist/js/modern/dev-tools/mock/getMockData.js +0 -114
- package/dist/js/modern/dev-tools/mock/index.js +0 -54
- package/dist/js/modern/dev-tools/register/index.js +0 -111
- package/dist/js/modern/dev-tools/watcher/dependency-tree.js +0 -59
- package/dist/js/modern/dev-tools/watcher/index.js +0 -106
- package/dist/js/modern/dev-tools/watcher/stats-cache.js +0 -58
- package/dist/js/modern/index.js +0 -12
- package/dist/js/modern/server/dev-server.js +0 -293
- package/dist/js/modern/server/index.js +0 -16
- package/dist/js/modern/types.js +0 -0
- package/dist/js/node/constants.js +0 -42
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -65
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +0 -152
- package/dist/js/node/dev-tools/dev-middleware/index.js +0 -119
- package/dist/js/node/dev-tools/dev-middleware/socket-server.js +0 -159
- package/dist/js/node/dev-tools/https/index.js +0 -72
- package/dist/js/node/dev-tools/mock/getMockData.js +0 -135
- package/dist/js/node/dev-tools/mock/index.js +0 -83
- package/dist/js/node/dev-tools/register/index.js +0 -138
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +0 -89
- package/dist/js/node/dev-tools/watcher/index.js +0 -135
- package/dist/js/node/dev-tools/watcher/stats-cache.js +0 -87
- package/dist/js/node/index.js +0 -35
- package/dist/js/node/server/dev-server.js +0 -310
- package/dist/js/node/server/index.js +0 -39
- package/dist/js/node/types.js +0 -15
- package/dist/js/treeshaking/constants.js +0 -21
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -51
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +0 -157
- package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +0 -322
- package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +0 -209
- package/dist/js/treeshaking/dev-tools/https/index.js +0 -193
- package/dist/js/treeshaking/dev-tools/mock/getMockData.js +0 -327
- package/dist/js/treeshaking/dev-tools/mock/index.js +0 -191
- package/dist/js/treeshaking/dev-tools/register/index.js +0 -153
- package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +0 -150
- package/dist/js/treeshaking/dev-tools/watcher/index.js +0 -200
- package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +0 -128
- package/dist/js/treeshaking/index.js +0 -9
- package/dist/js/treeshaking/server/dev-server.js +0 -799
- package/dist/js/treeshaking/server/index.js +0 -92
- package/dist/js/treeshaking/types.js +0 -1
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __reflectGet = Reflect.get;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
-
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
23
|
-
var __async = (__this, __arguments, generator) => {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
var fulfilled = (value) => {
|
|
26
|
-
try {
|
|
27
|
-
step(generator.next(value));
|
|
28
|
-
} catch (e) {
|
|
29
|
-
reject(e);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
var rejected = (value) => {
|
|
33
|
-
try {
|
|
34
|
-
step(generator.throw(value));
|
|
35
|
-
} catch (e) {
|
|
36
|
-
reject(e);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
40
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
import { createServer } from "http";
|
|
44
|
-
import path from "path";
|
|
45
|
-
import { createServer as createHttpsServer } from "https";
|
|
46
|
-
import {
|
|
47
|
-
API_DIR,
|
|
48
|
-
SERVER_BUNDLE_DIRECTORY,
|
|
49
|
-
SERVER_DIR,
|
|
50
|
-
SHARED_DIR
|
|
51
|
-
} from "@modern-js/utils";
|
|
52
|
-
import {
|
|
53
|
-
createProxyHandler,
|
|
54
|
-
ModernServer,
|
|
55
|
-
AGGRED_DIR
|
|
56
|
-
} from "@modern-js/prod-server";
|
|
57
|
-
import { LOADABLE_STATS_FILE } from "@modern-js/utils/constants";
|
|
58
|
-
import { getDefaultDevOptions } from "../constants";
|
|
59
|
-
import { createMockHandler } from "../dev-tools/mock";
|
|
60
|
-
import { enableRegister } from "../dev-tools/register";
|
|
61
|
-
import Watcher, { mergeWatchOptions } from "../dev-tools/watcher";
|
|
62
|
-
import DevMiddleware from "../dev-tools/dev-middleware";
|
|
63
|
-
class ModernDevServer extends ModernServer {
|
|
64
|
-
constructor(options) {
|
|
65
|
-
super(options);
|
|
66
|
-
this.mockHandler = null;
|
|
67
|
-
this.workDir = this.pwd;
|
|
68
|
-
this.dev = this.getDevOptions(options);
|
|
69
|
-
this.devMiddleware = new DevMiddleware({
|
|
70
|
-
dev: this.dev,
|
|
71
|
-
devMiddleware: options.devMiddleware
|
|
72
|
-
});
|
|
73
|
-
enableRegister(this.pwd, this.conf);
|
|
74
|
-
}
|
|
75
|
-
getDevOptions(options) {
|
|
76
|
-
const devOptions = typeof options.dev === "boolean" ? {} : options.dev;
|
|
77
|
-
const defaultOptions = getDefaultDevOptions();
|
|
78
|
-
return __spreadProps(__spreadValues(__spreadValues({}, defaultOptions), devOptions), {
|
|
79
|
-
client: __spreadValues(__spreadValues({}, defaultOptions.client), devOptions == null ? void 0 : devOptions.client)
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
addMiddlewareHandler(handlers) {
|
|
83
|
-
handlers.forEach((handler) => {
|
|
84
|
-
this.addHandler((ctx, next) => {
|
|
85
|
-
const { req, res } = ctx;
|
|
86
|
-
return handler(req, res, next);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
applySetupMiddlewares() {
|
|
91
|
-
const setupMiddlewares = this.dev.setupMiddlewares || [];
|
|
92
|
-
const serverOptions = {
|
|
93
|
-
sockWrite: (type, data) => this.devMiddleware.sockWrite(type, data)
|
|
94
|
-
};
|
|
95
|
-
const befores = [];
|
|
96
|
-
const afters = [];
|
|
97
|
-
setupMiddlewares.forEach((handler) => {
|
|
98
|
-
handler(
|
|
99
|
-
{
|
|
100
|
-
unshift: (...handlers) => befores.unshift(...handlers),
|
|
101
|
-
push: (...handlers) => afters.push(...handlers)
|
|
102
|
-
},
|
|
103
|
-
serverOptions
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
return { befores, afters };
|
|
107
|
-
}
|
|
108
|
-
onInit(runner, app) {
|
|
109
|
-
return __async(this, null, function* () {
|
|
110
|
-
this.runner = runner;
|
|
111
|
-
const { dev } = this;
|
|
112
|
-
const { befores, afters } = this.applySetupMiddlewares();
|
|
113
|
-
const beforeHandlers = yield this.setupBeforeDevMiddleware();
|
|
114
|
-
this.addMiddlewareHandler([...beforeHandlers, ...befores]);
|
|
115
|
-
yield this.applyDefaultMiddlewares(app);
|
|
116
|
-
const afterHandlers = yield this.setupAfterDevMiddleware();
|
|
117
|
-
this.addMiddlewareHandler([...afters, ...afterHandlers]);
|
|
118
|
-
yield __superGet(ModernDevServer.prototype, this, "onInit").call(this, runner, app);
|
|
119
|
-
if (dev.watch) {
|
|
120
|
-
this.startWatcher();
|
|
121
|
-
app.on("close", () => __async(this, null, function* () {
|
|
122
|
-
var _a;
|
|
123
|
-
yield (_a = this.watcher) == null ? void 0 : _a.close();
|
|
124
|
-
}));
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
applyDefaultMiddlewares(app) {
|
|
129
|
-
return __async(this, null, function* () {
|
|
130
|
-
const { pwd, dev, devMiddleware } = this;
|
|
131
|
-
this.addHandler((ctx, next) => {
|
|
132
|
-
ctx.res.setHeader("Access-Control-Allow-Origin", "*");
|
|
133
|
-
if (ctx.path.includes("hot-update")) {
|
|
134
|
-
ctx.res.setHeader("Access-Control-Allow-Credentials", "false");
|
|
135
|
-
}
|
|
136
|
-
const confHeaders = dev.headers;
|
|
137
|
-
if (confHeaders) {
|
|
138
|
-
for (const [key, value] of Object.entries(confHeaders)) {
|
|
139
|
-
ctx.res.setHeader(key, value);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
next();
|
|
143
|
-
});
|
|
144
|
-
this.mockHandler = createMockHandler({ pwd });
|
|
145
|
-
this.addHandler((ctx, next) => {
|
|
146
|
-
if (this.mockHandler) {
|
|
147
|
-
this.mockHandler(ctx, next);
|
|
148
|
-
} else {
|
|
149
|
-
next();
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
const proxyHandlers = createProxyHandler(dev.proxy);
|
|
153
|
-
if (proxyHandlers) {
|
|
154
|
-
proxyHandlers.forEach((handler) => {
|
|
155
|
-
this.addHandler(handler);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
devMiddleware.init(app);
|
|
159
|
-
devMiddleware.on("change", (stats) => {
|
|
160
|
-
if (stats.toJson({ all: false }).name === "client") {
|
|
161
|
-
this.onRepack({ routes: this.getRoutes() });
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
this.addHandler((ctx, next) => {
|
|
165
|
-
const { req, res } = ctx;
|
|
166
|
-
if (devMiddleware.middleware) {
|
|
167
|
-
devMiddleware.middleware(req, res, next);
|
|
168
|
-
} else {
|
|
169
|
-
next();
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
if (dev.historyApiFallback) {
|
|
173
|
-
const { default: connectHistoryApiFallback } = yield import("connect-history-api-fallback");
|
|
174
|
-
const historyApiFallbackMiddleware = connectHistoryApiFallback(
|
|
175
|
-
typeof dev.historyApiFallback === "boolean" ? {} : dev.historyApiFallback
|
|
176
|
-
);
|
|
177
|
-
this.addHandler(
|
|
178
|
-
(ctx, next) => historyApiFallbackMiddleware(ctx.req, ctx.res, next)
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
onRepack(options = {}) {
|
|
184
|
-
if (Array.isArray(options.routes)) {
|
|
185
|
-
this.router.reset(this.filterRoutes(options.routes));
|
|
186
|
-
}
|
|
187
|
-
this.cleanSSRCache();
|
|
188
|
-
this.reader.updateFile();
|
|
189
|
-
super.onRepack(options);
|
|
190
|
-
}
|
|
191
|
-
createHTTPServer(handler) {
|
|
192
|
-
return __async(this, null, function* () {
|
|
193
|
-
const { dev } = this;
|
|
194
|
-
const devHttpsOption = typeof dev === "object" && dev.https;
|
|
195
|
-
if (devHttpsOption) {
|
|
196
|
-
const { genHttpsOptions } = require("../dev-tools/https");
|
|
197
|
-
const httpsOptions = yield genHttpsOptions(devHttpsOption, this.pwd);
|
|
198
|
-
return createHttpsServer(httpsOptions, handler);
|
|
199
|
-
} else {
|
|
200
|
-
return createServer(handler);
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
warmupSSRBundle() {
|
|
205
|
-
}
|
|
206
|
-
onServerChange({
|
|
207
|
-
filepath,
|
|
208
|
-
event
|
|
209
|
-
}) {
|
|
210
|
-
const { pwd } = this;
|
|
211
|
-
const { mock } = AGGRED_DIR;
|
|
212
|
-
const mockPath = path.normalize(path.join(pwd, mock));
|
|
213
|
-
this.runner.reset();
|
|
214
|
-
if (filepath.startsWith(mockPath)) {
|
|
215
|
-
this.mockHandler = createMockHandler({ pwd });
|
|
216
|
-
} else {
|
|
217
|
-
try {
|
|
218
|
-
const success = this.runner.onApiChange([
|
|
219
|
-
{ filename: filepath, event }
|
|
220
|
-
]);
|
|
221
|
-
if (success !== true) {
|
|
222
|
-
super.onServerChange({ filepath });
|
|
223
|
-
}
|
|
224
|
-
} catch (e) {
|
|
225
|
-
this.logger.error(e);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
createContext(req, res) {
|
|
230
|
-
return super.createContext(req, res, { etag: true });
|
|
231
|
-
}
|
|
232
|
-
setupBeforeDevMiddleware() {
|
|
233
|
-
return __async(this, null, function* () {
|
|
234
|
-
const { runner, conf, dev } = this;
|
|
235
|
-
const setupMids = dev.before || [];
|
|
236
|
-
const pluginMids = yield runner.beforeDevServer(conf);
|
|
237
|
-
return [...setupMids, ...pluginMids].flat();
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
setupAfterDevMiddleware() {
|
|
241
|
-
return __async(this, null, function* () {
|
|
242
|
-
const { runner, conf, dev } = this;
|
|
243
|
-
const setupMids = dev.after || [];
|
|
244
|
-
const pluginMids = yield runner.afterDevServer(conf);
|
|
245
|
-
return [...pluginMids, ...setupMids].flat();
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
cleanSSRCache() {
|
|
249
|
-
const { distDir } = this;
|
|
250
|
-
const bundles = this.router.getBundles();
|
|
251
|
-
bundles.forEach((bundle) => {
|
|
252
|
-
const filepath = path.join(distDir, bundle);
|
|
253
|
-
if (require.cache[filepath]) {
|
|
254
|
-
delete require.cache[filepath];
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
const loadable = path.join(distDir, LOADABLE_STATS_FILE);
|
|
258
|
-
if (require.cache[loadable]) {
|
|
259
|
-
delete require.cache[loadable];
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
startWatcher() {
|
|
263
|
-
var _a;
|
|
264
|
-
const { pwd, distDir } = this;
|
|
265
|
-
const { mock } = AGGRED_DIR;
|
|
266
|
-
const defaultWatched = [
|
|
267
|
-
`${mock}/**/*`,
|
|
268
|
-
`${SERVER_DIR}/**/*`,
|
|
269
|
-
`${API_DIR}/**`,
|
|
270
|
-
`${SHARED_DIR}/**/*`,
|
|
271
|
-
`${distDir}/${SERVER_BUNDLE_DIRECTORY}/*-server-loaders.js`
|
|
272
|
-
];
|
|
273
|
-
const watchOptions = mergeWatchOptions((_a = this.conf.server) == null ? void 0 : _a.watchOptions);
|
|
274
|
-
const defaultWatchedPaths = defaultWatched.map((p) => {
|
|
275
|
-
const finalPath = path.isAbsolute(p) ? p : path.join(pwd, p);
|
|
276
|
-
return path.normalize(finalPath);
|
|
277
|
-
});
|
|
278
|
-
const watcher = new Watcher();
|
|
279
|
-
watcher.createDepTree();
|
|
280
|
-
watcher.listen(defaultWatchedPaths, watchOptions, (filepath, event) => {
|
|
281
|
-
watcher.updateDepTree();
|
|
282
|
-
watcher.cleanDepCache(filepath);
|
|
283
|
-
this.onServerChange({
|
|
284
|
-
filepath,
|
|
285
|
-
event
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
this.watcher = watcher;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
export {
|
|
292
|
-
ModernDevServer
|
|
293
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Server } from "@modern-js/prod-server";
|
|
2
|
-
import { ModernDevServer } from "./dev-server";
|
|
3
|
-
const createDevServer = (options) => {
|
|
4
|
-
return new ModernDevServer(options);
|
|
5
|
-
};
|
|
6
|
-
class DevServer extends Server {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
super(options);
|
|
9
|
-
if (options.dev) {
|
|
10
|
-
this.serverImpl = createDevServer;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export {
|
|
15
|
-
DevServer
|
|
16
|
-
};
|
package/dist/js/modern/types.js
DELETED
|
File without changes
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var constants_exports = {};
|
|
19
|
-
__export(constants_exports, {
|
|
20
|
-
getDefaultDevOptions: () => getDefaultDevOptions
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(constants_exports);
|
|
23
|
-
var import_utils = require("@modern-js/utils");
|
|
24
|
-
const getDefaultDevOptions = () => {
|
|
25
|
-
const network = (0, import_utils.getIpv4Interfaces)().find((item) => !item.internal);
|
|
26
|
-
return {
|
|
27
|
-
client: {
|
|
28
|
-
port: "8080",
|
|
29
|
-
path: import_utils.HMR_SOCK_PATH,
|
|
30
|
-
host: (network == null ? void 0 : network.address) || "localhost"
|
|
31
|
-
},
|
|
32
|
-
https: false,
|
|
33
|
-
devMiddleware: { writeToDisk: true },
|
|
34
|
-
watch: true,
|
|
35
|
-
hot: true,
|
|
36
|
-
liveReload: true
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
-
0 && (module.exports = {
|
|
41
|
-
getDefaultDevOptions
|
|
42
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var createSocketUrl_exports = {};
|
|
19
|
-
__export(createSocketUrl_exports, {
|
|
20
|
-
createSocketUrl: () => createSocketUrl,
|
|
21
|
-
formatURL: () => formatURL
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(createSocketUrl_exports);
|
|
24
|
-
var import_constants = require("@modern-js/utils/constants");
|
|
25
|
-
function createSocketUrl(resourceQuery) {
|
|
26
|
-
const searchParams = resourceQuery.substr(1).split("&");
|
|
27
|
-
const options = {};
|
|
28
|
-
for (const pair of searchParams) {
|
|
29
|
-
const ary = pair.split("=");
|
|
30
|
-
options[ary[0]] = decodeURIComponent(ary[1]);
|
|
31
|
-
}
|
|
32
|
-
const currentLocation = self.location;
|
|
33
|
-
return getSocketUrl(options, currentLocation);
|
|
34
|
-
}
|
|
35
|
-
function formatURL({
|
|
36
|
-
port,
|
|
37
|
-
protocol,
|
|
38
|
-
hostname,
|
|
39
|
-
pathname
|
|
40
|
-
}) {
|
|
41
|
-
if (window.URL) {
|
|
42
|
-
const url = new URL("http://localhost");
|
|
43
|
-
url.port = port;
|
|
44
|
-
url.hostname = hostname;
|
|
45
|
-
url.protocol = protocol;
|
|
46
|
-
url.pathname = pathname;
|
|
47
|
-
return url.toString();
|
|
48
|
-
}
|
|
49
|
-
const colon = protocol.indexOf(":") === -1 ? ":" : "";
|
|
50
|
-
return `${protocol}${colon}//${hostname}:${port}${pathname}`;
|
|
51
|
-
}
|
|
52
|
-
function getSocketUrl(urlParts, location) {
|
|
53
|
-
const { host, port, path, protocol } = urlParts;
|
|
54
|
-
return formatURL({
|
|
55
|
-
protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
|
|
56
|
-
hostname: host || location.hostname,
|
|
57
|
-
port: port || location.port,
|
|
58
|
-
pathname: path || import_constants.HMR_SOCK_PATH
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
-
0 && (module.exports = {
|
|
63
|
-
createSocketUrl,
|
|
64
|
-
formatURL
|
|
65
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
-
for (let key of __getOwnPropNames(from))
|
|
10
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
}
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
17
|
-
mod
|
|
18
|
-
));
|
|
19
|
-
var import_strip_ansi = __toESM(require("@modern-js/utils/strip-ansi"));
|
|
20
|
-
var import_format = require("@modern-js/utils/format");
|
|
21
|
-
var import_createSocketUrl = require("./createSocketUrl");
|
|
22
|
-
const hadRuntimeError = false;
|
|
23
|
-
const socketUrl = (0, import_createSocketUrl.createSocketUrl)(__resourceQuery);
|
|
24
|
-
const connection = new WebSocket(socketUrl);
|
|
25
|
-
connection.onclose = function() {
|
|
26
|
-
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
27
|
-
console.info(
|
|
28
|
-
"The development server has disconnected.\nRefresh the page if necessary."
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
let isFirstCompilation = true;
|
|
33
|
-
let mostRecentCompilationHash = null;
|
|
34
|
-
let hasCompileErrors = false;
|
|
35
|
-
function clearOutdatedErrors() {
|
|
36
|
-
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
37
|
-
if (hasCompileErrors) {
|
|
38
|
-
console.clear();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function handleSuccess() {
|
|
43
|
-
clearOutdatedErrors();
|
|
44
|
-
const isHotUpdate = !isFirstCompilation;
|
|
45
|
-
isFirstCompilation = false;
|
|
46
|
-
hasCompileErrors = false;
|
|
47
|
-
if (isHotUpdate) {
|
|
48
|
-
tryApplyUpdates();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function handleWarnings(warnings) {
|
|
52
|
-
clearOutdatedErrors();
|
|
53
|
-
const isHotUpdate = !isFirstCompilation;
|
|
54
|
-
isFirstCompilation = false;
|
|
55
|
-
hasCompileErrors = false;
|
|
56
|
-
function printWarnings() {
|
|
57
|
-
const formatted = (0, import_format.formatWebpackMessages)({
|
|
58
|
-
warnings,
|
|
59
|
-
errors: []
|
|
60
|
-
});
|
|
61
|
-
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
62
|
-
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
63
|
-
if (i === 5) {
|
|
64
|
-
console.warn(
|
|
65
|
-
"There were more warnings in other files.\nYou can find a complete log in the terminal."
|
|
66
|
-
);
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
console.warn((0, import_strip_ansi.default)(formatted.warnings[i]));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
printWarnings();
|
|
74
|
-
if (isHotUpdate) {
|
|
75
|
-
tryApplyUpdates();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function handleErrors(errors) {
|
|
79
|
-
clearOutdatedErrors();
|
|
80
|
-
isFirstCompilation = false;
|
|
81
|
-
hasCompileErrors = true;
|
|
82
|
-
const formatted = (0, import_format.formatWebpackMessages)({
|
|
83
|
-
errors,
|
|
84
|
-
warnings: []
|
|
85
|
-
});
|
|
86
|
-
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
87
|
-
for (const error of formatted.errors) {
|
|
88
|
-
console.error((0, import_strip_ansi.default)(error));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function handleAvailableHash(hash) {
|
|
93
|
-
mostRecentCompilationHash = hash;
|
|
94
|
-
}
|
|
95
|
-
connection.onmessage = function(e) {
|
|
96
|
-
const message = JSON.parse(e.data);
|
|
97
|
-
switch (message.type) {
|
|
98
|
-
case "hash":
|
|
99
|
-
handleAvailableHash(message.data);
|
|
100
|
-
break;
|
|
101
|
-
case "still-ok":
|
|
102
|
-
case "ok":
|
|
103
|
-
handleSuccess();
|
|
104
|
-
break;
|
|
105
|
-
case "content-changed":
|
|
106
|
-
window.location.reload();
|
|
107
|
-
break;
|
|
108
|
-
case "warnings":
|
|
109
|
-
handleWarnings(message.data);
|
|
110
|
-
break;
|
|
111
|
-
case "errors":
|
|
112
|
-
handleErrors(message.data);
|
|
113
|
-
break;
|
|
114
|
-
default:
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
function isUpdateAvailable() {
|
|
118
|
-
return mostRecentCompilationHash !== __webpack_hash__;
|
|
119
|
-
}
|
|
120
|
-
function canApplyUpdates() {
|
|
121
|
-
return module.hot.status() === "idle";
|
|
122
|
-
}
|
|
123
|
-
function tryApplyUpdates() {
|
|
124
|
-
if (!module.hot) {
|
|
125
|
-
window.location.reload();
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
function handleApplyUpdates(err, updatedModules) {
|
|
132
|
-
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
133
|
-
if (wantsForcedReload) {
|
|
134
|
-
window.location.reload();
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (isUpdateAvailable()) {
|
|
138
|
-
tryApplyUpdates();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const result = module.hot.check(true, handleApplyUpdates);
|
|
142
|
-
if (result == null ? void 0 : result.then) {
|
|
143
|
-
result.then(
|
|
144
|
-
(updatedModules) => {
|
|
145
|
-
handleApplyUpdates(null, updatedModules);
|
|
146
|
-
},
|
|
147
|
-
(err) => {
|
|
148
|
-
handleApplyUpdates(err, null);
|
|
149
|
-
}
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
|
-
var __export = (target, all) => {
|
|
22
|
-
for (var name in all)
|
|
23
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
-
};
|
|
25
|
-
var __copyProps = (to, from, except, desc) => {
|
|
26
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
-
for (let key of __getOwnPropNames(from))
|
|
28
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
-
}
|
|
31
|
-
return to;
|
|
32
|
-
};
|
|
33
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
34
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
-
mod
|
|
36
|
-
));
|
|
37
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
-
var __async = (__this, __arguments, generator) => {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
var fulfilled = (value) => {
|
|
41
|
-
try {
|
|
42
|
-
step(generator.next(value));
|
|
43
|
-
} catch (e) {
|
|
44
|
-
reject(e);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
var rejected = (value) => {
|
|
48
|
-
try {
|
|
49
|
-
step(generator.throw(value));
|
|
50
|
-
} catch (e) {
|
|
51
|
-
reject(e);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
55
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
var dev_middleware_exports = {};
|
|
59
|
-
__export(dev_middleware_exports, {
|
|
60
|
-
default: () => DevMiddleware
|
|
61
|
-
});
|
|
62
|
-
module.exports = __toCommonJS(dev_middleware_exports);
|
|
63
|
-
var import_events = require("events");
|
|
64
|
-
var import_socket_server = __toESM(require("./socket-server"));
|
|
65
|
-
const noop = () => {
|
|
66
|
-
};
|
|
67
|
-
function getHMRClientPath(client) {
|
|
68
|
-
const protocol = (client == null ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
|
|
69
|
-
const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
70
|
-
const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
71
|
-
const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
72
|
-
const clientEntry = `${require.resolve("./hmr-client")}?${host}${path}${port}${protocol}`;
|
|
73
|
-
return clientEntry;
|
|
74
|
-
}
|
|
75
|
-
class DevMiddleware extends import_events.EventEmitter {
|
|
76
|
-
constructor({ dev, devMiddleware }) {
|
|
77
|
-
super();
|
|
78
|
-
this.devOptions = dev;
|
|
79
|
-
this.socketServer = new import_socket_server.default(dev);
|
|
80
|
-
if (devMiddleware) {
|
|
81
|
-
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
init(app) {
|
|
85
|
-
app.on("listening", () => {
|
|
86
|
-
this.socketServer.prepare(app);
|
|
87
|
-
});
|
|
88
|
-
app.on("close", () => __async(this, null, function* () {
|
|
89
|
-
var _a;
|
|
90
|
-
(_a = this.middleware) == null ? void 0 : _a.close(noop);
|
|
91
|
-
this.socketServer.close();
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
sockWrite(type, data) {
|
|
95
|
-
this.socketServer.sockWrite(type, data);
|
|
96
|
-
}
|
|
97
|
-
setupDevMiddleware(devMiddleware) {
|
|
98
|
-
const { devOptions } = this;
|
|
99
|
-
const callbacks = {
|
|
100
|
-
onInvalid: () => {
|
|
101
|
-
this.socketServer.sockWrite("invalid");
|
|
102
|
-
},
|
|
103
|
-
onDone: (stats) => {
|
|
104
|
-
this.socketServer.updateStats(stats);
|
|
105
|
-
this.emit("change", stats);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const enableHMR = this.devOptions.hot || this.devOptions.liveReload;
|
|
109
|
-
const middleware = devMiddleware(__spreadValues({
|
|
110
|
-
headers: devOptions.headers,
|
|
111
|
-
stats: false,
|
|
112
|
-
callbacks,
|
|
113
|
-
hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0
|
|
114
|
-
}, devOptions.devMiddleware));
|
|
115
|
-
return middleware;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
119
|
-
0 && (module.exports = {});
|