@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 CHANGED
@@ -1,7 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- const _runBin = require("./runBin");
7
- (0, _runBin.run)();
3
+ var import_runBin = require("./runBin");
4
+ (0, import_runBin.run)();
@@ -1,15 +1,32 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "createDefaultConfig", {
6
- enumerable: true,
7
- get: function() {
8
- return createDefaultConfig;
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.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
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
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- assignPkgConfig: function() {
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
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
21
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
22
- const _lodash = require("@modern-js/utils/lodash");
23
- const _utils = require("@modern-js/utils");
24
- const _utils1 = require("../utils");
25
- const _loadConfig = require("./loadConfig");
26
- const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0, _lodash.mergeWith)({}, userConfig, pkgConfig, (objValue, srcValue) => {
27
- if (objValue === void 0 && (0, _utils.isPlainObject)(srcValue)) {
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, _utils.getNodeEnv)(),
38
- command: (0, _utils.getCommand)()
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 _utils.CONFIG_FILE_EXTENSIONS) {
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 (_utils.fs.existsSync(replacedPath)) {
63
+ if (import_utils.fs.existsSync(replacedPath)) {
50
64
  localConfigFile = replacedPath;
51
65
  }
52
66
  }
53
67
  }
54
68
  } else {
55
- localConfigFile = (0, _utils.findExists)(_utils.CONFIG_FILE_EXTENSIONS.map((extension) => _path.default.resolve(appDirectory, `${_loadConfig.LOCAL_CONFIG_FILE_NAME}${extension}`)));
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, _loadConfig.loadConfig)(appDirectory, localConfigFile);
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, _loadConfig.getConfigFilePath)(appDirectory, filePath);
65
- const loaded = await (0, _loadConfig.loadConfig)(appDirectory, configFile, packageJsonConfig, loadedConfig);
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
- _utils.logger.warn(`Can not find any config file in the current project, please check if you have a correct config file.`);
68
- _utils.logger.warn(`Current project path: ${_utils.chalk.yellow(appDirectory)}`);
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
- var _loaded;
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, _utils.isDevCommand)()) {
89
+ if ((0, import_utils.isDevCommand)()) {
77
90
  const localConfig = await loadLocalConfig(appDirectory, configFile);
78
91
  if (localConfig) {
79
- mergedConfig = (0, _utils1.mergeConfig)([
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.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "createResolveConfig", {
6
- enumerable: true,
7
- get: function() {
8
- return createResolveConfig;
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
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
- const _utils = require("@modern-js/utils");
13
- const _patchSchema = require("../schema/patchSchema");
14
- const _repeatKeyWarning = require("../utils/repeatKeyWarning");
15
- const _mergeConfig = require("../utils/mergeConfig");
16
- const _createDefaultConfig = require("./createDefaultConfig");
17
- const debug = (0, _utils.createDebugger)("resolve-config");
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(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils/ajv")));
21
- const { default: ajvKeywords } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils/ajv-keywords")));
22
- const { default: betterAjvErrors } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils/better-ajv-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")));
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, _patchSchema.patchSchema)(schemas);
51
+ const validateSchema = (0, import_patchSchema.patchSchema)(schemas);
30
52
  const validate = ajv.compile(validateSchema);
31
- (0, _repeatKeyWarning.repeatKeyWarning)(validateSchema, jsConfig, pkgConfig);
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
- var _validate;
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
- _utils.logger.log(errors);
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
- _utils.logger.error(errors);
75
+ import_utils.logger.error(errors);
55
76
  throw new Error(`Validate configuration error.`);
56
77
  }
57
78
  }
58
- const resolved = (0, _mergeConfig.mergeConfig)([
59
- (0, _createDefaultConfig.createDefaultConfig)(),
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
+ });
@@ -1,8 +1,26 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
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.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
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
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- CONFIG_FILE_NAME: function() {
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
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
39
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
40
- const _utils = require("@modern-js/utils");
41
- const _nodebundlerequire = require("@modern-js/node-bundle-require");
42
- const debug = (0, _utils.createDebugger)("load-config");
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(_utils.fs.readFileSync(_path.default.resolve(appDirectory, "./package.json"), "utf8"));
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, _utils.globby)(`${targetDir}/**/*`, {
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
- _utils.fs.unlinkSync(file.path);
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, _nodebundlerequire.bundleRequire)(configFile, {
86
+ const mod = await (0, import_node_bundle_require.bundleRequire)(configFile, {
85
87
  autoClear: false,
86
88
  getOutputFile: async (filePath) => {
87
- const defaultOutputFileName = _path.default.basename(await (0, _nodebundlerequire.defaultGetOutputFile)(filePath));
88
- const outputPath = _path.default.join(appDirectory, _utils.CONFIG_CACHE_DIR);
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 _path.default.join(outputPath, defaultOutputFileName);
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 (_path.default.isAbsolute(filePath)) {
107
+ if (import_path.default.isAbsolute(filePath)) {
106
108
  return filePath;
107
109
  }
108
- return _path.default.resolve(appDirectory, filePath);
110
+ return import_path.default.resolve(appDirectory, filePath);
109
111
  }
110
- return (0, _utils.findExists)(_utils.CONFIG_FILE_EXTENSIONS.map((extension) => _path.default.resolve(appDirectory, `${CONFIG_FILE_NAME}${extension}`)));
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
- _path.default.resolve(appDirectory, "./package.json")
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.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
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
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- AppContext: function() {
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
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
39
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
40
- const _utils = require("@modern-js/utils");
41
- const _plugin = require("@modern-js/plugin");
42
- const AppContext = (0, _plugin.createContext)({});
43
- const ConfigContext = (0, _plugin.createContext)({});
44
- const ResolvedConfigContext = (0, _plugin.createContext)({});
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: _utils.address.ip(),
59
+ ip: import_utils.address.ip(),
58
60
  port: 0,
59
- packageName: require(_path.default.resolve(appDirectory, "./package.json")).name,
60
- srcDirectory: _path.default.resolve(appDirectory, srcDir),
61
- apiDirectory: _path.default.resolve(appDirectory, apiDir),
62
- lambdaDirectory: _path.default.resolve(appDirectory, apiDir, "lambda"),
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: _path.default.resolve(appDirectory, sharedDir),
65
- nodeModulesDirectory: _path.default.resolve(appDirectory, "./node_modules"),
66
- internalDirectory: _path.default.resolve(appDirectory, `./node_modules/.${metaName}`),
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
+ });