@modern-js/core 2.0.0-beta.0 → 2.0.0-beta.2

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 (76) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/dist/bin.js +1 -4
  3. package/dist/config/createLoadedConfig.d.ts +6 -0
  4. package/dist/config/createLoadedConfig.js +35 -0
  5. package/dist/config/createResolvedConfig.d.ts +3 -0
  6. package/dist/config/createResolvedConfig.js +92 -0
  7. package/dist/config/index.d.ts +2 -17
  8. package/dist/config/index.js +2 -136
  9. package/dist/context.d.ts +5 -9
  10. package/dist/index.d.ts +12 -14
  11. package/dist/index.js +30 -58
  12. package/dist/loadPlugins.d.ts +2 -12
  13. package/dist/loadPlugins.js +12 -5
  14. package/dist/manager.d.ts +80 -64
  15. package/dist/manager.js +11 -5
  16. package/dist/schema/patchSchema.d.ts +19 -0
  17. package/dist/{config/schema/index.js → schema/patchSchema.js} +8 -45
  18. package/dist/schema/source.d.ts +9 -0
  19. package/dist/schema/source.js +10 -0
  20. package/dist/schema/testing.d.ts +13 -0
  21. package/dist/schema/testing.js +11 -0
  22. package/dist/schema/traverseSchema.d.ts +2 -0
  23. package/dist/schema/traverseSchema.js +20 -0
  24. package/dist/types/config/index.d.ts +41 -0
  25. package/dist/{config/types → types/config}/index.js +0 -0
  26. package/dist/types/config/testing.d.ts +15 -0
  27. package/dist/{config/types/electron.js → types/config/testing.js} +0 -0
  28. package/dist/types/context.d.ts +26 -0
  29. package/dist/{config/types/less.js → types/context.js} +0 -0
  30. package/dist/types/hooks.d.ts +26 -0
  31. package/dist/{config/types/postcss.js → types/hooks.js} +0 -0
  32. package/dist/types/index.d.ts +10 -1
  33. package/dist/types/index.js +5 -1
  34. package/dist/types/plugin.d.ts +26 -0
  35. package/dist/{config/types/sass.js → types/plugin.js} +0 -0
  36. package/dist/types/pluginAPI.d.ts +18 -0
  37. package/dist/{config/types/ssg.js → types/pluginAPI.js} +0 -0
  38. package/dist/utils/mergeConfig.d.ts +2 -0
  39. package/dist/{config → utils}/mergeConfig.js +1 -8
  40. package/dist/utils/repeatKeyWarning.d.ts +2 -2
  41. package/dist/utils/repeatKeyWarning.js +2 -2
  42. package/package.json +17 -10
  43. package/compiled/v8-compile-cache/index.d.ts +0 -1
  44. package/compiled/v8-compile-cache/index.js +0 -1
  45. package/compiled/v8-compile-cache/license +0 -21
  46. package/compiled/v8-compile-cache/package.json +0 -1
  47. package/dist/config/defaults.d.ts +0 -29
  48. package/dist/config/defaults.js +0 -110
  49. package/dist/config/mergeConfig.d.ts +0 -32
  50. package/dist/config/schema/deploy.d.ts +0 -16
  51. package/dist/config/schema/deploy.js +0 -16
  52. package/dist/config/schema/index.d.ts +0 -499
  53. package/dist/config/schema/output.d.ts +0 -146
  54. package/dist/config/schema/output.js +0 -68
  55. package/dist/config/schema/server.d.ts +0 -194
  56. package/dist/config/schema/server.js +0 -111
  57. package/dist/config/schema/source.d.ts +0 -64
  58. package/dist/config/schema/source.js +0 -38
  59. package/dist/config/schema/tools.d.ts +0 -51
  60. package/dist/config/schema/tools.js +0 -24
  61. package/dist/config/types/electron.d.ts +0 -13
  62. package/dist/config/types/index.d.ts +0 -260
  63. package/dist/config/types/less.d.ts +0 -12
  64. package/dist/config/types/postcss.d.ts +0 -28
  65. package/dist/config/types/sass.d.ts +0 -10
  66. package/dist/config/types/ssg.d.ts +0 -15
  67. package/dist/config/types/test.d.ts +0 -14
  68. package/dist/config/types/test.js +0 -2
  69. package/dist/config/types/ts-loader.d.ts +0 -23
  70. package/dist/config/types/ts-loader.js +0 -2
  71. package/dist/initWatcher.d.ts +0 -3
  72. package/dist/initWatcher.js +0 -66
  73. package/dist/pluginAPI.d.ts +0 -13
  74. package/dist/pluginAPI.js +0 -16
  75. package/dist/types/cli.d.ts +0 -59
  76. package/dist/types/cli.js +0 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,133 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 2.0.0-beta.2
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Minor Changes
10
+
11
+ - c9e800d39a: feat: support React18 streaming SSR
12
+ feat: 支持 React18 流式 SSR
13
+ - 92f0ead: feat:
14
+
15
+ 1. core: 增加 test 函数
16
+ 2. module plugins: 增加 `babel`, `mainField`, `target` 插件
17
+ 3. storybook: 修改部分逻辑并且增加 tspath webpack 插件
18
+ 4. 增加 designSystem 配置
19
+
20
+ feat:
21
+
22
+ 1. core: add test method
23
+ 2. module plugins: add `babel`, `mainField`, `target` plugin
24
+ 3. storybook: change some logic and add tspath webpack plugin
25
+ 4. add `designSystem` config
26
+
27
+ - edd1cfb1af: feat: modernjs Access builder compiler
28
+ feat: modernjs 接入 builder 构建
29
+ - d5a31df781: refactor: remove unbundle configs and types
30
+
31
+ refactor: 移除 unbundle 相关的配置项和类型定义
32
+
33
+ ### Patch Changes
34
+
35
+ - 85edee888c: feat(app-tools): support tools.htmlPlugin config
36
+
37
+ feat(app-tools): 支持 tools.htmlPlugin 配置项
38
+
39
+ - b8bbe036c7: feat: change type logic
40
+ feat: 修改类型相关的逻辑
41
+ - 8b8e1bb571: feat: support nested routes
42
+ feat: 支持嵌套路由
43
+ - 3bbea92b2a: feat: support Hook、Middleware new API
44
+ feat: 支持 Hook、Middleware 的新 API
45
+ - 14b712da84: fix: use consistent alias type and default value across packages
46
+
47
+ fix: 在各个包中使用一致的 alias 类型定义和默认值
48
+
49
+ - Updated dependencies [a2509bfbdb]
50
+ - Updated dependencies [92f0ead]
51
+ - Updated dependencies [edd1cfb1af]
52
+ - Updated dependencies [cc971eabfc]
53
+ - Updated dependencies [5b9049f2e9]
54
+ - Updated dependencies [92004d1]
55
+ - Updated dependencies [b8bbe036c7]
56
+ - Updated dependencies [d5a31df781]
57
+ - Updated dependencies [dda38c9c3e]
58
+ - Updated dependencies [3bbea92b2a]
59
+ - Updated dependencies [f179749]
60
+ - Updated dependencies [abf3421a75]
61
+ - Updated dependencies [543be9558e]
62
+ - Updated dependencies [14b712da84]
63
+ - @modern-js/node-bundle-require@2.0.0-beta.2
64
+ - @modern-js/utils@2.0.0-beta.2
65
+ - @modern-js/plugin@2.0.0-beta.2
66
+
67
+ ## 2.0.0-beta.1
68
+
69
+ ### Major Changes
70
+
71
+ - dda38c9: chore: v2
72
+
73
+ ### Minor Changes
74
+
75
+ - c9e800d39a: feat: support React18 streaming SSR
76
+ feat: 支持 React18 流式 SSR
77
+ - 92f0ead: feat:
78
+
79
+ 1. core: 增加 test 函数
80
+ 2. module plugins: 增加 `babel`, `mainField`, `target` 插件
81
+ 3. storybook: 修改部分逻辑并且增加 tspath webpack 插件
82
+ 4. 增加 designSystem 配置
83
+
84
+ feat:
85
+
86
+ 1. core: add test method
87
+ 2. module plugins: add `babel`, `mainField`, `target` plugin
88
+ 3. storybook: change some logic and add tspath webpack plugin
89
+ 4. add `designSystem` config
90
+
91
+ - edd1cfb1af: feat: modernjs Access builder compiler
92
+ feat: modernjs 接入 builder 构建
93
+ - d5a31df781: refactor: remove unbundle configs and types
94
+
95
+ refactor: 移除 unbundle 相关的配置项和类型定义
96
+
97
+ ### Patch Changes
98
+
99
+ - 85edee888c: feat(app-tools): support tools.htmlPlugin config
100
+
101
+ feat(app-tools): 支持 tools.htmlPlugin 配置项
102
+
103
+ - b8bbe036c7: feat: change type logic
104
+ feat: 修改类型相关的逻辑
105
+ - 8b8e1bb571: feat: support nested routes
106
+ feat: 支持嵌套路由
107
+ - 3bbea92b2a: feat: support Hook、Middleware new API
108
+ feat: 支持 Hook、Middleware 的新 API
109
+ - 14b712d: fix: use consistent alias type and default value across packages
110
+
111
+ fix: 在各个包中使用一致的 alias 类型定义和默认值
112
+
113
+ - Updated dependencies [a2509bfbdb]
114
+ - Updated dependencies [92f0ead]
115
+ - Updated dependencies [edd1cfb1af]
116
+ - Updated dependencies [cc971eabfc]
117
+ - Updated dependencies [5b9049f]
118
+ - Updated dependencies [92004d1]
119
+ - Updated dependencies [b8bbe036c7]
120
+ - Updated dependencies [d5a31df781]
121
+ - Updated dependencies [dda38c9]
122
+ - Updated dependencies [3bbea92b2a]
123
+ - Updated dependencies [f179749]
124
+ - Updated dependencies [abf3421]
125
+ - Updated dependencies [543be9558e]
126
+ - Updated dependencies [14b712d]
127
+ - @modern-js/node-bundle-require@2.0.0-beta.1
128
+ - @modern-js/utils@2.0.0-beta.1
129
+ - @modern-js/plugin@2.0.0-beta.1
130
+
3
131
  ## 2.0.0-beta.0
4
132
 
5
133
  ### Major Changes
package/dist/bin.js CHANGED
@@ -1,9 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- /* eslint-disable-next-line eslint-comments/disable-enable-pair */
4
- /* eslint-disable import/first */
5
3
  Object.defineProperty(exports, "__esModule", { value: true });
6
- require('../compiled/v8-compile-cache');
7
4
  const utils_1 = require("@modern-js/utils");
8
5
  const _1 = require(".");
9
6
  const command = process.argv[2];
@@ -38,4 +35,4 @@ const customConfigFile = cliParams.config || cliParams.c;
38
35
  if (SUPPORT_CONFIG_PARAM_COMMANDS.includes(command) && customConfigFile) {
39
36
  runOptions.configFile = customConfigFile;
40
37
  }
41
- _1.cli.run(process.argv.slice(2), runOptions);
38
+ _1.cli.run(runOptions);
@@ -0,0 +1,6 @@
1
+ import { LoadedConfig, UserConfig, ConfigParams } from '../types';
2
+ /**
3
+ * Assign the pkg config into the user config.
4
+ */
5
+ export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?: ConfigParams) => UserConfig;
6
+ export declare function createLoadedConfig(appDirectory: string, filePath?: string, packageJsonConfig?: string): Promise<LoadedConfig<{}>>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLoadedConfig = exports.assignPkgConfig = void 0;
4
+ const lodash_1 = require("@modern-js/utils/lodash");
5
+ const utils_1 = require("@modern-js/utils");
6
+ const load_configs_1 = require("../load-configs");
7
+ /**
8
+ * Assign the pkg config into the user config.
9
+ */
10
+ const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0, lodash_1.mergeWith)({}, userConfig, pkgConfig, (objValue, srcValue) => {
11
+ // mergeWith can not merge object with symbol, but plugins object contains symbol,
12
+ // so we need to handle it manually.
13
+ if (objValue === undefined && (0, utils_1.isPlainObject)(srcValue)) {
14
+ return { ...srcValue };
15
+ }
16
+ // return undefined to use the default behavior of mergeWith
17
+ return undefined;
18
+ });
19
+ exports.assignPkgConfig = assignPkgConfig;
20
+ async function createLoadedConfig(appDirectory, filePath, packageJsonConfig) {
21
+ const loaded = await (0, load_configs_1.loadConfig)(appDirectory, filePath, packageJsonConfig);
22
+ const config = !loaded
23
+ ? {}
24
+ : await (typeof loaded.config === 'function'
25
+ ? loaded.config(0)
26
+ : loaded.config);
27
+ return {
28
+ config: (0, exports.assignPkgConfig)(config, loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig),
29
+ filePath: loaded.path,
30
+ dependencies: loaded.dependencies || [],
31
+ pkgConfig: loaded.pkgConfig || {},
32
+ jsConfig: config || {},
33
+ };
34
+ }
35
+ exports.createLoadedConfig = createLoadedConfig;
@@ -0,0 +1,3 @@
1
+ import type { ErrorObject } from '@modern-js/utils/ajv';
2
+ import type { UserConfig, NormalizedConfig, LoadedConfig, PluginValidateSchema } from '../types';
3
+ export declare const createResolveConfig: (loaded: LoadedConfig<{}>, configs: UserConfig[], schemas: PluginValidateSchema[], onSchemaError?: (error: ErrorObject) => void | Promise<void>) => Promise<NormalizedConfig>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.createResolveConfig = void 0;
27
+ const utils_1 = require("@modern-js/utils");
28
+ const constants_1 = require("@modern-js/utils/constants");
29
+ const patchSchema_1 = require("../schema/patchSchema");
30
+ const repeatKeyWarning_1 = require("../utils/repeatKeyWarning");
31
+ const mergeConfig_1 = require("../utils/mergeConfig");
32
+ const debug = (0, utils_1.createDebugger)('resolve-config');
33
+ const showAdditionalPropertiesError = async (error) => {
34
+ if (error.keyword === 'additionalProperties' &&
35
+ error.params.additionalProperty) {
36
+ const target = [
37
+ error.instancePath.slice(1),
38
+ error.params.additionalProperty,
39
+ ]
40
+ .filter(Boolean)
41
+ .join('.');
42
+ const name = Object.keys(constants_1.PLUGIN_SCHEMAS).find(key => constants_1.PLUGIN_SCHEMAS[key].some((schemaItem) => schemaItem.target === target));
43
+ if (name) {
44
+ const packageManager = await (0, utils_1.getPackageManager)();
45
+ utils_1.logger.warn(`The configuration of ${utils_1.chalk.bold(target)} is provided by plugin ${utils_1.chalk.bold(name)}. Please use ${utils_1.chalk.bold(`${packageManager} run new`)} to enable the corresponding capability.\n`);
46
+ }
47
+ }
48
+ };
49
+ const createResolveConfig = async (
50
+ // eslint-disable-next-line @typescript-eslint/ban-types
51
+ loaded, configs, schemas, onSchemaError = showAdditionalPropertiesError) => {
52
+ var _a;
53
+ const { default: Ajv } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/ajv')));
54
+ const { default: ajvKeywords } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/ajv-keywords')));
55
+ const { default: betterAjvErrors } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/better-ajv-errors')));
56
+ const { config: userConfig, jsConfig, pkgConfig } = loaded;
57
+ const ajv = new Ajv({ $data: true, strict: false });
58
+ ajvKeywords(ajv);
59
+ const validateSchema = (0, patchSchema_1.patchSchema)(schemas);
60
+ const validate = ajv.compile(validateSchema);
61
+ (0, repeatKeyWarning_1.repeatKeyWarning)(validateSchema, jsConfig, pkgConfig);
62
+ // validate user config.
63
+ const valid = validate(userConfig);
64
+ const formatValidateError = (config) => {
65
+ var _a;
66
+ return betterAjvErrors(validateSchema, config, (_a = validate.errors) === null || _a === void 0 ? void 0 : _a.map(e => ({
67
+ ...e,
68
+ dataPath: e.instancePath,
69
+ })), {
70
+ indent: 2,
71
+ });
72
+ };
73
+ // FIXME: pass temporarily
74
+ if (!valid && ((_a = validate.errors) === null || _a === void 0 ? void 0 : _a.length)) {
75
+ await onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
76
+ const errors = formatValidateError(userConfig);
77
+ utils_1.logger.log(errors);
78
+ throw new Error(`Validate configuration error`);
79
+ }
80
+ // validate config from plugins.
81
+ for (const config of configs) {
82
+ if (!validate(config)) {
83
+ const errors = formatValidateError(config);
84
+ utils_1.logger.error(errors);
85
+ throw new Error(`Validate configuration error.`);
86
+ }
87
+ }
88
+ const resolved = (0, mergeConfig_1.mergeConfig)([...configs, userConfig]);
89
+ debug('resolved %o', resolved);
90
+ return resolved;
91
+ };
92
+ exports.createResolveConfig = createResolveConfig;
@@ -1,17 +1,2 @@
1
- import type { ErrorObject } from '@modern-js/utils/ajv';
2
- import { getDefaultConfig } from './defaults';
3
- import { NormalizedConfig } from './mergeConfig';
4
- import { PluginValidateSchema } from './schema';
5
- import type { UserConfig, ConfigParam, LoadedConfig } from './types';
6
- export { getDefaultConfig };
7
- export * from './mergeConfig';
8
- export * from './types';
9
- export * from './schema';
10
- export declare const addServerConfigToDeps: (dependencies: string[], appDirectory: string, serverConfigFile: string) => Promise<void>;
11
- export declare const defineConfig: (config: ConfigParam) => ConfigParam;
12
- /**
13
- * Assign the pkg config into the user config.
14
- */
15
- export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?: ConfigParam) => UserConfig & ConfigParam;
16
- export declare const loadUserConfig: (appDirectory: string, filePath?: string, packageJsonConfig?: string) => Promise<LoadedConfig>;
17
- export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void | Promise<void>) => Promise<NormalizedConfig>;
1
+ export * from './createLoadedConfig';
2
+ export * from './createResolvedConfig';
@@ -10,143 +10,9 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
15
  };
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
28
16
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.resolveConfig = exports.loadUserConfig = exports.assignPkgConfig = exports.defineConfig = exports.addServerConfigToDeps = exports.getDefaultConfig = void 0;
30
- const utils_1 = require("@modern-js/utils");
31
- const lodash_1 = require("@modern-js/utils/lodash");
32
- const context_1 = require("../context");
33
- const load_configs_1 = require("../load-configs");
34
- const repeatKeyWarning_1 = require("../utils/repeatKeyWarning");
35
- const defaults_1 = require("./defaults");
36
- Object.defineProperty(exports, "getDefaultConfig", { enumerable: true, get: function () { return defaults_1.getDefaultConfig; } });
37
- const mergeConfig_1 = require("./mergeConfig");
38
- const schema_1 = require("./schema");
39
- const debug = (0, utils_1.createDebugger)('resolve-config');
40
- __exportStar(require("./mergeConfig"), exports);
41
- __exportStar(require("./types"), exports);
42
- __exportStar(require("./schema"), exports);
43
- const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
44
- const serverConfig = await (0, utils_1.getServerConfig)(appDirectory, serverConfigFile);
45
- if (serverConfig) {
46
- dependencies.push(serverConfig);
47
- }
48
- };
49
- exports.addServerConfigToDeps = addServerConfigToDeps;
50
- const defineConfig = (config) => config;
51
- exports.defineConfig = defineConfig;
52
- /**
53
- * Assign the pkg config into the user config.
54
- */
55
- const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0, lodash_1.mergeWith)({}, userConfig, pkgConfig, (objValue, srcValue) => {
56
- // mergeWith can not merge object with symbol, but plugins object contains symbol,
57
- // so we need to handle it manually.
58
- if (objValue === undefined && (0, utils_1.isPlainObject)(srcValue)) {
59
- return { ...srcValue };
60
- }
61
- // return undefined to use the default behavior of mergeWith
62
- return undefined;
63
- });
64
- exports.assignPkgConfig = assignPkgConfig;
65
- const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
66
- const loaded = await (0, load_configs_1.loadConfig)(appDirectory, filePath, packageJsonConfig);
67
- const config = !loaded
68
- ? {}
69
- : await (typeof loaded.config === 'function'
70
- ? loaded.config(0)
71
- : loaded.config);
72
- return {
73
- config: (0, exports.assignPkgConfig)(config, loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig),
74
- jsConfig: config || {},
75
- pkgConfig: ((loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
76
- filePath: loaded === null || loaded === void 0 ? void 0 : loaded.path,
77
- dependencies: (loaded === null || loaded === void 0 ? void 0 : loaded.dependencies) || [],
78
- };
79
- };
80
- exports.loadUserConfig = loadUserConfig;
81
- const showAdditionalPropertiesError = async (error) => {
82
- if (error.keyword === 'additionalProperties' &&
83
- error.params.additionalProperty) {
84
- const target = [
85
- error.instancePath.slice(1),
86
- error.params.additionalProperty,
87
- ]
88
- .filter(Boolean)
89
- .join('.');
90
- const name = Object.keys(utils_1.PLUGIN_SCHEMAS).find(key => utils_1.PLUGIN_SCHEMAS[key].some((schemaItem) => schemaItem.target === target));
91
- if (name) {
92
- const packageManager = await (0, utils_1.getPackageManager)();
93
- utils_1.logger.warn(`The configuration of ${utils_1.chalk.bold(target)} is provided by plugin ${utils_1.chalk.bold(name)}. Please use ${utils_1.chalk.bold(`${packageManager} run new`)} to enable the corresponding capability.\n`);
94
- }
95
- }
96
- };
97
- const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv, onSchemaError = showAdditionalPropertiesError) => {
98
- var _a;
99
- const { default: Ajv } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/ajv')));
100
- const { default: ajvKeywords } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/ajv-keywords')));
101
- const { default: betterAjvErrors } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/better-ajv-errors')));
102
- const { config: userConfig, jsConfig, pkgConfig } = loaded;
103
- const ajv = new Ajv({ $data: true, strict: false });
104
- ajvKeywords(ajv);
105
- const validateSchema = (0, schema_1.patchSchema)(schemas);
106
- const validate = ajv.compile(validateSchema);
107
- (0, repeatKeyWarning_1.repeatKeyWarning)(validateSchema, jsConfig, pkgConfig);
108
- // validate user config.
109
- const valid = validate(userConfig);
110
- const formatValidateError = (config) => {
111
- var _a;
112
- return betterAjvErrors(validateSchema, config, (_a = validate.errors) === null || _a === void 0 ? void 0 : _a.map(e => ({
113
- ...e,
114
- dataPath: e.instancePath,
115
- })), {
116
- indent: 2,
117
- });
118
- };
119
- if (!valid && ((_a = validate.errors) === null || _a === void 0 ? void 0 : _a.length)) {
120
- await onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
121
- const errors = formatValidateError(userConfig);
122
- utils_1.logger.log(errors);
123
- throw new Error(`Validate configuration error`);
124
- }
125
- // validate config from plugins.
126
- for (const config of configs) {
127
- if (!validate(config)) {
128
- const errors = formatValidateError(config);
129
- utils_1.logger.error(errors);
130
- throw new Error(`Validate configuration error.`);
131
- }
132
- }
133
- const resolved = (0, mergeConfig_1.mergeConfig)([
134
- (0, defaults_1.getDefaultConfig)(context_1.AppContext.use().value),
135
- ...configs,
136
- userConfig,
137
- ]);
138
- resolved._raw = loaded.config;
139
- if ((0, utils_1.isDev)() && argv[0] === 'dev') {
140
- if (restartWithExistingPort > 0) {
141
- // dev server is restarted, should use existing port number
142
- resolved.server.port = restartWithExistingPort;
143
- }
144
- else {
145
- // get port for new dev server
146
- resolved.server.port = await (0, utils_1.getPort)(resolved.server.port);
147
- }
148
- }
149
- debug('resolved %o', resolved);
150
- return resolved;
151
- };
152
- exports.resolveConfig = resolveConfig;
17
+ __exportStar(require("./createLoadedConfig"), exports);
18
+ __exportStar(require("./createResolvedConfig"), exports);
package/dist/context.d.ts CHANGED
@@ -1,11 +1,7 @@
1
- import type { IAppContext, InternalPlugins } from '@modern-js/types';
2
- import { UserConfig } from './config';
3
- import { NormalizedConfig } from './config/mergeConfig';
4
- import { CliPlugin } from './manager';
5
- export type { IAppContext };
1
+ import type { CliPlugin, UserConfig, IAppContext, InternalPlugins, NormalizedConfig } from './types';
6
2
  export declare const AppContext: import("@modern-js/plugin").Context<IAppContext>;
7
- export declare const ConfigContext: import("@modern-js/plugin").Context<UserConfig>;
8
- export declare const ResolvedConfigContext: import("@modern-js/plugin").Context<NormalizedConfig>;
3
+ export declare const ConfigContext: import("@modern-js/plugin").Context<UserConfig<any, {}, {}, {}>>;
4
+ export declare const ResolvedConfigContext: import("@modern-js/plugin").Context<NormalizedConfig<any, {}, {}, {}>>;
9
5
  /**
10
6
  * Set app context.
11
7
  * @param value new app context. It will override previous app context.
@@ -18,11 +14,11 @@ export declare const useAppContext: () => IAppContext;
18
14
  /**
19
15
  * Get original content of user config.
20
16
  */
21
- export declare const useConfigContext: () => UserConfig;
17
+ export declare const useConfigContext: <Extends extends Record<string, any>>() => UserConfig<Extends>;
22
18
  /**
23
19
  * Get normalized content of user config.
24
20
  */
25
- export declare const useResolvedConfigContext: () => NormalizedConfig;
21
+ export declare const useResolvedConfigContext: <Extends extends Record<string, any>>() => NormalizedConfig<Extends>;
26
22
  export declare const initAppContext: ({ appDirectory, plugins, configFile, options, serverConfigFile, serverInternalPlugins, }: {
27
23
  appDirectory: string;
28
24
  plugins: CliPlugin[];
package/dist/index.d.ts CHANGED
@@ -1,17 +1,14 @@
1
1
  import type { ErrorObject } from '@modern-js/utils/ajv';
2
2
  import { InternalPlugins } from '@modern-js/types';
3
3
  import { TransformPlugin } from './loadPlugins';
4
- import { IAppContext, initAppContext } from './context';
5
- export * from './config';
6
- export type { Hooks, ImportSpecifier, ImportStatement, RuntimePlugin, } from './types';
4
+ import { initAppContext } from './context';
5
+ export * from './types';
7
6
  export * from '@modern-js/plugin';
8
7
  export { manager, mountHook, createPlugin, registerHook } from './manager';
9
- export type { CliHooks, CliPlugin, CliHookCallbacks } from './manager';
10
- export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, } from './pluginAPI';
11
- export type { PluginAPI } from './pluginAPI';
12
- export type { IAppContext };
8
+ export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, } from './context';
13
9
  declare const initAppDir: (cwd?: string) => Promise<string>;
14
10
  export interface CoreOptions {
11
+ cwd?: string;
15
12
  version?: string;
16
13
  configFile?: string;
17
14
  serverConfigFile?: string;
@@ -30,6 +27,7 @@ export interface CoreOptions {
30
27
  };
31
28
  }
32
29
  export declare const mergeOptions: (options?: CoreOptions) => {
30
+ cwd?: string | undefined;
33
31
  version?: string | undefined;
34
32
  configFile?: string | undefined;
35
33
  serverConfigFile: string;
@@ -48,13 +46,13 @@ export declare const mergeOptions: (options?: CoreOptions) => {
48
46
  } | undefined;
49
47
  };
50
48
  export declare const cli: {
51
- init: (argv?: string[], options?: CoreOptions) => Promise<{
52
- loadedConfig: import("./config").LoadedConfig;
53
- appContext: IAppContext;
54
- resolved: import("./config").NormalizedConfig;
55
- }>;
56
- run: (argv: string[], options?: CoreOptions) => Promise<void>;
57
- restart: () => Promise<void>;
49
+ init: (options?: CoreOptions) => Promise<void>;
50
+ run: (options?: CoreOptions) => Promise<void>;
51
+ test: (argv: string[], options?: {
52
+ coreOptions?: CoreOptions;
53
+ disableWatcher?: boolean;
54
+ }) => Promise<void>;
55
+ initOptions: CoreOptions | undefined;
58
56
  };
59
57
  export { initAppDir, initAppContext };
60
58
  declare module '@modern-js/utils/compiled/commander' {