Skip to content

Commit

Permalink
fix(ts-config-writer) - nest typesRoot under compilerOptions and make…
Browse files Browse the repository at this point in the history
… them relative paths (#7212)

## Proposed Changes

- nest typesRoot under compilerOptions
- make typesRoot values relative paths instead of absolute 
- Uniq typesRoot
  • Loading branch information
GiladShoham authored Mar 28, 2023
1 parent 51e974f commit 086b3ae
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scopes/typescript/typescript/ts-config-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { stringify, parse, assign } from 'comment-json';
import { sha1 } from '@teambit/legacy/dist/utils';
import fs from 'fs-extra';
import { ExecutionContext } from '@teambit/envs';
import { basename, join } from 'path';
import { basename, join, relative } from 'path';
import type {
ConfigWriterEntry,
WrittenConfigFile,
Expand All @@ -11,6 +11,7 @@ import type {
EnvMapValue,
PostProcessExtendingConfigFilesArgs,
} from '@teambit/workspace-config-files';
import { uniq } from 'lodash';
import { CompilerMain } from '@teambit/compiler';
import { Logger } from '@teambit/logger';
import { IdeConfig, TypescriptCompilerInterface } from './typescript-compiler-interface';
Expand Down Expand Up @@ -105,9 +106,13 @@ export class TypescriptConfigWriter implements ConfigWriterEntry {
tsConfig = parse(content);
}
// @ts-ignore
const typeRoots = tsConfig.typeRoots || [];
typeRoots.push(join(configsRootDir, GLOBAL_TYPES_DIR));
assign(tsConfig, { typeRoots });
const compilerOptions = tsConfig.compilerOptions || {};
const typeRoots = compilerOptions.typeRoots || [];
const globalTypesDir = join(configsRootDir, GLOBAL_TYPES_DIR);
const relativeGlobalTypesDir = relative(workspaceDir, globalTypesDir);
typeRoots.push(relativeGlobalTypesDir);
assign(compilerOptions, { typeRoots: uniq(typeRoots) });
assign(tsConfig, { compilerOptions });
await fs.outputFile(rootTsConfigPath, stringify(tsConfig, null, 2));
}

Expand Down

0 comments on commit 086b3ae

Please sign in to comment.