diff --git a/packages/app-cli/tests/services/plugins/defaultPluginsUtils.ts b/packages/app-cli/tests/services/plugins/defaultPluginsUtils.ts index b661bc539..5bd6b7b62 100644 --- a/packages/app-cli/tests/services/plugins/defaultPluginsUtils.ts +++ b/packages/app-cli/tests/services/plugins/defaultPluginsUtils.ts @@ -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'); @@ -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 }, diff --git a/packages/app-cli/tests/support/testDefaultPlugins/joplin.plugin.ambrt.backlinksToNote.jpl b/packages/app-cli/tests/support/testDefaultPlugins/joplin.plugin.ambrt.backlinksToNote.jpl new file mode 100644 index 000000000..3c472f8fb Binary files /dev/null and b/packages/app-cli/tests/support/testDefaultPlugins/joplin.plugin.ambrt.backlinksToNote.jpl differ diff --git a/packages/app-cli/tests/support/testDefaultPlugins/org.joplinapp.plugins.ToggleSidebars.jpl b/packages/app-cli/tests/support/testDefaultPlugins/org.joplinapp.plugins.ToggleSidebars.jpl new file mode 100644 index 000000000..77063baf7 Binary files /dev/null and b/packages/app-cli/tests/support/testDefaultPlugins/org.joplinapp.plugins.ToggleSidebars.jpl differ diff --git a/packages/default-plugins/buildDefaultPlugins.ts b/packages/default-plugins/buildDefaultPlugins.ts index e1e04bf54..a5bfe3b6d 100644 --- a/packages/default-plugins/buildDefaultPlugins.ts +++ b/packages/default-plugins/buildDefaultPlugins.ts @@ -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'; @@ -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.'); } diff --git a/packages/lib/services/plugins/defaultPlugins/defaultPluginsUtils.ts b/packages/lib/services/plugins/defaultPlugins/defaultPluginsUtils.ts index 4b0837d08..3e75c2813 100644 --- a/packages/lib/services/plugins/defaultPlugins/defaultPluginsUtils.ts +++ b/packages/lib/services/plugins/defaultPlugins/defaultPluginsUtils.ts @@ -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