@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.
@@ -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
- export const isRes = (r) => Boolean(r);
8
- export const getDistFilePath = (option) => {
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
- export const resolveSourceMap = (option) => {
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
- export const compiler = (option) => {
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 (((_babelRes = babelRes) === null || _babelRes === void 0 ? void 0 : _babelRes.map) && babelConfig.sourceMaps && babelConfig.sourceMaps !== "inline") {
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
- export class CompilerErrorResult {
2
+ class CompilerErrorResult {
3
3
  init(initErrorResult) {
4
- var _initErrorResult;
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
+ };
@@ -1,6 +1,9 @@
1
- export const defaultDistFileExtMap = {
1
+ const defaultDistFileExtMap = {
2
2
  ".js": ".js",
3
3
  ".jsx": ".js",
4
4
  ".ts": ".js",
5
5
  ".tsx": ".js"
6
6
  };
7
+ export {
8
+ defaultDistFileExtMap
9
+ };
@@ -10,7 +10,10 @@ const defaultOptions = {
10
10
  verbose: false,
11
11
  clean: false
12
12
  };
13
- export const mergeDefaultOption = (compilerOptions) => ({
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
- export const getGlobPattern = (dir, extensions) => {
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
- export const getFinalExtensions = (extensions) => {
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
- export const getFilesFromDir = ({ dir, finalExt = [], ignore = [] }) => {
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
- export const getFinalCompilerOption = (option) => {
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
+ };
@@ -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
- export async function compiler(compilerOptions, babelOptions = {}) {
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
+ };
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +1,8 @@
1
1
  import * as path from "path";
2
- export function addSourceMappingUrl(code, loc) {
2
+ function addSourceMappingUrl(code, loc) {
3
3
  return `${code}
4
4
  //# sourceMappingURL=${path.normalize(path.basename(loc))}`;
5
5
  }
6
+ export {
7
+ addSourceMappingUrl
8
+ };
@@ -1,7 +1,7 @@
1
1
  import { logger } from "@modern-js/utils";
2
- export const sourceDirAndFileNamesValidMessage = "At least one of the sourceDir and filenames configurations must be configured";
3
- export const watchDirValidMessage = "should set watchDir when enableWatch is true";
4
- export const validateSourceDirAndFileNames = (compilerOptions) => {
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
- export const validateWatchDir = (compilerOptions) => {
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
- export const validate = (compilerOptions) => {
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.35.0",
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.35.0"
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.35.0",
48
- "@scripts/build": "2.35.0"
47
+ "@scripts/jest-config": "2.36.0",
48
+ "@scripts/build": "2.36.0"
49
49
  },
50
50
  "sideEffects": false,
51
51
  "publishConfig": {