-
-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(plugin-webpack): fix incorrect PRELOAD_WEBPACK_ENTRY. #635
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, can you add a test for this?
@@ -164,8 +164,8 @@ Your packaged app may be larger than expected if you dont ignore everything othe | |||
if (entryPoint.preload) { | |||
defines[`${entryPoint.name.toUpperCase().replace(/ /g, '_')}_PRELOAD_WEBPACK_ENTRY`] = | |||
this.isProd | |||
? `\`file://\$\{require('path').resolve(__dirname, '../renderer', '${entryPoint.name}', 'preload.js')\}\`` | |||
: `'${path.resolve(this.baseDir, 'renderer', entryPoint.name, 'preload.js')}'`; | |||
? `\`\$\{require('path').resolve(__dirname, '../renderer', '${entryPoint.name}', 'preload.js')\}\`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't this part of the ternary expression need the escaping logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't need it, because the result is an expression. (Keep in mind, the webpackDefine plugin does not define the variable, it just replaces MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY in the source with whatever string it's given)
In production
{
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY
}
will get transformed to
{
preload: require('path').resolve(__dirname, '../renderer', 'MAIN_WINDOW', 'preload.js')
}
Whereas in development, the result is a string and needs to get properly escaped since
MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY = `'${path.resolve(this.baseDir, 'renderer', entryPoint.name, 'preload.js')}'`
results in
{
preload: '\basedir\renderer\main\preload.js'
}
However, it has to be
{
preload: '\\basedir\\renderer\\main\\preload.js'
}
Sure, I'll try. A unit test, or E2E and actually spawn electron browserWindow with preload? |
A unit test, please. |
@malept, a test added |
BrowserWindow preload parameter should be an absolute path. Remove prepending 'file://' from prod value of PRELOAD_WEBPACK_ENTRY. Properly escape backslashes in the dev value of PRELOAD_WEBPACK_ENTRY to prevent failure on Windows.
Sorry, rebased and squashed, because I used my company email address by mistake in the original commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use String.raw()
anywhere where there's a string literal with backslashes.
Other than that, I defer to @MarshallOfSound.
@MarshallOfSound, any chance to merge this soon, please, as this bug is blocking the use of preload scripts on Windows? |
BrowserWindow preload parameter should be an absolute path. Remove prepending 'file://' from prod
value of PRELOAD_WEBPACK_ENTRY.
Properly escape backslashes in the dev value of PRELOAD_WEBPACK_ENTRY to prevent failure on Windows.
These tests are failing, but are unrelated: