Skip to content

Commit 2437eaf

Browse files
committed
build: use rollup to build esm, cjs, and browser bundles
1 parent 58d6dc4 commit 2437eaf

24 files changed

+3576
-5759
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
"@babel/plugin-proposal-object-rest-spread",
77
"@babel/transform-async-to-generator"
88
]
9-
}
9+
}

package-lock.json

+3,233-4,661
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+19-11
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,17 @@
77
"test:unit:watch": "MOCK_AXIOS=true jest ./tests/unit --watch",
88
"test:integration": "jest ./tests/integration/",
99
"test:integration:watch": "jest ./tests/integration/ --watch",
10-
"build": "npm run build:dist && npm run build:lib",
11-
"build:dist": "webpack --mode production",
12-
"build:lib": "NODE_ENV=production babel src --out-dir lib",
10+
"build": "rm -rf ./dist && rollup -c",
1311
"prepublish": "in-publish && npm run build || not-in-publish",
12+
"prepare": "npm run build",
1413
"lint": "standard ./src",
1514
"semantic-release": "semantic-release",
1615
"server": "node ./tests/integration/mockServer.js",
1716
"server:dev": "nodemon ./tests/integration/mockServer.js"
1817
},
19-
"main": "lib/typeform.js",
20-
"directories": {
21-
"lib": "lib",
22-
"test": "tests"
23-
},
18+
"main": "dist/index.cjs.js",
19+
"browser": "dist/typeform-api.js",
20+
"module": "dist/index.esm.js",
2421
"engines": {
2522
"node": ">=8"
2623
},
@@ -42,6 +39,14 @@
4239
"url": "https://github.com/Typeform/js-api-client/issues"
4340
},
4441
"homepage": "https://github.com/Typeform/js-api-client#readme",
42+
"files": [
43+
"dist/**",
44+
"LICENSE.md",
45+
"package.json",
46+
"package-lock.json",
47+
"README.md",
48+
"yarn.lock"
49+
],
4550
"dependencies": {
4651
"axios": "^0.19.0"
4752
},
@@ -70,10 +75,13 @@
7075
"json-server": "^0.14.0",
7176
"lint-staged": "^7.0.4",
7277
"nodemon": "^1.18.3",
78+
"rollup": "^1.20.0",
79+
"rollup-plugin-commonjs": "^10.0.2",
80+
"rollup-plugin-json": "^4.0.0",
81+
"rollup-plugin-node-resolve": "^5.2.0",
82+
"rollup-plugin-terser": "^5.1.1",
7383
"semantic-release": "^15.13.19",
74-
"standard": "^11.0.1",
75-
"webpack": "^4.20.2",
76-
"webpack-cli": "^3.1.1"
84+
"standard": "^11.0.1"
7785
},
7886
"lint-staged": {
7987
"*.js": [

rollup.config.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import commonjs from 'rollup-plugin-commonjs'
2+
import json from 'rollup-plugin-json'
3+
import resolveModule from 'rollup-plugin-node-resolve'
4+
import pkg from './package.json'
5+
import { terser } from 'rollup-plugin-terser'
6+
7+
const onwarn = (warning, rollupWarn) => {
8+
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
9+
rollupWarn(warning)
10+
}
11+
}
12+
13+
const plugins = [
14+
commonjs({
15+
include: ['node_modules/**']
16+
}),
17+
json()
18+
]
19+
20+
export default [{
21+
input: 'src/index.js',
22+
output: [{
23+
file: pkg.main,
24+
format: 'cjs',
25+
exports: 'named'
26+
}, {
27+
file: pkg.module,
28+
format: 'es',
29+
exports: 'named'
30+
}],
31+
onwarn,
32+
plugins: [
33+
resolveModule({
34+
mainFields: ['main', 'module'],
35+
preferBuiltins: true
36+
}),
37+
...plugins
38+
],
39+
external: ['http', 'https', 'url', 'zlib', 'assert', 'stream', 'tty', 'util', 'os']
40+
}, {
41+
input: 'src/index.js',
42+
output: {
43+
file: pkg.browser,
44+
format: 'umd',
45+
name: 'typeformAPI',
46+
exports: 'named'
47+
},
48+
onwarn,
49+
plugins: [
50+
resolveModule({
51+
mainFields: ['browser']
52+
}),
53+
terser(),
54+
...plugins
55+
]
56+
}]

src/forms.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export default http => new Form(http)
2-
3-
class Form {
1+
export class Forms {
42
constructor (_http) {
53
this._http = _http
64
this._messages = new FormMessages(_http)

src/images.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export default http => new Images(http)
2-
3-
class Images {
1+
export class Images {
42
constructor (_http) {
53
this._http = _http
64
}

src/index.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { clientConstructor } from './create-client'
2+
import { Forms } from './forms'
3+
import { Images } from './images'
4+
import { Teams } from './teams'
5+
import { Themes } from './themes'
6+
import { Workspaces } from './workspaces'
7+
import { Responses } from './responses'
8+
import { Webhooks } from './webhooks'
9+
10+
export const createClient = (args = {}) => {
11+
if (!args.token) {
12+
throw new Error('Token is missing')
13+
}
14+
15+
const http = clientConstructor(args)
16+
17+
return {
18+
forms: new Forms(http),
19+
images: new Images(http),
20+
teams: new Teams(http),
21+
themes: new Themes(http),
22+
workspaces: new Workspaces(http),
23+
responses: new Responses(http),
24+
webhooks: new Webhooks(http)
25+
}
26+
}

src/responses.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export default http => new Responses(http)
2-
3-
class Responses {
1+
export class Responses {
42
constructor (_http) {
53
this._http = _http
64
}

src/teams.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { isMemberPropValid, createMemberPatchQuery } from './utils'
22

3-
export default http => new Teams(http)
4-
5-
class Teams {
3+
export class Teams {
64
constructor (_http) {
75
this._http = _http
86
}

src/themes.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { FONTS_AVAILABLE } from './constants'
22

3-
export default http => new Themes(http)
4-
5-
class Themes {
3+
export class Themes {
64
constructor (_http) {
75
this._http = _http
86
}

src/typeform.js

-28
This file was deleted.

src/webhooks.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export default http => new Webhooks(http)
2-
3-
class Webhooks {
1+
export class Webhooks {
42
constructor (_http) {
53
this._http = _http
64
}

src/workspaces.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { isMemberPropValid, createMemberPatchQuery } from './utils'
22

3-
export default http => new Workspaces(http)
4-
5-
class Workspaces {
3+
export class Workspaces {
64
constructor (_http) {
75
this._http = _http
86
}

tests/integration/forms.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createClient } from '../../src/typeform'
1+
import { createClient } from '../../src'
22

33
jest.mock('../../src/constants', () => ({ API_BASE_URL: 'http://localhost:3000' }))
44

tests/unit/forms.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { clientConstructor } from '../../src/create-client'
22
import { API_BASE_URL } from '../../src/constants'
3-
import forms from '../../src/forms'
3+
import { Forms } from '../../src/forms'
44

55
beforeEach(() => {
66
axios.reset()
@@ -10,7 +10,7 @@ beforeEach(() => {
1010
const http = clientConstructor({
1111
token: '123'
1212
})
13-
const formsRequest = forms(http)
13+
const formsRequest = new Forms(http)
1414

1515
test('get all forms has the correct method and path', async () => {
1616
await formsRequest.list()

tests/unit/images.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { clientConstructor } from '../../src/create-client'
22
import { API_BASE_URL } from '../../src/constants'
3-
import images from '../../src/images'
3+
import { Images } from '../../src/images'
44

55
beforeEach(() => {
66
axios.reset()
@@ -10,7 +10,7 @@ beforeEach(() => {
1010
const http = clientConstructor({
1111
token: '123'
1212
})
13-
const imagesRequest = images(http)
13+
const imagesRequest = new Images(http)
1414

1515
test('get images collection', async () => {
1616
await imagesRequest.list()

tests/unit/typeform.test.js renamed to tests/unit/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { clientConstructor } from '../../src/create-client'
2-
import { createClient } from '../../src/typeform'
2+
import { createClient } from '../../src'
33

44
beforeEach(() => {
55
axios.reset()

tests/unit/responses.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { API_BASE_URL } from '../../src/constants'
22
import { clientConstructor } from '../../src/create-client'
3-
import responses from '../../src/responses'
3+
import { Responses } from '../../src/responses'
44

55
beforeEach(() => {
66
axios.reset()
@@ -11,7 +11,7 @@ const http = clientConstructor({
1111
token: '123'
1212
})
1313

14-
const responsesRequest = responses(http)
14+
const responsesRequest = new Responses(http)
1515

1616
test('List responses has the correct path and method', async () => {
1717
await responsesRequest.list({ uid: 2 })

tests/unit/teams.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { clientConstructor } from '../../src/create-client'
22
import { API_BASE_URL } from '../../src/constants'
3-
import teams from '../../src/teams'
3+
import { Teams } from '../../src/teams'
44

55
beforeEach(() => {
66
axios.reset()
@@ -10,7 +10,7 @@ beforeEach(() => {
1010
const http = clientConstructor({
1111
token: '123'
1212
})
13-
const teamsRequest = teams(http)
13+
const teamsRequest = new Teams(http)
1414

1515
test('getTeam has the correct url in the request', async () => {
1616
await teamsRequest.get()

tests/unit/themes.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { clientConstructor } from '../../src/create-client'
22
import { API_BASE_URL } from '../../src/constants'
3-
import themes from '../../src/themes'
3+
import { Themes } from '../../src/themes'
44

55
const mockThemePayload = {
66
name: 'New theme',
@@ -21,7 +21,7 @@ beforeEach(() => {
2121
const http = clientConstructor({
2222
token: '123'
2323
})
24-
const themesRequest = themes(http)
24+
const themesRequest = new Themes(http)
2525

2626
test('Get themes has the correct path', async () => {
2727
await themesRequest.list()

tests/unit/webhooks.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { clientConstructor } from '../../src/create-client'
22
import { API_BASE_URL } from '../../src/constants'
3-
4-
import webhooks from '../../src/webhooks'
3+
import { Webhooks } from '../../src/webhooks'
54

65
beforeEach(() => {
76
axios.reset()
@@ -11,7 +10,7 @@ beforeEach(() => {
1110
const http = clientConstructor({
1211
token: '123'
1312
})
14-
const webhooksRequest = webhooks(http)
13+
const webhooksRequest = new Webhooks(http)
1514

1615
test('Create a new webhooks has the correct path, method and url', async () => {
1716
const request = {

tests/unit/workspaces.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { clientConstructor } from '../../src/create-client'
22
import { API_BASE_URL } from '../../src/constants'
3-
import workspaces from '../../src/workspaces'
3+
import { Workspaces } from '../../src/workspaces'
44

55
beforeEach(() => {
66
axios.reset()
@@ -10,7 +10,7 @@ beforeEach(() => {
1010
const http = clientConstructor({
1111
token: '123'
1212
})
13-
const workspacesRequest = workspaces(http)
13+
const workspacesRequest = new Workspaces(http)
1414

1515
test(`Get workspaces has the correct path`, async () => {
1616
await workspacesRequest.list()

webpack.config.js

-20
This file was deleted.

0 commit comments

Comments
 (0)