Bundled Oclif CLI with PKG is failing to initialize Package.json and Plugins
cdbkr opened this issue · comments
It seems it is not working as expected with a cli bundled with PKG.
When going through the Root Plugin initialization, and trying to read Package.json, the fs:promise access
function throws with
[Error: ENOENT: no such file or directory, access '/snapshot/mycli/package.json'] {
errno: -2,
code: 'ENOENT',
syscall: 'access',
path: '/snapshot/mycli/package.json'
}
I have debugged the content hosted by pkg
:
------------------------------- virtual file system
/snapshot
mycli 63381336
run.js 533
package.json 2356
oclif.manifest.json 1965
dist 13275
index.js 238
commands 7641
hello 7403
index.js 1300
utils 8421
some 780
index.js 780
When replacing that line with using readFile
or open
(instead of access
, as suggested by https://nodejs.org/api/fs.html#fsaccesspath-mode-callback), everything works as expected.
Probably a permission error in the virtualized system?
@cdbkr Thanks for posting this. Are you able to provide more details about how to replicate this? I'm not familiar with pkg
Either way, after reading through the node docs you posted I agree that there's a better way to check for the existence of a file. I can make a PR to adjust that and we can see if that resolves your issue.
This issue has been linked to a new work item: W-14266572
@cdbkr I published a dev release (
3.0.5-dev.0
) from my PR #816. Can you try using that version and see if it resolves your issue? Thanks!
thank you very much @mdonnalley for your prompt response and PR! I have tried the changes and it is actually working as expected, and stat
looks way better than readFile
and open
.
If that PR gets merged, this issue could be closed
@cdbkr Thanks for posting this. Are you able to provide more details about how to replicate this? I'm not familiar with
pkg
Either way, after reading through the node docs you posted I agree that there's a better way to check for the existence of a file. I can make a PR to adjust that and we can see if that resolves your issue.
I have created a repo to reproduce https://github.com/cdbkr/oclif-core-pkg-rep
These are the lines to configure and buildpkg
https://github.com/cdbkr/oclif-core-pkg-rep/blob/main/package.json#L67-L80
Then just running
./dist-bin/mycli
It should fail with the error mentioned.
Applying the featured version at the same repo
npm install --save @oclif/core@3.0.5-dev.0
and rebuilding, fixes the issue
@cdbkr looks like you've taken the repo down. Is there any chance you can restore it? I can't seem to get it working with pkg
with workspaces.
It seems to be looking for package.json
recursively all the way up to the root even when the intermediary is not a package