Skip to content

Commit f7bfb32

Browse files
committed
allow prob builds with esbuild
1 parent 4e6ead2 commit f7bfb32

File tree

15 files changed

+136
-47
lines changed

15 files changed

+136
-47
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ module.exports = (mainWindow) => {
7474

7575
buildSass();
7676

77-
require('chokidar')
78-
.watch('./styles', { ignored: /[\/\\]\./ })
79-
.on('change', buildSass);
77+
if (devMode) {
78+
require('chokidar')
79+
.watch('./styles', { ignored: /[\/\\]\./ })
80+
.on('change', buildSass);
81+
}
8082
};
8183

8284
const aliases = {

development/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/zsh
22
# copy latest version of electron remote
33
cp -r node_modules/@electron/remote ./static
4-
echo "TODO: prod build of js"
4+
node -e "require('./development/build')()"
55
electron-packager ./static Flex2 --platform=win32 --arch=x64 \
66
--asar --overwrite --package-manager yarn \
77
--win32metadata.CompanyName="Flex 2" \

static/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function createWindow() {
2828
});
2929

3030
if (devMode) {
31-
require('./../development')(mainWindow);
31+
require('./../development/build')(mainWindow);
3232
}
3333
}
3434

static/remote/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2019-2022 Electron contributors
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

static/remote/README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ configure your bundler appropriately to package the code of `@electron/remote`
5252
in the preload script. Of course, [using `@electron/remote` makes the sandbox
5353
much less effective][remote-considered-harmful].
5454

55-
**Note:** `@electron/remote` respects the `enableRemoteModule` WebPreferences
55+
**Note:** In `electron >= 14.0.0`, you must use the new `enable` API to enable the remote module for each desired `WebContents` separately: `require("@electron/remote/main").enable(webContents)`.
56+
57+
In `electron < 14.0.0`, `@electron/remote` respects the `enableRemoteModule` WebPreferences
5658
value. You must pass `{ webPreferences: { enableRemoteModule: true } }` to
5759
the constructor of `BrowserWindow`s that should be granted permission to use
5860
`@electron/remote`.
5961

60-
6162
# API Reference
6263

6364
The `remote` module provides a simple way to do inter-process communication
@@ -85,7 +86,9 @@ of the remote module:
8586
require('@electron/remote/main').initialize()
8687
```
8788

88-
**Note:** The remote module can be disabled for security reasons in the following contexts:
89+
**Note:** In `electron >= 14.0.0` the remote module is disabled by default for any `WebContents` instance and is only enabled for specified `WebContents` after explicitly calling `require("@electron/remote/main").enable(webContents)`.
90+
91+
In `electron < 14.0.0` the remote module can be disabled for security reasons in the following contexts:
8992
- [`BrowserWindow`](browser-window.md) - by setting the `enableRemoteModule` option to `false`.
9093
- [`<webview>`](webview-tag.md) - by setting the `enableremotemodule` attribute to `false`.
9194

@@ -214,8 +217,8 @@ e.g.
214217
```sh
215218
project/
216219
├── main
217-
   ├── foo.js
218-
   └── index.js
220+
├── foo.js
221+
└── index.js
219222
├── package.json
220223
└── renderer
221224
└── index.js
@@ -339,4 +342,4 @@ Custom value can be returned by setting `event.returnValue`.
339342

340343
[rmi]: https://en.wikipedia.org/wiki/Java_remote_method_invocation
341344
[enumerable-properties]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
342-
[remote-considered-harmful]: https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31
345+
[remote-considered-harmful]: https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31

static/remote/dist/src/common/module-names.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ exports.browserModuleNames = [
2929
'powerMonitor',
3030
'powerSaveBlocker',
3131
'protocol',
32+
'pushNotifications',
33+
'safeStorage',
3234
'screen',
3335
'session',
3436
'ShareMenu',
3537
'systemPreferences',
3638
'TopLevelWindow',
3739
'TouchBar',
3840
'Tray',
41+
'utilityProcess',
3942
'View',
4043
'webContents',
4144
'WebContentsView',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { initialize } from './server';
1+
export { initialize, enable } from "./server";
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.initialize = void 0;
3+
exports.enable = exports.initialize = void 0;
44
var server_1 = require("./server");
55
Object.defineProperty(exports, "initialize", { enumerable: true, get: function () { return server_1.initialize; } });
6+
Object.defineProperty(exports, "enable", { enumerable: true, get: function () { return server_1.enable; } });
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import { WebContents } from 'electron';
2-
export declare const isRemoteModuleEnabled: (contents: WebContents) => any;
2+
export declare const isRemoteModuleEnabled: (contents: WebContents) => boolean | undefined;
3+
export declare function enable(contents: WebContents): void;
34
export declare function initialize(): void;

static/remote/dist/src/main/server.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
return (mod && mod.__esModule) ? mod : { "default": mod };
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
6-
exports.initialize = exports.isRemoteModuleEnabled = void 0;
6+
exports.initialize = exports.enable = exports.isRemoteModuleEnabled = void 0;
77
const events_1 = require("events");
88
const objects_registry_1 = __importDefault(require("./objects-registry"));
99
const type_utils_1 = require("../common/type-utils");
1010
const electron_1 = require("electron");
1111
const get_electron_binding_1 = require("../common/get-electron-binding");
12+
const { Promise } = global;
1213
const v8Util = get_electron_binding_1.getElectronBinding('v8_util');
14+
const hasWebPrefsRemoteModuleAPI = (() => {
15+
var _a, _b;
16+
const electronVersion = Number((_b = (_a = process.versions.electron) === null || _a === void 0 ? void 0 : _a.split(".")) === null || _b === void 0 ? void 0 : _b[0]);
17+
return Number.isNaN(electronVersion) || electronVersion < 14;
18+
})();
1319
// The internal properties of Function.
1420
const FUNCTION_PROPERTIES = [
1521
'length', 'name', 'arguments', 'caller', 'prototype'
@@ -293,19 +299,23 @@ const isRemoteModuleEnabledImpl = function (contents) {
293299
};
294300
const isRemoteModuleEnabledCache = new WeakMap();
295301
const isRemoteModuleEnabled = function (contents) {
296-
if (!isRemoteModuleEnabledCache.has(contents)) {
302+
if (hasWebPrefsRemoteModuleAPI && !isRemoteModuleEnabledCache.has(contents)) {
297303
isRemoteModuleEnabledCache.set(contents, isRemoteModuleEnabledImpl(contents));
298304
}
299305
return isRemoteModuleEnabledCache.get(contents);
300306
};
301307
exports.isRemoteModuleEnabled = isRemoteModuleEnabled;
308+
function enable(contents) {
309+
isRemoteModuleEnabledCache.set(contents, true);
310+
}
311+
exports.enable = enable;
302312
const handleRemoteCommand = function (channel, handler) {
303313
electron_1.ipcMain.on(channel, (event, contextId, ...args) => {
304314
let returnValue;
305315
if (!exports.isRemoteModuleEnabled(event.sender)) {
306316
event.returnValue = {
307317
type: 'exception',
308-
value: valueToMeta(event.sender, contextId, new Error('@electron/remote is disabled for this WebContents. Set {enableRemoteModule: true} in WebPreferences to enable it.'))
318+
value: valueToMeta(event.sender, contextId, new Error('@electron/remote is disabled for this WebContents. Call require("@electron/remote/main").enable(webContents) to enable it.'))
309319
};
310320
return;
311321
}
@@ -337,7 +347,7 @@ const logStack = function (contents, code, stack) {
337347
let initialized = false;
338348
function initialize() {
339349
if (initialized)
340-
throw new Error('electron-remote has already been initialized');
350+
throw new Error('@electron/remote has already been initialized');
341351
initialized = true;
342352
handleRemoteCommand("REMOTE_BROWSER_WRONG_CONTEXT_ERROR" /* BROWSER_WRONG_CONTEXT_ERROR */, function (event, contextId, passedContextId, id) {
343353
const objectId = [passedContextId, id];
@@ -431,7 +441,8 @@ function initialize() {
431441
return valueToMeta(event.sender, contextId, func(...args), true);
432442
}
433443
catch (error) {
434-
const err = new Error(`Could not call remote function '${func.name || 'anonymous'}'. Check that the function signature is correct. Underlying error: ${error.message}\nUnderlying stack: ${error.stack}\n`);
444+
const err = new Error(`Could not call remote function '${func.name || "anonymous"}'. Check that the function signature is correct. Underlying error: ${error}\n` +
445+
(error instanceof Error ? `Underlying stack: ${error.stack}\n` : ""));
435446
err.cause = error;
436447
throw err;
437448
}
@@ -454,7 +465,8 @@ function initialize() {
454465
return valueToMeta(event.sender, contextId, object[method](...args), true);
455466
}
456467
catch (error) {
457-
const err = new Error(`Could not call remote method '${method}'. Check that the method signature is correct. Underlying error: ${error.message}\nUnderlying stack: ${error.stack}\n`);
468+
const err = new Error(`Could not call remote method '${method}'. Check that the method signature is correct. Underlying error: ${error}` +
469+
(error instanceof Error ? `Underlying stack: ${error.stack}\n` : ""));
458470
err.cause = error;
459471
throw err;
460472
}

0 commit comments

Comments
 (0)