Skip to content

Commit e008eb3

Browse files
author
Ivan Zotov
committed
Improve rollup config
1 parent 771d91f commit e008eb3

File tree

10 files changed

+219
-130
lines changed

10 files changed

+219
-130
lines changed

.eslintrc.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
{
22
"env": {
3-
"es6": true,
4-
"node": true
3+
"es6": true,
4+
"node": true
55
},
66
"extends": "eslint:recommended",
77
"globals": {
8-
"Atomics": "readonly",
9-
"SharedArrayBuffer": "readonly"
8+
"Atomics": "readonly",
9+
"SharedArrayBuffer": "readonly"
1010
},
1111
"parser": "babel-eslint",
1212
"parserOptions": {
13-
"ecmaFeatures": {
14-
"jsx": true
15-
},
16-
"ecmaVersion": 2018,
17-
"sourceType": "module"
13+
"ecmaFeatures": {
14+
"jsx": true
15+
},
16+
"ecmaVersion": 2018,
17+
"sourceType": "module"
1818
},
19-
"rules": {
20-
}
19+
"rules": {}
2120
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.DS_Store
2+
es/
3+
lib/
24
dist/
35
node_modules/
46
coverage/

babel.config.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
module.exports = {
22
presets: [
33
[
4-
"@babel/preset-env",
4+
'@babel/preset-env',
55
{
66
targets: {
7-
node: "current",
7+
node: 'current',
88
},
99
},
1010
],
1111
],
12-
plugins: [
13-
"@babel/plugin-proposal-class-properties",
14-
],
15-
};
12+
plugins: ['@babel/plugin-proposal-class-properties'],
13+
};

flow-typed/npm/@railsmob/events_v0.x.x.js.flow

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
*/
66

77
declare module "src/Events" {
8-
/**
9-
* @typedef {(args: any) => any} ListenerFn
10-
* @typedef {{
11-
id: string,
12-
fn: ListenerFn,...
13-
}} Listener
14-
*/
158
declare export default class Events {
169
static SEP: string;
1710
static ANY: string;
@@ -24,11 +17,18 @@ fn: ListenerFn,...
2417

2518
/**
2619
* @type {{
27-
[name: string]: Array<Listener>,...
20+
[name: string]: Array<{
21+
id: string,
22+
fn: Function,...
23+
}>,...
2824
}}
2925
*/
3026
listeners: {
31-
[name: string]: Array<Listener>,
27+
[name: string]: Array<{
28+
id: string,
29+
fn: Function,
30+
...
31+
}>,
3232
...
3333
};
3434
id: (name: string, id: string) => string;
@@ -37,21 +37,21 @@ fn: ListenerFn,...
3737

3838
/**
3939
* @param {string} eventId
40-
* @param {ListenerFn} fn
40+
* @param {Function} fn
4141
*/
42-
on: (eventId: string, fn: (args: any) => any) => void;
42+
on: (eventId: string, fn: Function) => void;
4343

4444
/**
4545
* @param {string} eventId
46-
* @param {ListenerFn} fn
46+
* @param {Function} fn
4747
*/
48-
once: (eventId: string, fn: (args: any) => any) => void;
48+
once: (eventId: string, fn: Function) => void;
4949

5050
/**
5151
* @param {string} eventId
52-
* @param {ListenerFn} fn
52+
* @param {Function} fn
5353
*/
54-
off: (eventId: string, fn: (args: any) => any) => void;
54+
off: (eventId: string, fn: Function) => void;
5555

5656
/**
5757
* @param {string} eventId
@@ -64,12 +64,6 @@ fn: ListenerFn,...
6464
*/
6565
parse: (eventId: string) => string[];
6666
}
67-
declare export type ListenerFn = (args: any) => any;
68-
declare export type Listener = {
69-
id: string,
70-
fn: (args: any) => any,
71-
...
72-
};
7367
}
7468

7569
declare module "index" {

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
22
"name": "@railsmob/events",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "Simple and well-tested events",
5-
"main": "dist/index.js",
5+
"main": "lib/index.js",
6+
"unpkg": "dist/index.js",
7+
"module": "es/index.js",
8+
"types": "./typings/index.d.ts",
69
"author": "Ivan Zotov <[email protected]> (http://ivanzotov.com/)",
710
"license": "MIT",
811
"private": false,
9-
"types": "./typings/index.d.ts",
1012
"repository": {
1113
"type": "git",
1214
"url": "https://github.com/railsmob/events.git"
@@ -23,10 +25,12 @@
2325
"build": "rollup -c",
2426
"tsc": "tsc -p .",
2527
"flow": "flow",
28+
"flowgen": "flowgen typings/index.d.ts -o flow-typed/npm/@railsmob/events_v0.x.x.js.flow",
2629
"debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
27-
"format": "prettier --write '__tests__/**/*.js' 'src/**/*.js' 'index.js'"
30+
"format": "prettier --write \"{__tests__,src,typings}/**/*.{js,ts}\" \"./*.{js,json}\""
2831
},
2932
"files": [
33+
"src",
3034
"dist",
3135
"typings",
3236
"flow-typed"
@@ -39,10 +43,12 @@
3943
"babel-jest": "^24.9.0",
4044
"eslint": "^6.7.1",
4145
"flow-bin": "^0.113.0",
46+
"flowgen": "^1.10.0",
4247
"jest": "^24.9.0",
4348
"prettier": "^1.19.1",
4449
"rollup": "^1.27.5",
4550
"rollup-plugin-babel": "^4.3.3",
51+
"rollup-plugin-terser": "^5.1.3",
4652
"typescript": "^3.7.3"
4753
},
4854
"jest": {

rollup.config.js

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,56 @@
11
import babel from 'rollup-plugin-babel';
2+
import { terser } from 'rollup-plugin-terser';
23

3-
module.exports = {
4-
input: 'index.js',
5-
output: {
6-
file: 'dist/index.js',
7-
format: 'cjs',
8-
},
9-
plugins: [
10-
babel({
11-
exclude: 'node_modules/**',
12-
}),
13-
],
14-
};
4+
export default [
5+
// CommonJS
6+
{
7+
input: 'index.js',
8+
output: {
9+
file: 'lib/index.js',
10+
format: 'cjs',
11+
indent: false,
12+
},
13+
plugins: [babel()],
14+
},
15+
// ES
16+
{
17+
input: 'index.js',
18+
output: {
19+
file: 'es/index.js',
20+
format: 'es',
21+
indent: false,
22+
},
23+
plugins: [babel()],
24+
},
25+
// UMD Dev
26+
{
27+
input: 'index.js',
28+
output: {
29+
file: 'dist/index.js',
30+
format: 'umd',
31+
name: 'RailsmobEvents',
32+
indent: false,
33+
},
34+
plugins: [
35+
babel({
36+
exclude: 'node_modules/**',
37+
}),
38+
],
39+
},
40+
// UMD Prod
41+
{
42+
input: 'index.js',
43+
output: {
44+
file: 'dist/index.min.js',
45+
format: 'umd',
46+
name: 'RailsmobEvents',
47+
indent: false,
48+
},
49+
plugins: [
50+
babel({
51+
exclude: 'node_modules/**',
52+
}),
53+
terser(),
54+
],
55+
},
56+
];

src/Events.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* @typedef {(args: any) => any} ListenerFn
3-
* @typedef {{ id: string, fn: ListenerFn }} Listener
4-
*/
5-
61
export default class Events {
72
static SEP = ':';
83
static ANY = 'any';
@@ -11,10 +6,10 @@ export default class Events {
116
* @param {string} name
127
* @param {string} id
138
*/
14-
static id = (name, id) => `${name}${Events.SEP}${id}`;
9+
static id = (name, id) => name + Events.SEP + id;
1510

1611
/**
17-
* @type {{ [name: string]: Array<Listener> }}
12+
* @type {{ [name: string]: Array<{ id: string, fn: Function }> }}
1813
*/
1914
listeners = {};
2015

@@ -25,7 +20,7 @@ export default class Events {
2520

2621
/**
2722
* @param {string} eventId
28-
* @param {ListenerFn} fn
23+
* @param {Function} fn
2924
*/
3025
on = (eventId, fn) => {
3126
const [name, id] = this.parse(eventId);
@@ -35,11 +30,11 @@ export default class Events {
3530

3631
/**
3732
* @param {string} eventId
38-
* @param {ListenerFn} fn
33+
* @param {Function} fn
3934
*/
4035
once = (eventId, fn) => {
4136
/**
42-
* @type {ListenerFn}
37+
* @type {(args: any) => any}
4338
*/
4439
const handler = args => {
4540
fn(args);
@@ -50,7 +45,7 @@ export default class Events {
5045

5146
/**
5247
* @param {string} eventId
53-
* @param {ListenerFn} fn
48+
* @param {Function} fn
5449
*/
5550
off = (eventId, fn) => {
5651
const [name, id] = this.parse(eventId);

tsconfig.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@
88
"declaration": true,
99
"emitDeclarationOnly": true
1010
},
11-
"files": [
12-
"./index.js",
13-
"./src/Events.js"
14-
]
15-
}
11+
"files": ["./index.js", "./src/Events.js"]
12+
}

0 commit comments

Comments
 (0)