|
1 | 1 | import * as fs from 'fs'; |
2 | 2 | import * as path from 'path'; |
3 | 3 |
|
4 | | -import { stripJsonComments, workspaceRoot } from '@nrwl/devkit'; |
| 4 | +import { stripJsonComments } from '@nrwl/devkit'; |
5 | 5 | import * as jju from 'jju'; |
6 | 6 | import type { TscTaskOptions } from 'just-scripts'; |
7 | 7 |
|
@@ -50,41 +50,53 @@ function enableAllowSyntheticDefaultImports(options: { pkgJson: PackageJson }) { |
50 | 50 | return shouldEnable ? { allowSyntheticDefaultImports: true } : null; |
51 | 51 | } |
52 | 52 |
|
53 | | -const rootTsConfig = JSON.parse(fs.readFileSync(path.join(workspaceRoot, 'tsconfig.base.json'), 'utf-8')) as TsConfig; |
| 53 | +function createNormalizedTsPaths(options: { definitionsRootPath: string; pathAliasesTsConfigPath: string }) { |
| 54 | + type PathAliases = Record<string, string[]>; |
| 55 | + const { definitionsRootPath, pathAliasesTsConfigPath } = options; |
| 56 | + const tsConfigRoot = JSON.parse(fs.readFileSync(pathAliasesTsConfigPath, 'utf-8')) as TsConfig; |
| 57 | + const paths = (tsConfigRoot.compilerOptions.paths as unknown) as undefined | PathAliases; |
54 | 58 |
|
55 | | -function createNormalizedTsPaths(options: { definitionsRootPath: string; rootTsConfig: TsConfig }) { |
56 | | - const paths = (options.rootTsConfig.compilerOptions.paths as unknown) as Record<string, string[]>; |
| 59 | + if (!paths) { |
| 60 | + throw new Error(`Provided "${pathAliasesTsConfigPath}" has no compilerOptions.path defined`); |
| 61 | + } |
57 | 62 |
|
58 | 63 | const normalizedPaths = Object.entries(paths).reduce((acc, [pkgName, pathAliases]) => { |
59 | | - acc[pkgName] = [path.join(options.definitionsRootPath, pathAliases[0].replace('index.ts', 'index.d.ts'))]; |
| 64 | + acc[pkgName] = [path.join(definitionsRootPath, pathAliases[0].replace('index.ts', 'index.d.ts'))]; |
60 | 65 | return acc; |
61 | | - }, {} as typeof paths); |
| 66 | + }, {} as PathAliases); |
62 | 67 |
|
63 | 68 | return normalizedPaths; |
64 | 69 | } |
65 | 70 |
|
66 | 71 | export function getTsPathAliasesApiExtractorConfig(options: { |
67 | 72 | tsConfig: TsConfig; |
68 | | - tsConfigPath: string; |
69 | 73 | packageJson: PackageJson; |
70 | 74 | definitionsRootPath: string; |
| 75 | + pathAliasesTsConfigPath?: string; |
71 | 76 | }) { |
72 | | - const normalizedPaths = createNormalizedTsPaths({ definitionsRootPath: options.definitionsRootPath, rootTsConfig }); |
| 77 | + const { packageJson, tsConfig, pathAliasesTsConfigPath, definitionsRootPath } = options; |
| 78 | + /** |
| 79 | + * Because api-extractor ran into race conditions when executing via lage (https://github.com/microsoft/fluentui/issues/25766), |
| 80 | + * we won't use path aliases on CI, rather serving api-extractor rolluped dts files cross package, that will be referenced via yarn workspace sym-links |
| 81 | + */ |
| 82 | + const normalizedPaths = pathAliasesTsConfigPath |
| 83 | + ? createNormalizedTsPaths({ definitionsRootPath, pathAliasesTsConfigPath }) |
| 84 | + : undefined; |
73 | 85 |
|
74 | 86 | /** |
75 | 87 | * Customized TSConfig that uses `tsconfig.lib.json` as base with some required overrides: |
76 | 88 | * |
77 | 89 | * NOTES: |
78 | 90 | * - `extends` is properly resolved via api-extractor which uses TS api |
79 | 91 | * - `skipLibCheck` needs to be explicitly set to `false` so errors propagate to api-extractor |
80 | | - * - `paths` is overriden to path mapping that points to generated declaration files. This also enables creation of dts rollup without a need of generating rollups for all dependencies 🫡 |
| 92 | + * - `paths` if usePathAliases is enabled, we override it to path mapping that points to generated declaration files. This also enables creation of dts rollup without a need of generating rollups for all dependencies 🫡 |
81 | 93 | * |
82 | 94 | */ |
83 | 95 | const apiExtractorTsConfig: TsConfig = { |
84 | | - ...options.tsConfig, |
| 96 | + ...tsConfig, |
85 | 97 | compilerOptions: { |
86 | | - ...options.tsConfig.compilerOptions, |
87 | | - ...enableAllowSyntheticDefaultImports({ pkgJson: options.packageJson }), |
| 98 | + ...tsConfig.compilerOptions, |
| 99 | + ...enableAllowSyntheticDefaultImports({ pkgJson: packageJson }), |
88 | 100 | /** |
89 | 101 | * This option has no effect on type declarations '.d.ts' thus can be turned off. For more info see https://www.typescriptlang.org/tsconfig#non-module-files |
90 | 102 | * |
|
0 commit comments