refactor: use node scheme imports in spec (#38487)

Co-authored-by: Milan Burda <miburda@microsoft.com>
This commit is contained in:
Milan Burda 2023-06-15 16:42:27 +02:00 committed by GitHub
parent bf1ba4a857
commit d78f37ec8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
105 changed files with 533 additions and 352 deletions

View file

@ -2,7 +2,7 @@
<body>
<script type="text/javascript" charset="utf-8">
window.addEventListener('unload', function (e) {
require('fs').writeFileSync(__dirname + '/close', 'close');
require('node:fs').writeFileSync(__dirname + '/close', 'close');
}, false);
window.onload = () => window.close();
</script>

View file

@ -1,5 +1,5 @@
const { app, BrowserWindow } = require('electron');
const path = require('path');
const path = require('node:path');
let win;
app.whenReady().then(function () {

View file

@ -1,6 +1,6 @@
const { app, BrowserWindow, ipcMain } = require('electron');
const net = require('net');
const path = require('path');
const net = require('node:net');
const path = require('node:path');
process.on('uncaughtException', () => {
app.exit(1);

View file

@ -1,5 +1,5 @@
const { app } = require('electron');
const net = require('net');
const net = require('node:net');
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch';

View file

@ -1,6 +1,6 @@
const { app, safeStorage, ipcMain } = require('electron');
const { promises: fs } = require('fs');
const path = require('path');
const { promises: fs } = require('node:fs');
const path = require('node:path');
const pathToEncryptedString = path.resolve(__dirname, '..', 'encrypted.txt');
const readFile = fs.readFile;

View file

@ -1,6 +1,6 @@
const { app, safeStorage, ipcMain } = require('electron');
const { promises: fs } = require('fs');
const path = require('path');
const { promises: fs } = require('node:fs');
const path = require('node:path');
const pathToEncryptedString = path.resolve(__dirname, '..', 'encrypted.txt');
const writeFile = fs.writeFile;

View file

@ -1,6 +1,6 @@
const { app } = require('electron');
const fs = require('fs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
// non-existent user data folder should not break requestSingleInstanceLock()
// ref: https://github.com/electron/electron/issues/33547

View file

@ -2,7 +2,7 @@
<body>
<script type="text/javascript" charset="utf-8">
window.addEventListener('unload', function (e) {
require('fs').writeFileSync(__dirname + '/unload', 'unload');
require('node:fs').writeFileSync(__dirname + '/unload', 'unload');
}, false);
</script>
</body>

View file

@ -1,5 +1,5 @@
const { app, utilityProcess } = require('electron');
const path = require('path');
const path = require('node:path');
app.whenReady().then(() => {
let child = null;

View file

@ -1,5 +1,5 @@
const { app, utilityProcess } = require('electron');
const path = require('path');
const path = require('node:path');
app.whenReady().then(() => {
const payload = app.commandLine.getSwitchValue('payload');

View file

@ -1,5 +1,5 @@
const { app, utilityProcess } = require('electron');
const path = require('path');
const path = require('node:path');
app.whenReady().then(() => {
const payload = app.commandLine.getSwitchValue('payload');

View file

@ -1,2 +1,2 @@
const result = require('child_process').execSync('sudo --help');
const result = require('node:child_process').execSync('sudo --help');
process.parentPort.postMessage(result);

View file

@ -1,5 +1,5 @@
const path = require('path');
const childProcess = require('child_process');
const path = require('node:path');
const childProcess = require('node:child_process');
const crashPath = path.join(__dirname, 'node-crash.js');
const child = childProcess.fork(crashPath, { silent: true });

View file

@ -1,6 +1,6 @@
const { app, BrowserWindow, crashReporter } = require('electron');
const path = require('path');
const childProcess = require('child_process');
const path = require('node:path');
const childProcess = require('node:child_process');
app.setVersion('0.1.0');

View file

@ -1,5 +1,5 @@
const path = require('path');
const childProcess = require('child_process');
const path = require('node:path');
const childProcess = require('node:child_process');
process.on('message', function () {
process.send(process.argv);

View file

@ -1,5 +1,5 @@
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const path = require('node:path');
async function createWindow () {
const mainWindow = new BrowserWindow({

View file

@ -3,7 +3,7 @@ const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('api', {
ipcRenderer,
run: async () => {
const { promises: fs } = require('fs');
const { promises: fs } = require('node:fs');
for (let i = 0; i < 10; i++) {
const list = await fs.readdir('.', { withFileTypes: true });
for (const file of list) {

View file

@ -1,5 +1,5 @@
const { app, BrowserWindow } = require('electron');
const path = require('path');
const path = require('node:path');
async function createWindow () {
const mainWindow = new BrowserWindow({

View file

@ -1,8 +1,8 @@
const { app } = require('electron');
const http = require('http');
const v8 = require('v8');
const http = require('node:http');
const v8 = require('node:v8');
// eslint-disable-next-line camelcase
const promises_1 = require('timers/promises');
const promises_1 = require('node:timers/promises');
if (app.commandLine.hasSwitch('boot-eval')) {
// eslint-disable-next-line no-eval

View file

@ -1,6 +1,6 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const path = require('node:path');
function createWindow () {
const mainWindow = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const http = require('http');
const http = require('node:http');
const { app, ipcMain, BrowserWindow } = require('electron');
if (process.argv.length > 3) {

View file

@ -1,5 +1,5 @@
const { app, BrowserWindow } = require('electron');
const path = require('path');
const path = require('node:path');
app.whenReady().then(() => {
const w = new BrowserWindow({

View file

@ -1,5 +1,5 @@
const fs = require('fs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
process.on('uncaughtException', (err) => {
console.error(err);

View file

@ -1,5 +1,5 @@
const fs = require('fs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
process.on('uncaughtException', (err) => {
console.error(err);

View file

@ -1,7 +1,7 @@
<html>
<body>
<script>
const fs = require('fs');
const fs = require('node:fs');
const { ipcRenderer } = require('electron');
async function readFile(path) {

View file

@ -1,5 +1,5 @@
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const path = require('node:path');
app.whenReady().then(() => {
let reloadCount = 0;

View file

@ -2,8 +2,8 @@
<body>
<iframe id="mainframe"></iframe>
<script>
const net = require('net');
const path = require('path');
const net = require('node:net');
const path = require('node:path');
document.getElementById("mainframe").src="./page2.html";

View file

@ -1,6 +1,6 @@
const { app, BrowserWindow } = require('electron');
const net = require('net');
const path = require('path');
const net = require('node:net');
const path = require('node:path');
function createWindow () {
const mainWindow = new BrowserWindow({

View file

@ -1,6 +1,6 @@
const { app, ipcMain, BrowserWindow } = require('electron');
const path = require('path');
const http = require('http');
const path = require('node:path');
const http = require('node:http');
function createWindow () {
const mainWindow = new BrowserWindow({

View file

@ -1,5 +1,5 @@
const { app, BrowserWindow } = require('electron');
const path = require('path');
const path = require('node:path');
app.whenReady().then(() => {
const win = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const fs = require('fs');
const fs = require('node:fs');
process.on('message', function (file) {
process.send(fs.readFileSync(file).toString());
});

View file

@ -1,4 +1,4 @@
const net = require('net');
const net = require('node:net');
const server = net.createServer(function () {});
server.listen(process.argv[2]);
process.exit(0);

View file

@ -1,10 +1,10 @@
const path = require('path');
const path = require('node:path');
process.on('uncaughtException', function (error) {
process.send(error.stack);
});
const child = require('child_process').fork(path.join(__dirname, '/ping.js'));
const child = require('node:child_process').fork(path.join(__dirname, '/ping.js'));
process.on('message', function (msg) {
child.send(msg);
});

View file

@ -1,6 +1,6 @@
const inspector = require('inspector');
const path = require('path');
const { pathToFileURL } = require('url');
const inspector = require('node:inspector');
const path = require('node:path');
const { pathToFileURL } = require('node:url');
// This test case will set a breakpoint 4 lines below
function debuggedFunction () {

View file

@ -1,5 +1,5 @@
const fs = require('fs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const stats = fs.statSync(path.join(__dirname, '..', 'test.asar', 'a.asar'));

View file

@ -1,5 +1,5 @@
(function () {
const { EventEmitter } = require('events');
const { EventEmitter } = require('node:events');
const emitter = new EventEmitter();
const rendererEventEmitterProperties = [];
let currentObj = emitter;

View file

@ -1,5 +1,5 @@
(function () {
const { setImmediate } = require('timers');
const { setImmediate } = require('node:timers');
const { ipcRenderer } = require('electron');
window.ipcRenderer = ipcRenderer;
window.setImmediate = setImmediate;
@ -34,8 +34,11 @@
cpuUsage: invoke(() => process.getCPUUsage()),
ioCounters: invoke(() => process.getIOCounters()),
uptime: invoke(() => process.uptime()),
// eslint-disable-next-line unicorn/prefer-node-protocol
nodeEvents: invoke(() => require('events') === require('node:events')),
// eslint-disable-next-line unicorn/prefer-node-protocol
nodeTimers: invoke(() => require('timers') === require('node:timers')),
// eslint-disable-next-line unicorn/prefer-node-protocol
nodeUrl: invoke(() => require('url') === require('node:url')),
env: process.env,
execPath: process.execPath,

View file

@ -5,7 +5,7 @@
// that does include proprietary codecs.
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const path = require('node:path');
const MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
const FIVE_MINUTES = 5 * 60 * 1000;

View file

@ -1,7 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
var path = require('path');
var path = require('node:path');
console.log(typeof require(path.join(__dirname, '..', '..', 'node_modules', '@electron-ci', 'echo')));
</script>
</body>

View file

@ -1,7 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
require('fs').readdir(process.cwd(), () => {
require('node:fs').readdir(process.cwd(), () => {
require('electron').ipcRenderer.send('async-node-api-done');
})
</script>

View file

@ -1,7 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
const url = require('url')
const url = require('node:url')
function tryPostMessage(...args) {
try {
window.opener.postMessage(...args)

View file

@ -2,9 +2,9 @@
// using a new version of the asar package
const asar = require('@electron/asar');
const fs = require('fs');
const os = require('os');
const path = require('path');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const archives = [];
for (const child of fs.readdirSync(__dirname)) {