Skip to content

Commit 255fccb

Browse files
committed
chore: removed yarn; fix: rollup build; chore: changed attaching error model to the axios
1 parent b4481cd commit 255fccb

File tree

7 files changed

+32
-2028
lines changed

7 files changed

+32
-2028
lines changed

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ node_js:
44
- "node"
55

66
cache:
7-
yarn: true
87
directories:
98
- "node_modules"
109

@@ -18,16 +17,16 @@ before_install:
1817
- export RELEASE_BODY=$(node -p "'[Click here to see release changes](https://github.com/$PROJECT_NAME/blob/$TRAVIS_BRANCH/CHANGELOG.md#' + require('./bin/getLatestTag.js') + ')'")
1918

2019
install:
21-
- yarn install --frozen-lockfile
20+
- npm ci
2221

2322
jobs:
2423
include:
2524
- stage: lint
26-
script: yarn lint
25+
script: npm run lint
2726
- stage: test
2827
script:
29-
- yarn run build
30-
- yarn test
28+
- npm run build
29+
- npm run test
3130
# - stage: publish
3231
# if: env(BRANCH_IS_TAG) != true AND branch = master AND type = push
3332
# name: "Create Github Release"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525

2626
<!-- ```js
2727
import kinka from 'kinka'
28-
import KinkaSerializy from 'axios-serializy'
28+
import axiosSerializy from 'axios-serializy'
2929
3030
3131
const api = kinka.create({
3232
baseURL: 'https://your-api.com',
3333
middlewares: [
34-
KinkaSerializy
34+
axiosSerializy
3535
]
3636
})
3737
@@ -51,7 +51,7 @@ Also if you want to serialize error messages from server you need to:
5151
const api = kinka.create({
5252
baseURL: 'https://your-api.com',
5353
middlewares: [
54-
KinkaSerializy({
54+
axiosSerializy({
5555
errorModel: YourPrettifiedErrorModel
5656
})
5757
]

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"clean": "rimraf lib dist es",
1212
"lint": "eslint .",
1313
"lint-fix": "eslint . --fix",
14-
"prepare": "yarn clean && yarn build",
14+
"prepare": "npm run clean && npm run build",
1515
"test": "exit 0"
1616
},
1717
"author": {

rollup.config.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ const replace = require('rollup-plugin-replace')
55
const terser = require('rollup-plugin-terser').terser
66
// const commonjs = require('rollup-plugin-commonjs')
77

8-
const deps = [
9-
...Object.keys(packageJson.dependencies || {}),
10-
...Object.keys(packageJson.peerDependencies || {}),
11-
]
8+
const deps = [...Object.keys(packageJson.peerDependencies || {})]
129

1310
const inputOutputConfig = (outputFile, outputFormat, commonOutput = {}) => ({
1411
input: 'src/index.js',
@@ -46,7 +43,12 @@ const productionBuildPlugins = [
4643
'response',
4744
'request',
4845
'isError',
49-
'KinkaSerializy',
46+
'interceptors',
47+
'axiosSerializy',
48+
'serializeResponseData',
49+
'deserializeRequestData',
50+
'use',
51+
'setErrorModel',
5052
],
5153
},
5254
module: true,
@@ -60,19 +62,19 @@ module.exports = [
6062
{
6163
...inputOutputConfig('lib/axios-serializy.js', 'cjs'),
6264
external: deps,
63-
plugins: [babel()],
65+
plugins: [resolve(), babel()],
6466
},
6567
{
6668
...inputOutputConfig('lib/axios-serializy.min.js', 'cjs'),
6769
external: deps,
68-
plugins: [babel(), ...productionBuildPlugins],
70+
plugins: [resolve(), babel(), ...productionBuildPlugins],
6971
},
7072

7173
// EcmaScript builds
7274
{
7375
...inputOutputConfig('es/axios-serializy.js', 'es'),
7476
external: deps,
75-
plugins: [babel()],
77+
plugins: [resolve(), babel()],
7678
},
7779
{
7880
...inputOutputConfig('es/axios-serializy.mjs', 'es'),
@@ -83,7 +85,10 @@ module.exports = [
8385
// UMD builds
8486
{
8587
...inputOutputConfig('dist/axios-serializy.js', 'umd', {
86-
name: 'KinkaSerializy',
88+
name: 'axiosSerializy',
89+
globals: {
90+
axios: 'axios',
91+
},
8792
}),
8893
external: deps,
8994
plugins: [
@@ -98,7 +103,10 @@ module.exports = [
98103
},
99104
{
100105
...inputOutputConfig('dist/axios-serializy.min.js', 'umd', {
101-
name: 'KinkaSerializy',
106+
name: 'axiosSerializy',
107+
globals: {
108+
axios: 'axios',
109+
},
102110
}),
103111
external: deps,
104112
plugins: [

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
serializeResponseData,
55
} from 'http-helpers-serializy'
66

7-
let errorModel = null
7+
axios._errorModel = null
88

99
axios.interceptors.request.use(
1010
function(config) {
@@ -39,15 +39,15 @@ axios.interceptors.response.use(
3939
return response
4040
},
4141
function(error) {
42-
if (errorModel && error.response) {
42+
if (axios._errorModel && error.response) {
4343
const { error: serializedError } = serializeResponseData(
4444
error.config.model,
4545
null,
4646
{
4747
method: error.config.method,
4848
url: error.config.url,
4949
isError: true,
50-
errorModel,
50+
errorModel: axios._errorModel,
5151
error: error.response.data,
5252
}
5353
)
@@ -59,8 +59,8 @@ axios.interceptors.response.use(
5959
}
6060
)
6161

62-
export function attachErrorModel(_errorModel) {
63-
errorModel = _errorModel
62+
axios.setErrorModel = function(_errorModel) {
63+
axios._errorModel = _errorModel
6464
}
6565

6666
export default axios

0 commit comments

Comments
 (0)