Skip to content

Commit

Permalink
Add esm loader and fix cjs and esm bindings collision
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Nov 10, 2017
1 parent 279de39 commit 608c75f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 93 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ node_js:
- 8
- 6
script:
- npm run ci:test
- npm run test
- npm run test-types
after_success: npm run report-coverage
25 changes: 8 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@
"scripts": {
"prepublish": "npm run build",
"build": "rollup -c && cross-env MINIFY=true rollup -c && cp derivable.d.ts derivable.js.flow dist/",
"lint": "eslint src test",
"test": "npm run build && jest && npm run lint",
"lint": "eslint src",
"ci:test": "npm run test && (cd test_flow && npm install && npm test)",
"test-types": "(cd test_flow && npm install && npm test)",
"bench": "node scripts/bench.js",
"coverage": "jest --coverage",
"report-coverage": "jest --coverage && cat ./coverage/lcov.info | coveralls",
"stats": "node scripts/stats.js",
"toc": "doctoc README.md",
"clean": "rm -rf dist",
"all": "npm run clean && npm run build && npm run test && npm run coverage && npm run stats && npm run bench && npm run toc"
"all": "npm run clean && npm run build && npm run coverage && npm run stats && npm run bench && npm run toc"
},
"main": "dist/derivable.js",
"module": "dist/derivable.es.js",
"typings": "dist/derivable.d.ts",
"typescript": {
"definition": "dist/derivable.d.ts"
},
"@std/esm": {
"esm": "js"
},
"jest": {
"testRegex": ".*_test.js$"
},
Expand All @@ -39,20 +42,9 @@
"reactive",
"dynamic"
],
"babel": {
"env": {
"test": {
"plugins": [
"transform-es2015-modules-commonjs"
]
}
}
},
"devDependencies": {
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-register": "^6.7.2",
"@std/esm": "^0.13.0",
"benchmark": "^2.1.0",
"bluebird": "^2.9.34",
"colors": "^1.1.2",
"coveralls": "^2.11.9",
"cross-env": "^5.1.1",
Expand All @@ -64,8 +56,7 @@
"mobx": "^2.3.3",
"np": "^2.16.0",
"rollup": "^0.51.1",
"rollup-plugin-uglify": "^2.0.1",
"source-map-support": "^0.3.2"
"rollup-plugin-uglify": "^2.0.1"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/derivation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function Derivation (deriver) {
this._activeChildren = [];
this._state = DISCONNECTED;

if (util.DEBUG_MODE) {
if (util.isDebug()) {
this.stack = Error().stack;
}
};
Expand All @@ -34,7 +34,7 @@ util.assign(Derivation.prototype, {
this._parents = [];
}
parents.startCapturingParents(this, this._parents);
if (!util.DEBUG_MODE) {
if (!util.isDebug()) {
newVal = that._deriver();
} else {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/reactors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function Reactor(parent, react, governor) {
this._reacting = false;
this._type = types.REACTOR;

if (util.DEBUG_MODE) {
if (util.isDebug()) {
this.stack = Error().stack;
}
}
Expand All @@ -31,7 +31,7 @@ util.assign(Reactor.prototype, {
this._reacting = true;
this.react(nextValue);
} catch (e) {
if (util.DEBUG_MODE) {
if (util.isDebug()) {
console.error(this.stack);
}
throw e;
Expand Down
7 changes: 6 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ export function some (x) {
return (x !== null) && (x !== void 0);
};

export var DEBUG_MODE = false;
var DEBUG_MODE = false;

export function setDebugMode (val) {
DEBUG_MODE = !!val;
};

export function isDebug() {
return DEBUG_MODE;
}

export function setEquals (derivable, equals) {
derivable._equals = equals;
return derivable;
Expand Down
19 changes: 9 additions & 10 deletions test/unit/util_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

require('source-map-support');
require('babel-register');
require = require('@std/esm')(module);
const util = require('../../src/util');

test('the equals function checks equality for primitives', () => {
Expand Down Expand Up @@ -102,27 +101,27 @@ test('the some function checks whether something is not (null or undefined)', fu
expect(util.some(false)).toEqual(true);
});

test('the DEBUG_MODE flag should be false by default', function () {
expect(util.DEBUG_MODE).toEqual(false);
test('the debug flag should be false by default', function () {
expect(util.isDebug()).toEqual(false);
});

test('the setDebugMode function sets the DEBUG_MODE flag', function () {
test('the setDebugMode function sets the debug flag', function () {
util.setDebugMode(true);
expect(util.DEBUG_MODE).toEqual(true);
expect(util.isDebug()).toEqual(true);
});

test('the setDebugMode function casts its argument to boolean', function () {
util.setDebugMode("haha");
expect(util.DEBUG_MODE).toEqual(true);
expect(util.isDebug()).toEqual(true);

util.setDebugMode(null);
expect(util.DEBUG_MODE).toEqual(false);
expect(util.isDebug()).toEqual(false);

util.setDebugMode(3);
expect(util.DEBUG_MODE).toEqual(true);
expect(util.isDebug()).toEqual(true);

util.setDebugMode(0);
expect(util.DEBUG_MODE).toEqual(false);
expect(util.isDebug()).toEqual(false);
});

test('the setEquals function sets the _equals property of an object and returns the object', function () {
Expand Down
66 changes: 6 additions & 60 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# yarn lockfile v1


"@std/esm@^0.13.0":
version "0.13.0"
resolved "https://registry.yarnpkg.com/@std/esm/-/esm-0.13.0.tgz#b2ca2f7d96f50eec14bd14f0b8afc3138b2a40d4"

abab@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e"
Expand Down Expand Up @@ -186,10 +190,6 @@ assert-plus@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-0.2.0.tgz#d74e1b87e7affc0db8aadb7021f3fe48101ab234"

assertion-error@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.0.2.tgz#13ca515d86206da0bac66e834dd397d87581094c"

astral-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
Expand Down Expand Up @@ -301,30 +301,14 @@ babel-plugin-syntax-object-rest-spread@^6.13.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5"

babel-plugin-transform-es2015-modules-commonjs@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.26.0.tgz#0d8394029b7dc6abe1a97ef181e00758dd2e5d8a"
dependencies:
babel-plugin-transform-strict-mode "^6.24.1"
babel-runtime "^6.26.0"
babel-template "^6.26.0"
babel-types "^6.26.0"

babel-plugin-transform-strict-mode@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758"
dependencies:
babel-runtime "^6.22.0"
babel-types "^6.24.1"

babel-preset-jest@^21.2.0:
version "21.2.0"
resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-21.2.0.tgz#ff9d2bce08abd98e8a36d9a8a5189b9173b85638"
dependencies:
babel-plugin-jest-hoist "^21.2.0"
babel-plugin-syntax-object-rest-spread "^6.13.0"

babel-register@^6.26.0, babel-register@^6.7.2:
babel-register@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-register/-/babel-register-6.26.0.tgz#6ed021173e2fcb486d7acb45c6009a856f647071"
dependencies:
Expand Down Expand Up @@ -367,7 +351,7 @@ babel-traverse@^6.18.0, babel-traverse@^6.26.0:
invariant "^2.2.2"
lodash "^4.17.4"

babel-types@^6.18.0, babel-types@^6.24.1, babel-types@^6.26.0:
babel-types@^6.18.0, babel-types@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497"
dependencies:
Expand Down Expand Up @@ -407,10 +391,6 @@ block-stream@*:
dependencies:
inherits "~2.0.0"

bluebird@^2.9.34:
version "2.11.0"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1"

boom@2.x.x:
version "2.10.1"
resolved "https://registry.yarnpkg.com/boom/-/boom-2.10.1.tgz#39c8918ceff5799f83f9492a848f625add0c766f"
Expand Down Expand Up @@ -532,14 +512,6 @@ center-align@^0.1.1:
align-text "^0.1.3"
lazy-cache "^1.0.3"

chai@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247"
dependencies:
assertion-error "^1.0.1"
deep-eql "^0.1.3"
type-detect "^1.0.0"

chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
Expand Down Expand Up @@ -797,12 +769,6 @@ decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"

deep-eql@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2"
dependencies:
type-detect "0.1.1"

deep-extend@~0.4.0:
version "0.4.2"
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.2.tgz#48b699c27e334bf89f10892be432f6e4c7d34a7f"
Expand Down Expand Up @@ -3216,24 +3182,12 @@ sntp@2.x.x:
dependencies:
hoek "4.x.x"

source-map-support@^0.3.2:
version "0.3.3"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.3.3.tgz#34900977d5ba3f07c7757ee72e73bb1a9b53754f"
dependencies:
source-map "0.1.32"

source-map-support@^0.4.15:
version "0.4.18"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f"
dependencies:
source-map "^0.5.6"

source-map@0.1.32:
version "0.1.32"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.1.32.tgz#c8b6c167797ba4740a8ea33252162ff08591b266"
dependencies:
amdefine ">=0.0.4"

source-map@^0.4.4:
version "0.4.4"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b"
Expand Down Expand Up @@ -3539,14 +3493,6 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"

type-detect@0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822"

type-detect@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2"

typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
Expand Down

0 comments on commit 608c75f

Please sign in to comment.