From 4a6333130684f8ccdbc670b367901a8bedfb56d9 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Wed, 15 Nov 2023 05:44:09 -0800 Subject: [PATCH] Plugin Repo: Resolves #9280: Allow marking specific NPM packages as superseded (#9302) --- packages/plugin-repo-cli/index.ts | 16 +++++++++++----- .../plugin-repo-cli/lib/overrideUtils.test.ts | 14 +++++++++++++- packages/plugin-repo-cli/lib/overrideUtils.ts | 14 ++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/packages/plugin-repo-cli/index.ts b/packages/plugin-repo-cli/index.ts index 2cd7457a3..65e8b281c 100644 --- a/packages/plugin-repo-cli/index.ts +++ b/packages/plugin-repo-cli/index.ts @@ -16,7 +16,7 @@ import { NpmPackage } from './lib/types'; import gitCompareUrl from './lib/gitCompareUrl'; import commandUpdateRelease from './commands/updateRelease'; import { isJoplinPluginPackage, readJsonFile } from './lib/utils'; -import { applyManifestOverrides, getObsoleteManifests, readManifestOverrides } from './lib/overrideUtils'; +import { applyManifestOverrides, getObsoleteManifests, getSupersededPackages, readManifestOverrides } from './lib/overrideUtils'; import { execCommand } from '@joplin/utils'; function pluginInfoFromSearchResults(results: any[]): NpmPackage[] { @@ -139,18 +139,24 @@ function chdir(path: string): string { } async function processNpmPackage(npmPackage: NpmPackage, repoDir: string, dryRun: boolean) { - const tempDir = `${repoDir}/temp`; - - await fs.mkdirp(tempDir); - const originalPluginManifests = await readManifests(repoDir); const manifestOverrides = await readManifestOverrides(repoDir); + const supersededPackages = getSupersededPackages(manifestOverrides); + + if (supersededPackages.includes(npmPackage.name)) { + console.log('Skipping superseded package', npmPackage.name); + return; + } + const obsoleteManifests = getObsoleteManifests(manifestOverrides); const existingManifests = { ...originalPluginManifests, ...obsoleteManifests, }; + const tempDir = `${repoDir}/temp`; + await fs.mkdirp(tempDir); + const packageTempDir = `${tempDir}/packages`; await fs.mkdirp(packageTempDir); diff --git a/packages/plugin-repo-cli/lib/overrideUtils.test.ts b/packages/plugin-repo-cli/lib/overrideUtils.test.ts index fafab7221..0bff2619c 100644 --- a/packages/plugin-repo-cli/lib/overrideUtils.test.ts +++ b/packages/plugin-repo-cli/lib/overrideUtils.test.ts @@ -1,4 +1,4 @@ -import { applyManifestOverrides, getObsoleteManifests, ManifestOverrides } from './overrideUtils'; +import { applyManifestOverrides, getObsoleteManifests, getSupersededPackages, ManifestOverrides } from './overrideUtils'; describe('overrideUtils', () => { @@ -92,4 +92,16 @@ describe('overrideUtils', () => { expect(updatedManifests['joplin.plugin.ambrt.backlinksToNote']._recommended).toBe(undefined); }); + test('should get superseded packages', () => { + const manifestOverrides = { + 'joplin.plugin.benji.favorites': { + _superseded_package: 'joplin-plugin-benji-favorites', + }, + 'io.github.jackgruber.copytags': { + _recommended: true, + }, + }; + const supersededPackages = getSupersededPackages(manifestOverrides); + expect(supersededPackages).toMatchObject(['joplin-plugin-benji-favorites']); + }); }); diff --git a/packages/plugin-repo-cli/lib/overrideUtils.ts b/packages/plugin-repo-cli/lib/overrideUtils.ts index 102a9d622..9fed1f79f 100644 --- a/packages/plugin-repo-cli/lib/overrideUtils.ts +++ b/packages/plugin-repo-cli/lib/overrideUtils.ts @@ -4,6 +4,7 @@ import { readJsonFile } from './utils'; export interface ManifestOverride { _obsolete?: boolean; _recommended?: boolean; + _superseded_package?: string; } export type ManifestOverrides = Record; @@ -49,3 +50,16 @@ function pluginManifestOverridesPath(repoDir: string): string { export async function readManifestOverrides(repoDir: string): Promise { return readJsonFile(pluginManifestOverridesPath(repoDir), {}); } + +export const getSupersededPackages = (manifsetOverrides: ManifestOverrides): string[] => { + const supersededPackages = []; + + for (const id in manifsetOverrides) { + const supersededPackage = manifsetOverrides[id]._superseded_package; + if (supersededPackage) { + supersededPackages.push(supersededPackage); + } + } + + return supersededPackages; +};