diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c09c65..86448ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,8 +1,10 @@ name: CI on: - - pull_request - - push + pull_request: + branches: ["**"] + push: + branches: [main] jobs: ci: diff --git a/eslint.config.mjs b/eslint.config.mjs index 3ab4a1b..e66d437 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,5 +1,3 @@ -// @ts-check - import eslint from "@eslint/js"; import tseslint from "typescript-eslint"; import eslintConfigPrettier from "eslint-config-prettier"; diff --git a/jest.config.ts b/jest.config.ts index 92d8a2c..ca9a37a 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,19 +1,12 @@ -import type { Config } from "@jest/types"; +import type { JestConfigWithTsJest } from "ts-jest"; -const config: Config.InitialOptions = { - extensionsToTreatAsEsm: [".ts"], +const config = { + preset: "ts-jest/presets/default-esm", + moduleFileExtensions: ["ts", "js"], setupFilesAfterEnv: ["./jest.setup.ts"], moduleNameMapper: { "^(\\.{1,2}/.*)\\.js$": "$1", }, - transform: { - "^.+\\.ts$": [ - "ts-jest", - { - useESM: true, - }, - ], - }, -}; +} satisfies JestConfigWithTsJest; -export default config; +module.exports = config; diff --git a/package.json b/package.json index 02db3e0..63bf2fb 100644 --- a/package.json +++ b/package.json @@ -2,23 +2,66 @@ "name": "@api-platform/api-doc-parser", "version": "0.16.8", "description": "Transform an API documentation (Hydra, OpenAPI, GraphQL) in an intermediate representation that can be used for various tasks such as creating smart API clients, scaffolding code or building administration interfaces.", - "files": [ - "*.md", - "lib", - "src" + "keywords": [ + "api", + "api-platform", + "documentation", + "hydra", + "openapi", + "graphql", + "jsonld", + "json-schema", + "typescript", + "client" ], - "type": "module", - "exports": "./lib/index.js", - "main": "./lib/index.js", - "repository": "api-platform/api-doc-parser", "homepage": "https://github.com/api-platform/api-doc-parser", "bugs": "https://github.com/api-platform/api-doc-parser/issues", - "author": "Kévin Dunglas", + "repository": { + "type": "git", + "url": "git+https://github.com/api-platform/api-doc-parser.git" + }, "license": "MIT", + "author": "Kévin Dunglas", + "sideEffects": false, + "type": "module", + "exports": { + ".": { + "types": "./lib/index.d.ts", + "import": "./lib/index.js", + "default": "./lib/index.js" + }, + "./package.json": "./package.json" + }, + "main": "./lib/index.js", + "types": "./lib/index.d.ts", + "files": [ + "lib", + "LICENSE", + "package.json", + "README.md" + ], + "scripts": { + "build": "rm -rf lib && tsc --project tsconfig.build.json", + "build:watch": "tsc --watch", + "eslint-check": "eslint-config-prettier src/index.ts", + "lint": "eslint src", + "lint:fix": "eslint src --fix", + "test": "NODE_OPTIONS=--experimental-vm-modules jest", + "typecheck": "tsc --noEmit", + "typecheck:watch": "tsc --noEmit --watch" + }, + "dependencies": { + "graphql": "^16.0.0", + "inflection": "^3.0.0", + "jsonld": "^8.3.2", + "jsonref": "^9.0.0", + "lodash.get": "^4.4.0" + }, "devDependencies": { "@eslint/compat": "^1.2.5", "@eslint/eslintrc": "^3.2.0", "@eslint/js": "^9.19.0", + "@jest/globals": "29.7.0", "@jest/types": "29.0.0", "@types/inflection": "^1.13.0", "@types/jest": "^29.0.0", @@ -41,25 +84,11 @@ "typescript": "^5.7.0", "typescript-eslint": "^8.22.0" }, - "dependencies": { - "graphql": "^16.0.0", - "inflection": "^3.0.0", - "jsonld": "^8.3.2", - "jsonref": "^9.0.0", - "lodash.get": "^4.4.0", - "tslib": "^2.0.0" - }, - "scripts": { - "test": "NODE_OPTIONS=--experimental-vm-modules jest", - "lint": "eslint src", - "fix": "pnpm lint --fix", - "eslint-check": "eslint-config-prettier src/index.ts", - "build": "rm -rf lib/* && tsc", - "watch": "tsc --watch" + "packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977", + "engines": { + "node": ">=18" }, - "sideEffects": false, "publishConfig": { "access": "public" - }, - "packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977" + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c41dc11..6ff1789 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,9 +23,6 @@ importers: lodash.get: specifier: ^4.4.0 version: 4.4.2 - tslib: - specifier: ^2.0.0 - version: 2.8.1 devDependencies: '@eslint/compat': specifier: ^1.2.5 @@ -36,6 +33,9 @@ importers: '@eslint/js': specifier: ^9.19.0 version: 9.28.0 + '@jest/globals': + specifier: 29.7.0 + version: 29.7.0 '@jest/types': specifier: 29.0.0 version: 29.0.0 @@ -5177,7 +5177,8 @@ snapshots: minimist: 1.2.8 strip-bom: 3.0.0 - tslib@2.8.1: {} + tslib@2.8.1: + optional: true type-check@0.4.0: dependencies: diff --git a/src/hydra/fetchJsonLd.ts b/src/hydra/fetchJsonLd.ts index 0211e40..de5136e 100644 --- a/src/hydra/fetchJsonLd.ts +++ b/src/hydra/fetchJsonLd.ts @@ -1,4 +1,4 @@ -import type { Document, JsonLd, RemoteDocument } from "jsonld/jsonld-spec"; +import type { Document, JsonLd, RemoteDocument } from "jsonld/jsonld-spec.js"; import type { RequestInitExtended } from "./types.js"; const jsonLdMimeType = "application/ld+json"; diff --git a/src/openapi3/parseOpenApi3Documentation.ts b/src/openapi3/parseOpenApi3Documentation.ts index 0e4ad19..dca307a 100644 --- a/src/openapi3/parseOpenApi3Documentation.ts +++ b/src/openapi3/parseOpenApi3Documentation.ts @@ -1,7 +1,7 @@ import { Api } from "../Api.js"; import handleJson, { removeTrailingSlash } from "./handleJson.js"; import type { OpenAPIV3 } from "openapi-types"; -import type { RequestInitExtended } from "./types"; +import type { RequestInitExtended } from "./types.js"; export interface ParsedOpenApi3Documentation { api: Api; diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..5b17b13 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + /* Emit */ + "rootDir": "src" + }, + "include": ["./src"], + "exclude": ["./src/**/*.test.ts"] +} diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json deleted file mode 100644 index 402914b..0000000 --- a/tsconfig.eslint.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "./tsconfig.json", - "include": ["jest.config.ts", "jest.setup.ts", "./src"], - "exclude": [] -} diff --git a/tsconfig.json b/tsconfig.json index e19bc0f..f9b8696 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,41 @@ { "compilerOptions": { - "target": "es6", - "module": "esnext", - "moduleResolution": "node", - "sourceMap": true, - "outDir": "./lib", + /* Type checking */ + // "exactOptionalPropertyTypes": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, + "noImplicitReturns": true, + // "noUncheckedIndexedAccess": true, + "noPropertyAccessFromIndexSignature": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "strict": true, + + /* Modules */ + "module": "NodeNext", + "noUncheckedSideEffectImports": true, + "types": ["jest"], + + /* Language and Environment */ + "lib": ["ES2022", "DOM"], + "moduleDetection": "force", + "target": "ES2022", + + /* Output Formatting */ + "noErrorTruncation": true, + + /* Emit */ "declaration": true, "declarationMap": true, - "rootDir": "./src", - "importHelpers": true, - "strict": true, - "esModuleInterop": true + "inlineSources": true, + "outDir": "lib", + "sourceMap": true, + + /* Interop Constraints */ + // "erasableSyntaxOnly": true, + "isolatedDeclarations": true, + "verbatimModuleSyntax": true }, - "exclude": [ - "src/**/*.test.ts", - ], "include": ["./src"] }