Skip to content

Commit

Permalink
Desktop: Fixes #9781: Extract default plugins to directories matching…
Browse files Browse the repository at this point in the history
… their IDs (#9782)
  • Loading branch information
personalizedrefrigerator authored Jan 26, 2024
1 parent da4d57c commit 13da286
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('defaultPluginsUtils', () => {
});

it('should load default plugins when nor previously installed', (async () => {
const testPluginDir = `${supportDir}/pluginRepo/plugins`;
const testPluginDir = `${supportDir}/testDefaultPlugins`;
Setting.setValue('installedDefaultPlugins', []);

const service = newPluginService('2.1');
Expand All @@ -57,7 +57,7 @@ describe('defaultPluginsUtils', () => {
}));

it('should keep already created default plugins disabled with previous default plugins installed', (async () => {
const testPluginDir = `${supportDir}/pluginRepo/plugins`;
const testPluginDir = `${supportDir}/testDefaultPlugins`;
Setting.setValue('installedDefaultPlugins', ['org.joplinapp.plugins.ToggleSidebars']);
Setting.setValue('plugins.states', {
'org.joplinapp.plugins.ToggleSidebars': { ...defaultPluginSetting(), enabled: false },
Expand Down
Binary file not shown.
Binary file not shown.
14 changes: 4 additions & 10 deletions packages/default-plugins/buildDefaultPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/* eslint-disable no-console */

import { copy, exists, remove, mkdirp, readdir, mkdtemp } from 'fs-extra';
import { copy, exists, remove, readdir, mkdtemp } from 'fs-extra';
import { join, resolve, basename } from 'path';
import { tmpdir } from 'os';
import { chdir, cwd } from 'process';
Expand Down Expand Up @@ -95,17 +95,11 @@ const buildDefaultPlugins = async (outputParentDir: string|null, beforeInstall:

if (outputParentDir !== null) {
logStatus(`Checking output directory in ${outputParentDir}`);
const outputDirectory = join(outputParentDir, pluginId);
if (await exists(outputDirectory)) {
await remove(outputDirectory);
}
await mkdirp(outputDirectory);
const outputPath = join(outputParentDir, `${pluginId}.jpl`);

const sourceFile = jplFiles[0];
const destFile = join(outputDirectory, 'plugin.jpl');

logStatus(`Copying built file from ${sourceFile} to ${destFile}`);
await copy(sourceFile, destFile);
logStatus(`Copying built file from ${sourceFile} to ${outputPath}`);
await copy(sourceFile, outputPath);
} else {
console.warn('No output directory specified. Not copying built .jpl files.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,26 @@ export const getDefaultPluginPathsAndSettings = async (

for (const pluginStat of defaultPluginsPaths) {
// Each plugin should be within a folder with the same ID as the plugin
const pluginFolderName = pluginStat.path;
const pluginId = pluginFolderName;
const pluginFileName = pluginStat.path;
const pluginIdMatch = pluginFileName.match(/^(.*)+\.jpl$/);

// Previously, default plugins were stored as
// default-plugin-id/plugin.jpl
// We handle this case by skipping files that don't match the format
// default-plugin-id.jpl
if (!pluginIdMatch) {
logger.warn(`Default plugin filename ${pluginFileName} is not a .JPL file. Skipping.`);
continue;
}

const pluginId = pluginIdMatch[1];

if (!defaultPluginsInfo.hasOwnProperty(pluginId)) {
logger.warn(`Default plugin ${pluginId} is missing in defaultPluginsInfo. Not loading.`);
continue;
}

pluginPaths.push(join(defaultPluginsDir, pluginFolderName, 'plugin.jpl'));
pluginPaths.push(join(defaultPluginsDir, pluginFileName));

pluginSettings = produce(pluginSettings, (draft: PluginSettings) => {
// Default plugins can be overridden but not uninstalled (as they're part of
Expand Down

0 comments on commit 13da286

Please sign in to comment.