create-packer 1.25.1 → 1.25.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-packer",
3
- "version": "1.25.1",
3
+ "version": "1.25.3",
4
4
  "main": "index.js",
5
5
  "repository": "https://github.com/kevily/create-packer",
6
6
  "author": "1k <bug_zero@163.com>",
@@ -12,9 +12,6 @@
12
12
  "format": "prettier --write \"**/*.{ts,js,tsx,jsx,json,css,scss,less,json}\"",
13
13
  "lint": "tsc --noEmit && eslint **/*.{tsx,ts} && stylelint **/*.{css,scss,less}",
14
14
  "lint:fix": "eslint **/*.{tsx,ts} --fix && stylelint **/*.{css,scss,less} --fix",
15
- "test:watchs": "jest --watch",
16
- "test": "jest",
17
- "test:coverage": "jest --silent --watchAll=false --coverage",
18
15
  "cz": "cz",
19
16
  "push": "npm run commit && git push",
20
17
  "commit": "git add . && npm run cz"
@@ -33,18 +30,12 @@
33
30
  "@commitlint/config-conventional": "17.6.1",
34
31
  "@commitlint/cz-commitlint": "17.5.0",
35
32
  "@crxjs/vite-plugin": "2.0.0-beta.18",
36
- "@testing-library/dom": "9.2.0",
37
- "@testing-library/jest-dom": "5.16.5",
38
- "@testing-library/react": "14.0.0",
39
- "@testing-library/user-event": "14.4.3",
40
33
  "@types/chrome": "^0.0.244",
41
- "@types/jest": "29.5.1",
42
34
  "@types/lodash-es": "4.17.7",
43
35
  "@types/node": "18.16.0",
44
36
  "@types/qs": "6.9.7",
45
37
  "@types/react": "18.0.38",
46
38
  "@types/react-dom": "18.0.11",
47
- "@types/testing-library__jest-dom": "5.14.5",
48
39
  "@typescript-eslint/eslint-plugin": "5.59.0",
49
40
  "@typescript-eslint/parser": "5.59.0",
50
41
  "@vitejs/plugin-react": "4.0.0",
@@ -59,8 +50,6 @@
59
50
  "eslint-plugin-react-hooks": "4.6.0",
60
51
  "husky": "8.0.3",
61
52
  "inquirer": "8",
62
- "jest": "29.5.0",
63
- "jest-environment-jsdom": "29.5.0",
64
53
  "postcss": "8.4.23",
65
54
  "postcss-import": "15.1.0",
66
55
  "postcss-nesting": "11.2.2",
@@ -1,4 +1,4 @@
1
- import { noop, size } from 'lodash-es'
1
+ import { forEach, size } from 'lodash-es'
2
2
  import { stringify } from 'qs'
3
3
 
4
4
  type fetchConfigType = Required<Parameters<typeof fetch>>[1]
@@ -9,8 +9,8 @@ interface configType {
9
9
  'Content-Type'?: string
10
10
  [key: string]: string | undefined
11
11
  }
12
- onError?: (e: Response) => void
13
12
  }
13
+ type onErrorType = (e: Response) => void
14
14
 
15
15
  async function resFormatter(response: Response) {
16
16
  const contentType = response.headers.get('Content-Type')
@@ -28,25 +28,36 @@ async function resFormatter(response: Response) {
28
28
 
29
29
  class Request {
30
30
  config: configType
31
+ interceptors: {
32
+ error: onErrorType[]
33
+ }
31
34
  constructor(config: configType) {
32
35
  this.config = {
33
- onError: noop,
34
36
  ...config,
35
37
  headers: {
36
38
  'Content-Type': 'application/json',
37
39
  ...config.headers
38
40
  }
39
41
  }
42
+ this.interceptors = {
43
+ error: []
44
+ }
45
+ }
46
+ onError(callback: onErrorType) {
47
+ this.interceptors.error.push(callback)
40
48
  }
41
49
  async request(url: string, config?: fetchConfigType) {
42
50
  try {
43
51
  const response = await fetch(this.config.baseURL + url, {
44
52
  headers: this.config.headers as never,
53
+ redirect: 'manual',
45
54
  ...config
46
55
  })
47
56
  if (response.status !== 200) {
48
57
  const errMsg = `服务器错误状态:${response.status}`
49
- this.config.onError?.(response)
58
+ forEach(this.interceptors.error, onError => {
59
+ onError(response)
60
+ })
50
61
  throw new Error(errMsg)
51
62
  }
52
63
  return resFormatter(response)
@@ -1,55 +0,0 @@
1
- /** @type {import('@jest/types').Config.InitialOptions} */
2
- module.exports = {
3
- // The test environment that will be used for testing, jsdom for browser environment
4
- // https://jestjs.io/docs/configuration#testenvironment-string
5
- testEnvironment: 'jsdom',
6
-
7
- // A list of paths to directories that Jest should use to search for files in
8
- // https://jestjs.io/docs/configuration#roots-arraystring
9
- roots: ['<rootDir>/src/'],
10
-
11
- // The glob patterns Jest uses to detect test files.
12
- // https://jestjs.io/docs/configuration#testmatch-arraystring
13
- testMatch: ['**/*.spec.ts?(x)'],
14
-
15
- // Jest transformations
16
- // https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
17
- transform: {
18
- '^.+\\.tsx?$': 'ts-jest' // Transform TypeScript files using ts-jest
19
- },
20
-
21
- // A list of paths to modules that run some code to configure or set up the testing framework before each test file in the suite is executed
22
- // https://jestjs.io/docs/configuration#setupfilesafterenv-array
23
- setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
24
-
25
- // Code coverage config
26
- // https://jestjs.io/docs/configuration#collectcoveragefrom-array
27
- coverageDirectory: '<rootDir>/coverage/',
28
- collectCoverageFrom: [
29
- '<rootDir>/src/**/*.{ts,tsx}',
30
- '!**/__mocks__/**',
31
- '!**/node_modules/**',
32
- '!**/*.d.ts'
33
- ],
34
-
35
- // Important: order matters, specific rules should be defined first
36
- // https://jestjs.io/fr/docs/configuration#modulenamemapper-objectstring-string--arraystring
37
- moduleNameMapper: {
38
- // Handle CSS imports (with CSS modules)
39
- // https://jestjs.io/docs/webpack#mocking-css-modules
40
- '^.+\\.module\\.(css|sass|scss|less)$': 'identity-obj-proxy',
41
-
42
- // Handle CSS imports (without CSS modules)
43
- '^.+\\.(css|sass|scss|less)$': '<rootDir>/__mocks__/styleMock.js',
44
-
45
- // Handle static assets
46
- // https://jestjs.io/docs/webpack#handling-static-assets
47
- '^.+\\.(jpg|jpeg|png|gif|webp|avif|svg|ttf|woff|woff2)$': `<rootDir>/__mocks__/fileMock.js`,
48
-
49
- // Handle TypeScript path aliases
50
- '^@/(.*)$': '<rootDir>/src/$1'
51
- },
52
-
53
- verbose: true,
54
- testTimeout: 30000
55
- }
@@ -1,5 +0,0 @@
1
- // jest-dom adds custom jest matchers for asserting on DOM nodes.
2
- // allows you to do things like:
3
- // expect(element).toHaveTextContent(/react/i)
4
- // learn more: https://github.com/testing-library/jest-dom
5
- import '@testing-library/jest-dom'