@modern-js/server 2.0.0-beta.3 → 2.0.0-beta.6
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 +159 -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 +31 -14
- package/dist/js/node/dev-tools/dev-middleware/dev-server-plugin.js +38 -24
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +36 -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 +59 -66
- package/dist/js/node/dev-tools/https/global.d.js +0 -0
- package/dist/js/node/dev-tools/https/index.js +56 -13
- package/dist/js/node/dev-tools/mock/getMockData.js +90 -51
- package/dist/js/node/dev-tools/mock/index.js +66 -28
- package/dist/js/node/dev-tools/register/index.js +100 -64
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +55 -43
- package/dist/js/node/dev-tools/watcher/index.js +83 -47
- package/dist/js/node/dev-tools/watcher/stats-cache.js +44 -30
- package/dist/js/node/index.js +29 -15
- package/dist/js/node/server/dev-server.js +220 -237
- package/dist/js/node/server/index.js +30 -11
- package/dist/js/node/types.js +15 -0
- 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 +15 -12
|
@@ -1,102 +1,138 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var register_exports = {};
|
|
42
|
+
__export(register_exports, {
|
|
43
|
+
enableRegister: () => enableRegister
|
|
5
44
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
-
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; }
|
|
14
|
-
const debug = (0, _utils.createDebugger)('server');
|
|
45
|
+
module.exports = __toCommonJS(register_exports);
|
|
46
|
+
var import_path = __toESM(require("path"));
|
|
47
|
+
var import_server_utils = require("@modern-js/server-utils");
|
|
48
|
+
var import_utils = require("@modern-js/utils");
|
|
49
|
+
const debug = (0, import_utils.createDebugger)("server");
|
|
15
50
|
const checkDep = (depName, paths) => {
|
|
16
|
-
let packagePath =
|
|
51
|
+
let packagePath = "";
|
|
17
52
|
try {
|
|
18
53
|
packagePath = require.resolve(depName, {
|
|
19
54
|
paths
|
|
20
55
|
});
|
|
21
|
-
} catch (error) {
|
|
56
|
+
} catch (error) {
|
|
57
|
+
}
|
|
22
58
|
return Boolean(packagePath);
|
|
23
59
|
};
|
|
24
|
-
const enableRegister = (projectRoot, config
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
60
|
+
const enableRegister = (projectRoot, config) => {
|
|
61
|
+
var _a, _b, _c;
|
|
62
|
+
const registerDirs = ["./api", "./server", "./config/mock", "./shared"];
|
|
28
63
|
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
29
|
-
const tsconfigPath =
|
|
30
|
-
const isTsProject =
|
|
31
|
-
const existTsNode = checkDep(
|
|
32
|
-
const existTsConfigPaths = checkDep(
|
|
64
|
+
const tsconfigPath = import_path.default.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
65
|
+
const isTsProject = import_utils.fs.existsSync(tsconfigPath);
|
|
66
|
+
const existTsNode = checkDep("ts-node", [projectRoot]);
|
|
67
|
+
const existTsConfigPaths = checkDep("tsconfig-paths", [projectRoot]);
|
|
33
68
|
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, {
|
|
69
|
+
debug("use ts-node");
|
|
70
|
+
const distPath = ((_a = config.output.distPath) == null ? void 0 : _a.root) || "dist";
|
|
71
|
+
const tsNode = require("ts-node");
|
|
72
|
+
const tsConfigPaths = require("tsconfig-paths");
|
|
73
|
+
const { alias } = config.source;
|
|
74
|
+
const aliasConfig = (0, import_utils.getAliasConfig)(alias, {
|
|
43
75
|
appDirectory: projectRoot,
|
|
44
76
|
tsconfigPath
|
|
45
77
|
});
|
|
46
|
-
const {
|
|
47
|
-
paths = {},
|
|
48
|
-
absoluteBaseUrl = './'
|
|
49
|
-
} = aliasConfig;
|
|
78
|
+
const { paths = {}, absoluteBaseUrl = "./" } = aliasConfig;
|
|
50
79
|
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
51
80
|
let tsPath = paths[key];
|
|
52
|
-
if (typeof tsPath ===
|
|
53
|
-
tsPath =
|
|
81
|
+
if (typeof tsPath === "string" && import_path.default.isAbsolute(tsPath)) {
|
|
82
|
+
tsPath = import_path.default.relative(absoluteBaseUrl, tsPath);
|
|
54
83
|
}
|
|
55
|
-
if (typeof tsPath ===
|
|
84
|
+
if (typeof tsPath === "string") {
|
|
56
85
|
tsPath = [tsPath];
|
|
57
86
|
}
|
|
58
|
-
return
|
|
87
|
+
return __spreadProps(__spreadValues({}, o), {
|
|
59
88
|
[`${key}`]: tsPath
|
|
60
89
|
});
|
|
61
90
|
}, {});
|
|
62
91
|
tsConfigPaths.register({
|
|
63
|
-
baseUrl: absoluteBaseUrl ||
|
|
92
|
+
baseUrl: absoluteBaseUrl || "./",
|
|
64
93
|
paths: tsPaths
|
|
65
94
|
});
|
|
66
95
|
tsNode.register({
|
|
67
96
|
project: tsconfigPath,
|
|
68
|
-
// for env.d.ts, https://www.npmjs.com/package/ts-node#missing-types
|
|
69
97
|
files: true,
|
|
70
98
|
transpileOnly: true,
|
|
71
|
-
ignore: [
|
|
99
|
+
ignore: ["(?:^|/)node_modules/", `(?:^|/)${distPath}/`]
|
|
72
100
|
});
|
|
73
101
|
} else {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
102
|
+
debug("use @babel/register");
|
|
103
|
+
const babelConfig = (0, import_server_utils.resolveBabelConfig)(
|
|
104
|
+
projectRoot,
|
|
105
|
+
__spreadProps(__spreadValues({}, config.source), {
|
|
106
|
+
babelConfig: (_b = config.tools) == null ? void 0 : _b.babel,
|
|
107
|
+
server: {
|
|
108
|
+
compiler: (_c = config.server) == null ? void 0 : _c.compiler
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
{
|
|
112
|
+
tsconfigPath,
|
|
113
|
+
syntax: "es6+",
|
|
114
|
+
type: "commonjs"
|
|
80
115
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return true;
|
|
116
|
+
);
|
|
117
|
+
return require("@babel/register")(__spreadProps(__spreadValues({}, babelConfig), {
|
|
118
|
+
only: [
|
|
119
|
+
function(filePath) {
|
|
120
|
+
if (filePath.includes(`node_modules${import_path.default.sep}.modern-js`)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return registerDirs.some(
|
|
124
|
+
(registerDir) => filePath.startsWith(import_path.default.join(projectRoot, registerDir))
|
|
125
|
+
);
|
|
92
126
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
extensions: ['.js', '.ts'],
|
|
127
|
+
],
|
|
128
|
+
extensions: [".js", ".ts"],
|
|
96
129
|
babelrc: false,
|
|
97
130
|
configFile: false,
|
|
98
131
|
root: projectRoot
|
|
99
132
|
}));
|
|
100
133
|
}
|
|
101
134
|
};
|
|
102
|
-
|
|
135
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
+
0 && (module.exports = {
|
|
137
|
+
enableRegister
|
|
138
|
+
});
|
|
@@ -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 dependency_tree_exports = {};
|
|
25
|
+
__export(dependency_tree_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(dependency_tree_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,13 @@ 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
|
-
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
DependencyTree,
|
|
88
|
+
defaultIgnores
|
|
89
|
+
});
|
|
@@ -1,90 +1,121 @@
|
|
|
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 __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
|
|
5
44
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
-
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; }
|
|
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");
|
|
15
50
|
const defaultWatchOptions = {
|
|
16
|
-
// 初始化的时候不触发 add、addDir 事件
|
|
17
51
|
ignoreInitial: true,
|
|
18
52
|
ignored: /api\/typings\/.*/
|
|
19
53
|
};
|
|
20
|
-
|
|
21
|
-
const getWatchedFiles = watcher => {
|
|
54
|
+
const getWatchedFiles = (watcher) => {
|
|
22
55
|
const watched = watcher.getWatched();
|
|
23
56
|
const files = [];
|
|
24
|
-
Object.keys(watched).forEach(dir => {
|
|
25
|
-
watched[dir].forEach(fileName => {
|
|
26
|
-
files.push(
|
|
57
|
+
Object.keys(watched).forEach((dir) => {
|
|
58
|
+
watched[dir].forEach((fileName) => {
|
|
59
|
+
files.push(import_path.default.join(dir, fileName));
|
|
27
60
|
});
|
|
28
61
|
});
|
|
29
62
|
return files;
|
|
30
63
|
};
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const watchOptions = _objectSpread({}, options);
|
|
64
|
+
const mergeWatchOptions = (options) => {
|
|
65
|
+
const watchOptions = __spreadValues({}, options);
|
|
34
66
|
if (watchOptions) {
|
|
35
|
-
const {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
67
|
+
const { ignored } = watchOptions;
|
|
68
|
+
const finalIgnored = ignored ? [
|
|
69
|
+
defaultWatchOptions.ignored,
|
|
70
|
+
...Array.isArray(ignored) ? ignored : [ignored]
|
|
71
|
+
] : ignored;
|
|
39
72
|
if (finalIgnored) {
|
|
40
73
|
watchOptions.ignored = finalIgnored;
|
|
41
74
|
}
|
|
42
75
|
}
|
|
43
|
-
const finalWatchOptions =
|
|
76
|
+
const finalWatchOptions = __spreadValues(__spreadValues({}, defaultWatchOptions), watchOptions);
|
|
44
77
|
return finalWatchOptions;
|
|
45
78
|
};
|
|
46
|
-
exports.mergeWatchOptions = mergeWatchOptions;
|
|
47
79
|
class Watcher {
|
|
48
80
|
constructor() {
|
|
49
|
-
|
|
50
|
-
_defineProperty(this, "watcher", void 0);
|
|
81
|
+
this.dependencyTree = null;
|
|
51
82
|
}
|
|
52
83
|
listen(files, options, callback) {
|
|
53
84
|
const watched = files.filter(Boolean);
|
|
54
|
-
const filenames = watched.map(filename => filename.replace(/\\/g,
|
|
55
|
-
const cache = new
|
|
56
|
-
const watcher =
|
|
57
|
-
watcher.on(
|
|
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", () => {
|
|
58
89
|
cache.add(getWatchedFiles(watcher));
|
|
59
90
|
});
|
|
60
|
-
watcher.on(
|
|
61
|
-
if (!
|
|
91
|
+
watcher.on("change", (changed) => {
|
|
92
|
+
if (!import_utils.fs.existsSync(changed) || cache.isDiff(changed)) {
|
|
62
93
|
cache.refresh(changed);
|
|
63
|
-
callback(changed,
|
|
94
|
+
callback(changed, "change");
|
|
64
95
|
}
|
|
65
96
|
});
|
|
66
|
-
watcher.on(
|
|
97
|
+
watcher.on("add", (changed) => {
|
|
67
98
|
if (!cache.has(changed)) {
|
|
68
99
|
cache.add([changed]);
|
|
69
|
-
callback(changed,
|
|
100
|
+
callback(changed, "add");
|
|
70
101
|
}
|
|
71
102
|
});
|
|
72
|
-
watcher.on(
|
|
103
|
+
watcher.on("unlink", (changed) => {
|
|
73
104
|
cache.del(changed);
|
|
74
|
-
callback(changed,
|
|
105
|
+
callback(changed, "unlink");
|
|
75
106
|
});
|
|
76
107
|
this.watcher = watcher;
|
|
77
108
|
}
|
|
78
109
|
createDepTree() {
|
|
79
|
-
this.dependencyTree = new
|
|
110
|
+
this.dependencyTree = new import_dependency_tree.DependencyTree();
|
|
80
111
|
}
|
|
81
112
|
updateDepTree() {
|
|
82
|
-
var
|
|
83
|
-
(
|
|
113
|
+
var _a;
|
|
114
|
+
(_a = this.dependencyTree) == null ? void 0 : _a.update(require.cache);
|
|
84
115
|
}
|
|
85
116
|
cleanDepCache(filepath) {
|
|
86
|
-
var
|
|
87
|
-
const node = (
|
|
117
|
+
var _a;
|
|
118
|
+
const node = (_a = this.dependencyTree) == null ? void 0 : _a.getNode(filepath);
|
|
88
119
|
if (node && require.cache[filepath]) {
|
|
89
120
|
delete require.cache[filepath];
|
|
90
121
|
for (const parentNode of node.parent.values()) {
|
|
@@ -96,4 +127,9 @@ class Watcher {
|
|
|
96
127
|
return this.watcher.close();
|
|
97
128
|
}
|
|
98
129
|
}
|
|
99
|
-
|
|
130
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
131
|
+
0 && (module.exports = {
|
|
132
|
+
defaultWatchOptions,
|
|
133
|
+
getWatchedFiles,
|
|
134
|
+
mergeWatchOptions
|
|
135
|
+
});
|
|
@@ -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 stats_cache_exports = {};
|
|
25
|
+
__export(stats_cache_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(stats_cache_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,10 @@ 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
|
-
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
StatsCache
|
|
87
|
+
});
|