From 2bc2c09ef695f6fa45b78f4439995740357d516c Mon Sep 17 00:00:00 2001 From: P-Chan Date: Tue, 1 Aug 2023 21:31:51 +0900 Subject: [PATCH] feat: add shareable tsconfig support Fix https://github.com/danger/danger-js/issues/1283 --- package.json | 3 ++- source/ambient.d.ts | 2 ++ source/runner/runners/utils/transpiler.ts | 4 ++-- yarn.lock | 12 ++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a3a9c96ee..dcf3ee820 100644 --- a/package.json +++ b/package.json @@ -142,6 +142,7 @@ "typescript-json-schema": "^0.53.0" }, "dependencies": { + "@gitbeaker/node": "^21.3.0", "@octokit/rest": "^18.12.0", "async-retry": "1.2.3", "chalk": "^2.3.0", @@ -150,7 +151,7 @@ "debug": "^4.1.1", "fast-json-patch": "^3.0.0-1", "get-stdin": "^6.0.0", - "@gitbeaker/node": "^21.3.0", + "get-tsconfig": "^4.6.2", "http-proxy-agent": "^5.0.0", "https-proxy-agent": "^5.0.1", "hyperlinker": "^1.0.0", diff --git a/source/ambient.d.ts b/source/ambient.d.ts index 97cae1172..40b9e7795 100644 --- a/source/ambient.d.ts +++ b/source/ambient.d.ts @@ -20,6 +20,8 @@ declare module "cli-interact" declare module "hyperlinker" declare module "supports-hyperlinks" +declare module "get-tsconfig" + // declare module "require-from-string" { // export interface RequireOptions { // /** List of paths, that will be appended to module paths. Useful, when you want diff --git a/source/runner/runners/utils/transpiler.ts b/source/runner/runners/utils/transpiler.ts index 97021cef4..71145337d 100644 --- a/source/runner/runners/utils/transpiler.ts +++ b/source/runner/runners/utils/transpiler.ts @@ -1,6 +1,6 @@ import * as fs from "fs" import * as path from "path" -import JSON5 from "json5" +import { parseTsconfig } from "get-tsconfig" import { debug } from "../../../debug" const enum BabelPackagePrefix { @@ -126,7 +126,7 @@ export const typescriptify = (content: string, dir: string): string => { let compilerOptions: any const tsConfigPath = lookupTSConfig(dir) if (tsConfigPath) { - compilerOptions = JSON5.parse(fs.readFileSync(tsConfigPath, "utf8")) + compilerOptions = parseTsconfig(tsConfigPath) } else { compilerOptions = ts.getDefaultCompilerOptions() } diff --git a/yarn.lock b/yarn.lock index 6a11f88d4..2fa343921 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4566,6 +4566,13 @@ get-stream@^6.0.0: resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg== +get-tsconfig@^4.6.2: + version "4.6.2" + resolved "https://registry.yarnpkg.com/get-tsconfig/-/get-tsconfig-4.6.2.tgz#831879a5e6c2aa24fe79b60340e2233a1e0f472e" + integrity sha512-E5XrT4CbbXcXWy+1jChlZmrmCwd5KGx502kDCXJJ7y898TtWW9FwoG5HfOLVRKmlmDGkWN2HM9Ho+/Y8F0sJDg== + dependencies: + resolve-pkg-maps "^1.0.0" + get-value@^2.0.3, get-value@^2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" @@ -8340,6 +8347,11 @@ resolve-from@^5.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== +resolve-pkg-maps@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz#616b3dc2c57056b5588c31cdf4b3d64db133720f" + integrity sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw== + resolve-url@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"