@modern-js/server 2.14.0 → 2.15.1-alpha.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 +9 -0
- package/dist/cjs/server/devServer.js +2 -2
- package/dist/esm/server/devServer.js +68 -24
- package/dist/esm-node/server/devServer.js +2 -2
- package/dist/js/modern/constants.js +19 -0
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +41 -0
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +143 -0
- package/dist/js/modern/dev-tools/dev-middleware/index.js +94 -0
- package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +132 -0
- package/dist/js/modern/dev-tools/https/index.js +49 -0
- package/dist/js/modern/dev-tools/mock/getMockData.js +114 -0
- package/dist/js/modern/dev-tools/mock/index.js +54 -0
- package/dist/js/modern/dev-tools/register/index.js +111 -0
- package/dist/js/modern/dev-tools/watcher/dependency-tree.js +59 -0
- package/dist/js/modern/dev-tools/watcher/index.js +106 -0
- package/dist/js/modern/dev-tools/watcher/stats-cache.js +58 -0
- package/dist/js/modern/index.js +12 -0
- package/dist/js/modern/server/dev-server.js +293 -0
- package/dist/js/modern/server/index.js +16 -0
- package/dist/js/modern/types.js +0 -0
- package/dist/js/node/constants.js +42 -0
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +65 -0
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +152 -0
- package/dist/js/node/dev-tools/dev-middleware/index.js +119 -0
- package/dist/js/node/dev-tools/dev-middleware/socket-server.js +159 -0
- package/dist/js/node/dev-tools/https/index.js +72 -0
- package/dist/js/node/dev-tools/mock/getMockData.js +135 -0
- package/dist/js/node/dev-tools/mock/index.js +83 -0
- package/dist/js/node/dev-tools/register/index.js +138 -0
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +89 -0
- package/dist/js/node/dev-tools/watcher/index.js +135 -0
- package/dist/js/node/dev-tools/watcher/stats-cache.js +87 -0
- package/dist/js/node/index.js +35 -0
- package/dist/js/node/server/dev-server.js +310 -0
- package/dist/js/node/server/index.js +39 -0
- package/dist/js/node/types.js +15 -0
- package/dist/js/treeshaking/constants.js +21 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +51 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +157 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +322 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +209 -0
- package/dist/js/treeshaking/dev-tools/https/index.js +193 -0
- package/dist/js/treeshaking/dev-tools/mock/getMockData.js +327 -0
- package/dist/js/treeshaking/dev-tools/mock/index.js +191 -0
- package/dist/js/treeshaking/dev-tools/register/index.js +153 -0
- package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +150 -0
- package/dist/js/treeshaking/dev-tools/watcher/index.js +200 -0
- package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +128 -0
- package/dist/js/treeshaking/index.js +9 -0
- package/dist/js/treeshaking/server/dev-server.js +799 -0
- package/dist/js/treeshaking/server/index.js +92 -0
- package/dist/js/treeshaking/types.js +1 -0
- package/dist/types/server/devServer.d.ts +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,135 @@
|
|
|
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 watcher_exports = {};
|
|
39
|
+
__export(watcher_exports, {
|
|
40
|
+
default: () => Watcher,
|
|
41
|
+
defaultWatchOptions: () => defaultWatchOptions,
|
|
42
|
+
getWatchedFiles: () => getWatchedFiles,
|
|
43
|
+
mergeWatchOptions: () => mergeWatchOptions
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(watcher_exports);
|
|
46
|
+
var import_path = __toESM(require("path"));
|
|
47
|
+
var import_utils = require("@modern-js/utils");
|
|
48
|
+
var import_dependency_tree = require("./dependency-tree");
|
|
49
|
+
var import_stats_cache = require("./stats-cache");
|
|
50
|
+
const defaultWatchOptions = {
|
|
51
|
+
ignoreInitial: true,
|
|
52
|
+
ignored: /api\/typings\/.*/
|
|
53
|
+
};
|
|
54
|
+
const getWatchedFiles = (watcher) => {
|
|
55
|
+
const watched = watcher.getWatched();
|
|
56
|
+
const files = [];
|
|
57
|
+
Object.keys(watched).forEach((dir) => {
|
|
58
|
+
watched[dir].forEach((fileName) => {
|
|
59
|
+
files.push(import_path.default.join(dir, fileName));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
return files;
|
|
63
|
+
};
|
|
64
|
+
const mergeWatchOptions = (options) => {
|
|
65
|
+
const watchOptions = __spreadValues({}, options);
|
|
66
|
+
if (watchOptions) {
|
|
67
|
+
const { ignored } = watchOptions;
|
|
68
|
+
const finalIgnored = ignored ? [
|
|
69
|
+
defaultWatchOptions.ignored,
|
|
70
|
+
...Array.isArray(ignored) ? ignored : [ignored]
|
|
71
|
+
] : ignored;
|
|
72
|
+
if (finalIgnored) {
|
|
73
|
+
watchOptions.ignored = finalIgnored;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const finalWatchOptions = __spreadValues(__spreadValues({}, defaultWatchOptions), watchOptions);
|
|
77
|
+
return finalWatchOptions;
|
|
78
|
+
};
|
|
79
|
+
class Watcher {
|
|
80
|
+
constructor() {
|
|
81
|
+
this.dependencyTree = null;
|
|
82
|
+
}
|
|
83
|
+
listen(files, options, callback) {
|
|
84
|
+
const watched = files.filter(Boolean);
|
|
85
|
+
const filenames = watched.map((filename) => filename.replace(/\\/g, "/"));
|
|
86
|
+
const cache = new import_stats_cache.StatsCache();
|
|
87
|
+
const watcher = import_utils.chokidar.watch(filenames, options);
|
|
88
|
+
watcher.on("ready", () => {
|
|
89
|
+
cache.add(getWatchedFiles(watcher));
|
|
90
|
+
});
|
|
91
|
+
watcher.on("change", (changed) => {
|
|
92
|
+
if (!import_utils.fs.existsSync(changed) || cache.isDiff(changed)) {
|
|
93
|
+
cache.refresh(changed);
|
|
94
|
+
callback(changed, "change");
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
watcher.on("add", (changed) => {
|
|
98
|
+
if (!cache.has(changed)) {
|
|
99
|
+
cache.add([changed]);
|
|
100
|
+
callback(changed, "add");
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
watcher.on("unlink", (changed) => {
|
|
104
|
+
cache.del(changed);
|
|
105
|
+
callback(changed, "unlink");
|
|
106
|
+
});
|
|
107
|
+
this.watcher = watcher;
|
|
108
|
+
}
|
|
109
|
+
createDepTree() {
|
|
110
|
+
this.dependencyTree = new import_dependency_tree.DependencyTree();
|
|
111
|
+
}
|
|
112
|
+
updateDepTree() {
|
|
113
|
+
var _a;
|
|
114
|
+
(_a = this.dependencyTree) == null ? void 0 : _a.update(require.cache);
|
|
115
|
+
}
|
|
116
|
+
cleanDepCache(filepath) {
|
|
117
|
+
var _a;
|
|
118
|
+
const node = (_a = this.dependencyTree) == null ? void 0 : _a.getNode(filepath);
|
|
119
|
+
if (node && require.cache[filepath]) {
|
|
120
|
+
delete require.cache[filepath];
|
|
121
|
+
for (const parentNode of node.parent.values()) {
|
|
122
|
+
this.cleanDepCache(parentNode.module.filename);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
close() {
|
|
127
|
+
return this.watcher.close();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
131
|
+
0 && (module.exports = {
|
|
132
|
+
defaultWatchOptions,
|
|
133
|
+
getWatchedFiles,
|
|
134
|
+
mergeWatchOptions
|
|
135
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
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 __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var stats_cache_exports = {};
|
|
25
|
+
__export(stats_cache_exports, {
|
|
26
|
+
StatsCache: () => StatsCache
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(stats_cache_exports);
|
|
29
|
+
var import_fs = __toESM(require("fs"));
|
|
30
|
+
var import_crypto = __toESM(require("crypto"));
|
|
31
|
+
class StatsCache {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.cachedHash = {};
|
|
34
|
+
this.cachedSize = {};
|
|
35
|
+
}
|
|
36
|
+
add(files) {
|
|
37
|
+
const { cachedHash, cachedSize } = this;
|
|
38
|
+
for (const filename of files) {
|
|
39
|
+
if (import_fs.default.existsSync(filename)) {
|
|
40
|
+
const stats = import_fs.default.statSync(filename);
|
|
41
|
+
if (stats.isFile() && !cachedHash[filename]) {
|
|
42
|
+
cachedHash[filename] = this.hash(stats, filename);
|
|
43
|
+
cachedSize[filename] = stats.size;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
refresh(filename) {
|
|
49
|
+
const { cachedHash, cachedSize } = this;
|
|
50
|
+
if (import_fs.default.existsSync(filename)) {
|
|
51
|
+
const stats = import_fs.default.statSync(filename);
|
|
52
|
+
if (stats.isFile()) {
|
|
53
|
+
cachedHash[filename] = this.hash(stats, filename);
|
|
54
|
+
cachedSize[filename] = stats.size;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
del(filename) {
|
|
59
|
+
if (this.cachedHash[filename]) {
|
|
60
|
+
delete this.cachedHash[filename];
|
|
61
|
+
delete this.cachedSize[filename];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
isDiff(filename) {
|
|
65
|
+
const { cachedHash, cachedSize } = this;
|
|
66
|
+
const stats = import_fs.default.statSync(filename);
|
|
67
|
+
const hash = cachedHash[filename];
|
|
68
|
+
const size = cachedSize[filename];
|
|
69
|
+
if (stats.size !== size) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
if (this.hash(stats, filename) !== hash) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
has(filename) {
|
|
78
|
+
return Boolean(this.cachedHash[filename]);
|
|
79
|
+
}
|
|
80
|
+
hash(stats, filename) {
|
|
81
|
+
return import_crypto.default.createHash("md5").update(import_fs.default.readFileSync(filename)).digest("hex");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
StatsCache
|
|
87
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
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 src_exports = {};
|
|
19
|
+
__export(src_exports, {
|
|
20
|
+
Server: () => import_server.DevServer,
|
|
21
|
+
default: () => src_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(src_exports);
|
|
24
|
+
var import_server = require("./server");
|
|
25
|
+
var src_default = (options) => {
|
|
26
|
+
if (options == null) {
|
|
27
|
+
throw new Error("can not start server without options");
|
|
28
|
+
}
|
|
29
|
+
const server = new import_server.DevServer(options);
|
|
30
|
+
return server.init();
|
|
31
|
+
};
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
Server
|
|
35
|
+
});
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __reflectGet = Reflect.get;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
for (var name in all)
|
|
27
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
+
};
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from))
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
39
|
+
mod
|
|
40
|
+
));
|
|
41
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
42
|
+
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
43
|
+
var __async = (__this, __arguments, generator) => {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
var fulfilled = (value) => {
|
|
46
|
+
try {
|
|
47
|
+
step(generator.next(value));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var rejected = (value) => {
|
|
53
|
+
try {
|
|
54
|
+
step(generator.throw(value));
|
|
55
|
+
} catch (e) {
|
|
56
|
+
reject(e);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
60
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
var dev_server_exports = {};
|
|
64
|
+
__export(dev_server_exports, {
|
|
65
|
+
ModernDevServer: () => ModernDevServer
|
|
66
|
+
});
|
|
67
|
+
module.exports = __toCommonJS(dev_server_exports);
|
|
68
|
+
var import_http = require("http");
|
|
69
|
+
var import_path = __toESM(require("path"));
|
|
70
|
+
var import_https = require("https");
|
|
71
|
+
var import_utils = require("@modern-js/utils");
|
|
72
|
+
var import_prod_server = require("@modern-js/prod-server");
|
|
73
|
+
var import_constants = require("@modern-js/utils/constants");
|
|
74
|
+
var import_constants2 = require("../constants");
|
|
75
|
+
var import_mock = require("../dev-tools/mock");
|
|
76
|
+
var import_register = require("../dev-tools/register");
|
|
77
|
+
var import_watcher = __toESM(require("../dev-tools/watcher"));
|
|
78
|
+
var import_dev_middleware = __toESM(require("../dev-tools/dev-middleware"));
|
|
79
|
+
class ModernDevServer extends import_prod_server.ModernServer {
|
|
80
|
+
constructor(options) {
|
|
81
|
+
super(options);
|
|
82
|
+
this.mockHandler = null;
|
|
83
|
+
this.workDir = this.pwd;
|
|
84
|
+
this.dev = this.getDevOptions(options);
|
|
85
|
+
this.devMiddleware = new import_dev_middleware.default({
|
|
86
|
+
dev: this.dev,
|
|
87
|
+
devMiddleware: options.devMiddleware
|
|
88
|
+
});
|
|
89
|
+
(0, import_register.enableRegister)(this.pwd, this.conf);
|
|
90
|
+
}
|
|
91
|
+
getDevOptions(options) {
|
|
92
|
+
const devOptions = typeof options.dev === "boolean" ? {} : options.dev;
|
|
93
|
+
const defaultOptions = (0, import_constants2.getDefaultDevOptions)();
|
|
94
|
+
return __spreadProps(__spreadValues(__spreadValues({}, defaultOptions), devOptions), {
|
|
95
|
+
client: __spreadValues(__spreadValues({}, defaultOptions.client), devOptions == null ? void 0 : devOptions.client)
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
addMiddlewareHandler(handlers) {
|
|
99
|
+
handlers.forEach((handler) => {
|
|
100
|
+
this.addHandler((ctx, next) => {
|
|
101
|
+
const { req, res } = ctx;
|
|
102
|
+
return handler(req, res, next);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
applySetupMiddlewares() {
|
|
107
|
+
const setupMiddlewares = this.dev.setupMiddlewares || [];
|
|
108
|
+
const serverOptions = {
|
|
109
|
+
sockWrite: (type, data) => this.devMiddleware.sockWrite(type, data)
|
|
110
|
+
};
|
|
111
|
+
const befores = [];
|
|
112
|
+
const afters = [];
|
|
113
|
+
setupMiddlewares.forEach((handler) => {
|
|
114
|
+
handler(
|
|
115
|
+
{
|
|
116
|
+
unshift: (...handlers) => befores.unshift(...handlers),
|
|
117
|
+
push: (...handlers) => afters.push(...handlers)
|
|
118
|
+
},
|
|
119
|
+
serverOptions
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
return { befores, afters };
|
|
123
|
+
}
|
|
124
|
+
onInit(runner, app) {
|
|
125
|
+
return __async(this, null, function* () {
|
|
126
|
+
this.runner = runner;
|
|
127
|
+
const { dev } = this;
|
|
128
|
+
const { befores, afters } = this.applySetupMiddlewares();
|
|
129
|
+
const beforeHandlers = yield this.setupBeforeDevMiddleware();
|
|
130
|
+
this.addMiddlewareHandler([...beforeHandlers, ...befores]);
|
|
131
|
+
yield this.applyDefaultMiddlewares(app);
|
|
132
|
+
const afterHandlers = yield this.setupAfterDevMiddleware();
|
|
133
|
+
this.addMiddlewareHandler([...afters, ...afterHandlers]);
|
|
134
|
+
yield __superGet(ModernDevServer.prototype, this, "onInit").call(this, runner, app);
|
|
135
|
+
if (dev.watch) {
|
|
136
|
+
this.startWatcher();
|
|
137
|
+
app.on("close", () => __async(this, null, function* () {
|
|
138
|
+
var _a;
|
|
139
|
+
yield (_a = this.watcher) == null ? void 0 : _a.close();
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
applyDefaultMiddlewares(app) {
|
|
145
|
+
return __async(this, null, function* () {
|
|
146
|
+
const { pwd, dev, devMiddleware } = this;
|
|
147
|
+
this.addHandler((ctx, next) => {
|
|
148
|
+
ctx.res.setHeader("Access-Control-Allow-Origin", "*");
|
|
149
|
+
if (ctx.path.includes("hot-update")) {
|
|
150
|
+
ctx.res.setHeader("Access-Control-Allow-Credentials", "false");
|
|
151
|
+
}
|
|
152
|
+
const confHeaders = dev.headers;
|
|
153
|
+
if (confHeaders) {
|
|
154
|
+
for (const [key, value] of Object.entries(confHeaders)) {
|
|
155
|
+
ctx.res.setHeader(key, value);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
next();
|
|
159
|
+
});
|
|
160
|
+
this.mockHandler = (0, import_mock.createMockHandler)({ pwd });
|
|
161
|
+
this.addHandler((ctx, next) => {
|
|
162
|
+
if (this.mockHandler) {
|
|
163
|
+
this.mockHandler(ctx, next);
|
|
164
|
+
} else {
|
|
165
|
+
next();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
const proxyHandlers = (0, import_prod_server.createProxyHandler)(dev.proxy);
|
|
169
|
+
if (proxyHandlers) {
|
|
170
|
+
proxyHandlers.forEach((handler) => {
|
|
171
|
+
this.addHandler(handler);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
devMiddleware.init(app);
|
|
175
|
+
devMiddleware.on("change", (stats) => {
|
|
176
|
+
if (stats.toJson({ all: false }).name === "client") {
|
|
177
|
+
this.onRepack({ routes: this.getRoutes() });
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
this.addHandler((ctx, next) => {
|
|
181
|
+
const { req, res } = ctx;
|
|
182
|
+
if (devMiddleware.middleware) {
|
|
183
|
+
devMiddleware.middleware(req, res, next);
|
|
184
|
+
} else {
|
|
185
|
+
next();
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
if (dev.historyApiFallback) {
|
|
189
|
+
const { default: connectHistoryApiFallback } = yield Promise.resolve().then(() => __toESM(require("connect-history-api-fallback")));
|
|
190
|
+
const historyApiFallbackMiddleware = connectHistoryApiFallback(
|
|
191
|
+
typeof dev.historyApiFallback === "boolean" ? {} : dev.historyApiFallback
|
|
192
|
+
);
|
|
193
|
+
this.addHandler(
|
|
194
|
+
(ctx, next) => historyApiFallbackMiddleware(ctx.req, ctx.res, next)
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
onRepack(options = {}) {
|
|
200
|
+
if (Array.isArray(options.routes)) {
|
|
201
|
+
this.router.reset(this.filterRoutes(options.routes));
|
|
202
|
+
}
|
|
203
|
+
this.cleanSSRCache();
|
|
204
|
+
this.reader.updateFile();
|
|
205
|
+
super.onRepack(options);
|
|
206
|
+
}
|
|
207
|
+
createHTTPServer(handler) {
|
|
208
|
+
return __async(this, null, function* () {
|
|
209
|
+
const { dev } = this;
|
|
210
|
+
const devHttpsOption = typeof dev === "object" && dev.https;
|
|
211
|
+
if (devHttpsOption) {
|
|
212
|
+
const { genHttpsOptions } = require("../dev-tools/https");
|
|
213
|
+
const httpsOptions = yield genHttpsOptions(devHttpsOption, this.pwd);
|
|
214
|
+
return (0, import_https.createServer)(httpsOptions, handler);
|
|
215
|
+
} else {
|
|
216
|
+
return (0, import_http.createServer)(handler);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
warmupSSRBundle() {
|
|
221
|
+
}
|
|
222
|
+
onServerChange({
|
|
223
|
+
filepath,
|
|
224
|
+
event
|
|
225
|
+
}) {
|
|
226
|
+
const { pwd } = this;
|
|
227
|
+
const { mock } = import_prod_server.AGGRED_DIR;
|
|
228
|
+
const mockPath = import_path.default.normalize(import_path.default.join(pwd, mock));
|
|
229
|
+
this.runner.reset();
|
|
230
|
+
if (filepath.startsWith(mockPath)) {
|
|
231
|
+
this.mockHandler = (0, import_mock.createMockHandler)({ pwd });
|
|
232
|
+
} else {
|
|
233
|
+
try {
|
|
234
|
+
const success = this.runner.onApiChange([
|
|
235
|
+
{ filename: filepath, event }
|
|
236
|
+
]);
|
|
237
|
+
if (success !== true) {
|
|
238
|
+
super.onServerChange({ filepath });
|
|
239
|
+
}
|
|
240
|
+
} catch (e) {
|
|
241
|
+
this.logger.error(e);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
createContext(req, res) {
|
|
246
|
+
return super.createContext(req, res, { etag: true });
|
|
247
|
+
}
|
|
248
|
+
setupBeforeDevMiddleware() {
|
|
249
|
+
return __async(this, null, function* () {
|
|
250
|
+
const { runner, conf, dev } = this;
|
|
251
|
+
const setupMids = dev.before || [];
|
|
252
|
+
const pluginMids = yield runner.beforeDevServer(conf);
|
|
253
|
+
return [...setupMids, ...pluginMids].flat();
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
setupAfterDevMiddleware() {
|
|
257
|
+
return __async(this, null, function* () {
|
|
258
|
+
const { runner, conf, dev } = this;
|
|
259
|
+
const setupMids = dev.after || [];
|
|
260
|
+
const pluginMids = yield runner.afterDevServer(conf);
|
|
261
|
+
return [...pluginMids, ...setupMids].flat();
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
cleanSSRCache() {
|
|
265
|
+
const { distDir } = this;
|
|
266
|
+
const bundles = this.router.getBundles();
|
|
267
|
+
bundles.forEach((bundle) => {
|
|
268
|
+
const filepath = import_path.default.join(distDir, bundle);
|
|
269
|
+
if (require.cache[filepath]) {
|
|
270
|
+
delete require.cache[filepath];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
const loadable = import_path.default.join(distDir, import_constants.LOADABLE_STATS_FILE);
|
|
274
|
+
if (require.cache[loadable]) {
|
|
275
|
+
delete require.cache[loadable];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
startWatcher() {
|
|
279
|
+
var _a;
|
|
280
|
+
const { pwd, distDir } = this;
|
|
281
|
+
const { mock } = import_prod_server.AGGRED_DIR;
|
|
282
|
+
const defaultWatched = [
|
|
283
|
+
`${mock}/**/*`,
|
|
284
|
+
`${import_utils.SERVER_DIR}/**/*`,
|
|
285
|
+
`${import_utils.API_DIR}/**`,
|
|
286
|
+
`${import_utils.SHARED_DIR}/**/*`,
|
|
287
|
+
`${distDir}/${import_utils.SERVER_BUNDLE_DIRECTORY}/*-server-loaders.js`
|
|
288
|
+
];
|
|
289
|
+
const watchOptions = (0, import_watcher.mergeWatchOptions)((_a = this.conf.server) == null ? void 0 : _a.watchOptions);
|
|
290
|
+
const defaultWatchedPaths = defaultWatched.map((p) => {
|
|
291
|
+
const finalPath = import_path.default.isAbsolute(p) ? p : import_path.default.join(pwd, p);
|
|
292
|
+
return import_path.default.normalize(finalPath);
|
|
293
|
+
});
|
|
294
|
+
const watcher = new import_watcher.default();
|
|
295
|
+
watcher.createDepTree();
|
|
296
|
+
watcher.listen(defaultWatchedPaths, watchOptions, (filepath, event) => {
|
|
297
|
+
watcher.updateDepTree();
|
|
298
|
+
watcher.cleanDepCache(filepath);
|
|
299
|
+
this.onServerChange({
|
|
300
|
+
filepath,
|
|
301
|
+
event
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
this.watcher = watcher;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
308
|
+
0 && (module.exports = {
|
|
309
|
+
ModernDevServer
|
|
310
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
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 server_exports = {};
|
|
19
|
+
__export(server_exports, {
|
|
20
|
+
DevServer: () => DevServer
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(server_exports);
|
|
23
|
+
var import_prod_server = require("@modern-js/prod-server");
|
|
24
|
+
var import_dev_server = require("./dev-server");
|
|
25
|
+
const createDevServer = (options) => {
|
|
26
|
+
return new import_dev_server.ModernDevServer(options);
|
|
27
|
+
};
|
|
28
|
+
class DevServer extends import_prod_server.Server {
|
|
29
|
+
constructor(options) {
|
|
30
|
+
super(options);
|
|
31
|
+
if (options.dev) {
|
|
32
|
+
this.serverImpl = createDevServer;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
DevServer
|
|
39
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getIpv4Interfaces, HMR_SOCK_PATH } from "@modern-js/utils";
|
|
2
|
+
var getDefaultDevOptions = function() {
|
|
3
|
+
var network = getIpv4Interfaces().find(function(item) {
|
|
4
|
+
return !item.internal;
|
|
5
|
+
});
|
|
6
|
+
return {
|
|
7
|
+
client: {
|
|
8
|
+
port: "8080",
|
|
9
|
+
path: HMR_SOCK_PATH,
|
|
10
|
+
host: (network === null || network === void 0 ? void 0 : network.address) || "localhost"
|
|
11
|
+
},
|
|
12
|
+
https: false,
|
|
13
|
+
devMiddleware: {
|
|
14
|
+
writeToDisk: true
|
|
15
|
+
},
|
|
16
|
+
watch: true,
|
|
17
|
+
hot: true,
|
|
18
|
+
liveReload: true
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export { getDefaultDevOptions };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { HMR_SOCK_PATH } from "@modern-js/utils/constants";
|
|
2
|
+
function createSocketUrl(resourceQuery) {
|
|
3
|
+
var searchParams = resourceQuery.substr(1).split("&");
|
|
4
|
+
var options = {};
|
|
5
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
6
|
+
try {
|
|
7
|
+
for(var _iterator = searchParams[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
8
|
+
var pair = _step.value;
|
|
9
|
+
var ary = pair.split("=");
|
|
10
|
+
options[ary[0]] = decodeURIComponent(ary[1]);
|
|
11
|
+
}
|
|
12
|
+
} catch (err) {
|
|
13
|
+
_didIteratorError = true;
|
|
14
|
+
_iteratorError = err;
|
|
15
|
+
} finally{
|
|
16
|
+
try {
|
|
17
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
18
|
+
_iterator.return();
|
|
19
|
+
}
|
|
20
|
+
} finally{
|
|
21
|
+
if (_didIteratorError) {
|
|
22
|
+
throw _iteratorError;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
var currentLocation = self.location;
|
|
27
|
+
return getSocketUrl(options, currentLocation);
|
|
28
|
+
}
|
|
29
|
+
function formatURL(param) {
|
|
30
|
+
var port = param.port, protocol = param.protocol, hostname = param.hostname, pathname = param.pathname;
|
|
31
|
+
if (window.URL) {
|
|
32
|
+
var url = new URL("http://localhost");
|
|
33
|
+
url.port = port;
|
|
34
|
+
url.hostname = hostname;
|
|
35
|
+
url.protocol = protocol;
|
|
36
|
+
url.pathname = pathname;
|
|
37
|
+
return url.toString();
|
|
38
|
+
}
|
|
39
|
+
var colon = protocol.indexOf(":") === -1 ? ":" : "";
|
|
40
|
+
return "".concat(protocol).concat(colon, "//").concat(hostname, ":").concat(port).concat(pathname);
|
|
41
|
+
}
|
|
42
|
+
function getSocketUrl(urlParts, location) {
|
|
43
|
+
var host = urlParts.host, port = urlParts.port, path = urlParts.path, protocol = urlParts.protocol;
|
|
44
|
+
return formatURL({
|
|
45
|
+
protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
|
|
46
|
+
hostname: host || location.hostname,
|
|
47
|
+
port: port || location.port,
|
|
48
|
+
pathname: path || HMR_SOCK_PATH
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export { createSocketUrl, formatURL };
|