From c969265696b9d06950474c2a3916b0502d4461eb Mon Sep 17 00:00:00 2001 From: J3m5 <5523410+J3m5@users.noreply.github.com> Date: Mon, 2 Jun 2025 21:50:02 +0200 Subject: [PATCH 01/10] chore(package.json): apply sort-package-json --- package.json | 54 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 02db3e0..8cee02d 100644 --- a/package.json +++ b/package.json @@ -2,19 +2,36 @@ "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.", + "homepage": "https://github.com/api-platform/api-doc-parser", + "bugs": "https://github.com/api-platform/api-doc-parser/issues", + "repository": "api-platform/api-doc-parser", + "license": "MIT", + "author": "Kévin Dunglas", + "sideEffects": false, + "type": "module", + "exports": "./lib/index.js", + "main": "./lib/index.js", "files": [ "*.md", "lib", "src" ], - "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", - "license": "MIT", + "scripts": { + "build": "rm -rf lib/* && tsc", + "eslint-check": "eslint-config-prettier src/index.ts", + "fix": "pnpm lint --fix", + "lint": "eslint src", + "test": "NODE_OPTIONS=--experimental-vm-modules jest", + "watch": "tsc --watch" + }, + "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" + }, "devDependencies": { "@eslint/compat": "^1.2.5", "@eslint/eslintrc": "^3.2.0", @@ -41,25 +58,8 @@ "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" - }, - "sideEffects": false, + "packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977", "publishConfig": { "access": "public" - }, - "packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977" + } } From 8d02ff0b02901e6da9b9315b5ede83f02a34eb8a Mon Sep 17 00:00:00 2001 From: J3m5 <5523410+J3m5@users.noreply.github.com> Date: Tue, 3 Jun 2025 14:22:28 +0200 Subject: [PATCH 02/10] build(tsconfig.ts): sort and categorize compilerOptions --- tsconfig.json | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index e19bc0f..93e5f6d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,24 @@ { "compilerOptions": { - "target": "es6", + /* Type checking */ + "strict": true, + + /* Modules */ "module": "esnext", "moduleResolution": "node", - "sourceMap": true, - "outDir": "./lib", + "rootDir": "./src", + + /* Language and Environment */ + "target": "es6", + + /* Emit */ "declaration": true, "declarationMap": true, - "rootDir": "./src", "importHelpers": true, - "strict": true, + "sourceMap": true, + "outDir": "./lib", + + /* Interop Constraints */ "esModuleInterop": true }, "exclude": [ From 243a418ee7078b2e18b0598d9681ab7204c450ae Mon Sep 17 00:00:00 2001 From: J3m5 <5523410+J3m5@users.noreply.github.com> Date: Tue, 3 Jun 2025 14:25:36 +0200 Subject: [PATCH 03/10] build(tsconfig.ts): modernize and improve compilerOptions --- eslint.config.mjs | 2 -- tsconfig.build.json | 9 +++++++++ tsconfig.eslint.json | 5 ----- tsconfig.json | 33 +++++++++++++++++++++++---------- 4 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 tsconfig.build.json delete mode 100644 tsconfig.eslint.json 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/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 93e5f6d..f9b8696 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,28 +1,41 @@ { "compilerOptions": { /* Type checking */ + // "exactOptionalPropertyTypes": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, + "noImplicitReturns": true, + // "noUncheckedIndexedAccess": true, + "noPropertyAccessFromIndexSignature": true, + "noUnusedLocals": true, + "noUnusedParameters": true, "strict": true, /* Modules */ - "module": "esnext", - "moduleResolution": "node", - "rootDir": "./src", + "module": "NodeNext", + "noUncheckedSideEffectImports": true, + "types": ["jest"], /* Language and Environment */ - "target": "es6", + "lib": ["ES2022", "DOM"], + "moduleDetection": "force", + "target": "ES2022", + + /* Output Formatting */ + "noErrorTruncation": true, /* Emit */ "declaration": true, "declarationMap": true, - "importHelpers": true, + "inlineSources": true, + "outDir": "lib", "sourceMap": true, - "outDir": "./lib", /* Interop Constraints */ - "esModuleInterop": true + // "erasableSyntaxOnly": true, + "isolatedDeclarations": true, + "verbatimModuleSyntax": true }, - "exclude": [ - "src/**/*.test.ts", - ], "include": ["./src"] } From bed1df30d3b0465350bcafb1e182f65b73911322 Mon Sep 17 00:00:00 2001 From: J3m5 <5523410+J3m5@users.noreply.github.com> Date: Wed, 4 Jun 2025 00:55:48 +0200 Subject: [PATCH 04/10] build(package.json): update exports structure and add types definition --- package.json | 13 ++++++++++--- pnpm-lock.yaml | 6 ++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 8cee02d..1976b42 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,16 @@ "author": "Kévin Dunglas", "sideEffects": false, "type": "module", - "exports": "./lib/index.js", + "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": [ "*.md", "lib", @@ -29,8 +37,7 @@ "inflection": "^3.0.0", "jsonld": "^8.3.2", "jsonref": "^9.0.0", - "lodash.get": "^4.4.0", - "tslib": "^2.0.0" + "lodash.get": "^4.4.0" }, "devDependencies": { "@eslint/compat": "^1.2.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c41dc11..b0257f9 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 @@ -5177,7 +5174,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: From 999d04304c4b9b0de06df4682817a8de474e16b1 Mon Sep 17 00:00:00 2001 From: J3m5 <5523410+J3m5@users.noreply.github.com> Date: Wed, 4 Jun 2025 00:58:22 +0200 Subject: [PATCH 05/10] build(package.json): remove src from files field as source files are now inlined in source maps add LICENSE and include only README.md --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1976b42..873d686 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,10 @@ "main": "./lib/index.js", "types": "./lib/index.d.ts", "files": [ - "*.md", "lib", - "src" + "LICENSE", + "package.json", + "README.md" ], "scripts": { "build": "rm -rf lib/* && tsc", From 9a69c8a8b658b838ffd74ae0b793e833d42ff1a8 Mon Sep 17 00:00:00 2001 From: J3m5 <5523410+J3m5@users.noreply.github.com> Date: Wed, 4 Jun 2025 01:01:29 +0200 Subject: [PATCH 06/10] build(package.json): update scripts, add typecheck[:watch], rename fix to lint:fix, rename watch to build:watch also remove tsconfig.tsbuildinfo on build --- package.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 873d686..f63f188 100644 --- a/package.json +++ b/package.json @@ -26,12 +26,14 @@ "README.md" ], "scripts": { - "build": "rm -rf lib/* && tsc", + "build": "rm -rf lib tsconfig.tsbuildinfo && tsc", + "build:watch": "tsc --watch", "eslint-check": "eslint-config-prettier src/index.ts", - "fix": "pnpm lint --fix", "lint": "eslint src", + "lint:fix": "eslint src --fix", "test": "NODE_OPTIONS=--experimental-vm-modules jest", - "watch": "tsc --watch" + "typecheck": "tsc --noEmit", + "typecheck:watch": "tsc --noEmit --watch" }, "dependencies": { "graphql": "^16.0.0", From 66fcf52f05950eaed9f95b06855b9fb50435c019 Mon Sep 17 00:00:00 2001 From: J3m5 <5523410+J3m5@users.noreply.github.com> Date: Wed, 4 Jun 2025 01:04:27 +0200 Subject: [PATCH 07/10] build(package.json): add keywords, update repository with recommended structure and url doc: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#repository --- package.json | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f63f188..8125e9a 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,24 @@ "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.", + "keywords": [ + "api", + "api-platform", + "documentation", + "hydra", + "openapi", + "graphql", + "jsonld", + "json-schema", + "typescript", + "client" + ], "homepage": "https://github.com/api-platform/api-doc-parser", "bugs": "https://github.com/api-platform/api-doc-parser/issues", - "repository": "api-platform/api-doc-parser", + "repository": { + "type": "git", + "url": "git+https://github.com/api-platform/api-doc-parser.git" + }, "license": "MIT", "author": "Kévin Dunglas", "sideEffects": false, @@ -26,7 +41,7 @@ "README.md" ], "scripts": { - "build": "rm -rf lib tsconfig.tsbuildinfo && tsc", + "build": "rm -rf lib && tsc --project tsconfig.build.json", "build:watch": "tsc --watch", "eslint-check": "eslint-config-prettier src/index.ts", "lint": "eslint src", @@ -69,6 +84,9 @@ "typescript-eslint": "^8.22.0" }, "packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977", + "engines": { + "node": ">=18" + }, "publishConfig": { "access": "public" } From 8875bf9641bcc8a36a7de3a36d7d14fa39a7bfc2 Mon Sep 17 00:00:00 2001 From: J3m5 <5523410+J3m5@users.noreply.github.com> Date: Wed, 4 Jun 2025 01:08:22 +0200 Subject: [PATCH 08/10] test(jest): update config and add @jest/globals dev dependency --- jest.config.ts | 19 ++++++------------- package.json | 1 + pnpm-lock.yaml | 3 +++ 3 files changed, 10 insertions(+), 13 deletions(-) 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 8125e9a..63bf2fb 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "@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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b0257f9..6ff1789 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,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 From f72e63eaa3a4fd82658fd8d38bab31b7ddcfad93 Mon Sep 17 00:00:00 2001 From: J3m5 <5523410+J3m5@users.noreply.github.com> Date: Wed, 4 Jun 2025 01:12:27 +0200 Subject: [PATCH 09/10] fix(imports): add .js extension to imports --- src/hydra/fetchJsonLd.ts | 2 +- src/openapi3/parseOpenApi3Documentation.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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; From c8be1ba44dc8b8dd36c8da8dcfec103bc63fe112 Mon Sep 17 00:00:00 2001 From: J3m5 <5523410+J3m5@users.noreply.github.com> Date: Wed, 4 Jun 2025 20:00:16 +0200 Subject: [PATCH 10/10] fix(ci): prevent duplicated CI run on pull requests --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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: