|
1 | 1 | import { createRequire } from 'module'; |
2 | 2 | import { dirname, resolve } from 'path'; |
| 3 | +import { versionInfo } from 'graphql'; |
3 | 4 | import { defineConfig } from 'vitest/config'; |
4 | 5 |
|
5 | | -// Use an absolute path to graphql/index.mjs so ALL imports (Vite-processed |
6 | | -// and Node.js-native) resolve to the same ESM module in Node.js's module cache, |
7 | | -// preventing graphql@17's devInstanceOf from detecting false cross-realm usage. |
8 | | -const _require = createRequire(import.meta.url); |
9 | | -// require.resolve('graphql') returns index.mjs in Node.js v24 (via module-sync condition) |
10 | | -const graphqlIndexMjs = resolve(dirname(_require.resolve('graphql')), 'index.mjs'); |
11 | | - |
12 | 6 | export const sharedConfig = defineConfig({ |
13 | 7 | resolve: { |
14 | 8 | alias: { |
15 | | - graphql: graphqlIndexMjs, |
| 9 | + graphql: (function resolveGraphQL() { |
| 10 | + if (versionInfo.major < 17) { |
| 11 | + return 'graphql/index.js'; |
| 12 | + } |
| 13 | + // Use an absolute path to graphql/index.mjs so ALL imports (Vite-processed |
| 14 | + // and Node.js-native) resolve to the same ESM module in Node.js's module cache, |
| 15 | + // preventing graphql@17's devInstanceOf from detecting false cross-realm usage. |
| 16 | + const _require = createRequire(import.meta.url); |
| 17 | + // require.resolve('graphql') returns index.mjs in Node.js v24 (via module-sync condition) |
| 18 | + const graphqlIndexMjs = resolve(dirname(_require.resolve('graphql')), 'index.mjs'); |
| 19 | + return graphqlIndexMjs; |
| 20 | + })(), |
16 | 21 | }, |
17 | 22 | tsconfigPaths: true, |
18 | 23 | }, |
|
0 commit comments