@modern-js/core 1.6.0 → 1.7.1-beta.peer.1

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 (68) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/js/modern/config/index.js +11 -7
  3. package/dist/js/modern/config/mergeConfig.js +1 -1
  4. package/dist/js/modern/config/schema/index.js +1 -1
  5. package/dist/js/modern/config/types/electron.js +1 -0
  6. package/dist/js/modern/config/types/index.js +1 -0
  7. package/dist/js/modern/config/types/less.js +0 -0
  8. package/dist/js/modern/config/types/sass.js +0 -0
  9. package/dist/js/modern/config/types/ssg.js +0 -0
  10. package/dist/js/modern/config/types/test.js +0 -0
  11. package/dist/js/modern/config/types/unbundle.js +0 -0
  12. package/dist/js/modern/context.js +9 -2
  13. package/dist/js/modern/index.js +27 -9
  14. package/dist/js/modern/initWatcher.js +2 -2
  15. package/dist/js/modern/loadPlugins.js +9 -4
  16. package/dist/js/modern/utils/commander.js +15 -15
  17. package/dist/js/node/config/index.js +38 -11
  18. package/dist/js/node/config/mergeConfig.js +2 -4
  19. package/dist/js/node/config/schema/index.js +3 -5
  20. package/dist/js/node/config/types/electron.js +5 -0
  21. package/dist/js/node/config/types/index.js +5 -0
  22. package/dist/js/node/config/types/less.js +0 -0
  23. package/dist/js/node/config/types/sass.js +0 -0
  24. package/dist/js/node/config/types/ssg.js +0 -0
  25. package/dist/js/node/config/types/test.js +0 -0
  26. package/dist/js/node/config/types/unbundle.js +0 -0
  27. package/dist/js/node/context.js +9 -2
  28. package/dist/js/node/index.js +32 -10
  29. package/dist/js/node/initWatcher.js +2 -3
  30. package/dist/js/node/loadPlugins.js +9 -4
  31. package/dist/js/node/utils/commander.js +16 -19
  32. package/dist/types/config/index.d.ts +4 -140
  33. package/dist/types/config/types/electron.d.ts +13 -0
  34. package/dist/types/config/types/index.d.ts +252 -0
  35. package/dist/types/config/types/less.d.ts +10 -0
  36. package/dist/types/config/types/sass.d.ts +8 -0
  37. package/dist/types/config/types/ssg.d.ts +13 -0
  38. package/dist/types/config/types/test.d.ts +15 -0
  39. package/dist/types/config/types/unbundle.d.ts +28 -0
  40. package/dist/types/context.d.ts +18 -6
  41. package/dist/types/index.d.ts +28 -1
  42. package/dist/types/initWatcher.d.ts +1 -2
  43. package/dist/types/loadPlugins.d.ts +3 -0
  44. package/dist/types/manager.d.ts +7 -6
  45. package/dist/types/utils/commander.d.ts +4 -7
  46. package/jest.config.js +0 -1
  47. package/package.json +18 -17
  48. package/tests/.eslintrc.js +0 -6
  49. package/tests/btsm.test.ts +0 -20
  50. package/tests/config.test.ts +0 -137
  51. package/tests/context.test.ts +0 -70
  52. package/tests/fixtures/index-test/package.json +0 -3
  53. package/tests/fixtures/load-plugin/not-found/package.json +0 -3
  54. package/tests/fixtures/load-plugin/not-found/test-plugin-a.js +0 -1
  55. package/tests/fixtures/load-plugin/user-plugins/package.json +0 -3
  56. package/tests/fixtures/load-plugin/user-plugins/test-plugin-a.js +0 -1
  57. package/tests/fixtures/load-plugin/user-plugins/test-plugin-b.js +0 -3
  58. package/tests/fixtures/load-plugin/user-plugins/test-plugin-c.js +0 -3
  59. package/tests/index.test.ts +0 -69
  60. package/tests/initWatcher.test.ts +0 -63
  61. package/tests/loadEnv.test.ts +0 -173
  62. package/tests/loadPlugin.test.ts +0 -116
  63. package/tests/mergeConfig.test.ts +0 -97
  64. package/tests/pluginAPI.test.ts +0 -19
  65. package/tests/repeatKeyWarning.test.ts +0 -68
  66. package/tests/schema.test.ts +0 -107
  67. package/tests/tsconfig.json +0 -11
  68. package/tests/utils.test.ts +0 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 1.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d2d1d6b2: feat: support server config
8
+
9
+ ### Patch Changes
10
+
11
+ - 60855eb2: fix: ignore initial watching add event
12
+ - ec1b7367: fix: tools config types
13
+ - 07a4887e: feat: prebundle commander and signale to @modern-js/utils
14
+ - 17d0cc46: feat: prebundle lodash to @modern-js/utils/lodash
15
+ - Updated dependencies [77ff9754]
16
+ - Updated dependencies [d2d1d6b2]
17
+ - Updated dependencies [07a4887e]
18
+ - Updated dependencies [ea2ae711]
19
+ - Updated dependencies [17d0cc46]
20
+ - Updated dependencies [d2d1d6b2]
21
+ - @modern-js/utils@1.4.0
22
+ - @modern-js/load-config@1.3.0
23
+
24
+ ## 1.6.1
25
+
26
+ ### Patch Changes
27
+
28
+ - ef28a4e6: fix: module-tools build error
29
+ - 132f7b53: feat: move config declarations to @modern-js/core
30
+ - 9d4a005b: fix: config babel via tools.babel
31
+ - Updated dependencies [132f7b53]
32
+ - @modern-js/utils@1.3.7
33
+
3
34
  ## 1.6.0
4
35
 
5
36
  ### Minor Changes
@@ -7,9 +7,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
7
7
  import { loadConfig } from '@modern-js/load-config';
8
8
  import Ajv from 'ajv';
9
9
  import ajvKeywords from 'ajv-keywords';
10
- import logger from 'signale';
11
- import { createDebugger, getPort, isDev, PLUGIN_SCHEMAS, chalk } from '@modern-js/utils';
12
- import mergeWith from 'lodash.mergewith';
10
+ import { signale as logger, createDebugger, getPort, isDev, PLUGIN_SCHEMAS, chalk, getServerConfig } from '@modern-js/utils';
11
+ import { mergeWith } from '@modern-js/utils/lodash';
13
12
  import betterAjvErrors from 'better-ajv-errors';
14
13
  import { codeFrameColumns } from '@babel/code-frame';
15
14
  import { repeatKeyWarning } from "../utils/repeatKeyWarning";
@@ -19,6 +18,14 @@ import { patchSchema } from "./schema";
19
18
  const debug = createDebugger('resolve-config');
20
19
  export { defaults as defaultsConfig };
21
20
  export { mergeConfig };
21
+ export * from "./types";
22
+ export const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
23
+ const serverConfig = await getServerConfig(appDirectory, serverConfigFile);
24
+
25
+ if (serverConfig) {
26
+ dependencies.push(serverConfig);
27
+ }
28
+ };
22
29
  export const defineConfig = config => config;
23
30
  export const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
24
31
  const loaded = await loadConfig(appDirectory, filePath, packageJsonConfig);
@@ -42,8 +49,6 @@ const showAdditionalPropertiesError = error => {
42
49
  }
43
50
  }
44
51
  };
45
- /* eslint-disable max-statements, max-params */
46
-
47
52
 
48
53
  export const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv, onSchemaError = showAdditionalPropertiesError) => {
49
54
  var _validate$errors;
@@ -107,5 +112,4 @@ export const resolveConfig = async (loaded, configs, schemas, restartWithExistin
107
112
 
108
113
  debug('resolved %o', resolved);
109
114
  return resolved;
110
- };
111
- /* eslint-enable max-statements, max-params */
115
+ };
@@ -1,4 +1,4 @@
1
- import mergeWith from 'lodash.mergewith';
1
+ import { mergeWith } from '@modern-js/utils/lodash';
2
2
  import { isFunction } from '@modern-js/utils';
3
3
 
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { isObject, createDebugger } from '@modern-js/utils';
2
- import cloneDeep from 'lodash.clonedeep';
2
+ import { cloneDeep } from '@modern-js/utils/lodash';
3
3
  import { source } from "./source";
4
4
  import { output } from "./output";
5
5
  import { server } from "./server";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -25,7 +25,13 @@ export const useConfigContext = () => ConfigContext.use().value;
25
25
  */
26
26
 
27
27
  export const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
28
- export const initAppContext = (appDirectory, plugins, configFile, options) => {
28
+ export const initAppContext = ({
29
+ appDirectory,
30
+ plugins,
31
+ configFile,
32
+ options,
33
+ serverConfigFile
34
+ }) => {
29
35
  const {
30
36
  metaName = 'modern-js',
31
37
  srcDir = 'src',
@@ -36,6 +42,7 @@ export const initAppContext = (appDirectory, plugins, configFile, options) => {
36
42
  metaName,
37
43
  appDirectory,
38
44
  configFile,
45
+ serverConfigFile,
39
46
  ip: address.ip(),
40
47
  port: 0,
41
48
  packageName: require(path.resolve(appDirectory, './package.json')).name,
@@ -49,7 +56,7 @@ export const initAppContext = (appDirectory, plugins, configFile, options) => {
49
56
  serverRoutes: [],
50
57
  entrypoints: [],
51
58
  checkedEntries: [],
52
- existSrc: true,
59
+ apiOnly: false,
53
60
  internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
54
61
  internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
55
62
  };
@@ -5,10 +5,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
5
5
  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; }
6
6
 
7
7
  import path from 'path';
8
- import { pkgUp, ensureAbsolutePath, logger } from '@modern-js/utils';
8
+ import { pkgUp, program, ensureAbsolutePath, logger, DEFAULT_SERVER_CONFIG } from '@modern-js/utils';
9
9
  import { enable } from '@modern-js/plugin/node';
10
- import { program } from "./utils/commander";
11
- import { resolveConfig, loadUserConfig } from "./config";
10
+ import { initCommandsMap } from "./utils/commander";
11
+ import { resolveConfig, loadUserConfig, addServerConfigToDeps } from "./config";
12
12
  import { loadPlugins } from "./loadPlugins";
13
13
  import { AppContext, ConfigContext, initAppContext, ResolvedConfigContext } from "./context";
14
14
  import { initWatcher } from "./initWatcher";
@@ -40,6 +40,13 @@ const initAppDir = async cwd => {
40
40
  return path.dirname(pkg);
41
41
  };
42
42
 
43
+ export const mergeOptions = options => {
44
+ const defaultOptions = {
45
+ serverConfigFile: DEFAULT_SERVER_CONFIG
46
+ };
47
+ return _objectSpread(_objectSpread({}, defaultOptions), options);
48
+ };
49
+
43
50
  const createCli = () => {
44
51
  let hooksRunner;
45
52
  let isRestart = false;
@@ -47,20 +54,31 @@ const createCli = () => {
47
54
  let restartOptions;
48
55
 
49
56
  const init = async (argv = [], options) => {
50
- var _options$options$meta, _options$options;
57
+ var _mergedOptions$option, _mergedOptions$option2;
51
58
 
52
59
  enable();
53
60
  manager.clear();
54
- restartOptions = options;
61
+ const mergedOptions = mergeOptions(options);
62
+ restartOptions = mergedOptions;
55
63
  const appDirectory = await initAppDir();
56
- const metaName = (_options$options$meta = options === null || options === void 0 ? void 0 : (_options$options = options.options) === null || _options$options === void 0 ? void 0 : _options$options.metaName) !== null && _options$options$meta !== void 0 ? _options$options$meta : 'MODERN';
64
+ initCommandsMap();
65
+ 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';
57
66
  loadEnv(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
58
- const loaded = await loadUserConfig(appDirectory, options === null || options === void 0 ? void 0 : options.configFile, options === null || options === void 0 ? void 0 : options.packageJsonConfig);
67
+ const loaded = await loadUserConfig(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
59
68
  const plugins = loadPlugins(appDirectory, loaded.config, {
60
- internalPlugins: options === null || options === void 0 ? void 0 : options.plugins
69
+ internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins,
70
+ transformPlugin: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.transformPlugin
61
71
  });
62
72
  plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
63
- const appContext = initAppContext(appDirectory, plugins, loaded.filePath, options === null || options === void 0 ? void 0 : options.options);
73
+ const appContext = initAppContext({
74
+ appDirectory,
75
+ plugins,
76
+ configFile: loaded.filePath,
77
+ options: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options,
78
+ serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile
79
+ }); // 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
80
+
81
+ addServerConfigToDeps(loaded.dependencies, appDirectory, mergedOptions.serverConfigFile);
64
82
  manager.run(() => {
65
83
  ConfigContext.set(loaded.config);
66
84
  AppContext.set(appContext);
@@ -1,8 +1,7 @@
1
1
  import crypto from 'crypto';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
- import { isDev, createDebugger, isTest } from '@modern-js/utils';
5
- import chokidar from 'chokidar';
4
+ import { isDev, chokidar, createDebugger, isTest } from '@modern-js/utils';
6
5
  const debug = createDebugger('watch-files');
7
6
 
8
7
  const md5 = data => crypto.createHash('md5').update(data).digest('hex');
@@ -17,6 +16,7 @@ export const initWatcher = async (loaded, appDirectory, configDir, hooksRunner,
17
16
  debug(`watched: %o`, watched);
18
17
  const watcher = chokidar.watch(watched, {
19
18
  cwd: appDirectory,
19
+ ignoreInitial: true,
20
20
  ignorePermissionErrors: true,
21
21
  ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
22
22
  });
@@ -42,13 +42,17 @@ export function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
42
42
  return appPlugins;
43
43
  }
44
44
 
45
- const resolveCliPlugin = (p, appDirectory) => {
45
+ const resolveCliPlugin = (p, userConfig, appDirectory, transformPlugin) => {
46
46
  const pkg = typeof p === 'string' ? p : p[0];
47
+ const pluginOptions = typeof p === 'string' ? undefined : p[1];
47
48
  const path = tryResolve(pkg, appDirectory);
48
- const module = compatRequire(path);
49
+ let module = compatRequire(path);
50
+
51
+ if (transformPlugin) {
52
+ module = transformPlugin(module, userConfig, pluginOptions);
53
+ }
49
54
 
50
55
  if (typeof module === 'function') {
51
- const pluginOptions = Array.isArray(p) ? p[1] : undefined;
52
56
  const result = module(pluginOptions);
53
57
  return createPlugin(result.setup, result);
54
58
  }
@@ -68,6 +72,7 @@ const isOldPluginConfig = config => Array.isArray(config) && config.some(item =>
68
72
  * @param appDirectory - Application root directory.
69
73
  * @param userConfig - Resolved user config.
70
74
  * @param options.internalPlugins - Internal plugins.
75
+ * @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
71
76
  * @returns Plugin Objects has been required.
72
77
  */
73
78
 
@@ -87,7 +92,7 @@ export const loadPlugins = (appDirectory, userConfig, options = {}) => {
87
92
  const loadedPlugin = {};
88
93
 
89
94
  if (cli) {
90
- loadedPlugin.cli = resolveCliPlugin(cli, appDirectory);
95
+ loadedPlugin.cli = resolveCliPlugin(cli, userConfig, appDirectory, options.transformPlugin);
91
96
  } // server plugins don't support to accept params
92
97
 
93
98
 
@@ -1,19 +1,19 @@
1
- import { program, Command } from 'commander';
1
+ import { program } from '@modern-js/utils';
2
+ export function initCommandsMap() {
3
+ if (!program.hasOwnProperty('commandsMap')) {
4
+ Object.defineProperty(program, 'commandsMap', {
5
+ get() {
6
+ const map = new Map();
2
7
 
3
- if (!program.hasOwnProperty('commandsMap')) {
4
- Object.defineProperty(program, 'commandsMap', {
5
- get() {
6
- const map = new Map();
8
+ for (const command of program.commands) {
9
+ map.set(command._name, command);
10
+ }
7
11
 
8
- for (const command of program.commands) {
9
- map.set(command._name, command);
10
- }
12
+ return map;
13
+ },
11
14
 
12
- return map;
13
- },
14
-
15
- configurable: false
16
- });
15
+ configurable: false
16
+ });
17
+ }
17
18
  }
18
-
19
- export { program, Command };
19
+ export { program };
@@ -3,6 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ addServerConfigToDeps: true,
8
+ defineConfig: true,
9
+ loadUserConfig: true,
10
+ resolveConfig: true,
11
+ defaultsConfig: true,
12
+ mergeConfig: true
13
+ };
14
+ exports.addServerConfigToDeps = void 0;
6
15
  Object.defineProperty(exports, "defaultsConfig", {
7
16
  enumerable: true,
8
17
  get: function () {
@@ -24,11 +33,9 @@ var _ajv = _interopRequireDefault(require("ajv"));
24
33
 
25
34
  var _ajvKeywords = _interopRequireDefault(require("ajv-keywords"));
26
35
 
27
- var _signale = _interopRequireDefault(require("signale"));
28
-
29
36
  var _utils = require("@modern-js/utils");
30
37
 
31
- var _lodash = _interopRequireDefault(require("lodash.mergewith"));
38
+ var _lodash = require("@modern-js/utils/lodash");
32
39
 
33
40
  var _betterAjvErrors = _interopRequireDefault(require("better-ajv-errors"));
34
41
 
@@ -42,6 +49,20 @@ var _mergeConfig = require("./mergeConfig");
42
49
 
43
50
  var _schema = require("./schema");
44
51
 
52
+ var _types = require("./types");
53
+
54
+ Object.keys(_types).forEach(function (key) {
55
+ if (key === "default" || key === "__esModule") return;
56
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
57
+ if (key in exports && exports[key] === _types[key]) return;
58
+ Object.defineProperty(exports, key, {
59
+ enumerable: true,
60
+ get: function () {
61
+ return _types[key];
62
+ }
63
+ });
64
+ });
65
+
45
66
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
46
67
 
47
68
  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; }
@@ -52,6 +73,16 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
52
73
 
53
74
  const debug = (0, _utils.createDebugger)('resolve-config');
54
75
 
76
+ const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
77
+ const serverConfig = await (0, _utils.getServerConfig)(appDirectory, serverConfigFile);
78
+
79
+ if (serverConfig) {
80
+ dependencies.push(serverConfig);
81
+ }
82
+ };
83
+
84
+ exports.addServerConfigToDeps = addServerConfigToDeps;
85
+
55
86
  const defineConfig = config => config;
56
87
 
57
88
  exports.defineConfig = defineConfig;
@@ -60,7 +91,7 @@ const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
60
91
  const loaded = await (0, _loadConfig.loadConfig)(appDirectory, filePath, packageJsonConfig);
61
92
  const config = !loaded ? {} : await (typeof loaded.config === 'function' ? loaded.config(0) : loaded.config);
62
93
  return {
63
- config: (0, _lodash.default)({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
94
+ config: (0, _lodash.mergeWith)({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
64
95
  jsConfig: config || {},
65
96
  pkgConfig: (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {},
66
97
  filePath: loaded === null || loaded === void 0 ? void 0 : loaded.path,
@@ -76,12 +107,10 @@ const showAdditionalPropertiesError = error => {
76
107
  const name = Object.keys(_utils.PLUGIN_SCHEMAS).find(key => _utils.PLUGIN_SCHEMAS[key].some(schemaItem => schemaItem.target === target));
77
108
 
78
109
  if (name) {
79
- _signale.default.warn(`The configuration of ${_utils.chalk.bold(target)} is provided by plugin ${_utils.chalk.bold(name)}. Please use ${_utils.chalk.bold('yarn new')} to enable the corresponding capability.\n`);
110
+ _utils.signale.warn(`The configuration of ${_utils.chalk.bold(target)} is provided by plugin ${_utils.chalk.bold(name)}. Please use ${_utils.chalk.bold('yarn new')} to enable the corresponding capability.\n`);
80
111
  }
81
112
  }
82
113
  };
83
- /* eslint-disable max-statements, max-params */
84
-
85
114
 
86
115
  const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv, onSchemaError = showAdditionalPropertiesError) => {
87
116
  var _validate$errors;
@@ -113,7 +142,7 @@ const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort,
113
142
  indent: 2
114
143
  });
115
144
 
116
- _signale.default.log((0, _codeFrame.codeFrameColumns)(JSON.stringify(userConfig, null, 2), {
145
+ _utils.signale.log((0, _codeFrame.codeFrameColumns)(JSON.stringify(userConfig, null, 2), {
117
146
  start: errors === null || errors === void 0 ? void 0 : errors[0].start,
118
147
  end: errors === null || errors === void 0 ? void 0 : errors[0].end
119
148
  }, {
@@ -127,7 +156,7 @@ const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort,
127
156
 
128
157
  for (const config of configs) {
129
158
  if (!validate(config)) {
130
- _signale.default.error(validate.errors);
159
+ _utils.signale.error(validate.errors);
131
160
 
132
161
  throw new Error(`Validate configuration error.`);
133
162
  }
@@ -149,7 +178,5 @@ const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort,
149
178
  debug('resolved %o', resolved);
150
179
  return resolved;
151
180
  };
152
- /* eslint-enable max-statements, max-params */
153
-
154
181
 
155
182
  exports.resolveConfig = resolveConfig;
@@ -5,19 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.mergeConfig = void 0;
7
7
 
8
- var _lodash = _interopRequireDefault(require("lodash.mergewith"));
8
+ var _lodash = require("@modern-js/utils/lodash");
9
9
 
10
10
  var _utils = require("@modern-js/utils");
11
11
 
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
12
  /**
15
13
  * merge configuration from modern.config.js and plugins.
16
14
  *
17
15
  * @param configs - Configuration from modern.config.ts or plugin's config hook.
18
16
  * @returns - normalized user config.
19
17
  */
20
- const mergeConfig = configs => (0, _lodash.default)({}, ...configs, (target, source) => {
18
+ const mergeConfig = configs => (0, _lodash.mergeWith)({}, ...configs, (target, source) => {
21
19
  if (Array.isArray(target)) {
22
20
  if (Array.isArray(source)) {
23
21
  return [...target, ...source];
@@ -7,7 +7,7 @@ exports.traverseSchema = exports.patchSchema = void 0;
7
7
 
8
8
  var _utils = require("@modern-js/utils");
9
9
 
10
- var _lodash = _interopRequireDefault(require("lodash.clonedeep"));
10
+ var _lodash = require("@modern-js/utils/lodash");
11
11
 
12
12
  var _source = require("./source");
13
13
 
@@ -19,8 +19,6 @@ var _deploy = require("./deploy");
19
19
 
20
20
  var _tools = require("./tools");
21
21
 
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
22
  const debug = (0, _utils.createDebugger)('validate-schema');
25
23
  const plugins = {
26
24
  type: 'array',
@@ -40,7 +38,7 @@ const dev = {
40
38
  };
41
39
 
42
40
  const patchSchema = pluginSchemas => {
43
- const finalSchema = (0, _lodash.default)({
41
+ const finalSchema = (0, _lodash.cloneDeep)({
44
42
  type: 'object',
45
43
  additionalProperties: false,
46
44
  properties: {
@@ -96,7 +94,7 @@ const patchSchema = pluginSchemas => {
96
94
  throw new Error(`${target} already exists in current validate schema`);
97
95
  }
98
96
 
99
- targetNode[mountProperty] = (0, _lodash.default)(schema);
97
+ targetNode[mountProperty] = (0, _lodash.cloneDeep)(schema);
100
98
  }
101
99
 
102
100
  debug(`final validate schema: %o`, finalSchema);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,5 @@
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
@@ -53,7 +53,13 @@ const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
53
53
 
54
54
  exports.useResolvedConfigContext = useResolvedConfigContext;
55
55
 
56
- const initAppContext = (appDirectory, plugins, configFile, options) => {
56
+ const initAppContext = ({
57
+ appDirectory,
58
+ plugins,
59
+ configFile,
60
+ options,
61
+ serverConfigFile
62
+ }) => {
57
63
  const {
58
64
  metaName = 'modern-js',
59
65
  srcDir = 'src',
@@ -64,6 +70,7 @@ const initAppContext = (appDirectory, plugins, configFile, options) => {
64
70
  metaName,
65
71
  appDirectory,
66
72
  configFile,
73
+ serverConfigFile,
67
74
  ip: _address.default.ip(),
68
75
  port: 0,
69
76
  packageName: require(_path.default.resolve(appDirectory, './package.json')).name,
@@ -77,7 +84,7 @@ const initAppContext = (appDirectory, plugins, configFile, options) => {
77
84
  serverRoutes: [],
78
85
  entrypoints: [],
79
86
  checkedEntries: [],
80
- existSrc: true,
87
+ apiOnly: false,
81
88
  internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
82
89
  internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
83
90
  };
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
+ mergeOptions: true,
7
8
  cli: true,
8
9
  initAppDir: true,
9
10
  initAppContext: true,
@@ -57,6 +58,7 @@ Object.defineProperty(exports, "manager", {
57
58
  return _manager.manager;
58
59
  }
59
60
  });
61
+ exports.mergeOptions = void 0;
60
62
  Object.defineProperty(exports, "mountHook", {
61
63
  enumerable: true,
62
64
  get: function () {
@@ -162,7 +164,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
162
164
 
163
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; }
164
166
 
165
- _commander.program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
167
+ _utils.program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
166
168
 
167
169
  const initAppDir = async cwd => {
168
170
  if (!cwd) {
@@ -183,6 +185,15 @@ const initAppDir = async cwd => {
183
185
 
184
186
  exports.initAppDir = initAppDir;
185
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
+
186
197
  const createCli = () => {
187
198
  let hooksRunner;
188
199
  let isRestart = false;
@@ -190,22 +201,33 @@ const createCli = () => {
190
201
  let restartOptions;
191
202
 
192
203
  const init = async (argv = [], options) => {
193
- var _options$options$meta, _options$options;
204
+ var _mergedOptions$option, _mergedOptions$option2;
194
205
 
195
206
  (0, _node.enable)();
196
207
 
197
208
  _manager.manager.clear();
198
209
 
199
- restartOptions = options;
210
+ const mergedOptions = mergeOptions(options);
211
+ restartOptions = mergedOptions;
200
212
  const appDirectory = await initAppDir();
201
- const metaName = (_options$options$meta = options === null || options === void 0 ? void 0 : (_options$options = options.options) === null || _options$options === void 0 ? void 0 : _options$options.metaName) !== null && _options$options$meta !== void 0 ? _options$options$meta : 'MODERN';
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';
202
215
  (0, _loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
203
- const loaded = await (0, _config.loadUserConfig)(appDirectory, options === null || options === void 0 ? void 0 : options.configFile, options === null || options === void 0 ? void 0 : options.packageJsonConfig);
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);
204
217
  const plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config, {
205
- internalPlugins: options === null || options === void 0 ? void 0 : options.plugins
218
+ internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins,
219
+ transformPlugin: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.transformPlugin
206
220
  });
207
221
  plugins.forEach(plugin => plugin.cli && _manager.manager.usePlugin(plugin.cli));
208
- const appContext = (0, _context.initAppContext)(appDirectory, plugins, loaded.filePath, options === null || options === void 0 ? void 0 : options.options);
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);
209
231
 
210
232
  _manager.manager.run(() => {
211
233
  _context.ConfigContext.set(loaded.config);
@@ -263,11 +285,11 @@ const createCli = () => {
263
285
  resolved
264
286
  } = await init(argv, options);
265
287
  await hooksRunner.commands({
266
- program: _commander.program
288
+ program: _utils.program
267
289
  });
268
290
  (0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
269
291
 
270
- _manager.manager.run(() => _commander.program.parse(process.argv));
292
+ _manager.manager.run(() => _utils.program.parse(process.argv));
271
293
  }
272
294
 
273
295
  async function restart() {
@@ -291,7 +313,7 @@ const createCli = () => {
291
313
  hasGetError = true;
292
314
  } finally {
293
315
  if (!hasGetError) {
294
- _manager.manager.run(() => _commander.program.parse(process.argv));
316
+ _manager.manager.run(() => _utils.program.parse(process.argv));
295
317
  }
296
318
  }
297
319
  }
@@ -13,8 +13,6 @@ var _path = _interopRequireDefault(require("path"));
13
13
 
14
14
  var _utils = require("@modern-js/utils");
15
15
 
16
- var _chokidar = _interopRequireDefault(require("chokidar"));
17
-
18
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
17
 
20
18
  const debug = (0, _utils.createDebugger)('watch-files');
@@ -33,8 +31,9 @@ const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) =
33
31
  const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
34
32
  debug(`watched: %o`, watched);
35
33
 
36
- const watcher = _chokidar.default.watch(watched, {
34
+ const watcher = _utils.chokidar.watch(watched, {
37
35
  cwd: appDirectory,
36
+ ignoreInitial: true,
38
37
  ignorePermissionErrors: true,
39
38
  ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
40
39
  });