1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Plugin Repo: Resolves #9280: Allow marking specific NPM packages as superseded (#9302)

This commit is contained in:
Henry Heino 2023-11-15 05:44:09 -08:00 committed by GitHub
parent 48621443ec
commit 4a63331306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 6 deletions

View File

@ -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);

View File

@ -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']);
});
});

View File

@ -4,6 +4,7 @@ import { readJsonFile } from './utils';
export interface ManifestOverride {
_obsolete?: boolean;
_recommended?: boolean;
_superseded_package?: string;
}
export type ManifestOverrides = Record<string, ManifestOverride>;
@ -49,3 +50,16 @@ function pluginManifestOverridesPath(repoDir: string): string {
export async function readManifestOverrides(repoDir: string): Promise<ManifestOverrides> {
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;
};