@modern-js/core 1.7.1-beta.peer.1 → 1.9.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 (196) hide show
  1. package/.eslintrc.js +1 -0
  2. package/CHANGELOG.md +47 -0
  3. package/bin/modern-js.js +1 -1
  4. package/compiled/ajv/codegen.js +1 -0
  5. package/compiled/ajv/dist/ajv.d.ts +16 -0
  6. package/compiled/ajv/dist/compile/codegen/code.d.ts +40 -0
  7. package/compiled/ajv/dist/compile/codegen/index.d.ts +79 -0
  8. package/compiled/ajv/dist/compile/codegen/scope.d.ts +79 -0
  9. package/compiled/ajv/dist/compile/errors.d.ts +13 -0
  10. package/compiled/ajv/dist/compile/index.d.ts +80 -0
  11. package/compiled/ajv/dist/compile/ref_error.d.ts +6 -0
  12. package/compiled/ajv/dist/compile/resolve.d.ts +12 -0
  13. package/compiled/ajv/dist/compile/rules.d.ts +28 -0
  14. package/compiled/ajv/dist/compile/util.d.ts +40 -0
  15. package/compiled/ajv/dist/compile/validate/index.d.ts +42 -0
  16. package/compiled/ajv/dist/compile/validate/subschema.d.ts +47 -0
  17. package/compiled/ajv/dist/core.d.ts +173 -0
  18. package/compiled/ajv/dist/runtime/validation_error.d.ts +7 -0
  19. package/compiled/ajv/dist/types/index.d.ts +183 -0
  20. package/compiled/ajv/dist/types/json-schema.d.ts +124 -0
  21. package/compiled/ajv/dist/types/jtd-schema.d.ts +169 -0
  22. package/compiled/ajv/index.js +9 -0
  23. package/compiled/ajv/license +22 -0
  24. package/compiled/ajv/package.json +1 -0
  25. package/compiled/ajv/uri-js/dist/es5/uri.all.d.ts +59 -0
  26. package/compiled/ajv-keywords/ajv/dist/ajv.d.ts +16 -0
  27. package/compiled/ajv-keywords/ajv/dist/compile/codegen/code.d.ts +40 -0
  28. package/compiled/ajv-keywords/ajv/dist/compile/codegen/index.d.ts +79 -0
  29. package/compiled/ajv-keywords/ajv/dist/compile/codegen/scope.d.ts +79 -0
  30. package/compiled/ajv-keywords/ajv/dist/compile/errors.d.ts +13 -0
  31. package/compiled/ajv-keywords/ajv/dist/compile/index.d.ts +80 -0
  32. package/compiled/ajv-keywords/ajv/dist/compile/ref_error.d.ts +6 -0
  33. package/compiled/ajv-keywords/ajv/dist/compile/resolve.d.ts +12 -0
  34. package/compiled/ajv-keywords/ajv/dist/compile/rules.d.ts +28 -0
  35. package/compiled/ajv-keywords/ajv/dist/compile/util.d.ts +40 -0
  36. package/compiled/ajv-keywords/ajv/dist/compile/validate/index.d.ts +42 -0
  37. package/compiled/ajv-keywords/ajv/dist/compile/validate/subschema.d.ts +47 -0
  38. package/compiled/ajv-keywords/ajv/dist/core.d.ts +173 -0
  39. package/compiled/ajv-keywords/ajv/dist/runtime/validation_error.d.ts +7 -0
  40. package/compiled/ajv-keywords/ajv/dist/types/index.d.ts +183 -0
  41. package/compiled/ajv-keywords/ajv/dist/types/json-schema.d.ts +124 -0
  42. package/compiled/ajv-keywords/ajv/dist/types/jtd-schema.d.ts +169 -0
  43. package/compiled/ajv-keywords/dist/index.d.ts +4 -0
  44. package/compiled/ajv-keywords/index.js +1 -0
  45. package/compiled/ajv-keywords/license +21 -0
  46. package/compiled/ajv-keywords/package.json +1 -0
  47. package/compiled/ajv-keywords/uri-js/dist/es5/uri.all.d.ts +59 -0
  48. package/compiled/better-ajv-errors/ajv/dist/ajv.d.ts +16 -0
  49. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/code.d.ts +40 -0
  50. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/index.d.ts +79 -0
  51. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/scope.d.ts +79 -0
  52. package/compiled/better-ajv-errors/ajv/dist/compile/errors.d.ts +13 -0
  53. package/compiled/better-ajv-errors/ajv/dist/compile/index.d.ts +80 -0
  54. package/compiled/better-ajv-errors/ajv/dist/compile/ref_error.d.ts +6 -0
  55. package/compiled/better-ajv-errors/ajv/dist/compile/resolve.d.ts +12 -0
  56. package/compiled/better-ajv-errors/ajv/dist/compile/rules.d.ts +28 -0
  57. package/compiled/better-ajv-errors/ajv/dist/compile/util.d.ts +40 -0
  58. package/compiled/better-ajv-errors/ajv/dist/compile/validate/index.d.ts +42 -0
  59. package/compiled/better-ajv-errors/ajv/dist/compile/validate/subschema.d.ts +47 -0
  60. package/compiled/better-ajv-errors/ajv/dist/core.d.ts +173 -0
  61. package/compiled/better-ajv-errors/ajv/dist/runtime/validation_error.d.ts +7 -0
  62. package/compiled/better-ajv-errors/ajv/dist/types/index.d.ts +183 -0
  63. package/compiled/better-ajv-errors/ajv/dist/types/json-schema.d.ts +124 -0
  64. package/compiled/better-ajv-errors/ajv/dist/types/jtd-schema.d.ts +169 -0
  65. package/compiled/better-ajv-errors/index.js +1 -0
  66. package/compiled/better-ajv-errors/license +13 -0
  67. package/compiled/better-ajv-errors/package.json +1 -0
  68. package/compiled/better-ajv-errors/typings.d.ts +24 -0
  69. package/compiled/better-ajv-errors/uri-js/dist/es5/uri.all.d.ts +59 -0
  70. package/compiled/v8-compile-cache/index.js +1 -0
  71. package/compiled/v8-compile-cache/license +21 -0
  72. package/compiled/v8-compile-cache/package.json +1 -0
  73. package/dist/cli.d.ts +1 -0
  74. package/dist/cli.js +33 -0
  75. package/dist/config/defaults.d.ts +28 -0
  76. package/dist/config/defaults.js +98 -0
  77. package/dist/{types/config → config}/index.d.ts +2 -2
  78. package/dist/config/index.js +120 -0
  79. package/dist/config/mergeConfig.d.ts +30 -0
  80. package/dist/config/mergeConfig.js +26 -0
  81. package/dist/config/schema/deploy.d.ts +16 -0
  82. package/dist/config/schema/deploy.js +16 -0
  83. package/dist/config/schema/index.d.ts +466 -0
  84. package/dist/config/schema/index.js +95 -0
  85. package/dist/config/schema/output.d.ts +146 -0
  86. package/dist/config/schema/output.js +68 -0
  87. package/dist/config/schema/server.d.ts +182 -0
  88. package/dist/config/schema/server.js +107 -0
  89. package/dist/config/schema/source.d.ts +58 -0
  90. package/dist/config/schema/source.js +36 -0
  91. package/dist/config/schema/tools.d.ts +36 -0
  92. package/dist/config/schema/tools.js +19 -0
  93. package/dist/config/types/electron.d.ts +13 -0
  94. package/dist/config/types/electron.js +2 -0
  95. package/dist/config/types/index.d.ts +240 -0
  96. package/dist/config/types/index.js +2 -0
  97. package/dist/config/types/less.d.ts +10 -0
  98. package/dist/config/types/less.js +2 -0
  99. package/dist/config/types/sass.d.ts +8 -0
  100. package/dist/config/types/sass.js +2 -0
  101. package/dist/{types/config → config}/types/ssg.d.ts +8 -8
  102. package/dist/config/types/ssg.js +2 -0
  103. package/dist/config/types/test.d.ts +14 -0
  104. package/dist/config/types/test.js +2 -0
  105. package/dist/config/types/unbundle.d.ts +25 -0
  106. package/dist/config/types/unbundle.js +2 -0
  107. package/dist/{types/context.d.ts → context.d.ts} +12 -22
  108. package/dist/context.js +59 -0
  109. package/dist/index.d.ts +64 -0
  110. package/dist/index.js +177 -0
  111. package/dist/{types/initWatcher.d.ts → initWatcher.d.ts} +1 -1
  112. package/dist/initWatcher.js +75 -0
  113. package/dist/{types/loadEnv.d.ts → loadEnv.d.ts} +1 -1
  114. package/dist/loadEnv.js +21 -0
  115. package/dist/{types/loadPlugins.d.ts → loadPlugins.d.ts} +13 -16
  116. package/dist/loadPlugins.js +109 -0
  117. package/dist/manager.d.ts +72 -0
  118. package/dist/manager.js +24 -0
  119. package/dist/{types/pluginAPI.d.ts → pluginAPI.d.ts} +5 -6
  120. package/dist/pluginAPI.js +16 -0
  121. package/dist/{types/utils → utils}/commander.d.ts +1 -1
  122. package/dist/utils/commander.js +20 -0
  123. package/dist/{types/utils → utils}/repeatKeyWarning.d.ts +1 -1
  124. package/dist/utils/repeatKeyWarning.js +22 -0
  125. package/package.json +14 -28
  126. package/tsconfig.json +3 -4
  127. package/dist/js/modern/cli.js +0 -29
  128. package/dist/js/modern/config/defaults.js +0 -103
  129. package/dist/js/modern/config/index.js +0 -115
  130. package/dist/js/modern/config/mergeConfig.js +0 -22
  131. package/dist/js/modern/config/schema/deploy.js +0 -17
  132. package/dist/js/modern/config/schema/index.js +0 -107
  133. package/dist/js/modern/config/schema/output.js +0 -147
  134. package/dist/js/modern/config/schema/server.js +0 -170
  135. package/dist/js/modern/config/schema/source.js +0 -59
  136. package/dist/js/modern/config/schema/tools.js +0 -36
  137. package/dist/js/modern/config/types/electron.js +0 -1
  138. package/dist/js/modern/config/types/index.js +0 -1
  139. package/dist/js/modern/config/types/less.js +0 -0
  140. package/dist/js/modern/config/types/sass.js +0 -0
  141. package/dist/js/modern/config/types/ssg.js +0 -0
  142. package/dist/js/modern/config/types/test.js +0 -0
  143. package/dist/js/modern/config/types/unbundle.js +0 -0
  144. package/dist/js/modern/context.js +0 -63
  145. package/dist/js/modern/index.js +0 -169
  146. package/dist/js/modern/initWatcher.js +0 -62
  147. package/dist/js/modern/loadEnv.js +0 -14
  148. package/dist/js/modern/loadPlugins.js +0 -122
  149. package/dist/js/modern/manager.js +0 -28
  150. package/dist/js/modern/pluginAPI.js +0 -11
  151. package/dist/js/modern/utils/commander.js +0 -19
  152. package/dist/js/modern/utils/repeatKeyWarning.js +0 -18
  153. package/dist/js/node/cli.js +0 -35
  154. package/dist/js/node/config/defaults.js +0 -110
  155. package/dist/js/node/config/index.js +0 -182
  156. package/dist/js/node/config/mergeConfig.js +0 -32
  157. package/dist/js/node/config/schema/deploy.js +0 -26
  158. package/dist/js/node/config/schema/index.js +0 -127
  159. package/dist/js/node/config/schema/output.js +0 -156
  160. package/dist/js/node/config/schema/server.js +0 -179
  161. package/dist/js/node/config/schema/source.js +0 -68
  162. package/dist/js/node/config/schema/tools.js +0 -43
  163. package/dist/js/node/config/types/electron.js +0 -5
  164. package/dist/js/node/config/types/index.js +0 -5
  165. package/dist/js/node/config/types/less.js +0 -0
  166. package/dist/js/node/config/types/sass.js +0 -0
  167. package/dist/js/node/config/types/ssg.js +0 -0
  168. package/dist/js/node/config/types/test.js +0 -0
  169. package/dist/js/node/config/types/unbundle.js +0 -0
  170. package/dist/js/node/context.js +0 -93
  171. package/dist/js/node/index.js +0 -329
  172. package/dist/js/node/initWatcher.js +0 -82
  173. package/dist/js/node/loadEnv.js +0 -30
  174. package/dist/js/node/loadPlugins.js +0 -134
  175. package/dist/js/node/manager.js +0 -45
  176. package/dist/js/node/pluginAPI.js +0 -54
  177. package/dist/js/node/utils/commander.js +0 -32
  178. package/dist/js/node/utils/repeatKeyWarning.js +0 -31
  179. package/dist/types/cli.d.ts +0 -1
  180. package/dist/types/config/defaults.d.ts +0 -28
  181. package/dist/types/config/mergeConfig.d.ts +0 -31
  182. package/dist/types/config/schema/deploy.d.ts +0 -16
  183. package/dist/types/config/schema/index.d.ts +0 -466
  184. package/dist/types/config/schema/output.d.ts +0 -146
  185. package/dist/types/config/schema/server.d.ts +0 -182
  186. package/dist/types/config/schema/source.d.ts +0 -58
  187. package/dist/types/config/schema/tools.d.ts +0 -36
  188. package/dist/types/config/types/electron.d.ts +0 -13
  189. package/dist/types/config/types/index.d.ts +0 -252
  190. package/dist/types/config/types/less.d.ts +0 -10
  191. package/dist/types/config/types/sass.d.ts +0 -8
  192. package/dist/types/config/types/test.d.ts +0 -15
  193. package/dist/types/config/types/unbundle.d.ts +0 -28
  194. package/dist/types/index.d.ts +0 -64
  195. package/dist/types/manager.d.ts +0 -75
  196. package/modern.config.js +0 -6
@@ -1,122 +0,0 @@
1
- import { isDepExists, createDebugger, compatRequire, INTERNAL_PLUGINS } from '@modern-js/utils';
2
- import { createPlugin } from "./manager";
3
- const debug = createDebugger('load-plugins');
4
-
5
- /**
6
- * Try to resolve plugin entry file path.
7
- * @param name - Plugin name.
8
- * @param appDirectory - Application root directory.
9
- * @returns Resolved file path.
10
- */
11
- const tryResolve = (name, appDirectory) => {
12
- let filePath = '';
13
-
14
- try {
15
- filePath = require.resolve(name, {
16
- paths: [appDirectory]
17
- });
18
- delete require.cache[filePath];
19
- } catch (err) {
20
- if (err.code === 'MODULE_NOT_FOUND') {
21
- throw new Error(`Can not find plugin ${name}.`);
22
- }
23
-
24
- throw err;
25
- }
26
-
27
- return filePath;
28
- };
29
-
30
- export function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
31
- const allPlugins = internalPlugins || INTERNAL_PLUGINS;
32
- const appPlugins = [...Object.keys(allPlugins).filter(name => {
33
- const config = allPlugins[name];
34
-
35
- if (config.forced === true) {
36
- // 参考 packages/cli/core/src/cli.ts 文件
37
- return true;
38
- }
39
-
40
- return isDepExists(appDirectory, name);
41
- }).map(name => allPlugins[name]), ...oldPluginConfig];
42
- return appPlugins;
43
- }
44
-
45
- const resolveCliPlugin = (p, userConfig, appDirectory, transformPlugin) => {
46
- const pkg = typeof p === 'string' ? p : p[0];
47
- const pluginOptions = typeof p === 'string' ? undefined : p[1];
48
- const path = tryResolve(pkg, appDirectory);
49
- let module = compatRequire(path);
50
-
51
- if (transformPlugin) {
52
- module = transformPlugin(module, userConfig, pluginOptions);
53
- }
54
-
55
- if (typeof module === 'function') {
56
- const result = module(pluginOptions);
57
- return createPlugin(result.setup, result);
58
- }
59
-
60
- return module;
61
- };
62
-
63
- const isOldPluginConfig = config => Array.isArray(config) && config.some(item => {
64
- if (typeof item === 'string' || Array.isArray(item)) {
65
- return true;
66
- }
67
-
68
- return 'cli' in item || 'server' in item;
69
- });
70
- /**
71
- * Load internal plugins which in @modern-js scope and user's custom plugins.
72
- * @param appDirectory - Application root directory.
73
- * @param userConfig - Resolved user config.
74
- * @param options.internalPlugins - Internal plugins.
75
- * @param options.transformPlugin - transform plugin before using it. Used for compatible with legacy jupiter plugins.
76
- * @returns Plugin Objects has been required.
77
- */
78
-
79
-
80
- export const loadPlugins = (appDirectory, userConfig, options = {}) => {
81
- const pluginConfig = userConfig.plugins;
82
- const plugins = getAppPlugins(appDirectory, isOldPluginConfig(pluginConfig) ? pluginConfig : [], options.internalPlugins);
83
- const loadedPlugins = plugins.map(plugin => {
84
- const _plugin = typeof plugin === 'string' || Array.isArray(plugin) ? {
85
- cli: plugin
86
- } : plugin;
87
-
88
- const {
89
- cli,
90
- server
91
- } = _plugin;
92
- const loadedPlugin = {};
93
-
94
- if (cli) {
95
- loadedPlugin.cli = resolveCliPlugin(cli, userConfig, appDirectory, options.transformPlugin);
96
- } // server plugins don't support to accept params
97
-
98
-
99
- if (server && typeof server === 'string') {
100
- loadedPlugin.server = server;
101
- loadedPlugin.serverPkg = server;
102
- }
103
-
104
- debug(`resolve plugin %s: %s`, plugin, {
105
- cli: loadedPlugin.cli,
106
- server: loadedPlugin.server
107
- });
108
- return loadedPlugin;
109
- });
110
-
111
- if (!isOldPluginConfig(pluginConfig)) {
112
- const cliPlugins = Array.isArray(pluginConfig) ? pluginConfig : pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.cli;
113
-
114
- if (cliPlugins !== null && cliPlugins !== void 0 && cliPlugins.length) {
115
- loadedPlugins.push(...cliPlugins.map(item => ({
116
- cli: createPlugin(item.setup, item)
117
- })));
118
- }
119
- }
120
-
121
- return loadedPlugins;
122
- };
@@ -1,28 +0,0 @@
1
- import { createAsyncManager, createAsyncWorkflow, createAsyncWaterfall, createParallelWorkflow } from '@modern-js/plugin';
2
- import { compatRequire } from '@modern-js/utils';
3
- import { pluginAPI } from "./pluginAPI";
4
- const baseHooks = {
5
- config: createParallelWorkflow(),
6
- resolvedConfig: createAsyncWaterfall(),
7
- validateSchema: createParallelWorkflow(),
8
- prepare: createAsyncWorkflow(),
9
- commands: createAsyncWorkflow(),
10
- watchFiles: createParallelWorkflow(),
11
- fileChange: createAsyncWorkflow(),
12
- beforeExit: createAsyncWorkflow(),
13
- beforeRestart: createAsyncWorkflow()
14
- };
15
- /** All hooks of cli plugin. */
16
-
17
- export const manager = createAsyncManager(baseHooks, pluginAPI);
18
- /** Plugin options of a cli plugin. */
19
-
20
- export const {
21
- createPlugin,
22
- registerHook,
23
- useRunner: mountHook
24
- } = manager;
25
- export const usePlugins = plugins => plugins.forEach(pluginPath => {
26
- const module = compatRequire(require.resolve(pluginPath));
27
- manager.usePlugin(module);
28
- });
@@ -1,11 +0,0 @@
1
- import { AppContext, ConfigContext, setAppContext, useAppContext, useConfigContext, ResolvedConfigContext, useResolvedConfigContext } from "./context";
2
- export const pluginAPI = {
3
- setAppContext,
4
- useAppContext,
5
- useConfigContext,
6
- useResolvedConfigContext
7
- };
8
- /** all apis for cli plugin */
9
-
10
- // TODO: only export types after refactor all plugins
11
- export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext };
@@ -1,19 +0,0 @@
1
- import { program } from '@modern-js/utils';
2
- export function initCommandsMap() {
3
- if (!program.hasOwnProperty('commandsMap')) {
4
- Object.defineProperty(program, 'commandsMap', {
5
- get() {
6
- const map = new Map();
7
-
8
- for (const command of program.commands) {
9
- map.set(command._name, command);
10
- }
11
-
12
- return map;
13
- },
14
-
15
- configurable: false
16
- });
17
- }
18
- }
19
- export { program };
@@ -1,18 +0,0 @@
1
- import { traverseSchema } from "../config/schema";
2
- export const deepGet = (obj, key) => {
3
- for (const p of key.split('.')) {
4
- // eslint-disable-next-line no-param-reassign
5
- obj = obj ? obj[p] : undefined;
6
- }
7
-
8
- return obj;
9
- };
10
- export const repeatKeyWarning = (schema, jsConfig, pkgConfig) => {
11
- const keys = traverseSchema(schema);
12
-
13
- for (const key of keys) {
14
- if (deepGet(jsConfig, key) !== undefined && deepGet(pkgConfig, key) !== undefined) {
15
- throw new Error(`The same configuration ${key} exists in modern.config.js and package.json.\n Please remove it from package.json.`);
16
- }
17
- }
18
- };
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- var _path = _interopRequireDefault(require("path"));
4
-
5
- var _ = require(".");
6
-
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
- // 这个文件跟 bin/modern-js.js 基本一样
10
- // 在开发阶段,因为 package.json 的 exports['./bin']['jsnext:source'] 配置
11
- // 了这个文件,所以需要保留, 后续如果找到更好的方式之后会移除这个文件
12
- const {
13
- version
14
- } = require("../../package.json"); // XXX: 通过这个方式去掉了 package.json 里面对于 @modern-js/module-tools 的 devDependencies 依赖
15
- // 然后可以正常的执行 modern build
16
-
17
-
18
- const kModuleToolsCliPath = _path.default.resolve(__dirname, '../../../solutions/module-tools/src/index.ts');
19
-
20
- process.env.MODERN_JS_VERSION = version;
21
-
22
- if (!process.env.NODE_ENV) {
23
- process.env.NODE_ENV = // eslint-disable-next-line no-nested-ternary
24
- ['build', 'start', 'deploy'].includes(process.argv[2]) ? 'production' : process.argv[2] === 'test' ? 'test' : 'development';
25
- }
26
-
27
- _.cli.run(process.argv.slice(2), {
28
- plugins: {
29
- '@modern-js/module-tools': {
30
- cli: kModuleToolsCliPath,
31
- // 是否需要强制加载这个组件,跳过 loadPlugins 里面 filter 的检测逻辑
32
- forced: true
33
- }
34
- }
35
- });
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.defaults = void 0;
7
- const sourceDefaults = {
8
- entries: undefined,
9
- disableDefaultEntries: false,
10
- entriesDir: './src',
11
- configDir: './config',
12
- apiDir: './api',
13
- envVars: [],
14
- globalVars: undefined,
15
- alias: undefined,
16
- moduleScopes: undefined,
17
- include: []
18
- };
19
- const outputDefaults = {
20
- assetPrefix: '/',
21
- htmlPath: 'html',
22
- jsPath: 'static/js',
23
- cssPath: 'static/css',
24
- mediaPath: 'static/media',
25
- path: 'dist',
26
- title: '',
27
- titleByEntries: undefined,
28
- meta: {
29
- charset: {
30
- charset: 'utf-8'
31
- },
32
- viewport: 'width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no',
33
- 'http-equiv': {
34
- 'http-equiv': 'x-ua-compatible',
35
- content: 'ie=edge'
36
- },
37
- renderer: 'webkit',
38
- layoutmode: 'standard',
39
- imagemode: 'force',
40
- 'wap-font-scale': 'no',
41
- 'format-detection': 'telephone=no'
42
- },
43
- metaByEntries: undefined,
44
- inject: 'head',
45
- injectByEntries: undefined,
46
- mountId: 'root',
47
- favicon: '',
48
- faviconByEntries: undefined,
49
- copy: undefined,
50
- scriptExt: undefined,
51
- disableHtmlFolder: false,
52
- disableCssModuleExtension: false,
53
- disableCssExtract: false,
54
- enableCssModuleTSDeclaration: false,
55
- disableMinimize: false,
56
- enableInlineStyles: false,
57
- enableInlineScripts: false,
58
- disableSourceMap: false,
59
- disableInlineRuntimeChunk: false,
60
- disableAssetsCache: false,
61
- enableLatestDecorators: false,
62
- polyfill: 'entry',
63
- dataUriLimit: 10000,
64
- templateParameters: {},
65
- templateParametersByEntries: undefined,
66
- cssModuleLocalIdentName: '[name]__[local]--[hash:base64:5]',
67
- enableModernMode: false,
68
- federation: undefined,
69
- disableNodePolyfill: false,
70
- enableTsLoader: false
71
- };
72
- const serverDefaults = {
73
- routes: undefined,
74
- publicRoutes: undefined,
75
- ssr: undefined,
76
- ssrByEntries: undefined,
77
- baseUrl: '/',
78
- port: 8080
79
- };
80
- const devDefaults = {
81
- assetPrefix: false,
82
- https: false
83
- };
84
- const deployDefaults = {
85
- domain: '',
86
- domainByEntries: undefined
87
- };
88
- const toolsDefaults = {
89
- webpack: undefined,
90
- babel: undefined,
91
- postcss: undefined,
92
- autoprefixer: undefined,
93
- lodash: undefined,
94
- devServer: undefined,
95
- tsLoader: undefined,
96
- terser: undefined,
97
- minifyCss: undefined
98
- };
99
- const defaults = {
100
- source: sourceDefaults,
101
- output: outputDefaults,
102
- server: serverDefaults,
103
- dev: devDefaults,
104
- deploy: deployDefaults,
105
- tools: toolsDefaults,
106
- plugins: [],
107
- runtime: {},
108
- runtimeByEntries: {}
109
- };
110
- exports.defaults = defaults;
@@ -1,182 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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;
15
- Object.defineProperty(exports, "defaultsConfig", {
16
- enumerable: true,
17
- get: function () {
18
- return _defaults.defaults;
19
- }
20
- });
21
- exports.loadUserConfig = exports.defineConfig = void 0;
22
- Object.defineProperty(exports, "mergeConfig", {
23
- enumerable: true,
24
- get: function () {
25
- return _mergeConfig.mergeConfig;
26
- }
27
- });
28
- exports.resolveConfig = void 0;
29
-
30
- var _loadConfig = require("@modern-js/load-config");
31
-
32
- var _ajv = _interopRequireDefault(require("ajv"));
33
-
34
- var _ajvKeywords = _interopRequireDefault(require("ajv-keywords"));
35
-
36
- var _utils = require("@modern-js/utils");
37
-
38
- var _lodash = require("@modern-js/utils/lodash");
39
-
40
- var _betterAjvErrors = _interopRequireDefault(require("better-ajv-errors"));
41
-
42
- var _codeFrame = require("@babel/code-frame");
43
-
44
- var _repeatKeyWarning = require("../utils/repeatKeyWarning");
45
-
46
- var _defaults = require("./defaults");
47
-
48
- var _mergeConfig = require("./mergeConfig");
49
-
50
- var _schema = require("./schema");
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
-
66
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
67
-
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; }
69
-
70
- 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; }
71
-
72
- 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; }
73
-
74
- const debug = (0, _utils.createDebugger)('resolve-config');
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
-
86
- const defineConfig = config => config;
87
-
88
- exports.defineConfig = defineConfig;
89
-
90
- const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
91
- const loaded = await (0, _loadConfig.loadConfig)(appDirectory, filePath, packageJsonConfig);
92
- const config = !loaded ? {} : await (typeof loaded.config === 'function' ? loaded.config(0) : loaded.config);
93
- return {
94
- config: (0, _lodash.mergeWith)({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
95
- jsConfig: config || {},
96
- pkgConfig: (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {},
97
- filePath: loaded === null || loaded === void 0 ? void 0 : loaded.path,
98
- dependencies: (loaded === null || loaded === void 0 ? void 0 : loaded.dependencies) || []
99
- };
100
- };
101
-
102
- exports.loadUserConfig = loadUserConfig;
103
-
104
- const showAdditionalPropertiesError = error => {
105
- if (error.keyword === 'additionalProperties' && error.params.additionalProperty) {
106
- const target = [error.instancePath.slice(1), error.params.additionalProperty].filter(Boolean).join('.');
107
- const name = Object.keys(_utils.PLUGIN_SCHEMAS).find(key => _utils.PLUGIN_SCHEMAS[key].some(schemaItem => schemaItem.target === target));
108
-
109
- if (name) {
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`);
111
- }
112
- }
113
- };
114
-
115
- const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv, onSchemaError = showAdditionalPropertiesError) => {
116
- var _validate$errors;
117
-
118
- const {
119
- config: userConfig,
120
- jsConfig,
121
- pkgConfig
122
- } = loaded;
123
- const ajv = new _ajv.default({
124
- $data: true,
125
- strict: false
126
- });
127
- (0, _ajvKeywords.default)(ajv);
128
- const validateSchema = (0, _schema.patchSchema)(schemas);
129
- const validate = ajv.compile(validateSchema);
130
- (0, _repeatKeyWarning.repeatKeyWarning)(validateSchema, jsConfig, pkgConfig); // validate user config.
131
-
132
- const valid = validate(userConfig);
133
-
134
- if (!valid && (_validate$errors = validate.errors) !== null && _validate$errors !== void 0 && _validate$errors.length) {
135
- var _validate$errors2;
136
-
137
- onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
138
- const errors = (0, _betterAjvErrors.default)(validateSchema, userConfig, (_validate$errors2 = validate.errors) === null || _validate$errors2 === void 0 ? void 0 : _validate$errors2.map(e => _objectSpread(_objectSpread({}, e), {}, {
139
- dataPath: e.instancePath
140
- })), {
141
- format: 'js',
142
- indent: 2
143
- });
144
-
145
- _utils.signale.log((0, _codeFrame.codeFrameColumns)(JSON.stringify(userConfig, null, 2), {
146
- start: errors === null || errors === void 0 ? void 0 : errors[0].start,
147
- end: errors === null || errors === void 0 ? void 0 : errors[0].end
148
- }, {
149
- highlightCode: true,
150
- message: errors === null || errors === void 0 ? void 0 : errors[0].error
151
- }));
152
-
153
- throw new Error(`Validate configuration error`);
154
- } // validate config from plugins.
155
-
156
-
157
- for (const config of configs) {
158
- if (!validate(config)) {
159
- _utils.signale.error(validate.errors);
160
-
161
- throw new Error(`Validate configuration error.`);
162
- }
163
- }
164
-
165
- const resolved = (0, _mergeConfig.mergeConfig)([_defaults.defaults, ...configs, userConfig]);
166
- resolved._raw = loaded.config;
167
-
168
- if ((0, _utils.isDev)() && argv[0] === 'dev') {
169
- if (restartWithExistingPort > 0) {
170
- // dev server is restarted, should use existing port number
171
- resolved.server.port = restartWithExistingPort;
172
- } else {
173
- // get port for new dev server
174
- resolved.server.port = await (0, _utils.getPort)(resolved.server.port);
175
- }
176
- }
177
-
178
- debug('resolved %o', resolved);
179
- return resolved;
180
- };
181
-
182
- exports.resolveConfig = resolveConfig;
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.mergeConfig = void 0;
7
-
8
- var _lodash = require("@modern-js/utils/lodash");
9
-
10
- var _utils = require("@modern-js/utils");
11
-
12
- /**
13
- * merge configuration from modern.config.js and plugins.
14
- *
15
- * @param configs - Configuration from modern.config.ts or plugin's config hook.
16
- * @returns - normalized user config.
17
- */
18
- const mergeConfig = configs => (0, _lodash.mergeWith)({}, ...configs, (target, source) => {
19
- if (Array.isArray(target)) {
20
- if (Array.isArray(source)) {
21
- return [...target, ...source];
22
- } else {
23
- return typeof source !== 'undefined' ? [...target, source] : target;
24
- }
25
- } else if ((0, _utils.isFunction)(source)) {
26
- return typeof target !== 'undefined' ? [target, source] : [source];
27
- }
28
-
29
- return undefined;
30
- });
31
-
32
- exports.mergeConfig = mergeConfig;
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.deploy = void 0;
7
-
8
- var _utils = require("@modern-js/utils");
9
-
10
- const deploy = {
11
- type: 'object',
12
- properties: {
13
- domain: {
14
- type: ['array', 'string']
15
- },
16
- domainByEntries: {
17
- type: 'object',
18
- patternProperties: {
19
- [_utils.ENTRY_NAME_PATTERN]: {
20
- type: ['array', 'string']
21
- }
22
- }
23
- }
24
- }
25
- };
26
- exports.deploy = deploy;