Skip to content

Commit

Permalink
Node 6 support (#789)
Browse files Browse the repository at this point in the history
* Run the tests on node 6
* Disable web assembly tests if not supported
* Check if we should ignore a babelrc before merging
  • Loading branch information
devongovett authored Feb 12, 2018
1 parent 47f252b commit 95a6ebf
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 13 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js
node_js:
# TODO: Run Babel on tests so that async-await works in Node 6
# - '6'
- '6'
- '8'
cache:
yarn: true
Expand Down
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Test against the latest version of this Node.js version
environment:
nodejs_version: "8"
matrix:
- nodejs_version: "6"
- nodejs_version: "8"

# Install scripts. (runs after repo cloning)
install:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-transform-async-super": "^1.0.0",
"babel-register": "^6.26.0",
"bsb-js": "^1.0.1",
"codecov": "^3.0.0",
"coffeescript": "^2.0.3",
Expand Down
3 changes: 2 additions & 1 deletion src/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"node": "6"
}
}]],
"plugins": ["transform-async-super"],
"ignore": ["builtins"]
}
}
13 changes: 12 additions & 1 deletion src/transforms/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const presetEnv = require('babel-preset-env');
const getTargetEngines = require('../utils/getTargetEngines');
const localRequire = require('../utils/localRequire');
const path = require('path');
const {util: babelUtils} = require('babel-core');

const NODE_MODULES = `${path.sep}node_modules${path.sep}`;
const ENV_PLUGINS = require('babel-preset-env/data/plugins');
Expand Down Expand Up @@ -90,7 +91,7 @@ async function getBabelConfig(asset) {
let jsxConfig = getJSXConfig(asset, !!babelrc);

// Merge the babel-preset-env config and the babelrc if needed
if (babelrc) {
if (babelrc && !shouldIgnoreBabelrc(asset.name, babelrc)) {
if (envConfig) {
// Filter out presets that are already applied by babel-preset-env
if (Array.isArray(babelrc.presets)) {
Expand Down Expand Up @@ -195,6 +196,16 @@ async function findBabelRc(asset) {
return await asset.getConfig(['.babelrc', '.babelrc.js']);
}

function shouldIgnoreBabelrc(filename, babelrc) {
// Determine if we should ignore this babelrc file. We do this here instead of
// letting babel-core handle it because this config might be merged with our
// autogenerated one later which shouldn't be ignored.
let ignore = babelUtils.arrayify(babelrc.ignore, babelUtils.regexify);
let only =
babelrc.only && babelUtils.arrayify(babelrc.only, babelUtils.regexify);
return babelUtils.shouldIgnore(filename, ignore, only);
}

/**
* Generates a babel-preset-env config for an asset.
* This is done by finding the source module's target engines, and the app's
Expand Down
8 changes: 8 additions & 0 deletions test/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [["env", {
"targets": {
"node": "current"
}
}]],
"ignore": ["integration", "input"]
}
12 changes: 6 additions & 6 deletions test/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ describe('css', function() {
await bundle(__dirname + '/input/index.css');

// cssnext was installed
let package = require('./input/package.json');
assert(package.devDependencies['postcss-cssnext']);
let pkg = require('./input/package.json');
assert(pkg.devDependencies['postcss-cssnext']);

// peer dependency caniuse-lite was installed
assert(package.devDependencies['caniuse-lite']);
assert(pkg.devDependencies['caniuse-lite']);

// cssnext is applied
let css = fs.readFileSync(__dirname + '/dist/index.css', 'utf8');
Expand All @@ -259,11 +259,11 @@ describe('css', function() {
await bundle(__dirname + '/input/index.css');

// cssnext was installed
let package = require('./input/package.json');
assert(package.devDependencies['postcss-cssnext']);
let pkg = require('./input/package.json');
assert(pkg.devDependencies['postcss-cssnext']);

// peer dependency caniuse-lite was installed
assert(package.devDependencies['caniuse-lite']);
assert(pkg.devDependencies['caniuse-lite']);

// appveyor is not currently writing to the yarn.lock file and will require further investigation
// let lockfile = fs.readFileSync(__dirname + '/input/yarn.lock', 'utf8');
Expand Down
3 changes: 2 additions & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--timeout 25000
--timeout 25000
--require babel-register
2 changes: 1 addition & 1 deletion test/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs');
const commandExists = require('command-exists');

describe('rust', function() {
if (!commandExists.sync('rustup')) {
if (typeof WebAssembly === 'undefined' || !commandExists.sync('rustup')) {
// eslint-disable-next-line no-console
console.log(
'Skipping Rust tests. Install https://www.rustup.rs/ to run them.'
Expand Down
4 changes: 4 additions & 0 deletions test/wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const assert = require('assert');
const {bundle, run, assertBundleTree, deferred} = require('./utils');

describe('wasm', function() {
if (typeof WebAssembly === 'undefined') {
return;
}

it('should preload a wasm file for a sync require', async function() {
let b = await bundle(__dirname + '/integration/wasm-sync/index.js');

Expand Down
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,12 @@ babel-plugin-syntax-trailing-function-commas@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3"

babel-plugin-transform-async-super@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-super/-/babel-plugin-transform-async-super-1.0.0.tgz#4d0884df0cad1017271105522b79f78db7892678"
dependencies:
babel-template "^6.26.0"

babel-plugin-transform-async-to-generator@^6.22.0:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-generator/-/babel-plugin-transform-async-to-generator-6.24.1.tgz#6536e378aff6cb1d5517ac0e40eb3e9fc8d08761"
Expand Down

0 comments on commit 95a6ebf

Please sign in to comment.