diff --git a/packages/workspace/src/executors/tsc/tsc.impl.spec.ts b/packages/workspace/src/executors/tsc/tsc.impl.spec.ts index 992cb2fea67a9..6b8fbbc0df287 100644 --- a/packages/workspace/src/executors/tsc/tsc.impl.spec.ts +++ b/packages/workspace/src/executors/tsc/tsc.impl.spec.ts @@ -67,38 +67,18 @@ describe('executor: tsc', () => { expect(result).toBe(expectedResult); }); - describe('copy assets', () => { - it('should not copy assets when typescript compilation is not successful', async () => { - compileTypeScriptMock.mockReturnValue({ success: false }); + it('should copy assets before typescript compilation', async () => { + await tscExecutor(options, context); - await tscExecutor(options, context); - - expect(copyAssets).not.toHaveBeenCalled(); - }); - - it('should copy assets when typescript compilation is successful', async () => { - compileTypeScriptMock.mockReturnValue({ success: true }); - - await tscExecutor(options, context); - - expect(copyAssets).toHaveBeenCalledWith( - assets, - context.root, - normalizedOptions.outputPath - ); - }); + expect(copyAssets).toHaveBeenCalledWith( + assets, + context.root, + normalizedOptions.outputPath + ); }); describe('update package.json', () => { - it('should not update package.json when typescript compilation is not successful', async () => { - compileTypeScriptMock.mockReturnValue({ success: false }); - - await tscExecutor(options, context); - - expect(writeJsonFile).not.toHaveBeenCalled(); - }); - - it('should update the package.json when typescript compilation is successful and both main and typings are missing', async () => { + it('should update the package.json when both main and typings are missing', async () => { compileTypeScriptMock.mockReturnValue({ success: true }); await tscExecutor(options, context); @@ -113,7 +93,7 @@ describe('executor: tsc', () => { ); }); - it('should update the package.json when typescript compilation is successful and only main is missing', async () => { + it('should update the package.json when only main is missing', async () => { compileTypeScriptMock.mockReturnValue({ success: true }); const packageJson = { ...defaultPackageJson, @@ -132,7 +112,7 @@ describe('executor: tsc', () => { ); }); - it('should update the package.json when typescript compilation is successful and only typings is missing', async () => { + it('should update the package.json when only typings is missing', async () => { compileTypeScriptMock.mockReturnValue({ success: true }); const packageJson = { ...defaultPackageJson, @@ -151,7 +131,7 @@ describe('executor: tsc', () => { ); }); - it('should not update the package.json when typescript compilation is successful and both main and typings are specified', async () => { + it('should not update the package.json when both main and typings are specified', async () => { compileTypeScriptMock.mockReturnValue({ success: true }); readJsonFileMock.mockReturnValue({ ...defaultPackageJson, diff --git a/packages/workspace/src/executors/tsc/tsc.impl.ts b/packages/workspace/src/executors/tsc/tsc.impl.ts index e7051cb396d62..b9637a789870f 100644 --- a/packages/workspace/src/executors/tsc/tsc.impl.ts +++ b/packages/workspace/src/executors/tsc/tsc.impl.ts @@ -12,23 +12,19 @@ export async function tscExecutor( const normalizedOptions = normalizeOptions(options, context); const projectRoot = context.workspace.projects[context.projectName].root; - const result = compileTypeScript({ + await copyAssets( + normalizedOptions.assets, + context.root, + normalizedOptions.outputPath + ); + updatePackageJson(normalizedOptions, projectRoot); + + return compileTypeScript({ outputPath: normalizedOptions.outputPath, projectName: context.projectName, projectRoot, tsConfig: normalizedOptions.tsConfig, }); - - if (result.success) { - await copyAssets( - normalizedOptions.assets, - context.root, - normalizedOptions.outputPath - ); - updatePackageJson(normalizedOptions, projectRoot); - } - - return result; } function getMainFileDirRelativeToProjectRoot( diff --git a/packages/workspace/src/utilities/typescript/compilation.ts b/packages/workspace/src/utilities/typescript/compilation.ts index 1bb511e1d371b..71603d0df63f9 100644 --- a/packages/workspace/src/utilities/typescript/compilation.ts +++ b/packages/workspace/src/utilities/typescript/compilation.ts @@ -15,7 +15,7 @@ export interface TypeScriptCompilationOptions { export function compileTypeScript( options: TypeScriptCompilationOptions -): { success: boolean } { +): { success: boolean } | Promise { const normalizedOptions = normalizeOptions(options); if (normalizedOptions.deleteOutputPath) { @@ -64,16 +64,14 @@ function createProgram( } } -function createWatchProgram( - tsconfig: ts.ParsedCommandLine -): { success: boolean } { +function createWatchProgram(tsconfig: ts.ParsedCommandLine): Promise { const host = ts.createWatchCompilerHost( tsconfig.fileNames, tsconfig.options, ts.sys ); ts.createWatchProgram(host); - return { success: true }; + return new Promise(() => {}); } function normalizeOptions(