From 0f2a58fd32aa26a1760fa2e1ad222c16ff71920e Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Sun, 27 Oct 2024 14:51:07 +0100 Subject: [PATCH] Internal: Replaced internal "pacote" calls with the decorated functions. --- .../lib/utils/checkversionavailability.js | 6 ++-- .../lib/utils/isversionpublishablefortag.js | 4 +-- .../lib/utils/versions.js | 4 +-- .../tests/utils/checkversionavailability.js | 10 +++--- .../tests/utils/isversionpublishablefortag.js | 14 ++++---- .../tests/utils/versions.js | 36 +++++++++---------- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/packages/ckeditor5-dev-release-tools/lib/utils/checkversionavailability.js b/packages/ckeditor5-dev-release-tools/lib/utils/checkversionavailability.js index 47d634686..a44057f27 100644 --- a/packages/ckeditor5-dev-release-tools/lib/utils/checkversionavailability.js +++ b/packages/ckeditor5-dev-release-tools/lib/utils/checkversionavailability.js @@ -3,7 +3,7 @@ * For licensing, see LICENSE.md. */ -import pacote from 'pacote'; +import { manifest } from './pacotecacheless.js'; /** * Checks if the provided version for the package exists in the npm registry. @@ -15,9 +15,9 @@ import pacote from 'pacote'; * @returns {Promise} */ export default async function checkVersionAvailability( version, packageName ) { - return pacote.manifest( `${ packageName }@${ version }`, { cache: null, preferOnline: true } ) + return manifest( `${ packageName }@${ version }` ) .then( () => { - // If `pacote.manifest` resolves, a package with the given version exists. + // If `manifest` resolves, a package with the given version exists. return false; } ) .catch( () => { diff --git a/packages/ckeditor5-dev-release-tools/lib/utils/isversionpublishablefortag.js b/packages/ckeditor5-dev-release-tools/lib/utils/isversionpublishablefortag.js index 4c12983f9..a95fc6c77 100644 --- a/packages/ckeditor5-dev-release-tools/lib/utils/isversionpublishablefortag.js +++ b/packages/ckeditor5-dev-release-tools/lib/utils/isversionpublishablefortag.js @@ -4,7 +4,7 @@ */ import semver from 'semver'; -import pacote from 'pacote'; +import { manifest } from './pacotecacheless.js'; /** * This util aims to verify if the given `packageName` can be published with the given `version` on the `npmTag`. @@ -15,7 +15,7 @@ import pacote from 'pacote'; * @returns {Promise.} */ export default async function isVersionPublishableForTag( packageName, version, npmTag ) { - const npmVersion = await pacote.manifest( `${ packageName }@${ npmTag }`, { cache: null, preferOnline: true } ) + const npmVersion = await manifest( `${ packageName }@${ npmTag }` ) .then( ( { version } ) => version ) // An `npmTag` does not exist, or it's a first release of a package. .catch( () => null ); diff --git a/packages/ckeditor5-dev-release-tools/lib/utils/versions.js b/packages/ckeditor5-dev-release-tools/lib/utils/versions.js index 56a401863..004dbbd9f 100644 --- a/packages/ckeditor5-dev-release-tools/lib/utils/versions.js +++ b/packages/ckeditor5-dev-release-tools/lib/utils/versions.js @@ -4,7 +4,7 @@ */ import { tools } from '@ckeditor/ckeditor5-dev-utils'; -import pacote from 'pacote'; +import { packument } from './pacotecacheless.js'; import getChangelog from './getchangelog.js'; import getPackageJson from './getpackagejson.js'; @@ -38,7 +38,7 @@ export function getLastFromChangelog( cwd = process.cwd() ) { export function getLastPreRelease( releaseIdentifier, cwd = process.cwd() ) { const packageName = getPackageJson( cwd ).name; - return pacote.packument( packageName, { cache: null, preferOnline: true } ) + return packument( packageName ) .then( result => { const lastVersion = Object.keys( result.versions ) .filter( version => version.startsWith( releaseIdentifier ) ) diff --git a/packages/ckeditor5-dev-release-tools/tests/utils/checkversionavailability.js b/packages/ckeditor5-dev-release-tools/tests/utils/checkversionavailability.js index a5831fea7..0a0badc4c 100644 --- a/packages/ckeditor5-dev-release-tools/tests/utils/checkversionavailability.js +++ b/packages/ckeditor5-dev-release-tools/tests/utils/checkversionavailability.js @@ -4,21 +4,21 @@ */ import { describe, expect, it, vi } from 'vitest'; -import pacote from 'pacote'; import checkVersionAvailability from '../../lib/utils/checkversionavailability.js'; +import { manifest } from '../../lib/utils/pacotecacheless.js'; -vi.mock( 'pacote' ); +vi.mock( '../../lib/utils/pacotecacheless.js' ); describe( 'checkVersionAvailability()', () => { it( 'should resolve to true if version does not exist', async () => { - vi.mocked( pacote.manifest ).mockRejectedValue( 'E404' ); + vi.mocked( manifest ).mockRejectedValue( 'E404' ); await expect( checkVersionAvailability( '1.0.1', 'stub-package' ) ).resolves.toBe( true ); - expect( pacote.manifest ).toHaveBeenCalledExactlyOnceWith( 'stub-package@1.0.1', expect.any( Object ) ); + expect( manifest ).toHaveBeenCalledExactlyOnceWith( 'stub-package@1.0.1' ); } ); it( 'should resolve to false if version exists', async () => { - pacote.manifest.mockResolvedValue( '1.0.1' ); + manifest.mockResolvedValue( '1.0.1' ); await expect( checkVersionAvailability( '1.0.1', 'stub-package' ) ).resolves.toBe( false ); } ); diff --git a/packages/ckeditor5-dev-release-tools/tests/utils/isversionpublishablefortag.js b/packages/ckeditor5-dev-release-tools/tests/utils/isversionpublishablefortag.js index 6ca3572f7..e64d34cab 100644 --- a/packages/ckeditor5-dev-release-tools/tests/utils/isversionpublishablefortag.js +++ b/packages/ckeditor5-dev-release-tools/tests/utils/isversionpublishablefortag.js @@ -4,18 +4,18 @@ */ import { describe, expect, it, vi } from 'vitest'; -import pacote from 'pacote'; import semver from 'semver'; import isVersionPublishableForTag from '../../lib/utils/isversionpublishablefortag.js'; +import { manifest } from '../../lib/utils/pacotecacheless.js'; -vi.mock( 'pacote' ); +vi.mock( '../../lib/utils/pacotecacheless.js' ); vi.mock( 'semver' ); describe( 'isVersionPublishableForTag()', () => { it( 'should return false if given version is not available', async () => { vi.mocked( semver.lte ).mockReturnValue( true ); - vi.mocked( pacote.manifest ).mockResolvedValue( ( { + vi.mocked( manifest ).mockResolvedValue( ( { version: '1.0.0' } ) ); @@ -23,13 +23,13 @@ describe( 'isVersionPublishableForTag()', () => { expect( result ).to.equal( false ); expect( semver.lte ).toHaveBeenCalledExactlyOnceWith( '1.0.0', '1.0.0' ); - expect( pacote.manifest ).toHaveBeenCalledExactlyOnceWith( 'package-name@latest', expect.any( Object ) ); + expect( manifest ).toHaveBeenCalledExactlyOnceWith( 'package-name@latest' ); } ); it( 'should return false if given version is not higher than the latest published', async () => { vi.mocked( semver.lte ).mockReturnValue( true ); - vi.mocked( pacote.manifest ).mockResolvedValue( ( { + vi.mocked( manifest ).mockResolvedValue( ( { version: '1.0.1' } ) ); @@ -40,12 +40,12 @@ describe( 'isVersionPublishableForTag()', () => { } ); it( 'should return true if given npm tag is not published yet', async () => { - vi.mocked( pacote.manifest ).mockRejectedValue( 'E404' ); + vi.mocked( manifest ).mockRejectedValue( 'E404' ); const result = await isVersionPublishableForTag( 'package-name', '1.0.0', 'alpha' ); expect( result ).to.equal( true ); expect( semver.lte ).not.toHaveBeenCalled(); - expect( pacote.manifest ).toHaveBeenCalledExactlyOnceWith( 'package-name@alpha', expect.any( Object ) ); + expect( manifest ).toHaveBeenCalledExactlyOnceWith( 'package-name@alpha' ); } ); } ); diff --git a/packages/ckeditor5-dev-release-tools/tests/utils/versions.js b/packages/ckeditor5-dev-release-tools/tests/utils/versions.js index f4c62e412..b04d75cd4 100644 --- a/packages/ckeditor5-dev-release-tools/tests/utils/versions.js +++ b/packages/ckeditor5-dev-release-tools/tests/utils/versions.js @@ -5,9 +5,9 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { tools } from '@ckeditor/ckeditor5-dev-utils'; -import pacote from 'pacote'; import getChangelog from '../../lib/utils/getchangelog.js'; import getPackageJson from '../../lib/utils/getpackagejson.js'; +import { packument } from '../../lib/utils/pacotecacheless.js'; import { getLastFromChangelog, @@ -21,7 +21,7 @@ import { } from '../../lib/utils/versions.js'; vi.mock( '@ckeditor/ckeditor5-dev-utils' ); -vi.mock( 'pacote' ); +vi.mock( '../../lib/utils/pacotecacheless.js' ); vi.mock( '../../lib/utils/getchangelog.js' ); vi.mock( '../../lib/utils/getpackagejson.js' ); @@ -106,20 +106,20 @@ describe( 'versions', () => { } ); it( 'asks npm for all versions of a package', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: {} } ); return getLastPreRelease( '42.0.0-alpha' ) .then( () => { - expect( vi.mocked( pacote ).packument ).toHaveBeenCalledTimes( 1 ); - expect( vi.mocked( pacote ).packument ).toHaveBeenCalledWith( 'ckeditor5', expect.any( Object ) ); + expect( vi.mocked( packument ) ).toHaveBeenCalledTimes( 1 ); + expect( vi.mocked( packument ) ).toHaveBeenCalledWith( 'ckeditor5' ); } ); } ); it( 'returns null if there is no version for a package', () => { - vi.mocked( pacote ).packument.mockRejectedValue(); + vi.mocked( packument ).mockRejectedValue(); return getLastPreRelease( '42.0.0-alpha' ) .then( result => { @@ -128,7 +128,7 @@ describe( 'versions', () => { } ); it( 'returns null if there is no pre-release version matching the release identifier', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-nightly-20230615.0': {}, @@ -146,7 +146,7 @@ describe( 'versions', () => { } ); it( 'returns last pre-release version matching the release identifier', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-nightly-20230615.0': {}, @@ -164,7 +164,7 @@ describe( 'versions', () => { } ); it( 'returns last pre-release version matching the release identifier (non-chronological versions order)', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-nightly-20230615.0': {}, @@ -183,7 +183,7 @@ describe( 'versions', () => { } ); it( 'returns last pre-release version matching the release identifier (sequence numbers greater than 10)', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-nightly-20230615.0': {}, @@ -203,7 +203,7 @@ describe( 'versions', () => { } ); it( 'returns last nightly version', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-nightly-20230614.0': {}, @@ -225,7 +225,7 @@ describe( 'versions', () => { } ); it( 'returns last nightly version from a specified day', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-nightly-20230614.0': {}, @@ -253,7 +253,7 @@ describe( 'versions', () => { } ); it( 'returns last nightly pre-release version', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-nightly-20230613.0': {}, @@ -279,7 +279,7 @@ describe( 'versions', () => { } ); it( 'returns pre-release version with id = 0 if pre-release version was never published for the package yet', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-nightly-20230615.0': {}, @@ -295,7 +295,7 @@ describe( 'versions', () => { } ); it( 'returns pre-release version with incremented id if older pre-release version was already published', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-nightly-20230615.0': {}, @@ -311,7 +311,7 @@ describe( 'versions', () => { } ); it( 'returns nightly version with incremented id if older nightly version was already published', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-nightly-20230615.5': {}, @@ -340,7 +340,7 @@ describe( 'versions', () => { } ); it( 'asks for a last nightly pre-release version', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-nightly-20230615.0': {}, @@ -369,7 +369,7 @@ describe( 'versions', () => { } ); it( 'asks for a last internal pre-release version', () => { - vi.mocked( pacote ).packument.mockResolvedValue( { + vi.mocked( packument ).mockResolvedValue( { name: 'ckeditor5', versions: { '0.0.0-internal-20230615.0': {},