node-internal-fs.js 669 B

12345678910111213141516171819202122
  1. const fs = require('fs');
  2. // In node's core, this is implemented in C
  3. // https://github.com/nodejs/node/blob/v15.3.0/src/node_file.cc#L891-L985
  4. function internalModuleReadJSON(path) {
  5. let string
  6. try {
  7. string = fs.readFileSync(path, 'utf8')
  8. } catch (e) {
  9. if (e.code === 'ENOENT') return []
  10. throw e
  11. }
  12. // Node's implementation checks for the presence of relevant keys: main, name, type, exports, imports
  13. // Node does this for performance to skip unnecessary parsing.
  14. // This would slow us down and, based on our usage, we can skip it.
  15. const containsKeys = true
  16. return [string, containsKeys]
  17. }
  18. module.exports = {
  19. internalModuleReadJSON
  20. };