Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: self.module.paths not working in web workers (#30014)
* fix: global.module.paths in workers * spec: add a regression test Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
- Loading branch information
1 parent
d27adae
commit a32c399
Showing
7 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<h1>Hello World!</h1> | ||
<script src="./renderer.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Modules to control application life and create native browser window | ||
const { app, BrowserWindow, ipcMain } = require('electron'); | ||
const path = require('path'); | ||
|
||
function createWindow () { | ||
const mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
show: false, | ||
webPreferences: { | ||
nodeIntegration: true, | ||
nodeIntegrationInWorker: true, | ||
contextIsolation: false | ||
} | ||
}); | ||
|
||
mainWindow.loadFile('index.html'); | ||
} | ||
|
||
ipcMain.handle('module-paths', (e, success) => { | ||
process.exit(success ? 0 : 1); | ||
}); | ||
|
||
app.whenReady().then(() => { | ||
createWindow(); | ||
|
||
app.on('activate', function () { | ||
if (BrowserWindow.getAllWindows().length === 0) createWindow(); | ||
}); | ||
}); | ||
|
||
app.on('window-all-closed', function () { | ||
if (process.platform !== 'darwin') app.quit(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "electron-test-self-module-paths", | ||
"main": "main.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { ipcRenderer } = require('electron'); | ||
|
||
const worker = new Worker('worker.js'); | ||
|
||
worker.onmessage = (event) => { | ||
const workerPaths = event.data.sort().toString(); | ||
const rendererPaths = self.module.paths.sort().toString(); | ||
const validModulePaths = workerPaths === rendererPaths && workerPaths !== 0; | ||
|
||
ipcRenderer.invoke('module-paths', validModulePaths); | ||
worker.terminate(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
self.postMessage(self.module.paths); |