Skip to content

bug(jet-brains-integration): error if process.cwd()!==packageRoot, even if not creating the manifest #151

@maxpatiiuk

Description

@maxpatiiuk

jet-brains-integration is assuming that process.cwd() is pointing to package root. If it is not, it crashes at this line:

const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));

Since the fs access is in the global scope, it crashes even if the code didn't directly generate the manifest - any indirect imports to jet-brains-integration trigger the error:

 yarn s2l:migrate
node:fs:448
    return binding.readFileUtf8(path, stringToFlags(options.flag));
                   ^

Error: ENOENT: no such file or directory, open 'package.json'
    at Object.readFileSync (node:fs:448:20)
    at file://.../node_modules/custom-element-jet-brains-integration/dist/index.js:256:34
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:474:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:109:5) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'package.json'
}

Suggestions:

  • Don't try to read package.json in the global scope - tests and other scripts may indirectly import the jet-brains-integration, with no intention of generating the manifest
    • My workaround for now: async-import the bundle that includes the indirect import to jet-brains-integration only if needed
  • Have jet-brains-integration look up the directory tree to find the nearest package.json OR, even better, let us explicitly provide you with a package.json contents (which would make mocking in tests easier too)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions