Skip to content

Commit

Permalink
fix(babel): use require.resolve for resolve babel plugins (#700) (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Dec 8, 2020
1 parent 17ee220 commit 3ddf4ac
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/extractor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"@babel/generator": ">=7",
"@babel/plugin-transform-runtime": ">=7",
"@babel/plugin-transform-template-literals": ">=7",
"@linaria/babel": "^3.0.0-beta.0",
"@linaria/preeval": "^3.0.0-beta.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/extractor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const extractor: Evaluator = (filename, options, text, only = null) => {
options,
]);
transformOptions.plugins!.unshift([
'@babel/plugin-transform-runtime',
require.resolve('@babel/plugin-transform-runtime'),
{ useESModules: false },
]);

Expand All @@ -81,7 +81,7 @@ const extractor: Evaluator = (filename, options, text, only = null) => {
// Presets ordering is from last to first, so we add the plugin at the beginning of the list, which persist the order that was established with formerly used `@babel/preset-env`.

transformOptions.presets!.unshift({
plugins: ['@babel/plugin-transform-template-literals'],
plugins: [require.resolve('@babel/plugin-transform-template-literals')],
});
// Expressions will be extracted only for __linariaPreval.
// In all other cases a code will be returned as is.
Expand Down
2 changes: 2 additions & 0 deletions packages/shaker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"dependencies": {
"@babel/generator": ">=7",
"@babel/plugin-transform-runtime": ">=7",
"@babel/plugin-transform-template-literals": ">=7",
"@babel/preset-env": ">=7",
"@linaria/babel": "^3.0.0-beta.0",
"@linaria/logger": "^3.0.0-beta.0",
"@linaria/preeval": "^3.0.0-beta.0",
Expand Down
10 changes: 6 additions & 4 deletions packages/shaker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ function prepareForShake(

transformOptions.ast = true;
transformOptions.presets!.unshift([
'@babel/preset-env',
require.resolve('@babel/preset-env'),
{
targets: 'ie 11',
// we need this plugin so we list it explicitly, explanation in `evaluators/extractor/index`
// we need this plugin so we list it explicitly, explanation in `packages/extractor/src/index`
include: ['@babel/plugin-transform-template-literals'],
},
]);
transformOptions.presets!.unshift([
require.resolve('@linaria/preeval'),
options,
]);
transformOptions.plugins!.unshift('transform-react-remove-prop-types');
transformOptions.plugins!.unshift(
require.resolve('babel-plugin-transform-react-remove-prop-types')
);
transformOptions.plugins!.unshift([
'@babel/plugin-transform-runtime',
require.resolve('@babel/plugin-transform-runtime'),
{ useESModules: false },
]);

Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,13 @@
"@babel/helper-plugin-utils" "^7.10.4"
"@babel/helper-regex" "^7.10.4"

"@babel/plugin-transform-template-literals@>=7":
version "7.12.1"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.12.1.tgz#b43ece6ed9a79c0c71119f576d299ef09d942843"
integrity sha512-b4Zx3KHi+taXB1dVRBhVJtEPi9h1THCeKmae2qP0YdUHIFhVjtpqqNfxeVAa1xeHVhAy4SbHxEwx5cltAu5apw==
dependencies:
"@babel/helper-plugin-utils" "^7.10.4"

"@babel/plugin-transform-template-literals@^7.10.4":
version "7.10.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.10.5.tgz#78bc5d626a6642db3312d9d0f001f5e7639fde8c"
Expand Down

0 comments on commit 3ddf4ac

Please sign in to comment.