@modern-js/server 2.15.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.
Files changed (53) hide show
  1. package/dist/cjs/server/devServer.js +2 -2
  2. package/dist/esm/server/devServer.js +68 -24
  3. package/dist/esm-node/server/devServer.js +2 -2
  4. package/dist/js/modern/constants.js +19 -0
  5. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +41 -0
  6. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +143 -0
  7. package/dist/js/modern/dev-tools/dev-middleware/index.js +94 -0
  8. package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +132 -0
  9. package/dist/js/modern/dev-tools/https/index.js +49 -0
  10. package/dist/js/modern/dev-tools/mock/getMockData.js +114 -0
  11. package/dist/js/modern/dev-tools/mock/index.js +54 -0
  12. package/dist/js/modern/dev-tools/register/index.js +111 -0
  13. package/dist/js/modern/dev-tools/watcher/dependency-tree.js +59 -0
  14. package/dist/js/modern/dev-tools/watcher/index.js +106 -0
  15. package/dist/js/modern/dev-tools/watcher/stats-cache.js +58 -0
  16. package/dist/js/modern/index.js +12 -0
  17. package/dist/js/modern/server/dev-server.js +293 -0
  18. package/dist/js/modern/server/index.js +16 -0
  19. package/dist/js/modern/types.js +0 -0
  20. package/dist/js/node/constants.js +42 -0
  21. package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +65 -0
  22. package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +152 -0
  23. package/dist/js/node/dev-tools/dev-middleware/index.js +119 -0
  24. package/dist/js/node/dev-tools/dev-middleware/socket-server.js +159 -0
  25. package/dist/js/node/dev-tools/https/index.js +72 -0
  26. package/dist/js/node/dev-tools/mock/getMockData.js +135 -0
  27. package/dist/js/node/dev-tools/mock/index.js +83 -0
  28. package/dist/js/node/dev-tools/register/index.js +138 -0
  29. package/dist/js/node/dev-tools/watcher/dependency-tree.js +89 -0
  30. package/dist/js/node/dev-tools/watcher/index.js +135 -0
  31. package/dist/js/node/dev-tools/watcher/stats-cache.js +87 -0
  32. package/dist/js/node/index.js +35 -0
  33. package/dist/js/node/server/dev-server.js +310 -0
  34. package/dist/js/node/server/index.js +39 -0
  35. package/dist/js/node/types.js +15 -0
  36. package/dist/js/treeshaking/constants.js +21 -0
  37. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +51 -0
  38. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +157 -0
  39. package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +322 -0
  40. package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +209 -0
  41. package/dist/js/treeshaking/dev-tools/https/index.js +193 -0
  42. package/dist/js/treeshaking/dev-tools/mock/getMockData.js +327 -0
  43. package/dist/js/treeshaking/dev-tools/mock/index.js +191 -0
  44. package/dist/js/treeshaking/dev-tools/register/index.js +153 -0
  45. package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +150 -0
  46. package/dist/js/treeshaking/dev-tools/watcher/index.js +200 -0
  47. package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +128 -0
  48. package/dist/js/treeshaking/index.js +9 -0
  49. package/dist/js/treeshaking/server/dev-server.js +799 -0
  50. package/dist/js/treeshaking/server/index.js +92 -0
  51. package/dist/js/treeshaking/types.js +1 -0
  52. package/dist/types/server/devServer.d.ts +1 -1
  53. package/package.json +4 -4
@@ -0,0 +1,153 @@
1
+ function _defineProperty(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _objectSpread(target) {
15
+ for(var i = 1; i < arguments.length; i++){
16
+ var source = arguments[i] != null ? arguments[i] : {};
17
+ var ownKeys = Object.keys(source);
18
+ if (typeof Object.getOwnPropertySymbols === "function") {
19
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
+ }));
22
+ }
23
+ ownKeys.forEach(function(key) {
24
+ _defineProperty(target, key, source[key]);
25
+ });
26
+ }
27
+ return target;
28
+ }
29
+ function ownKeys(object, enumerableOnly) {
30
+ var keys = Object.keys(object);
31
+ if (Object.getOwnPropertySymbols) {
32
+ var symbols = Object.getOwnPropertySymbols(object);
33
+ if (enumerableOnly) {
34
+ symbols = symbols.filter(function(sym) {
35
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
36
+ });
37
+ }
38
+ keys.push.apply(keys, symbols);
39
+ }
40
+ return keys;
41
+ }
42
+ function _objectSpreadProps(target, source) {
43
+ source = source != null ? source : {};
44
+ if (Object.getOwnPropertyDescriptors) {
45
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
46
+ } else {
47
+ ownKeys(Object(source)).forEach(function(key) {
48
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
49
+ });
50
+ }
51
+ return target;
52
+ }
53
+ import path from "path";
54
+ import { resolveBabelConfig } from "@modern-js/server-utils";
55
+ import { fs, getAliasConfig, createDebugger } from "@modern-js/utils";
56
+ var debug = createDebugger("server");
57
+ var checkDep = function(depName, paths) {
58
+ var packagePath = "";
59
+ try {
60
+ packagePath = require.resolve(depName, {
61
+ paths: paths
62
+ });
63
+ } catch (error) {}
64
+ return Boolean(packagePath);
65
+ };
66
+ var enableRegister = function(projectRoot, config) {
67
+ var registerDirs = [
68
+ "./api",
69
+ "./server",
70
+ "./config/mock",
71
+ "./shared"
72
+ ];
73
+ var TS_CONFIG_FILENAME = "tsconfig.json";
74
+ var tsconfigPath = path.resolve(projectRoot, TS_CONFIG_FILENAME);
75
+ var isTsProject = fs.existsSync(tsconfigPath);
76
+ var existTsNode = checkDep("ts-node", [
77
+ projectRoot
78
+ ]);
79
+ var existTsConfigPaths = checkDep("tsconfig-paths", [
80
+ projectRoot
81
+ ]);
82
+ if (isTsProject && existTsNode && existTsConfigPaths) {
83
+ var ref;
84
+ debug("use ts-node");
85
+ var distPath = ((ref = config.output.distPath) === null || ref === void 0 ? void 0 : ref.root) || "dist";
86
+ var tsNode = require("ts-node");
87
+ var tsConfigPaths = require("tsconfig-paths");
88
+ var alias = config.source.alias;
89
+ var aliasConfig = getAliasConfig(alias, {
90
+ appDirectory: projectRoot,
91
+ tsconfigPath: tsconfigPath
92
+ });
93
+ var _paths = aliasConfig.paths, paths = _paths === void 0 ? {} : _paths, _absoluteBaseUrl = aliasConfig.absoluteBaseUrl, absoluteBaseUrl = _absoluteBaseUrl === void 0 ? "./" : _absoluteBaseUrl;
94
+ var tsPaths = Object.keys(paths).reduce(function(o, key) {
95
+ var tsPath = paths[key];
96
+ if (typeof tsPath === "string" && path.isAbsolute(tsPath)) {
97
+ tsPath = path.relative(absoluteBaseUrl, tsPath);
98
+ }
99
+ if (typeof tsPath === "string") {
100
+ tsPath = [
101
+ tsPath
102
+ ];
103
+ }
104
+ return _objectSpreadProps(_objectSpread({}, o), _defineProperty({}, "".concat(key), tsPath));
105
+ }, {});
106
+ tsConfigPaths.register({
107
+ baseUrl: absoluteBaseUrl || "./",
108
+ paths: tsPaths
109
+ });
110
+ tsNode.register({
111
+ project: tsconfigPath,
112
+ files: true,
113
+ transpileOnly: true,
114
+ ignore: [
115
+ "(?:^|/)node_modules/",
116
+ "(?:^|/)".concat(distPath, "/")
117
+ ]
118
+ });
119
+ } else {
120
+ var ref1, ref2;
121
+ debug("use @babel/register");
122
+ var babelConfig = resolveBabelConfig(projectRoot, _objectSpreadProps(_objectSpread({}, config.source), {
123
+ babelConfig: (ref1 = config.tools) === null || ref1 === void 0 ? void 0 : ref1.babel,
124
+ server: {
125
+ compiler: (ref2 = config.server) === null || ref2 === void 0 ? void 0 : ref2.compiler
126
+ }
127
+ }), {
128
+ tsconfigPath: tsconfigPath,
129
+ syntax: "es6+",
130
+ type: "commonjs"
131
+ });
132
+ return require("@babel/register")(_objectSpreadProps(_objectSpread({}, babelConfig), {
133
+ only: [
134
+ function(filePath) {
135
+ if (filePath.includes("node_modules".concat(path.sep, ".modern-js"))) {
136
+ return true;
137
+ }
138
+ return registerDirs.some(function(registerDir) {
139
+ return filePath.startsWith(path.join(projectRoot, registerDir));
140
+ });
141
+ }
142
+ ],
143
+ extensions: [
144
+ ".js",
145
+ ".ts"
146
+ ],
147
+ babelrc: false,
148
+ configFile: false,
149
+ root: projectRoot
150
+ }));
151
+ }
152
+ };
153
+ export { enableRegister };
@@ -0,0 +1,150 @@
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithoutHoles(arr) {
7
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
+ }
9
+ function _classCallCheck(instance, Constructor) {
10
+ if (!(instance instanceof Constructor)) {
11
+ throw new TypeError("Cannot call a class as a function");
12
+ }
13
+ }
14
+ function _defineProperties(target, props) {
15
+ for(var i = 0; i < props.length; i++){
16
+ var descriptor = props[i];
17
+ descriptor.enumerable = descriptor.enumerable || false;
18
+ descriptor.configurable = true;
19
+ if ("value" in descriptor) descriptor.writable = true;
20
+ Object.defineProperty(target, descriptor.key, descriptor);
21
+ }
22
+ }
23
+ function _createClass(Constructor, protoProps, staticProps) {
24
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
25
+ if (staticProps) _defineProperties(Constructor, staticProps);
26
+ return Constructor;
27
+ }
28
+ function _defineProperty(obj, key, value) {
29
+ if (key in obj) {
30
+ Object.defineProperty(obj, key, {
31
+ value: value,
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true
35
+ });
36
+ } else {
37
+ obj[key] = value;
38
+ }
39
+ return obj;
40
+ }
41
+ function _iterableToArray(iter) {
42
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
43
+ }
44
+ function _nonIterableSpread() {
45
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
46
+ }
47
+ function _toConsumableArray(arr) {
48
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
49
+ }
50
+ function _unsupportedIterableToArray(o, minLen) {
51
+ if (!o) return;
52
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
53
+ var n = Object.prototype.toString.call(o).slice(8, -1);
54
+ if (n === "Object" && o.constructor) n = o.constructor.name;
55
+ if (n === "Map" || n === "Set") return Array.from(n);
56
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
57
+ }
58
+ import minimatch from "minimatch";
59
+ var defaultIgnores = [
60
+ "**/bower_components/**",
61
+ "**/coverage/**",
62
+ "**/node_modules/**",
63
+ "**/.*/**",
64
+ "**/*.d.ts",
65
+ "**/*.log"
66
+ ];
67
+ var DependencyTree = /*#__PURE__*/ function() {
68
+ "use strict";
69
+ function DependencyTree() {
70
+ _classCallCheck(this, DependencyTree);
71
+ _defineProperty(this, "tree", void 0);
72
+ _defineProperty(this, "ignore", void 0);
73
+ this.tree = /* @__PURE__ */ new Map();
74
+ this.ignore = _toConsumableArray(defaultIgnores);
75
+ }
76
+ _createClass(DependencyTree, [
77
+ {
78
+ key: "getNode",
79
+ value: function getNode(path) {
80
+ return this.tree.get(path);
81
+ }
82
+ },
83
+ {
84
+ key: "update",
85
+ value: function update(cache) {
86
+ var _this = this;
87
+ this.tree.clear();
88
+ Object.keys(cache).forEach(function(path) {
89
+ if (!_this.shouldIgnore(path)) {
90
+ var module = cache[path];
91
+ _this.tree.set(module.filename, {
92
+ module: module,
93
+ parent: /* @__PURE__ */ new Set(),
94
+ children: /* @__PURE__ */ new Set()
95
+ });
96
+ }
97
+ });
98
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
99
+ try {
100
+ var _this1 = this, _loop = function() {
101
+ var treeNode = _step.value;
102
+ var parent = treeNode.module.parent;
103
+ var children = treeNode.module.children;
104
+ if (parent && !_this1.shouldIgnore(parent.filename)) {
105
+ var parentTreeNode = _this1.tree.get(parent.filename);
106
+ if (parentTreeNode) {
107
+ treeNode.parent.add(parentTreeNode);
108
+ }
109
+ }
110
+ children.forEach(function(child) {
111
+ if (!_this.shouldIgnore(child.filename)) {
112
+ var childTreeNode = _this.tree.get(child.filename);
113
+ if (childTreeNode) {
114
+ treeNode.children.add(childTreeNode);
115
+ childTreeNode.parent.add(treeNode);
116
+ }
117
+ }
118
+ });
119
+ };
120
+ for(var _iterator = this.tree.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
121
+ } catch (err) {
122
+ _didIteratorError = true;
123
+ _iteratorError = err;
124
+ } finally{
125
+ try {
126
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
127
+ _iterator.return();
128
+ }
129
+ } finally{
130
+ if (_didIteratorError) {
131
+ throw _iteratorError;
132
+ }
133
+ }
134
+ }
135
+ }
136
+ },
137
+ {
138
+ key: "shouldIgnore",
139
+ value: function shouldIgnore(path) {
140
+ return !path || Boolean(this.ignore.find(function(rule) {
141
+ return minimatch.match([
142
+ path
143
+ ], rule).length > 0;
144
+ }));
145
+ }
146
+ }
147
+ ]);
148
+ return DependencyTree;
149
+ }();
150
+ export { DependencyTree, defaultIgnores };
@@ -0,0 +1,200 @@
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithoutHoles(arr) {
7
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
+ }
9
+ function _classCallCheck(instance, Constructor) {
10
+ if (!(instance instanceof Constructor)) {
11
+ throw new TypeError("Cannot call a class as a function");
12
+ }
13
+ }
14
+ function _defineProperties(target, props) {
15
+ for(var i = 0; i < props.length; i++){
16
+ var descriptor = props[i];
17
+ descriptor.enumerable = descriptor.enumerable || false;
18
+ descriptor.configurable = true;
19
+ if ("value" in descriptor) descriptor.writable = true;
20
+ Object.defineProperty(target, descriptor.key, descriptor);
21
+ }
22
+ }
23
+ function _createClass(Constructor, protoProps, staticProps) {
24
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
25
+ if (staticProps) _defineProperties(Constructor, staticProps);
26
+ return Constructor;
27
+ }
28
+ function _defineProperty(obj, key, value) {
29
+ if (key in obj) {
30
+ Object.defineProperty(obj, key, {
31
+ value: value,
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true
35
+ });
36
+ } else {
37
+ obj[key] = value;
38
+ }
39
+ return obj;
40
+ }
41
+ function _iterableToArray(iter) {
42
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
43
+ }
44
+ function _nonIterableSpread() {
45
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
46
+ }
47
+ function _objectSpread(target) {
48
+ for(var i = 1; i < arguments.length; i++){
49
+ var source = arguments[i] != null ? arguments[i] : {};
50
+ var ownKeys = Object.keys(source);
51
+ if (typeof Object.getOwnPropertySymbols === "function") {
52
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
53
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
54
+ }));
55
+ }
56
+ ownKeys.forEach(function(key) {
57
+ _defineProperty(target, key, source[key]);
58
+ });
59
+ }
60
+ return target;
61
+ }
62
+ function _toConsumableArray(arr) {
63
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
64
+ }
65
+ function _unsupportedIterableToArray(o, minLen) {
66
+ if (!o) return;
67
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
68
+ var n = Object.prototype.toString.call(o).slice(8, -1);
69
+ if (n === "Object" && o.constructor) n = o.constructor.name;
70
+ if (n === "Map" || n === "Set") return Array.from(n);
71
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
72
+ }
73
+ import path from "path";
74
+ import { fs, chokidar } from "@modern-js/utils";
75
+ import { DependencyTree } from "./dependency-tree";
76
+ import { StatsCache } from "./stats-cache";
77
+ var defaultWatchOptions = {
78
+ ignoreInitial: true,
79
+ ignored: /api\/typings\/.*/
80
+ };
81
+ var getWatchedFiles = function(watcher) {
82
+ var watched = watcher.getWatched();
83
+ var files = [];
84
+ Object.keys(watched).forEach(function(dir) {
85
+ watched[dir].forEach(function(fileName) {
86
+ files.push(path.join(dir, fileName));
87
+ });
88
+ });
89
+ return files;
90
+ };
91
+ var mergeWatchOptions = function(options) {
92
+ var watchOptions = _objectSpread({}, options);
93
+ if (watchOptions) {
94
+ var ignored = watchOptions.ignored;
95
+ var finalIgnored = ignored ? [
96
+ defaultWatchOptions.ignored
97
+ ].concat(_toConsumableArray(Array.isArray(ignored) ? ignored : [
98
+ ignored
99
+ ])) : ignored;
100
+ if (finalIgnored) {
101
+ watchOptions.ignored = finalIgnored;
102
+ }
103
+ }
104
+ var finalWatchOptions = _objectSpread({}, defaultWatchOptions, watchOptions);
105
+ return finalWatchOptions;
106
+ };
107
+ var Watcher = /*#__PURE__*/ function() {
108
+ "use strict";
109
+ function Watcher() {
110
+ _classCallCheck(this, Watcher);
111
+ _defineProperty(this, "dependencyTree", null);
112
+ _defineProperty(this, "watcher", void 0);
113
+ }
114
+ _createClass(Watcher, [
115
+ {
116
+ key: "listen",
117
+ value: function listen(files, options, callback) {
118
+ var watched = files.filter(Boolean);
119
+ var filenames = watched.map(function(filename) {
120
+ return filename.replace(/\\/g, "/");
121
+ });
122
+ var cache = new StatsCache();
123
+ var watcher = chokidar.watch(filenames, options);
124
+ watcher.on("ready", function() {
125
+ cache.add(getWatchedFiles(watcher));
126
+ });
127
+ watcher.on("change", function(changed) {
128
+ if (!fs.existsSync(changed) || cache.isDiff(changed)) {
129
+ cache.refresh(changed);
130
+ callback(changed, "change");
131
+ }
132
+ });
133
+ watcher.on("add", function(changed) {
134
+ if (!cache.has(changed)) {
135
+ cache.add([
136
+ changed
137
+ ]);
138
+ callback(changed, "add");
139
+ }
140
+ });
141
+ watcher.on("unlink", function(changed) {
142
+ cache.del(changed);
143
+ callback(changed, "unlink");
144
+ });
145
+ this.watcher = watcher;
146
+ }
147
+ },
148
+ {
149
+ key: "createDepTree",
150
+ value: function createDepTree() {
151
+ this.dependencyTree = new DependencyTree();
152
+ }
153
+ },
154
+ {
155
+ key: "updateDepTree",
156
+ value: function updateDepTree() {
157
+ var ref;
158
+ (ref = this.dependencyTree) === null || ref === void 0 ? void 0 : ref.update(require.cache);
159
+ }
160
+ },
161
+ {
162
+ key: "cleanDepCache",
163
+ value: function cleanDepCache(filepath) {
164
+ var ref;
165
+ var node = (ref = this.dependencyTree) === null || ref === void 0 ? void 0 : ref.getNode(filepath);
166
+ if (node && require.cache[filepath]) {
167
+ delete require.cache[filepath];
168
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
169
+ try {
170
+ for(var _iterator = node.parent.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
171
+ var parentNode = _step.value;
172
+ this.cleanDepCache(parentNode.module.filename);
173
+ }
174
+ } catch (err) {
175
+ _didIteratorError = true;
176
+ _iteratorError = err;
177
+ } finally{
178
+ try {
179
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
180
+ _iterator.return();
181
+ }
182
+ } finally{
183
+ if (_didIteratorError) {
184
+ throw _iteratorError;
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ },
191
+ {
192
+ key: "close",
193
+ value: function close() {
194
+ return this.watcher.close();
195
+ }
196
+ }
197
+ ]);
198
+ return Watcher;
199
+ }();
200
+ export { Watcher as default, defaultWatchOptions, getWatchedFiles, mergeWatchOptions };
@@ -0,0 +1,128 @@
1
+ function _classCallCheck(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ function _defineProperties(target, props) {
7
+ for(var i = 0; i < props.length; i++){
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor) descriptor.writable = true;
12
+ Object.defineProperty(target, descriptor.key, descriptor);
13
+ }
14
+ }
15
+ function _createClass(Constructor, protoProps, staticProps) {
16
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
+ if (staticProps) _defineProperties(Constructor, staticProps);
18
+ return Constructor;
19
+ }
20
+ function _defineProperty(obj, key, value) {
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
30
+ }
31
+ return obj;
32
+ }
33
+ import fs from "fs";
34
+ import crypto from "crypto";
35
+ var StatsCache = /*#__PURE__*/ function() {
36
+ "use strict";
37
+ function StatsCache() {
38
+ _classCallCheck(this, StatsCache);
39
+ _defineProperty(this, "cachedHash", {});
40
+ _defineProperty(this, "cachedSize", {});
41
+ }
42
+ _createClass(StatsCache, [
43
+ {
44
+ key: "add",
45
+ value: function add(files) {
46
+ var ref = this, cachedHash = ref.cachedHash, cachedSize = ref.cachedSize;
47
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
48
+ try {
49
+ for(var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
50
+ var filename = _step.value;
51
+ if (fs.existsSync(filename)) {
52
+ var stats = fs.statSync(filename);
53
+ if (stats.isFile() && !cachedHash[filename]) {
54
+ cachedHash[filename] = this.hash(stats, filename);
55
+ cachedSize[filename] = stats.size;
56
+ }
57
+ }
58
+ }
59
+ } catch (err) {
60
+ _didIteratorError = true;
61
+ _iteratorError = err;
62
+ } finally{
63
+ try {
64
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
65
+ _iterator.return();
66
+ }
67
+ } finally{
68
+ if (_didIteratorError) {
69
+ throw _iteratorError;
70
+ }
71
+ }
72
+ }
73
+ }
74
+ },
75
+ {
76
+ key: "refresh",
77
+ value: function refresh(filename) {
78
+ var ref = this, cachedHash = ref.cachedHash, cachedSize = ref.cachedSize;
79
+ if (fs.existsSync(filename)) {
80
+ var stats = fs.statSync(filename);
81
+ if (stats.isFile()) {
82
+ cachedHash[filename] = this.hash(stats, filename);
83
+ cachedSize[filename] = stats.size;
84
+ }
85
+ }
86
+ }
87
+ },
88
+ {
89
+ key: "del",
90
+ value: function del(filename) {
91
+ if (this.cachedHash[filename]) {
92
+ delete this.cachedHash[filename];
93
+ delete this.cachedSize[filename];
94
+ }
95
+ }
96
+ },
97
+ {
98
+ key: "isDiff",
99
+ value: function isDiff(filename) {
100
+ var ref = this, cachedHash = ref.cachedHash, cachedSize = ref.cachedSize;
101
+ var stats = fs.statSync(filename);
102
+ var hash = cachedHash[filename];
103
+ var size = cachedSize[filename];
104
+ if (stats.size !== size) {
105
+ return true;
106
+ }
107
+ if (this.hash(stats, filename) !== hash) {
108
+ return true;
109
+ }
110
+ return false;
111
+ }
112
+ },
113
+ {
114
+ key: "has",
115
+ value: function has(filename) {
116
+ return Boolean(this.cachedHash[filename]);
117
+ }
118
+ },
119
+ {
120
+ key: "hash",
121
+ value: function hash(stats, filename) {
122
+ return crypto.createHash("md5").update(fs.readFileSync(filename)).digest("hex");
123
+ }
124
+ }
125
+ ]);
126
+ return StatsCache;
127
+ }();
128
+ export { StatsCache };
@@ -0,0 +1,9 @@
1
+ import { DevServer as Server } from "./server";
2
+ var src_default = function(options) {
3
+ if (options == null) {
4
+ throw new Error("can not start server without options");
5
+ }
6
+ var server = new Server(options);
7
+ return server.init();
8
+ };
9
+ export { Server, src_default as default };