@modern-js/core 1.9.0 → 1.10.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 (53) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/compiled/ajv-keywords/index.d.ts +1 -0
  3. package/compiled/ajv-keywords/package.json +1 -1
  4. package/compiled/better-ajv-errors/index.d.ts +1 -0
  5. package/compiled/better-ajv-errors/package.json +1 -1
  6. package/compiled/v8-compile-cache/index.d.ts +1 -0
  7. package/compiled/v8-compile-cache/package.json +1 -1
  8. package/dist/config/index.d.ts +1 -1
  9. package/dist/config/index.js +18 -23
  10. package/dist/config/schema/index.js +2 -3
  11. package/dist/config/types/index.d.ts +36 -36
  12. package/dist/index.js +54 -55
  13. package/dist/initWatcher.js +3 -12
  14. package/package.json +5 -6
  15. package/tsconfig.json +1 -0
  16. package/compiled/ajv-keywords/ajv/dist/ajv.d.ts +0 -16
  17. package/compiled/ajv-keywords/ajv/dist/compile/codegen/code.d.ts +0 -40
  18. package/compiled/ajv-keywords/ajv/dist/compile/codegen/index.d.ts +0 -79
  19. package/compiled/ajv-keywords/ajv/dist/compile/codegen/scope.d.ts +0 -79
  20. package/compiled/ajv-keywords/ajv/dist/compile/errors.d.ts +0 -13
  21. package/compiled/ajv-keywords/ajv/dist/compile/index.d.ts +0 -80
  22. package/compiled/ajv-keywords/ajv/dist/compile/ref_error.d.ts +0 -6
  23. package/compiled/ajv-keywords/ajv/dist/compile/resolve.d.ts +0 -12
  24. package/compiled/ajv-keywords/ajv/dist/compile/rules.d.ts +0 -28
  25. package/compiled/ajv-keywords/ajv/dist/compile/util.d.ts +0 -40
  26. package/compiled/ajv-keywords/ajv/dist/compile/validate/index.d.ts +0 -42
  27. package/compiled/ajv-keywords/ajv/dist/compile/validate/subschema.d.ts +0 -47
  28. package/compiled/ajv-keywords/ajv/dist/core.d.ts +0 -173
  29. package/compiled/ajv-keywords/ajv/dist/runtime/validation_error.d.ts +0 -7
  30. package/compiled/ajv-keywords/ajv/dist/types/index.d.ts +0 -183
  31. package/compiled/ajv-keywords/ajv/dist/types/json-schema.d.ts +0 -124
  32. package/compiled/ajv-keywords/ajv/dist/types/jtd-schema.d.ts +0 -169
  33. package/compiled/ajv-keywords/dist/index.d.ts +0 -4
  34. package/compiled/ajv-keywords/uri-js/dist/es5/uri.all.d.ts +0 -59
  35. package/compiled/better-ajv-errors/ajv/dist/ajv.d.ts +0 -16
  36. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/code.d.ts +0 -40
  37. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/index.d.ts +0 -79
  38. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/scope.d.ts +0 -79
  39. package/compiled/better-ajv-errors/ajv/dist/compile/errors.d.ts +0 -13
  40. package/compiled/better-ajv-errors/ajv/dist/compile/index.d.ts +0 -80
  41. package/compiled/better-ajv-errors/ajv/dist/compile/ref_error.d.ts +0 -6
  42. package/compiled/better-ajv-errors/ajv/dist/compile/resolve.d.ts +0 -12
  43. package/compiled/better-ajv-errors/ajv/dist/compile/rules.d.ts +0 -28
  44. package/compiled/better-ajv-errors/ajv/dist/compile/util.d.ts +0 -40
  45. package/compiled/better-ajv-errors/ajv/dist/compile/validate/index.d.ts +0 -42
  46. package/compiled/better-ajv-errors/ajv/dist/compile/validate/subschema.d.ts +0 -47
  47. package/compiled/better-ajv-errors/ajv/dist/core.d.ts +0 -173
  48. package/compiled/better-ajv-errors/ajv/dist/runtime/validation_error.d.ts +0 -7
  49. package/compiled/better-ajv-errors/ajv/dist/types/index.d.ts +0 -183
  50. package/compiled/better-ajv-errors/ajv/dist/types/json-schema.d.ts +0 -124
  51. package/compiled/better-ajv-errors/ajv/dist/types/jtd-schema.d.ts +0 -169
  52. package/compiled/better-ajv-errors/typings.d.ts +0 -24
  53. package/compiled/better-ajv-errors/uri-js/dist/es5/uri.all.d.ts +0 -59
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 1.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0ee4bb4e: feat: prebundle webpack loaders and plugins
8
+
9
+ ### Patch Changes
10
+
11
+ - a22d3ea8: fix: package manager name in logs and comments
12
+ - 5c00db22: fix: ignore existed schema properties
13
+ - 92f4909e: fix: cli.init should return correct appContext
14
+ - Updated dependencies [0ee4bb4e]
15
+ - Updated dependencies [6fa74d5f]
16
+ - @modern-js/utils@1.7.0
17
+
3
18
  ## 1.9.0
4
19
 
5
20
  ### Minor 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>;
@@ -9,15 +9,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
9
9
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
12
  var __importDefault = (this && this.__importDefault) || function (mod) {
22
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
14
  };
@@ -37,20 +28,20 @@ Object.defineProperty(exports, "mergeConfig", { enumerable: true, get: function
37
28
  const schema_1 = require("./schema");
38
29
  const debug = (0, utils_1.createDebugger)('resolve-config');
39
30
  __exportStar(require("./types"), exports);
40
- const addServerConfigToDeps = (dependencies, appDirectory, serverConfigFile) => __awaiter(void 0, void 0, void 0, function* () {
41
- 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);
42
33
  if (serverConfig) {
43
34
  dependencies.push(serverConfig);
44
35
  }
45
- });
36
+ };
46
37
  exports.addServerConfigToDeps = addServerConfigToDeps;
47
38
  const defineConfig = (config) => config;
48
39
  exports.defineConfig = defineConfig;
49
- const loadUserConfig = (appDirectory, filePath, packageJsonConfig) => __awaiter(void 0, void 0, void 0, function* () {
50
- 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);
51
42
  const config = !loaded
52
43
  ? {}
53
- : yield (typeof loaded.config === 'function'
44
+ : await (typeof loaded.config === 'function'
54
45
  ? loaded.config(0)
55
46
  : loaded.config);
56
47
  return {
@@ -60,9 +51,9 @@ const loadUserConfig = (appDirectory, filePath, packageJsonConfig) => __awaiter(
60
51
  filePath: loaded === null || loaded === void 0 ? void 0 : loaded.path,
61
52
  dependencies: (loaded === null || loaded === void 0 ? void 0 : loaded.dependencies) || [],
62
53
  };
63
- });
54
+ };
64
55
  exports.loadUserConfig = loadUserConfig;
65
- const showAdditionalPropertiesError = (error) => {
56
+ const showAdditionalPropertiesError = async (error) => {
66
57
  if (error.keyword === 'additionalProperties' &&
67
58
  error.params.additionalProperty) {
68
59
  const target = [
@@ -73,11 +64,12 @@ const showAdditionalPropertiesError = (error) => {
73
64
  .join('.');
74
65
  const name = Object.keys(utils_1.PLUGIN_SCHEMAS).find(key => utils_1.PLUGIN_SCHEMAS[key].some((schemaItem) => schemaItem.target === target));
75
66
  if (name) {
76
- 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`);
77
69
  }
78
70
  }
79
71
  };
80
- 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) => {
81
73
  var _a, _b;
82
74
  const { config: userConfig, jsConfig, pkgConfig } = loaded;
83
75
  const ajv = new ajv_1.default({ $data: true, strict: false });
@@ -88,8 +80,11 @@ const resolveConfig = (loaded, configs, schemas, restartWithExistingPort, argv,
88
80
  // validate user config.
89
81
  const valid = validate(userConfig);
90
82
  if (!valid && ((_a = validate.errors) === null || _a === void 0 ? void 0 : _a.length)) {
91
- onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
92
- 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
+ })), {
93
88
  indent: 2,
94
89
  });
95
90
  utils_1.signale.log(errors);
@@ -111,10 +106,10 @@ const resolveConfig = (loaded, configs, schemas, restartWithExistingPort, argv,
111
106
  }
112
107
  else {
113
108
  // get port for new dev server
114
- resolved.server.port = yield (0, utils_1.getPort)(resolved.server.port);
109
+ resolved.server.port = await (0, utils_1.getPort)(resolved.server.port);
115
110
  }
116
111
  }
117
112
  debug('resolved %o', resolved);
118
113
  return resolved;
119
- });
114
+ };
120
115
  exports.resolveConfig = resolveConfig;
@@ -67,10 +67,9 @@ const patchSchema = (pluginSchemas) => {
67
67
  const props = target.split('.');
68
68
  const mountProperty = props.pop();
69
69
  const targetNode = findTargetNode(props);
70
- if (targetNode.hasOwnProperty(mountProperty)) {
71
- throw new Error(`${target} already exists in current validate schema`);
70
+ if (!targetNode.hasOwnProperty(mountProperty)) {
71
+ targetNode[mountProperty] = (0, lodash_1.cloneDeep)(schema);
72
72
  }
73
- targetNode[mountProperty] = (0, lodash_1.cloneDeep)(schema);
74
73
  }
75
74
  debug(`final validate schema: %o`, finalSchema);
76
75
  return finalSchema;
@@ -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
@@ -9,15 +9,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
9
9
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
12
  var __importDefault = (this && this.__importDefault) || function (mod) {
22
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
14
  };
@@ -56,23 +47,26 @@ utils_1.program
56
47
  .name('modern')
57
48
  .usage('<command> [options]')
58
49
  .version(process.env.MODERN_JS_VERSION || '0.1.0');
59
- const initAppDir = (cwd) => __awaiter(void 0, void 0, void 0, function* () {
50
+ const initAppDir = async (cwd) => {
60
51
  if (!cwd) {
61
52
  // eslint-disable-next-line no-param-reassign
62
53
  cwd = process.cwd();
63
54
  }
64
- const pkg = yield (0, utils_1.pkgUp)({ cwd });
55
+ const pkg = await (0, utils_1.pkgUp)({ cwd });
65
56
  if (!pkg) {
66
57
  throw new Error(`no package.json found in current work dir: ${cwd}`);
67
58
  }
68
59
  return path_1.default.dirname(pkg);
69
- });
60
+ };
70
61
  exports.initAppDir = initAppDir;
71
62
  const mergeOptions = (options) => {
72
63
  const defaultOptions = {
73
64
  serverConfigFile: utils_1.DEFAULT_SERVER_CONFIG,
74
65
  };
75
- return Object.assign(Object.assign({}, defaultOptions), options);
66
+ return {
67
+ ...defaultOptions,
68
+ ...options,
69
+ };
76
70
  };
77
71
  exports.mergeOptions = mergeOptions;
78
72
  const createCli = () => {
@@ -80,17 +74,17 @@ const createCli = () => {
80
74
  let isRestart = false;
81
75
  let restartWithExistingPort = 0;
82
76
  let restartOptions;
83
- const init = (argv = [], options) => __awaiter(void 0, void 0, void 0, function* () {
77
+ const init = async (argv = [], options) => {
84
78
  var _a, _b;
85
79
  (0, node_1.enable)();
86
80
  manager_1.manager.clear();
87
81
  const mergedOptions = (0, exports.mergeOptions)(options);
88
82
  restartOptions = mergedOptions;
89
- const appDirectory = yield initAppDir();
83
+ const appDirectory = await initAppDir();
90
84
  (0, commander_1.initCommandsMap)();
91
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';
92
86
  (0, loadEnv_1.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
93
- 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);
94
88
  const plugins = (0, loadPlugins_1.loadPlugins)(appDirectory, loaded.config, {
95
89
  internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins,
96
90
  transformPlugin: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.transformPlugin,
@@ -109,10 +103,10 @@ const createCli = () => {
109
103
  context_1.ConfigContext.set(loaded.config);
110
104
  context_1.AppContext.set(appContext);
111
105
  });
112
- hooksRunner = yield manager_1.manager.init();
106
+ hooksRunner = await manager_1.manager.init();
113
107
  ['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
114
- process.on(event, (err) => __awaiter(void 0, void 0, void 0, function* () {
115
- yield hooksRunner.beforeExit();
108
+ process.on(event, async (err) => {
109
+ await hooksRunner.beforeExit();
116
110
  if (err instanceof Error) {
117
111
  utils_1.logger.error(err.stack);
118
112
  }
@@ -120,53 +114,58 @@ const createCli = () => {
120
114
  // eslint-disable-next-line no-process-exit
121
115
  process.exit(1);
122
116
  });
123
- }));
117
+ });
124
118
  });
125
- const extraConfigs = yield hooksRunner.config();
126
- const extraSchemas = yield hooksRunner.validateSchema();
127
- const config = yield (0, config_1.resolveConfig)(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv, options === null || options === void 0 ? void 0 : options.onSchemaError);
128
- 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({
129
123
  resolved: config,
130
124
  });
131
125
  // update context value
132
126
  manager_1.manager.run(() => {
133
127
  context_1.ConfigContext.set(loaded.config);
134
128
  context_1.ResolvedConfigContext.set(resolved);
135
- context_1.AppContext.set(Object.assign(Object.assign({}, appContext), { port: resolved.server.port, distDirectory: (0, utils_1.ensureAbsolutePath)(appDirectory, resolved.output.path) }));
136
- });
137
- yield hooksRunner.prepare();
138
- return { loadedConfig: loaded, appContext, resolved };
139
- });
140
- function run(argv, options) {
141
- return __awaiter(this, void 0, void 0, function* () {
142
- const { loadedConfig, appContext, resolved } = yield init(argv, options);
143
- yield hooksRunner.commands({ program: utils_1.program });
144
- (0, initWatcher_1.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
145
- 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
+ });
146
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));
147
148
  }
148
- function restart() {
149
+ async function restart() {
149
150
  var _a, _b;
150
- return __awaiter(this, void 0, void 0, function* () {
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
- yield runner.beforeRestart();
157
- try {
158
- yield init(process.argv.slice(2), restartOptions);
159
- }
160
- catch (err) {
161
- console.error(err);
162
- 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));
163
167
  }
164
- finally {
165
- if (!hasGetError) {
166
- manager_1.manager.run(() => utils_1.program.parse(process.argv));
167
- }
168
- }
169
- });
168
+ }
170
169
  }
171
170
  return {
172
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;
package/package.json CHANGED
@@ -11,9 +11,9 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.9.0",
14
+ "version": "1.10.0",
15
15
  "jsnext:source": "./src/index.ts",
16
- "types": "./dist/types/index.d.ts",
16
+ "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
18
18
  "module": "./dist/index.js",
19
19
  "jsnext:modern": "./dist/index.js",
@@ -42,11 +42,11 @@
42
42
  "dependencies": {
43
43
  "@modern-js/load-config": "^1.3.1",
44
44
  "@modern-js/plugin": "^1.3.3",
45
- "@modern-js/utils": "^1.6.0"
45
+ "@modern-js/utils": "^1.7.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@jest/types": "^27.0.6",
49
- "@modern-js/types": "1.5.1",
49
+ "@modern-js/types": "1.5.2",
50
50
  "@scripts/build": "0.0.0",
51
51
  "@scripts/jest-config": "0.0.0",
52
52
  "@types/babel__code-frame": "^7.0.3",
@@ -63,8 +63,7 @@
63
63
  "electron-builder": "22.7.0",
64
64
  "terser-webpack-plugin": "^5.1.4",
65
65
  "typescript": "^4",
66
- "webpack": "^5.71.0",
67
- "webpack-chain": "^6.5.1"
66
+ "webpack": "^5.71.0"
68
67
  },
69
68
  "sideEffects": false,
70
69
  "publishConfig": {
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "@modern-js/tsconfig/base",
3
3
  "compilerOptions": {
4
+ "target": "ES2019",
4
5
  "declaration": true,
5
6
  "outDir": "./dist",
6
7
  "baseUrl": "./",
@@ -1,16 +0,0 @@
1
- import type { AnySchemaObject } from './types';
2
- import AjvCore from './core';
3
- declare class Ajv extends AjvCore {
4
- _addVocabularies(): void;
5
- _addDefaultMetaSchema(): void;
6
- defaultMeta(): string | AnySchemaObject | undefined;
7
- }
8
- export default Ajv;
9
- export { Format, FormatDefinition, AsyncFormatDefinition, KeywordDefinition, KeywordErrorDefinition, CodeKeywordDefinition, MacroKeywordDefinition, FuncKeywordDefinition, Vocabulary, Schema, SchemaObject, AnySchemaObject, AsyncSchema, AnySchema, ValidateFunction, AsyncValidateFunction, SchemaValidateFunction, ErrorObject, ErrorNoParams, } from "./types";
10
- export { Plugin, Options, CodeOptions, InstanceOptions, Logger, ErrorsTextOptions } from "./core";
11
- export { SchemaCxt, SchemaObjCxt } from "./compile";
12
- export { KeywordCxt } from "./compile/validate";
13
- export { DefinedError } from "./vocabularies/errors";
14
- export { JSONType } from "./compile/rules";
15
- export { JSONSchemaType } from "./types/json-schema";
16
- export { _, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions } from "./compile/codegen";
@@ -1,40 +0,0 @@
1
- export declare abstract class _CodeOrName {
2
- abstract readonly str: string;
3
- abstract readonly names: UsedNames;
4
- abstract toString(): string;
5
- abstract emptyStr(): boolean;
6
- }
7
- export declare const IDENTIFIER: RegExp;
8
- export declare class Name extends _CodeOrName {
9
- readonly str: string;
10
- constructor(s: string);
11
- toString(): string;
12
- emptyStr(): boolean;
13
- get names(): UsedNames;
14
- }
15
- export declare class _Code extends _CodeOrName {
16
- readonly _items: readonly CodeItem[];
17
- private _str?;
18
- private _names?;
19
- constructor(code: string | readonly CodeItem[]);
20
- toString(): string;
21
- emptyStr(): boolean;
22
- get str(): string;
23
- get names(): UsedNames;
24
- }
25
- export declare type CodeItem = Name | string | number | boolean | null;
26
- export declare type UsedNames = Record<string, number | undefined>;
27
- export declare type Code = _Code | Name;
28
- export declare type SafeExpr = Code | number | boolean | null;
29
- export declare const nil: _Code;
30
- declare type CodeArg = SafeExpr | string | undefined;
31
- export declare function _(strs: TemplateStringsArray, ...args: CodeArg[]): _Code;
32
- export declare function str(strs: TemplateStringsArray, ...args: (CodeArg | string[])[]): _Code;
33
- export declare function addCodeArg(code: CodeItem[], arg: CodeArg | string[]): void;
34
- export declare function strConcat(c1: Code, c2: Code): Code;
35
- export declare function stringify(x: unknown): Code;
36
- export declare function safeStringify(x: unknown): string;
37
- export declare function getProperty(key: Code | string | number): Code;
38
- export declare function getEsmExportName(key: Code | string | number): Code;
39
- export declare function regexpCode(rx: RegExp): Code;
40
- export {};