Skip to content

Commit

Permalink
fix(resolve): fix rollup node resolve realpath checks
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Jul 18, 2020
1 parent 16918fc commit d3f4c4f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/compiler/sys/resolve/resolve-module-async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,26 @@ export const createCustomResolverAsync = (sys: d.CompilerSystem, inMemoryFs: d.I
cb(null, false);
},

async readFile(p: string, cb: (err: any, data: any) => void) {
async readFile(p: string, cb: (err: any, data?: any) => void) {
const fsFilePath = normalizeFsPath(p);

const data = await inMemoryFs.readFile(fsFilePath);
if (isString(data)) {
return cb(null, data);
}

return cb(`readFile not found: ${p}`, undefined);
return cb(`readFile not found: ${p}`);
},

async realpath(p: string, cb: (err: any, data: any) => void) {
const results = await sys.realpath(normalizeFsPath(p));
cb(results.error, results.path);
async realpath(p: string, cb: (err: any, data?: any) => void) {
const fsFilePath = normalizeFsPath(p);
const results = await sys.realpath(fsFilePath);

if (results.error && results.error.code !== 'ENOENT') {
cb(results.error);
} else {
cb(null, results.error ? fsFilePath : results.path);
}
},

extensions: exts,
Expand Down
12 changes: 8 additions & 4 deletions src/compiler/sys/resolve/resolve-module-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,15 @@ export const createCustomResolverSync = (sys: d.CompilerSystem, inMemoryFs: d.In
},

realpathSync(p: string) {
const results = sys.realpathSync(normalizeFsPath(p));
if (results.error) {
throw results.error;
const fsFilePath = normalizeFsPath(p);
try {
return sys.realpathSync(fsFilePath);
} catch (realpathErr) {
if (realpathErr.code !== 'ENOENT') {
throw realpathErr;
}
}
return results.path;
return fsFilePath;
},

extensions: exts,
Expand Down

0 comments on commit d3f4c4f

Please sign in to comment.