Skip to content

Commit 3ac923d

Browse files
committed
Add native Node.js ES Modules support
1 parent 328fb66 commit 3ac923d

14 files changed

+140
-29
lines changed

.gitignore

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.DS_Store
2-
_*
3-
node_modules
4-
lib
1+
dist/
2+
lib/
3+
node_modules/

.npmignore

-2
This file was deleted.

esm.js

-5
This file was deleted.

extras.js

-1
This file was deleted.

index.js

-1
This file was deleted.

package-lock.json

+85
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+18-5
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,32 @@
55
"description": "An Implementation of ES Observables",
66
"homepage": "https://github.com/zenparsing/zen-observable",
77
"license": "MIT",
8+
"main": "./dist/cjs/index.js",
9+
"exports": {
10+
"require": "./dist/cjs/index.js",
11+
"import": "./dist/es/index.js"
12+
},
13+
"module": "./dist/es/index.js",
14+
"type": "commonjs",
815
"devDependencies": {
916
"@babel/cli": "^7.6.0",
1017
"@babel/core": "^7.6.0",
1118
"@babel/preset-env": "^7.6.0",
1219
"@babel/register": "^7.6.0",
20+
"@rollup/plugin-babel": "^5.0.0",
1321
"eslint": "^6.5.0",
14-
"mocha": "^6.2.0"
22+
"mocha": "^6.2.0",
23+
"rollup": "^2.14.0"
1524
},
1625
"dependencies": {},
1726
"scripts": {
18-
"test": "mocha --recursive --require ./scripts/mocha-require",
27+
"build": "rollup --config",
1928
"lint": "eslint src/*",
20-
"build": "git clean -dfX ./lib && node ./scripts/build",
21-
"prepublishOnly": "npm run lint && npm test && npm run build"
22-
}
29+
"prepare": "npm run build",
30+
"prepublishOnly": "npm run lint && npm test",
31+
"test": "mocha --recursive --require ./scripts/mocha-require"
32+
},
33+
"files": [
34+
"dist/"
35+
]
2336
}

rollup.config.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { babel } from '@rollup/plugin-babel';
2+
3+
function emitModulePackageFile() {
4+
return {
5+
name: 'emit-module-package-file',
6+
generateBundle() {
7+
this.emitFile({
8+
type: 'asset',
9+
fileName: 'package.json',
10+
source: '{"type":"module"}',
11+
});
12+
},
13+
};
14+
}
15+
16+
export default {
17+
input: ['src/index.js', 'src/extras.js'],
18+
output: [
19+
{ dir: 'dist/cjs/', format: 'cjs', exports: 'named' },
20+
{ dir: 'dist/es/', format: 'es', plugins: [emitModulePackageFile()] },
21+
],
22+
plugins: [
23+
babel({
24+
babelHelpers: 'bundled',
25+
plugins: require('./scripts/babel-plugins'),
26+
}),
27+
],
28+
};

scripts/babel-plugins.js

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module.exports = [
88
'@babel/plugin-transform-duplicate-keys',
99
'@babel/plugin-transform-for-of',
1010
'@babel/plugin-transform-literals',
11-
'@babel/plugin-transform-modules-commonjs',
1211
'@babel/plugin-transform-parameters',
1312
'@babel/plugin-transform-shorthand-properties',
1413
'@babel/plugin-transform-spread',

scripts/build.js

-7
This file was deleted.

scripts/mocha-require.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
require('@babel/register')({
2-
plugins: require('./babel-plugins'),
2+
plugins: [
3+
...require('./babel-plugins'),
4+
'@babel/plugin-transform-modules-commonjs',
5+
],
36
});

src/extras.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Observable } from './Observable.js';
1+
import { Observable } from './index.js';
22

33
// Emits all values from all inputs in parallel
44
export function merge(...sources) {

src/Observable.js src/index.js

File renamed without changes.

test/setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Observable } from '../src/Observable.js';
1+
import { Observable } from '../src/index.js';
22

33
beforeEach(() => {
44
global.Observable = Observable;

0 commit comments

Comments
 (0)