From 03636d6c0352cc3146443d59dd168d7568bb1dca Mon Sep 17 00:00:00 2001 From: Yomguithereal Date: Wed, 19 Feb 2020 14:09:24 +0100 Subject: [PATCH] Solving the commonjs conundrum --- package.json | 5 ++++- scripts/commonjs-addendum.js | 5 +++++ scripts/test-commonjs.js | 3 +++ scripts/test-es6-import.js | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 scripts/commonjs-addendum.js create mode 100644 scripts/test-commonjs.js create mode 100644 scripts/test-es6-import.js diff --git a/package.json b/package.json index 8449e1f..662c932 100644 --- a/package.json +++ b/package.json @@ -36,9 +36,12 @@ "benchmark": "babel-node --presets @babel/preset-env benchmark.js", "build": "node ./scripts/build.js", "check": "npm test && npm run lint && npm run build", - "dist": "babel ./src --out-dir dist --presets @babel/preset-env && cp src/baobab.d.ts dist/.", + "dist:addendum": "cat scripts/commonjs-addendum.js >> dist/baobab.js", + "dist": "babel ./src --out-dir dist --presets @babel/preset-env && cp src/baobab.d.ts dist/. && npm run dist:addendum", "lint": "eslint -c eslint.config.js ./src ./test && tslint src/baobab.d.ts test/suites/*.ts", "prepublish": "npm run check && npm run dist", + "test:commonjs": "node scripts/test-commonjs.js", + "test:es6-import": "babel --presets @babel/preset-env scripts/test-es6-import.js | node", "test": "ts-mocha --reporter spec --require test/register.js test/suites/*.ts" }, "repository": { diff --git a/scripts/commonjs-addendum.js b/scripts/commonjs-addendum.js new file mode 100644 index 0000000..8e290e8 --- /dev/null +++ b/scripts/commonjs-addendum.js @@ -0,0 +1,5 @@ + +for (var exportedName in exports) + Baobab[exportedName] = exports[exportedName]; + +module.exports = Baobab; diff --git a/scripts/test-commonjs.js b/scripts/test-commonjs.js new file mode 100644 index 0000000..27a7731 --- /dev/null +++ b/scripts/test-commonjs.js @@ -0,0 +1,3 @@ +var Baobab = require('../dist/baobab'); + +console.log(Baobab, new Baobab(), Baobab.helpers); diff --git a/scripts/test-es6-import.js b/scripts/test-es6-import.js new file mode 100644 index 0000000..4513e14 --- /dev/null +++ b/scripts/test-es6-import.js @@ -0,0 +1,3 @@ +import Baobab, {helpers} from './dist/baobab'; + +console.log(Baobab, new Baobab(), helpers);