mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Chore: Fixed mobile build
This commit is contained in:
parent
1aebcbb27c
commit
db4f6e9ce5
@ -1,6 +1,7 @@
|
||||
import { PluginStates } from '../reducer';
|
||||
import { ContentScriptType } from '../api/types';
|
||||
import { dirname } from '@joplin/renderer/pathUtils';
|
||||
import shim from '../../../shim';
|
||||
|
||||
export interface ExtraContentScript {
|
||||
id: string;
|
||||
@ -17,6 +18,8 @@ export function contentScriptsToCodeMirrorPlugin(plugins: PluginStates): ExtraCo
|
||||
}
|
||||
|
||||
function loadContentScripts(plugins: PluginStates, scriptType: ContentScriptType): ExtraContentScript[] {
|
||||
if (!plugins) return null;
|
||||
|
||||
const output: ExtraContentScript[] = [];
|
||||
|
||||
for (const pluginId in plugins) {
|
||||
@ -25,7 +28,7 @@ function loadContentScripts(plugins: PluginStates, scriptType: ContentScriptType
|
||||
if (!contentScripts) continue;
|
||||
|
||||
for (const contentScript of contentScripts) {
|
||||
const module = require(contentScript.path);
|
||||
const module = shim.requireDynamic(contentScript.path);
|
||||
if (!module.default || typeof module.default !== 'function') throw new Error(`Content script must export a function under the "default" key: Plugin: ${pluginId}: Script: ${contentScript.id}`);
|
||||
|
||||
const loadedModule = module.default({});
|
||||
|
@ -533,6 +533,10 @@ function shimInit(sharp = null, keytar = null, React = null) {
|
||||
shim.keytar = () => {
|
||||
return keytar;
|
||||
};
|
||||
|
||||
shim.requireDynamic = (path) => {
|
||||
return require(path);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { shimInit };
|
||||
|
@ -325,6 +325,16 @@ const shim = {
|
||||
keytar: (): any => {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
|
||||
// In general all imports should be static, but for cases where dynamic
|
||||
// require is needed, we should use the shim so that the code can build in
|
||||
// React Native. In React Native that code path will throw an error, but at
|
||||
// least it will build.
|
||||
// https://stackoverflow.com/questions/55581073
|
||||
requireDynamic: (_path: string): any => {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
export default shim;
|
||||
|
Loading…
Reference in New Issue
Block a user