mirror of https://github.com/sundowndev/http.git
refactor(package): update module (#206)
parent
2347b08fc2
commit
6a34d0fc0b
|
@ -23,14 +23,12 @@ jobs:
|
|||
paths:
|
||||
- "node_modules"
|
||||
|
||||
# Build
|
||||
# - run:
|
||||
# name: Build
|
||||
# command: |
|
||||
# mkdir -p dist
|
||||
# yarn build
|
||||
|
||||
# Test
|
||||
- run:
|
||||
name: Tests
|
||||
command: yarn test && yarn codecov
|
||||
command: yarn test
|
||||
|
||||
# Coverage
|
||||
- run:
|
||||
name: Coverage
|
||||
command: yarn codecov
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# Common
|
||||
node_modules
|
||||
dist
|
||||
.nuxt
|
||||
coverage
|
||||
|
||||
# Plugin
|
||||
lib/plugin.js
|
29
.eslintrc.js
29
.eslintrc.js
|
@ -1,31 +1,10 @@
|
|||
module.exports = {
|
||||
root: true,
|
||||
// parser: 'babel-eslint',
|
||||
parserOptions: {
|
||||
parser: 'babel-eslint',
|
||||
sourceType: 'module'
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
node: true,
|
||||
jest: true
|
||||
},
|
||||
extends: 'standard',
|
||||
plugins: [
|
||||
'jest',
|
||||
'vue'
|
||||
],
|
||||
rules: {
|
||||
// Allow paren-less arrow functions
|
||||
'arrow-parens': 0,
|
||||
// Allow async-await
|
||||
'generator-star-spacing': 0,
|
||||
// Allow debugger during development
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
|
||||
// Do not allow console.logs etc...
|
||||
'no-console': 2
|
||||
},
|
||||
globals: {
|
||||
'jest/globals': true,
|
||||
jasmine: true
|
||||
}
|
||||
extends: [
|
||||
'@nuxtjs'
|
||||
]
|
||||
}
|
||||
|
|
|
@ -4,6 +4,6 @@ node_modules
|
|||
*.log*
|
||||
.nuxt
|
||||
.vscode
|
||||
.DS_STORE
|
||||
.DS_Store
|
||||
coverage
|
||||
_book
|
||||
dist
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2017 Nuxt Community
|
||||
Copyright (c) Nuxt Community
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
47
README.md
47
README.md
|
@ -1,28 +1,13 @@
|
|||
# 📦 Axios Module
|
||||
|
||||
> Secure and Easy <a href="https://github.com/mzabriskie/axios">Axios</a> integration with Nuxt.js.
|
||||
[![npm version][npm-version-src]][npm-version-href]
|
||||
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
||||
[![Circle CI][circle-ci-src]][circle-ci-href]
|
||||
[![Codecov][codecov-src]][codecov-href]
|
||||
[![Dependencies][david-dm-src]][david-dm-href]
|
||||
[![Standard JS][standard-js-src]][standard-js-href]
|
||||
|
||||
<p align="center">
|
||||
<a href="https://david-dm.org/nuxt-community/axios-module">
|
||||
<img alt="" src="https://david-dm.org/nuxt-community/axios-module/status.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://standardjs.com">
|
||||
<img alt="" src="https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://circleci.com/gh/nuxt-community/axios-module">
|
||||
<img alt="" src="https://img.shields.io/circleci/project/github/nuxt-community/axios-module.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://codecov.io/gh/nuxt-community/axios-module">
|
||||
<img alt="" src="https://img.shields.io/codecov/c/github/nuxt-community/axios-module.svg?style=flat-square">
|
||||
</a>
|
||||
<br>
|
||||
<a href="https://npmjs.com/package/@nuxtjs/axios">
|
||||
<img alt="" src="https://img.shields.io/npm/v/@nuxtjs/axios/latest.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://npmjs.com/package/@nuxtjs/axios">
|
||||
<img alt="" src="https://img.shields.io/npm/dt/@nuxtjs/axios.svg?style=flat-square">
|
||||
</a>
|
||||
</p>
|
||||
> Secure and Easy <a href="https://github.com/mzabriskie/axios">Axios</a> integration with Nuxt.js.
|
||||
|
||||
## ✅ Features
|
||||
|
||||
|
@ -46,4 +31,20 @@
|
|||
|
||||
## 📑 License
|
||||
|
||||
[MIT License](./LICENSE) - Nuxt Community
|
||||
[MIT License](./LICENSE)
|
||||
|
||||
Copyright (c) Nuxt Community
|
||||
|
||||
<!-- Badges -->
|
||||
[npm-version-src]: https://img.shields.io/npm/dt/@nuxtjs/axios.svg?style=flat-square
|
||||
[npm-version-href]: https://npmjs.com/package/@nuxtjs/axios
|
||||
[npm-downloads-src]: https://img.shields.io/npm/v/@nuxtjs/axios/latest.svg?style=flat-square
|
||||
[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/axios
|
||||
[circle-ci-src]: https://img.shields.io/circleci/project/github/nuxt-community/axios-module.svg?style=flat-square
|
||||
[circle-ci-href]: https://circleci.com/gh/nuxt-community/axios-module
|
||||
[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/axios-module.svg?style=flat-square
|
||||
[codecov-href]: https://codecov.io/gh/nuxt-community/axios-module
|
||||
[david-dm-src]: https://david-dm.org/nuxt-community/axios-module/status.svg?style=flat-square
|
||||
[david-dm-href]: https://david-dm.org/nuxt-community/axios-module
|
||||
[standard-js-src]: https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square
|
||||
[standard-js-href]: https://standardjs.com
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env', {
|
||||
targets: {
|
||||
esmodules: true
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
extends: [
|
||||
'@commitlint/config-conventional'
|
||||
]
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
module.exports = {
|
||||
hooks: {
|
||||
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
|
||||
'pre-commit': 'yarn lint',
|
||||
'pre-push': 'yarn lint'
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
module.exports = {
|
||||
testEnvironment: 'node',
|
||||
collectCoverage: true,
|
||||
collectCoverageFrom: [
|
||||
'lib/**/*.js',
|
||||
'!lib/plugin.js'
|
||||
],
|
||||
moduleNameMapper: {
|
||||
'^~/(.*)$': '<rootDir>/lib/$1',
|
||||
'^~~$': '<rootDir>',
|
||||
'^@@$': '<rootDir>',
|
||||
'^@/(.*)$': '<rootDir>/lib/$1'
|
||||
},
|
||||
transform: {
|
||||
'^.+\\.js$': 'babel-jest'
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ const consola = require('consola')
|
|||
|
||||
const logger = consola.withScope('nuxt:axios')
|
||||
|
||||
module.exports = function nuxtAxios (_moduleOptions) {
|
||||
function axiosModule(_moduleOptions) {
|
||||
// Combine options
|
||||
const moduleOptions = Object.assign({}, this.options.axios, _moduleOptions)
|
||||
|
||||
|
@ -79,7 +79,7 @@ module.exports = function nuxtAxios (_moduleOptions) {
|
|||
|
||||
// Register plugin
|
||||
this.addPlugin({
|
||||
src: path.resolve(__dirname, 'plugin.template.js'),
|
||||
src: path.resolve(__dirname, 'plugin.js'),
|
||||
fileName: 'axios.js',
|
||||
options
|
||||
})
|
||||
|
@ -99,4 +99,5 @@ module.exports = function nuxtAxios (_moduleOptions) {
|
|||
logger.debug(`browserBaseURL: ${options.browserBaseURL}`)
|
||||
}
|
||||
|
||||
module.exports = axiosModule
|
||||
module.exports.meta = require('../package.json')
|
||||
|
|
56
package.json
56
package.json
|
@ -3,6 +3,9 @@
|
|||
"version": "5.3.6",
|
||||
"description": "Secure and easy axios integration with Nuxt.js",
|
||||
"license": "MIT",
|
||||
"contributors": [
|
||||
"Pooya Parsa <pooya@pi0.ir>"
|
||||
],
|
||||
"main": "lib/module.js",
|
||||
"types": "index.d.ts",
|
||||
"repository": "https://github.com/nuxt-community/axios-module",
|
||||
|
@ -12,29 +15,13 @@
|
|||
"scripts": {
|
||||
"dev": "nuxt test/fixture",
|
||||
"lint": "eslint lib test",
|
||||
"test": "npm run lint && jest",
|
||||
"release": "standard-version && git push --follow-tags && npm publish",
|
||||
"prepare": "npm run test"
|
||||
"test": "yarn lint && jest",
|
||||
"release": "yarn test && standard-version && git push --follow-tags && npm publish"
|
||||
},
|
||||
"eslintIgnore": [
|
||||
"*.template.*"
|
||||
],
|
||||
"files": [
|
||||
"lib",
|
||||
"src",
|
||||
"dist",
|
||||
"index.d.ts"
|
||||
],
|
||||
"jest": {
|
||||
"testEnvironment": "node",
|
||||
"coverageDirectory": "./coverage/",
|
||||
"collectCoverage": true,
|
||||
"collectCoverageFrom": [
|
||||
"lib",
|
||||
"test",
|
||||
"!test/fixture"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@nuxtjs/proxy": "^1.3.1",
|
||||
"axios": "^0.18.0",
|
||||
|
@ -42,18 +29,25 @@
|
|||
"consola": "^2.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"codecov": "^3.1.0",
|
||||
"eslint": "^5.13.0",
|
||||
"eslint-config-standard": "^12.0.0",
|
||||
"eslint-plugin-import": "^2.16.0",
|
||||
"eslint-plugin-jest": "^22.2.2",
|
||||
"eslint-plugin-node": "^8.0.1",
|
||||
"eslint-plugin-promise": "^4.0.1",
|
||||
"eslint-plugin-standard": "^4.0.0",
|
||||
"eslint-plugin-vue": "^5.1.0",
|
||||
"jest": "^24.1.0",
|
||||
"jsdom": "^13.2.0",
|
||||
"nuxt-edge": "^2.3.0-25706271.cca799c",
|
||||
"standard-version": "^4.4.0"
|
||||
"@babel/core": "latest",
|
||||
"@babel/preset-env": "latest",
|
||||
"@commitlint/cli": "latest",
|
||||
"@commitlint/config-conventional": "latest",
|
||||
"@nuxtjs/eslint-config": "latest",
|
||||
"babel-eslint": "latest",
|
||||
"babel-jest": "latest",
|
||||
"codecov": "latest",
|
||||
"eslint": "latest",
|
||||
"eslint-config-standard": "latest",
|
||||
"eslint-plugin-import": "latest",
|
||||
"eslint-plugin-jest": "latest",
|
||||
"eslint-plugin-node": "latest",
|
||||
"eslint-plugin-promise": "latest",
|
||||
"eslint-plugin-standard": "latest",
|
||||
"eslint-plugin-vue": "latest",
|
||||
"husky": "latest",
|
||||
"jest": "latest",
|
||||
"nuxt-edge": "latest",
|
||||
"standard-version": "latest"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
jest.setTimeout(60000)
|
||||
|
||||
const { Nuxt, Builder } = require('nuxt-edge')
|
||||
const axios = require('axios')
|
||||
const config = require('./fixture/nuxt.config')
|
||||
|
@ -18,7 +20,7 @@ describe('axios module', () => {
|
|||
|
||||
await new Builder(nuxt).build()
|
||||
await nuxt.listen(3000)
|
||||
}, 60000)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await nuxt.close()
|
||||
|
@ -26,10 +28,10 @@ describe('axios module', () => {
|
|||
|
||||
test('baseURL', () => {
|
||||
expect(addTemplate).toBeDefined()
|
||||
let call = addTemplate.mock.calls.find(args =>
|
||||
args[0].src.includes('plugin.template.js')
|
||||
const call = addTemplate.mock.calls.find(args =>
|
||||
args[0].src.includes('plugin.js')
|
||||
)
|
||||
let options = call[0].options
|
||||
const options = call[0].options
|
||||
expect(options.baseURL.toString()).toBe(
|
||||
`http://localhost:3000/test_api`
|
||||
)
|
||||
|
@ -37,7 +39,7 @@ describe('axios module', () => {
|
|||
})
|
||||
|
||||
test('asyncData', async () => {
|
||||
let html = (await axios.get(url('/asyncData'))).data
|
||||
const html = (await axios.get(url('/asyncData'))).data
|
||||
expect(html).toContain('foo/bar')
|
||||
})
|
||||
|
||||
|
@ -65,10 +67,10 @@ describe('axios module', () => {
|
|||
.then(h => /session-[0-9]+/.exec(h))
|
||||
.then(m => (m && m[0] ? m[0] : null))
|
||||
|
||||
let a = await makeReq()
|
||||
let b = await makeReq(true)
|
||||
let c = await makeReq()
|
||||
let d = await makeReq(true)
|
||||
const a = await makeReq()
|
||||
const b = await makeReq(true)
|
||||
const c = await makeReq()
|
||||
const d = await makeReq(true)
|
||||
|
||||
expect(a).toBeNull()
|
||||
expect(b).not.toBeNull()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = {
|
||||
path: '/test_api',
|
||||
handler (req, res) {
|
||||
handler(req, res) {
|
||||
res.end(JSON.stringify({
|
||||
url: req.url,
|
||||
method: req.method
|
||||
|
|
|
@ -7,7 +7,9 @@ module.exports = {
|
|||
render: {
|
||||
resourceHints: false
|
||||
},
|
||||
modules: ['@@'],
|
||||
modules: [
|
||||
{ handler: require('../../') }
|
||||
],
|
||||
serverMiddleware: ['~/api.js'],
|
||||
axios: {
|
||||
prefix: `/test_api`,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export default function ({ $axios, redirect }) {
|
||||
$axios.onRequest(config => {
|
||||
$axios.onRequest((config) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('SPY: ' + config.url)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
export default {
|
||||
actions: {
|
||||
nuxtServerInit ({ commit }, ctx) {
|
||||
nuxtServerInit({ commit }, ctx) {
|
||||
if (!ctx.$axios) {
|
||||
throw new Error('$axios is not defined!')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue