fix(core): allow tsConfig without compilerOptions to work (#8119)

This commit is contained in:
Jack Hsu 2021-12-10 16:56:17 -05:00 committed by GitHub
parent 590577010d
commit d6307181ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -1,9 +1,11 @@
import { NxJsonConfiguration, WorkspaceJsonConfiguration } from '@nrwl/devkit';
import {
createCache as _createCache,
extractCachedFileData,
ProjectGraphCache,
shouldRecomputeWholeGraph,
} from './nx-deps-cache';
import { createCache } from './nx-deps-cache';
describe('nx deps utils', () => {
describe('shouldRecomputeWholeGraph', () => {
@ -277,6 +279,17 @@ describe('nx deps utils', () => {
});
});
describe('createCache', () => {
it('should work with empty tsConfig', () => {
_createCache(
createNxJson({}),
createPackageJsonDeps({}),
createCache({}),
{}
);
});
});
function createCache(p: Partial<ProjectGraphCache>): ProjectGraphCache {
const defaults: ProjectGraphCache = {
version: '3.0',

View File

@ -90,7 +90,7 @@ export function createCache(
nxJson: NxJsonConfiguration<'*' | string[]>,
packageJsonDeps: Record<string, string>,
projectGraph: ProjectGraph<any>,
tsConfig: { compilerOptions: { paths?: { [p: string]: any } } }
tsConfig: { compilerOptions?: { paths?: { [p: string]: any } } }
) {
const nxJsonPlugins = (nxJson.plugins || []).map((p) => ({
name: p,
@ -99,7 +99,8 @@ export function createCache(
const newValue: ProjectGraphCache = {
version: projectGraph.version || '5.0',
deps: packageJsonDeps,
pathMappings: tsConfig.compilerOptions.paths || {},
// compilerOptions may not exist, especially for repos converted through add-nx-to-monorepo
pathMappings: tsConfig.compilerOptions?.paths || {},
nxJsonPlugins,
nodes: projectGraph.nodes,
externalNodes: projectGraph.externalNodes,