@modern-js/core 1.1.2 → 1.1.3

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,25 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 1.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 085a6a58: refactor server plugin
8
+ - 085a6a58: refactor server plugin
9
+ - 085a6a58: refactor server conifg
10
+ - d4fcc73a: add options.plugins:
11
+ - 085a6a58: support server runtime
12
+ - ed1f6b12: feat: support build --analyze
13
+ - a5ebbb00: fix: remove enableUsageBuiltIns config
14
+ - 085a6a58: feat: refactor server plugin
15
+ - Updated dependencies [085a6a58]
16
+ - Updated dependencies [085a6a58]
17
+ - Updated dependencies [085a6a58]
18
+ - Updated dependencies [d280ea33]
19
+ - Updated dependencies [085a6a58]
20
+ - Updated dependencies [085a6a58]
21
+ - @modern-js/utils@1.1.3
22
+
3
23
  ## 1.1.2
4
24
 
5
25
  ### Patch Changes
@@ -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
  },
@@ -6,7 +6,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
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 };
@@ -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
  },
@@ -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,
@@ -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);
@@ -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
  };
@@ -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
  };
@@ -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,10 +88,11 @@ 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;
@@ -91,4 +107,5 @@ export declare const cli: {
91
107
  }>;
92
108
  run: (argv: string[], options?: CoreOptions | undefined) => Promise<void>;
93
109
  restart: () => Promise<void>;
94
- };
110
+ };
111
+ export { loadUserConfig, initAppDir, initAppContext };
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.3",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -40,7 +40,7 @@
40
40
  "@babel/runtime": "^7",
41
41
  "@modern-js/load-config": "^1.1.1",
42
42
  "@modern-js/plugin": "^1.1.2",
43
- "@modern-js/utils": "^1.1.2",
43
+ "@modern-js/utils": "^1.1.3",
44
44
  "address": "^1.1.2",
45
45
  "ajv": "^8.6.2",
46
46
  "ajv-keywords": "^5.0.0",
@@ -66,8 +66,8 @@
66
66
  "@types/react-dom": "^17",
67
67
  "@types/signale": "^1.4.2",
68
68
  "typescript": "^4",
69
- "@modern-js/plugin-testing": "^1.1.0",
70
- "@modern-js/module-tools": "^1.1.0"
69
+ "@modern-js/plugin-testing": "^1.1.1",
70
+ "@modern-js/module-tools": "^1.1.1"
71
71
  },
72
72
  "sideEffects": false,
73
73
  "modernConfig": {
@@ -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' },
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,7 +141,7 @@ 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
146
  beforeUsePlugins: (plugins: any, config: any) => { cli: any; server: any }[];
137
147
  }
@@ -149,9 +159,13 @@ const createCli = () => {
149
159
 
150
160
  loadEnv(appDirectory);
151
161
 
152
- const loaded = await loadUserConfig(appDirectory);
162
+ const loaded = await loadUserConfig(appDirectory, options?.configFile);
153
163
 
154
- let plugins = loadPlugins(appDirectory, loaded.config.plugins || []);
164
+ let plugins = loadPlugins(
165
+ appDirectory,
166
+ loaded.config.plugins || [],
167
+ options?.plugins,
168
+ );
155
169
 
156
170
  if (options?.beforeUsePlugins) {
157
171
  plugins = options.beforeUsePlugins(plugins, loaded.config);
@@ -187,7 +201,7 @@ const createCli = () => {
187
201
 
188
202
  const extraSchemas = await hooksRunner.validateSchema();
189
203
 
190
- const resolved = await resolveConfig(
204
+ const config = await resolveConfig(
191
205
  loaded,
192
206
  extraConfigs as any,
193
207
  extraSchemas as any,
@@ -195,6 +209,10 @@ const createCli = () => {
195
209
  argv,
196
210
  );
197
211
 
212
+ const { resolved } = await hooksRunner.resolvedConfig({
213
+ resolved: config,
214
+ });
215
+
198
216
  // update context value
199
217
  manager.run(() => {
200
218
  ConfigContext.set(loaded.config);
@@ -252,3 +270,5 @@ const createCli = () => {
252
270
  };
253
271
 
254
272
  export const cli = createCli();
273
+
274
+ export { loadUserConfig, initAppDir, initAppContext };