Skip to content

Commit c896db1

Browse files
committed
fix: swallow require.resolve errors for unit tests
1 parent 9d76dd4 commit c896db1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/runtime/src/helpers/functions.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,24 @@ const traceNextServer = async (publish: string, baseDir: string): Promise<string
245245
return filtered.map((file) => relative(baseDir, file))
246246
}
247247

248+
export const traceNPMPackage = async (pack: string, publish: string) => {
249+
try {
250+
return await glob(join(dirname(require.resolve(pack, { paths: [publish] })), '**', '*'))
251+
} catch (error) {
252+
if (process.env.NODE_ENV === 'test') {
253+
return []
254+
}
255+
throw error
256+
}
257+
}
258+
248259
export const getAPIPRouteCommonDependencies = async (publish: string, baseDir: string) => {
249260
const [requiredServerFiles, nextServerFiles, followRedirectsFiles] = await Promise.all([
250261
traceRequiredServerFiles(publish),
251262
traceNextServer(publish, baseDir),
252263

253264
// used by our own bridge.js
254-
glob(join(dirname(require.resolve('follow-redirects', { paths: [publish] })), '**', '*')),
265+
traceNPMPackage('follow-redirects', publish),
255266
])
256267

257268
return [...requiredServerFiles, ...nextServerFiles, ...followRedirectsFiles]

0 commit comments

Comments
 (0)