-
-
Notifications
You must be signed in to change notification settings - Fork 5k
/
pluginRunnerBackgroundPage.ts
47 lines (41 loc) · 1.34 KB
/
pluginRunnerBackgroundPage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
export { runPlugin, stopPlugin } from './startStopPlugin';
// Old plugins allowed to import legacy APIs
const legacyPluginIds = [
'outline',
'ylc395.noteLinkSystem',
'com.github.joplin.kanban',
];
const pathLibrary = require('path');
const punycode = require('punycode/');
export const requireModule = (moduleName: string, fromPluginId: string) => {
if (moduleName === 'path') {
return pathLibrary;
}
if (legacyPluginIds.includes(fromPluginId)) {
if (moduleName === 'punycode') {
console.warn('Requiring punycode is deprecated. Please transition to a newer API.');
return punycode;
}
if (moduleName === 'fs' || moduleName === 'fs-extra') {
console.warn('The fs library is unavailable to mobile plugins. A non-functional mock will be returned.');
return {
existsSync: () => false,
pathExists: () => false,
readFileSync: () => '',
readFile: () => '',
writeFileSync: () => '',
writeFile: () => '',
appendFile: () => '',
};
}
if (moduleName === 'process') {
return {};
}
if (moduleName === 'url') {
return { parse: (u: string) => new URL(u) };
}
}
throw new Error(`Unable to require module ${moduleName} on mobile.`);
};
export { default as initializePluginBackgroundIframe } from './initializePluginBackgroundIframe';
export { default as initializeDialogWebView } from './initializeDialogWebView';