diff --git a/frontend/packages/api/.eslintignore b/frontend/packages/api/.eslintignore new file mode 100644 index 0000000000..009af5438f --- /dev/null +++ b/frontend/packages/api/.eslintignore @@ -0,0 +1,2 @@ +dist +coverage diff --git a/frontend/packages/api/.eslintrc.cjs b/frontend/packages/api/.eslintrc.cjs new file mode 100644 index 0000000000..7447e199ce --- /dev/null +++ b/frontend/packages/api/.eslintrc.cjs @@ -0,0 +1,32 @@ +module.exports = { + overrides: [ + { + files: ['**/*.ts'], + env: { + browser: true, + es2021: true, + }, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:@typescript-eslint/recommended-requiring-type-checking', + 'prettier', + ], + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: ['./tsconfig.json'], + }, + plugins: ['@typescript-eslint'], + }, + { + files: ['**/*.{js,cjx}'], + parser: 'espree', + extends: ['eslint:recommended', 'prettier'], + env: { + node: true, + }, + }, + ], +} diff --git a/frontend/packages/api/dist/index.d.ts b/frontend/packages/api/dist/index.d.ts deleted file mode 100755 index cb0ff5c3b5..0000000000 --- a/frontend/packages/api/dist/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/frontend/packages/api/dist/index.js b/frontend/packages/api/dist/index.js deleted file mode 100755 index cb0ff5c3b5..0000000000 --- a/frontend/packages/api/dist/index.js +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/frontend/packages/api/package.json b/frontend/packages/api/package.json index b40eb827b3..1b37866486 100644 --- a/frontend/packages/api/package.json +++ b/frontend/packages/api/package.json @@ -17,18 +17,17 @@ "author": "Paul Mineev", "license": "MIT", "scripts": { - "dev": "tsc -w -p tsconfig.dev.json", - "build": "tsc", - "prebuild": "rm -rf dist", + "dev": "tsc -w --incremental", + "build": "rm -rf dist && tsc", "prepublish": "./prepublish.sh", "postpublish": "./postpublish.sh", "test": "jest", "coverage": "jest --coverage", - "lint": "eslint src --ext=.ts,.js", + "lint": "eslint --ext=.ts,.js,.cjs ./", "type-check": "tsc --noEmit", "format": "prettier --write '**/*.{ts,js,json}'", "lint-staged:format": "prettier --write", - "lint-staged:lint": "eslint --fix" + "lint-staged:lint": "eslint --ext=.ts,.js,.cjs --fix" }, "devDependencies": { "@swc/core": "^1.2.215", diff --git a/frontend/packages/api/src/lib/fetcher.ts b/frontend/packages/api/src/lib/fetcher.ts index 1aded5e323..55cec1423e 100644 --- a/frontend/packages/api/src/lib/fetcher.ts +++ b/frontend/packages/api/src/lib/fetcher.ts @@ -54,7 +54,7 @@ export const createFetcher = (site: string, baseUrl: string): Client => { // An HTTP header cannot be empty. // Although some webservers allow this (nginx, Apache), others answer 400 Bad Request (lighttpd). const xsrfToken = getCookie(XSRF_COOKIE) - if (xsrfToken !== undefined) { + if (typeof xsrfToken === 'string') { headers.set(XSRF_HEADER, xsrfToken) } diff --git a/frontend/packages/api/test/lib.ts b/frontend/packages/api/test/lib.ts index db3bb38fd4..26b6a78459 100644 --- a/frontend/packages/api/test/lib.ts +++ b/frontend/packages/api/test/lib.ts @@ -7,7 +7,7 @@ export function mockEndpoint( url: string, params: { method?: 'get' | 'put' | 'post' | 'delete' - body?: string | Record | unknown[] + body?: number | string | null | Record | unknown[] status?: number headers?: Record } = {} diff --git a/frontend/packages/api/tsconfig.json b/frontend/packages/api/tsconfig.json index 38a1c6d25a..ec4c390b50 100644 --- a/frontend/packages/api/tsconfig.json +++ b/frontend/packages/api/tsconfig.json @@ -3,7 +3,7 @@ /* Visit https://aka.ms/tsconfig to read more about this file */ /* Projects */ - "incremental": true /* Save .tsbuildinfo files to allow for incremental compilation of projects. */, + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ @@ -43,8 +43,8 @@ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */, + // "checkJs": true /* Enable error reporting in type-checked JavaScript files. */, // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ /* Emit */ @@ -53,7 +53,7 @@ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ + "outDir": "./dist" /* Specify an output folder for all emitted files. */, // "removeComments": true, /* Disable emitting comments. */ // "noEmit": true, /* Disable emitting files from a compilation. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ @@ -69,7 +69,7 @@ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ - "declarationDir": "./dist/types" /* Specify the output directory for generated declaration files. */, + // "declarationDir": "./" /* Specify the output directory for generated declaration files. */, // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ /* Interop Constraints */ @@ -103,5 +103,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "include": ["src/**/*.ts"], + "exclude": ["tests/**", "coverage/**", "dist/**", "**/*.spec.ts"] }