@modern-js/server 2.0.0-beta.3 → 2.0.0-beta.4
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 +79 -0
- package/dist/js/modern/constants.js +10 -9
- package/dist/js/modern/dev-tools/dev-middleware/dev-server-plugin.js +14 -20
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +14 -19
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +134 -184
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/types.d.js +0 -0
- package/dist/js/modern/dev-tools/dev-middleware/index.js +65 -60
- package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +33 -59
- package/dist/js/modern/dev-tools/https/global.d.js +0 -0
- package/dist/js/modern/dev-tools/https/index.js +28 -5
- package/dist/js/modern/dev-tools/mock/getMockData.js +71 -45
- package/dist/js/modern/dev-tools/mock/index.js +34 -15
- package/dist/js/modern/dev-tools/register/index.js +71 -54
- package/dist/js/modern/dev-tools/watcher/dependency-tree.js +25 -34
- package/dist/js/modern/dev-tools/watcher/index.js +51 -33
- package/dist/js/modern/dev-tools/watcher/stats-cache.js +13 -20
- package/dist/js/modern/index.js +7 -4
- package/dist/js/modern/server/dev-server.js +191 -215
- package/dist/js/modern/server/index.js +7 -4
- package/dist/js/node/constants.js +27 -14
- package/dist/js/node/dev-tools/dev-middleware/dev-server-plugin.js +36 -24
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +31 -24
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +56 -98
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/types.d.js +0 -0
- package/dist/js/node/dev-tools/dev-middleware/index.js +94 -72
- package/dist/js/node/dev-tools/dev-middleware/socket-server.js +57 -66
- package/dist/js/node/dev-tools/https/global.d.js +0 -0
- package/dist/js/node/dev-tools/https/index.js +52 -13
- package/dist/js/node/dev-tools/mock/getMockData.js +88 -51
- package/dist/js/node/dev-tools/mock/index.js +62 -28
- package/dist/js/node/dev-tools/register/index.js +98 -64
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +50 -43
- package/dist/js/node/dev-tools/watcher/index.js +79 -47
- package/dist/js/node/dev-tools/watcher/stats-cache.js +40 -30
- package/dist/js/node/index.js +25 -15
- package/dist/js/node/server/dev-server.js +234 -237
- package/dist/js/node/server/index.js +26 -11
- package/dist/js/treeshaking/constants.js +21 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/dev-server-plugin.js +74 -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/hmr-client/types.d.js +1 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +363 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +209 -0
- package/dist/js/treeshaking/dev-tools/https/global.d.js +1 -0
- package/dist/js/treeshaking/dev-tools/https/index.js +161 -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 +800 -0
- package/dist/js/treeshaking/server/index.js +92 -0
- package/dist/js/treeshaking/types.js +1 -0
- package/dist/types/dev-tools/mock/getMockData.d.ts +2 -0
- package/dist/types/dev-tools/watcher/dependency-tree.d.ts +2 -0
- package/dist/types/dev-tools/watcher/index.d.ts +1 -1
- package/dist/types/index.d.ts +2 -0
- package/package.json +16 -13
- package/temp-fix-hmr.js +483 -0
|
@@ -1,102 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
enableRegister: () => enableRegister
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
28
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_server_utils = require("@modern-js/server-utils");
|
|
31
|
+
var import_utils = require("@modern-js/utils");
|
|
32
|
+
var __defProp2 = Object.defineProperty;
|
|
33
|
+
var __defProps = Object.defineProperties;
|
|
34
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
35
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
36
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
37
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
38
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
39
|
+
var __spreadValues = (a, b) => {
|
|
40
|
+
for (var prop in b || (b = {}))
|
|
41
|
+
if (__hasOwnProp2.call(b, prop))
|
|
42
|
+
__defNormalProp(a, prop, b[prop]);
|
|
43
|
+
if (__getOwnPropSymbols)
|
|
44
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
45
|
+
if (__propIsEnum.call(b, prop))
|
|
46
|
+
__defNormalProp(a, prop, b[prop]);
|
|
47
|
+
}
|
|
48
|
+
return a;
|
|
49
|
+
};
|
|
50
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
51
|
+
const debug = (0, import_utils.createDebugger)("server");
|
|
15
52
|
const checkDep = (depName, paths) => {
|
|
16
|
-
let packagePath =
|
|
53
|
+
let packagePath = "";
|
|
17
54
|
try {
|
|
18
55
|
packagePath = require.resolve(depName, {
|
|
19
56
|
paths
|
|
20
57
|
});
|
|
21
|
-
} catch (error) {
|
|
58
|
+
} catch (error) {
|
|
59
|
+
}
|
|
22
60
|
return Boolean(packagePath);
|
|
23
61
|
};
|
|
24
|
-
const enableRegister = (projectRoot, config
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
62
|
+
const enableRegister = (projectRoot, config) => {
|
|
63
|
+
var _a, _b, _c;
|
|
64
|
+
const registerDirs = ["./api", "./server", "./config/mock", "./shared"];
|
|
28
65
|
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
29
|
-
const tsconfigPath =
|
|
30
|
-
const isTsProject =
|
|
31
|
-
const existTsNode = checkDep(
|
|
32
|
-
const existTsConfigPaths = checkDep(
|
|
66
|
+
const tsconfigPath = import_path.default.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
67
|
+
const isTsProject = import_utils.fs.existsSync(tsconfigPath);
|
|
68
|
+
const existTsNode = checkDep("ts-node", [projectRoot]);
|
|
69
|
+
const existTsConfigPaths = checkDep("tsconfig-paths", [projectRoot]);
|
|
33
70
|
if (isTsProject && existTsNode && existTsConfigPaths) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const {
|
|
40
|
-
alias
|
|
41
|
-
} = config.source;
|
|
42
|
-
const aliasConfig = (0, _utils.getAliasConfig)(alias, {
|
|
71
|
+
debug("use ts-node");
|
|
72
|
+
const distPath = ((_a = config.output.distPath) == null ? void 0 : _a.root) || "dist";
|
|
73
|
+
const tsNode = require("ts-node");
|
|
74
|
+
const tsConfigPaths = require("tsconfig-paths");
|
|
75
|
+
const { alias } = config.source;
|
|
76
|
+
const aliasConfig = (0, import_utils.getAliasConfig)(alias, {
|
|
43
77
|
appDirectory: projectRoot,
|
|
44
78
|
tsconfigPath
|
|
45
79
|
});
|
|
46
|
-
const {
|
|
47
|
-
paths = {},
|
|
48
|
-
absoluteBaseUrl = './'
|
|
49
|
-
} = aliasConfig;
|
|
80
|
+
const { paths = {}, absoluteBaseUrl = "./" } = aliasConfig;
|
|
50
81
|
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
51
82
|
let tsPath = paths[key];
|
|
52
|
-
if (typeof tsPath ===
|
|
53
|
-
tsPath =
|
|
83
|
+
if (typeof tsPath === "string" && import_path.default.isAbsolute(tsPath)) {
|
|
84
|
+
tsPath = import_path.default.relative(absoluteBaseUrl, tsPath);
|
|
54
85
|
}
|
|
55
|
-
if (typeof tsPath ===
|
|
86
|
+
if (typeof tsPath === "string") {
|
|
56
87
|
tsPath = [tsPath];
|
|
57
88
|
}
|
|
58
|
-
return
|
|
89
|
+
return __spreadProps(__spreadValues({}, o), {
|
|
59
90
|
[`${key}`]: tsPath
|
|
60
91
|
});
|
|
61
92
|
}, {});
|
|
62
93
|
tsConfigPaths.register({
|
|
63
|
-
baseUrl: absoluteBaseUrl ||
|
|
94
|
+
baseUrl: absoluteBaseUrl || "./",
|
|
64
95
|
paths: tsPaths
|
|
65
96
|
});
|
|
66
97
|
tsNode.register({
|
|
67
98
|
project: tsconfigPath,
|
|
68
|
-
// for env.d.ts, https://www.npmjs.com/package/ts-node#missing-types
|
|
69
99
|
files: true,
|
|
70
100
|
transpileOnly: true,
|
|
71
|
-
ignore: [
|
|
101
|
+
ignore: ["(?:^|/)node_modules/", `(?:^|/)${distPath}/`]
|
|
72
102
|
});
|
|
73
103
|
} else {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
104
|
+
debug("use @babel/register");
|
|
105
|
+
const babelConfig = (0, import_server_utils.resolveBabelConfig)(
|
|
106
|
+
projectRoot,
|
|
107
|
+
__spreadProps(__spreadValues({}, config.source), {
|
|
108
|
+
babelConfig: (_b = config.tools) == null ? void 0 : _b.babel,
|
|
109
|
+
server: {
|
|
110
|
+
compiler: (_c = config.server) == null ? void 0 : _c.compiler
|
|
111
|
+
}
|
|
112
|
+
}),
|
|
113
|
+
{
|
|
114
|
+
tsconfigPath,
|
|
115
|
+
syntax: "es6+",
|
|
116
|
+
type: "commonjs"
|
|
80
117
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return true;
|
|
118
|
+
);
|
|
119
|
+
return require("@babel/register")(__spreadProps(__spreadValues({}, babelConfig), {
|
|
120
|
+
only: [
|
|
121
|
+
function(filePath) {
|
|
122
|
+
if (filePath.includes(`node_modules${import_path.default.sep}.modern-js`)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
return registerDirs.some(
|
|
126
|
+
(registerDir) => filePath.startsWith(import_path.default.join(projectRoot, registerDir))
|
|
127
|
+
);
|
|
92
128
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
extensions: ['.js', '.ts'],
|
|
129
|
+
],
|
|
130
|
+
extensions: [".js", ".ts"],
|
|
96
131
|
babelrc: false,
|
|
97
132
|
configFile: false,
|
|
98
133
|
root: projectRoot
|
|
99
134
|
}));
|
|
100
135
|
}
|
|
101
136
|
};
|
|
102
|
-
exports.enableRegister = enableRegister;
|
|
@@ -1,65 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
DependencyTree: () => DependencyTree,
|
|
27
|
+
defaultIgnores: () => defaultIgnores
|
|
5
28
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
29
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
30
|
+
var import_minimatch = __toESM(require("minimatch"));
|
|
31
|
+
const defaultIgnores = [
|
|
32
|
+
"**/bower_components/**",
|
|
33
|
+
"**/coverage/**",
|
|
34
|
+
"**/node_modules/**",
|
|
35
|
+
"**/.*/**",
|
|
36
|
+
"**/*.d.ts",
|
|
37
|
+
"**/*.log"
|
|
38
|
+
];
|
|
17
39
|
class DependencyTree {
|
|
18
40
|
constructor() {
|
|
19
|
-
|
|
20
|
-
_defineProperty(this, "ignore", void 0);
|
|
21
|
-
this.tree = new Map();
|
|
41
|
+
this.tree = /* @__PURE__ */ new Map();
|
|
22
42
|
this.ignore = [...defaultIgnores];
|
|
23
43
|
}
|
|
24
44
|
getNode(path) {
|
|
25
45
|
return this.tree.get(path);
|
|
26
46
|
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* update dependency tree
|
|
30
|
-
*
|
|
31
|
-
* @param cache
|
|
32
|
-
*/
|
|
33
47
|
update(cache) {
|
|
34
48
|
this.tree.clear();
|
|
35
|
-
|
|
36
|
-
// insert all module that not ignored
|
|
37
|
-
Object.keys(cache).forEach(path => {
|
|
49
|
+
Object.keys(cache).forEach((path) => {
|
|
38
50
|
if (!this.shouldIgnore(path)) {
|
|
39
|
-
const
|
|
40
|
-
this.tree.set(
|
|
41
|
-
module,
|
|
42
|
-
parent: new Set(),
|
|
43
|
-
children: new Set()
|
|
51
|
+
const module2 = cache[path];
|
|
52
|
+
this.tree.set(module2.filename, {
|
|
53
|
+
module: module2,
|
|
54
|
+
parent: /* @__PURE__ */ new Set(),
|
|
55
|
+
children: /* @__PURE__ */ new Set()
|
|
44
56
|
});
|
|
45
57
|
}
|
|
46
58
|
});
|
|
47
|
-
|
|
48
|
-
// update treeNode parent and children
|
|
49
59
|
for (const treeNode of this.tree.values()) {
|
|
50
|
-
const {
|
|
51
|
-
|
|
52
|
-
} = treeNode.module;
|
|
53
|
-
const {
|
|
54
|
-
children
|
|
55
|
-
} = treeNode.module;
|
|
60
|
+
const { parent } = treeNode.module;
|
|
61
|
+
const { children } = treeNode.module;
|
|
56
62
|
if (parent && !this.shouldIgnore(parent.filename)) {
|
|
57
63
|
const parentTreeNode = this.tree.get(parent.filename);
|
|
58
64
|
if (parentTreeNode) {
|
|
59
65
|
treeNode.parent.add(parentTreeNode);
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
|
-
children.forEach(child => {
|
|
68
|
+
children.forEach((child) => {
|
|
63
69
|
if (!this.shouldIgnore(child.filename)) {
|
|
64
70
|
const childTreeNode = this.tree.get(child.filename);
|
|
65
71
|
if (childTreeNode) {
|
|
@@ -71,7 +77,8 @@ class DependencyTree {
|
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
79
|
shouldIgnore(path) {
|
|
74
|
-
return !path || Boolean(
|
|
80
|
+
return !path || Boolean(
|
|
81
|
+
this.ignore.find((rule) => import_minimatch.default.match([path], rule).length > 0)
|
|
82
|
+
);
|
|
75
83
|
}
|
|
76
84
|
}
|
|
77
|
-
exports.DependencyTree = DependencyTree;
|
|
@@ -1,90 +1,123 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
default: () => Watcher,
|
|
27
|
+
defaultWatchOptions: () => defaultWatchOptions,
|
|
28
|
+
getWatchedFiles: () => getWatchedFiles,
|
|
29
|
+
mergeWatchOptions: () => mergeWatchOptions
|
|
5
30
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
31
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
32
|
+
var import_path = __toESM(require("path"));
|
|
33
|
+
var import_utils = require("@modern-js/utils");
|
|
34
|
+
var import_dependency_tree = require("./dependency-tree");
|
|
35
|
+
var import_stats_cache = require("./stats-cache");
|
|
36
|
+
var __defProp2 = Object.defineProperty;
|
|
37
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
38
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
39
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
40
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
41
|
+
var __spreadValues = (a, b) => {
|
|
42
|
+
for (var prop in b || (b = {}))
|
|
43
|
+
if (__hasOwnProp2.call(b, prop))
|
|
44
|
+
__defNormalProp(a, prop, b[prop]);
|
|
45
|
+
if (__getOwnPropSymbols)
|
|
46
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
47
|
+
if (__propIsEnum.call(b, prop))
|
|
48
|
+
__defNormalProp(a, prop, b[prop]);
|
|
49
|
+
}
|
|
50
|
+
return a;
|
|
51
|
+
};
|
|
15
52
|
const defaultWatchOptions = {
|
|
16
|
-
// 初始化的时候不触发 add、addDir 事件
|
|
17
53
|
ignoreInitial: true,
|
|
18
54
|
ignored: /api\/typings\/.*/
|
|
19
55
|
};
|
|
20
|
-
|
|
21
|
-
const getWatchedFiles = watcher => {
|
|
56
|
+
const getWatchedFiles = (watcher) => {
|
|
22
57
|
const watched = watcher.getWatched();
|
|
23
58
|
const files = [];
|
|
24
|
-
Object.keys(watched).forEach(dir => {
|
|
25
|
-
watched[dir].forEach(fileName => {
|
|
26
|
-
files.push(
|
|
59
|
+
Object.keys(watched).forEach((dir) => {
|
|
60
|
+
watched[dir].forEach((fileName) => {
|
|
61
|
+
files.push(import_path.default.join(dir, fileName));
|
|
27
62
|
});
|
|
28
63
|
});
|
|
29
64
|
return files;
|
|
30
65
|
};
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const watchOptions = _objectSpread({}, options);
|
|
66
|
+
const mergeWatchOptions = (options) => {
|
|
67
|
+
const watchOptions = __spreadValues({}, options);
|
|
34
68
|
if (watchOptions) {
|
|
35
|
-
const {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
69
|
+
const { ignored } = watchOptions;
|
|
70
|
+
const finalIgnored = ignored ? [
|
|
71
|
+
defaultWatchOptions.ignored,
|
|
72
|
+
...Array.isArray(ignored) ? ignored : [ignored]
|
|
73
|
+
] : ignored;
|
|
39
74
|
if (finalIgnored) {
|
|
40
75
|
watchOptions.ignored = finalIgnored;
|
|
41
76
|
}
|
|
42
77
|
}
|
|
43
|
-
const finalWatchOptions =
|
|
78
|
+
const finalWatchOptions = __spreadValues(__spreadValues({}, defaultWatchOptions), watchOptions);
|
|
44
79
|
return finalWatchOptions;
|
|
45
80
|
};
|
|
46
|
-
exports.mergeWatchOptions = mergeWatchOptions;
|
|
47
81
|
class Watcher {
|
|
48
82
|
constructor() {
|
|
49
|
-
|
|
50
|
-
_defineProperty(this, "watcher", void 0);
|
|
83
|
+
this.dependencyTree = null;
|
|
51
84
|
}
|
|
52
85
|
listen(files, options, callback) {
|
|
53
86
|
const watched = files.filter(Boolean);
|
|
54
|
-
const filenames = watched.map(filename => filename.replace(/\\/g,
|
|
55
|
-
const cache = new
|
|
56
|
-
const watcher =
|
|
57
|
-
watcher.on(
|
|
87
|
+
const filenames = watched.map((filename) => filename.replace(/\\/g, "/"));
|
|
88
|
+
const cache = new import_stats_cache.StatsCache();
|
|
89
|
+
const watcher = import_utils.chokidar.watch(filenames, options);
|
|
90
|
+
watcher.on("ready", () => {
|
|
58
91
|
cache.add(getWatchedFiles(watcher));
|
|
59
92
|
});
|
|
60
|
-
watcher.on(
|
|
61
|
-
if (!
|
|
93
|
+
watcher.on("change", (changed) => {
|
|
94
|
+
if (!import_utils.fs.existsSync(changed) || cache.isDiff(changed)) {
|
|
62
95
|
cache.refresh(changed);
|
|
63
|
-
callback(changed,
|
|
96
|
+
callback(changed, "change");
|
|
64
97
|
}
|
|
65
98
|
});
|
|
66
|
-
watcher.on(
|
|
99
|
+
watcher.on("add", (changed) => {
|
|
67
100
|
if (!cache.has(changed)) {
|
|
68
101
|
cache.add([changed]);
|
|
69
|
-
callback(changed,
|
|
102
|
+
callback(changed, "add");
|
|
70
103
|
}
|
|
71
104
|
});
|
|
72
|
-
watcher.on(
|
|
105
|
+
watcher.on("unlink", (changed) => {
|
|
73
106
|
cache.del(changed);
|
|
74
|
-
callback(changed,
|
|
107
|
+
callback(changed, "unlink");
|
|
75
108
|
});
|
|
76
109
|
this.watcher = watcher;
|
|
77
110
|
}
|
|
78
111
|
createDepTree() {
|
|
79
|
-
this.dependencyTree = new
|
|
112
|
+
this.dependencyTree = new import_dependency_tree.DependencyTree();
|
|
80
113
|
}
|
|
81
114
|
updateDepTree() {
|
|
82
|
-
var
|
|
83
|
-
(
|
|
115
|
+
var _a;
|
|
116
|
+
(_a = this.dependencyTree) == null ? void 0 : _a.update(require.cache);
|
|
84
117
|
}
|
|
85
118
|
cleanDepCache(filepath) {
|
|
86
|
-
var
|
|
87
|
-
const node = (
|
|
119
|
+
var _a;
|
|
120
|
+
const node = (_a = this.dependencyTree) == null ? void 0 : _a.getNode(filepath);
|
|
88
121
|
if (node && require.cache[filepath]) {
|
|
89
122
|
delete require.cache[filepath];
|
|
90
123
|
for (const parentNode of node.parent.values()) {
|
|
@@ -96,4 +129,3 @@ class Watcher {
|
|
|
96
129
|
return this.watcher.close();
|
|
97
130
|
}
|
|
98
131
|
}
|
|
99
|
-
exports.default = Watcher;
|
|
@@ -1,26 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
StatsCache: () => StatsCache
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
28
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
+
var import_fs = __toESM(require("fs"));
|
|
30
|
+
var import_crypto = __toESM(require("crypto"));
|
|
11
31
|
class StatsCache {
|
|
12
32
|
constructor() {
|
|
13
|
-
|
|
14
|
-
|
|
33
|
+
this.cachedHash = {};
|
|
34
|
+
this.cachedSize = {};
|
|
15
35
|
}
|
|
16
36
|
add(files) {
|
|
17
|
-
const {
|
|
18
|
-
cachedHash,
|
|
19
|
-
cachedSize
|
|
20
|
-
} = this;
|
|
37
|
+
const { cachedHash, cachedSize } = this;
|
|
21
38
|
for (const filename of files) {
|
|
22
|
-
if (
|
|
23
|
-
const stats =
|
|
39
|
+
if (import_fs.default.existsSync(filename)) {
|
|
40
|
+
const stats = import_fs.default.statSync(filename);
|
|
24
41
|
if (stats.isFile() && !cachedHash[filename]) {
|
|
25
42
|
cachedHash[filename] = this.hash(stats, filename);
|
|
26
43
|
cachedSize[filename] = stats.size;
|
|
@@ -29,12 +46,9 @@ class StatsCache {
|
|
|
29
46
|
}
|
|
30
47
|
}
|
|
31
48
|
refresh(filename) {
|
|
32
|
-
const {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} = this;
|
|
36
|
-
if (_fs.default.existsSync(filename)) {
|
|
37
|
-
const stats = _fs.default.statSync(filename);
|
|
49
|
+
const { cachedHash, cachedSize } = this;
|
|
50
|
+
if (import_fs.default.existsSync(filename)) {
|
|
51
|
+
const stats = import_fs.default.statSync(filename);
|
|
38
52
|
if (stats.isFile()) {
|
|
39
53
|
cachedHash[filename] = this.hash(stats, filename);
|
|
40
54
|
cachedSize[filename] = stats.size;
|
|
@@ -48,11 +62,8 @@ class StatsCache {
|
|
|
48
62
|
}
|
|
49
63
|
}
|
|
50
64
|
isDiff(filename) {
|
|
51
|
-
const {
|
|
52
|
-
|
|
53
|
-
cachedSize
|
|
54
|
-
} = this;
|
|
55
|
-
const stats = _fs.default.statSync(filename);
|
|
65
|
+
const { cachedHash, cachedSize } = this;
|
|
66
|
+
const stats = import_fs.default.statSync(filename);
|
|
56
67
|
const hash = cachedHash[filename];
|
|
57
68
|
const size = cachedSize[filename];
|
|
58
69
|
if (stats.size !== size) {
|
|
@@ -67,7 +78,6 @@ class StatsCache {
|
|
|
67
78
|
return Boolean(this.cachedHash[filename]);
|
|
68
79
|
}
|
|
69
80
|
hash(stats, filename) {
|
|
70
|
-
return
|
|
81
|
+
return import_crypto.default.createHash("md5").update(import_fs.default.readFileSync(filename)).digest("hex");
|
|
71
82
|
}
|
|
72
83
|
}
|
|
73
|
-
exports.StatsCache = StatsCache;
|
package/dist/js/node/index.js
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 });
|
|
10
14
|
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var stdin_exports = {};
|
|
19
|
+
__export(stdin_exports, {
|
|
20
|
+
Server: () => import_server.DevServer,
|
|
21
|
+
default: () => src_default
|
|
11
22
|
});
|
|
12
|
-
exports
|
|
13
|
-
var
|
|
14
|
-
var
|
|
23
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
24
|
+
var import_server = require("./server");
|
|
25
|
+
var src_default = (options) => {
|
|
15
26
|
if (options == null) {
|
|
16
|
-
throw new Error(
|
|
27
|
+
throw new Error("can not start mserver without options");
|
|
17
28
|
}
|
|
18
|
-
const server = new
|
|
29
|
+
const server = new import_server.DevServer(options);
|
|
19
30
|
return server.init();
|
|
20
31
|
};
|
|
21
|
-
exports.default = _default;
|