build: drop @types/webpack-env in favor of webpack/module types (#48047)

* build: drop @types/webpack-env in favor of webpack/module types

* chore: improve type when assigning to global.require
This commit is contained in:
David Sanders 2025-08-12 05:10:30 -07:00 committed by GitHub
commit 116c24aaf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 24 additions and 25 deletions

View file

@ -143,7 +143,9 @@ if ((globalThis.process || binding.process).argv.includes("--profile-electron-in
transpileOnly: onlyPrintingGraph, transpileOnly: onlyPrintingGraph,
ignoreDiagnostics: [ ignoreDiagnostics: [
// File '{0}' is not under 'rootDir' '{1}'. // File '{0}' is not under 'rootDir' '{1}'.
6059 6059,
// Private field '{0}' must be declared in an enclosing class.
1111
] ]
} }
}] }]

View file

@ -204,7 +204,7 @@ delete process.appCodeLoaded;
if (packagePath) { if (packagePath) {
// Finally load app's main.js and transfer control to C++. // Finally load app's main.js and transfer control to C++.
if ((packageJson.type === 'module' && !mainStartupScript.endsWith('.cjs')) || mainStartupScript.endsWith('.mjs')) { if ((packageJson.type === 'module' && !mainStartupScript.endsWith('.cjs')) || mainStartupScript.endsWith('.mjs')) {
const { runEntryPointWithESMLoader } = __non_webpack_require__('internal/modules/run_main'); const { runEntryPointWithESMLoader } = __non_webpack_require__('internal/modules/run_main') as typeof import('@node/lib/internal/modules/run_main');
const main = (require('url') as typeof url).pathToFileURL(path.join(packagePath, mainStartupScript)); const main = (require('url') as typeof url).pathToFileURL(path.join(packagePath, mainStartupScript));
runEntryPointWithESMLoader(async (cascadedLoader: any) => { runEntryPointWithESMLoader(async (cascadedLoader: any) => {
try { try {

View file

@ -52,20 +52,20 @@ const {
getValidatedPath, getValidatedPath,
getOptions, getOptions,
getDirent getDirent
} = __non_webpack_require__('internal/fs/utils'); } = __non_webpack_require__('internal/fs/utils') as typeof import('@node/lib/internal/fs/utils');
const { const {
assignFunctionName assignFunctionName
} = __non_webpack_require__('internal/util'); } = __non_webpack_require__('internal/util') as typeof import('@node/lib/internal/util');
const { const {
validateBoolean, validateBoolean,
validateFunction validateFunction
} = __non_webpack_require__('internal/validators'); } = __non_webpack_require__('internal/validators') as typeof import('@node/lib/internal/validators');
// In the renderer node internals use the node global URL but we do not set that to be // In the renderer node internals use the node global URL but we do not set that to be
// the global URL instance. We need to do instanceof checks against the internal URL impl // the global URL instance. We need to do instanceof checks against the internal URL impl
const { URL: NodeURL } = __non_webpack_require__('internal/url'); const { URL: NodeURL } = __non_webpack_require__('internal/url') as typeof import('@node/lib/internal/url');
// Separate asar package's path from full path. // Separate asar package's path from full path.
const splitPath = (archivePathOrBuffer: string | Buffer | URL) => { const splitPath = (archivePathOrBuffer: string | Buffer | URL) => {
@ -745,8 +745,8 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
const stat = internalBinding('fs').internalModuleStat(resultPath); const stat = internalBinding('fs').internalModuleStat(resultPath);
context.readdirResults.push(dirent); context.readdirResults.push(dirent);
if (dirent.isDirectory() || stat === 1) { if (dirent!.isDirectory() || stat === 1) {
context.pathsQueue.push(path.join(dirent.path, dirent.name)); context.pathsQueue.push(path.join(dirent!.path, dirent!.name));
} }
} }
} }
@ -857,13 +857,13 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
const { readdir } = fs; const { readdir } = fs;
fs.readdir = function (pathArgument: string, options: ReaddirOptions, callback: ReaddirCallback) { fs.readdir = function (pathArgument: string, options: ReaddirOptions, callback: ReaddirCallback) {
callback = typeof options === 'function' ? options : callback; callback = typeof options === 'function' ? options : callback;
validateFunction(callback, 'callback'); validateFunction(callback, 'callback')!;
options = getOptions(options); options = getOptions(options);
pathArgument = getValidatedPath(pathArgument); pathArgument = getValidatedPath(pathArgument);
if (options?.recursive != null) { if (options?.recursive != null) {
validateBoolean(options?.recursive, 'options.recursive'); validateBoolean(options?.recursive, 'options.recursive')!;
} }
if (options?.recursive) { if (options?.recursive) {
@ -914,7 +914,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
pathArgument = getValidatedPath(pathArgument); pathArgument = getValidatedPath(pathArgument);
if (options?.recursive != null) { if (options?.recursive != null) {
validateBoolean(options?.recursive, 'options.recursive'); validateBoolean(options?.recursive, 'options.recursive')!;
} }
if (options?.recursive) { if (options?.recursive) {
@ -957,7 +957,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
pathArgument = getValidatedPath(pathArgument); pathArgument = getValidatedPath(pathArgument);
if (options?.recursive != null) { if (options?.recursive != null) {
validateBoolean(options?.recursive, 'options.recursive'); validateBoolean(options?.recursive, 'options.recursive')!;
} }
if (options?.recursive) { if (options?.recursive) {

View file

@ -65,9 +65,9 @@ require('@electron/internal/renderer/common-init');
if (nodeIntegration) { if (nodeIntegration) {
// Export node bindings to global. // Export node bindings to global.
const { makeRequireFunction } = __non_webpack_require__('internal/modules/helpers'); const { makeRequireFunction } = __non_webpack_require__('internal/modules/helpers') as typeof import('@node/lib/internal/modules/helpers');
global.module = new Module('electron/js2c/renderer_init'); global.module = new Module('electron/js2c/renderer_init');
global.require = makeRequireFunction(global.module); global.require = makeRequireFunction(global.module) as NodeRequire;
// Set the __filename to the path of html file if it is file: protocol. // Set the __filename to the path of html file if it is file: protocol.
if (window.location.protocol === 'file:') { if (window.location.protocol === 'file:') {
@ -150,7 +150,7 @@ if (cjsPreloads.length) {
} }
} }
if (esmPreloads.length) { if (esmPreloads.length) {
const { runEntryPointWithESMLoader } = __non_webpack_require__('internal/modules/run_main'); const { runEntryPointWithESMLoader } = __non_webpack_require__('internal/modules/run_main') as typeof import('@node/lib/internal/modules/run_main');
runEntryPointWithESMLoader(async (cascadedLoader: any) => { runEntryPointWithESMLoader(async (cascadedLoader: any) => {
// Load the preload scripts. // Load the preload scripts.

View file

@ -36,7 +36,7 @@ parentPort.on('removeListener', (name: string) => {
}); });
// Finally load entry script. // Finally load entry script.
const { runEntryPointWithESMLoader } = __non_webpack_require__('internal/modules/run_main'); const { runEntryPointWithESMLoader } = __non_webpack_require__('internal/modules/run_main') as typeof import('@node/lib/internal/modules/run_main');
const mainEntry = pathToFileURL(entryScript); const mainEntry = pathToFileURL(entryScript);
runEntryPointWithESMLoader(async (cascadedLoader: any) => { runEntryPointWithESMLoader(async (cascadedLoader: any) => {

View file

@ -13,9 +13,9 @@ require('@electron/internal/common/init');
const { hasSwitch, getSwitchValue } = process._linkedBinding('electron_common_command_line'); const { hasSwitch, getSwitchValue } = process._linkedBinding('electron_common_command_line');
// Export node bindings to global. // Export node bindings to global.
const { makeRequireFunction } = __non_webpack_require__('internal/modules/helpers'); const { makeRequireFunction } = __non_webpack_require__('internal/modules/helpers') as typeof import('@node/lib/internal/modules/helpers');
global.module = new Module('electron/js2c/worker_init'); global.module = new Module('electron/js2c/worker_init');
global.require = makeRequireFunction(global.module); global.require = makeRequireFunction(global.module) as NodeRequire;
// See WebWorkerObserver::WorkerScriptReadyForEvaluation. // See WebWorkerObserver::WorkerScriptReadyForEvaluation.
if ((globalThis as any).blinkfetch) { if ((globalThis as any).blinkfetch) {

View file

@ -18,7 +18,6 @@
"@types/semver": "^7.5.8", "@types/semver": "^7.5.8",
"@types/stream-json": "^1.7.7", "@types/stream-json": "^1.7.7",
"@types/temp": "^0.9.4", "@types/temp": "^0.9.4",
"@types/webpack-env": "^1.18.5",
"@typescript-eslint/eslint-plugin": "^8.7.0", "@typescript-eslint/eslint-plugin": "^8.7.0",
"@typescript-eslint/parser": "^8.7.0", "@typescript-eslint/parser": "^8.7.0",
"buffer": "^6.0.3", "buffer": "^6.0.3",

View file

@ -16,7 +16,8 @@
"outDir": "ts-gen", "outDir": "ts-gen",
"typeRoots" : ["./node_modules/@types", "./spec/node_modules/@types"], "typeRoots" : ["./node_modules/@types", "./spec/node_modules/@types"],
"paths": { "paths": {
"@electron/internal/*": ["lib/*"] "@electron/internal/*": ["lib/*"],
"@node/*": ["../third_party/electron_node/*"]
} }
}, },
"exclude": [ "exclude": [

View file

@ -1,3 +1,5 @@
/// <reference types="webpack/module" />
declare const BUILDFLAG: (flag: boolean) => boolean; declare const BUILDFLAG: (flag: boolean) => boolean;
declare namespace NodeJS { declare namespace NodeJS {

View file

@ -1058,11 +1058,6 @@
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-3.0.2.tgz#6dd61e43ef60b34086287f83683a5c1b2dc53d20" resolved "https://registry.yarnpkg.com/@types/unist/-/unist-3.0.2.tgz#6dd61e43ef60b34086287f83683a5c1b2dc53d20"
integrity sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ== integrity sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==
"@types/webpack-env@^1.18.5":
version "1.18.5"
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.18.5.tgz#eccda0b04fe024bed505881e2e532f9c119169bf"
integrity sha512-wz7kjjRRj8/Lty4B+Kr0LN6Ypc/3SymeCCGSbaXp2leH0ZVg/PriNiOwNj4bD4uphI7A8NXS4b6Gl373sfO5mA==
"@types/yauzl@^2.9.1": "@types/yauzl@^2.9.1":
version "2.10.0" version "2.10.0"
resolved "https://registry.yarnpkg.com/@types/yauzl/-/yauzl-2.10.0.tgz#b3248295276cf8c6f153ebe6a9aba0c988cb2599" resolved "https://registry.yarnpkg.com/@types/yauzl/-/yauzl-2.10.0.tgz#b3248295276cf8c6f153ebe6a9aba0c988cb2599"