Skip to content

Commit

Permalink
Solving the commonjs conundrum
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomguithereal committed Feb 19, 2020
1 parent de92198 commit 03636d6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 5 additions & 0 deletions scripts/commonjs-addendum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

for (var exportedName in exports)
Baobab[exportedName] = exports[exportedName];

module.exports = Baobab;
3 changes: 3 additions & 0 deletions scripts/test-commonjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var Baobab = require('../dist/baobab');

console.log(Baobab, new Baobab(), Baobab.helpers);
3 changes: 3 additions & 0 deletions scripts/test-es6-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Baobab, {helpers} from './dist/baobab';

console.log(Baobab, new Baobab(), helpers);

0 comments on commit 03636d6

Please sign in to comment.