@modern-js/core 1.5.0 → 1.7.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 (55) hide show
  1. package/.eslintrc.js +0 -2
  2. package/CHANGELOG.md +48 -0
  3. package/dist/js/modern/config/defaults.js +4 -1
  4. package/dist/js/modern/config/index.js +11 -7
  5. package/dist/js/modern/config/mergeConfig.js +1 -1
  6. package/dist/js/modern/config/schema/index.js +1 -1
  7. package/dist/js/modern/config/types/index.js +1 -0
  8. package/dist/js/modern/config/types/less.js +0 -0
  9. package/dist/js/modern/config/types/sass.js +0 -0
  10. package/dist/js/modern/config/types/ssg.js +0 -0
  11. package/dist/js/modern/config/types/test.js +0 -0
  12. package/dist/js/modern/config/types/unbundle.js +0 -0
  13. package/dist/js/modern/context.js +8 -1
  14. package/dist/js/modern/index.js +26 -9
  15. package/dist/js/modern/initWatcher.js +2 -2
  16. package/dist/js/modern/loadPlugins.js +41 -41
  17. package/dist/js/modern/utils/commander.js +15 -15
  18. package/dist/js/node/config/defaults.js +4 -1
  19. package/dist/js/node/config/index.js +38 -11
  20. package/dist/js/node/config/mergeConfig.js +2 -4
  21. package/dist/js/node/config/schema/index.js +3 -5
  22. package/dist/js/node/config/types/index.js +5 -0
  23. package/dist/js/node/config/types/less.js +0 -0
  24. package/dist/js/node/config/types/sass.js +0 -0
  25. package/dist/js/node/config/types/ssg.js +0 -0
  26. package/dist/js/node/config/types/test.js +0 -0
  27. package/dist/js/node/config/types/unbundle.js +0 -0
  28. package/dist/js/node/context.js +8 -1
  29. package/dist/js/node/index.js +31 -10
  30. package/dist/js/node/initWatcher.js +2 -3
  31. package/dist/js/node/loadPlugins.js +40 -41
  32. package/dist/js/node/utils/commander.js +16 -19
  33. package/dist/types/config/defaults.d.ts +3 -0
  34. package/dist/types/config/index.d.ts +4 -129
  35. package/dist/types/config/types/index.d.ts +239 -0
  36. package/dist/types/config/types/less.d.ts +10 -0
  37. package/dist/types/config/types/sass.d.ts +8 -0
  38. package/dist/types/config/types/ssg.d.ts +13 -0
  39. package/dist/types/config/types/test.d.ts +15 -0
  40. package/dist/types/config/types/unbundle.d.ts +28 -0
  41. package/dist/types/context.d.ts +18 -6
  42. package/dist/types/index.d.ts +19 -0
  43. package/dist/types/initWatcher.d.ts +1 -2
  44. package/dist/types/loadPlugins.d.ts +24 -10
  45. package/dist/types/manager.d.ts +1 -1
  46. package/dist/types/utils/commander.d.ts +4 -3
  47. package/jest.config.js +0 -1
  48. package/package.json +17 -17
  49. package/tests/config.test.ts +14 -5
  50. package/tests/context.test.ts +17 -2
  51. package/tests/fixtures/index-test/modern.server-runtime.config.js +0 -0
  52. package/tests/index.test.ts +15 -1
  53. package/tests/initWatcher.test.ts +1 -1
  54. package/tests/loadPlugin.test.ts +31 -6
  55. package/tests/utils.test.ts +1 -2
package/.eslintrc.js CHANGED
@@ -2,9 +2,7 @@ module.exports = {
2
2
  root: true,
3
3
  extends: ['@modern-js'],
4
4
  parserOptions: {
5
- // the base path used to search for `tsconfig.json`
6
5
  tsconfigRootDir: __dirname,
7
- // the relative path to sub-package's `tsconfig.json`
8
6
  project: ['./tsconfig.json'],
9
7
  },
10
8
  };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
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
+
34
+ ## 1.6.0
35
+
36
+ ### Minor Changes
37
+
38
+ - 4e2026e4: feat: support new plugin config
39
+
40
+ ### Patch Changes
41
+
42
+ - 05ce88a0: fix: set default value for type NormalizedConfig to ensure all config keys are required
43
+ - a8df060e: support setup dev middleware first step
44
+ - 6a7acb81: modify devServer type and name
45
+ - Updated dependencies [c2046f37]
46
+ - Updated dependencies [dc88abf9]
47
+ - Updated dependencies [0462ff77]
48
+ - @modern-js/utils@1.3.6
49
+ - @modern-js/plugin@1.3.2
50
+
3
51
  ## 1.5.0
4
52
 
5
53
  ### Minor Changes
@@ -96,5 +96,8 @@ export const defaults = {
96
96
  server: serverDefaults,
97
97
  dev: devDefaults,
98
98
  deploy: deployDefaults,
99
- tools: toolsDefaults
99
+ tools: toolsDefaults,
100
+ plugins: [],
101
+ runtime: {},
102
+ runtimeByEntries: {}
100
103
  };
@@ -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 {};
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,
@@ -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,30 @@ 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
61
70
  });
62
71
  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);
72
+ const appContext = initAppContext({
73
+ appDirectory,
74
+ plugins,
75
+ configFile: loaded.filePath,
76
+ options: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options,
77
+ serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile
78
+ }); // 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
79
+
80
+ addServerConfigToDeps(loaded.dependencies, appDirectory, mergedOptions.serverConfigFile);
64
81
  manager.run(() => {
65
82
  ConfigContext.set(loaded.config);
66
83
  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
  });
@@ -1,9 +1,3 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
- 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; }
4
-
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
-
7
1
  import { isDepExists, createDebugger, compatRequire, INTERNAL_PLUGINS } from '@modern-js/utils';
8
2
  import { createPlugin } from "./manager";
9
3
  const debug = createDebugger('load-plugins');
@@ -33,7 +27,7 @@ const tryResolve = (name, appDirectory) => {
33
27
  return filePath;
34
28
  };
35
29
 
36
- export function getAppPlugins(appDirectory, pluginConfig, internalPlugins) {
30
+ export function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
37
31
  const allPlugins = internalPlugins || INTERNAL_PLUGINS;
38
32
  const appPlugins = [...Object.keys(allPlugins).filter(name => {
39
33
  const config = allPlugins[name];
@@ -44,9 +38,31 @@ export function getAppPlugins(appDirectory, pluginConfig, internalPlugins) {
44
38
  }
45
39
 
46
40
  return isDepExists(appDirectory, name);
47
- }).map(name => allPlugins[name]), ...pluginConfig];
41
+ }).map(name => allPlugins[name]), ...oldPluginConfig];
48
42
  return appPlugins;
49
43
  }
44
+
45
+ const resolveCliPlugin = (p, appDirectory) => {
46
+ const pkg = typeof p === 'string' ? p : p[0];
47
+ const path = tryResolve(pkg, appDirectory);
48
+ const module = compatRequire(path);
49
+
50
+ if (typeof module === 'function') {
51
+ const pluginOptions = Array.isArray(p) ? p[1] : undefined;
52
+ const result = module(pluginOptions);
53
+ return createPlugin(result.setup, result);
54
+ }
55
+
56
+ return module;
57
+ };
58
+
59
+ const isOldPluginConfig = config => Array.isArray(config) && config.some(item => {
60
+ if (typeof item === 'string' || Array.isArray(item)) {
61
+ return true;
62
+ }
63
+
64
+ return 'cli' in item || 'server' in item;
65
+ });
50
66
  /**
51
67
  * Load internal plugins which in @modern-js scope and user's custom plugins.
52
68
  * @param appDirectory - Application root directory.
@@ -55,31 +71,11 @@ export function getAppPlugins(appDirectory, pluginConfig, internalPlugins) {
55
71
  * @returns Plugin Objects has been required.
56
72
  */
57
73
 
58
- export const loadPlugins = (appDirectory, userConfig, options = {}) => {
59
- const {
60
- internalPlugins
61
- } = options;
62
-
63
- const resolvePlugin = p => {
64
- const pkg = typeof p === 'string' ? p : p[0];
65
- const path = tryResolve(pkg, appDirectory);
66
- let module = compatRequire(path);
67
- const pluginOptions = Array.isArray(p) ? p[1] : undefined;
68
-
69
- if (typeof module === 'function') {
70
- const plugin = module(pluginOptions);
71
- module = createPlugin(plugin.setup, plugin);
72
- }
73
-
74
- return {
75
- pkg,
76
- path,
77
- module
78
- };
79
- };
80
74
 
81
- const plugins = getAppPlugins(appDirectory, userConfig.plugins || [], internalPlugins);
82
- return plugins.map(plugin => {
75
+ export const loadPlugins = (appDirectory, userConfig, options = {}) => {
76
+ const pluginConfig = userConfig.plugins;
77
+ const plugins = getAppPlugins(appDirectory, isOldPluginConfig(pluginConfig) ? pluginConfig : [], options.internalPlugins);
78
+ const loadedPlugins = plugins.map(plugin => {
83
79
  const _plugin = typeof plugin === 'string' || Array.isArray(plugin) ? {
84
80
  cli: plugin
85
81
  } : plugin;
@@ -91,15 +87,7 @@ export const loadPlugins = (appDirectory, userConfig, options = {}) => {
91
87
  const loadedPlugin = {};
92
88
 
93
89
  if (cli) {
94
- const {
95
- pkg,
96
- path,
97
- module
98
- } = resolvePlugin(cli);
99
- loadedPlugin.cli = _objectSpread(_objectSpread({}, module), {}, {
100
- pluginPath: path
101
- });
102
- loadedPlugin.cliPkg = pkg;
90
+ loadedPlugin.cli = resolveCliPlugin(cli, appDirectory);
103
91
  } // server plugins don't support to accept params
104
92
 
105
93
 
@@ -114,4 +102,16 @@ export const loadPlugins = (appDirectory, userConfig, options = {}) => {
114
102
  });
115
103
  return loadedPlugin;
116
104
  });
105
+
106
+ if (!isOldPluginConfig(pluginConfig)) {
107
+ const cliPlugins = Array.isArray(pluginConfig) ? pluginConfig : pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.cli;
108
+
109
+ if (cliPlugins !== null && cliPlugins !== void 0 && cliPlugins.length) {
110
+ loadedPlugins.push(...cliPlugins.map(item => ({
111
+ cli: createPlugin(item.setup, item)
112
+ })));
113
+ }
114
+ }
115
+
116
+ return loadedPlugins;
117
117
  };
@@ -1,19 +1,19 @@
1
- import { program, Command } from 'commander';
1
+ import { program, Command } 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 };
@@ -102,6 +102,9 @@ const defaults = {
102
102
  server: serverDefaults,
103
103
  dev: devDefaults,
104
104
  deploy: deployDefaults,
105
- tools: toolsDefaults
105
+ tools: toolsDefaults,
106
+ plugins: [],
107
+ runtime: {},
108
+ runtimeByEntries: {}
106
109
  };
107
110
  exports.defaults = defaults;
@@ -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
+ });
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,