1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-24 23:26:50 +02:00

Mobile: Fixed mobile build

This commit is contained in:
Laurent Cozic
2021-01-27 17:42:58 +00:00
parent 35597ce3c2
commit 12187b9da3
24 changed files with 1247 additions and 79 deletions

View File

@ -1,3 +1,5 @@
'use strict';
const fs = require('fs-extra');
const shim = require('./shim').default;
const { GeolocationNode } = require('./geolocation-node.js');
@ -23,6 +25,15 @@ function fileExists(filePath) {
}
}
// https://github.com/sindresorhus/callsites/blob/main/index.js
function callsites() {
const _prepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = (_any, stack) => stack;
const stack = new Error().stack.slice(1);
Error.prepareStackTrace = _prepareStackTrace;
return stack;
}
const gunzipFile = function(source, destination) {
if (!fileExists(source)) {
throw new Error(`No such file: ${source}`);
@ -535,7 +546,17 @@ function shimInit(sharp = null, keytar = null, React = null) {
};
shim.requireDynamic = (path) => {
return require(path);
if (path.indexOf('.') === 0) {
const sites = callsites();
if (sites.length <= 1) throw new Error(`Cannot require file (1) ${path}`);
const filename = sites[1].getFileName();
if (!filename) throw new Error(`Cannot require file (2) ${path}`);
const fileDirName = require('path').dirname(filename);
return require(`${fileDirName}/${path}`);
} else {
return require(path);
}
};
}