@modern-js/core 2.35.0 → 2.36.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.
- package/dist/bin.js +2 -5
- package/dist/config/createDefaultConfig.js +24 -7
- package/dist/config/createLoadedConfig.js +55 -37
- package/dist/config/createResolvedConfig.js +50 -25
- package/dist/config/index.js +24 -6
- package/dist/config/loadConfig.js +62 -49
- package/dist/context.js +61 -48
- package/dist/createCli.js +72 -60
- package/dist/index.js +57 -56
- package/dist/loadEnv.js +40 -14
- package/dist/loadPlugins.js +40 -31
- package/dist/manager.js +45 -36
- package/dist/nodeApi.js +31 -22
- package/dist/runBin.js +32 -18
- package/dist/schema/patchSchema.js +29 -12
- package/dist/schema/traverseSchema.js +24 -7
- package/dist/types/config/index.js +15 -3
- package/dist/types/context.d.ts +51 -12
- package/dist/types/context.js +15 -3
- package/dist/types/coreOptions.js +15 -3
- package/dist/types/hooks.js +15 -3
- package/dist/types/index.js +30 -9
- package/dist/types/plugin.js +15 -3
- package/dist/types/pluginAPI.js +15 -3
- package/dist/utils/checkIsDuplicationPlugin.js +27 -10
- package/dist/utils/commander.js +29 -19
- package/dist/utils/createFileWatcher.js +45 -20
- package/dist/utils/index.js +30 -9
- package/dist/utils/initAppDir.js +38 -12
- package/dist/utils/mergeConfig.js +32 -15
- package/dist/utils/repeatKeyWarning.js +27 -17
- package/package.json +8 -8
package/dist/bin.js
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var createDefaultConfig_exports = {};
|
|
20
|
+
__export(createDefaultConfig_exports, {
|
|
21
|
+
createDefaultConfig: () => createDefaultConfig
|
|
10
22
|
});
|
|
23
|
+
module.exports = __toCommonJS(createDefaultConfig_exports);
|
|
11
24
|
function createDefaultConfig() {
|
|
12
25
|
return {
|
|
13
26
|
autoLoadPlugins: false
|
|
14
27
|
};
|
|
15
28
|
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
createDefaultConfig
|
|
32
|
+
});
|
|
@@ -1,30 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
6
9
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return assignPkgConfig;
|
|
15
|
-
},
|
|
16
|
-
createLoadedConfig: function() {
|
|
17
|
-
return createLoadedConfig;
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var createLoadedConfig_exports = {};
|
|
30
|
+
__export(createLoadedConfig_exports, {
|
|
31
|
+
assignPkgConfig: () => assignPkgConfig,
|
|
32
|
+
createLoadedConfig: () => createLoadedConfig
|
|
19
33
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0,
|
|
27
|
-
if (objValue === void 0 && (0,
|
|
34
|
+
module.exports = __toCommonJS(createLoadedConfig_exports);
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_lodash = require("@modern-js/utils/lodash");
|
|
37
|
+
var import_utils = require("@modern-js/utils");
|
|
38
|
+
var import_utils2 = require("../utils");
|
|
39
|
+
var import_loadConfig = require("./loadConfig");
|
|
40
|
+
const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0, import_lodash.mergeWith)({}, userConfig, pkgConfig, (objValue, srcValue) => {
|
|
41
|
+
if (objValue === void 0 && (0, import_utils.isPlainObject)(srcValue)) {
|
|
28
42
|
return {
|
|
29
43
|
...srcValue
|
|
30
44
|
};
|
|
@@ -34,8 +48,8 @@ const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0, _lodash.mergeWi
|
|
|
34
48
|
async function getConfigObject(config) {
|
|
35
49
|
if (typeof config === "function") {
|
|
36
50
|
return await config({
|
|
37
|
-
env: (0,
|
|
38
|
-
command: (0,
|
|
51
|
+
env: (0, import_utils.getNodeEnv)(),
|
|
52
|
+
command: (0, import_utils.getCommand)()
|
|
39
53
|
}) || {};
|
|
40
54
|
}
|
|
41
55
|
return config || {};
|
|
@@ -43,40 +57,39 @@ async function getConfigObject(config) {
|
|
|
43
57
|
async function loadLocalConfig(appDirectory, configFile) {
|
|
44
58
|
let localConfigFile = false;
|
|
45
59
|
if (typeof configFile === "string") {
|
|
46
|
-
for (const ext of
|
|
60
|
+
for (const ext of import_utils.CONFIG_FILE_EXTENSIONS) {
|
|
47
61
|
if (configFile.endsWith(ext)) {
|
|
48
62
|
const replacedPath = configFile.replace(ext, `.local${ext}`);
|
|
49
|
-
if (
|
|
63
|
+
if (import_utils.fs.existsSync(replacedPath)) {
|
|
50
64
|
localConfigFile = replacedPath;
|
|
51
65
|
}
|
|
52
66
|
}
|
|
53
67
|
}
|
|
54
68
|
} else {
|
|
55
|
-
localConfigFile = (0,
|
|
69
|
+
localConfigFile = (0, import_utils.findExists)(import_utils.CONFIG_FILE_EXTENSIONS.map((extension) => import_path.default.resolve(appDirectory, `${import_loadConfig.LOCAL_CONFIG_FILE_NAME}${extension}`)));
|
|
56
70
|
}
|
|
57
71
|
if (localConfigFile) {
|
|
58
|
-
const loaded = await (0,
|
|
72
|
+
const loaded = await (0, import_loadConfig.loadConfig)(appDirectory, localConfigFile);
|
|
59
73
|
return getConfigObject(loaded.config);
|
|
60
74
|
}
|
|
61
75
|
return null;
|
|
62
76
|
}
|
|
63
77
|
async function createLoadedConfig(appDirectory, filePath, packageJsonConfig, loadedConfig) {
|
|
64
|
-
const configFile = (0,
|
|
65
|
-
const loaded = await (0,
|
|
78
|
+
const configFile = (0, import_loadConfig.getConfigFilePath)(appDirectory, filePath);
|
|
79
|
+
const loaded = await (0, import_loadConfig.loadConfig)(appDirectory, configFile, packageJsonConfig, loadedConfig);
|
|
66
80
|
if (!loaded.config && !loaded.pkgConfig) {
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
import_utils.logger.warn(`Can not find any config file in the current project, please check if you have a correct config file.`);
|
|
82
|
+
import_utils.logger.warn(`Current project path: ${import_utils.chalk.yellow(appDirectory)}`);
|
|
69
83
|
}
|
|
70
84
|
const config = await getConfigObject(loaded.config);
|
|
71
85
|
let mergedConfig = config;
|
|
72
86
|
if (loaded.pkgConfig) {
|
|
73
|
-
|
|
74
|
-
mergedConfig = assignPkgConfig(config, (_loaded = loaded) === null || _loaded === void 0 ? void 0 : _loaded.pkgConfig);
|
|
87
|
+
mergedConfig = assignPkgConfig(config, loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig);
|
|
75
88
|
}
|
|
76
|
-
if ((0,
|
|
89
|
+
if ((0, import_utils.isDevCommand)()) {
|
|
77
90
|
const localConfig = await loadLocalConfig(appDirectory, configFile);
|
|
78
91
|
if (localConfig) {
|
|
79
|
-
mergedConfig = (0,
|
|
92
|
+
mergedConfig = (0, import_utils2.mergeConfig)([
|
|
80
93
|
mergedConfig,
|
|
81
94
|
localConfig
|
|
82
95
|
]);
|
|
@@ -90,3 +103,8 @@ async function createLoadedConfig(appDirectory, filePath, packageJsonConfig, loa
|
|
|
90
103
|
jsConfig: config || {}
|
|
91
104
|
};
|
|
92
105
|
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
assignPkgConfig,
|
|
109
|
+
createLoadedConfig
|
|
110
|
+
});
|
|
@@ -1,34 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var createResolvedConfig_exports = {};
|
|
30
|
+
__export(createResolvedConfig_exports, {
|
|
31
|
+
createResolveConfig: () => createResolveConfig
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const debug = (0,
|
|
33
|
+
module.exports = __toCommonJS(createResolvedConfig_exports);
|
|
34
|
+
var import_utils = require("@modern-js/utils");
|
|
35
|
+
var import_patchSchema = require("../schema/patchSchema");
|
|
36
|
+
var import_repeatKeyWarning = require("../utils/repeatKeyWarning");
|
|
37
|
+
var import_mergeConfig = require("../utils/mergeConfig");
|
|
38
|
+
var import_createDefaultConfig = require("./createDefaultConfig");
|
|
39
|
+
const debug = (0, import_utils.createDebugger)("resolve-config");
|
|
18
40
|
const createResolveConfig = async (loaded, configs, schemas, onSchemaError) => {
|
|
19
41
|
var _validate_errors;
|
|
20
|
-
const { default: Ajv } = await Promise.resolve().then(() =>
|
|
21
|
-
const { default: ajvKeywords } = await Promise.resolve().then(() =>
|
|
22
|
-
const { default: betterAjvErrors } = await Promise.resolve().then(() =>
|
|
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")));
|
|
23
45
|
const { config: userConfig, jsConfig, pkgConfig } = loaded;
|
|
24
46
|
const ajv = new Ajv({
|
|
25
47
|
$data: true,
|
|
26
48
|
strict: false
|
|
27
49
|
});
|
|
28
50
|
ajvKeywords(ajv);
|
|
29
|
-
const validateSchema = (0,
|
|
51
|
+
const validateSchema = (0, import_patchSchema.patchSchema)(schemas);
|
|
30
52
|
const validate = ajv.compile(validateSchema);
|
|
31
|
-
(0,
|
|
53
|
+
(0, import_repeatKeyWarning.repeatKeyWarning)(validateSchema, jsConfig, pkgConfig);
|
|
32
54
|
const valid = validate(userConfig);
|
|
33
55
|
const formatValidateError = (config) => {
|
|
34
56
|
var _validate_errors2;
|
|
@@ -41,25 +63,28 @@ const createResolveConfig = async (loaded, configs, schemas, onSchemaError) => {
|
|
|
41
63
|
};
|
|
42
64
|
if (!valid && ((_validate_errors = validate.errors) === null || _validate_errors === void 0 ? void 0 : _validate_errors.length)) {
|
|
43
65
|
if (onSchemaError) {
|
|
44
|
-
|
|
45
|
-
await onSchemaError((_validate = validate) === null || _validate === void 0 ? void 0 : _validate.errors[0]);
|
|
66
|
+
await onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
|
|
46
67
|
}
|
|
47
68
|
const errors = formatValidateError(userConfig);
|
|
48
|
-
|
|
69
|
+
import_utils.logger.log(errors);
|
|
49
70
|
throw new Error(`Validate configuration error`);
|
|
50
71
|
}
|
|
51
72
|
for (const config of configs) {
|
|
52
73
|
if (!validate(config)) {
|
|
53
74
|
const errors = formatValidateError(config);
|
|
54
|
-
|
|
75
|
+
import_utils.logger.error(errors);
|
|
55
76
|
throw new Error(`Validate configuration error.`);
|
|
56
77
|
}
|
|
57
78
|
}
|
|
58
|
-
const resolved = (0,
|
|
59
|
-
(0,
|
|
79
|
+
const resolved = (0, import_mergeConfig.mergeConfig)([
|
|
80
|
+
(0, import_createDefaultConfig.createDefaultConfig)(),
|
|
60
81
|
...configs,
|
|
61
82
|
userConfig
|
|
62
83
|
]);
|
|
63
84
|
debug("resolved %o", resolved);
|
|
64
85
|
return resolved;
|
|
65
86
|
};
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
createResolveConfig
|
|
90
|
+
});
|
package/dist/config/index.js
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var config_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(config_exports);
|
|
18
|
+
__reExport(config_exports, require("./createLoadedConfig"), module.exports);
|
|
19
|
+
__reExport(config_exports, require("./createResolvedConfig"), module.exports);
|
|
20
|
+
__reExport(config_exports, require("./createDefaultConfig"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("./createLoadedConfig"),
|
|
24
|
+
...require("./createResolvedConfig"),
|
|
25
|
+
...require("./createDefaultConfig")
|
|
4
26
|
});
|
|
5
|
-
const _export_star = require("@swc/helpers/_/_export_star");
|
|
6
|
-
_export_star._(require("./createLoadedConfig"), exports);
|
|
7
|
-
_export_star._(require("./createResolvedConfig"), exports);
|
|
8
|
-
_export_star._(require("./createDefaultConfig"), exports);
|
|
@@ -1,50 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
6
9
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return CONFIG_FILE_NAME;
|
|
15
|
-
},
|
|
16
|
-
LOCAL_CONFIG_FILE_NAME: function() {
|
|
17
|
-
return LOCAL_CONFIG_FILE_NAME;
|
|
18
|
-
},
|
|
19
|
-
PACKAGE_JSON_CONFIG_NAME: function() {
|
|
20
|
-
return PACKAGE_JSON_CONFIG_NAME;
|
|
21
|
-
},
|
|
22
|
-
getPackageConfig: function() {
|
|
23
|
-
return getPackageConfig;
|
|
24
|
-
},
|
|
25
|
-
getDependencies: function() {
|
|
26
|
-
return getDependencies;
|
|
27
|
-
},
|
|
28
|
-
clearFilesOverTime: function() {
|
|
29
|
-
return clearFilesOverTime;
|
|
30
|
-
},
|
|
31
|
-
getConfigFilePath: function() {
|
|
32
|
-
return getConfigFilePath;
|
|
33
|
-
},
|
|
34
|
-
loadConfig: function() {
|
|
35
|
-
return loadConfig;
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
36
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var loadConfig_exports = {};
|
|
30
|
+
__export(loadConfig_exports, {
|
|
31
|
+
CONFIG_FILE_NAME: () => CONFIG_FILE_NAME,
|
|
32
|
+
LOCAL_CONFIG_FILE_NAME: () => LOCAL_CONFIG_FILE_NAME,
|
|
33
|
+
PACKAGE_JSON_CONFIG_NAME: () => PACKAGE_JSON_CONFIG_NAME,
|
|
34
|
+
clearFilesOverTime: () => clearFilesOverTime,
|
|
35
|
+
getConfigFilePath: () => getConfigFilePath,
|
|
36
|
+
getDependencies: () => getDependencies,
|
|
37
|
+
getPackageConfig: () => getPackageConfig,
|
|
38
|
+
loadConfig: () => loadConfig
|
|
37
39
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const debug = (0,
|
|
40
|
+
module.exports = __toCommonJS(loadConfig_exports);
|
|
41
|
+
var import_path = __toESM(require("path"));
|
|
42
|
+
var import_utils = require("@modern-js/utils");
|
|
43
|
+
var import_node_bundle_require = require("@modern-js/node-bundle-require");
|
|
44
|
+
const debug = (0, import_utils.createDebugger)("load-config");
|
|
43
45
|
const CONFIG_FILE_NAME = "modern.config";
|
|
44
46
|
const LOCAL_CONFIG_FILE_NAME = "modern.config.local";
|
|
45
47
|
const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
|
|
46
48
|
const getPackageConfig = (appDirectory, packageJsonConfig) => {
|
|
47
|
-
const json = JSON.parse(
|
|
49
|
+
const json = JSON.parse(import_utils.fs.readFileSync(import_path.default.resolve(appDirectory, "./package.json"), "utf8"));
|
|
48
50
|
return json[packageJsonConfig !== null && packageJsonConfig !== void 0 ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
|
|
49
51
|
};
|
|
50
52
|
const getDependencies = (filePath) => {
|
|
@@ -64,7 +66,7 @@ const getDependencies = (filePath) => {
|
|
|
64
66
|
};
|
|
65
67
|
const clearFilesOverTime = async (targetDir, overtime) => {
|
|
66
68
|
try {
|
|
67
|
-
const files = await (0,
|
|
69
|
+
const files = await (0, import_utils.globby)(`${targetDir}/**/*`, {
|
|
68
70
|
stats: true,
|
|
69
71
|
absolute: true
|
|
70
72
|
});
|
|
@@ -72,7 +74,7 @@ const clearFilesOverTime = async (targetDir, overtime) => {
|
|
|
72
74
|
if (files.length > 0) {
|
|
73
75
|
for (const file of files) {
|
|
74
76
|
if (currentTime - file.stats.birthtimeMs >= overtime * 1e3) {
|
|
75
|
-
|
|
77
|
+
import_utils.fs.unlinkSync(file.path);
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
}
|
|
@@ -81,14 +83,14 @@ const clearFilesOverTime = async (targetDir, overtime) => {
|
|
|
81
83
|
};
|
|
82
84
|
const bundleRequireWithCatch = async (configFile, { appDirectory }) => {
|
|
83
85
|
try {
|
|
84
|
-
const mod = await (0,
|
|
86
|
+
const mod = await (0, import_node_bundle_require.bundleRequire)(configFile, {
|
|
85
87
|
autoClear: false,
|
|
86
88
|
getOutputFile: async (filePath) => {
|
|
87
|
-
const defaultOutputFileName =
|
|
88
|
-
const outputPath =
|
|
89
|
+
const defaultOutputFileName = import_path.default.basename(await (0, import_node_bundle_require.defaultGetOutputFile)(filePath));
|
|
90
|
+
const outputPath = import_path.default.join(appDirectory, import_utils.CONFIG_CACHE_DIR);
|
|
89
91
|
const timeLimit = 10 * 60;
|
|
90
92
|
await clearFilesOverTime(outputPath, timeLimit);
|
|
91
|
-
return
|
|
93
|
+
return import_path.default.join(outputPath, defaultOutputFileName);
|
|
92
94
|
}
|
|
93
95
|
});
|
|
94
96
|
return mod;
|
|
@@ -102,18 +104,18 @@ ${e.message || ""}`;
|
|
|
102
104
|
};
|
|
103
105
|
const getConfigFilePath = (appDirectory, filePath) => {
|
|
104
106
|
if (filePath) {
|
|
105
|
-
if (
|
|
107
|
+
if (import_path.default.isAbsolute(filePath)) {
|
|
106
108
|
return filePath;
|
|
107
109
|
}
|
|
108
|
-
return
|
|
110
|
+
return import_path.default.resolve(appDirectory, filePath);
|
|
109
111
|
}
|
|
110
|
-
return (0,
|
|
112
|
+
return (0, import_utils.findExists)(import_utils.CONFIG_FILE_EXTENSIONS.map((extension) => import_path.default.resolve(appDirectory, `${CONFIG_FILE_NAME}${extension}`)));
|
|
111
113
|
};
|
|
112
114
|
const loadConfig = async (appDirectory, configFile, packageJsonConfig, loadedConfig) => {
|
|
113
115
|
const pkgConfig = getPackageConfig(appDirectory, packageJsonConfig);
|
|
114
116
|
let config;
|
|
115
117
|
const dependencies = pkgConfig ? [
|
|
116
|
-
|
|
118
|
+
import_path.default.resolve(appDirectory, "./package.json")
|
|
117
119
|
] : [];
|
|
118
120
|
if (loadedConfig) {
|
|
119
121
|
config = loadedConfig;
|
|
@@ -131,3 +133,14 @@ const loadConfig = async (appDirectory, configFile, packageJsonConfig, loadedCon
|
|
|
131
133
|
dependencies
|
|
132
134
|
};
|
|
133
135
|
};
|
|
136
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
137
|
+
0 && (module.exports = {
|
|
138
|
+
CONFIG_FILE_NAME,
|
|
139
|
+
LOCAL_CONFIG_FILE_NAME,
|
|
140
|
+
PACKAGE_JSON_CONFIG_NAME,
|
|
141
|
+
clearFilesOverTime,
|
|
142
|
+
getConfigFilePath,
|
|
143
|
+
getDependencies,
|
|
144
|
+
getPackageConfig,
|
|
145
|
+
loadConfig
|
|
146
|
+
});
|
package/dist/context.js
CHANGED
|
@@ -1,47 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
6
9
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return AppContext;
|
|
15
|
-
},
|
|
16
|
-
ConfigContext: function() {
|
|
17
|
-
return ConfigContext;
|
|
18
|
-
},
|
|
19
|
-
ResolvedConfigContext: function() {
|
|
20
|
-
return ResolvedConfigContext;
|
|
21
|
-
},
|
|
22
|
-
setAppContext: function() {
|
|
23
|
-
return setAppContext;
|
|
24
|
-
},
|
|
25
|
-
useAppContext: function() {
|
|
26
|
-
return useAppContext;
|
|
27
|
-
},
|
|
28
|
-
useConfigContext: function() {
|
|
29
|
-
return useConfigContext;
|
|
30
|
-
},
|
|
31
|
-
useResolvedConfigContext: function() {
|
|
32
|
-
return useResolvedConfigContext;
|
|
33
|
-
},
|
|
34
|
-
initAppContext: function() {
|
|
35
|
-
return initAppContext;
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
36
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var context_exports = {};
|
|
30
|
+
__export(context_exports, {
|
|
31
|
+
AppContext: () => AppContext,
|
|
32
|
+
ConfigContext: () => ConfigContext,
|
|
33
|
+
ResolvedConfigContext: () => ResolvedConfigContext,
|
|
34
|
+
initAppContext: () => initAppContext,
|
|
35
|
+
setAppContext: () => setAppContext,
|
|
36
|
+
useAppContext: () => useAppContext,
|
|
37
|
+
useConfigContext: () => useConfigContext,
|
|
38
|
+
useResolvedConfigContext: () => useResolvedConfigContext
|
|
37
39
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const AppContext = (0,
|
|
43
|
-
const ConfigContext = (0,
|
|
44
|
-
const ResolvedConfigContext = (0,
|
|
40
|
+
module.exports = __toCommonJS(context_exports);
|
|
41
|
+
var import_path = __toESM(require("path"));
|
|
42
|
+
var import_utils = require("@modern-js/utils");
|
|
43
|
+
var import_plugin = require("@modern-js/plugin");
|
|
44
|
+
const AppContext = (0, import_plugin.createContext)({});
|
|
45
|
+
const ConfigContext = (0, import_plugin.createContext)({});
|
|
46
|
+
const ResolvedConfigContext = (0, import_plugin.createContext)({});
|
|
45
47
|
const setAppContext = (value) => AppContext.set(value);
|
|
46
48
|
const useAppContext = () => AppContext.use().value;
|
|
47
49
|
const useConfigContext = () => ConfigContext.use().value;
|
|
@@ -54,16 +56,16 @@ const initAppContext = ({ appDirectory, plugins, configFile, options, serverConf
|
|
|
54
56
|
configFile,
|
|
55
57
|
serverConfigFile,
|
|
56
58
|
serverInternalPlugins,
|
|
57
|
-
ip:
|
|
59
|
+
ip: import_utils.address.ip(),
|
|
58
60
|
port: 0,
|
|
59
|
-
packageName: require(
|
|
60
|
-
srcDirectory:
|
|
61
|
-
apiDirectory:
|
|
62
|
-
lambdaDirectory:
|
|
61
|
+
packageName: require(import_path.default.resolve(appDirectory, "./package.json")).name,
|
|
62
|
+
srcDirectory: import_path.default.resolve(appDirectory, srcDir),
|
|
63
|
+
apiDirectory: import_path.default.resolve(appDirectory, apiDir),
|
|
64
|
+
lambdaDirectory: import_path.default.resolve(appDirectory, apiDir, "lambda"),
|
|
63
65
|
distDirectory: distDir,
|
|
64
|
-
sharedDirectory:
|
|
65
|
-
nodeModulesDirectory:
|
|
66
|
-
internalDirectory:
|
|
66
|
+
sharedDirectory: import_path.default.resolve(appDirectory, sharedDir),
|
|
67
|
+
nodeModulesDirectory: import_path.default.resolve(appDirectory, "./node_modules"),
|
|
68
|
+
internalDirectory: import_path.default.resolve(appDirectory, `./node_modules/.${metaName}`),
|
|
67
69
|
plugins,
|
|
68
70
|
htmlTemplates: {},
|
|
69
71
|
serverRoutes: [],
|
|
@@ -74,3 +76,14 @@ const initAppContext = ({ appDirectory, plugins, configFile, options, serverConf
|
|
|
74
76
|
internalSrcAlias: `@_${metaName.replace(/-/g, "_")}_src`
|
|
75
77
|
};
|
|
76
78
|
};
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
AppContext,
|
|
82
|
+
ConfigContext,
|
|
83
|
+
ResolvedConfigContext,
|
|
84
|
+
initAppContext,
|
|
85
|
+
setAppContext,
|
|
86
|
+
useAppContext,
|
|
87
|
+
useConfigContext,
|
|
88
|
+
useResolvedConfigContext
|
|
89
|
+
});
|