From 7a6a1665d602d057c8d9d72aadfccbf98b7ad28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Smyrek?= Date: Tue, 29 Oct 2024 08:38:20 +0100 Subject: [PATCH] Revert "Other: The `publishPackageOnNpmCallback()` util does not remove a package directory even if npm says it was published. Closes ckeditor/ckeditor5#17322." This reverts commit a1b37c79347a7f74f88f6d945526e90b8ea96a67. --- .../lib/utils/publishpackageonnpmcallback.js | 3 ++- .../tests/utils/publishpackageonnpmcallback.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/ckeditor5-dev-release-tools/lib/utils/publishpackageonnpmcallback.js b/packages/ckeditor5-dev-release-tools/lib/utils/publishpackageonnpmcallback.js index 2d8f33087..2ae395b11 100644 --- a/packages/ckeditor5-dev-release-tools/lib/utils/publishpackageonnpmcallback.js +++ b/packages/ckeditor5-dev-release-tools/lib/utils/publishpackageonnpmcallback.js @@ -13,6 +13,7 @@ */ export default async function publishPackageOnNpmCallback( packagePath, taskOptions ) { const { tools } = await import( '@ckeditor/ckeditor5-dev-utils' ); + const { default: fs } = await import( 'fs-extra' ); try { await tools.shExec( `npm publish --access=public --tag ${ taskOptions.npmTag }`, { @@ -21,7 +22,7 @@ export default async function publishPackageOnNpmCallback( packagePath, taskOpti verbosity: 'silent' } ); - // Do nothing if `npm publish` says "OK". We cannot trust anything npm says. + await fs.remove( packagePath ); } catch { // Do nothing if an error occurs. A parent task will handle it. } diff --git a/packages/ckeditor5-dev-release-tools/tests/utils/publishpackageonnpmcallback.js b/packages/ckeditor5-dev-release-tools/tests/utils/publishpackageonnpmcallback.js index 4c9582fd3..ea78439db 100644 --- a/packages/ckeditor5-dev-release-tools/tests/utils/publishpackageonnpmcallback.js +++ b/packages/ckeditor5-dev-release-tools/tests/utils/publishpackageonnpmcallback.js @@ -62,18 +62,18 @@ describe( 'publishPackageOnNpmCallback()', () => { } ); } ); - // See: https://github.com/ckeditor/ckeditor5/issues/17322. - it( 'should not remove package directory after publishing on npm', async () => { + it( 'should remove package directory after publishing on npm', () => { const packagePath = '/workspace/ckeditor5/packages/ckeditor5-foo'; - await publishPackageOnNpmCallback( packagePath, { npmTag: 'nightly' } ); - - expect( fs.remove ).not.toHaveBeenCalled(); + return publishPackageOnNpmCallback( packagePath, { npmTag: 'nightly' } ) + .then( () => { + expect( fs.remove ).toHaveBeenCalledTimes( 1 ); + expect( fs.remove ).toHaveBeenCalledWith( packagePath ); + } ); } ); - // See: https://github.com/ckeditor/ckeditor5/issues/17120 - it( 'should not remove a package directory and not throw error when publishing on npm failed', async () => { - vi.mocked( tools.shExec ).mockRejectedValue( new Error( 'I failed because I can' ) ); + it( 'should not remove a package directory and not throw error when publishing on npm failed with code 409', async () => { + vi.mocked( tools.shExec ).mockRejectedValue( new Error( 'code E409' ) ); const packagePath = '/workspace/ckeditor5/packages/ckeditor5-foo';