Skip to content

Commit

Permalink
fix: server-chan 新增弃用 warn
Browse files Browse the repository at this point in the history
fix #5
  • Loading branch information
CaoMeiYouRen committed Mar 2, 2021
1 parent 5aef7e3 commit c9a9d0d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const __WARN__ = process.env.NODE_ENV === 'production' ? 1 : 0
module.exports = {
root: true,
globals: {
globalThis: true,
},
env: {
},
Expand Down
31 changes: 16 additions & 15 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function getPlugins({ isBrowser = false, isMin = false, isDeclaration = false })
replace({
exclude: 'node_modules/**',
'process.env.NODE_ENV': JSON.stringify(env.NODE_ENV || 'production'),
'process.browser': isBrowser,
preventAssignment: false,
}),
)
Expand Down Expand Up @@ -130,19 +131,19 @@ export default [
isMin: false,
}),
},
// { // 本包不推荐在浏览器中使用,故不生成浏览器版本
// input: 'src/index.ts',
// external,
// output: {
// file: 'dist/index.browser.js', // 生成 browser
// format: 'umd',
// name: outputName,
// sourcemap: true,
// },
// plugins: getPlugins({
// isBrowser: true,
// isDeclaration: false,
// isMin: true,
// }),
// },
{ // 本包不推荐在浏览器中使用,故不生成浏览器版本
input: 'src/index.ts',
external,
output: {
file: 'dist/index.browser.js', // 生成 browser
format: 'umd',
name: outputName,
sourcemap: true,
},
plugins: getPlugins({
isBrowser: true,
isDeclaration: false,
isMin: false,
}),
},
]
4 changes: 4 additions & 0 deletions src/config/env.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export const __PROD__ = process.env.NODE_ENV === 'production'
export const __DEV__ = process.env.NODE_ENV === 'development'

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// export const __BROWSER__ = typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs
2 changes: 2 additions & 0 deletions src/push/server-chan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ajax } from '@/utils/ajax'
import { AxiosResponse } from 'axios'
import debug from 'debug'
import { warn } from '@/utils/helper'
import { Send } from '../interfaces/send'

const Debugger = debug('push:server-chan')
Expand All @@ -24,6 +25,7 @@ export class ServerChan implements Send {
constructor(SCKEY: string) {
this.SCKEY = SCKEY
Debugger('set SCKEY: "%s"', SCKEY)
warn('ServerChan 已弃用!将在2021年4月后下线,请尽快完成配置的更新。详见 https://sc.ftqq.com')
if (!this.SCKEY) {
throw new Error('SCKEY 是必须的!')
}
Expand Down
5 changes: 4 additions & 1 deletion src/utils/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export async function ajax(config: AjaxConfig): Promise<AxiosResponse<any>> {
if (typeof reqData === 'object' && reqHeaders[contentType] === 'application/x-www-form-urlencoded') {
return qs.stringify(reqData)
}
if (typeof reqData === 'string' || reqData instanceof Buffer || reqData instanceof ArrayBuffer) {
if (typeof reqData === 'string') {
return reqData
}
if (reqData instanceof Buffer || reqData instanceof ArrayBuffer) {
return reqData
}
return JSON.stringify(reqData)
Expand Down

0 comments on commit c9a9d0d

Please sign in to comment.