@modern-js/core 1.8.0 → 1.9.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 (196) hide show
  1. package/.eslintrc.js +1 -0
  2. package/CHANGELOG.md +22 -0
  3. package/bin/modern-js.js +1 -1
  4. package/compiled/ajv/codegen.js +1 -0
  5. package/compiled/ajv/dist/ajv.d.ts +16 -0
  6. package/compiled/ajv/dist/compile/codegen/code.d.ts +40 -0
  7. package/compiled/ajv/dist/compile/codegen/index.d.ts +79 -0
  8. package/compiled/ajv/dist/compile/codegen/scope.d.ts +79 -0
  9. package/compiled/ajv/dist/compile/errors.d.ts +13 -0
  10. package/compiled/ajv/dist/compile/index.d.ts +80 -0
  11. package/compiled/ajv/dist/compile/ref_error.d.ts +6 -0
  12. package/compiled/ajv/dist/compile/resolve.d.ts +12 -0
  13. package/compiled/ajv/dist/compile/rules.d.ts +28 -0
  14. package/compiled/ajv/dist/compile/util.d.ts +40 -0
  15. package/compiled/ajv/dist/compile/validate/index.d.ts +42 -0
  16. package/compiled/ajv/dist/compile/validate/subschema.d.ts +47 -0
  17. package/compiled/ajv/dist/core.d.ts +173 -0
  18. package/compiled/ajv/dist/runtime/validation_error.d.ts +7 -0
  19. package/compiled/ajv/dist/types/index.d.ts +183 -0
  20. package/compiled/ajv/dist/types/json-schema.d.ts +124 -0
  21. package/compiled/ajv/dist/types/jtd-schema.d.ts +169 -0
  22. package/compiled/ajv/index.js +9 -0
  23. package/compiled/ajv/license +22 -0
  24. package/compiled/ajv/package.json +1 -0
  25. package/compiled/ajv/uri-js/dist/es5/uri.all.d.ts +59 -0
  26. package/compiled/ajv-keywords/ajv/dist/ajv.d.ts +16 -0
  27. package/compiled/ajv-keywords/ajv/dist/compile/codegen/code.d.ts +40 -0
  28. package/compiled/ajv-keywords/ajv/dist/compile/codegen/index.d.ts +79 -0
  29. package/compiled/ajv-keywords/ajv/dist/compile/codegen/scope.d.ts +79 -0
  30. package/compiled/ajv-keywords/ajv/dist/compile/errors.d.ts +13 -0
  31. package/compiled/ajv-keywords/ajv/dist/compile/index.d.ts +80 -0
  32. package/compiled/ajv-keywords/ajv/dist/compile/ref_error.d.ts +6 -0
  33. package/compiled/ajv-keywords/ajv/dist/compile/resolve.d.ts +12 -0
  34. package/compiled/ajv-keywords/ajv/dist/compile/rules.d.ts +28 -0
  35. package/compiled/ajv-keywords/ajv/dist/compile/util.d.ts +40 -0
  36. package/compiled/ajv-keywords/ajv/dist/compile/validate/index.d.ts +42 -0
  37. package/compiled/ajv-keywords/ajv/dist/compile/validate/subschema.d.ts +47 -0
  38. package/compiled/ajv-keywords/ajv/dist/core.d.ts +173 -0
  39. package/compiled/ajv-keywords/ajv/dist/runtime/validation_error.d.ts +7 -0
  40. package/compiled/ajv-keywords/ajv/dist/types/index.d.ts +183 -0
  41. package/compiled/ajv-keywords/ajv/dist/types/json-schema.d.ts +124 -0
  42. package/compiled/ajv-keywords/ajv/dist/types/jtd-schema.d.ts +169 -0
  43. package/compiled/ajv-keywords/dist/index.d.ts +4 -0
  44. package/compiled/ajv-keywords/index.js +1 -0
  45. package/compiled/ajv-keywords/license +21 -0
  46. package/compiled/ajv-keywords/package.json +1 -0
  47. package/compiled/ajv-keywords/uri-js/dist/es5/uri.all.d.ts +59 -0
  48. package/compiled/better-ajv-errors/ajv/dist/ajv.d.ts +16 -0
  49. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/code.d.ts +40 -0
  50. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/index.d.ts +79 -0
  51. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/scope.d.ts +79 -0
  52. package/compiled/better-ajv-errors/ajv/dist/compile/errors.d.ts +13 -0
  53. package/compiled/better-ajv-errors/ajv/dist/compile/index.d.ts +80 -0
  54. package/compiled/better-ajv-errors/ajv/dist/compile/ref_error.d.ts +6 -0
  55. package/compiled/better-ajv-errors/ajv/dist/compile/resolve.d.ts +12 -0
  56. package/compiled/better-ajv-errors/ajv/dist/compile/rules.d.ts +28 -0
  57. package/compiled/better-ajv-errors/ajv/dist/compile/util.d.ts +40 -0
  58. package/compiled/better-ajv-errors/ajv/dist/compile/validate/index.d.ts +42 -0
  59. package/compiled/better-ajv-errors/ajv/dist/compile/validate/subschema.d.ts +47 -0
  60. package/compiled/better-ajv-errors/ajv/dist/core.d.ts +173 -0
  61. package/compiled/better-ajv-errors/ajv/dist/runtime/validation_error.d.ts +7 -0
  62. package/compiled/better-ajv-errors/ajv/dist/types/index.d.ts +183 -0
  63. package/compiled/better-ajv-errors/ajv/dist/types/json-schema.d.ts +124 -0
  64. package/compiled/better-ajv-errors/ajv/dist/types/jtd-schema.d.ts +169 -0
  65. package/compiled/better-ajv-errors/index.js +1 -0
  66. package/compiled/better-ajv-errors/license +13 -0
  67. package/compiled/better-ajv-errors/package.json +1 -0
  68. package/compiled/better-ajv-errors/typings.d.ts +24 -0
  69. package/compiled/better-ajv-errors/uri-js/dist/es5/uri.all.d.ts +59 -0
  70. package/compiled/v8-compile-cache/index.js +1 -0
  71. package/compiled/v8-compile-cache/license +21 -0
  72. package/compiled/v8-compile-cache/package.json +1 -0
  73. package/dist/cli.d.ts +1 -0
  74. package/dist/cli.js +33 -0
  75. package/dist/config/defaults.d.ts +28 -0
  76. package/dist/config/defaults.js +98 -0
  77. package/dist/{types/config → config}/index.d.ts +2 -2
  78. package/dist/config/index.js +120 -0
  79. package/dist/config/mergeConfig.d.ts +30 -0
  80. package/dist/config/mergeConfig.js +26 -0
  81. package/dist/config/schema/deploy.d.ts +16 -0
  82. package/dist/config/schema/deploy.js +16 -0
  83. package/dist/config/schema/index.d.ts +466 -0
  84. package/dist/config/schema/index.js +95 -0
  85. package/dist/config/schema/output.d.ts +146 -0
  86. package/dist/config/schema/output.js +68 -0
  87. package/dist/config/schema/server.d.ts +182 -0
  88. package/dist/config/schema/server.js +107 -0
  89. package/dist/config/schema/source.d.ts +58 -0
  90. package/dist/config/schema/source.js +36 -0
  91. package/dist/config/schema/tools.d.ts +36 -0
  92. package/dist/config/schema/tools.js +19 -0
  93. package/dist/config/types/electron.d.ts +13 -0
  94. package/dist/config/types/electron.js +2 -0
  95. package/dist/config/types/index.d.ts +240 -0
  96. package/dist/config/types/index.js +2 -0
  97. package/dist/config/types/less.d.ts +10 -0
  98. package/dist/config/types/less.js +2 -0
  99. package/dist/config/types/sass.d.ts +8 -0
  100. package/dist/config/types/sass.js +2 -0
  101. package/dist/{types/config → config}/types/ssg.d.ts +8 -8
  102. package/dist/config/types/ssg.js +2 -0
  103. package/dist/config/types/test.d.ts +14 -0
  104. package/dist/config/types/test.js +2 -0
  105. package/dist/config/types/unbundle.d.ts +25 -0
  106. package/dist/config/types/unbundle.js +2 -0
  107. package/dist/{types/context.d.ts → context.d.ts} +12 -22
  108. package/dist/context.js +59 -0
  109. package/dist/index.d.ts +64 -0
  110. package/dist/index.js +177 -0
  111. package/dist/{types/initWatcher.d.ts → initWatcher.d.ts} +1 -1
  112. package/dist/initWatcher.js +75 -0
  113. package/dist/{types/loadEnv.d.ts → loadEnv.d.ts} +1 -1
  114. package/dist/loadEnv.js +21 -0
  115. package/dist/{types/loadPlugins.d.ts → loadPlugins.d.ts} +13 -16
  116. package/dist/loadPlugins.js +109 -0
  117. package/dist/manager.d.ts +72 -0
  118. package/dist/manager.js +24 -0
  119. package/dist/{types/pluginAPI.d.ts → pluginAPI.d.ts} +5 -6
  120. package/dist/pluginAPI.js +16 -0
  121. package/dist/{types/utils → utils}/commander.d.ts +1 -1
  122. package/dist/utils/commander.js +20 -0
  123. package/dist/{types/utils → utils}/repeatKeyWarning.d.ts +1 -1
  124. package/dist/utils/repeatKeyWarning.js +22 -0
  125. package/package.json +12 -26
  126. package/tsconfig.json +3 -4
  127. package/dist/js/modern/cli.js +0 -29
  128. package/dist/js/modern/config/defaults.js +0 -103
  129. package/dist/js/modern/config/index.js +0 -115
  130. package/dist/js/modern/config/mergeConfig.js +0 -22
  131. package/dist/js/modern/config/schema/deploy.js +0 -17
  132. package/dist/js/modern/config/schema/index.js +0 -107
  133. package/dist/js/modern/config/schema/output.js +0 -147
  134. package/dist/js/modern/config/schema/server.js +0 -170
  135. package/dist/js/modern/config/schema/source.js +0 -59
  136. package/dist/js/modern/config/schema/tools.js +0 -36
  137. package/dist/js/modern/config/types/electron.js +0 -1
  138. package/dist/js/modern/config/types/index.js +0 -1
  139. package/dist/js/modern/config/types/less.js +0 -0
  140. package/dist/js/modern/config/types/sass.js +0 -0
  141. package/dist/js/modern/config/types/ssg.js +0 -0
  142. package/dist/js/modern/config/types/test.js +0 -0
  143. package/dist/js/modern/config/types/unbundle.js +0 -0
  144. package/dist/js/modern/context.js +0 -63
  145. package/dist/js/modern/index.js +0 -169
  146. package/dist/js/modern/initWatcher.js +0 -62
  147. package/dist/js/modern/loadEnv.js +0 -14
  148. package/dist/js/modern/loadPlugins.js +0 -122
  149. package/dist/js/modern/manager.js +0 -28
  150. package/dist/js/modern/pluginAPI.js +0 -11
  151. package/dist/js/modern/utils/commander.js +0 -19
  152. package/dist/js/modern/utils/repeatKeyWarning.js +0 -18
  153. package/dist/js/node/cli.js +0 -35
  154. package/dist/js/node/config/defaults.js +0 -110
  155. package/dist/js/node/config/index.js +0 -182
  156. package/dist/js/node/config/mergeConfig.js +0 -32
  157. package/dist/js/node/config/schema/deploy.js +0 -26
  158. package/dist/js/node/config/schema/index.js +0 -127
  159. package/dist/js/node/config/schema/output.js +0 -156
  160. package/dist/js/node/config/schema/server.js +0 -179
  161. package/dist/js/node/config/schema/source.js +0 -68
  162. package/dist/js/node/config/schema/tools.js +0 -43
  163. package/dist/js/node/config/types/electron.js +0 -5
  164. package/dist/js/node/config/types/index.js +0 -5
  165. package/dist/js/node/config/types/less.js +0 -0
  166. package/dist/js/node/config/types/sass.js +0 -0
  167. package/dist/js/node/config/types/ssg.js +0 -0
  168. package/dist/js/node/config/types/test.js +0 -0
  169. package/dist/js/node/config/types/unbundle.js +0 -0
  170. package/dist/js/node/context.js +0 -93
  171. package/dist/js/node/index.js +0 -329
  172. package/dist/js/node/initWatcher.js +0 -82
  173. package/dist/js/node/loadEnv.js +0 -30
  174. package/dist/js/node/loadPlugins.js +0 -134
  175. package/dist/js/node/manager.js +0 -45
  176. package/dist/js/node/pluginAPI.js +0 -54
  177. package/dist/js/node/utils/commander.js +0 -32
  178. package/dist/js/node/utils/repeatKeyWarning.js +0 -31
  179. package/dist/types/cli.d.ts +0 -1
  180. package/dist/types/config/defaults.d.ts +0 -28
  181. package/dist/types/config/mergeConfig.d.ts +0 -31
  182. package/dist/types/config/schema/deploy.d.ts +0 -16
  183. package/dist/types/config/schema/index.d.ts +0 -466
  184. package/dist/types/config/schema/output.d.ts +0 -146
  185. package/dist/types/config/schema/server.d.ts +0 -182
  186. package/dist/types/config/schema/source.d.ts +0 -58
  187. package/dist/types/config/schema/tools.d.ts +0 -36
  188. package/dist/types/config/types/electron.d.ts +0 -13
  189. package/dist/types/config/types/index.d.ts +0 -252
  190. package/dist/types/config/types/less.d.ts +0 -10
  191. package/dist/types/config/types/sass.d.ts +0 -8
  192. package/dist/types/config/types/test.d.ts +0 -15
  193. package/dist/types/config/types/unbundle.d.ts +0 -28
  194. package/dist/types/index.d.ts +0 -64
  195. package/dist/types/manager.d.ts +0 -75
  196. package/modern.config.js +0 -6
@@ -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;
@@ -1,134 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getAppPlugins = getAppPlugins;
7
- exports.loadPlugins = void 0;
8
-
9
- var _utils = require("@modern-js/utils");
10
-
11
- var _manager = require("./manager");
12
-
13
- const debug = (0, _utils.createDebugger)('load-plugins');
14
-
15
- /**
16
- * Try to resolve plugin entry file path.
17
- * @param name - Plugin name.
18
- * @param appDirectory - Application root directory.
19
- * @returns Resolved file path.
20
- */
21
- const tryResolve = (name, appDirectory) => {
22
- let filePath = '';
23
-
24
- try {
25
- filePath = require.resolve(name, {
26
- paths: [appDirectory]
27
- });
28
- delete require.cache[filePath];
29
- } catch (err) {
30
- if (err.code === 'MODULE_NOT_FOUND') {
31
- throw new Error(`Can not find plugin ${name}.`);
32
- }
33
-
34
- throw err;
35
- }
36
-
37
- return filePath;
38
- };
39
-
40
- function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
41
- const allPlugins = internalPlugins || _utils.INTERNAL_PLUGINS;
42
- const appPlugins = [...Object.keys(allPlugins).filter(name => {
43
- const config = allPlugins[name];
44
-
45
- if (config.forced === true) {
46
- // 参考 packages/cli/core/src/cli.ts 文件
47
- return true;
48
- }
49
-
50
- return (0, _utils.isDepExists)(appDirectory, name);
51
- }).map(name => allPlugins[name]), ...oldPluginConfig];
52
- return appPlugins;
53
- }
54
-
55
- const resolveCliPlugin = (p, userConfig, appDirectory, transformPlugin) => {
56
- const pkg = typeof p === 'string' ? p : p[0];
57
- const pluginOptions = typeof p === 'string' ? undefined : p[1];
58
- const path = tryResolve(pkg, appDirectory);
59
- let module = (0, _utils.compatRequire)(path);
60
-
61
- if (transformPlugin) {
62
- module = transformPlugin(module, userConfig, pluginOptions);
63
- }
64
-
65
- if (typeof module === 'function') {
66
- const result = module(pluginOptions);
67
- return (0, _manager.createPlugin)(result.setup, result);
68
- }
69
-
70
- return module;
71
- };
72
-
73
- const isOldPluginConfig = config => Array.isArray(config) && config.some(item => {
74
- if (typeof item === 'string' || Array.isArray(item)) {
75
- return true;
76
- }
77
-
78
- return 'cli' in item || 'server' in item;
79
- });
80
- /**
81
- * Load internal plugins which in @modern-js scope and user's custom plugins.
82
- * @param appDirectory - Application root directory.
83
- * @param userConfig - Resolved user config.
84
- * @param options.internalPlugins - Internal plugins.
85
- * @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
86
- * @returns Plugin Objects has been required.
87
- */
88
-
89
-
90
- const loadPlugins = (appDirectory, userConfig, options = {}) => {
91
- const pluginConfig = userConfig.plugins;
92
- const plugins = getAppPlugins(appDirectory, isOldPluginConfig(pluginConfig) ? pluginConfig : [], options.internalPlugins);
93
- const loadedPlugins = plugins.map(plugin => {
94
- const _plugin = typeof plugin === 'string' || Array.isArray(plugin) ? {
95
- cli: plugin
96
- } : plugin;
97
-
98
- const {
99
- cli,
100
- server
101
- } = _plugin;
102
- const loadedPlugin = {};
103
-
104
- if (cli) {
105
- loadedPlugin.cli = resolveCliPlugin(cli, userConfig, appDirectory, options.transformPlugin);
106
- } // server plugins don't support to accept params
107
-
108
-
109
- if (server && typeof server === 'string') {
110
- loadedPlugin.server = server;
111
- loadedPlugin.serverPkg = server;
112
- }
113
-
114
- debug(`resolve plugin %s: %s`, plugin, {
115
- cli: loadedPlugin.cli,
116
- server: loadedPlugin.server
117
- });
118
- return loadedPlugin;
119
- });
120
-
121
- if (!isOldPluginConfig(pluginConfig)) {
122
- const cliPlugins = Array.isArray(pluginConfig) ? pluginConfig : pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.cli;
123
-
124
- if (cliPlugins !== null && cliPlugins !== void 0 && cliPlugins.length) {
125
- loadedPlugins.push(...cliPlugins.map(item => ({
126
- cli: (0, _manager.createPlugin)(item.setup, item)
127
- })));
128
- }
129
- }
130
-
131
- return loadedPlugins;
132
- };
133
-
134
- exports.loadPlugins = loadPlugins;
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.usePlugins = exports.registerHook = exports.mountHook = exports.manager = exports.createPlugin = void 0;
7
-
8
- var _plugin = require("@modern-js/plugin");
9
-
10
- var _utils = require("@modern-js/utils");
11
-
12
- var _pluginAPI = require("./pluginAPI");
13
-
14
- const baseHooks = {
15
- config: (0, _plugin.createParallelWorkflow)(),
16
- resolvedConfig: (0, _plugin.createAsyncWaterfall)(),
17
- validateSchema: (0, _plugin.createParallelWorkflow)(),
18
- prepare: (0, _plugin.createAsyncWorkflow)(),
19
- commands: (0, _plugin.createAsyncWorkflow)(),
20
- watchFiles: (0, _plugin.createParallelWorkflow)(),
21
- fileChange: (0, _plugin.createAsyncWorkflow)(),
22
- beforeExit: (0, _plugin.createAsyncWorkflow)(),
23
- beforeRestart: (0, _plugin.createAsyncWorkflow)()
24
- };
25
- /** All hooks of cli plugin. */
26
-
27
- const manager = (0, _plugin.createAsyncManager)(baseHooks, _pluginAPI.pluginAPI);
28
- /** Plugin options of a cli plugin. */
29
-
30
- exports.manager = manager;
31
- const {
32
- createPlugin,
33
- registerHook,
34
- useRunner: mountHook
35
- } = manager;
36
- exports.mountHook = mountHook;
37
- exports.registerHook = registerHook;
38
- exports.createPlugin = createPlugin;
39
-
40
- const usePlugins = plugins => plugins.forEach(pluginPath => {
41
- const module = (0, _utils.compatRequire)(require.resolve(pluginPath));
42
- manager.usePlugin(module);
43
- });
44
-
45
- exports.usePlugins = usePlugins;
@@ -1,54 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "AppContext", {
7
- enumerable: true,
8
- get: function () {
9
- return _context.AppContext;
10
- }
11
- });
12
- Object.defineProperty(exports, "ConfigContext", {
13
- enumerable: true,
14
- get: function () {
15
- return _context.ConfigContext;
16
- }
17
- });
18
- Object.defineProperty(exports, "ResolvedConfigContext", {
19
- enumerable: true,
20
- get: function () {
21
- return _context.ResolvedConfigContext;
22
- }
23
- });
24
- exports.pluginAPI = void 0;
25
- Object.defineProperty(exports, "useAppContext", {
26
- enumerable: true,
27
- get: function () {
28
- return _context.useAppContext;
29
- }
30
- });
31
- Object.defineProperty(exports, "useConfigContext", {
32
- enumerable: true,
33
- get: function () {
34
- return _context.useConfigContext;
35
- }
36
- });
37
- Object.defineProperty(exports, "useResolvedConfigContext", {
38
- enumerable: true,
39
- get: function () {
40
- return _context.useResolvedConfigContext;
41
- }
42
- });
43
-
44
- var _context = require("./context");
45
-
46
- const pluginAPI = {
47
- setAppContext: _context.setAppContext,
48
- useAppContext: _context.useAppContext,
49
- useConfigContext: _context.useConfigContext,
50
- useResolvedConfigContext: _context.useResolvedConfigContext
51
- };
52
- /** all apis for cli plugin */
53
-
54
- exports.pluginAPI = pluginAPI;
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.initCommandsMap = initCommandsMap;
7
- Object.defineProperty(exports, "program", {
8
- enumerable: true,
9
- get: function () {
10
- return _utils.program;
11
- }
12
- });
13
-
14
- var _utils = require("@modern-js/utils");
15
-
16
- function initCommandsMap() {
17
- if (!_utils.program.hasOwnProperty('commandsMap')) {
18
- Object.defineProperty(_utils.program, 'commandsMap', {
19
- get() {
20
- const map = new Map();
21
-
22
- for (const command of _utils.program.commands) {
23
- map.set(command._name, command);
24
- }
25
-
26
- return map;
27
- },
28
-
29
- configurable: false
30
- });
31
- }
32
- }