From 4dae4043fd2d261d914f89a6cede2eaefb9663b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=A7=91=F0=9F=8F=BB=E2=80=8D=F0=9F=92=BB=20Romain=20M?= =?UTF-8?q?arcadier?= Date: Mon, 18 Jul 2022 14:54:26 +0200 Subject: [PATCH] feat(jsii): allow specifying baseUrl and paths in tsconfig.json Allow user control of the `baseUrl` and `paths` compiler options in `tsconfig.json` via the `jsii.tsc` stanza in `package.json`. Fixes #865 --- .../content/user-guides/lib-author/configuration/index.md | 1 + packages/jsii/lib/project-info.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/gh-pages/content/user-guides/lib-author/configuration/index.md b/gh-pages/content/user-guides/lib-author/configuration/index.md index 32c77a84fc..34515cc1b8 100644 --- a/gh-pages/content/user-guides/lib-author/configuration/index.md +++ b/gh-pages/content/user-guides/lib-author/configuration/index.md @@ -197,6 +197,7 @@ are set in the `jsii.tsc` section of the `package.json` file, but use the same n default, all visible `@types/*` packages will be loaded, which can be undesirable (in particular in monorepos, where some type libraries are not compatible with the TypeScript compiler version that `jsii` uses). The value specified here will be forwarded as-is to the TypeScript compiler. +- `baseUrl` and `paths` can be used to configure TypeScript path mappings, and are copied verbatim to `tsconfig.json`. Refer to the [TypeScript compiler options reference][ts-options] for more information about those options. diff --git a/packages/jsii/lib/project-info.ts b/packages/jsii/lib/project-info.ts index 713d32a9f6..2de0ae3f13 100644 --- a/packages/jsii/lib/project-info.ts +++ b/packages/jsii/lib/project-info.ts @@ -20,6 +20,9 @@ export type TSCompilerOptions = Partial< // Directory preferences | 'outDir' | 'rootDir' + // TypeScript path mapping + | 'baseUrl' + | 'paths' // Style preferences | 'forceConsistentCasingInFileNames' // Source map preferences @@ -220,6 +223,8 @@ export function loadProjectInfo(projectRoot: string): ProjectInfoResult { tsc: { outDir: pkg.jsii?.tsc?.outDir, rootDir: pkg.jsii?.tsc?.rootDir, + baseUrl: pkg.jsii?.tsc?.baseUrl, + paths: pkg.jsii?.tsc?.paths, forceConsistentCasingInFileNames: pkg.jsii?.tsc?.forceConsistentCasingInFileNames, ..._sourceMapPreferences(pkg.jsii?.tsc),