From 4344174150f66a10e6c807496e0ef38b5f1c11bc Mon Sep 17 00:00:00 2001 From: productdevbook Date: Tue, 26 Dec 2023 08:31:38 +0300 Subject: [PATCH] chore: add graphql lookupNodeModuleSubpath test --- src/resolve.ts | 3 ++- .../package/node_modules/graphql/cjs/index.js | 1 + .../package/node_modules/graphql/package.json | 13 +++++++++++++ .../package/node_modules/graphql/src/index.js | 1 + test/utils.test.ts | 6 ++++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/fixture/package/node_modules/graphql/cjs/index.js create mode 100644 test/fixture/package/node_modules/graphql/package.json create mode 100644 test/fixture/package/node_modules/graphql/src/index.js diff --git a/src/resolve.ts b/src/resolve.ts index 2029201..8e3f7ae 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -174,8 +174,9 @@ export async function lookupNodeModuleSubpath( path: string, ): Promise { path = normalize(fileURLToPath(path)); + console.log(path); const { name, subpath } = parseNodeModulePath(path); - + console.log({ name, subpath }); if (!name || !subpath) { return subpath; } diff --git a/test/fixture/package/node_modules/graphql/cjs/index.js b/test/fixture/package/node_modules/graphql/cjs/index.js new file mode 100644 index 0000000..32b4de0 --- /dev/null +++ b/test/fixture/package/node_modules/graphql/cjs/index.js @@ -0,0 +1 @@ +export default "cjs"; diff --git a/test/fixture/package/node_modules/graphql/package.json b/test/fixture/package/node_modules/graphql/package.json new file mode 100644 index 0000000..0e4c0e1 --- /dev/null +++ b/test/fixture/package/node_modules/graphql/package.json @@ -0,0 +1,13 @@ +{ + "name": "postgres", + "version": "3.4.3", + "description": "Fastest full featured PostgreSQL client for Node.js", + "type": "module", + "module": "src/index.js", + "main": "cjs/src/index.js", + "exports": { + "bun": "./src/index.js", + "import": "./src/index.js", + "default": "./cjs/src/index.js" + } +} diff --git a/test/fixture/package/node_modules/graphql/src/index.js b/test/fixture/package/node_modules/graphql/src/index.js new file mode 100644 index 0000000..06c676e --- /dev/null +++ b/test/fixture/package/node_modules/graphql/src/index.js @@ -0,0 +1 @@ +export default "esm"; diff --git a/test/utils.test.ts b/test/utils.test.ts index 0c05b75..c29a9b8 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -133,11 +133,17 @@ describe("lookupNodeModuleSubpath", () => { input: r("fixture/package/node_modules/subpaths/"), output: "./", }, + { + name: "resolves main export", + input: r("fixture/package/node_modules/graphql/src/index.js"), + output: "import", + }, ]; for (const t of tests) { it(t.name, async () => { const result = await lookupNodeModuleSubpath(t.input); + console.log(result); expect(result).toBe(t.output); }); }