Skip to content

Commit

Permalink
fix 'useESModules' option issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 18, 2021
1 parent 82b0dc5 commit 5144dad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/tsbb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@babel/core": "7.13.10",
"@jest/types": "26.6.2",
"@tsbb/babel-preset-tsbb": "1.14.1",
"@tsbb/babel-preset-tsbb": "1.14.2",
"@types/graceful-fs": "4.1.5",
"@types/node": "14.14.34",
"babel-jest": "26.6.3",
Expand Down
14 changes: 8 additions & 6 deletions packages/tsbb/src/babel/transform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import semver from 'semver';
import { transformFile, BabelFileResult, TransformOptions, loadOptions } from '@babel/core';
import { IOptions } from '@tsbb/babel-preset-tsbb';
import { IOptions, ITransformRuntimeOptions } from '@tsbb/babel-preset-tsbb';

export interface ITransformResult extends BabelFileResult {
options: TransformOptions;
Expand Down Expand Up @@ -33,12 +33,14 @@ export default (filePath: string, options: ITransformOptions, targets: ITargets)
const runtimeVersion = semver.clean(require('@babel/runtime/package.json').version);
presetOptions.modules = false;
presetOptions.transformRuntime = {
// [@babel/plugin-transform-runtime] The 'useESModules' option is not necessary when using
// a @babel/runtime version >= 7.13.0 and not using the 'absoluteRuntime' option,
// because it automatically detects the necessary module format.
useESModules: !semver.gte(runtimeVersion, '7.13.0'),
version: require('@babel/helpers/package.json').version,
} as any;
};
// [@babel/plugin-transform-runtime] The 'useESModules' option is not necessary when using
// a @babel/runtime version >= 7.13.0 and not using the 'absoluteRuntime' option,
// because it automatically detects the necessary module format.
if (!semver.gte(runtimeVersion, '7.13.0')) {
presetOptions.transformRuntime!.useESModules = !semver.gte(runtimeVersion, '7.13.0');
}
}
babelOptions = {
presets: [
Expand Down

0 comments on commit 5144dad

Please sign in to comment.