@modern-js/core 1.1.2 → 1.1.5-beta.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 1.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - d73ff455: support multi process product
8
+ - d73ff455: support multi process product
9
+ - d73ff455: support multi process product
10
+ - d73ff455: support multi process product
11
+ - d73ff455: support multi process product
12
+ - Updated dependencies [d927bc83]
13
+ - Updated dependencies [d73ff455]
14
+ - Updated dependencies [9c1ab865]
15
+ - Updated dependencies [d73ff455]
16
+ - Updated dependencies [d73ff455]
17
+ - Updated dependencies [d73ff455]
18
+ - Updated dependencies [d73ff455]
19
+ - @modern-js/utils@1.1.4
20
+
21
+ ## 1.1.3
22
+
23
+ ### Patch Changes
24
+
25
+ - 085a6a58: refactor server plugin
26
+ - 085a6a58: refactor server plugin
27
+ - 085a6a58: refactor server conifg
28
+ - d4fcc73a: add options.plugins:
29
+ - 085a6a58: support server runtime
30
+ - ed1f6b12: feat: support build --analyze
31
+ - a5ebbb00: fix: remove enableUsageBuiltIns config
32
+ - 085a6a58: feat: refactor server plugin
33
+ - Updated dependencies [085a6a58]
34
+ - Updated dependencies [085a6a58]
35
+ - Updated dependencies [085a6a58]
36
+ - Updated dependencies [d280ea33]
37
+ - Updated dependencies [085a6a58]
38
+ - Updated dependencies [085a6a58]
39
+ - @modern-js/utils@1.1.3
40
+
3
41
  ## 1.1.2
4
42
 
5
43
  ### Patch Changes
@@ -1,6 +1,6 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
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
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
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
4
 
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
 
@@ -107,9 +107,6 @@ export const output = {
107
107
  enableLatestDecorators: {
108
108
  type: 'boolean'
109
109
  },
110
- enableUsageBuiltIns: {
111
- type: 'boolean'
112
- },
113
110
  enableTsLoader: {
114
111
  type: 'boolean'
115
112
  },
@@ -157,7 +157,7 @@ export const server = {
157
157
  logger: {
158
158
  type: 'object'
159
159
  },
160
- measure: {
160
+ metrics: {
161
161
  type: 'object'
162
162
  },
163
163
  proxy: {
@@ -1,12 +1,12 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
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
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
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
4
 
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
8
  import { compatRequire, pkgUp, ensureAbsolutePath, logger } from '@modern-js/utils';
9
- import { createAsyncManager, createAsyncWorkflow, createParallelWorkflow } from '@modern-js/plugin';
9
+ import { createAsyncManager, createAsyncWorkflow, createParallelWorkflow, createAsyncWaterfall } from '@modern-js/plugin';
10
10
  import { enable } from '@modern-js/plugin/node';
11
11
  import { program } from "./utils/commander";
12
12
  import { resolveConfig, defineConfig, loadUserConfig } from "./config";
@@ -20,6 +20,7 @@ export * from '@modern-js/plugin/node';
20
20
  program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
21
21
  const hooksMap = {
22
22
  config: createParallelWorkflow(),
23
+ resolvedConfig: createAsyncWaterfall(),
23
24
  validateSchema: createParallelWorkflow(),
24
25
  // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
25
26
  prepare: createAsyncWorkflow(),
@@ -36,7 +37,7 @@ export const {
36
37
  useRunner: mountHook
37
38
  } = manager;
38
39
  export const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin(compatRequire(require.resolve(plugin))));
39
- export { defineConfig, AppContext, useAppContext, useConfigContext, useResolvedConfigContext };
40
+ export { defineConfig, AppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, ConfigContext };
40
41
 
41
42
  const initAppDir = async () => {
42
43
  const pkg = await pkgUp({
@@ -59,8 +60,8 @@ const createCli = () => {
59
60
  manager.clear();
60
61
  const appDirectory = await initAppDir();
61
62
  loadEnv(appDirectory);
62
- const loaded = await loadUserConfig(appDirectory);
63
- let plugins = loadPlugins(appDirectory, loaded.config.plugins || []);
63
+ const loaded = await loadUserConfig(appDirectory, options === null || options === void 0 ? void 0 : options.configFile);
64
+ let plugins = loadPlugins(appDirectory, loaded.config.plugins || [], options === null || options === void 0 ? void 0 : options.plugins);
64
65
 
65
66
  if (options !== null && options !== void 0 && options.beforeUsePlugins) {
66
67
  plugins = options.beforeUsePlugins(plugins, loaded.config);
@@ -89,7 +90,12 @@ const createCli = () => {
89
90
  });
90
91
  const extraConfigs = await hooksRunner.config();
91
92
  const extraSchemas = await hooksRunner.validateSchema();
92
- const resolved = await resolveConfig(loaded, extraConfigs, extraSchemas, isRestart, argv); // update context value
93
+ const config = await resolveConfig(loaded, extraConfigs, extraSchemas, isRestart, argv);
94
+ const {
95
+ resolved
96
+ } = await hooksRunner.resolvedConfig({
97
+ resolved: config
98
+ }); // update context value
93
99
 
94
100
  manager.run(() => {
95
101
  ConfigContext.set(loaded.config);
@@ -144,4 +150,5 @@ const createCli = () => {
144
150
  };
145
151
  };
146
152
 
147
- export const cli = createCli();
153
+ export const cli = createCli();
154
+ export { loadUserConfig, initAppDir, initAppContext };
@@ -1,3 +1,9 @@
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
+
1
7
  import { isDepExists, createDebugger, compatRequire, INTERNAL_PLUGINS } from '@modern-js/utils';
2
8
  const debug = createDebugger('load-plugins');
3
9
 
@@ -58,9 +64,20 @@ export const loadPlugins = (appDirectory, pluginConfig, internalPlugins) => {
58
64
  cli,
59
65
  server
60
66
  });
67
+
68
+ const cliPlugin = cli && _objectSpread(_objectSpread({}, compatRequire(cli)), {}, {
69
+ pluginPath: cli
70
+ });
71
+
72
+ const serverPlugin = server && _objectSpread(_objectSpread({}, compatRequire(server)), {}, {
73
+ pluginPath: server
74
+ });
75
+
61
76
  return {
62
- cli: cli && compatRequire(cli),
63
- server: server && compatRequire(server)
77
+ cli: cliPlugin,
78
+ cliPath: typeof plugin === 'string' ? plugin : plugin.cli,
79
+ server: serverPlugin,
80
+ serverPath: typeof plugin === 'string' ? undefined : plugin.server
64
81
  };
65
82
  });
66
83
  };
@@ -44,9 +44,9 @@ var _schema = require("./schema");
44
44
 
45
45
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
46
46
 
47
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
47
+ 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; }
48
48
 
49
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
49
+ 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; }
50
50
 
51
51
  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; }
52
52
 
@@ -115,9 +115,6 @@ const output = {
115
115
  enableLatestDecorators: {
116
116
  type: 'boolean'
117
117
  },
118
- enableUsageBuiltIns: {
119
- type: 'boolean'
120
- },
121
118
  enableTsLoader: {
122
119
  type: 'boolean'
123
120
  },
@@ -165,7 +165,7 @@ const server = {
165
165
  logger: {
166
166
  type: 'object'
167
167
  },
168
- measure: {
168
+ metrics: {
169
169
  type: 'object'
170
170
  },
171
171
  proxy: {
@@ -10,10 +10,15 @@ var _exportNames = {
10
10
  mountHook: true,
11
11
  usePlugins: true,
12
12
  cli: true,
13
+ initAppDir: true,
13
14
  defineConfig: true,
15
+ loadUserConfig: true,
14
16
  defaultsConfig: true,
15
17
  mergeConfig: true,
16
18
  AppContext: true,
19
+ ConfigContext: true,
20
+ initAppContext: true,
21
+ ResolvedConfigContext: true,
17
22
  useAppContext: true,
18
23
  useConfigContext: true,
19
24
  useResolvedConfigContext: true
@@ -24,6 +29,18 @@ Object.defineProperty(exports, "AppContext", {
24
29
  return _context.AppContext;
25
30
  }
26
31
  });
32
+ Object.defineProperty(exports, "ConfigContext", {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _context.ConfigContext;
36
+ }
37
+ });
38
+ Object.defineProperty(exports, "ResolvedConfigContext", {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _context.ResolvedConfigContext;
42
+ }
43
+ });
27
44
  exports.createPlugin = exports.cli = void 0;
28
45
  Object.defineProperty(exports, "defaultsConfig", {
29
46
  enumerable: true,
@@ -37,6 +54,19 @@ Object.defineProperty(exports, "defineConfig", {
37
54
  return _config.defineConfig;
38
55
  }
39
56
  });
57
+ Object.defineProperty(exports, "initAppContext", {
58
+ enumerable: true,
59
+ get: function () {
60
+ return _context.initAppContext;
61
+ }
62
+ });
63
+ exports.initAppDir = void 0;
64
+ Object.defineProperty(exports, "loadUserConfig", {
65
+ enumerable: true,
66
+ get: function () {
67
+ return _config.loadUserConfig;
68
+ }
69
+ });
40
70
  exports.manager = void 0;
41
71
  Object.defineProperty(exports, "mergeConfig", {
42
72
  enumerable: true,
@@ -111,9 +141,9 @@ var _loadEnv = require("./loadEnv");
111
141
 
112
142
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
113
143
 
114
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
144
+ 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; }
115
145
 
116
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
146
+ 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; }
117
147
 
118
148
  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; }
119
149
 
@@ -121,6 +151,7 @@ _commander.program.name('modern').usage('<command> [options]').version(process.e
121
151
 
122
152
  const hooksMap = {
123
153
  config: (0, _plugin.createParallelWorkflow)(),
154
+ resolvedConfig: (0, _plugin.createAsyncWaterfall)(),
124
155
  validateSchema: (0, _plugin.createParallelWorkflow)(),
125
156
  // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
126
157
  prepare: (0, _plugin.createAsyncWorkflow)(),
@@ -157,6 +188,8 @@ const initAppDir = async () => {
157
188
  return _path.default.dirname(pkg);
158
189
  };
159
190
 
191
+ exports.initAppDir = initAppDir;
192
+
160
193
  const createCli = () => {
161
194
  let hooksRunner;
162
195
  let isRestart = false;
@@ -166,8 +199,8 @@ const createCli = () => {
166
199
  manager.clear();
167
200
  const appDirectory = await initAppDir();
168
201
  (0, _loadEnv.loadEnv)(appDirectory);
169
- const loaded = await (0, _config.loadUserConfig)(appDirectory);
170
- let plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config.plugins || []);
202
+ const loaded = await (0, _config.loadUserConfig)(appDirectory, options === null || options === void 0 ? void 0 : options.configFile);
203
+ let plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config.plugins || [], options === null || options === void 0 ? void 0 : options.plugins);
171
204
 
172
205
  if (options !== null && options !== void 0 && options.beforeUsePlugins) {
173
206
  plugins = options.beforeUsePlugins(plugins, loaded.config);
@@ -197,7 +230,12 @@ const createCli = () => {
197
230
  });
198
231
  const extraConfigs = await hooksRunner.config();
199
232
  const extraSchemas = await hooksRunner.validateSchema();
200
- const resolved = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas, isRestart, argv); // update context value
233
+ const config = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas, isRestart, argv);
234
+ const {
235
+ resolved
236
+ } = await hooksRunner.resolvedConfig({
237
+ resolved: config
238
+ }); // update context value
201
239
 
202
240
  manager.run(() => {
203
241
  _context.ConfigContext.set(loaded.config);
@@ -7,6 +7,12 @@ exports.loadPlugins = void 0;
7
7
 
8
8
  var _utils = require("@modern-js/utils");
9
9
 
10
+ 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; }
11
+
12
+ 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; }
13
+
14
+ 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; }
15
+
10
16
  const debug = (0, _utils.createDebugger)('load-plugins');
11
17
 
12
18
  /**
@@ -66,9 +72,20 @@ const loadPlugins = (appDirectory, pluginConfig, internalPlugins) => {
66
72
  cli,
67
73
  server
68
74
  });
75
+
76
+ const cliPlugin = cli && _objectSpread(_objectSpread({}, (0, _utils.compatRequire)(cli)), {}, {
77
+ pluginPath: cli
78
+ });
79
+
80
+ const serverPlugin = server && _objectSpread(_objectSpread({}, (0, _utils.compatRequire)(server)), {}, {
81
+ pluginPath: server
82
+ });
83
+
69
84
  return {
70
- cli: cli && (0, _utils.compatRequire)(cli),
71
- server: server && (0, _utils.compatRequire)(server)
85
+ cli: cliPlugin,
86
+ cliPath: typeof plugin === 'string' ? plugin : plugin.cli,
87
+ server: serverPlugin,
88
+ serverPath: typeof plugin === 'string' ? undefined : plugin.server
72
89
  };
73
90
  });
74
91
  };
@@ -72,8 +72,8 @@ export interface ServerConfig {
72
72
  ssrByEntries?: Record<string, boolean | Record<string, unknown>>;
73
73
  baseUrl?: string | Array<string>;
74
74
  port?: number;
75
- logger?: Record<string, string>;
76
- measure?: Record<string, string>;
75
+ logger?: Record<string, any>;
76
+ metrics?: Record<string, any>;
77
77
  enableMicroFrontendDebug?: boolean;
78
78
  }
79
79
  export interface DevConfig {
@@ -81,7 +81,7 @@ export interface DevConfig {
81
81
  https?: boolean;
82
82
  }
83
83
  export interface DeployConfig {
84
- microFrontend?: boolean | Record<string, unknown>;
84
+ microFrontend?: boolean & Record<string, unknown>;
85
85
  domain?: string | Array<string>;
86
86
  domainByEntries?: Record<string, string | Array<string>>;
87
87
  }
@@ -17,6 +17,7 @@ export interface NormalizedToolsConfig extends Omit<ToolsConfig, 'webpack' | 'ba
17
17
  export interface NormalizedConfig extends Omit<Required<UserConfig>, 'source' | 'tools'> {
18
18
  source: NormalizedSourceConfig;
19
19
  tools: NormalizedToolsConfig;
20
+ cliOptions?: Record<string, any>;
20
21
  _raw: UserConfig;
21
22
  }
22
23
  /**
@@ -173,9 +173,6 @@ export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | P
173
173
  enableLatestDecorators: {
174
174
  type: string;
175
175
  };
176
- enableUsageBuiltIns: {
177
- type: string;
178
- };
179
176
  enableTsLoader: {
180
177
  type: string;
181
178
  };
@@ -382,7 +379,7 @@ export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | P
382
379
  logger: {
383
380
  type: string;
384
381
  };
385
- measure: {
382
+ metrics: {
386
383
  type: string;
387
384
  };
388
385
  proxy: {
@@ -106,9 +106,6 @@ export declare const output: {
106
106
  enableLatestDecorators: {
107
107
  type: string;
108
108
  };
109
- enableUsageBuiltIns: {
110
- type: string;
111
- };
112
109
  enableTsLoader: {
113
110
  type: string;
114
111
  };
@@ -169,7 +169,7 @@ export declare const server: {
169
169
  logger: {
170
170
  type: string;
171
171
  };
172
- measure: {
172
+ metrics: {
173
173
  type: string;
174
174
  };
175
175
  proxy: {
@@ -1,9 +1,9 @@
1
1
  import { INTERNAL_PLUGINS } from '@modern-js/utils';
2
- import { ParallelWorkflow, AsyncWorkflow, Progresses2Runners } from '@modern-js/plugin';
2
+ import { ParallelWorkflow, AsyncWorkflow, Progresses2Runners, AsyncWaterfall } from '@modern-js/plugin';
3
3
  import type { Hooks } from '@modern-js/types';
4
4
  import { Command } from './utils/commander';
5
- import { defineConfig, UserConfig, ToolsConfig } from './config';
6
- import { AppContext, IAppContext, useAppContext, useConfigContext, useResolvedConfigContext } from './context';
5
+ import { defineConfig, loadUserConfig, UserConfig, ToolsConfig } from './config';
6
+ import { AppContext, ConfigContext, IAppContext, initAppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext } from './context';
7
7
  import { NormalizedConfig } from './config/mergeConfig';
8
8
  export type { Hooks };
9
9
  export { defaultsConfig, mergeConfig } from './config';
@@ -11,6 +11,9 @@ export * from '@modern-js/plugin';
11
11
  export * from '@modern-js/plugin/node';
12
12
  export declare type HooksRunner = Progresses2Runners<{
13
13
  config: ParallelWorkflow<void>;
14
+ resolvedConfig: AsyncWaterfall<{
15
+ resolved: NormalizedConfig;
16
+ }>;
14
17
  validateSchema: ParallelWorkflow<void>;
15
18
  prepare: AsyncWorkflow<void, void>;
16
19
  commands: AsyncWorkflow<{
@@ -24,6 +27,9 @@ export declare type HooksRunner = Progresses2Runners<{
24
27
  }>;
25
28
  export declare const manager: import("@modern-js/plugin").AsyncManager<Hooks, {
26
29
  config: ParallelWorkflow<void, unknown>;
30
+ resolvedConfig: AsyncWaterfall<{
31
+ resolved: NormalizedConfig;
32
+ }>;
27
33
  validateSchema: ParallelWorkflow<void, unknown>;
28
34
  prepare: AsyncWorkflow<void, void>;
29
35
  commands: AsyncWorkflow<{
@@ -37,6 +43,9 @@ export declare const manager: import("@modern-js/plugin").AsyncManager<Hooks, {
37
43
  }>;
38
44
  export declare const createPlugin: (initializer: import("@modern-js/plugin").AsyncInitializer<Partial<import("@modern-js/plugin").Progresses2Threads<{
39
45
  config: ParallelWorkflow<void, unknown>;
46
+ resolvedConfig: AsyncWaterfall<{
47
+ resolved: NormalizedConfig;
48
+ }>;
40
49
  validateSchema: ParallelWorkflow<void, unknown>;
41
50
  prepare: AsyncWorkflow<void, void>;
42
51
  commands: AsyncWorkflow<{
@@ -49,6 +58,9 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
49
58
  beforeExit: AsyncWorkflow<void, void>;
50
59
  } & import("@modern-js/plugin").ClearDraftProgress<Hooks>>>>, options?: import("@modern-js/plugin").PluginOptions | undefined) => import("@modern-js/plugin").AsyncPlugin<Partial<import("@modern-js/plugin").Progresses2Threads<{
51
60
  config: ParallelWorkflow<void, unknown>;
61
+ resolvedConfig: AsyncWaterfall<{
62
+ resolved: NormalizedConfig;
63
+ }>;
52
64
  validateSchema: ParallelWorkflow<void, unknown>;
53
65
  prepare: AsyncWorkflow<void, void>;
54
66
  commands: AsyncWorkflow<{
@@ -61,6 +73,9 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
61
73
  beforeExit: AsyncWorkflow<void, void>;
62
74
  } & import("@modern-js/plugin").ClearDraftProgress<Hooks>>>>, registerHook: (newShape: Partial<Hooks>) => void, mountHook: () => Progresses2Runners<{
63
75
  config: ParallelWorkflow<void, unknown>;
76
+ resolvedConfig: AsyncWaterfall<{
77
+ resolved: NormalizedConfig;
78
+ }>;
64
79
  validateSchema: ParallelWorkflow<void, unknown>;
65
80
  prepare: AsyncWorkflow<void, void>;
66
81
  commands: AsyncWorkflow<{
@@ -73,14 +88,17 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
73
88
  beforeExit: AsyncWorkflow<void, void>;
74
89
  } & import("@modern-js/plugin").ClearDraftProgress<Hooks>>;
75
90
  export declare const usePlugins: (plugins: string[]) => void;
76
- export { defineConfig, AppContext, useAppContext, useConfigContext, useResolvedConfigContext };
91
+ export { defineConfig, AppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, ConfigContext };
77
92
  export type { NormalizedConfig, IAppContext, UserConfig, ToolsConfig };
93
+ declare const initAppDir: () => Promise<string>;
78
94
  export interface CoreOptions {
79
- name?: string;
95
+ configFile?: string;
80
96
  plugins?: typeof INTERNAL_PLUGINS;
81
97
  beforeUsePlugins: (plugins: any, config: any) => {
82
98
  cli: any;
99
+ cliPath: any;
83
100
  server: any;
101
+ serverPath: any;
84
102
  }[];
85
103
  }
86
104
  export declare const cli: {
@@ -91,4 +109,5 @@ export declare const cli: {
91
109
  }>;
92
110
  run: (argv: string[], options?: CoreOptions | undefined) => Promise<void>;
93
111
  restart: () => Promise<void>;
94
- };
112
+ };
113
+ export { loadUserConfig, initAppDir, initAppContext };
@@ -17,5 +17,7 @@ export declare const loadPlugins: (appDirectory: string, pluginConfig: PluginCon
17
17
  };
18
18
  } | undefined) => {
19
19
  cli: any;
20
+ cliPath: string | undefined;
20
21
  server: any;
22
+ serverPath: string | undefined;
21
23
  }[];
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.2",
14
+ "version": "1.1.5-beta.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -35,12 +35,20 @@
35
35
  }
36
36
  },
37
37
  "bin": "./bin/modern-js.js",
38
+ "scripts": {
39
+ "prepare": "pnpm build",
40
+ "prepublishOnly": "pnpm build -- --platform",
41
+ "new": "modern new",
42
+ "build": "modern build",
43
+ "dev": "modern build --watch",
44
+ "test": "modern test --passWithNoTests"
45
+ },
38
46
  "dependencies": {
39
47
  "@babel/code-frame": "^7.14.5",
40
48
  "@babel/runtime": "^7",
41
- "@modern-js/load-config": "^1.1.1",
42
- "@modern-js/plugin": "^1.1.2",
43
- "@modern-js/utils": "^1.1.2",
49
+ "@modern-js/load-config": "workspace:^1.1.1",
50
+ "@modern-js/plugin": "workspace:^1.1.2",
51
+ "@modern-js/utils": "workspace:^1.1.4",
44
52
  "address": "^1.1.2",
45
53
  "ajv": "^8.6.2",
46
54
  "ajv-keywords": "^5.0.0",
@@ -57,7 +65,7 @@
57
65
  },
58
66
  "devDependencies": {
59
67
  "@types/babel__code-frame": "^7.0.3",
60
- "@modern-js/types": "^1.1.2",
68
+ "@modern-js/types": "workspace:^1.1.3",
61
69
  "@types/jest": "^26",
62
70
  "@types/lodash.clonedeep": "^4.5.6",
63
71
  "@types/lodash.mergewith": "^4.6.6",
@@ -66,8 +74,8 @@
66
74
  "@types/react-dom": "^17",
67
75
  "@types/signale": "^1.4.2",
68
76
  "typescript": "^4",
69
- "@modern-js/plugin-testing": "^1.1.0",
70
- "@modern-js/module-tools": "^1.1.0"
77
+ "@modern-js/plugin-testing": "^1.1.1",
78
+ "@modern-js/module-tools": "^1.1.2"
71
79
  },
72
80
  "sideEffects": false,
73
81
  "modernConfig": {
@@ -78,11 +86,5 @@
78
86
  "publishConfig": {
79
87
  "registry": "https://registry.npmjs.org/",
80
88
  "access": "public"
81
- },
82
- "scripts": {
83
- "new": "modern new",
84
- "build": "modern build",
85
- "dev": "modern build --watch",
86
- "test": "modern test --passWithNoTests"
87
89
  }
88
- }
90
+ }
@@ -106,8 +106,8 @@ export interface ServerConfig {
106
106
  ssrByEntries?: Record<string, boolean | Record<string, unknown>>;
107
107
  baseUrl?: string | Array<string>;
108
108
  port?: number;
109
- logger?: Record<string, string>;
110
- measure?: Record<string, string>;
109
+ logger?: Record<string, any>;
110
+ metrics?: Record<string, any>;
111
111
  enableMicroFrontendDebug?: boolean;
112
112
  }
113
113
 
@@ -117,7 +117,7 @@ export interface DevConfig {
117
117
  }
118
118
 
119
119
  export interface DeployConfig {
120
- microFrontend?: boolean | Record<string, unknown>;
120
+ microFrontend?: boolean & Record<string, unknown>;
121
121
  domain?: string | Array<string>;
122
122
  domainByEntries?: Record<string, string | Array<string>>;
123
123
  }
@@ -43,6 +43,7 @@ export interface NormalizedConfig
43
43
  extends Omit<Required<UserConfig>, 'source' | 'tools'> {
44
44
  source: NormalizedSourceConfig;
45
45
  tools: NormalizedToolsConfig;
46
+ cliOptions?: Record<string, any>;
46
47
  _raw: UserConfig;
47
48
  }
48
49
 
@@ -46,7 +46,6 @@ export const output = {
46
46
  disableInlineRuntimeChunk: { type: 'boolean' },
47
47
  disableAssetsCache: { type: 'boolean' },
48
48
  enableLatestDecorators: { type: 'boolean' },
49
- enableUsageBuiltIns: { type: 'boolean' },
50
49
  enableTsLoader: { type: 'boolean' },
51
50
  dataUriLimit: { type: 'number' },
52
51
  templateParameters: { type: 'object' },
@@ -99,7 +99,7 @@ export const server = {
99
99
  middleware: { instanceof: ['Array', 'Function'] },
100
100
  renderHook: { instanceof: 'Function' },
101
101
  logger: { type: 'object' },
102
- measure: { type: 'object' },
102
+ metrics: { type: 'object' },
103
103
  proxy: { type: 'object' },
104
104
  enableMicroFrontendDebug: { type: 'boolean' },
105
105
  },
package/src/index.ts CHANGED
@@ -13,6 +13,8 @@ import {
13
13
  ParallelWorkflow,
14
14
  AsyncWorkflow,
15
15
  Progresses2Runners,
16
+ createAsyncWaterfall,
17
+ AsyncWaterfall,
16
18
  } from '@modern-js/plugin';
17
19
  import { enable } from '@modern-js/plugin/node';
18
20
 
@@ -53,6 +55,9 @@ program
53
55
 
54
56
  export type HooksRunner = Progresses2Runners<{
55
57
  config: ParallelWorkflow<void>;
58
+ resolvedConfig: AsyncWaterfall<{
59
+ resolved: NormalizedConfig;
60
+ }>;
56
61
  validateSchema: ParallelWorkflow<void>;
57
62
  prepare: AsyncWorkflow<void, void>;
58
63
  commands: AsyncWorkflow<
@@ -73,6 +78,9 @@ export type HooksRunner = Progresses2Runners<{
73
78
 
74
79
  const hooksMap = {
75
80
  config: createParallelWorkflow(),
81
+ resolvedConfig: createAsyncWaterfall<{
82
+ resolved: NormalizedConfig;
83
+ }>(),
76
84
  validateSchema: createParallelWorkflow(),
77
85
  // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
78
86
  prepare: createAsyncWorkflow<void, void>(),
@@ -111,9 +119,11 @@ export const usePlugins = (plugins: string[]) =>
111
119
  export {
112
120
  defineConfig,
113
121
  AppContext,
122
+ ResolvedConfigContext,
114
123
  useAppContext,
115
124
  useConfigContext,
116
125
  useResolvedConfigContext,
126
+ ConfigContext,
117
127
  };
118
128
 
119
129
  export type { NormalizedConfig, IAppContext, UserConfig, ToolsConfig };
@@ -131,9 +141,12 @@ const initAppDir = async (): Promise<string> => {
131
141
  };
132
142
 
133
143
  export interface CoreOptions {
134
- name?: string;
144
+ configFile?: string;
135
145
  plugins?: typeof INTERNAL_PLUGINS;
136
- beforeUsePlugins: (plugins: any, config: any) => { cli: any; server: any }[];
146
+ beforeUsePlugins: (
147
+ plugins: any,
148
+ config: any,
149
+ ) => { cli: any; cliPath: any; server: any; serverPath: any }[];
137
150
  }
138
151
 
139
152
  const createCli = () => {
@@ -149,9 +162,13 @@ const createCli = () => {
149
162
 
150
163
  loadEnv(appDirectory);
151
164
 
152
- const loaded = await loadUserConfig(appDirectory);
165
+ const loaded = await loadUserConfig(appDirectory, options?.configFile);
153
166
 
154
- let plugins = loadPlugins(appDirectory, loaded.config.plugins || []);
167
+ let plugins = loadPlugins(
168
+ appDirectory,
169
+ loaded.config.plugins || [],
170
+ options?.plugins,
171
+ );
155
172
 
156
173
  if (options?.beforeUsePlugins) {
157
174
  plugins = options.beforeUsePlugins(plugins, loaded.config);
@@ -187,7 +204,7 @@ const createCli = () => {
187
204
 
188
205
  const extraSchemas = await hooksRunner.validateSchema();
189
206
 
190
- const resolved = await resolveConfig(
207
+ const config = await resolveConfig(
191
208
  loaded,
192
209
  extraConfigs as any,
193
210
  extraSchemas as any,
@@ -195,6 +212,10 @@ const createCli = () => {
195
212
  argv,
196
213
  );
197
214
 
215
+ const { resolved } = await hooksRunner.resolvedConfig({
216
+ resolved: config,
217
+ });
218
+
198
219
  // update context value
199
220
  manager.run(() => {
200
221
  ConfigContext.set(loaded.config);
@@ -252,3 +273,5 @@ const createCli = () => {
252
273
  };
253
274
 
254
275
  export const cli = createCli();
276
+
277
+ export { loadUserConfig, initAppDir, initAppContext };
@@ -75,9 +75,17 @@ export const loadPlugins = (
75
75
  server,
76
76
  });
77
77
 
78
+ const cliPlugin = cli && { ...compatRequire(cli), pluginPath: cli };
79
+ const serverPlugin = server && {
80
+ ...compatRequire(server),
81
+ pluginPath: server,
82
+ };
83
+
78
84
  return {
79
- cli: cli && compatRequire(cli),
80
- server: server && compatRequire(server),
85
+ cli: cliPlugin,
86
+ cliPath: typeof plugin === 'string' ? plugin : plugin.cli,
87
+ server: serverPlugin,
88
+ serverPath: typeof plugin === 'string' ? undefined : plugin.server,
81
89
  };
82
90
  });
83
91
  };
@@ -14,8 +14,20 @@ describe('load plugins', () => {
14
14
  ]);
15
15
 
16
16
  expect(plugins).toEqual([
17
- { cli: { name: 'a' } },
18
- { server: { name: 'b' } },
17
+ {
18
+ cli: {
19
+ name: 'a',
20
+ pluginPath: path.join(fixture, './test-plugin-a.js'),
21
+ },
22
+ cliPath: path.join(fixture, './test-plugin-a.js'),
23
+ },
24
+ {
25
+ server: {
26
+ name: 'b',
27
+ pluginPath: path.join(fixture, './test-plugin-b.js'),
28
+ },
29
+ serverPath: './test-plugin-b',
30
+ },
19
31
  ]);
20
32
  });
21
33