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