Skip to content

Commit

Permalink
Ensure babel extends builtins on jsnext build
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism committed Nov 30, 2016
1 parent 453cb3c commit a0d2ced
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 54 deletions.
16 changes: 1 addition & 15 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
{
"presets": [
"es2015"
],
"plugins": [
"add-module-exports",
[
"babel-plugin-transform-builtin-extend",
{
"globals": [
"Error"
],
"approximate": true
}
]
]
"presets": "./babel-config.js"
}
29 changes: 29 additions & 0 deletions babel-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var plugins = [
[
"babel-plugin-transform-builtin-extend",
{
"globals": ["Error"],
"approximate": true
}
]
];

var env = process.env.BABEL_ENV || process.env.NODE_ENV;

var modules;

if (env === 'es') {
modules = false;
} else {
modules = 'commonjs';
plugins.push('add-module-exports');
}

module.exports = {
"presets": [
["es2015", { modules: modules }]
],
"plugins": plugins
};
33 changes: 0 additions & 33 deletions build.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ var ExtendableError = function (_extendableBuiltin2) {
}(_extendableBuiltin(Error));

exports.default = ExtendableError;
module.exports = exports['default'];
module.exports = exports['default'];
31 changes: 27 additions & 4 deletions lib/index.jsnext.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,31 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var ExtendableError = function (_Error) {
_inherits(ExtendableError, _Error);
function _extendableBuiltin(cls) {
function ExtendableBuiltin() {
cls.apply(this, arguments);
}

ExtendableBuiltin.prototype = Object.create(cls.prototype, {
constructor: {
value: cls,
enumerable: false,
writable: true,
configurable: true
}
});

if (Object.setPrototypeOf) {
Object.setPrototypeOf(ExtendableBuiltin, cls);
} else {
ExtendableBuiltin.__proto__ = cls;
}

return ExtendableBuiltin;
}

var ExtendableError = function (_extendableBuiltin2) {
_inherits(ExtendableError, _extendableBuiltin2);

function ExtendableError() {
var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
Expand Down Expand Up @@ -44,6 +67,6 @@ var ExtendableError = function (_Error) {
}

return ExtendableError;
}(Error);
}(_extendableBuiltin(Error));

export default ExtendableError;
export default ExtendableError;
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"typings": "./lib/index.d.ts",
"scripts": {
"test": "mocha --compilers js:babel-core/register --recursive",
"build": "node build.js",
"build": "npm run build:commonjs && npm run build:es",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src/index.js --out-file lib/index.js",
"build:es": "cross-env BABEL_ENV=es babel src/index.js --out-file lib/index.jsnext.js",
"prepublish": "npm run build && npm run test"
},
"repository": {
Expand All @@ -32,6 +34,7 @@
"babel-plugin-transform-builtin-extend": "^1.1.0",
"babel-preset-es2015": "^6.6.0",
"chai": "^3.2.0",
"cross-env": "^3.1.3",
"mocha": "^2.4.5"
},
"dependencies": {}
Expand Down

0 comments on commit a0d2ced

Please sign in to comment.