@modern-js/core 2.5.1-alpha.0 → 2.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 2.6.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [e1f799e]
8
+ - Updated dependencies [7915ab3]
9
+ - Updated dependencies [0fe658a]
10
+ - @modern-js/utils@2.6.0
11
+ - @modern-js/node-bundle-require@2.6.0
12
+ - @modern-js/plugin@2.6.0
13
+
3
14
  ## 2.5.0
4
15
 
5
16
  ### Patch Changes
package/dist/context.d.ts CHANGED
@@ -26,7 +26,6 @@ export declare const initAppContext: ({ appDirectory, plugins, configFile, optio
26
26
  options?: {
27
27
  metaName?: string | undefined;
28
28
  srcDir?: string | undefined;
29
- apiDir?: string | undefined;
30
29
  distDir?: string | undefined;
31
30
  sharedDir?: string | undefined;
32
31
  } | undefined;
package/dist/context.js CHANGED
@@ -32,7 +32,7 @@ exports.useConfigContext = useConfigContext;
32
32
  const useResolvedConfigContext = () => exports.ResolvedConfigContext.use().value;
33
33
  exports.useResolvedConfigContext = useResolvedConfigContext;
34
34
  const initAppContext = ({ appDirectory, plugins, configFile, options, serverConfigFile, serverInternalPlugins, toolsType, }) => {
35
- const { metaName = 'modern-js', srcDir = 'src', distDir = '', apiDir = 'api', sharedDir = 'shared', } = options || {};
35
+ const { metaName = 'modern-js', srcDir = 'src', distDir = '', sharedDir = 'shared', } = options || {};
36
36
  return {
37
37
  metaName,
38
38
  appDirectory,
@@ -43,8 +43,6 @@ const initAppContext = ({ appDirectory, plugins, configFile, options, serverConf
43
43
  port: 0,
44
44
  packageName: require(path_1.default.resolve(appDirectory, './package.json')).name,
45
45
  srcDirectory: path_1.default.resolve(appDirectory, srcDir),
46
- apiDirectory: path_1.default.resolve(appDirectory, apiDir),
47
- lambdaDirectory: path_1.default.resolve(appDirectory, apiDir, 'lambda'),
48
46
  distDirectory: distDir,
49
47
  sharedDirectory: path_1.default.resolve(appDirectory, sharedDir),
50
48
  nodeModulesDirectory: path_1.default.resolve(appDirectory, './node_modules'),
@@ -13,8 +13,6 @@ export interface IAppContext {
13
13
  toolsType?: ToolsType;
14
14
  packageName: string;
15
15
  srcDirectory: string;
16
- apiDirectory: string;
17
- lambdaDirectory: string;
18
16
  sharedDirectory: string;
19
17
  nodeModulesDirectory: string;
20
18
  internalDirectory: string;
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "modern",
11
11
  "modern.js"
12
12
  ],
13
- "version": "2.5.1-alpha.0",
13
+ "version": "2.6.0",
14
14
  "jsnext:source": "./src/index.ts",
15
15
  "types": "./dist/index.d.ts",
16
16
  "main": "./dist/index.js",
@@ -50,17 +50,12 @@
50
50
  }
51
51
  },
52
52
  "dependencies": {
53
- "@modern-js/node-bundle-require": "2.5.0",
54
- "@modern-js/plugin": "2.5.0",
55
- "@modern-js/utils": "2.5.0"
53
+ "@modern-js/node-bundle-require": "2.6.0",
54
+ "@modern-js/plugin": "2.6.0",
55
+ "@modern-js/utils": "2.6.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@jest/types": "^27.0.6",
59
- "@modern-js/builder-shared": "2.5.0",
60
- "@modern-js/babel-preset-app": "2.5.0",
61
- "@modern-js/types": "2.5.0",
62
- "@scripts/build": "2.5.0",
63
- "@scripts/jest-config": "2.5.0",
64
59
  "@types/babel__code-frame": "^7.0.3",
65
60
  "@types/babel__core": "^7.1.16",
66
61
  "@types/jest": "^27",
@@ -74,7 +69,12 @@
74
69
  "sass": "^1.45.0",
75
70
  "terser-webpack-plugin": "^5.1.4",
76
71
  "typescript": "^4",
77
- "webpack": "^5.75.0"
72
+ "webpack": "^5.75.0",
73
+ "@modern-js/builder-shared": "2.6.0",
74
+ "@modern-js/babel-preset-app": "2.6.0",
75
+ "@modern-js/types": "2.6.0",
76
+ "@scripts/build": "2.6.0",
77
+ "@scripts/jest-config": "2.6.0"
78
78
  },
79
79
  "sideEffects": false,
80
80
  "publishConfig": {
@@ -1,34 +0,0 @@
1
- import path from 'path';
2
- export declare const CONFIG_FILE_NAME = "modern.config";
3
- export declare const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
4
- /**
5
- * Get user config from package.json.
6
- * @param appDirectory - App root directory.
7
- * @returns modernConfig or undefined
8
- */
9
- export declare const getPackageConfig: <T>(appDirectory: string, packageJsonConfig?: string) => T | undefined;
10
- /**
11
- * Get the file dependencies by module.children, ignore file path in node_modules and this monorepo packages default.
12
- * @param filePath - Absolute file path.
13
- * @returns File dependencies array.
14
- */
15
- export declare const getDependencies: (filePath: string) => string[];
16
- /**
17
- *
18
- * @param targetDir target dir
19
- * @param overtime Unit of second
20
- */
21
- export declare const clearFilesOverTime: (targetDir: string, overtime: number) => Promise<void>;
22
- export declare const getConfigFilePath: (appDirectory: string, filePath?: string) => string | false;
23
- /**
24
- * Parse and load user config file, support extensions like .ts, mjs, js, ejs.
25
- * @param appDirectory - App root directory, from which start search user config file.
26
- * @param filePath - Specific absolute config file path.
27
- * @returns Object contain config file path, user config object and dependency files used by config file.
28
- */
29
- export declare const loadConfig: <T>(appDirectory: string, filePath?: string, packageJsonConfig?: string) => Promise<{
30
- path: string | false;
31
- config?: T | undefined;
32
- dependencies?: string[] | undefined;
33
- pkgConfig?: T | undefined;
34
- }>;
@@ -1,124 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.loadConfig = exports.getConfigFilePath = exports.clearFilesOverTime = exports.getDependencies = exports.getPackageConfig = exports.PACKAGE_JSON_CONFIG_NAME = exports.CONFIG_FILE_NAME = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const utils_1 = require("@modern-js/utils");
9
- const node_bundle_require_1 = require("@modern-js/node-bundle-require");
10
- const debug = (0, utils_1.createDebugger)('load-config');
11
- exports.CONFIG_FILE_NAME = 'modern.config';
12
- exports.PACKAGE_JSON_CONFIG_NAME = 'modernConfig';
13
- /**
14
- * Get user config from package.json.
15
- * @param appDirectory - App root directory.
16
- * @returns modernConfig or undefined
17
- */
18
- const getPackageConfig = (appDirectory, packageJsonConfig) => {
19
- const json = JSON.parse(utils_1.fs.readFileSync(path_1.default.resolve(appDirectory, './package.json'), 'utf8'));
20
- return json[packageJsonConfig !== null && packageJsonConfig !== void 0 ? packageJsonConfig : exports.PACKAGE_JSON_CONFIG_NAME];
21
- };
22
- exports.getPackageConfig = getPackageConfig;
23
- /**
24
- * Get the file dependencies by module.children, ignore file path in node_modules and this monorepo packages default.
25
- * @param filePath - Absolute file path.
26
- * @returns File dependencies array.
27
- */
28
- const getDependencies = (filePath) => {
29
- const mod = require.cache[filePath];
30
- if (!mod) {
31
- debug(`${filePath} has not been required yet`);
32
- return [];
33
- }
34
- const deps = [];
35
- if (!/\/node_modules\/|\/modern-js\/packages\//.test(mod.id)) {
36
- deps.push(mod.id);
37
- for (const child of mod.children) {
38
- deps.push(...(0, exports.getDependencies)(child.id));
39
- }
40
- }
41
- return deps;
42
- };
43
- exports.getDependencies = getDependencies;
44
- /**
45
- *
46
- * @param targetDir target dir
47
- * @param overtime Unit of second
48
- */
49
- const clearFilesOverTime = async (targetDir, overtime) => {
50
- // when stats is true, globby return Stats[]
51
- const files = (await (0, utils_1.globby)(`${targetDir}/**/*`, {
52
- stats: true,
53
- absolute: true,
54
- }));
55
- const currentTime = Date.now();
56
- if (files.length > 0) {
57
- for (const file of files) {
58
- if (currentTime - file.stats.birthtimeMs >= overtime * 1000) {
59
- utils_1.fs.unlinkSync(file.path);
60
- }
61
- }
62
- }
63
- };
64
- exports.clearFilesOverTime = clearFilesOverTime;
65
- const bundleRequireWithCatch = async (configFile, { appDirectory }) => {
66
- try {
67
- const mod = await (0, node_bundle_require_1.bundleRequire)(configFile, {
68
- autoClear: false,
69
- getOutputFile: async (filePath) => {
70
- const defaultOutputFileName = path_1.default.basename(await (0, node_bundle_require_1.defaultGetOutputFile)(filePath));
71
- const outputPath = path_1.default.join(appDirectory, utils_1.CONFIG_CACHE_DIR);
72
- // 10 min
73
- const timeLimit = 10 * 60;
74
- await (0, exports.clearFilesOverTime)(outputPath, timeLimit);
75
- return path_1.default.join(outputPath, defaultOutputFileName);
76
- },
77
- });
78
- return mod;
79
- }
80
- catch (e) {
81
- if (e instanceof Error) {
82
- e.message = `Get Error while loading config file: ${configFile}, please check it and retry.\n${e.message || ''}`;
83
- }
84
- throw e;
85
- }
86
- };
87
- const getConfigFilePath = (appDirectory, filePath) => {
88
- if (filePath) {
89
- if (path_1.default.isAbsolute(filePath)) {
90
- return filePath;
91
- }
92
- return path_1.default.resolve(appDirectory, filePath);
93
- }
94
- return (0, utils_1.findExists)(utils_1.CONFIG_FILE_EXTENSIONS.map(extension => path_1.default.resolve(appDirectory, `${exports.CONFIG_FILE_NAME}${extension}`)));
95
- };
96
- exports.getConfigFilePath = getConfigFilePath;
97
- /**
98
- * Parse and load user config file, support extensions like .ts, mjs, js, ejs.
99
- * @param appDirectory - App root directory, from which start search user config file.
100
- * @param filePath - Specific absolute config file path.
101
- * @returns Object contain config file path, user config object and dependency files used by config file.
102
- */
103
- const loadConfig = async (appDirectory, filePath, packageJsonConfig) => {
104
- const configFile = (0, exports.getConfigFilePath)(appDirectory, filePath);
105
- const pkgConfig = (0, exports.getPackageConfig)(appDirectory, packageJsonConfig);
106
- let config;
107
- const dependencies = pkgConfig
108
- ? [path_1.default.resolve(appDirectory, './package.json')]
109
- : [];
110
- if (configFile) {
111
- delete require.cache[configFile];
112
- const mod = await bundleRequireWithCatch(configFile, { appDirectory });
113
- config = mod.default || mod;
114
- // TODO: get deps.
115
- // dependencies = dependencies.concat(getDependencies(configFile));
116
- }
117
- return {
118
- path: configFile,
119
- config,
120
- pkgConfig,
121
- dependencies,
122
- };
123
- };
124
- exports.loadConfig = loadConfig;