| // Copyright 2026 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| import { registerHooks } from 'node:module'; |
| import * as path from 'node:path'; |
| import { pathToFileURL } from 'node:url'; |
| |
| const devtoolsRoot = path.dirname(import.meta.dirname); |
| const packageJsonURL = pathToFileURL(path.join(devtoolsRoot, 'package.json')).href; |
| |
| registerHooks({ |
| resolve(specifier, context, nextResolve) { |
| try { |
| return nextResolve(specifier, context); |
| } catch (err) { |
| if (!specifier.startsWith('.') && !specifier.startsWith('/') && !specifier.startsWith('node:')) { |
| return nextResolve(specifier, { |
| ...context, |
| parentURL: packageJsonURL, |
| }); |
| } |
| throw err; |
| } |
| }, |
| }); |