Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package.json can't be found bugfix #170

Merged
merged 6 commits into from
Dec 12, 2017
Merged

Package.json can't be found bugfix #170

merged 6 commits into from
Dec 12, 2017

Conversation

DeMoorJasper
Copy link
Member

Currently the package.json file is only searched for within the directory and not in parent directories, this should fix this.

As discussed here: closes #167

src/Bundler.js Outdated
}
}
} catch (err) {
let currPath = Path.dirname(this.mainFile);
currPath = currPath.substring(0, currPath.lastIndexOf('/'));
Copy link
Contributor

Choose a reason for hiding this comment

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

May be more robust to use Path to traverse up a directory.

currPath  = Path.join(currPath, '..');

let deps = Object.assign({}, pkg.dependencies, pkg.devDependencies);
for (let dep in deps) {
if (dep.startsWith('parcel-plugin-')) {
localRequire(dep, this.mainFile)(this);
localRequire(dep, location)(this);
}
}
} catch (err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is err always because it isn't found, or could it be something like access denied? Wouldn't want to keep traversing if it is found but just couldn't read it. That's a legitimate error.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll look into it

@DeMoorJasper DeMoorJasper deleted the feature/fix-167 branch December 11, 2017 13:33
@DeMoorJasper DeMoorJasper restored the feature/fix-167 branch December 11, 2017 13:35
@DeMoorJasper DeMoorJasper reopened this Dec 11, 2017
@marcioj
Copy link
Contributor

marcioj commented Dec 11, 2017

@DeMoorJasper nice work! Do you think it is possible to add tests for this issue? In order to avoid future regressions?

@DeMoorJasper
Copy link
Member Author

@marcioj i'll look into it, not sure how to write tests for this though

src/Bundler.js Outdated
}
}
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND' && location.length > 1) {
Copy link
Member

Choose a reason for hiding this comment

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

we probably only want to do this if the require of package.json failed, not one of plugins.

what if we used the config.load util function that already exists to load the package.json file instead? that will already do the traversing for us.

Copy link
Member Author

@DeMoorJasper DeMoorJasper Dec 11, 2017

Choose a reason for hiding this comment

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

Ow totally looked over the localRequire of plugins being in the same try-catch.

@DeMoorJasper DeMoorJasper changed the title Plugin resolver, does path traversal for apps that run in a sub-directory Package.json can't be found bug Dec 11, 2017
@DeMoorJasper DeMoorJasper changed the title Package.json can't be found bug Package.json can't be found bugfix Dec 11, 2017
@marcioj
Copy link
Contributor

marcioj commented Dec 11, 2017

@marcioj i'll look into it, not sure how to write tests for this though

@DeMoorJasper I'd try to create something based on this test. You can then copy thetest/integration/plugins and change to a subfolder like structure. Like src/index.js and src/test.txt ..

@DeMoorJasper
Copy link
Member Author

DeMoorJasper commented Dec 11, 2017

Tests should now handle parent folder package.json as well

@devongovett devongovett merged commit 7469a15 into parcel-bundler:master Dec 12, 2017
@DeMoorJasper DeMoorJasper deleted the feature/fix-167 branch December 12, 2017 22:57
devongovett pushed a commit that referenced this pull request Oct 15, 2018
* add path traversing for package.json, plugin bug

* improve

* fix

* add another test
devongovett pushed a commit that referenced this pull request Oct 15, 2018
* add path traversing for package.json, plugin bug

* improve

* fix

* add another test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugins are not loaded if the entry is not on the same directory as package.json
4 participants