From 83bf6ccb952e5e1ad1c11d767d602c437d1e6dcd Mon Sep 17 00:00:00 2001 From: Yerko Palma Date: Tue, 16 Oct 2018 14:59:54 +0000 Subject: [PATCH 1/4] add es module --- index.es.js | 35 +++++++++++++++++++++++++++++++++++ package.json | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 index.es.js diff --git a/index.es.js b/index.es.js new file mode 100644 index 0000000..d0b3eac --- /dev/null +++ b/index.es.js @@ -0,0 +1,35 @@ +import assert from 'www.unpkg.com/nanoassert?module' + +var placeholder = { + cancel: noop, + finish: noop, + pause: noop, + play: noop, + reverse: noop, + finished: { + then: Promise.resolve // Animations can be chained with promises or property definitions + } +} + +export default function animate (keyframes, timingProperties) { + assert.equal(typeof keyframes, 'object', 'nanoanimation: keyframes should be an array or an object') + assert.ok(typeof timingProperties === 'object' || typeof timingProperties === 'number', 'nanoanimation: timingProperties should be type object or number') + + return function (element, _done) { + var done = _done || noop + assert.equal(typeof element, 'object', 'nanoanimation: element should be type object') + assert.equal(typeof done, 'function', 'nanoanimation: done should be type function') + + if (typeof window === 'undefined' || !('AnimationEvent' in window)) { + done() + return placeholder + } + + var animation = element.animate(keyframes, timingProperties) + animation.pause() + animation.onfinish = done + return animation + } +} + +function noop () {} diff --git a/package.json b/package.json index 2989151..38e0b0b 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,8 @@ "description": "Safety wrapper around the Web Animation API", "repository": "choojs/nanoanimation", "version": "2.1.0", + "main": "index.js", + "module": "index.es.js", "scripts": { "deps": "dependency-check . && dependency-check . --extra --no-dev", "start": "node .", From d64033cda3e387323491f673c3d9b26833bce9ee Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 17 Oct 2018 12:33:33 -0300 Subject: [PATCH 2/4] use .mjs extension --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 38e0b0b..3b15f3d 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "repository": "choojs/nanoanimation", "version": "2.1.0", "main": "index.js", - "module": "index.es.js", + "module": "index.mjs", "scripts": { "deps": "dependency-check . && dependency-check . --extra --no-dev", "start": "node .", From e0f66e22db55f73c6183c212a212881fb0151de8 Mon Sep 17 00:00:00 2001 From: Yerko Palma Date: Wed, 17 Oct 2018 15:54:25 +0000 Subject: [PATCH 3/4] use microbundle --- index.es.js | 35 ----------------------------------- index.js | 6 ++---- package.json | 8 ++++++-- 3 files changed, 8 insertions(+), 41 deletions(-) delete mode 100644 index.es.js diff --git a/index.es.js b/index.es.js deleted file mode 100644 index d0b3eac..0000000 --- a/index.es.js +++ /dev/null @@ -1,35 +0,0 @@ -import assert from 'www.unpkg.com/nanoassert?module' - -var placeholder = { - cancel: noop, - finish: noop, - pause: noop, - play: noop, - reverse: noop, - finished: { - then: Promise.resolve // Animations can be chained with promises or property definitions - } -} - -export default function animate (keyframes, timingProperties) { - assert.equal(typeof keyframes, 'object', 'nanoanimation: keyframes should be an array or an object') - assert.ok(typeof timingProperties === 'object' || typeof timingProperties === 'number', 'nanoanimation: timingProperties should be type object or number') - - return function (element, _done) { - var done = _done || noop - assert.equal(typeof element, 'object', 'nanoanimation: element should be type object') - assert.equal(typeof done, 'function', 'nanoanimation: done should be type function') - - if (typeof window === 'undefined' || !('AnimationEvent' in window)) { - done() - return placeholder - } - - var animation = element.animate(keyframes, timingProperties) - animation.pause() - animation.onfinish = done - return animation - } -} - -function noop () {} diff --git a/index.js b/index.js index a19319a..479ba95 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -var assert = require('nanoassert') +import assert from 'nanoassert' var placeholder = { cancel: noop, @@ -11,9 +11,7 @@ var placeholder = { } } -module.exports = animate - -function animate (keyframes, timingProperties) { +export default function animate (keyframes, timingProperties) { assert.equal(typeof keyframes, 'object', 'nanoanimation: keyframes should be an array or an object') assert.ok(typeof timingProperties === 'object' || typeof timingProperties === 'number', 'nanoanimation: timingProperties should be type object or number') diff --git a/package.json b/package.json index 3b15f3d..51fb837 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,14 @@ "description": "Safety wrapper around the Web Animation API", "repository": "choojs/nanoanimation", "version": "2.1.0", - "main": "index.js", - "module": "index.mjs", + "source": "index.js", + "main": "dist/nanoanimation.js", + "module": "dist/nanoanimation.mjs", "scripts": { "deps": "dependency-check . && dependency-check . --extra --no-dev", "start": "node .", + "build": "microbundle -o dist -f cjs,es", + "prepublishOnly": "npm run build", "test": "standard && npm run deps" }, "dependencies": { @@ -15,6 +18,7 @@ }, "devDependencies": { "dependency-check": "^2.9.1", + "microbundle": "^0.6.0", "standard": "^10.0.3", "tape": "^4.8.0" }, From 04d396882e36d96a5411a06f95d8bf761578dac5 Mon Sep 17 00:00:00 2001 From: Yerko Palma Date: Wed, 17 Oct 2018 16:01:18 +0000 Subject: [PATCH 4/4] build files before tests --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 51fb837..d4652d8 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "start": "node .", "build": "microbundle -o dist -f cjs,es", "prepublishOnly": "npm run build", + "pretest": "npm run build", "test": "standard && npm run deps" }, "dependencies": {