Skip to content

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

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dsanders11
Copy link
Member

@dsanders11 dsanders11 commented Jul 17, 2025

Description of Change

This change was prompted by #47621 which is trying to bring in the latest @types/webpack-env and causing TS build errors due to conflicting types. Webpack added module.d.ts in v5.62.0, which serves the same purpose as @types/webpack-env, so this PR switches to it and drops @types/webpack-env.

This PR also adds a path mapping in tsconfig.json to map @node/* to ../third_party/electron_node and types the requires of Node.js modules so that we get accurate types for them, which required tweaking our existing types a bit.

Checklist

  • PR description included and stakeholders cc'd

Release Notes

Notes: none

@dsanders11 dsanders11 added target/35-x-y PR should also be added to the "35-x-y" branch. target/36-x-y PR should also be added to the "36-x-y" branch. target/37-x-y PR should also be added to the "37-x-y" branch. target/38-x-y PR should also be added to the "38-x-y" branch. labels Jul 17, 2025
@@ -150,7 +150,7 @@ if (cjsPreloads.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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not map this magically somehow in TS, declaring the type of non_webpack_require better or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I'm aware of. If we could, it would also be a bit tricky because it would be mapping internal/modules/run_main to ../third_party/electron_node/lib/internal/modules/run_main implicitly, which would be coupling __non_webpack_require__ to just requiring modules from ../third_party/electron_node which probably isn't something we want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think defining it as internal/* mapping to ../third_party/electron_node/lib/internal/$1 is fine if that's possible?

@dsanders11 dsanders11 force-pushed the build/drop-types-webpack-env branch from 0554134 to ad0d440 Compare July 17, 2025 16:34
@dsanders11 dsanders11 marked this pull request as ready for review July 17, 2025 17:26
@@ -857,13 +857,13 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
const { readdir } = fs;
fs.readdir = function (pathArgument: string, options: ReaddirOptions, callback: ReaddirCallback) {
callback = typeof options === 'function' ? options : callback;
validateFunction(callback, 'callback');
validateFunction(callback, 'callback')!;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are necessary because TS doesn't like the typings for these validate* functions from Node because you can't use asserts x is type syntax with arrow functions, see microsoft/TypeScript#34523. There's workarounds but the typings in Node are being done via JSDoc and not sure a workaround can be done in that particular case.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trips on at least this line from Node - figured it was easier to dd an ignore than try to patch it or otherwise may tsc happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/none target/35-x-y PR should also be added to the "35-x-y" branch. target/36-x-y PR should also be added to the "36-x-y" branch. target/37-x-y PR should also be added to the "37-x-y" branch. target/38-x-y PR should also be added to the "38-x-y" branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy