Skip to content

get only existing package main#1577

Merged
devongovett merged 7 commits into
parcel-bundler:masterfrom
ranfdev:master
Jul 21, 2018
Merged

get only existing package main#1577
devongovett merged 7 commits into
parcel-bundler:masterfrom
ranfdev:master

Conversation

@ranfdev

@ranfdev ranfdev commented Jun 18, 2018

Copy link
Copy Markdown
Contributor

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...

Comment thread src/Resolver.js Outdated
for (let source of [pkg.source, pkg.module, browser, pkg.main, 'index']) {
if (
typeof source === 'string' &&
(await fs.exists(path.resolve(pkg.pkgdir, source)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ranfdev

ranfdev commented Jun 19, 2018

Copy link
Copy Markdown
Contributor Author

The errors are not related to this pr

Comment thread src/Resolver.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ranfdev ranfdev Jun 21, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DeMoorJasper

Copy link
Copy Markdown
Member

Could you resolve the conflicts?

@ranfdev

ranfdev commented Jun 25, 2018

Copy link
Copy Markdown
Contributor Author

Ok

Comment thread src/Resolver.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ranfdev

ranfdev commented Jul 12, 2018

Copy link
Copy Markdown
Contributor Author

@devongovett this should do the job

@devongovett devongovett merged commit f431b78 into parcel-bundler:master Jul 21, 2018
devongovett pushed a commit that referenced this pull request Oct 15, 2018
devongovett pushed a commit that referenced this pull request Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't resolve some dependencies

4 participants