Skip to content

Commit

Permalink
chore: add test-legacy build env
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Aug 13, 2020
1 parent 9f14d98 commit c07cc06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: actions/setup-node@v2-beta # Build Babel on latest node versions
- name: Build
run: |
BABEL_ENV=production make -j bootstrap
BABEL_ENV=test-legacy make -j bootstrap
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2-beta
with:
Expand Down
12 changes: 7 additions & 5 deletions babel.config.js
Expand Up @@ -17,7 +17,8 @@ module.exports = function (api) {
};
const envOpts = Object.assign({}, envOptsNoTargets);

const compileDynamicImport = env === "test" || env === "development";
const compileDynamicImport =
env === "test" || env === "development" || env === "test-legacy";

let convertESM = true;
let ignoreLib = true;
Expand Down Expand Up @@ -55,6 +56,7 @@ module.exports = function (api) {
);
if (env === "rollup") envOpts.targets = { node: nodeVersion };
break;
case "test-legacy": // In test-legacy environment, we build babel on latest node but test on minimum supported legacy versions
case "production":
// Config during builds before publish.
envOpts.targets = {
Expand Down Expand Up @@ -109,7 +111,7 @@ module.exports = function (api) {
"@babel/proposal-object-rest-spread",
{ useBuiltIns: true, loose: true },
],
dynamicImportUrlToPath,
compileDynamicImport ? dynamicImportUrlToPath : null,
compileDynamicImport ? "@babel/plugin-proposal-dynamic-import" : null,

convertESM ? "@babel/transform-modules-commonjs" : null,
Expand Down Expand Up @@ -170,9 +172,9 @@ module.exports = function (api) {
// NOTE: This plugin must run before @babel/plugin-transform-modules-commonjs,
// and assumes that the target is the current node version.
function dynamicImportUrlToPath({ template, env }) {
const currentNodeSupportsURL = !!require("url").pathToFileURL;

if (currentNodeSupportsURL && env() !== "production") {
const currentNodeSupportsURL =
!!require("url").pathToFileURL && env() !== "test-legacy"; // test-legacy is run on legacy node versions without pathToFileURL support
if (currentNodeSupportsURL) {
return {
visitor: {
CallExpression(path) {
Expand Down

0 comments on commit c07cc06

Please sign in to comment.