Skip to content

Commit 8b2bc26

Browse files
test: skip electron-main-no-esm on old node and cover node-commonjs require branch
The electron-main-no-esm bundle imports 'createRequire' from 'module', which older Node versions cannot link in the vm ESM runner, so gate it behind supportsRequireInModule. Require the electron built-ins in the node-commonjs config so the require (commonjs) externals branch is executed.
1 parent df09c29 commit 8b2bc26

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const electron = require("electron");
2+
const app = require("app");
3+
const shell = require("shell");
4+
5+
it("should externalize required electron built-in modules as node-commonjs", () => {
6+
expect(electron.marker).toBe("electron");
7+
expect(app.marker).toBe("app");
8+
expect(shell.marker).toBe("shell");
9+
});

test/configCases/target/electron-main-module/webpack.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = [
55
{
66
// `module-import` path: electron built-ins are imported as ESM
77
target: "electron-main",
8+
entry: "./index.js",
89
output: {
910
module: true
1011
},
@@ -19,6 +20,7 @@ module.exports = [
1920
{
2021
// `node-commonjs` path: electron built-ins are required
2122
target: "electron-main",
23+
entry: "./require.js",
2224
optimization: {
2325
concatenateModules: false,
2426
minimize: false
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
const supportsRequireInModule = require("../../../helpers/supportsRequireInModule");
4+
5+
// `output.module` here emits `import { createRequire } from "module"`,
6+
// which older Node versions can't link in the vm ESM runner
7+
module.exports = () => supportsRequireInModule();

0 commit comments

Comments
 (0)