@modern-js/core 1.9.2 → 1.10.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 (152) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/compiled/ajv/package.json +1 -1
  3. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/ajv.d.ts +0 -0
  4. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/compile/codegen/code.d.ts +0 -0
  5. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/compile/codegen/index.d.ts +0 -0
  6. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/compile/codegen/scope.d.ts +0 -0
  7. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/compile/errors.d.ts +0 -0
  8. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/compile/index.d.ts +0 -0
  9. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/compile/ref_error.d.ts +0 -0
  10. package/compiled/ajv/{dist → types}/compile/resolve.d.ts +0 -0
  11. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/compile/rules.d.ts +0 -0
  12. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/compile/util.d.ts +0 -0
  13. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/compile/validate/index.d.ts +0 -0
  14. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/compile/validate/subschema.d.ts +0 -0
  15. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/core.d.ts +0 -0
  16. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/runtime/validation_error.d.ts +0 -0
  17. package/compiled/ajv/{dist → types}/types/index.d.ts +0 -0
  18. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/types/json-schema.d.ts +0 -0
  19. package/compiled/{ajv-keywords/ajv/dist → ajv/types}/types/jtd-schema.d.ts +0 -0
  20. package/compiled/ajv-keywords/index.d.ts +1 -0
  21. package/compiled/ajv-keywords/package.json +1 -1
  22. package/compiled/better-ajv-errors/index.d.ts +1 -0
  23. package/compiled/better-ajv-errors/package.json +1 -1
  24. package/compiled/v8-compile-cache/index.d.ts +1 -0
  25. package/compiled/v8-compile-cache/package.json +1 -1
  26. package/dist/config/index.d.ts +1 -1
  27. package/dist/config/index.js +19 -28
  28. package/dist/config/mergeConfig.js +5 -1
  29. package/dist/config/types/index.d.ts +37 -37
  30. package/dist/index.js +55 -60
  31. package/dist/initWatcher.js +3 -12
  32. package/dist/loadPlugins.d.ts +1 -1
  33. package/package.json +34 -13
  34. package/.eslintrc.js +0 -9
  35. package/compiled/ajv/dist/ajv.d.ts +0 -16
  36. package/compiled/ajv/dist/compile/codegen/code.d.ts +0 -40
  37. package/compiled/ajv/dist/compile/codegen/index.d.ts +0 -79
  38. package/compiled/ajv/dist/compile/codegen/scope.d.ts +0 -79
  39. package/compiled/ajv/dist/compile/errors.d.ts +0 -13
  40. package/compiled/ajv/dist/compile/index.d.ts +0 -80
  41. package/compiled/ajv/dist/compile/ref_error.d.ts +0 -6
  42. package/compiled/ajv/dist/compile/rules.d.ts +0 -28
  43. package/compiled/ajv/dist/compile/util.d.ts +0 -40
  44. package/compiled/ajv/dist/compile/validate/index.d.ts +0 -42
  45. package/compiled/ajv/dist/compile/validate/subschema.d.ts +0 -47
  46. package/compiled/ajv/dist/core.d.ts +0 -173
  47. package/compiled/ajv/dist/runtime/validation_error.d.ts +0 -7
  48. package/compiled/ajv/dist/types/json-schema.d.ts +0 -124
  49. package/compiled/ajv/dist/types/jtd-schema.d.ts +0 -169
  50. package/compiled/ajv-keywords/ajv/dist/compile/resolve.d.ts +0 -12
  51. package/compiled/ajv-keywords/ajv/dist/types/index.d.ts +0 -183
  52. package/compiled/ajv-keywords/dist/index.d.ts +0 -4
  53. package/compiled/ajv-keywords/uri-js/dist/es5/uri.all.d.ts +0 -59
  54. package/compiled/better-ajv-errors/ajv/dist/ajv.d.ts +0 -16
  55. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/code.d.ts +0 -40
  56. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/index.d.ts +0 -79
  57. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/scope.d.ts +0 -79
  58. package/compiled/better-ajv-errors/ajv/dist/compile/errors.d.ts +0 -13
  59. package/compiled/better-ajv-errors/ajv/dist/compile/index.d.ts +0 -80
  60. package/compiled/better-ajv-errors/ajv/dist/compile/ref_error.d.ts +0 -6
  61. package/compiled/better-ajv-errors/ajv/dist/compile/resolve.d.ts +0 -12
  62. package/compiled/better-ajv-errors/ajv/dist/compile/rules.d.ts +0 -28
  63. package/compiled/better-ajv-errors/ajv/dist/compile/util.d.ts +0 -40
  64. package/compiled/better-ajv-errors/ajv/dist/compile/validate/index.d.ts +0 -42
  65. package/compiled/better-ajv-errors/ajv/dist/compile/validate/subschema.d.ts +0 -47
  66. package/compiled/better-ajv-errors/ajv/dist/core.d.ts +0 -173
  67. package/compiled/better-ajv-errors/ajv/dist/runtime/validation_error.d.ts +0 -7
  68. package/compiled/better-ajv-errors/ajv/dist/types/index.d.ts +0 -183
  69. package/compiled/better-ajv-errors/ajv/dist/types/json-schema.d.ts +0 -124
  70. package/compiled/better-ajv-errors/ajv/dist/types/jtd-schema.d.ts +0 -169
  71. package/compiled/better-ajv-errors/typings.d.ts +0 -24
  72. package/compiled/better-ajv-errors/uri-js/dist/es5/uri.all.d.ts +0 -59
  73. package/dist/js/modern/cli.js +0 -29
  74. package/dist/js/modern/config/defaults.js +0 -103
  75. package/dist/js/modern/config/index.js +0 -115
  76. package/dist/js/modern/config/mergeConfig.js +0 -22
  77. package/dist/js/modern/config/schema/deploy.js +0 -17
  78. package/dist/js/modern/config/schema/index.js +0 -107
  79. package/dist/js/modern/config/schema/output.js +0 -147
  80. package/dist/js/modern/config/schema/server.js +0 -170
  81. package/dist/js/modern/config/schema/source.js +0 -59
  82. package/dist/js/modern/config/schema/tools.js +0 -36
  83. package/dist/js/modern/config/types/electron.js +0 -1
  84. package/dist/js/modern/config/types/index.js +0 -1
  85. package/dist/js/modern/config/types/less.js +0 -0
  86. package/dist/js/modern/config/types/sass.js +0 -0
  87. package/dist/js/modern/config/types/ssg.js +0 -0
  88. package/dist/js/modern/config/types/test.js +0 -0
  89. package/dist/js/modern/config/types/unbundle.js +0 -0
  90. package/dist/js/modern/context.js +0 -63
  91. package/dist/js/modern/index.js +0 -169
  92. package/dist/js/modern/initWatcher.js +0 -62
  93. package/dist/js/modern/loadEnv.js +0 -14
  94. package/dist/js/modern/loadPlugins.js +0 -122
  95. package/dist/js/modern/manager.js +0 -28
  96. package/dist/js/modern/pluginAPI.js +0 -11
  97. package/dist/js/modern/utils/commander.js +0 -19
  98. package/dist/js/modern/utils/repeatKeyWarning.js +0 -18
  99. package/dist/js/node/cli.js +0 -35
  100. package/dist/js/node/config/defaults.js +0 -110
  101. package/dist/js/node/config/index.js +0 -182
  102. package/dist/js/node/config/mergeConfig.js +0 -32
  103. package/dist/js/node/config/schema/deploy.js +0 -26
  104. package/dist/js/node/config/schema/index.js +0 -127
  105. package/dist/js/node/config/schema/output.js +0 -156
  106. package/dist/js/node/config/schema/server.js +0 -179
  107. package/dist/js/node/config/schema/source.js +0 -68
  108. package/dist/js/node/config/schema/tools.js +0 -43
  109. package/dist/js/node/config/types/electron.js +0 -5
  110. package/dist/js/node/config/types/index.js +0 -5
  111. package/dist/js/node/config/types/less.js +0 -0
  112. package/dist/js/node/config/types/sass.js +0 -0
  113. package/dist/js/node/config/types/ssg.js +0 -0
  114. package/dist/js/node/config/types/test.js +0 -0
  115. package/dist/js/node/config/types/unbundle.js +0 -0
  116. package/dist/js/node/context.js +0 -93
  117. package/dist/js/node/index.js +0 -329
  118. package/dist/js/node/initWatcher.js +0 -82
  119. package/dist/js/node/loadEnv.js +0 -30
  120. package/dist/js/node/loadPlugins.js +0 -134
  121. package/dist/js/node/manager.js +0 -45
  122. package/dist/js/node/pluginAPI.js +0 -54
  123. package/dist/js/node/utils/commander.js +0 -32
  124. package/dist/js/node/utils/repeatKeyWarning.js +0 -31
  125. package/dist/types/cli.d.ts +0 -1
  126. package/dist/types/config/defaults.d.ts +0 -28
  127. package/dist/types/config/index.d.ts +0 -12
  128. package/dist/types/config/mergeConfig.d.ts +0 -31
  129. package/dist/types/config/schema/deploy.d.ts +0 -16
  130. package/dist/types/config/schema/index.d.ts +0 -466
  131. package/dist/types/config/schema/output.d.ts +0 -146
  132. package/dist/types/config/schema/server.d.ts +0 -182
  133. package/dist/types/config/schema/source.d.ts +0 -58
  134. package/dist/types/config/schema/tools.d.ts +0 -36
  135. package/dist/types/config/types/electron.d.ts +0 -13
  136. package/dist/types/config/types/index.d.ts +0 -252
  137. package/dist/types/config/types/less.d.ts +0 -10
  138. package/dist/types/config/types/sass.d.ts +0 -8
  139. package/dist/types/config/types/ssg.d.ts +0 -13
  140. package/dist/types/config/types/test.d.ts +0 -15
  141. package/dist/types/config/types/unbundle.d.ts +0 -28
  142. package/dist/types/context.d.ts +0 -47
  143. package/dist/types/index.d.ts +0 -64
  144. package/dist/types/initWatcher.d.ts +0 -3
  145. package/dist/types/loadEnv.d.ts +0 -1
  146. package/dist/types/loadPlugins.d.ts +0 -44
  147. package/dist/types/manager.d.ts +0 -75
  148. package/dist/types/pluginAPI.d.ts +0 -13
  149. package/dist/types/utils/commander.d.ts +0 -4
  150. package/dist/types/utils/repeatKeyWarning.d.ts +0 -3
  151. package/jest.config.js +0 -7
  152. package/tsconfig.json +0 -11
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 1.10.2
4
+
5
+ ### Patch Changes
6
+
7
+ - d32f35134: chore: add modern/jest/eslint/ts config files to .npmignore
8
+ - d9d398e16: add filter logic for merge config
9
+ - Updated dependencies [d5913bd96]
10
+ - Updated dependencies [d32f35134]
11
+ - Updated dependencies [6ae4a34ae]
12
+ - Updated dependencies [b80229c79]
13
+ - Updated dependencies [948cc4436]
14
+ - @modern-js/plugin@1.3.4
15
+ - @modern-js/load-config@1.3.3
16
+ - @modern-js/utils@1.7.3
17
+
18
+ ## 1.10.1
19
+
20
+ ### Patch Changes
21
+
22
+ - 69a728375: fix: remove exports.jsnext:source after publish
23
+ - Updated dependencies [cd7346b0d]
24
+ - Updated dependencies [69a728375]
25
+ - @modern-js/utils@1.7.2
26
+ - @modern-js/load-config@1.3.2
27
+
28
+ ## 1.10.0
29
+
30
+ ### Minor Changes
31
+
32
+ - 0ee4bb4e: feat: prebundle webpack loaders and plugins
33
+
34
+ ### Patch Changes
35
+
36
+ - a22d3ea8: fix: package manager name in logs and comments
37
+ - 5c00db22: fix: ignore existed schema properties
38
+ - 92f4909e: fix: cli.init should return correct appContext
39
+ - Updated dependencies [0ee4bb4e]
40
+ - Updated dependencies [6fa74d5f]
41
+ - @modern-js/utils@1.7.0
42
+
3
43
  ## 1.9.0
4
44
 
5
45
  ### Minor Changes
@@ -1 +1 @@
1
- {"name":"ajv","author":"Evgeny Poberezkin","version":"8.11.0","funding":{"type":"github","url":"https://github.com/sponsors/epoberezkin"},"license":"MIT","types":"dist/ajv.d.ts"}
1
+ {"name":"ajv","author":"Evgeny Poberezkin","version":"8.11.0","funding":{"type":"github","url":"https://github.com/sponsors/epoberezkin"},"license":"MIT","types":"types/ajv.d.ts"}
File without changes
@@ -0,0 +1 @@
1
+ export = any;
@@ -1 +1 @@
1
- {"name":"ajv-keywords","author":"Evgeny Poberezkin","version":"5.1.0","license":"MIT","types":"dist/index.d.ts"}
1
+ {"name":"ajv-keywords","author":"Evgeny Poberezkin","version":"5.1.0","license":"MIT","types":"index.d.ts"}
@@ -0,0 +1 @@
1
+ export = any;
@@ -1 +1 @@
1
- {"name":"better-ajv-errors","author":"Rifat Nabi <to.rifat@gmail.com>","version":"1.2.0","license":"Apache-2.0","types":"./typings.d.ts"}
1
+ {"name":"better-ajv-errors","author":"Rifat Nabi <to.rifat@gmail.com>","version":"1.2.0","license":"Apache-2.0","types":"index.d.ts"}
@@ -0,0 +1 @@
1
+ export = any;
@@ -1 +1 @@
1
- {"name":"v8-compile-cache","author":"Andres Suarez <zertosh@gmail.com>","version":"2.3.0","license":"MIT"}
1
+ {"name":"v8-compile-cache","author":"Andres Suarez <zertosh@gmail.com>","version":"2.3.0","license":"MIT","types":"index.d.ts"}
@@ -9,4 +9,4 @@ export * from './types';
9
9
  export declare const addServerConfigToDeps: (dependencies: string[], appDirectory: string, serverConfigFile: string) => Promise<void>;
10
10
  export declare const defineConfig: (config: ConfigParam) => ConfigParam;
11
11
  export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => Promise<LoadedConfig>;
12
- export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void) => Promise<NormalizedConfig>;
12
+ export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void | Promise<void>) => Promise<NormalizedConfig>;
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
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);
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
5
  }) : (function(o, m, k, k2) {
10
6
  if (k2 === undefined) k2 = k;
11
7
  o[k2] = m[k];
@@ -13,15 +9,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
9
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
11
  };
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
12
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
14
  };
@@ -41,20 +28,20 @@ Object.defineProperty(exports, "mergeConfig", { enumerable: true, get: function
41
28
  const schema_1 = require("./schema");
42
29
  const debug = (0, utils_1.createDebugger)('resolve-config');
43
30
  __exportStar(require("./types"), exports);
44
- const addServerConfigToDeps = (dependencies, appDirectory, serverConfigFile) => __awaiter(void 0, void 0, void 0, function* () {
45
- const serverConfig = yield (0, utils_1.getServerConfig)(appDirectory, serverConfigFile);
31
+ const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
32
+ const serverConfig = await (0, utils_1.getServerConfig)(appDirectory, serverConfigFile);
46
33
  if (serverConfig) {
47
34
  dependencies.push(serverConfig);
48
35
  }
49
- });
36
+ };
50
37
  exports.addServerConfigToDeps = addServerConfigToDeps;
51
38
  const defineConfig = (config) => config;
52
39
  exports.defineConfig = defineConfig;
53
- const loadUserConfig = (appDirectory, filePath, packageJsonConfig) => __awaiter(void 0, void 0, void 0, function* () {
54
- const loaded = yield (0, load_config_1.loadConfig)(appDirectory, filePath, packageJsonConfig);
40
+ const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
41
+ const loaded = await (0, load_config_1.loadConfig)(appDirectory, filePath, packageJsonConfig);
55
42
  const config = !loaded
56
43
  ? {}
57
- : yield (typeof loaded.config === 'function'
44
+ : await (typeof loaded.config === 'function'
58
45
  ? loaded.config(0)
59
46
  : loaded.config);
60
47
  return {
@@ -64,9 +51,9 @@ const loadUserConfig = (appDirectory, filePath, packageJsonConfig) => __awaiter(
64
51
  filePath: loaded === null || loaded === void 0 ? void 0 : loaded.path,
65
52
  dependencies: (loaded === null || loaded === void 0 ? void 0 : loaded.dependencies) || [],
66
53
  };
67
- });
54
+ };
68
55
  exports.loadUserConfig = loadUserConfig;
69
- const showAdditionalPropertiesError = (error) => {
56
+ const showAdditionalPropertiesError = async (error) => {
70
57
  if (error.keyword === 'additionalProperties' &&
71
58
  error.params.additionalProperty) {
72
59
  const target = [
@@ -77,11 +64,12 @@ const showAdditionalPropertiesError = (error) => {
77
64
  .join('.');
78
65
  const name = Object.keys(utils_1.PLUGIN_SCHEMAS).find(key => utils_1.PLUGIN_SCHEMAS[key].some((schemaItem) => schemaItem.target === target));
79
66
  if (name) {
80
- utils_1.signale.warn(`The configuration of ${utils_1.chalk.bold(target)} is provided by plugin ${utils_1.chalk.bold(name)}. Please use ${utils_1.chalk.bold('yarn new')} to enable the corresponding capability.\n`);
67
+ const packageManager = await (0, utils_1.getPackageManager)();
68
+ utils_1.signale.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`);
81
69
  }
82
70
  }
83
71
  };
84
- const resolveConfig = (loaded, configs, schemas, restartWithExistingPort, argv, onSchemaError = showAdditionalPropertiesError) => __awaiter(void 0, void 0, void 0, function* () {
72
+ const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv, onSchemaError = showAdditionalPropertiesError) => {
85
73
  var _a, _b;
86
74
  const { config: userConfig, jsConfig, pkgConfig } = loaded;
87
75
  const ajv = new ajv_1.default({ $data: true, strict: false });
@@ -92,8 +80,11 @@ const resolveConfig = (loaded, configs, schemas, restartWithExistingPort, argv,
92
80
  // validate user config.
93
81
  const valid = validate(userConfig);
94
82
  if (!valid && ((_a = validate.errors) === null || _a === void 0 ? void 0 : _a.length)) {
95
- onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
96
- const errors = (0, better_ajv_errors_1.default)(validateSchema, userConfig, (_b = validate.errors) === null || _b === void 0 ? void 0 : _b.map(e => (Object.assign(Object.assign({}, e), { dataPath: e.instancePath }))), {
83
+ await onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
84
+ const errors = (0, better_ajv_errors_1.default)(validateSchema, userConfig, (_b = validate.errors) === null || _b === void 0 ? void 0 : _b.map(e => ({
85
+ ...e,
86
+ dataPath: e.instancePath,
87
+ })), {
97
88
  indent: 2,
98
89
  });
99
90
  utils_1.signale.log(errors);
@@ -115,10 +106,10 @@ const resolveConfig = (loaded, configs, schemas, restartWithExistingPort, argv,
115
106
  }
116
107
  else {
117
108
  // get port for new dev server
118
- resolved.server.port = yield (0, utils_1.getPort)(resolved.server.port);
109
+ resolved.server.port = await (0, utils_1.getPort)(resolved.server.port);
119
110
  }
120
111
  }
121
112
  debug('resolved %o', resolved);
122
113
  return resolved;
123
- });
114
+ };
124
115
  exports.resolveConfig = resolveConfig;
@@ -9,7 +9,11 @@ const utils_1 = require("@modern-js/utils");
9
9
  * @param configs - Configuration from modern.config.ts or plugin's config hook.
10
10
  * @returns - normalized user config.
11
11
  */
12
- const mergeConfig = (configs) => (0, lodash_1.mergeWith)({}, ...configs, (target, source) => {
12
+ const mergeConfig = (configs) => (0, lodash_1.mergeWith)({}, ...configs, (target, source, key) => {
13
+ // Do not use the following merge logic for source.designSystem and tools.tailwind(css)
14
+ if (key === 'designSystem' || key === 'tailwind' || key === 'tailwindcss') {
15
+ return (0, lodash_1.mergeWith)({}, target !== null && target !== void 0 ? target : {}, source !== null && source !== void 0 ? source : {});
16
+ }
13
17
  if (Array.isArray(target)) {
14
18
  if (Array.isArray(source)) {
15
19
  return [...target, ...source];
@@ -5,7 +5,7 @@ import type { MetaOptions } from '@modern-js/utils';
5
5
  import type { TransformOptions } from '@babel/core';
6
6
  import type webpack from 'webpack';
7
7
  import type { Configuration as WebpackConfiguration } from 'webpack';
8
- import autoprefixer from 'autoprefixer';
8
+ import type autoprefixer from 'autoprefixer';
9
9
  import type { BasePluginOptions, TerserOptions as RawTerserOptions } from 'terser-webpack-plugin';
10
10
  import type { PluginConfig } from '../../loadPlugins';
11
11
  import type { TestConfig, JestConfig } from './test';
@@ -33,9 +33,9 @@ export interface SourceConfig {
33
33
  moduleScopes?: Array<string | RegExp> | ((scopes: Array<string | RegExp>) => void) | ((scopes: Array<string | RegExp>) => Array<string | RegExp>);
34
34
  include?: Array<string | RegExp>;
35
35
  /**
36
- * The configuration of `source.designSystem` is provided by plugin `@modern-js/plugin-tailwindcss`.
37
- * Please use `yarn new` to enable the corresponding capability.
38
- * @requires `@modern-js/plugin-tailwindcss`
36
+ * The configuration of `source.designSystem` is provided by `tailwindcss` plugin.
37
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
38
+ * @requires `tailwindcss` plugin
39
39
  */
40
40
  designSystem?: Record<string, any>;
41
41
  }
@@ -82,15 +82,15 @@ export interface OutputConfig {
82
82
  enableTsLoader?: boolean;
83
83
  /**
84
84
  * Disables lazy import support for styles, currently supports antd and arco-design.
85
- * The configuration of `output.disableAutoImportStyle` is provided by plugin `@modern-js/plugin-unbundle`.
86
- * Please use `yarn new` to enable the corresponding capability.
87
- * @requires `@modern-js/plugin-unbundle`
85
+ * The configuration of `output.disableAutoImportStyle` is provided by `unbundle` plugin.
86
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
87
+ * @requires `unbundle` plugin
88
88
  */
89
89
  disableAutoImportStyle?: boolean;
90
90
  /**
91
- * The configuration of `output.ssg` is provided by plugin `@modern-js/plugin-ssg`.
92
- * Please use `yarn new` to enable the corresponding capability.
93
- * @requires `@modern-js/plugin-ssg`
91
+ * The configuration of `output.ssg` is provided by `ssg` plugin.
92
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
93
+ * @requires `ssg` plugin
94
94
  */
95
95
  ssg?: SSGConfig;
96
96
  }
@@ -115,15 +115,15 @@ export interface DevConfig {
115
115
  assetPrefix?: string | boolean;
116
116
  https?: boolean;
117
117
  /**
118
- * The configuration of `dev.proxy` is provided by plugin `@modern-js/plugin-proxy`.
119
- * Please use `yarn new` to enable the corresponding capability.
120
- * @requires `@modern-js/plugin-proxy`
118
+ * The configuration of `dev.proxy` is provided by `proxy` plugin.
119
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
120
+ * @requires `proxy` plugin
121
121
  */
122
122
  proxy?: DevProxyOptions;
123
123
  /**
124
- * The configuration of `dev.unbundle` is provided by plugin `@modern-js/plugin-unbundle`.
125
- * Please use `yarn new` to enable the corresponding capability.
126
- * @requires `@modern-js/plugin-unbundle`
124
+ * The configuration of `dev.unbundle` is provided by `unbundle` plugin.
125
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
126
+ * @requires `unbundle` plugin
127
127
  */
128
128
  unbundle?: UnbundleConfig;
129
129
  }
@@ -167,27 +167,27 @@ export interface ToolsConfig {
167
167
  minifyCss?: ConfigFunction;
168
168
  esbuild?: Record<string, unknown>;
169
169
  /**
170
- * The configuration of `tools.tailwindcss` is provided by plugin `@modern-js/plugin-tailwindcss`.
171
- * Please use `yarn new` to enable the corresponding capability.
172
- * @requires `@modern-js/plugin-tailwindcss`
170
+ * The configuration of `tools.tailwindcss` is provided by `tailwindcss` plugin.
171
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
172
+ * @requires `tailwindcss` plugin
173
173
  */
174
174
  tailwindcss?: Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
175
175
  /**
176
- * The configuration of `tools.jest` is provided by plugin `@modern-js/plugin-testing`.
177
- * Please use `yarn new` to enable the corresponding capability.
178
- * @requires `@modern-js/plugin-testing`
176
+ * The configuration of `tools.jest` is provided by `testing` plugin.
177
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
178
+ * @requires `testing` plugin
179
179
  */
180
180
  jest?: TestConfig['jest'];
181
181
  /**
182
- * The configuration of `tools.sass` is provided by plugin `@modern-js/plugin-sass`.
183
- * Please use `yarn new` to enable the corresponding capability.
184
- * @requires `@modern-js/plugin-sass`
182
+ * The configuration of `tools.sass` is provided by `sass` plugin.
183
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
184
+ * @requires `sass` plugin
185
185
  */
186
186
  sass?: SassConfig;
187
187
  /**
188
- * The configuration of `tools.less` is provided by plugin `@modern-js/plugin-less`.
189
- * Please use `yarn new` to enable the corresponding capability.
190
- * @requires `@modern-js/plugin-less`
188
+ * The configuration of `tools.less` is provided by `less` plugin.
189
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
190
+ * @requires `less` plugin
191
191
  */
192
192
  less?: LessConfig;
193
193
  }
@@ -212,21 +212,21 @@ export interface UserConfig {
212
212
  runtime?: RuntimeConfig;
213
213
  runtimeByEntries?: RuntimeByEntriesConfig;
214
214
  /**
215
- * The configuration of `bff` is provided by plugin `@modern-js/plugin-bff`.
216
- * Please use `yarn new` to enable the corresponding capability.
217
- * @requires `@modern-js/plugin-bff`
215
+ * The configuration of `bff` is provided by `bff` plugin.
216
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
217
+ * @requires `bff` plugin
218
218
  */
219
219
  bff?: BffConfig;
220
220
  /**
221
- * The configuration of `testing` is provided by plugin `@modern-js/plugin-testing`.
222
- * Please use `yarn new` to enable the corresponding capability.
223
- * @requires `@modern-js/plugin-testing`
221
+ * The configuration of `testing` is provided by `testing` plugin.
222
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
223
+ * @requires `testing` plugin
224
224
  */
225
225
  testing?: TestConfig;
226
226
  /**
227
- * The configuration of `electron` is provided by plugin `@modern-js/plugin-electron`.
228
- * Please use `yarn new` to enable the corresponding capability.
229
- * @requires `@modern-js/plugin-electron`
227
+ * The configuration of `electron` is provided by `electron` plugin.
228
+ * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
229
+ * @requires `electron` plugin
230
230
  */
231
231
  electron?: ElectronConfig;
232
232
  }
package/dist/index.js CHANGED
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
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);
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
5
  }) : (function(o, m, k, k2) {
10
6
  if (k2 === undefined) k2 = k;
11
7
  o[k2] = m[k];
@@ -13,15 +9,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
9
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
11
  };
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
12
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
14
  };
@@ -60,23 +47,26 @@ utils_1.program
60
47
  .name('modern')
61
48
  .usage('<command> [options]')
62
49
  .version(process.env.MODERN_JS_VERSION || '0.1.0');
63
- const initAppDir = (cwd) => __awaiter(void 0, void 0, void 0, function* () {
50
+ const initAppDir = async (cwd) => {
64
51
  if (!cwd) {
65
52
  // eslint-disable-next-line no-param-reassign
66
53
  cwd = process.cwd();
67
54
  }
68
- const pkg = yield (0, utils_1.pkgUp)({ cwd });
55
+ const pkg = await (0, utils_1.pkgUp)({ cwd });
69
56
  if (!pkg) {
70
57
  throw new Error(`no package.json found in current work dir: ${cwd}`);
71
58
  }
72
59
  return path_1.default.dirname(pkg);
73
- });
60
+ };
74
61
  exports.initAppDir = initAppDir;
75
62
  const mergeOptions = (options) => {
76
63
  const defaultOptions = {
77
64
  serverConfigFile: utils_1.DEFAULT_SERVER_CONFIG,
78
65
  };
79
- return Object.assign(Object.assign({}, defaultOptions), options);
66
+ return {
67
+ ...defaultOptions,
68
+ ...options,
69
+ };
80
70
  };
81
71
  exports.mergeOptions = mergeOptions;
82
72
  const createCli = () => {
@@ -84,17 +74,17 @@ const createCli = () => {
84
74
  let isRestart = false;
85
75
  let restartWithExistingPort = 0;
86
76
  let restartOptions;
87
- const init = (argv = [], options) => __awaiter(void 0, void 0, void 0, function* () {
77
+ const init = async (argv = [], options) => {
88
78
  var _a, _b;
89
79
  (0, node_1.enable)();
90
80
  manager_1.manager.clear();
91
81
  const mergedOptions = (0, exports.mergeOptions)(options);
92
82
  restartOptions = mergedOptions;
93
- const appDirectory = yield initAppDir();
83
+ const appDirectory = await initAppDir();
94
84
  (0, commander_1.initCommandsMap)();
95
85
  const metaName = (_b = (_a = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options) === null || _a === void 0 ? void 0 : _a.metaName) !== null && _b !== void 0 ? _b : 'MODERN';
96
86
  (0, loadEnv_1.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
97
- const loaded = yield (0, config_1.loadUserConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
87
+ const loaded = await (0, config_1.loadUserConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
98
88
  const plugins = (0, loadPlugins_1.loadPlugins)(appDirectory, loaded.config, {
99
89
  internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins,
100
90
  transformPlugin: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.transformPlugin,
@@ -113,10 +103,10 @@ const createCli = () => {
113
103
  context_1.ConfigContext.set(loaded.config);
114
104
  context_1.AppContext.set(appContext);
115
105
  });
116
- hooksRunner = yield manager_1.manager.init();
106
+ hooksRunner = await manager_1.manager.init();
117
107
  ['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
118
- process.on(event, (err) => __awaiter(void 0, void 0, void 0, function* () {
119
- yield hooksRunner.beforeExit();
108
+ process.on(event, async (err) => {
109
+ await hooksRunner.beforeExit();
120
110
  if (err instanceof Error) {
121
111
  utils_1.logger.error(err.stack);
122
112
  }
@@ -124,53 +114,58 @@ const createCli = () => {
124
114
  // eslint-disable-next-line no-process-exit
125
115
  process.exit(1);
126
116
  });
127
- }));
117
+ });
128
118
  });
129
- const extraConfigs = yield hooksRunner.config();
130
- const extraSchemas = yield hooksRunner.validateSchema();
131
- const config = yield (0, config_1.resolveConfig)(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv, options === null || options === void 0 ? void 0 : options.onSchemaError);
132
- const { resolved } = yield hooksRunner.resolvedConfig({
119
+ const extraConfigs = await hooksRunner.config();
120
+ const extraSchemas = await hooksRunner.validateSchema();
121
+ const config = await (0, config_1.resolveConfig)(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv, options === null || options === void 0 ? void 0 : options.onSchemaError);
122
+ const { resolved } = await hooksRunner.resolvedConfig({
133
123
  resolved: config,
134
124
  });
135
125
  // update context value
136
126
  manager_1.manager.run(() => {
137
127
  context_1.ConfigContext.set(loaded.config);
138
128
  context_1.ResolvedConfigContext.set(resolved);
139
- context_1.AppContext.set(Object.assign(Object.assign({}, appContext), { port: resolved.server.port, distDirectory: (0, utils_1.ensureAbsolutePath)(appDirectory, resolved.output.path) }));
140
- });
141
- yield hooksRunner.prepare();
142
- return { loadedConfig: loaded, appContext, resolved };
143
- });
144
- function run(argv, options) {
145
- return __awaiter(this, void 0, void 0, function* () {
146
- const { loadedConfig, appContext, resolved } = yield init(argv, options);
147
- yield hooksRunner.commands({ program: utils_1.program });
148
- (0, initWatcher_1.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
149
- manager_1.manager.run(() => utils_1.program.parse(process.argv));
129
+ context_1.AppContext.set({
130
+ ...appContext,
131
+ port: resolved.server.port,
132
+ distDirectory: (0, utils_1.ensureAbsolutePath)(appDirectory, resolved.output.path),
133
+ });
150
134
  });
135
+ await hooksRunner.prepare();
136
+ return {
137
+ loadedConfig: loaded,
138
+ // appContext may be updated in `prepare` hook, should return latest value
139
+ appContext: (0, context_1.useAppContext)(),
140
+ resolved,
141
+ };
142
+ };
143
+ async function run(argv, options) {
144
+ const { loadedConfig, appContext, resolved } = await init(argv, options);
145
+ await hooksRunner.commands({ program: utils_1.program });
146
+ (0, initWatcher_1.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
147
+ manager_1.manager.run(() => utils_1.program.parse(process.argv));
151
148
  }
152
- function restart() {
149
+ async function restart() {
153
150
  var _a, _b;
154
- return __awaiter(this, void 0, void 0, function* () {
155
- isRestart = true;
156
- restartWithExistingPort = isRestart ? (_b = (_a = context_1.AppContext.use().value) === null || _a === void 0 ? void 0 : _a.port) !== null && _b !== void 0 ? _b : 0 : 0;
157
- utils_1.logger.info('Restart...\n');
158
- let hasGetError = false;
159
- const runner = manager_1.manager.useRunner();
160
- yield runner.beforeRestart();
161
- try {
162
- yield init(process.argv.slice(2), restartOptions);
163
- }
164
- catch (err) {
165
- console.error(err);
166
- hasGetError = true;
151
+ isRestart = true;
152
+ restartWithExistingPort = isRestart ? (_b = (_a = context_1.AppContext.use().value) === null || _a === void 0 ? void 0 : _a.port) !== null && _b !== void 0 ? _b : 0 : 0;
153
+ utils_1.logger.info('Restart...\n');
154
+ let hasGetError = false;
155
+ const runner = manager_1.manager.useRunner();
156
+ await runner.beforeRestart();
157
+ try {
158
+ await init(process.argv.slice(2), restartOptions);
159
+ }
160
+ catch (err) {
161
+ console.error(err);
162
+ hasGetError = true;
163
+ }
164
+ finally {
165
+ if (!hasGetError) {
166
+ manager_1.manager.run(() => utils_1.program.parse(process.argv));
167
167
  }
168
- finally {
169
- if (!hasGetError) {
170
- manager_1.manager.run(() => utils_1.program.parse(process.argv));
171
- }
172
- }
173
- });
168
+ }
174
169
  }
175
170
  return {
176
171
  init,
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -20,10 +11,10 @@ const utils_1 = require("@modern-js/utils");
20
11
  const debug = (0, utils_1.createDebugger)('watch-files');
21
12
  const md5 = (data) => crypto_1.default.createHash('md5').update(data).digest('hex');
22
13
  const hashMap = new Map();
23
- const initWatcher = (loaded, appDirectory, configDir, hooksRunner, argv) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) => {
24
15
  // only add fs watcher on dev mode.
25
16
  if (((0, utils_1.isDev)() || (0, utils_1.isTest)()) && argv[0] === 'dev') {
26
- const extraFiles = yield hooksRunner.watchFiles();
17
+ const extraFiles = await hooksRunner.watchFiles();
27
18
  const configPath = path_1.default.join(appDirectory, configDir);
28
19
  const watched = [
29
20
  `${configPath}/html`,
@@ -71,5 +62,5 @@ const initWatcher = (loaded, appDirectory, configDir, hooksRunner, argv) => __aw
71
62
  });
72
63
  return watcher;
73
64
  }
74
- });
65
+ };
75
66
  exports.initWatcher = initWatcher;
@@ -10,7 +10,7 @@ export declare type LoadedPlugin = {
10
10
  export declare type TransformPlugin = (plugin: PluginConfig, resolvedConfig: UserConfig, pluginOptions?: any) => PluginConfig;
11
11
  /**
12
12
  * @deprecated
13
- * Using NewPluginConfig insteand.
13
+ * Using NewPluginConfig instead.
14
14
  */
15
15
  declare type OldPluginConfig = Array<PluginItem | {
16
16
  cli?: PluginItem;