-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esm: share package.json cache between ESM and CJS loaders
Refs: #30674 PR-URL: #33229 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
- Loading branch information
1 parent
dd5f209
commit 8f10bb2
Showing
10 changed files
with
119 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const { SafeMap } = primordials; | ||
const { internalModuleReadJSON } = internalBinding('fs'); | ||
|
||
const cache = new SafeMap(); | ||
|
||
/** | ||
* | ||
* @param {string} path | ||
*/ | ||
function read(path) { | ||
if (cache.has(path)) { | ||
return cache.get(path); | ||
} | ||
|
||
const [string, containsKeys] = internalModuleReadJSON(path); | ||
const result = { string, containsKeys }; | ||
cache.set(path, result); | ||
return result; | ||
} | ||
|
||
module.exports = { read }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const { mustCall, isWindows } = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const { spawn } = require('child_process'); | ||
const { strictEqual, ok } = require('assert'); | ||
|
||
const entry = fixtures.path('/es-modules/import-invalid-pjson.mjs'); | ||
const invalidJson = fixtures.path('/node_modules/invalid-pjson/package.json'); | ||
|
||
const child = spawn(process.execPath, [entry]); | ||
child.stderr.setEncoding('utf8'); | ||
let stderr = ''; | ||
child.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
child.on('close', mustCall((code, signal) => { | ||
strictEqual(code, 1); | ||
strictEqual(signal, null); | ||
ok( | ||
stderr.includes( | ||
[ | ||
'[ERR_INVALID_PACKAGE_CONFIG]: ', | ||
`Invalid package config ${invalidJson}, `, | ||
`Unexpected token } in JSON at position ${isWindows ? 16 : 14}` | ||
].join(''), | ||
), | ||
stderr); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import 'invalid-pjson'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters