mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 10:19:08 +00:00
Fix dynamic imports in bundled app
This commit is contained in:
@@ -25,10 +25,24 @@ const source = readFileSync(srcPath);
|
|||||||
|
|
||||||
window.preloadCompileStartTime = Date.now();
|
window.preloadCompileStartTime = Date.now();
|
||||||
|
|
||||||
|
// `filename` is used for:
|
||||||
|
//
|
||||||
|
// - Annotating stack traces
|
||||||
|
// - Resolving dynamic `import()` calls
|
||||||
|
//
|
||||||
|
// When it is not an absolute path `import()` is resolved relative to the `cwd`.
|
||||||
|
//
|
||||||
|
// Since filename gets written into the `preload.bundle.cache` we need to use a
|
||||||
|
// path-independent value for reproducibility, and otherwise use full absolute
|
||||||
|
// path in the packaged app.
|
||||||
|
const filename = process.env.GENERATE_PRELOAD_CACHE
|
||||||
|
? 'preload.bundle.js'
|
||||||
|
: srcPath;
|
||||||
|
|
||||||
const script = new Script(
|
const script = new Script(
|
||||||
`(function(require, __dirname){${source.toString()}})`,
|
`(function(require, __dirname){${source.toString()}})`,
|
||||||
{
|
{
|
||||||
filename: 'preload.bundle.js',
|
filename,
|
||||||
lineOffset: 0,
|
lineOffset: 0,
|
||||||
cachedData,
|
cachedData,
|
||||||
importModuleDynamically: constants.USE_MAIN_CONTEXT_DEFAULT_LOADER,
|
importModuleDynamically: constants.USE_MAIN_CONTEXT_DEFAULT_LOADER,
|
||||||
@@ -37,14 +51,8 @@ const script = new Script(
|
|||||||
|
|
||||||
const { cachedDataRejected } = script;
|
const { cachedDataRejected } = script;
|
||||||
|
|
||||||
if (cachedDataRejected) {
|
|
||||||
console.log('preload cache rejected');
|
|
||||||
} else {
|
|
||||||
console.log('preload cache hit');
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn = script.runInThisContext({
|
const fn = script.runInThisContext({
|
||||||
filename: 'preload.bundle.js',
|
filename,
|
||||||
lineOffset: 0,
|
lineOffset: 0,
|
||||||
columnOffset: 0,
|
columnOffset: 0,
|
||||||
displayErrors: true,
|
displayErrors: true,
|
||||||
@@ -61,3 +69,9 @@ if (process.env.GENERATE_PRELOAD_CACHE) {
|
|||||||
cachedData != null && !cachedDataRejected
|
cachedData != null && !cachedDataRejected
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cachedDataRejected) {
|
||||||
|
console.log('preload cache rejected');
|
||||||
|
} else {
|
||||||
|
console.log('preload cache hit');
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user