Skip to content

Commit

Permalink
feat: add ESM support
Browse files Browse the repository at this point in the history
Closes #9, closes #10
  • Loading branch information
remarkablemark committed Dec 3, 2022
1 parent c8995bf commit 2e7d959
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: Run unit tests
run: npm run test:coverage

- name: Run ES modules tests
run: npm run test:module

- name: Build bundle
run: npm run build

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ function StyleToObject(style, iterator) {
}

module.exports = StyleToObject;
module.exports.default = StyleToObject; // ESM support
3 changes: 3 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import StyleToObject from './index.js';

export default StyleToObject;
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"author": "Mark <mark@remarkablemark.org>",
"main": "index.js",
"types": "index.d.ts",
"module": "index.mjs",
"exports": {
"import": "./index.mjs",
"require": "./index.js"
},
"scripts": {
"build": "run-s build:*",
"build:min": "NODE_ENV=production rollup --config --file dist/style-to-object.min.js --sourcemap",
Expand All @@ -16,9 +21,10 @@
"postinstall": "husky install",
"postpublish": "pinst --enable",
"prepublishOnly": "pinst --disable && run-s lint lint:dts test clean build",
"test": "mocha",
"test": "mocha --exclude **/*.mjs",
"test:coverage": "nyc npm test",
"test:watch": "mocha --watch"
"test:module": "node --experimental-modules test/index.mjs",
"test:watch": "npm run test -- --watch"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -60,7 +66,9 @@
},
"files": [
"/dist",
"index.d.ts"
"index.d.ts",
"index.js",
"index.mjs"
],
"license": "MIT"
}
5 changes: 5 additions & 0 deletions test/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import assert from 'assert';
import StyleToObject from '../index.mjs';

assert.strictEqual(typeof StyleToObject, 'function');
assert.deepEqual(StyleToObject('foo: bar'), { foo: 'bar' });

0 comments on commit 2e7d959

Please sign in to comment.