get only existing package main#1577
Conversation
| for (let source of [pkg.source, pkg.module, browser, pkg.main, 'index']) { | ||
| if ( | ||
| typeof source === 'string' && | ||
| (await fs.exists(path.resolve(pkg.pkgdir, source))) |
There was a problem hiding this comment.
Hi!
According to node.js docs fs.exists method is deprecated. In order to check if files exists we can use fs.access method or sync version fs.accessSync.
|
The errors are not related to this pr |
There was a problem hiding this comment.
Isn't this the responsibility of the library anyone is using?
Shouldn't main always be accesible? Otherwise it's a bug in package.json from the pkg that's being processed
There was a problem hiding this comment.
// else, check if the file main exists/is accessible
here i'm referring to the main variable in general, not only the pkg.main file. The value of the main variable in that moment could be pkg.source.
pkg.source is not always present in compiled packages, that's why parcel needs to check if it's accessible. If it's not, parcel should try to resolve the next possibleMain (e.g. pkg.module), until it finds an existing one.
Before this pr, parcel would try to load pkg.source even if it isn't accessible
There was a problem hiding this comment.
I think we should just have getPackageMain return an array of possible paths, and have loadDirectory loop through them and try each one. Since it is already reading files there, we would avoid checking twice.
|
Could you resolve the conflicts? |
|
Ok |
There was a problem hiding this comment.
I think we should just have getPackageMain return an array of possible paths, and have loadDirectory loop through them and try each one. Since it is already reading files there, we would avoid checking twice.
|
@devongovett this should do the job |
Sometimes a package has in his package.json a source field, but the package is already bundled/compiled, so there isn't any source file inside that package. Now, before returning any package file, parcel checks if the file exists. If it doesn't exists, parcel tries to use another file, until a real file is found. fixes #1568
I still need to fix the error...