Skip to content

Commit

Permalink
fix(build): fix umb build for browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaledgarbaya authored Mar 29, 2017
1 parent 2ec6d3a commit f82f898
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 49 deletions.
7 changes: 0 additions & 7 deletions index.js

This file was deleted.

3 changes: 2 additions & 1 deletion lib/contentful.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import assign from 'lodash/assign'
import axios from 'axios'
import version from '../version'
import {createHttpClient} from 'contentful-sdk-core'
import createContentfulApi from './create-contentful-api'
Expand All @@ -31,7 +32,7 @@ import createLinkResolver from './create-link-resolver'
* space: 'mySpaceId'
* })
*/
export default function createClient (axios, params) {
export function createClient (params) {

This comment has been minimized.

Copy link
@SpainTrain

SpainTrain Mar 29, 2017

Contributor

@Khaledgarbaya FYI this was a breaking change in a patch release

This comment has been minimized.

Copy link
@Khaledgarbaya

Khaledgarbaya Mar 29, 2017

Author Contributor

@SpainTrain I don't think it's a breaking change since before we were passing axios in the index.js, here but now we don't do that anymore and made lib/contentful.js as the main entry point instead of the old index.js.

This comment has been minimized.

Copy link
@SpainTrain

SpainTrain Mar 29, 2017

Contributor

Upgrading from 4.1.0 to 4.1.1 broke our build.

Having to switch from

import contentful from 'contentful'

const client = contentful.createClient({/* config */})

to

import {createClient} from 'contentful'

const client = createClient({/* config */})

is pretty obviously a breaking change, unless I am missing something? Were we using the library incorrectly?

This comment has been minimized.

Copy link
@Khaledgarbaya

Khaledgarbaya Mar 29, 2017

Author Contributor

hmm weird it was always import {createClient} from 'contentful' for my case even for older versions like here

if (!params.accessToken) {
throw new TypeError('Expected parameter accessToken')
}
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "contentful",
"description": "Client for Contentful's Content Delivery API",
"version": "4.1.0",
"homepage": "https://www.contentful.com/developers/documentation/content-delivery-api/",
"main": "index.js",
"main": "./dist/contentful.js",
"repository": {
"type": "git",
"url": "https://github.com/contentful/contentful.js.git"
Expand Down Expand Up @@ -35,7 +36,6 @@
"browser-coverage": "npm run test:cover && opener coverage/lcov-report/index.html",
"prepublish": "in-publish && npm run build:ci || not-in-publish",
"postpublish": "npm run docs:publish && npm run clean",
"pretest": "standard lib/*.js && standard lib/**/*.js && standard test/**/*.js",
"test": "npm run test:cover && npm run test:integration && npm run test:browser-local",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"devdep:build": "pushd ../contentful-sdk-core && npm run build && popd",
Expand Down Expand Up @@ -106,9 +106,6 @@
"engines": {
"node": ">=4.7.2"
},
"publishConfig": {
"tag": "beta"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'blue-tape'
import filter from 'lodash/filter'
import map from 'lodash/map'
import contentful from '../../'
import * as contentful from '../../lib/contentful'
import Promise from 'es6-promise'
const params = {
accessToken: 'b4c0n73n7fu1',
Expand Down
68 changes: 34 additions & 34 deletions test/unit/contentful-test.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
import test from 'tape'
import sinon from 'sinon'
import createClient from '../../lib/contentful'

const axios = {create: sinon.stub()}
import {createClient, __RewireAPI__ as createClientRewireApi} from '../../lib/contentful'

test('Throws if no accessToken is defined', (t) => {
t.throws(() => {
createClient(axios, {space: 'spaceid'})
createClient({space: 'spaceid'})
}, /Expected parameter accessToken/)
t.end()
})

test('Throws if no space is defined', (t) => {
t.throws(() => {
createClient(axios, {accessToken: 'accesstoken'})
createClient({accessToken: 'accesstoken'})
}, /Expected parameter space/)
t.end()
})

test('Passes along HTTP client parameters', (t) => {
createClient.__Rewire__('version', 'version')
createClientRewireApi.__Rewire__('axios', sinon.stub)
createClientRewireApi.__Rewire__('version', 'version')
const createHttpClientStub = sinon.stub()
const rateLimitStub = sinon.stub()
createClient.__Rewire__('createHttpClient', createHttpClientStub)
createClient.__Rewire__('rateLimit', rateLimitStub)
createClient(axios, {accessToken: 'accesstoken', space: 'spaceid'})
createClientRewireApi.__Rewire__('createHttpClient', createHttpClientStub)
createClientRewireApi.__Rewire__('rateLimit', rateLimitStub)
createClient({accessToken: 'accesstoken', space: 'spaceid'})
t.ok(createHttpClientStub.args[0][1].headers['Content-Type'])
t.equals(createHttpClientStub.args[0][1].headers['X-Contentful-User-Agent'], 'contentful.js/version')
createClient.__ResetDependency__('rateLimit')
createClient.__ResetDependency__('createHttpClient')
createClientRewireApi.__ResetDependency__('rateLimit')
createClientRewireApi.__ResetDependency__('createHttpClient')
createClientRewireApi.__ResetDependency__('axios')
t.end()
})

test('Returns a client instance', (t) => {
const createHttpClientStub = sinon.stub()
const rateLimitStub = sinon.stub()
createClient.__Rewire__('createHttpClient', createHttpClientStub)
createClient.__Rewire__('rateLimit', rateLimitStub)
const client = createClient(axios, {accessToken: 'accesstoken', space: 'spaceid'})
createClientRewireApi.__Rewire__('createHttpClient', createHttpClientStub)
createClientRewireApi.__Rewire__('rateLimit', rateLimitStub)
const client = createClient({accessToken: 'accesstoken', space: 'spaceid'})
t.ok(client.getSpace, 'getSpace')
t.ok(client.getEntry, 'getEntry')
t.ok(client.getEntries, 'getEntries')
t.ok(client.getContentType, 'getContentType')
t.ok(client.getContentTypes, 'getContentTypes')
t.ok(client.getAsset, 'getAsset')
t.ok(client.getAssets, 'getAssets')
createClient.__ResetDependency__('rateLimit')
createClient.__ResetDependency__('createHttpClient')
createClientRewireApi.__ResetDependency__('rateLimit')
createClientRewireApi.__ResetDependency__('createHttpClient')
t.end()
})

test('Initializes API with link resolution turned on by default', (t) => {
const createHttpClientStub = sinon.stub()
const rateLimitStub = sinon.stub()
createClient.__Rewire__('createHttpClient', createHttpClientStub)
createClient.__Rewire__('rateLimit', rateLimitStub)
createClientRewireApi.__Rewire__('createHttpClient', createHttpClientStub)
createClientRewireApi.__Rewire__('rateLimit', rateLimitStub)
const apiStub = sinon.stub().returns({})
createClient.__Rewire__('createContentfulApi', apiStub)
createClient(axios, {accessToken: 'accesstoken', space: 'spaceid'})
createClientRewireApi.__Rewire__('createContentfulApi', apiStub)
createClient({accessToken: 'accesstoken', space: 'spaceid'})
t.ok(apiStub.args[0][0].shouldLinksResolve({}), 'not overriden by query')
t.notOk(apiStub.args[0][0].shouldLinksResolve({resolveLinks: false}), 'overriden by query')
createClient.__ResetDependency__('createHttpClient')
createClient.__ResetDependency__('rateLimit')
createClientRewireApi.__ResetDependency__('createHttpClient')
createClientRewireApi.__ResetDependency__('rateLimit')
t.end()
})

test('Initializes API with link resolution turned on explicitly', (t) => {
const createHttpClientStub = sinon.stub()
const rateLimitStub = sinon.stub()
createClient.__Rewire__('createHttpClient', createHttpClientStub)
createClient.__Rewire__('rateLimit', rateLimitStub)
createClientRewireApi.__Rewire__('createHttpClient', createHttpClientStub)
createClientRewireApi.__Rewire__('rateLimit', rateLimitStub)
const apiStub = sinon.stub().returns({})
createClient.__Rewire__('createContentfulApi', apiStub)
createClient(axios, {accessToken: 'accesstoken', space: 'spaceid', resolveLinks: true})
createClientRewireApi.__Rewire__('createContentfulApi', apiStub)
createClient({accessToken: 'accesstoken', space: 'spaceid', resolveLinks: true})
t.ok(apiStub.args[0][0].shouldLinksResolve({}), 'not overriden by query')
t.notOk(apiStub.args[0][0].shouldLinksResolve({resolveLinks: false}), 'overriden by query')
createClient.__ResetDependency__('createHttpClient')
createClient.__ResetDependency__('rateLimit')
createClientRewireApi.__ResetDependency__('createHttpClient')
createClientRewireApi.__ResetDependency__('rateLimit')
t.end()
})

test('Initializes API with link resolution turned off explicitly', (t) => {
const createHttpClientStub = sinon.stub()
const rateLimitStub = sinon.stub()
createClient.__Rewire__('createHttpClient', createHttpClientStub)
createClient.__Rewire__('rateLimit', rateLimitStub)
createClientRewireApi.__Rewire__('createHttpClient', createHttpClientStub)
createClientRewireApi.__Rewire__('rateLimit', rateLimitStub)
const apiStub = sinon.stub().returns({})
createClient.__Rewire__('createContentfulApi', apiStub)
createClient(axios, {accessToken: 'accesstoken', space: 'spaceid', resolveLinks: false})
createClientRewireApi.__Rewire__('createContentfulApi', apiStub)
createClient({accessToken: 'accesstoken', space: 'spaceid', resolveLinks: false})
t.notOk(apiStub.args[0][0].resolveLinksGlobalSetting)
createClient.__ResetDependency__('createHttpClient')
createClient.__ResetDependency__('rateLimit')
createClientRewireApi.__ResetDependency__('createHttpClient')
createClientRewireApi.__ResetDependency__('rateLimit')
t.end()
})
2 changes: 1 addition & 1 deletion version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = ''
module.exports = '4.1.0'

0 comments on commit f82f898

Please sign in to comment.