Skip to content

Commit

Permalink
fix(core): rework where tmp tsconfigs are generated (#2805)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Apr 16, 2020
1 parent c993957 commit 3bdcc0b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
7 changes: 6 additions & 1 deletion packages/node/src/builders/package/package.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/web/src/builders/package/package.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
calculateProjectDependencies,
checkDependentProjectsHaveBeenBuilt,
DependentBuildableProjectNode,
readTsConfigWithRemappedPaths,
computeCompilerOptionsPaths,
updateBuildableProjectPackageJsonDependencies
} from '@nrwl/workspace/src/utils/buildable-libs-utils';

Expand Down Expand Up @@ -147,7 +147,7 @@ function createRollupOptions(
context: BuilderContext,
packageJson: any
): rollup.InputOptions {
const parsedTSConfig = readTsConfigWithRemappedPaths(
const compilerOptionPaths = computeCompilerOptionsPaths(
options.tsConfig,
dependencies
);
Expand All @@ -162,7 +162,7 @@ function createRollupOptions(
rootDir: options.entryRoot,
allowJs: false,
declaration: true,
paths: parsedTSConfig.compilerOptions.paths
paths: compilerOptionPaths
}
}
}),
Expand Down
36 changes: 27 additions & 9 deletions packages/workspace/src/utils/buildable-libs-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
});
Expand All @@ -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) {
Expand Down

0 comments on commit 3bdcc0b

Please sign in to comment.