The pkg option must be set with the package's package.json.
However this does not work well with ES imports. At the moment, importing JSON files with ES imports is still experimental in Node.js.
Also, hardcoding the path to package.json can be tricky when transpiling is involved. For example, my binary file is at src/bin.js, but it is transpiled to build/src/bin.js. If I want to run both files, I need to dynamically find the path to package.json with a library like read-pkg-up.
Adding an option to automatically find the package (with read-pkg-up for example) would solve this problem. This option would probably need user to pass __dirname to be able to find the right package.json.
What do you think?
I can submit a PR if needed.
The
pkgoption must be set with the package'spackage.json.However this does not work well with ES imports. At the moment, importing JSON files with ES imports is still experimental in Node.js.
Also, hardcoding the path to
package.jsoncan be tricky when transpiling is involved. For example, my binary file is atsrc/bin.js, but it is transpiled tobuild/src/bin.js. If I want to run both files, I need to dynamically find the path topackage.jsonwith a library likeread-pkg-up.Adding an option to automatically find the package (with
read-pkg-upfor example) would solve this problem. This option would probably need user to pass__dirnameto be able to find the rightpackage.json.What do you think?
I can submit a PR if needed.