1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Chore: Refactor InteropService to not use dynamic imports (#8454)

This commit is contained in:
Henry Heino
2023-07-12 02:30:38 -07:00
committed by GitHub
parent 93e4004033
commit d95d6733a1
12 changed files with 341 additions and 244 deletions

View File

@ -1,5 +1,5 @@
import InteropService from '../../services/interop/InteropService';
import { CustomExportContext, CustomImportContext, Module, ModuleType } from '../../services/interop/types';
import { CustomExportContext, CustomImportContext, ModuleType } from '../../services/interop/types';
import shim from '../../shim';
import { fileContentEqual, setupDatabaseAndSynchronizer, switchClient, checkThrowAsync, exportDir, supportDir } from '../../testing/test-utils';
import Folder from '../../models/Folder';
@ -10,6 +10,9 @@ import * as fs from 'fs-extra';
import { FolderEntity, NoteEntity, ResourceEntity } from '../database/types';
import { ModelType } from '../../BaseModel';
import * as ArrayUtils from '../../ArrayUtils';
import InteropService_Importer_Custom from './InteropService_Importer_Custom';
import InteropService_Exporter_Custom from './InteropService_Exporter_Custom';
import Module, { makeExportModule, makeImportModule } from './Module';
async function recreateExportDir() {
const dir = exportDir();
@ -47,35 +50,35 @@ function memoryExportModule() {
resources: [],
};
const module: Module = {
type: ModuleType.Exporter,
const module: Module = makeExportModule({
description: 'Memory Export Module',
format: 'memory',
fileExtensions: ['memory'],
isCustom: true,
}, () => {
return new InteropService_Exporter_Custom({
onInit: async (context: CustomExportContext) => {
result.destPath = context.destPath;
},
onInit: async (context: CustomExportContext) => {
result.destPath = context.destPath;
},
onProcessItem: async (_context: CustomExportContext, itemType: number, item: any) => {
result.items.push({
type: itemType,
object: item,
});
},
onProcessItem: async (_context: CustomExportContext, itemType: number, item: any) => {
result.items.push({
type: itemType,
object: item,
});
},
onProcessResource: async (_context: CustomExportContext, resource: any, filePath: string) => {
result.resources.push({
filePath: filePath,
object: resource,
});
},
onProcessResource: async (_context: CustomExportContext, resource: any, filePath: string) => {
result.resources.push({
filePath: filePath,
object: resource,
});
},
onClose: async (_context: CustomExportContext) => {
// nothing
},
};
onClose: async (_context: CustomExportContext) => {
// nothing
},
});
});
return { result, module };
}
@ -555,18 +558,19 @@ describe('services_InteropService', () => {
sourcePath: '',
};
const module: Module = {
const module = makeImportModule({
type: ModuleType.Importer,
description: 'Test Import Module',
format: 'testing',
fileExtensions: ['test'],
isCustom: true,
onExec: async (context: CustomImportContext) => {
result.hasBeenExecuted = true;
result.sourcePath = context.sourcePath;
},
};
}, () => {
return new InteropService_Importer_Custom({
onExec: async (context: CustomImportContext) => {
result.hasBeenExecuted = true;
result.sourcePath = context.sourcePath;
},
});
});
const service = InteropService.instance();
service.registerModule(module);
@ -596,31 +600,32 @@ describe('services_InteropService', () => {
closeCalled: false,
};
const module: Module = {
const module: Module = makeExportModule({
type: ModuleType.Exporter,
description: 'Test Export Module',
format: 'testing',
fileExtensions: ['test'],
isCustom: true,
}, () => {
return new InteropService_Exporter_Custom({
onInit: async (context: CustomExportContext) => {
result.destPath = context.destPath;
},
onInit: async (context: CustomExportContext) => {
result.destPath = context.destPath;
},
onProcessItem: async (_context: CustomExportContext, itemType: number, item: any) => {
result.itemTypes.push(itemType);
result.items.push(item);
},
onProcessItem: async (_context: CustomExportContext, itemType: number, item: any) => {
result.itemTypes.push(itemType);
result.items.push(item);
},
onProcessResource: async (_context: CustomExportContext, resource: any, filePath: string) => {
result.resources.push(resource);
result.filePaths.push(filePath);
},
onProcessResource: async (_context: CustomExportContext, resource: any, filePath: string) => {
result.resources.push(resource);
result.filePaths.push(filePath);
},
onClose: async (_context: CustomExportContext) => {
result.closeCalled = true;
},
};
onClose: async (_context: CustomExportContext) => {
result.closeCalled = true;
},
});
});
const service = InteropService.instance();
service.registerModule(module);