fix(misc): migration sets tsConfigs property for jest executor

This commit is contained in:
Victor Savkin 2020-12-21 12:44:11 -05:00
parent e768ad4862
commit baa4475b80

View File

@ -359,9 +359,9 @@ export class NxScopedHostForMigrations extends NxScopedHost {
) { ) {
return super return super
.read('/workspace.json' as any) .read('/workspace.json' as any)
.pipe(map(processConfig)); .pipe(map(processConfigWhenReading));
} else { } else {
return super.read(path).pipe(map(processConfig)); return super.read(path).pipe(map(processConfigWhenReading));
} }
} else { } else {
return super.read(path); return super.read(path);
@ -407,7 +407,10 @@ export class NxScopedHostForMigrations extends NxScopedHost {
hasWorkspace && hasWorkspace &&
(path == '/angular.json' || path == 'angular.json') (path == '/angular.json' || path == 'angular.json')
) { ) {
return super.write('/workspace.json' as any, content); return super.write(
'/workspace.json' as any,
processConfigWhenWriting(content)
);
} else { } else {
return super.write(path as any, content); return super.write(path as any, content);
} }
@ -420,7 +423,7 @@ export class NxScopedHostForMigrations extends NxScopedHost {
} }
} }
function processConfig(content: ArrayBuffer) { function processConfigWhenReading(content: ArrayBuffer) {
try { try {
const json = JSON.parse(Buffer.from(content).toString()); const json = JSON.parse(Buffer.from(content).toString());
Object.values(json.projects).forEach((p: any) => { Object.values(json.projects).forEach((p: any) => {
@ -442,6 +445,28 @@ function processConfig(content: ArrayBuffer) {
} }
} }
function processConfigWhenWriting(content: ArrayBuffer) {
try {
const json = JSON.parse(Buffer.from(content).toString());
Object.values(json.projects).forEach((p: any) => {
try {
Object.values(p.architect || p.targets).forEach((e: any) => {
if (
(e.builder === '@nrwl/jest:jest' ||
e.executor === '@nrwl/jest:jest') &&
e.options.tsConfig
) {
delete e.options.tsConfig;
}
});
} catch (e) {}
});
return Buffer.from(JSON.stringify(json, null, 2));
} catch (e) {
return content;
}
}
export async function generate( export async function generate(
root: string, root: string,
opts: GenerateOptions, opts: GenerateOptions,