Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Commit

Permalink
fixup: move parse to earlier phase
Browse files Browse the repository at this point in the history
  • Loading branch information
MylesBorins committed Mar 6, 2019
1 parent 10740f9 commit 5c81e3d
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,28 @@ translators.set('json', async (url) => {
const pathname = fileURLToPath(url);
const modulePath = isWindows ?
StringReplace(pathname, winSepRegEx, '\\') : pathname;
const module = CJSModule._cache[modulePath];
let module = CJSModule._cache[modulePath];
if (module && module.loaded) {
const exports = module.exports;
return createDynamicModule(['default'], url, (reflect) => {
reflect.exports.default.set(exports);
});
}
const content = await readFileAsync(pathname, 'utf-8');
try {
const exports = JsonParse(stripBOM(content));
module = {
exports,
loaded: true
};
} catch (err) {
err.message = pathname + ': ' + err.message;
throw err;
}
CJSModule._cache[modulePath] = module;
return createDynamicModule(['default'], url, (reflect) => {
debug(`Parsing JSONModule ${url}`);
try {
const exports = JsonParse(stripBOM(content));
const module = {
exports,
loaded: true
};
CJSModule._cache[modulePath] = module;
reflect.exports.default.set(exports);
} catch (err) {
err.message = pathname + ': ' + err.message;
throw err;
}
reflect.exports.default.set(module.exports);

});
});

0 comments on commit 5c81e3d

Please sign in to comment.