@modern-js/core 2.39.2 → 2.41.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.
@@ -1,3 +1,2 @@
1
- import type { ErrorObject } from '@modern-js/utils/ajv';
2
- import type { UserConfig, NormalizedConfig, LoadedConfig, PluginValidateSchema } from '../types';
3
- export declare const createResolveConfig: (loaded: LoadedConfig<{}>, configs: UserConfig[], schemas: PluginValidateSchema[], onSchemaError?: ((error: ErrorObject) => void | Promise<void>) | undefined) => Promise<NormalizedConfig>;
1
+ import type { UserConfig, NormalizedConfig, LoadedConfig } from '../types';
2
+ export declare const createResolveConfig: (loaded: LoadedConfig<{}>, configs: UserConfig[]) => Promise<NormalizedConfig>;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var createResolvedConfig_exports = {};
30
20
  __export(createResolvedConfig_exports, {
@@ -32,50 +22,11 @@ __export(createResolvedConfig_exports, {
32
22
  });
33
23
  module.exports = __toCommonJS(createResolvedConfig_exports);
34
24
  var import_utils = require("@modern-js/utils");
35
- var import_patchSchema = require("../schema/patchSchema");
36
- var import_repeatKeyWarning = require("../utils/repeatKeyWarning");
37
25
  var import_mergeConfig = require("../utils/mergeConfig");
38
26
  var import_createDefaultConfig = require("./createDefaultConfig");
39
27
  const debug = (0, import_utils.createDebugger)("resolve-config");
40
- const createResolveConfig = async (loaded, configs, schemas, onSchemaError) => {
41
- var _validate_errors;
42
- const { default: Ajv } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils/ajv")));
43
- const { default: ajvKeywords } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils/ajv-keywords")));
44
- const { default: betterAjvErrors } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils/better-ajv-errors")));
45
- const { config: userConfig, jsConfig, pkgConfig } = loaded;
46
- const ajv = new Ajv({
47
- $data: true,
48
- strict: false
49
- });
50
- ajvKeywords(ajv);
51
- const validateSchema = (0, import_patchSchema.patchSchema)(schemas);
52
- const validate = ajv.compile(validateSchema);
53
- (0, import_repeatKeyWarning.repeatKeyWarning)(validateSchema, jsConfig, pkgConfig);
54
- const valid = validate(userConfig);
55
- const formatValidateError = (config) => {
56
- var _validate_errors2;
57
- return betterAjvErrors(validateSchema, config, (_validate_errors2 = validate.errors) === null || _validate_errors2 === void 0 ? void 0 : _validate_errors2.map((e) => ({
58
- ...e,
59
- dataPath: e.instancePath
60
- })), {
61
- indent: 2
62
- });
63
- };
64
- if (!valid && ((_validate_errors = validate.errors) === null || _validate_errors === void 0 ? void 0 : _validate_errors.length)) {
65
- if (onSchemaError) {
66
- await onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
67
- }
68
- const errors = formatValidateError(userConfig);
69
- import_utils.logger.log(errors);
70
- throw new Error(`Validate configuration error`);
71
- }
72
- for (const config of configs) {
73
- if (!validate(config)) {
74
- const errors = formatValidateError(config);
75
- import_utils.logger.error(errors);
76
- throw new Error(`Validate configuration error.`);
77
- }
78
- }
28
+ const createResolveConfig = async (loaded, configs) => {
29
+ const { config: userConfig } = loaded;
79
30
  const resolved = (0, import_mergeConfig.mergeConfig)([
80
31
  (0, import_createDefaultConfig.createDefaultConfig)(),
81
32
  ...configs,
package/dist/createCli.js CHANGED
@@ -95,8 +95,7 @@ const createCli = () => {
95
95
  });
96
96
  await hooksRunner.beforeConfig();
97
97
  const extraConfigs = await hooksRunner.config();
98
- const extraSchemas = await hooksRunner.validateSchema();
99
- const normalizedConfig = await (0, import_config.createResolveConfig)(loaded, extraConfigs, extraSchemas, options === null || options === void 0 ? void 0 : options.onSchemaError);
98
+ const normalizedConfig = await (0, import_config.createResolveConfig)(loaded, extraConfigs);
100
99
  const { resolved } = await hooksRunner.resolvedConfig({
101
100
  resolved: normalizedConfig
102
101
  });
package/dist/manager.d.ts CHANGED
@@ -5,7 +5,6 @@ export declare const manager: import("@modern-js/plugin").AsyncManager<{
5
5
  resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
6
6
  resolved: import("./types").NormalizedConfig<{}>;
7
7
  }>;
8
- validateSchema: import("@modern-js/plugin").ParallelWorkflow<void>;
9
8
  prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
10
9
  afterPrepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
11
10
  watchFiles: import("@modern-js/plugin").ParallelWorkflow<void, string[] | {
@@ -29,7 +28,6 @@ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSet
29
28
  resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
30
29
  resolved: import("./types").NormalizedConfig<{}>;
31
30
  }>;
32
- validateSchema: import("@modern-js/plugin").ParallelWorkflow<void>;
33
31
  prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
34
32
  afterPrepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
35
33
  watchFiles: import("@modern-js/plugin").ParallelWorkflow<void, string[] | {
@@ -52,7 +50,6 @@ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSet
52
50
  resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
53
51
  resolved: import("./types").NormalizedConfig<{}>;
54
52
  }>;
55
- validateSchema: import("@modern-js/plugin").ParallelWorkflow<void>;
56
53
  prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
57
54
  afterPrepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
58
55
  watchFiles: import("@modern-js/plugin").ParallelWorkflow<void, string[] | {
@@ -75,7 +72,6 @@ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSet
75
72
  resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
76
73
  resolved: import("./types").NormalizedConfig<{}>;
77
74
  }>;
78
- validateSchema: import("@modern-js/plugin").ParallelWorkflow<void>;
79
75
  prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
80
76
  afterPrepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
81
77
  watchFiles: import("@modern-js/plugin").ParallelWorkflow<void, string[] | {
@@ -98,7 +94,6 @@ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSet
98
94
  resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
99
95
  resolved: import("./types").NormalizedConfig<{}>;
100
96
  }>;
101
- validateSchema: import("@modern-js/plugin").ParallelWorkflow<void>;
102
97
  prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
103
98
  afterPrepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
104
99
  watchFiles: import("@modern-js/plugin").ParallelWorkflow<void, string[] | {
@@ -121,7 +116,6 @@ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSet
121
116
  resolvedConfig: import("@modern-js/plugin").AsyncWaterfall<{
122
117
  resolved: import("./types").NormalizedConfig<{}>;
123
118
  }>;
124
- validateSchema: import("@modern-js/plugin").ParallelWorkflow<void>;
125
119
  prepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
126
120
  afterPrepare: import("@modern-js/plugin").AsyncWorkflow<void, void>;
127
121
  watchFiles: import("@modern-js/plugin").ParallelWorkflow<void, string[] | {
package/dist/manager.js CHANGED
@@ -29,7 +29,6 @@ const baseHooks = {
29
29
  beforeConfig: (0, import_plugin.createAsyncWorkflow)(),
30
30
  config: (0, import_plugin.createParallelWorkflow)(),
31
31
  resolvedConfig: (0, import_plugin.createAsyncWaterfall)(),
32
- validateSchema: (0, import_plugin.createParallelWorkflow)(),
33
32
  prepare: (0, import_plugin.createAsyncWorkflow)(),
34
33
  afterPrepare: (0, import_plugin.createAsyncWorkflow)(),
35
34
  commands: (0, import_plugin.createAsyncWorkflow)(),
@@ -1,4 +1,3 @@
1
- import type { ErrorObject } from '@modern-js/utils/compiled/ajv';
2
1
  import type { InternalPlugins } from './plugin';
3
2
  import type { UserConfig } from './config';
4
3
  export interface CoreOptions {
@@ -16,7 +15,6 @@ export interface CoreOptions {
16
15
  server?: InternalPlugins;
17
16
  autoLoad?: InternalPlugins;
18
17
  };
19
- onSchemaError?: (error: ErrorObject) => void;
20
18
  options?: {
21
19
  metaName?: string;
22
20
  srcDir?: string;
@@ -11,7 +11,6 @@ export type BaseHooks<Extends extends {
11
11
  resolvedConfig: AsyncWaterfall<{
12
12
  resolved: NormalizedConfig<Extends>;
13
13
  }>;
14
- validateSchema: ParallelWorkflow<void>;
15
14
  prepare: AsyncWorkflow<void, void>;
16
15
  afterPrepare: AsyncWorkflow<void, void>;
17
16
  watchFiles: ParallelWorkflow<void, string[] | {
@@ -1,11 +1,6 @@
1
- import type { JSONSchemaType } from '@modern-js/utils/ajv/json-schema';
2
1
  export * from './plugin';
3
2
  export * from './config';
4
3
  export * from './pluginAPI';
5
4
  export * from './hooks';
6
5
  export * from './context';
7
- export * from './coreOptions';
8
- export interface PluginValidateSchema {
9
- target: string;
10
- schema: JSONSchemaType<any>;
11
- }
6
+ export * from './coreOptions';
@@ -2,5 +2,4 @@ export * from './commander';
2
2
  export * from './createFileWatcher';
3
3
  export * from './initAppDir';
4
4
  export * from './mergeConfig';
5
- export * from './repeatKeyWarning';
6
5
  export * from './checkIsDuplicationPlugin';
@@ -19,7 +19,6 @@ __reExport(utils_exports, require("./commander"), module.exports);
19
19
  __reExport(utils_exports, require("./createFileWatcher"), module.exports);
20
20
  __reExport(utils_exports, require("./initAppDir"), module.exports);
21
21
  __reExport(utils_exports, require("./mergeConfig"), module.exports);
22
- __reExport(utils_exports, require("./repeatKeyWarning"), module.exports);
23
22
  __reExport(utils_exports, require("./checkIsDuplicationPlugin"), module.exports);
24
23
  // Annotate the CommonJS export names for ESM import in node:
25
24
  0 && (module.exports = {
@@ -27,6 +26,5 @@ __reExport(utils_exports, require("./checkIsDuplicationPlugin"), module.exports)
27
26
  ...require("./createFileWatcher"),
28
27
  ...require("./initAppDir"),
29
28
  ...require("./mergeConfig"),
30
- ...require("./repeatKeyWarning"),
31
29
  ...require("./checkIsDuplicationPlugin")
32
30
  });
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "modern",
15
15
  "modern.js"
16
16
  ],
17
- "version": "2.39.2",
17
+ "version": "2.41.0",
18
18
  "jsnext:source": "./src/index.ts",
19
19
  "types": "./dist/index.d.ts",
20
20
  "main": "./dist/index.js",
@@ -70,10 +70,10 @@
70
70
  }
71
71
  },
72
72
  "dependencies": {
73
- "@swc/helpers": "0.5.1",
74
- "@modern-js/node-bundle-require": "2.39.2",
75
- "@modern-js/plugin": "2.39.2",
76
- "@modern-js/utils": "2.39.2"
73
+ "@swc/helpers": "0.5.3",
74
+ "@modern-js/node-bundle-require": "2.41.0",
75
+ "@modern-js/utils": "2.41.0",
76
+ "@modern-js/plugin": "2.41.0"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@types/jest": "^29",
@@ -81,10 +81,10 @@
81
81
  "tsm": "2.3.0",
82
82
  "jest": "^29",
83
83
  "typescript": "^5",
84
- "@modern-js/builder-shared": "2.39.2",
85
- "@modern-js/types": "2.39.2",
86
- "@scripts/build": "2.39.2",
87
- "@scripts/jest-config": "2.39.2"
84
+ "@modern-js/types": "2.41.0",
85
+ "@scripts/build": "2.41.0",
86
+ "@scripts/jest-config": "2.41.0",
87
+ "@modern-js/builder-shared": "2.41.0"
88
88
  },
89
89
  "sideEffects": false,
90
90
  "publishConfig": {
@@ -1,5 +0,0 @@
1
- import { PluginValidateSchema } from '../types';
2
- export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | PluginValidateSchema[]>) => {
3
- type: string;
4
- properties: {};
5
- };
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var patchSchema_exports = {};
20
- __export(patchSchema_exports, {
21
- patchSchema: () => patchSchema
22
- });
23
- module.exports = __toCommonJS(patchSchema_exports);
24
- var import_utils = require("@modern-js/utils");
25
- var import_lodash = require("@modern-js/utils/lodash");
26
- const debug = (0, import_utils.createDebugger)("validate-schema");
27
- const patchSchema = (pluginSchemas) => {
28
- const finalSchema = {
29
- type: "object",
30
- properties: {}
31
- };
32
- const findTargetNode = (props) => {
33
- let node = finalSchema.properties;
34
- for (const prop of props) {
35
- if (!node[prop]) {
36
- node[prop] = {
37
- type: "object"
38
- };
39
- }
40
- node = node[prop];
41
- if (!node || !(0, import_utils.isObject)(node)) {
42
- throw new Error(`add schema ${props.join(".")} error`);
43
- }
44
- node.properties = node.hasOwnProperty("properties") ? node.properties : {};
45
- node = node.properties;
46
- }
47
- return node;
48
- };
49
- const finalPluginSchemas = [];
50
- pluginSchemas.forEach((item) => {
51
- if (Array.isArray(item)) {
52
- finalPluginSchemas.push(...item);
53
- } else {
54
- finalPluginSchemas.push(item);
55
- }
56
- });
57
- for (const { target, schema } of finalPluginSchemas) {
58
- if (!target) {
59
- throw new Error(`should return target property in plugin schema.`);
60
- }
61
- const props = target.split(".");
62
- const mountProperty = props.pop();
63
- const targetNode = findTargetNode(props);
64
- if (!targetNode.hasOwnProperty(mountProperty)) {
65
- targetNode[mountProperty] = (0, import_lodash.cloneDeep)(schema);
66
- }
67
- }
68
- debug(`final validate schema: %o`, finalSchema);
69
- return finalSchema;
70
- };
71
- // Annotate the CommonJS export names for ESM import in node:
72
- 0 && (module.exports = {
73
- patchSchema
74
- });
@@ -1,2 +0,0 @@
1
- import { patchSchema } from './patchSchema';
2
- export declare const traverseSchema: (schema: ReturnType<typeof patchSchema>) => string[];
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var traverseSchema_exports = {};
20
- __export(traverseSchema_exports, {
21
- traverseSchema: () => traverseSchema
22
- });
23
- module.exports = __toCommonJS(traverseSchema_exports);
24
- const traverseSchema = (schema) => {
25
- const keys = [];
26
- const traverse = ({ properties }, old = []) => {
27
- for (const key of Object.keys(properties)) {
28
- const current = [
29
- ...old,
30
- key
31
- ];
32
- if (properties[key].type === "object" && properties[key].properties) {
33
- traverse(properties[key], current);
34
- } else {
35
- keys.push(current.join("."));
36
- }
37
- }
38
- };
39
- traverse(schema);
40
- return keys;
41
- };
42
- // Annotate the CommonJS export names for ESM import in node:
43
- 0 && (module.exports = {
44
- traverseSchema
45
- });
@@ -1,3 +0,0 @@
1
- import { UserConfig } from '../types';
2
- export declare const deepGet: (obj: any, key: string) => any;
3
- export declare const repeatKeyWarning: <E extends Record<string, any>>(schema: any, jsConfig: UserConfig<E>, pkgConfig: UserConfig<E>) => void;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var repeatKeyWarning_exports = {};
20
- __export(repeatKeyWarning_exports, {
21
- deepGet: () => deepGet,
22
- repeatKeyWarning: () => repeatKeyWarning
23
- });
24
- module.exports = __toCommonJS(repeatKeyWarning_exports);
25
- var import_traverseSchema = require("../schema/traverseSchema");
26
- const deepGet = (obj, key) => {
27
- for (const p of key.split(".")) {
28
- obj = obj ? obj[p] : void 0;
29
- }
30
- return obj;
31
- };
32
- const repeatKeyWarning = (schema, jsConfig, pkgConfig) => {
33
- const keys = (0, import_traverseSchema.traverseSchema)(schema);
34
- for (const key of keys) {
35
- if (deepGet(jsConfig, key) !== void 0 && deepGet(pkgConfig, key) !== void 0) {
36
- throw new Error(`The same configuration ${key} exists in modern.config.js and package.json.
37
- Please remove it from package.json.`);
38
- }
39
- }
40
- };
41
- // Annotate the CommonJS export names for ESM import in node:
42
- 0 && (module.exports = {
43
- deepGet,
44
- repeatKeyWarning
45
- });