Skip to content

Commit

Permalink
fix: replace babel preset-env utils with helper module imports (#345)
Browse files Browse the repository at this point in the history
* fix: replace babel preset-env utils with helper module imports

* fix: fixed babel preset env test

Co-authored-by: Florian Weber <f.weber@ppm-vi.de>
  • Loading branch information
exreplay and Florian Weber authored Apr 17, 2021
1 parent 06023b3 commit 2c9e2be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@babel/helper-module-imports';
19 changes: 16 additions & 3 deletions packages/@averjs/babel-preset-app/lib/polyfillsPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { PluginObj } from '@babel/core';
import { NodePath, PluginObj } from '@babel/core';
import { Program } from '@babel/types';
import { BabelOptions } from '.';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { addSideEffect } = require('@babel/helper-module-imports');

function getModulePath(mod: string) {
const modPath =
mod === 'regenerator-runtime'
? 'regenerator-runtime/runtime'
: `core-js/modules/${mod}`;
return modPath;
}

function createImport(path: NodePath<Program>, mod: string) {
return addSideEffect(path, getModulePath(mod));
}

// add polyfill imports to the first file encountered.
export default function (): PluginObj {
Expand All @@ -16,8 +31,6 @@ export default function (): PluginObj {
}

const { polyfills } = state.opts as BabelOptions;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { createImport } = require('@babel/preset-env/lib/utils');
// imports are injected in reverse order
polyfills
?.slice()
Expand Down

0 comments on commit 2c9e2be

Please sign in to comment.