From 2fc5ce270a4ce38c1e649185e82d5f19e3e078a9 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Thu, 16 Apr 2020 14:30:49 -0400 Subject: [PATCH] fix(core): rework where tmp tsconfigs are generated (#2805) --- .../src/builders/package/package.impl.spec.ts | 7 +++- .../web/src/builders/package/package.impl.ts | 6 ++-- .../src/utils/buildable-libs-utils.ts | 36 ++++++++++++++----- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/packages/node/src/builders/package/package.impl.spec.ts b/packages/node/src/builders/package/package.impl.spec.ts index cce19601ae879..991f17b5c2e54 100644 --- a/packages/node/src/builders/package/package.impl.spec.ts +++ b/packages/node/src/builders/package/package.impl.spec.ts @@ -284,7 +284,12 @@ describe('NodeCompileBuilder', () => { }); it('should call the tsc compiler with the modified tsconfig.json', done => { - let tmpTsConfigPath = join('libs/nodelib', 'tsconfig.nx-tmp'); + let tmpTsConfigPath = join( + '/root', + 'tmp', + 'libs/nodelib', + 'tsconfig.generated.json' + ); runNodePackageBuilder(testOptions, context).subscribe({ complete: () => { diff --git a/packages/web/src/builders/package/package.impl.ts b/packages/web/src/builders/package/package.impl.ts index cee7182e3f10e..feee834652e0e 100644 --- a/packages/web/src/builders/package/package.impl.ts +++ b/packages/web/src/builders/package/package.impl.ts @@ -32,7 +32,7 @@ import { calculateProjectDependencies, checkDependentProjectsHaveBeenBuilt, DependentBuildableProjectNode, - readTsConfigWithRemappedPaths, + computeCompilerOptionsPaths, updateBuildableProjectPackageJsonDependencies } from '@nrwl/workspace/src/utils/buildable-libs-utils'; @@ -147,7 +147,7 @@ function createRollupOptions( context: BuilderContext, packageJson: any ): rollup.InputOptions { - const parsedTSConfig = readTsConfigWithRemappedPaths( + const compilerOptionPaths = computeCompilerOptionsPaths( options.tsConfig, dependencies ); @@ -162,7 +162,7 @@ function createRollupOptions( rootDir: options.entryRoot, allowJs: false, declaration: true, - paths: parsedTSConfig.compilerOptions.paths + paths: compilerOptionPaths } } }), diff --git a/packages/workspace/src/utils/buildable-libs-utils.ts b/packages/workspace/src/utils/buildable-libs-utils.ts index a907c2d426e90..876f801fc444d 100644 --- a/packages/workspace/src/utils/buildable-libs-utils.ts +++ b/packages/workspace/src/utils/buildable-libs-utils.ts @@ -4,7 +4,7 @@ import { ProjectType } from '../core/project-graph'; import { BuilderContext } from '@angular-devkit/architect'; -import { join, resolve, dirname } from 'path'; +import { join, resolve, dirname, relative } from 'path'; import { fileExists, readJsonFile, @@ -81,15 +81,27 @@ function recursivelyCollectDependencies( return acc; } -export function readTsConfigWithRemappedPaths( +function readTsConfigWithRemappedPaths( tsConfig: string, + generatedTsConfigPath: string, dependencies: DependentBuildableProjectNode[] ) { - const parsedTSConfig = ts.readConfigFile(tsConfig, ts.sys.readFile).config; - parsedTSConfig.compilerOptions = parsedTSConfig.compilerOptions || {}; - parsedTSConfig.compilerOptions.paths = readPaths(tsConfig) || {}; - updatePaths(dependencies, parsedTSConfig.compilerOptions.paths); - return parsedTSConfig; + const generatedTsConfig: any = { compilerOptions: {} }; + generatedTsConfig.extends = relative( + dirname(generatedTsConfigPath), + tsConfig + ); + generatedTsConfig.compilerOptions.paths = computeCompilerOptionsPaths( + tsConfig, + dependencies + ); + return generatedTsConfig; +} + +export function computeCompilerOptionsPaths(tsConfig, dependencies) { + const paths = readPaths(tsConfig) || {}; + updatePaths(dependencies, paths); + return paths; } function readPaths(tsConfig: string) { @@ -116,11 +128,17 @@ export function createTmpTsConfig( projectRoot: string, dependencies: DependentBuildableProjectNode[] ) { + const tmpTsConfigPath = join( + workspaceRoot, + 'tmp', + projectRoot, + 'tsconfig.generated.json' + ); const parsedTSConfig = readTsConfigWithRemappedPaths( tsconfigPath, + tmpTsConfigPath, dependencies ); - const tmpTsConfigPath = join(workspaceRoot, projectRoot, 'tsconfig.nx-tmp'); process.on('exit', () => { cleanupTmpTsConfigFile(tmpTsConfigPath); }); @@ -133,7 +151,7 @@ export function createTmpTsConfig( process.exit(0); }); writeJsonFile(tmpTsConfigPath, parsedTSConfig); - return join(projectRoot, 'tsconfig.nx-tmp'); + return join(tmpTsConfigPath); } function cleanupTmpTsConfigFile(tmpTsConfigPath) {