Skip to content

Commit

Permalink
fix(loader): default to default resolve path is ts-config paths fails…
Browse files Browse the repository at this point in the history
…; update deps
  • Loading branch information
ricokahler committed Jan 26, 2021
1 parent a2641c3 commit aa2fc6a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
28 changes: 12 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
"dependencies": {
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@babel/register": "^7.12.10",
"babel-plugin-module-resolver": "^4.1.0",
"loader-utils": "^2.0.0",
"lodash": "^4.17.20",
"pirates": "^4.0.1",
"regenerator-runtime": "^0.13.7",
"require-from-string": "^2.0.2",
"tsconfig-paths": "^3.9.0"
},
Expand Down
28 changes: 19 additions & 9 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export async function _prevalLoader(
extensions,
resolvePath: (sourcePath: string, currentFile: string, opts: any) => {
if (matchPath) {
return matchPath(sourcePath, require, fs.existsSync, extensions);
try {
return matchPath(sourcePath, require, fs.existsSync, extensions);
} catch {
return defaultResolvePath(sourcePath, currentFile, opts);
}
}

return defaultResolvePath(sourcePath, currentFile, opts);
Expand All @@ -53,14 +57,20 @@ export async function _prevalLoader(
] as const);

const hook = (code: string, filename?: string) => {
const result = transform(code, {
filename: filename || 'preval-file.ts',
presets: ['next/babel'],
plugins: [
// conditionally add
...(moduleResolver ? [moduleResolver] : []),
],
});
const result = transform(
`require('regenerator-runtime/runtime');\n${code}`,
{
filename: filename || 'preval-file.ts',
presets: [
['@babel/preset-env', { targets: 'node 10' }],
'next/babel',
],
plugins: [
// conditionally add
...(moduleResolver ? [moduleResolver] : []),
],
}
);

if (!result?.code) {
throw new PrevalError(
Expand Down

0 comments on commit aa2fc6a

Please sign in to comment.