From 9381b1f3f5ebefcd4de08e3d48a63f2e70f35f14 Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Thu, 27 Aug 2026 21:05:40 -0400 Subject: [PATCH] fix(windows): resolve staged headers from esm --- config/scripts/build-windows-process-tree-relay-addon.mjs | 5 ++++- config/scripts/windows-process-tree-gyp-path.test.mjs | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config/scripts/build-windows-process-tree-relay-addon.mjs b/config/scripts/build-windows-process-tree-relay-addon.mjs index b3b0720bf4f..c294687a295 100644 --- a/config/scripts/build-windows-process-tree-relay-addon.mjs +++ b/config/scripts/build-windows-process-tree-relay-addon.mjs @@ -29,6 +29,7 @@ import { readSync, writeFileSync } from 'node:fs' +import { createRequire } from 'node:module' import { dirname, join, resolve } from 'node:path' import { RELAY_WINDOWS_PROCESS_TREE_FILENAME } from '../../src/shared/relay-artifacts.ts' @@ -92,7 +93,9 @@ function assertPatchApplied() { function applyWindowsProcessTreeBuildFixes() { const bindingPath = join(PACKAGE_DIR, 'binding.gyp') const processPath = join(PACKAGE_DIR, 'src', 'process.cc') - const nodeAddonApiDir = dirname(require.resolve('node-addon-api/package.json')) + const nodeAddonApiDir = dirname( + createRequire(import.meta.url).resolve('node-addon-api/package.json') + ) const stagedHeaderDir = join(PACKAGE_DIR, 'deps', 'node-addon-api') let bindingGyp = readFileSync(bindingPath, 'utf8') let processCc = readFileSync(processPath, 'utf8') diff --git a/config/scripts/windows-process-tree-gyp-path.test.mjs b/config/scripts/windows-process-tree-gyp-path.test.mjs index b80d59ba7f9..ebdade274b1 100644 --- a/config/scripts/windows-process-tree-gyp-path.test.mjs +++ b/config/scripts/windows-process-tree-gyp-path.test.mjs @@ -21,7 +21,11 @@ describe('windows-process-tree node-addon-api gyp path', () => { 'utf8' ) expect(buildScript).toContain("for (const header of ['napi.h', 'napi-inl.h'])") + expect(buildScript).toContain("import { createRequire } from 'node:module'") expect(buildScript).toContain("import { dirname, join, resolve } from 'node:path'") + expect(buildScript).toContain( + "createRequire(import.meta.url).resolve('node-addon-api/package.json')" + ) expect(buildScript).toContain('Repaired un-applied pnpm patch hunks before build.') })