@modern-js/babel-compiler 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/cjs/build.js +33 -16
- package/dist/cjs/buildWatch.js +57 -40
- package/dist/cjs/compiler.js +57 -41
- package/dist/cjs/compilerErrorResult.js +27 -11
- package/dist/cjs/constants.js +24 -7
- package/dist/cjs/defaults.js +26 -9
- package/dist/cjs/getFinalOption.js +38 -30
- package/dist/cjs/index.js +37 -17
- package/dist/cjs/type.js +15 -3
- package/dist/cjs/utils.js +36 -10
- package/dist/cjs/validate.js +34 -27
- package/dist/esm/build.js +14 -11
- package/dist/esm/buildWatch.js +11 -5
- package/dist/esm/compiler.js +20 -15
- package/dist/esm/compilerErrorResult.js +5 -3
- package/dist/esm/constants.js +4 -1
- package/dist/esm/defaults.js +4 -1
- package/dist/esm/getFinalOption.js +15 -9
- package/dist/esm/index.js +4 -1
- package/dist/esm/type.js +0 -1
- package/dist/esm/utils.js +4 -1
- package/dist/esm/validate.js +12 -5
- package/dist/esm-node/build.js +4 -1
- package/dist/esm-node/buildWatch.js +10 -4
- package/dist/esm-node/compiler.js +11 -6
- package/dist/esm-node/compilerErrorResult.js +5 -3
- package/dist/esm-node/constants.js +4 -1
- package/dist/esm-node/defaults.js +4 -1
- package/dist/esm-node/getFinalOption.js +10 -4
- package/dist/esm-node/index.js +4 -1
- package/dist/esm-node/type.js +0 -1
- package/dist/esm-node/utils.js +4 -1
- package/dist/esm-node/validate.js +12 -5
- package/package.json +4 -4
|
@@ -4,13 +4,13 @@ import { logger, fs } from "@modern-js/utils";
|
|
|
4
4
|
import * as utils from "./utils";
|
|
5
5
|
import { defaultDistFileExtMap } from "./constants";
|
|
6
6
|
const defaultDistDir = "dist";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const isRes = (r) => Boolean(r);
|
|
8
|
+
const getDistFilePath = (option) => {
|
|
9
9
|
const { filepath, rootDir, distDir, extMap } = option;
|
|
10
10
|
const ext = path.extname(filepath);
|
|
11
11
|
return path.join(distDir, path.relative(rootDir, filepath).replace(ext, extMap[ext]));
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
const resolveSourceMap = (option) => {
|
|
14
14
|
const { babelRes, sourceFilePath, distFilePath, enableVirtualDist = false } = option;
|
|
15
15
|
const mapLoc = `${distFilePath}.map`;
|
|
16
16
|
babelRes.code = utils.addSourceMappingUrl(babelRes.code, mapLoc);
|
|
@@ -31,8 +31,7 @@ export const resolveSourceMap = (option) => {
|
|
|
31
31
|
fs.writeFileSync(mapLoc, JSON.stringify(babelRes.map));
|
|
32
32
|
return sourceMapVirtualDist;
|
|
33
33
|
};
|
|
34
|
-
|
|
35
|
-
var _babelRes;
|
|
34
|
+
const compiler = (option) => {
|
|
36
35
|
const { filepath, rootDir, enableVirtualDist = false, distDir = path.join(path.dirname(rootDir), defaultDistDir), verbose = false, babelConfig = {}, distFileExtMap = defaultDistFileExtMap, quiet = false } = option;
|
|
37
36
|
const babelRes = babel.transformFileSync(filepath, babelConfig);
|
|
38
37
|
let virtualDist = null;
|
|
@@ -53,7 +52,7 @@ export const compiler = (option) => {
|
|
|
53
52
|
sourcemap: ""
|
|
54
53
|
};
|
|
55
54
|
}
|
|
56
|
-
if ((
|
|
55
|
+
if ((babelRes === null || babelRes === void 0 ? void 0 : babelRes.map) && babelConfig.sourceMaps && babelConfig.sourceMaps !== "inline") {
|
|
57
56
|
if (virtualDist) {
|
|
58
57
|
virtualDist = {
|
|
59
58
|
...virtualDist,
|
|
@@ -88,3 +87,9 @@ export const compiler = (option) => {
|
|
|
88
87
|
}
|
|
89
88
|
return virtualDist;
|
|
90
89
|
};
|
|
90
|
+
export {
|
|
91
|
+
compiler,
|
|
92
|
+
getDistFilePath,
|
|
93
|
+
isRes,
|
|
94
|
+
resolveSourceMap
|
|
95
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
|
|
2
|
+
class CompilerErrorResult {
|
|
3
3
|
init(initErrorResult) {
|
|
4
|
-
|
|
5
|
-
this._messageDetails = ((_initErrorResult = initErrorResult) === null || _initErrorResult === void 0 ? void 0 : _initErrorResult.messageDetails) || [];
|
|
4
|
+
this._messageDetails = (initErrorResult === null || initErrorResult === void 0 ? void 0 : initErrorResult.messageDetails) || [];
|
|
6
5
|
}
|
|
7
6
|
update(messageDetails) {
|
|
8
7
|
for (const messageDetail of messageDetails) {
|
|
@@ -37,3 +36,6 @@ export class CompilerErrorResult {
|
|
|
37
36
|
this.init(initErrorResult);
|
|
38
37
|
}
|
|
39
38
|
}
|
|
39
|
+
export {
|
|
40
|
+
CompilerErrorResult
|
|
41
|
+
};
|
|
@@ -10,7 +10,10 @@ const defaultOptions = {
|
|
|
10
10
|
verbose: false,
|
|
11
11
|
clean: false
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
const mergeDefaultOption = (compilerOptions) => ({
|
|
14
14
|
...defaultOptions,
|
|
15
15
|
...compilerOptions
|
|
16
16
|
});
|
|
17
|
+
export {
|
|
18
|
+
mergeDefaultOption
|
|
19
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { glob } from "@modern-js/utils";
|
|
2
2
|
import { DEFAULT_EXTENSIONS } from "@babel/core";
|
|
3
3
|
import { mergeDefaultOption } from "./defaults";
|
|
4
|
-
|
|
4
|
+
const getGlobPattern = (dir, extensions) => {
|
|
5
5
|
if (extensions.length > 1) {
|
|
6
6
|
return `${dir}/**/*{${extensions.join(",")}}`;
|
|
7
7
|
} else if (extensions.length === 1) {
|
|
@@ -10,7 +10,7 @@ export const getGlobPattern = (dir, extensions) => {
|
|
|
10
10
|
return `${dir}/**/*`;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
const getFinalExtensions = (extensions) => {
|
|
14
14
|
const isExtensions = (ext) => Array.isArray(ext);
|
|
15
15
|
const isExtensionsFunc = (ext) => typeof ext === "function";
|
|
16
16
|
if (isExtensions(extensions)) {
|
|
@@ -24,7 +24,7 @@ export const getFinalExtensions = (extensions) => {
|
|
|
24
24
|
return DEFAULT_EXTENSIONS;
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
|
|
27
|
+
const getFilesFromDir = ({ dir, finalExt = [], ignore = [] }) => {
|
|
28
28
|
let globFindFilenames = [];
|
|
29
29
|
const globPattern = getGlobPattern(dir, finalExt);
|
|
30
30
|
globFindFilenames = glob.sync(globPattern, {
|
|
@@ -32,7 +32,7 @@ export const getFilesFromDir = ({ dir, finalExt = [], ignore = [] }) => {
|
|
|
32
32
|
});
|
|
33
33
|
return globFindFilenames;
|
|
34
34
|
};
|
|
35
|
-
|
|
35
|
+
const getFinalCompilerOption = (option) => {
|
|
36
36
|
const optionWithDefault = mergeDefaultOption(option);
|
|
37
37
|
const { sourceDir, ignore, enableWatch = false, watchDir, extensions = DEFAULT_EXTENSIONS } = option;
|
|
38
38
|
let globFindFilenames = [];
|
|
@@ -59,3 +59,9 @@ export const getFinalCompilerOption = (option) => {
|
|
|
59
59
|
]
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
|
+
export {
|
|
63
|
+
getFilesFromDir,
|
|
64
|
+
getFinalCompilerOption,
|
|
65
|
+
getFinalExtensions,
|
|
66
|
+
getGlobPattern
|
|
67
|
+
};
|
package/dist/esm-node/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { getFinalCompilerOption } from "./getFinalOption";
|
|
|
2
2
|
import { build } from "./build";
|
|
3
3
|
import { buildWatch } from "./buildWatch";
|
|
4
4
|
import { validate } from "./validate";
|
|
5
|
-
|
|
5
|
+
async function compiler(compilerOptions, babelOptions = {}) {
|
|
6
6
|
const validRet = validate(compilerOptions);
|
|
7
7
|
if (validRet) {
|
|
8
8
|
return validRet;
|
|
@@ -16,3 +16,6 @@ export async function compiler(compilerOptions, babelOptions = {}) {
|
|
|
16
16
|
}
|
|
17
17
|
export * from "./buildWatch";
|
|
18
18
|
export * from "./type";
|
|
19
|
+
export {
|
|
20
|
+
compiler
|
|
21
|
+
};
|
package/dist/esm-node/type.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm-node/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { logger } from "@modern-js/utils";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const sourceDirAndFileNamesValidMessage = "At least one of the sourceDir and filenames configurations must be configured";
|
|
3
|
+
const watchDirValidMessage = "should set watchDir when enableWatch is true";
|
|
4
|
+
const validateSourceDirAndFileNames = (compilerOptions) => {
|
|
5
5
|
const { sourceDir, filenames, quiet } = compilerOptions;
|
|
6
6
|
if (!sourceDir && !filenames) {
|
|
7
7
|
if (!quiet) {
|
|
@@ -15,7 +15,7 @@ export const validateSourceDirAndFileNames = (compilerOptions) => {
|
|
|
15
15
|
}
|
|
16
16
|
return null;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
const validateWatchDir = (compilerOptions) => {
|
|
19
19
|
const { watchDir, enableWatch, quiet } = compilerOptions;
|
|
20
20
|
if (enableWatch && !watchDir) {
|
|
21
21
|
if (!quiet) {
|
|
@@ -29,9 +29,16 @@ export const validateWatchDir = (compilerOptions) => {
|
|
|
29
29
|
}
|
|
30
30
|
return null;
|
|
31
31
|
};
|
|
32
|
-
|
|
32
|
+
const validate = (compilerOptions) => {
|
|
33
33
|
if (compilerOptions.enableWatch) {
|
|
34
34
|
return validateWatchDir(compilerOptions);
|
|
35
35
|
}
|
|
36
36
|
return validateSourceDirAndFileNames(compilerOptions);
|
|
37
37
|
};
|
|
38
|
+
export {
|
|
39
|
+
sourceDirAndFileNamesValidMessage,
|
|
40
|
+
validate,
|
|
41
|
+
validateSourceDirAndFileNames,
|
|
42
|
+
validateWatchDir,
|
|
43
|
+
watchDirValidMessage
|
|
44
|
+
};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.36.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/core": "^7.22.15",
|
|
35
35
|
"@swc/helpers": "0.5.1",
|
|
36
|
-
"@modern-js/utils": "2.
|
|
36
|
+
"@modern-js/utils": "2.36.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@babel/plugin-transform-classes": "^7.22.15",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@types/node": "^14",
|
|
45
45
|
"typescript": "^5",
|
|
46
46
|
"jest": "^29",
|
|
47
|
-
"@scripts/jest-config": "2.
|
|
48
|
-
"@scripts/build": "2.
|
|
47
|
+
"@scripts/jest-config": "2.36.0",
|
|
48
|
+
"@scripts/build": "2.36.0"
|
|
49
49
|
},
|
|
50
50
|
"sideEffects": false,
|
|
51
51
|
"publishConfig": {
|