Skip to content

Commit

Permalink
Add local babel workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jbhoosreddy committed Nov 22, 2019
1 parent 87976f5 commit c29be5d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
13 changes: 13 additions & 0 deletions lib/run-tests/contextualize-require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const path = require('path');

const babelPath = process.env.BABEL_PATH ?
path.resolve(process.cwd(), process.env.BABEL_PATH) :
undefined;

module.exports = function contextualizeRequire(path) {
if (!babelPath) {
return require(path);
}
const newPath = `${babelPath}/${path.replace('@babel/', 'packages/babel-')}`;
return require(newPath);
};
10 changes: 6 additions & 4 deletions lib/run-tests/get-babel-plugins.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use strict";

const requireBabel = require('./contextualize-require');

const featuresToPlugins = {
"class-fields-public": require("@babel/plugin-proposal-class-properties"),
"class-methods-private": require("@babel/plugin-proposal-private-methods"),
"numeric-separator-literal": require("@babel/plugin-proposal-numeric-separator"),
//"import.meta": require("@babel/plugin-syntax-import-meta"),
"class-fields-public": requireBabel("@babel/plugin-proposal-class-properties"),
"class-methods-private": requireBabel("@babel/plugin-proposal-private-methods"),
"numeric-separator-literal": requireBabel("@babel/plugin-proposal-numeric-separator"),
//"import.meta": requireBabel("@babel/plugin-syntax-import-meta"),
};

const defaultPlugins = [
Expand Down
5 changes: 3 additions & 2 deletions lib/run-tests/transpile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"use strict";

const { transformSync, loadOptions } = require("@babel/core");
const presetEnv = require("@babel/preset-env");
const requireBabel = require('./contextualize-require');
const { transformSync, loadOptions } = requireBabel("@babel/core");
const presetEnv = requireBabel("@babel/preset-env");

const getBabelPlugins = require("./get-babel-plugins");

Expand Down

0 comments on commit c29be5d

Please sign in to comment.