Skip to content

Commit 6a34d0f

Browse files
ricardogobbosouzapi0
authored andcommitted
refactor(package): update module (#206)
1 parent 2347b08 commit 6a34d0f

19 files changed

+1827
-1664
lines changed

Diff for: .circleci/config.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ jobs:
2323
paths:
2424
- "node_modules"
2525

26-
# Build
27-
# - run:
28-
# name: Build
29-
# command: |
30-
# mkdir -p dist
31-
# yarn build
32-
3326
# Test
3427
- run:
3528
name: Tests
36-
command: yarn test && yarn codecov
29+
command: yarn test
30+
31+
# Coverage
32+
- run:
33+
name: Coverage
34+
command: yarn codecov

Diff for: .eslintignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Common
2+
node_modules
3+
dist
4+
.nuxt
5+
coverage
6+
7+
# Plugin
8+
lib/plugin.js

Diff for: .eslintrc.js

+4-25
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
11
module.exports = {
22
root: true,
3-
// parser: 'babel-eslint',
43
parserOptions: {
4+
parser: 'babel-eslint',
55
sourceType: 'module'
66
},
7-
env: {
8-
browser: true,
9-
node: true,
10-
jest: true
11-
},
12-
extends: 'standard',
13-
plugins: [
14-
'jest',
15-
'vue'
16-
],
17-
rules: {
18-
// Allow paren-less arrow functions
19-
'arrow-parens': 0,
20-
// Allow async-await
21-
'generator-star-spacing': 0,
22-
// Allow debugger during development
23-
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
24-
// Do not allow console.logs etc...
25-
'no-console': 2
26-
},
27-
globals: {
28-
'jest/globals': true,
29-
jasmine: true
30-
}
7+
extends: [
8+
'@nuxtjs'
9+
]
3110
}

Diff for: .gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ node_modules
44
*.log*
55
.nuxt
66
.vscode
7-
.DS_STORE
7+
.DS_Store
88
coverage
9-
_book
9+
dist

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 Nuxt Community
3+
Copyright (c) Nuxt Community
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Diff for: README.md

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
# 📦 Axios Module
22

3-
> Secure and Easy <a href="https://github.com/mzabriskie/axios">Axios</a> integration with Nuxt.js.
3+
[![npm version][npm-version-src]][npm-version-href]
4+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
5+
[![Circle CI][circle-ci-src]][circle-ci-href]
6+
[![Codecov][codecov-src]][codecov-href]
7+
[![Dependencies][david-dm-src]][david-dm-href]
8+
[![Standard JS][standard-js-src]][standard-js-href]
49

5-
<p align="center">
6-
<a href="https://david-dm.org/nuxt-community/axios-module">
7-
<img alt="" src="https://david-dm.org/nuxt-community/axios-module/status.svg?style=flat-square">
8-
</a>
9-
<a href="https://standardjs.com">
10-
<img alt="" src="https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square">
11-
</a>
12-
<a href="https://circleci.com/gh/nuxt-community/axios-module">
13-
<img alt="" src="https://img.shields.io/circleci/project/github/nuxt-community/axios-module.svg?style=flat-square">
14-
</a>
15-
<a href="https://codecov.io/gh/nuxt-community/axios-module">
16-
<img alt="" src="https://img.shields.io/codecov/c/github/nuxt-community/axios-module.svg?style=flat-square">
17-
</a>
18-
<br>
19-
<a href="https://npmjs.com/package/@nuxtjs/axios">
20-
<img alt="" src="https://img.shields.io/npm/v/@nuxtjs/axios/latest.svg?style=flat-square">
21-
</a>
22-
<a href="https://npmjs.com/package/@nuxtjs/axios">
23-
<img alt="" src="https://img.shields.io/npm/dt/@nuxtjs/axios.svg?style=flat-square">
24-
</a>
25-
</p>
10+
> Secure and Easy <a href="https://github.com/mzabriskie/axios">Axios</a> integration with Nuxt.js.
2611
2712
## ✅ Features
2813

@@ -46,4 +31,20 @@
4631

4732
## 📑 License
4833

49-
[MIT License](./LICENSE) - Nuxt Community
34+
[MIT License](./LICENSE)
35+
36+
Copyright (c) Nuxt Community
37+
38+
<!-- Badges -->
39+
[npm-version-src]: https://img.shields.io/npm/dt/@nuxtjs/axios.svg?style=flat-square
40+
[npm-version-href]: https://npmjs.com/package/@nuxtjs/axios
41+
[npm-downloads-src]: https://img.shields.io/npm/v/@nuxtjs/axios/latest.svg?style=flat-square
42+
[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/axios
43+
[circle-ci-src]: https://img.shields.io/circleci/project/github/nuxt-community/axios-module.svg?style=flat-square
44+
[circle-ci-href]: https://circleci.com/gh/nuxt-community/axios-module
45+
[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/axios-module.svg?style=flat-square
46+
[codecov-href]: https://codecov.io/gh/nuxt-community/axios-module
47+
[david-dm-src]: https://david-dm.org/nuxt-community/axios-module/status.svg?style=flat-square
48+
[david-dm-href]: https://david-dm.org/nuxt-community/axios-module
49+
[standard-js-src]: https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square
50+
[standard-js-href]: https://standardjs.com

Diff for: babel.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env', {
5+
targets: {
6+
esmodules: true
7+
}
8+
}
9+
]
10+
]
11+
}

Diff for: commitlint.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
extends: [
3+
'@commitlint/config-conventional'
4+
]
5+
}

Diff for: husky.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
hooks: {
3+
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
4+
'pre-commit': 'yarn lint',
5+
'pre-push': 'yarn lint'
6+
}
7+
}

Diff for: jest.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
collectCoverage: true,
4+
collectCoverageFrom: [
5+
'lib/**/*.js',
6+
'!lib/plugin.js'
7+
],
8+
moduleNameMapper: {
9+
'^~/(.*)$': '<rootDir>/lib/$1',
10+
'^~~$': '<rootDir>',
11+
'^@@$': '<rootDir>',
12+
'^@/(.*)$': '<rootDir>/lib/$1'
13+
},
14+
transform: {
15+
'^.+\\.js$': 'babel-jest'
16+
}
17+
}

Diff for: lib/module.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const consola = require('consola')
33

44
const logger = consola.withScope('nuxt:axios')
55

6-
module.exports = function nuxtAxios (_moduleOptions) {
6+
function axiosModule(_moduleOptions) {
77
// Combine options
88
const moduleOptions = Object.assign({}, this.options.axios, _moduleOptions)
99

@@ -79,7 +79,7 @@ module.exports = function nuxtAxios (_moduleOptions) {
7979

8080
// Register plugin
8181
this.addPlugin({
82-
src: path.resolve(__dirname, 'plugin.template.js'),
82+
src: path.resolve(__dirname, 'plugin.js'),
8383
fileName: 'axios.js',
8484
options
8585
})
@@ -99,4 +99,5 @@ module.exports = function nuxtAxios (_moduleOptions) {
9999
logger.debug(`browserBaseURL: ${options.browserBaseURL}`)
100100
}
101101

102+
module.exports = axiosModule
102103
module.exports.meta = require('../package.json')

Diff for: lib/plugin.template.js renamed to lib/plugin.js

File renamed without changes.

Diff for: package.json

+25-31
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"version": "5.3.6",
44
"description": "Secure and easy axios integration with Nuxt.js",
55
"license": "MIT",
6+
"contributors": [
7+
"Pooya Parsa <[email protected]>"
8+
],
69
"main": "lib/module.js",
710
"types": "index.d.ts",
811
"repository": "https://github.com/nuxt-community/axios-module",
@@ -12,48 +15,39 @@
1215
"scripts": {
1316
"dev": "nuxt test/fixture",
1417
"lint": "eslint lib test",
15-
"test": "npm run lint && jest",
16-
"release": "standard-version && git push --follow-tags && npm publish",
17-
"prepare": "npm run test"
18+
"test": "yarn lint && jest",
19+
"release": "yarn test && standard-version && git push --follow-tags && npm publish"
1820
},
19-
"eslintIgnore": [
20-
"*.template.*"
21-
],
2221
"files": [
2322
"lib",
24-
"src",
25-
"dist",
2623
"index.d.ts"
2724
],
28-
"jest": {
29-
"testEnvironment": "node",
30-
"coverageDirectory": "./coverage/",
31-
"collectCoverage": true,
32-
"collectCoverageFrom": [
33-
"lib",
34-
"test",
35-
"!test/fixture"
36-
]
37-
},
3825
"dependencies": {
3926
"@nuxtjs/proxy": "^1.3.1",
4027
"axios": "^0.18.0",
4128
"axios-retry": "^3.1.2",
4229
"consola": "^2.4.0"
4330
},
4431
"devDependencies": {
45-
"codecov": "^3.1.0",
46-
"eslint": "^5.13.0",
47-
"eslint-config-standard": "^12.0.0",
48-
"eslint-plugin-import": "^2.16.0",
49-
"eslint-plugin-jest": "^22.2.2",
50-
"eslint-plugin-node": "^8.0.1",
51-
"eslint-plugin-promise": "^4.0.1",
52-
"eslint-plugin-standard": "^4.0.0",
53-
"eslint-plugin-vue": "^5.1.0",
54-
"jest": "^24.1.0",
55-
"jsdom": "^13.2.0",
56-
"nuxt-edge": "^2.3.0-25706271.cca799c",
57-
"standard-version": "^4.4.0"
32+
"@babel/core": "latest",
33+
"@babel/preset-env": "latest",
34+
"@commitlint/cli": "latest",
35+
"@commitlint/config-conventional": "latest",
36+
"@nuxtjs/eslint-config": "latest",
37+
"babel-eslint": "latest",
38+
"babel-jest": "latest",
39+
"codecov": "latest",
40+
"eslint": "latest",
41+
"eslint-config-standard": "latest",
42+
"eslint-plugin-import": "latest",
43+
"eslint-plugin-jest": "latest",
44+
"eslint-plugin-node": "latest",
45+
"eslint-plugin-promise": "latest",
46+
"eslint-plugin-standard": "latest",
47+
"eslint-plugin-vue": "latest",
48+
"husky": "latest",
49+
"jest": "latest",
50+
"nuxt-edge": "latest",
51+
"standard-version": "latest"
5852
}
5953
}

Diff for: test/axios.test.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
jest.setTimeout(60000)
2+
13
const { Nuxt, Builder } = require('nuxt-edge')
24
const axios = require('axios')
35
const config = require('./fixture/nuxt.config')
@@ -18,26 +20,26 @@ describe('axios module', () => {
1820

1921
await new Builder(nuxt).build()
2022
await nuxt.listen(3000)
21-
}, 60000)
23+
})
2224

2325
afterAll(async () => {
2426
await nuxt.close()
2527
})
2628

2729
test('baseURL', () => {
2830
expect(addTemplate).toBeDefined()
29-
let call = addTemplate.mock.calls.find(args =>
30-
args[0].src.includes('plugin.template.js')
31+
const call = addTemplate.mock.calls.find(args =>
32+
args[0].src.includes('plugin.js')
3133
)
32-
let options = call[0].options
34+
const options = call[0].options
3335
expect(options.baseURL.toString()).toBe(
3436
`http://localhost:3000/test_api`
3537
)
3638
expect(options.browserBaseURL.toString()).toBe('/test_api')
3739
})
3840

3941
test('asyncData', async () => {
40-
let html = (await axios.get(url('/asyncData'))).data
42+
const html = (await axios.get(url('/asyncData'))).data
4143
expect(html).toContain('foo/bar')
4244
})
4345

@@ -65,10 +67,10 @@ describe('axios module', () => {
6567
.then(h => /session-[0-9]+/.exec(h))
6668
.then(m => (m && m[0] ? m[0] : null))
6769

68-
let a = await makeReq()
69-
let b = await makeReq(true)
70-
let c = await makeReq()
71-
let d = await makeReq(true)
70+
const a = await makeReq()
71+
const b = await makeReq(true)
72+
const c = await makeReq()
73+
const d = await makeReq(true)
7274

7375
expect(a).toBeNull()
7476
expect(b).not.toBeNull()

Diff for: test/fixture/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
path: '/test_api',
3-
handler (req, res) {
3+
handler(req, res) {
44
res.end(JSON.stringify({
55
url: req.url,
66
method: req.method

Diff for: test/fixture/nuxt.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module.exports = {
77
render: {
88
resourceHints: false
99
},
10-
modules: ['@@'],
10+
modules: [
11+
{ handler: require('../../') }
12+
],
1113
serverMiddleware: ['~/api.js'],
1214
axios: {
1315
prefix: `/test_api`,

Diff for: test/fixture/plugins/axios.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default function ({ $axios, redirect }) {
2-
$axios.onRequest(config => {
2+
$axios.onRequest((config) => {
33
// eslint-disable-next-line no-console
44
console.log('SPY: ' + config.url)
55

Diff for: test/fixture/store/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default {
22
actions: {
3-
nuxtServerInit ({ commit }, ctx) {
3+
nuxtServerInit({ commit }, ctx) {
44
if (!ctx.$axios) {
55
throw new Error('$axios is not defined!')
66
}

0 commit comments

Comments
 (0)