@modern-js/core 1.9.2 → 1.10.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 (130) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/compiled/ajv-keywords/index.d.ts +1 -0
  3. package/compiled/ajv-keywords/package.json +1 -1
  4. package/compiled/better-ajv-errors/index.d.ts +1 -0
  5. package/compiled/better-ajv-errors/package.json +1 -1
  6. package/compiled/v8-compile-cache/index.d.ts +1 -0
  7. package/compiled/v8-compile-cache/package.json +1 -1
  8. package/dist/config/index.d.ts +1 -1
  9. package/dist/config/index.js +19 -28
  10. package/dist/config/types/index.d.ts +36 -36
  11. package/dist/index.js +55 -60
  12. package/dist/initWatcher.js +3 -12
  13. package/package.json +7 -8
  14. package/tsconfig.json +1 -0
  15. package/compiled/ajv-keywords/ajv/dist/ajv.d.ts +0 -16
  16. package/compiled/ajv-keywords/ajv/dist/compile/codegen/code.d.ts +0 -40
  17. package/compiled/ajv-keywords/ajv/dist/compile/codegen/index.d.ts +0 -79
  18. package/compiled/ajv-keywords/ajv/dist/compile/codegen/scope.d.ts +0 -79
  19. package/compiled/ajv-keywords/ajv/dist/compile/errors.d.ts +0 -13
  20. package/compiled/ajv-keywords/ajv/dist/compile/index.d.ts +0 -80
  21. package/compiled/ajv-keywords/ajv/dist/compile/ref_error.d.ts +0 -6
  22. package/compiled/ajv-keywords/ajv/dist/compile/resolve.d.ts +0 -12
  23. package/compiled/ajv-keywords/ajv/dist/compile/rules.d.ts +0 -28
  24. package/compiled/ajv-keywords/ajv/dist/compile/util.d.ts +0 -40
  25. package/compiled/ajv-keywords/ajv/dist/compile/validate/index.d.ts +0 -42
  26. package/compiled/ajv-keywords/ajv/dist/compile/validate/subschema.d.ts +0 -47
  27. package/compiled/ajv-keywords/ajv/dist/core.d.ts +0 -173
  28. package/compiled/ajv-keywords/ajv/dist/runtime/validation_error.d.ts +0 -7
  29. package/compiled/ajv-keywords/ajv/dist/types/index.d.ts +0 -183
  30. package/compiled/ajv-keywords/ajv/dist/types/json-schema.d.ts +0 -124
  31. package/compiled/ajv-keywords/ajv/dist/types/jtd-schema.d.ts +0 -169
  32. package/compiled/ajv-keywords/dist/index.d.ts +0 -4
  33. package/compiled/ajv-keywords/uri-js/dist/es5/uri.all.d.ts +0 -59
  34. package/compiled/better-ajv-errors/ajv/dist/ajv.d.ts +0 -16
  35. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/code.d.ts +0 -40
  36. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/index.d.ts +0 -79
  37. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/scope.d.ts +0 -79
  38. package/compiled/better-ajv-errors/ajv/dist/compile/errors.d.ts +0 -13
  39. package/compiled/better-ajv-errors/ajv/dist/compile/index.d.ts +0 -80
  40. package/compiled/better-ajv-errors/ajv/dist/compile/ref_error.d.ts +0 -6
  41. package/compiled/better-ajv-errors/ajv/dist/compile/resolve.d.ts +0 -12
  42. package/compiled/better-ajv-errors/ajv/dist/compile/rules.d.ts +0 -28
  43. package/compiled/better-ajv-errors/ajv/dist/compile/util.d.ts +0 -40
  44. package/compiled/better-ajv-errors/ajv/dist/compile/validate/index.d.ts +0 -42
  45. package/compiled/better-ajv-errors/ajv/dist/compile/validate/subschema.d.ts +0 -47
  46. package/compiled/better-ajv-errors/ajv/dist/core.d.ts +0 -173
  47. package/compiled/better-ajv-errors/ajv/dist/runtime/validation_error.d.ts +0 -7
  48. package/compiled/better-ajv-errors/ajv/dist/types/index.d.ts +0 -183
  49. package/compiled/better-ajv-errors/ajv/dist/types/json-schema.d.ts +0 -124
  50. package/compiled/better-ajv-errors/ajv/dist/types/jtd-schema.d.ts +0 -169
  51. package/compiled/better-ajv-errors/typings.d.ts +0 -24
  52. package/compiled/better-ajv-errors/uri-js/dist/es5/uri.all.d.ts +0 -59
  53. package/dist/js/modern/cli.js +0 -29
  54. package/dist/js/modern/config/defaults.js +0 -103
  55. package/dist/js/modern/config/index.js +0 -115
  56. package/dist/js/modern/config/mergeConfig.js +0 -22
  57. package/dist/js/modern/config/schema/deploy.js +0 -17
  58. package/dist/js/modern/config/schema/index.js +0 -107
  59. package/dist/js/modern/config/schema/output.js +0 -147
  60. package/dist/js/modern/config/schema/server.js +0 -170
  61. package/dist/js/modern/config/schema/source.js +0 -59
  62. package/dist/js/modern/config/schema/tools.js +0 -36
  63. package/dist/js/modern/config/types/electron.js +0 -1
  64. package/dist/js/modern/config/types/index.js +0 -1
  65. package/dist/js/modern/config/types/less.js +0 -0
  66. package/dist/js/modern/config/types/sass.js +0 -0
  67. package/dist/js/modern/config/types/ssg.js +0 -0
  68. package/dist/js/modern/config/types/test.js +0 -0
  69. package/dist/js/modern/config/types/unbundle.js +0 -0
  70. package/dist/js/modern/context.js +0 -63
  71. package/dist/js/modern/index.js +0 -169
  72. package/dist/js/modern/initWatcher.js +0 -62
  73. package/dist/js/modern/loadEnv.js +0 -14
  74. package/dist/js/modern/loadPlugins.js +0 -122
  75. package/dist/js/modern/manager.js +0 -28
  76. package/dist/js/modern/pluginAPI.js +0 -11
  77. package/dist/js/modern/utils/commander.js +0 -19
  78. package/dist/js/modern/utils/repeatKeyWarning.js +0 -18
  79. package/dist/js/node/cli.js +0 -35
  80. package/dist/js/node/config/defaults.js +0 -110
  81. package/dist/js/node/config/index.js +0 -182
  82. package/dist/js/node/config/mergeConfig.js +0 -32
  83. package/dist/js/node/config/schema/deploy.js +0 -26
  84. package/dist/js/node/config/schema/index.js +0 -127
  85. package/dist/js/node/config/schema/output.js +0 -156
  86. package/dist/js/node/config/schema/server.js +0 -179
  87. package/dist/js/node/config/schema/source.js +0 -68
  88. package/dist/js/node/config/schema/tools.js +0 -43
  89. package/dist/js/node/config/types/electron.js +0 -5
  90. package/dist/js/node/config/types/index.js +0 -5
  91. package/dist/js/node/config/types/less.js +0 -0
  92. package/dist/js/node/config/types/sass.js +0 -0
  93. package/dist/js/node/config/types/ssg.js +0 -0
  94. package/dist/js/node/config/types/test.js +0 -0
  95. package/dist/js/node/config/types/unbundle.js +0 -0
  96. package/dist/js/node/context.js +0 -93
  97. package/dist/js/node/index.js +0 -329
  98. package/dist/js/node/initWatcher.js +0 -82
  99. package/dist/js/node/loadEnv.js +0 -30
  100. package/dist/js/node/loadPlugins.js +0 -134
  101. package/dist/js/node/manager.js +0 -45
  102. package/dist/js/node/pluginAPI.js +0 -54
  103. package/dist/js/node/utils/commander.js +0 -32
  104. package/dist/js/node/utils/repeatKeyWarning.js +0 -31
  105. package/dist/types/cli.d.ts +0 -1
  106. package/dist/types/config/defaults.d.ts +0 -28
  107. package/dist/types/config/index.d.ts +0 -12
  108. package/dist/types/config/mergeConfig.d.ts +0 -31
  109. package/dist/types/config/schema/deploy.d.ts +0 -16
  110. package/dist/types/config/schema/index.d.ts +0 -466
  111. package/dist/types/config/schema/output.d.ts +0 -146
  112. package/dist/types/config/schema/server.d.ts +0 -182
  113. package/dist/types/config/schema/source.d.ts +0 -58
  114. package/dist/types/config/schema/tools.d.ts +0 -36
  115. package/dist/types/config/types/electron.d.ts +0 -13
  116. package/dist/types/config/types/index.d.ts +0 -252
  117. package/dist/types/config/types/less.d.ts +0 -10
  118. package/dist/types/config/types/sass.d.ts +0 -8
  119. package/dist/types/config/types/ssg.d.ts +0 -13
  120. package/dist/types/config/types/test.d.ts +0 -15
  121. package/dist/types/config/types/unbundle.d.ts +0 -28
  122. package/dist/types/context.d.ts +0 -47
  123. package/dist/types/index.d.ts +0 -64
  124. package/dist/types/initWatcher.d.ts +0 -3
  125. package/dist/types/loadEnv.d.ts +0 -1
  126. package/dist/types/loadPlugins.d.ts +0 -44
  127. package/dist/types/manager.d.ts +0 -75
  128. package/dist/types/pluginAPI.d.ts +0 -13
  129. package/dist/types/utils/commander.d.ts +0 -4
  130. package/dist/types/utils/repeatKeyWarning.d.ts +0 -3
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.source = void 0;
7
-
8
- var _utils = require("@modern-js/utils");
9
-
10
- const source = {
11
- type: 'object',
12
- additionalProperties: false,
13
- properties: {
14
- entries: {
15
- type: 'object',
16
- patternProperties: {
17
- [_utils.ENTRY_NAME_PATTERN]: {
18
- if: {
19
- type: 'object'
20
- },
21
- then: {
22
- required: ['entry'],
23
- properties: {
24
- entry: {
25
- type: ['string', 'array']
26
- },
27
- disableMount: {
28
- type: 'boolean'
29
- },
30
- enableFileSystemRoutes: {
31
- type: 'boolean'
32
- }
33
- },
34
- additionalProperties: false
35
- },
36
- else: {
37
- type: ['string', 'array']
38
- }
39
- }
40
- }
41
- },
42
- alias: {
43
- typeof: ['object', 'function']
44
- },
45
- disableDefaultEntries: {
46
- type: 'boolean'
47
- },
48
- envVars: {
49
- type: 'array'
50
- },
51
- globalVars: {
52
- type: 'object'
53
- },
54
- moduleScopes: {
55
- instanceof: ['Array', 'Function']
56
- },
57
- entriesDir: {
58
- type: 'string'
59
- },
60
- configDir: {
61
- type: 'string'
62
- },
63
- include: {
64
- type: ['array']
65
- }
66
- }
67
- };
68
- exports.source = source;
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.tools = void 0;
7
- const tools = {
8
- type: 'object',
9
- additionalProperties: false,
10
- properties: {
11
- webpack: {
12
- typeof: ['object', 'function']
13
- },
14
- babel: {
15
- typeof: ['object', 'function']
16
- },
17
- postcss: {
18
- typeof: ['object', 'function']
19
- },
20
- lodash: {
21
- typeof: ['object', 'function']
22
- },
23
- devServer: {
24
- type: 'object'
25
- },
26
- tsLoader: {
27
- typeof: ['object', 'function']
28
- },
29
- autoprefixer: {
30
- typeof: ['object', 'function']
31
- },
32
- terser: {
33
- typeof: ['object', 'function']
34
- },
35
- minifyCss: {
36
- typeof: ['object', 'function']
37
- },
38
- styledComponents: {
39
- typeof: ['object', 'function']
40
- }
41
- }
42
- };
43
- exports.tools = tools;
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,93 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.setAppContext = exports.initAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = void 0;
7
-
8
- var _path = _interopRequireDefault(require("path"));
9
-
10
- var _plugin = require("@modern-js/plugin");
11
-
12
- var _address = _interopRequireDefault(require("address"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const AppContext = (0, _plugin.createContext)({});
17
- exports.AppContext = AppContext;
18
- const ConfigContext = (0, _plugin.createContext)({});
19
- exports.ConfigContext = ConfigContext;
20
- const ResolvedConfigContext = (0, _plugin.createContext)({});
21
- /**
22
- * Set app context.
23
- * @param value new app context. It will override previous app context.
24
- */
25
-
26
- exports.ResolvedConfigContext = ResolvedConfigContext;
27
-
28
- const setAppContext = value => AppContext.set(value);
29
- /**
30
- * Get app context, including directories, plugins and some static infos.
31
- */
32
-
33
-
34
- exports.setAppContext = setAppContext;
35
-
36
- const useAppContext = () => AppContext.use().value;
37
- /**
38
- * Get original content of user config.
39
- */
40
-
41
-
42
- exports.useAppContext = useAppContext;
43
-
44
- const useConfigContext = () => ConfigContext.use().value;
45
- /**
46
- * Get normalized content of user config.
47
- */
48
-
49
-
50
- exports.useConfigContext = useConfigContext;
51
-
52
- const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
53
-
54
- exports.useResolvedConfigContext = useResolvedConfigContext;
55
-
56
- const initAppContext = ({
57
- appDirectory,
58
- plugins,
59
- configFile,
60
- options,
61
- serverConfigFile
62
- }) => {
63
- const {
64
- metaName = 'modern-js',
65
- srcDir = 'src',
66
- distDir = '',
67
- sharedDir = 'shared'
68
- } = options || {};
69
- return {
70
- metaName,
71
- appDirectory,
72
- configFile,
73
- serverConfigFile,
74
- ip: _address.default.ip(),
75
- port: 0,
76
- packageName: require(_path.default.resolve(appDirectory, './package.json')).name,
77
- srcDirectory: _path.default.resolve(appDirectory, srcDir),
78
- distDirectory: distDir,
79
- sharedDirectory: _path.default.resolve(appDirectory, sharedDir),
80
- nodeModulesDirectory: _path.default.resolve(appDirectory, './node_modules'),
81
- internalDirectory: _path.default.resolve(appDirectory, `./node_modules/.${metaName}`),
82
- plugins,
83
- htmlTemplates: {},
84
- serverRoutes: [],
85
- entrypoints: [],
86
- checkedEntries: [],
87
- apiOnly: false,
88
- internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
89
- internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
90
- };
91
- };
92
-
93
- exports.initAppContext = initAppContext;
@@ -1,329 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- mergeOptions: true,
8
- cli: true,
9
- initAppDir: true,
10
- initAppContext: true,
11
- manager: true,
12
- mountHook: true,
13
- usePlugins: true,
14
- createPlugin: true,
15
- registerHook: true,
16
- AppContext: true,
17
- ConfigContext: true,
18
- ResolvedConfigContext: true,
19
- useAppContext: true,
20
- useConfigContext: true,
21
- useResolvedConfigContext: true
22
- };
23
- Object.defineProperty(exports, "AppContext", {
24
- enumerable: true,
25
- get: function () {
26
- return _pluginAPI.AppContext;
27
- }
28
- });
29
- Object.defineProperty(exports, "ConfigContext", {
30
- enumerable: true,
31
- get: function () {
32
- return _pluginAPI.ConfigContext;
33
- }
34
- });
35
- Object.defineProperty(exports, "ResolvedConfigContext", {
36
- enumerable: true,
37
- get: function () {
38
- return _pluginAPI.ResolvedConfigContext;
39
- }
40
- });
41
- exports.cli = void 0;
42
- Object.defineProperty(exports, "createPlugin", {
43
- enumerable: true,
44
- get: function () {
45
- return _manager.createPlugin;
46
- }
47
- });
48
- Object.defineProperty(exports, "initAppContext", {
49
- enumerable: true,
50
- get: function () {
51
- return _context.initAppContext;
52
- }
53
- });
54
- exports.initAppDir = void 0;
55
- Object.defineProperty(exports, "manager", {
56
- enumerable: true,
57
- get: function () {
58
- return _manager.manager;
59
- }
60
- });
61
- exports.mergeOptions = void 0;
62
- Object.defineProperty(exports, "mountHook", {
63
- enumerable: true,
64
- get: function () {
65
- return _manager.mountHook;
66
- }
67
- });
68
- Object.defineProperty(exports, "registerHook", {
69
- enumerable: true,
70
- get: function () {
71
- return _manager.registerHook;
72
- }
73
- });
74
- Object.defineProperty(exports, "useAppContext", {
75
- enumerable: true,
76
- get: function () {
77
- return _pluginAPI.useAppContext;
78
- }
79
- });
80
- Object.defineProperty(exports, "useConfigContext", {
81
- enumerable: true,
82
- get: function () {
83
- return _pluginAPI.useConfigContext;
84
- }
85
- });
86
- Object.defineProperty(exports, "usePlugins", {
87
- enumerable: true,
88
- get: function () {
89
- return _manager.usePlugins;
90
- }
91
- });
92
- Object.defineProperty(exports, "useResolvedConfigContext", {
93
- enumerable: true,
94
- get: function () {
95
- return _pluginAPI.useResolvedConfigContext;
96
- }
97
- });
98
-
99
- var _path = _interopRequireDefault(require("path"));
100
-
101
- var _utils = require("@modern-js/utils");
102
-
103
- var _node = require("@modern-js/plugin/node");
104
-
105
- Object.keys(_node).forEach(function (key) {
106
- if (key === "default" || key === "__esModule") return;
107
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
108
- if (key in exports && exports[key] === _node[key]) return;
109
- Object.defineProperty(exports, key, {
110
- enumerable: true,
111
- get: function () {
112
- return _node[key];
113
- }
114
- });
115
- });
116
-
117
- var _commander = require("./utils/commander");
118
-
119
- var _config = require("./config");
120
-
121
- Object.keys(_config).forEach(function (key) {
122
- if (key === "default" || key === "__esModule") return;
123
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
124
- if (key in exports && exports[key] === _config[key]) return;
125
- Object.defineProperty(exports, key, {
126
- enumerable: true,
127
- get: function () {
128
- return _config[key];
129
- }
130
- });
131
- });
132
-
133
- var _loadPlugins = require("./loadPlugins");
134
-
135
- var _context = require("./context");
136
-
137
- var _initWatcher = require("./initWatcher");
138
-
139
- var _loadEnv = require("./loadEnv");
140
-
141
- var _manager = require("./manager");
142
-
143
- var _plugin = require("@modern-js/plugin");
144
-
145
- Object.keys(_plugin).forEach(function (key) {
146
- if (key === "default" || key === "__esModule") return;
147
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
148
- if (key in exports && exports[key] === _plugin[key]) return;
149
- Object.defineProperty(exports, key, {
150
- enumerable: true,
151
- get: function () {
152
- return _plugin[key];
153
- }
154
- });
155
- });
156
-
157
- var _pluginAPI = require("./pluginAPI");
158
-
159
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
160
-
161
- 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; }
162
-
163
- 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; }
164
-
165
- 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; }
166
-
167
- _utils.program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
168
-
169
- const initAppDir = async cwd => {
170
- if (!cwd) {
171
- // eslint-disable-next-line no-param-reassign
172
- cwd = process.cwd();
173
- }
174
-
175
- const pkg = await (0, _utils.pkgUp)({
176
- cwd
177
- });
178
-
179
- if (!pkg) {
180
- throw new Error(`no package.json found in current work dir: ${cwd}`);
181
- }
182
-
183
- return _path.default.dirname(pkg);
184
- };
185
-
186
- exports.initAppDir = initAppDir;
187
-
188
- const mergeOptions = options => {
189
- const defaultOptions = {
190
- serverConfigFile: _utils.DEFAULT_SERVER_CONFIG
191
- };
192
- return _objectSpread(_objectSpread({}, defaultOptions), options);
193
- };
194
-
195
- exports.mergeOptions = mergeOptions;
196
-
197
- const createCli = () => {
198
- let hooksRunner;
199
- let isRestart = false;
200
- let restartWithExistingPort = 0;
201
- let restartOptions;
202
-
203
- const init = async (argv = [], options) => {
204
- var _mergedOptions$option, _mergedOptions$option2;
205
-
206
- (0, _node.enable)();
207
-
208
- _manager.manager.clear();
209
-
210
- const mergedOptions = mergeOptions(options);
211
- restartOptions = mergedOptions;
212
- const appDirectory = await initAppDir();
213
- (0, _commander.initCommandsMap)();
214
- const metaName = (_mergedOptions$option = mergedOptions === null || mergedOptions === void 0 ? void 0 : (_mergedOptions$option2 = mergedOptions.options) === null || _mergedOptions$option2 === void 0 ? void 0 : _mergedOptions$option2.metaName) !== null && _mergedOptions$option !== void 0 ? _mergedOptions$option : 'MODERN';
215
- (0, _loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
216
- const loaded = await (0, _config.loadUserConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
217
- const plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config, {
218
- internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins,
219
- transformPlugin: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.transformPlugin
220
- });
221
- plugins.forEach(plugin => plugin.cli && _manager.manager.usePlugin(plugin.cli));
222
- const appContext = (0, _context.initAppContext)({
223
- appDirectory,
224
- plugins,
225
- configFile: loaded.filePath,
226
- options: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options,
227
- serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile
228
- }); // 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
229
-
230
- (0, _config.addServerConfigToDeps)(loaded.dependencies, appDirectory, mergedOptions.serverConfigFile);
231
-
232
- _manager.manager.run(() => {
233
- _context.ConfigContext.set(loaded.config);
234
-
235
- _context.AppContext.set(appContext);
236
- });
237
-
238
- hooksRunner = await _manager.manager.init();
239
- ['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
240
- process.on(event, async err => {
241
- await hooksRunner.beforeExit();
242
-
243
- if (err instanceof Error) {
244
- _utils.logger.error(err.stack);
245
- }
246
-
247
- process.nextTick(() => {
248
- // eslint-disable-next-line no-process-exit
249
- process.exit(1);
250
- });
251
- });
252
- });
253
- const extraConfigs = await hooksRunner.config();
254
- const extraSchemas = await hooksRunner.validateSchema();
255
- const config = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv, options === null || options === void 0 ? void 0 : options.onSchemaError);
256
- const {
257
- resolved
258
- } = await hooksRunner.resolvedConfig({
259
- resolved: config
260
- }); // update context value
261
-
262
- _manager.manager.run(() => {
263
- _context.ConfigContext.set(loaded.config);
264
-
265
- _context.ResolvedConfigContext.set(resolved);
266
-
267
- _context.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
268
- port: resolved.server.port,
269
- distDirectory: (0, _utils.ensureAbsolutePath)(appDirectory, resolved.output.path)
270
- }));
271
- });
272
-
273
- await hooksRunner.prepare();
274
- return {
275
- loadedConfig: loaded,
276
- appContext,
277
- resolved
278
- };
279
- };
280
-
281
- async function run(argv, options) {
282
- const {
283
- loadedConfig,
284
- appContext,
285
- resolved
286
- } = await init(argv, options);
287
- await hooksRunner.commands({
288
- program: _utils.program
289
- });
290
- (0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
291
-
292
- _manager.manager.run(() => _utils.program.parse(process.argv));
293
- }
294
-
295
- async function restart() {
296
- var _AppContext$use$value, _AppContext$use$value2;
297
-
298
- isRestart = true;
299
- restartWithExistingPort = isRestart ? (_AppContext$use$value = (_AppContext$use$value2 = _context.AppContext.use().value) === null || _AppContext$use$value2 === void 0 ? void 0 : _AppContext$use$value2.port) !== null && _AppContext$use$value !== void 0 ? _AppContext$use$value : 0 : 0;
300
-
301
- _utils.logger.info('Restart...\n');
302
-
303
- let hasGetError = false;
304
-
305
- const runner = _manager.manager.useRunner();
306
-
307
- await runner.beforeRestart();
308
-
309
- try {
310
- await init(process.argv.slice(2), restartOptions);
311
- } catch (err) {
312
- console.error(err);
313
- hasGetError = true;
314
- } finally {
315
- if (!hasGetError) {
316
- _manager.manager.run(() => _utils.program.parse(process.argv));
317
- }
318
- }
319
- }
320
-
321
- return {
322
- init,
323
- run,
324
- restart
325
- };
326
- };
327
-
328
- const cli = createCli();
329
- exports.cli = cli;
@@ -1,82 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.initWatcher = void 0;
7
-
8
- var _crypto = _interopRequireDefault(require("crypto"));
9
-
10
- var _fs = _interopRequireDefault(require("fs"));
11
-
12
- var _path = _interopRequireDefault(require("path"));
13
-
14
- var _utils = require("@modern-js/utils");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const debug = (0, _utils.createDebugger)('watch-files');
19
-
20
- const md5 = data => _crypto.default.createHash('md5').update(data).digest('hex');
21
-
22
- const hashMap = new Map();
23
-
24
- const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) => {
25
- // only add fs watcher on dev mode.
26
- if (((0, _utils.isDev)() || (0, _utils.isTest)()) && argv[0] === 'dev') {
27
- const extraFiles = await hooksRunner.watchFiles();
28
-
29
- const configPath = _path.default.join(appDirectory, configDir);
30
-
31
- const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
32
- debug(`watched: %o`, watched);
33
-
34
- const watcher = _utils.chokidar.watch(watched, {
35
- cwd: appDirectory,
36
- ignoreInitial: true,
37
- ignorePermissionErrors: true,
38
- ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
39
- });
40
-
41
- watcher.on('change', changed => {
42
- const lastHash = hashMap.get(changed);
43
- const currentHash = md5(_fs.default.readFileSync(_path.default.join(appDirectory, changed), 'utf8'));
44
-
45
- if (currentHash !== lastHash) {
46
- debug(`file change: %s`, changed);
47
- hashMap.set(changed, currentHash);
48
- hooksRunner.fileChange({
49
- filename: changed,
50
- eventType: 'change'
51
- });
52
- }
53
- });
54
- watcher.on('add', name => {
55
- debug(`add file: %s`, name);
56
- const currentHash = md5(_fs.default.readFileSync(_path.default.join(appDirectory, name), 'utf8'));
57
- hashMap.set(name, currentHash);
58
- hooksRunner.fileChange({
59
- filename: name,
60
- eventType: 'add'
61
- });
62
- });
63
- watcher.on('unlink', name => {
64
- debug(`remove file: %s`, name);
65
-
66
- if (hashMap.has(name)) {
67
- hashMap.delete(name);
68
- }
69
-
70
- hooksRunner.fileChange({
71
- filename: name,
72
- eventType: 'unlink'
73
- });
74
- });
75
- watcher.on('error', err => {
76
- throw err;
77
- });
78
- return watcher;
79
- }
80
- };
81
-
82
- exports.initWatcher = initWatcher;
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.loadEnv = void 0;
7
-
8
- var _fs = _interopRequireDefault(require("fs"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _dotenv = _interopRequireDefault(require("dotenv"));
13
-
14
- var _dotenvExpand = _interopRequireDefault(require("dotenv-expand"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const loadEnv = (appDirectory, mode = process.env.NODE_ENV) => {
19
- // Don't change the order of the filenames, since they are ordered by the priority.
20
- // Files on the left have more priority than files on the right.
21
- [`.env.${mode}.local`, '.env.local', `.env.${mode}`, '.env'].map(name => _path.default.resolve(appDirectory, name)).filter(filePath => _fs.default.existsSync(filePath) && !_fs.default.statSync(filePath).isDirectory()).forEach(filePath => {
22
- const envConfig = _dotenv.default.config({
23
- path: filePath
24
- });
25
-
26
- (0, _dotenvExpand.default)(envConfig);
27
- });
28
- };
29
-
30
- exports.loadEnv = loadEnv;