Skip to content

Commit 65d5f46

Browse files
debug
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
1 parent 5a7393a commit 65d5f46

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

code/src/vs/workbench/api/node/extensionHostProcess.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,31 @@ const args = minimist(process.argv.slice(2), {
8181
(function () {
8282
const Module = require('module');
8383
const originalLoad = Module._load;
84+
let lastModuleRequest: string | undefined;
85+
let lastModuleParent: string | undefined;
86+
87+
Module._load = function (request: string, parent: { id?: string; filename?: string } | undefined) {
88+
const prevRequest = lastModuleRequest;
89+
const prevParent = lastModuleParent;
90+
lastModuleRequest = request;
91+
lastModuleParent = parent?.filename ?? parent?.id;
8492

85-
Module._load = function (request: string) {
8693
if (request === 'natives') {
8794
throw new Error('Either the extension or an NPM dependency is using the [unsupported "natives" node module](https://go.microsoft.com/fwlink/?linkid=871887).');
8895
}
8996

90-
return originalLoad.apply(this, arguments);
97+
try {
98+
return originalLoad.apply(this, arguments);
99+
} finally {
100+
lastModuleRequest = prevRequest;
101+
lastModuleParent = prevParent;
102+
}
91103
};
104+
105+
(globalThis as unknown as { __vscodePendingMigrationLastModule?: () => { request?: string; parent?: string } }).__vscodePendingMigrationLastModule = () => ({
106+
request: lastModuleRequest,
107+
parent: lastModuleParent
108+
});
92109
})();
93110

94111
// custom process.exit logic...
@@ -140,12 +157,31 @@ function patchProcess(allowExit: boolean) {
140157
// NodeJS since v21 defines navigator as a global object. This will likely surprise many extensions and potentially break them
141158
// because `navigator` has historically often been used to check if running in a browser (vs running inside NodeJS)
142159
if (!args.supportGlobalNavigator) {
160+
let navigatorAccessCount = 0;
161+
let hasSuppressedNavigatorLogs = false;
162+
const maxNavigatorLogs = 25;
143163
Object.defineProperty(globalThis, 'navigator', {
144164
get: () => {
145165
onUnexpectedExternalError(new PendingMigrationError('navigator is now a global in nodejs, please see https://aka.ms/vscode-extensions/navigator for additional info on this error.'));
166+
navigatorAccessCount++;
167+
if (navigatorAccessCount <= maxNavigatorLogs) {
168+
const moduleTracker = (globalThis as unknown as { __vscodePendingMigrationLastModule?: () => { request?: string; parent?: string } }).__vscodePendingMigrationLastModule;
169+
const moduleContext = moduleTracker?.() ?? {};
170+
const stack = new Error().stack?.split('\n').slice(2, 10).join('\n');
171+
console.error(`[pending-migration][navigator] access #${navigatorAccessCount}; lastModule="${moduleContext.request ?? 'unknown'}"; parent="${moduleContext.parent ?? 'unknown'}"`);
172+
if (stack) {
173+
console.error(`[pending-migration][navigator] stack:\n${stack}`);
174+
}
175+
} else if (!hasSuppressedNavigatorLogs) {
176+
hasSuppressedNavigatorLogs = true;
177+
console.error(`[pending-migration][navigator] additional accesses suppressed after ${maxNavigatorLogs} logs`);
178+
}
146179
return undefined;
147180
}
148181
});
182+
console.error('[pending-migration][navigator] migration guard active; detailed accesses will be logged');
183+
} else {
184+
console.error('[pending-migration][navigator] supportGlobalNavigator=true; PendingMigrationError disabled');
149185
}
150186

151187

0 commit comments

Comments
 (0)