From c45a75051a8f800d5e5b411608094414afc9961c Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 12 Sep 2023 08:31:39 +0900 Subject: [PATCH] fix: createRequire from loader context --- src/loaders.ts | 2 +- tests/specs/typescript/tsconfig.ts | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/loaders.ts b/src/loaders.ts index 64a2fed..34d95bc 100644 --- a/src/loaders.ts +++ b/src/loaders.ts @@ -42,7 +42,7 @@ let mainThreadPort: MessagePort | undefined; export const globalPreload: GlobalPreloadHook = ({ port }) => { mainThreadPort = port; return ` - const require = getBuiltin('module').createRequire(getBuiltin('process').cwd() + '/'); + const require = getBuiltin('module').createRequire(${JSON.stringify(import.meta.url)}); require('@esbuild-kit/core-utils').installSourceMapSupport(port); port.unref(); // Allows process to exit without waiting for port to close `; diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts index eb5eeb9..2ae6e9c 100644 --- a/tests/specs/typescript/tsconfig.ts +++ b/tests/specs/typescript/tsconfig.ts @@ -1,5 +1,3 @@ -import path from 'path'; -import fs from 'fs/promises'; import { testSuite, expect } from 'manten'; import { createFixture } from 'fs-fixture'; import type { NodeApis } from '../../utils/node-with-loader.js'; @@ -39,12 +37,6 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }, }); - await fs.symlink( - path.resolve('node_modules'), - path.join(fixture.path, 'node_modules'), - 'dir', - ); - onTestFinish(async () => await fixture.rm()); // Strict mode is not tested because ESM is strict by default @@ -79,12 +71,6 @@ export default testSuite(async ({ describe }, node: NodeApis) => { 'src/jsx.jsx': checkJsx, }); - await fs.symlink( - path.resolve('node_modules'), - path.join(fixture.path, 'node_modules'), - 'dir', - ); - onTestFinish(async () => await fixture.rm()); const jsxJs = await node.load('./src/jsx.jsx', {