create-packer 1.26.3 → 1.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/template/docusaurus/package.json +1 -1
- package/template/lib/react/.eslintrc +1 -1
- package/template/lib/react/.stylelintrc +9 -3
- package/template/lib/react/package.json +12 -12
- package/template/lib/ts/package.json +9 -9
- package/template/nest/package.json +6 -6
- package/template/web-app/next/.stylelintrc +9 -3
- package/template/web-app/next/package.json +8 -8
- package/template/web-app/react/.eslintrc +1 -1
- package/template/web-app/react/.stylelintrc +9 -3
- package/template/web-app/react/README.md +1 -1
- package/template/web-app/react/main.tsx +1 -1
- package/template/web-app/react/package.json +19 -18
- package/template/web-app/react/pages/index.tsx +1 -1
- package/template/web-app/react/tsconfig.json +5 -4
- package/template/web-app/react/vite.config.ts +6 -17
- package/template/web-app/react-webpack/.eslintrc +1 -1
- package/template/web-app/react-webpack/.stylelintrc +9 -3
- package/template/web-app/react-webpack/package.json +45 -45
- package/template/web-app/solid/.stylelintrc +9 -3
- package/template/web-app/solid/package.json +8 -8
- package/template/web-app/svelte/package.json +13 -13
- package/template/web-app/vue/.stylelintrc +9 -3
- package/template/web-app/vue/README.md +1 -1
- package/template/web-app/vue/package.json +20 -19
- package/template/web-app/vue/vite.config.ts +6 -17
- package/template/web-extension/.eslintrc +13 -2
- package/template/web-extension/.stylelintrc +9 -3
- package/template/web-extension/background/index.ts +0 -0
- package/template/web-extension/content_script/content.tsx +1 -1
- package/template/web-extension/defineManifest.ts +6 -1
- package/template/web-extension/package.json +21 -16
- package/template/web-extension/pnpm-lock.yaml +6220 -0
- package/template/web-extension/popup/popup.container.tsx +1 -1
- package/template/web-extension/shared/constant/index.ts +0 -0
- package/template/web-extension/shared/message/backgroundMessage.ts +11 -0
- package/template/web-extension/shared/message/contentMeesage.ts +15 -0
- package/template/web-extension/shared/message/index.ts +3 -0
- package/template/web-extension/shared/message/popupMeesage.ts +12 -0
- package/template/web-extension/shared/service/tools/base.ts +33 -0
- package/template/web-extension/shared/service/tools/createRequestActions.ts +58 -0
- package/template/web-extension/shared/service/tools/createService.ts +46 -0
- package/template/web-extension/shared/service/tools/createServiceHooks.ts +65 -0
- package/template/web-extension/shared/service/tools/index.ts +4 -0
- package/template/web-extension/shared/service/types.ts +29 -11
- package/template/web-extension/shared/tools/index.ts +1 -0
- package/template/web-extension/shared/tools/message.ts +80 -0
- package/template/web-extension/tsconfig.json +1 -0
- package/template/web-extension/vite.config.ts +12 -17
- package/template/workspace/pnpm/packages/test/package.json +1 -1
- package/template/web-extension/content_script/content.spec.tsx +0 -15
- package/template/web-extension/shared/service/tools.ts +0 -132
- package/template/workspace/nx/node_modules/.pnpm/minipass-fetch@3.0.3/node_modules/minipass-sized/.gitignore +0 -22
- package/template/workspace/nx/node_modules/.pnpm/minipass-sized@1.0.3/node_modules/minipass-sized/.gitignore +0 -22
- package/template/workspace/nx/node_modules/.pnpm/node_modules/minipass-sized/.gitignore +0 -22
- package/template/workspace/nx/node_modules/.pnpm/node_modules/npm-normalize-package-bin/.gitignore +0 -24
- package/template/workspace/nx/node_modules/.pnpm/npm-bundled@1.1.2/node_modules/npm-normalize-package-bin/.gitignore +0 -24
- package/template/workspace/nx/node_modules/.pnpm/npm-normalize-package-bin@1.0.1/node_modules/npm-normalize-package-bin/.gitignore +0 -24
- package/template/workspace/nx/node_modules/.pnpm/npm-packlist@5.1.1/node_modules/npm-normalize-package-bin/.gitignore +0 -24
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { message } from '@/shared/tools'
|
|
2
|
+
export enum ACTIONS {
|
|
3
|
+
TEST = 'TEST'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface messageType {
|
|
7
|
+
[ACTIONS.TEST]: object
|
|
8
|
+
}
|
|
9
|
+
export interface responseType {}
|
|
10
|
+
|
|
11
|
+
export const action = message.create<ACTIONS, messageType, responseType>()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { message } from '@/shared/tools'
|
|
2
|
+
export enum ACTIONS {
|
|
3
|
+
TEST = 'TEST'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface messageType {
|
|
7
|
+
[ACTIONS.TEST]: object
|
|
8
|
+
}
|
|
9
|
+
export interface responseType {}
|
|
10
|
+
|
|
11
|
+
export const action = message.create<ACTIONS, messageType, responseType>()
|
|
12
|
+
|
|
13
|
+
export function batchSend<A extends ACTIONS>(message: { action: A } & messageType[A]) {
|
|
14
|
+
return action.batchSendToContent(message, { active: true, url: '*://*.tiktok.com/*' })
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { message } from '@/shared/tools'
|
|
2
|
+
|
|
3
|
+
export enum ACTIONS {
|
|
4
|
+
TEST = 'TEST'
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface messageType {
|
|
8
|
+
[ACTIONS.TEST]: object
|
|
9
|
+
}
|
|
10
|
+
export interface responseType {}
|
|
11
|
+
|
|
12
|
+
export const action = message.create<ACTIONS, messageType, responseType>()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { httpBodyType } from '../types'
|
|
2
|
+
|
|
3
|
+
export class FetchError extends Error {
|
|
4
|
+
public request: Request
|
|
5
|
+
|
|
6
|
+
constructor(request: Request) {
|
|
7
|
+
super()
|
|
8
|
+
this.name = 'FetchError'
|
|
9
|
+
this.request = request
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function pickRequestBody<Body = httpBodyType>(
|
|
14
|
+
req: Request
|
|
15
|
+
): Promise<Body | undefined> {
|
|
16
|
+
let reqBody = void 0
|
|
17
|
+
try {
|
|
18
|
+
reqBody = await req.clone().json()
|
|
19
|
+
} catch {
|
|
20
|
+
/* empty */
|
|
21
|
+
}
|
|
22
|
+
return reqBody
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function pickReponseBody<Body = any>(res: Response): Promise<Body | undefined> {
|
|
26
|
+
let body = void 0
|
|
27
|
+
try {
|
|
28
|
+
body = await res.clone().json()
|
|
29
|
+
} catch {
|
|
30
|
+
/** empty */
|
|
31
|
+
}
|
|
32
|
+
return body
|
|
33
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { KyInstance, Options } from 'ky'
|
|
2
|
+
import { Input } from 'ky/distribution/types/options'
|
|
3
|
+
import { includes, isString, omit } from 'lodash-es'
|
|
4
|
+
import { stringify } from 'qs'
|
|
5
|
+
import { Nullable } from '1k-types'
|
|
6
|
+
import { configType, httpErrorType, requestOptionsType, serviceHooksType } from '../types'
|
|
7
|
+
import { FetchError } from './base'
|
|
8
|
+
|
|
9
|
+
export function createRequestActions(
|
|
10
|
+
prefixUrl: configType['prefixUrl'],
|
|
11
|
+
request: KyInstance,
|
|
12
|
+
hooks: serviceHooksType
|
|
13
|
+
) {
|
|
14
|
+
function creator(method: Required<Options>['method']) {
|
|
15
|
+
return async function <DATA = any>(url: Input, option?: requestOptionsType): Promise<DATA> {
|
|
16
|
+
try {
|
|
17
|
+
return await request[method](url, omit(option, 'responseType'))[
|
|
18
|
+
option?.responseType || 'json'
|
|
19
|
+
]()
|
|
20
|
+
} catch (e: any) {
|
|
21
|
+
const searchParamsString = stringify(option?.searchParams, { addQueryPrefix: true })
|
|
22
|
+
let httpBody: Nullable<string> = void 0
|
|
23
|
+
if (option && isString(option?.body)) {
|
|
24
|
+
httpBody = option.body
|
|
25
|
+
} else if (option?.body) {
|
|
26
|
+
httpBody = 'other'
|
|
27
|
+
} else if (option?.json) {
|
|
28
|
+
httpBody = JSON.stringify(option.json)
|
|
29
|
+
}
|
|
30
|
+
let error = new FetchError(
|
|
31
|
+
new Request(prefixUrl + '/' + url + searchParamsString, {
|
|
32
|
+
method,
|
|
33
|
+
body: httpBody
|
|
34
|
+
})
|
|
35
|
+
)
|
|
36
|
+
error.message = e.message
|
|
37
|
+
if (includes([httpErrorType.HTTPError, httpErrorType.TimeoutError], e.name)) {
|
|
38
|
+
error = e
|
|
39
|
+
}
|
|
40
|
+
for (let i = 0; i < hooks.httpError.length; i++) {
|
|
41
|
+
await hooks.httpError[i](error)
|
|
42
|
+
}
|
|
43
|
+
throw error
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
get: creator('get'),
|
|
50
|
+
post: creator('post'),
|
|
51
|
+
put: creator('put'),
|
|
52
|
+
patch: creator('patch'),
|
|
53
|
+
head: creator('head'),
|
|
54
|
+
delete: creator('delete')
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type requestActionsType = ReturnType<typeof createRequestActions>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import ky from 'ky'
|
|
2
|
+
import { assign, isArray, isObject } from 'lodash-es'
|
|
3
|
+
import { configType } from '../types'
|
|
4
|
+
import { createRequestActions } from './createRequestActions'
|
|
5
|
+
import { createServiceHooks } from './createServiceHooks'
|
|
6
|
+
|
|
7
|
+
export function createService(config: configType) {
|
|
8
|
+
const { kyHooks, addHooks, serviceHooks } = createServiceHooks()
|
|
9
|
+
const globalParams: configType['globalParams'] = assign({}, config.globalParams)
|
|
10
|
+
const globalSearchParams: configType['globalSearchParams'] = assign(
|
|
11
|
+
{},
|
|
12
|
+
config.globalSearchParams
|
|
13
|
+
)
|
|
14
|
+
const request = ky.create({
|
|
15
|
+
prefixUrl: config.prefixUrl,
|
|
16
|
+
headers: config.headers,
|
|
17
|
+
hooks: kyHooks
|
|
18
|
+
})
|
|
19
|
+
const requestActions = createRequestActions(config.prefixUrl, request, serviceHooks)
|
|
20
|
+
|
|
21
|
+
function setGlobalParams(params: configType['globalParams']) {
|
|
22
|
+
assign(globalParams, params)
|
|
23
|
+
}
|
|
24
|
+
function setGlobalSearchParams(params: configType['globalSearchParams']) {
|
|
25
|
+
assign(globalSearchParams, params)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// init
|
|
29
|
+
// ------------------------------------------------------------------------
|
|
30
|
+
addHooks('beforeRequest', async req => {
|
|
31
|
+
const { searchParams, body } = req
|
|
32
|
+
req.searchParams = { ...globalSearchParams, ...searchParams }
|
|
33
|
+
|
|
34
|
+
if (!isArray(body) && isObject(body)) {
|
|
35
|
+
req.body = { ...globalParams, ...body }
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
instance: request,
|
|
41
|
+
...requestActions,
|
|
42
|
+
addHooks,
|
|
43
|
+
setGlobalParams,
|
|
44
|
+
setGlobalSearchParams
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Hooks } from 'ky'
|
|
2
|
+
import { omit } from 'lodash-es'
|
|
3
|
+
import { parse, stringify } from 'qs'
|
|
4
|
+
import { ArrayValues } from '1k-types'
|
|
5
|
+
import { serviceHooksType } from '../types'
|
|
6
|
+
import { pickRequestBody } from './base'
|
|
7
|
+
|
|
8
|
+
export function createServiceHooks(hooks?: Partial<serviceHooksType>) {
|
|
9
|
+
const serviceHooks: serviceHooksType = {
|
|
10
|
+
httpError: [],
|
|
11
|
+
beforeRequest: [],
|
|
12
|
+
afterResponse: [],
|
|
13
|
+
...(hooks || {})
|
|
14
|
+
}
|
|
15
|
+
const kyHooks: Hooks = {
|
|
16
|
+
beforeRequest: [
|
|
17
|
+
async req => {
|
|
18
|
+
// eslint-disable-next-line prefer-const
|
|
19
|
+
let [url, searchParams] = req.url.split('?')
|
|
20
|
+
const reqBody = await pickRequestBody(req)
|
|
21
|
+
const parsedSearchParams = parse(searchParams)
|
|
22
|
+
const reqConfig = {
|
|
23
|
+
searchParams: parsedSearchParams,
|
|
24
|
+
body: reqBody,
|
|
25
|
+
headers: req.headers,
|
|
26
|
+
method: req.method
|
|
27
|
+
}
|
|
28
|
+
await foreachHooks('beforeRequest', reqConfig)
|
|
29
|
+
url = url + stringify(reqConfig.searchParams, { addQueryPrefix: true })
|
|
30
|
+
return new Request(url, {
|
|
31
|
+
...omit(req, 'url'),
|
|
32
|
+
headers: reqConfig.headers,
|
|
33
|
+
body: reqBody ? JSON.stringify(reqConfig.body) : void 0
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
afterResponse: [
|
|
38
|
+
async (request, options, response) => {
|
|
39
|
+
await foreachHooks('afterResponse', { request, options, response })
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
function addHooks<K extends keyof serviceHooksType>(
|
|
44
|
+
key: K,
|
|
45
|
+
callback: ArrayValues<serviceHooksType[K]>
|
|
46
|
+
) {
|
|
47
|
+
serviceHooks[key].push(callback as any)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function foreachHooks<K extends keyof serviceHooksType>(
|
|
51
|
+
name: K,
|
|
52
|
+
arg: Parameters<ArrayValues<serviceHooksType[K]>>[0]
|
|
53
|
+
) {
|
|
54
|
+
for (let i = 0; i < serviceHooks[name].length; i++) {
|
|
55
|
+
const fn = serviceHooks[name][i]
|
|
56
|
+
await fn(arg as never)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
kyHooks,
|
|
62
|
+
serviceHooks,
|
|
63
|
+
addHooks
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,22 +1,40 @@
|
|
|
1
|
-
import { Options,
|
|
2
|
-
import { Nullable } from '1k-types'
|
|
1
|
+
import { HTTPError, NormalizedOptions, Options, TimeoutError } from 'ky'
|
|
2
|
+
import { AnyArray, AnyObject, Nullable } from '1k-types'
|
|
3
|
+
import { FetchError } from './tools'
|
|
3
4
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export interface requestOptionsType extends Options {
|
|
9
|
-
responseType?: 'json' | 'text' | 'blob'
|
|
5
|
+
export enum httpErrorType {
|
|
6
|
+
'HTTPError' = 'HTTPError',
|
|
7
|
+
'TimeoutError' = 'TimeoutError',
|
|
8
|
+
'FetchError' = 'FetchError'
|
|
10
9
|
}
|
|
11
10
|
|
|
11
|
+
export type httpBodyType = Nullable<string | number | AnyObject | AnyArray>
|
|
12
|
+
|
|
12
13
|
export type beforeRequestType = (req: {
|
|
13
14
|
searchParams: Record<string, any>
|
|
14
|
-
body:
|
|
15
|
+
body: httpBodyType
|
|
15
16
|
headers: Headers
|
|
16
17
|
method: Options['method']
|
|
17
18
|
}) => Promise<void> | void
|
|
18
|
-
export type
|
|
19
|
+
export type httpErrorHooksType = (
|
|
20
|
+
error: HTTPError | TimeoutError | FetchError
|
|
21
|
+
) => Promise<void> | void
|
|
22
|
+
export type AfterResponseHook = (arg: {
|
|
23
|
+
request: Request
|
|
24
|
+
options: NormalizedOptions
|
|
25
|
+
response: Response
|
|
26
|
+
}) => Promise<void> | void
|
|
19
27
|
export interface serviceHooksType {
|
|
20
|
-
|
|
28
|
+
httpError: httpErrorHooksType[]
|
|
21
29
|
beforeRequest: beforeRequestType[]
|
|
30
|
+
afterResponse: AfterResponseHook[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface configType extends Pick<Options, 'prefixUrl' | 'headers'> {
|
|
34
|
+
globalParams?: Record<string, any>
|
|
35
|
+
globalSearchParams?: Record<string, any>
|
|
36
|
+
hooks?: Partial<serviceHooksType>
|
|
37
|
+
}
|
|
38
|
+
export interface requestOptionsType extends Options {
|
|
39
|
+
responseType?: 'json' | 'text' | 'blob'
|
|
22
40
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as message from './message'
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { map, unset } from 'lodash-es'
|
|
2
|
+
|
|
3
|
+
export type defActionType = string
|
|
4
|
+
export type messageOpsType<Action extends defActionType> = Record<Action, object>
|
|
5
|
+
export type genMessageType<
|
|
6
|
+
Action extends defActionType,
|
|
7
|
+
MessageOps extends messageOpsType<Action>[Action]
|
|
8
|
+
> = { action: Action } & MessageOps
|
|
9
|
+
export type responseType<Action extends defActionType> = { [key in Action]?: any }
|
|
10
|
+
export type actionHandlerType<Message, Response> = (
|
|
11
|
+
message: Message,
|
|
12
|
+
sender: chrome.runtime.MessageSender,
|
|
13
|
+
callback: (response?: Response) => void
|
|
14
|
+
) => any
|
|
15
|
+
class MessageConstructor<
|
|
16
|
+
Action extends defActionType,
|
|
17
|
+
MessageConfig extends messageOpsType<Action>,
|
|
18
|
+
Response extends responseType<Action>
|
|
19
|
+
> {
|
|
20
|
+
action: {
|
|
21
|
+
[key: string]: actionHandlerType<
|
|
22
|
+
genMessageType<Action, MessageConfig[Action]>,
|
|
23
|
+
Response[Action]
|
|
24
|
+
>
|
|
25
|
+
}
|
|
26
|
+
constructor() {
|
|
27
|
+
this.action = {}
|
|
28
|
+
}
|
|
29
|
+
initListener() {
|
|
30
|
+
chrome.runtime.onMessage.addListener((message, sender, callback) => {
|
|
31
|
+
this.action[message.action]?.(message, sender, callback)
|
|
32
|
+
return true
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
addListener<A extends Action>(
|
|
36
|
+
action: A,
|
|
37
|
+
callback: actionHandlerType<genMessageType<A, MessageConfig[A]>, Response[A]>
|
|
38
|
+
) {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
this.action[action] = callback
|
|
41
|
+
}
|
|
42
|
+
removeListener(action: Action) {
|
|
43
|
+
unset(this.action, action)
|
|
44
|
+
}
|
|
45
|
+
async send<A extends Action>(message: genMessageType<A, MessageConfig[A]>) {
|
|
46
|
+
return new Promise<Response[A]>(resolve => {
|
|
47
|
+
chrome.runtime.sendMessage(message, response => resolve(response))
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async batchSendToContent<SendMessage extends genMessageType<Action, MessageConfig[Action]>>(
|
|
52
|
+
message: SendMessage,
|
|
53
|
+
config?: chrome.tabs.QueryInfo
|
|
54
|
+
) {
|
|
55
|
+
const tabs = config ? await chrome.tabs.query(config) : []
|
|
56
|
+
return await Promise.all(
|
|
57
|
+
map(tabs, tab => {
|
|
58
|
+
return new Promise<Response[SendMessage['action']]>(resolve => {
|
|
59
|
+
chrome.tabs.sendMessage(tab.id!, message, response => resolve(response))
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
sendToContent<SendMessage extends genMessageType<Action, MessageConfig[Action]>>(
|
|
65
|
+
tabId: number,
|
|
66
|
+
message: SendMessage
|
|
67
|
+
) {
|
|
68
|
+
return new Promise<Response[SendMessage['action']]>(resolve => {
|
|
69
|
+
chrome.tabs.sendMessage(tabId, message, response => resolve(response))
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function create<
|
|
75
|
+
Action extends defActionType,
|
|
76
|
+
MessageOps extends messageOpsType<Action>,
|
|
77
|
+
Response extends responseType<Action>
|
|
78
|
+
>() {
|
|
79
|
+
return new MessageConstructor<Action, MessageOps, Response>()
|
|
80
|
+
}
|
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
import { defineConfig } from 'vite'
|
|
2
2
|
import react from '@vitejs/plugin-react'
|
|
3
|
-
import
|
|
3
|
+
import stylelint from 'vite-plugin-stylelint'
|
|
4
|
+
import eslintPlugin from '@nabla/vite-plugin-eslint'
|
|
4
5
|
import { crx } from '@crxjs/vite-plugin'
|
|
6
|
+
import svgr from 'vite-plugin-svgr'
|
|
5
7
|
import defineManifest from './defineManifest'
|
|
6
8
|
|
|
7
9
|
// https://vitejs.dev/config/
|
|
8
10
|
export default defineConfig(({ mode }) => {
|
|
9
11
|
return {
|
|
10
12
|
plugins: [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
dev: {
|
|
17
|
-
logLevel: ['error']
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
stylelint: {
|
|
21
|
-
lintCommand: 'stylelint **/*.{css,scss,less}',
|
|
22
|
-
dev: {
|
|
23
|
-
logLevel: ['error']
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
enableBuild: false
|
|
13
|
+
svgr(),
|
|
14
|
+
stylelint({ cache: false, include: ['**/*.{css,scss,sass,less,styl,vue,svelte}'] }),
|
|
15
|
+
eslintPlugin({
|
|
16
|
+
eslintOptions: { cache: false, useEslintrc: true },
|
|
17
|
+
shouldLint: path => /\/[^?]*\.(vue|svelte|m?[jt]sx?)$/.test(path)
|
|
27
18
|
}),
|
|
28
19
|
react(),
|
|
29
20
|
crx({ manifest: defineManifest({ mode }) })
|
|
@@ -35,6 +26,10 @@ export default defineConfig(({ mode }) => {
|
|
|
35
26
|
},
|
|
36
27
|
esbuild: {
|
|
37
28
|
drop: mode === 'production' ? ['console', 'debugger'] : []
|
|
29
|
+
},
|
|
30
|
+
server: {
|
|
31
|
+
host: '0.0.0.0',
|
|
32
|
+
port: 30001
|
|
38
33
|
}
|
|
39
34
|
}
|
|
40
35
|
})
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/react'
|
|
2
|
-
import Content from './content'
|
|
3
|
-
|
|
4
|
-
describe('HelloWorld', () => {
|
|
5
|
-
it('should renders a msg', () => {
|
|
6
|
-
// arrange
|
|
7
|
-
render(<Content />)
|
|
8
|
-
|
|
9
|
-
// act
|
|
10
|
-
const title = screen.getByTestId('title')
|
|
11
|
-
|
|
12
|
-
// assert
|
|
13
|
-
expect(title).toHaveTextContent(/Hello React!/i)
|
|
14
|
-
})
|
|
15
|
-
})
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import ky, { Hooks, KyInstance, Options } from 'ky'
|
|
2
|
-
import { Input } from 'ky/distribution/types/options'
|
|
3
|
-
import { assign, includes, isArray, isObject, omit } from 'lodash-es'
|
|
4
|
-
import { parse, stringify } from 'qs'
|
|
5
|
-
import { ArrayValues } from '1k-types'
|
|
6
|
-
import { configType, requestOptionsType, serviceHooksType } from './types'
|
|
7
|
-
|
|
8
|
-
function createServiceHooks() {
|
|
9
|
-
const serviceHooks: serviceHooksType = {
|
|
10
|
-
beforeError: [],
|
|
11
|
-
beforeRequest: []
|
|
12
|
-
}
|
|
13
|
-
const kyHooks: Hooks = {
|
|
14
|
-
beforeError: [
|
|
15
|
-
async error => {
|
|
16
|
-
await foreachHooks('beforeError', error)
|
|
17
|
-
return error
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
beforeRequest: [
|
|
21
|
-
async req => {
|
|
22
|
-
// eslint-disable-next-line prefer-const
|
|
23
|
-
let [url, searchParams] = req.url.split('?')
|
|
24
|
-
let reqBody = void 0
|
|
25
|
-
if (!includes(['GET', 'HEAD'], req.method)) {
|
|
26
|
-
try {
|
|
27
|
-
reqBody = await req.json()
|
|
28
|
-
} catch {
|
|
29
|
-
/* empty */
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const parsedSearchParams = parse(searchParams)
|
|
33
|
-
const reqConfig = {
|
|
34
|
-
searchParams: parsedSearchParams,
|
|
35
|
-
body: reqBody,
|
|
36
|
-
headers: req.headers,
|
|
37
|
-
method: req.method
|
|
38
|
-
}
|
|
39
|
-
await foreachHooks('beforeRequest', reqConfig)
|
|
40
|
-
url = url + stringify(reqConfig.searchParams, { addQueryPrefix: true })
|
|
41
|
-
return new Request(url, {
|
|
42
|
-
...omit(req, 'url'),
|
|
43
|
-
headers: reqConfig.headers,
|
|
44
|
-
body: reqBody ? JSON.stringify(reqConfig.body) : void 0
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
function addHooks<K extends keyof serviceHooksType>(
|
|
50
|
-
key: K,
|
|
51
|
-
callback: ArrayValues<serviceHooksType[K]>
|
|
52
|
-
) {
|
|
53
|
-
serviceHooks[key].push(callback as any)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async function foreachHooks<K extends keyof serviceHooksType>(
|
|
57
|
-
name: K,
|
|
58
|
-
arg: Parameters<ArrayValues<serviceHooksType[K]>>[0]
|
|
59
|
-
) {
|
|
60
|
-
for (let i = 0; i < serviceHooks[name].length; i++) {
|
|
61
|
-
const fn = serviceHooks[name][i]
|
|
62
|
-
await fn(arg as never)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
kyHooks,
|
|
68
|
-
serviceHooks,
|
|
69
|
-
addHooks
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function createRequestActions(request: KyInstance) {
|
|
74
|
-
function creator(method: Required<Options>['method']) {
|
|
75
|
-
return function <DATA = any>(url: Input, option?: requestOptionsType): Promise<DATA> {
|
|
76
|
-
return request[method](url, omit(option, 'responseType'))[
|
|
77
|
-
option?.responseType || 'json'
|
|
78
|
-
]()
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
get: creator('get'),
|
|
84
|
-
post: creator('post'),
|
|
85
|
-
put: creator('put'),
|
|
86
|
-
patch: creator('patch'),
|
|
87
|
-
head: creator('head'),
|
|
88
|
-
delete: creator('delete')
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
export type requestActionsType = ReturnType<typeof createRequestActions>
|
|
92
|
-
|
|
93
|
-
export function createService(config: configType) {
|
|
94
|
-
const { kyHooks, addHooks } = createServiceHooks()
|
|
95
|
-
const globalParams: configType['globalParams'] = assign({}, config.globalParams)
|
|
96
|
-
const globalSearchParams: configType['globalSearchParams'] = assign(
|
|
97
|
-
{},
|
|
98
|
-
config.globalSearchParams
|
|
99
|
-
)
|
|
100
|
-
const request = ky.create({
|
|
101
|
-
prefixUrl: config.prefixUrl,
|
|
102
|
-
headers: config.headers,
|
|
103
|
-
hooks: kyHooks
|
|
104
|
-
})
|
|
105
|
-
const requestActions = createRequestActions(request)
|
|
106
|
-
|
|
107
|
-
function setGlobalParams(params: configType['globalParams']) {
|
|
108
|
-
assign(globalParams, params)
|
|
109
|
-
}
|
|
110
|
-
function setGlobalSearchParams(params: configType['globalSearchParams']) {
|
|
111
|
-
assign(globalSearchParams, params)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// 初始化
|
|
115
|
-
// ------------------------------------------------------------------------
|
|
116
|
-
addHooks('beforeRequest', async req => {
|
|
117
|
-
const { searchParams, body } = req
|
|
118
|
-
req.searchParams = { ...globalSearchParams, ...searchParams }
|
|
119
|
-
|
|
120
|
-
if (!isArray(body) && isObject(body)) {
|
|
121
|
-
req.body = { ...globalParams, ...body }
|
|
122
|
-
}
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
instance: request,
|
|
127
|
-
...requestActions,
|
|
128
|
-
addHooks,
|
|
129
|
-
setGlobalParams,
|
|
130
|
-
setGlobalSearchParams
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# ignore most things, include some others
|
|
2
|
-
/*
|
|
3
|
-
/.*
|
|
4
|
-
|
|
5
|
-
!bin/
|
|
6
|
-
!lib/
|
|
7
|
-
!docs/
|
|
8
|
-
!package.json
|
|
9
|
-
!package-lock.json
|
|
10
|
-
!README.md
|
|
11
|
-
!CONTRIBUTING.md
|
|
12
|
-
!LICENSE
|
|
13
|
-
!CHANGELOG.md
|
|
14
|
-
!example/
|
|
15
|
-
!scripts/
|
|
16
|
-
!tap-snapshots/
|
|
17
|
-
!test/
|
|
18
|
-
!.travis.yml
|
|
19
|
-
!.gitignore
|
|
20
|
-
!.gitattributes
|
|
21
|
-
!coverage-map.js
|
|
22
|
-
!index.js
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# ignore most things, include some others
|
|
2
|
-
/*
|
|
3
|
-
/.*
|
|
4
|
-
|
|
5
|
-
!bin/
|
|
6
|
-
!lib/
|
|
7
|
-
!docs/
|
|
8
|
-
!package.json
|
|
9
|
-
!package-lock.json
|
|
10
|
-
!README.md
|
|
11
|
-
!CONTRIBUTING.md
|
|
12
|
-
!LICENSE
|
|
13
|
-
!CHANGELOG.md
|
|
14
|
-
!example/
|
|
15
|
-
!scripts/
|
|
16
|
-
!tap-snapshots/
|
|
17
|
-
!test/
|
|
18
|
-
!.travis.yml
|
|
19
|
-
!.gitignore
|
|
20
|
-
!.gitattributes
|
|
21
|
-
!coverage-map.js
|
|
22
|
-
!index.js
|