Skip to content

Commit f6816c1

Browse files
authored
fix(register): skip load files in node_modules (#828)
1 parent af98621 commit f6816c1

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

packages/integrate-module/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@types/react-dom": "^18.3.0",
1616
"esmock": "^2.6.6",
1717
"ipaddr.js": "^2.2.0",
18+
"postgres": "^3.4.4",
1819
"react": "^18.3.1",
1920
"react-dom": "^18.3.1",
2021
"simple-git": "^3.25.0",

packages/integrate-module/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { supportedExtensions } from 'file-type'
99
import { renderToString } from 'react-dom/server'
1010
import { simpleGit } from 'simple-git'
1111
import ipaddr from 'ipaddr.js'
12+
import postgres from 'postgres'
1213

1314
import { CompiledClass } from './compiled.js'
1415
import cjs from './cjs'
@@ -90,3 +91,9 @@ await test('esmock should work', async () => {
9091

9192
assert.strictEqual(main.pathbasenamewrap(), 'hello')
9293
})
94+
95+
await test('postgres should work', async () => {
96+
postgres({
97+
host: 'postgres://localhost',
98+
})
99+
})

packages/register/esm.mts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,7 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => {
215215
}
216216

217217
// local project file
218-
if (
219-
path &&
220-
((process.platform !== 'win32' && !path.includes('/node_modules/')) ||
221-
(process.platform === 'win32' && !path.includes('\\node_modules\\')))
222-
) {
218+
if (path && isPathNotInNodeModules(path)) {
223219
debug('resolved: typescript', specifier, path)
224220
const url = new URL(join('file://', path))
225221
return addShortCircuitSignal({
@@ -272,6 +268,12 @@ export const load: LoadHook = async (url, context, nextLoad) => {
272268
return nextLoad(url, context)
273269
}
274270

271+
if (url.includes('/node_modules/')) {
272+
debug('skip load: node_modules', url)
273+
274+
return nextLoad(url, context)
275+
}
276+
275277
if (['builtin', 'json', 'wasm'].includes(context.format)) {
276278
debug('loaded: internal format', url)
277279
return nextLoad(url, context)
@@ -300,3 +302,10 @@ export const load: LoadHook = async (url, context, nextLoad) => {
300302
source: compiled,
301303
})
302304
}
305+
306+
function isPathNotInNodeModules(path: string) {
307+
return (
308+
(process.platform !== 'win32' && !path.includes('/node_modules/')) ||
309+
(process.platform === 'win32' && !path.includes('\\node_modules\\'))
310+
)
311+
}

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)