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

Allow importing package.json #2468

Merged
merged 15 commits into from
Aug 2, 2017
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions packages/react-dev-utils/ModuleScopePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,21 @@ class ModuleScopePlugin {
// Maybe an indexOf === 0 would be better?
const relative = path.relative(appSrc, request.context.issuer);
// If it's not in src/ or a subdirectory, not our request!
if (
relative.startsWith('../') ||
relative.startsWith('..\\')
) {
if (relative.startsWith('../') || relative.startsWith('..\\')) {
return callback();
}
// Find path from src to the requested file
const requestRelative = path.relative(
appSrc,
path.resolve(
path.dirname(request.context.issuer),
request.__innerRequest_request
)
const requestFullPath = path.resolve(
path.dirname(request.context.issuer),
request.__innerRequest_request
);
const requestRelative = path.relative(appSrc, requestFullPath);
if (/^(..[/|\\])+package(.json)?$/.test(requestRelative)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Timer I changed it to regex, I added '?' in (.json)? to make it optional. that way you can require("../package")

Copy link
Contributor

Choose a reason for hiding this comment

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

It should always include the extension no matter what.

return callback();
}
// Find path from src to the requested file
// Error if in a parent directory of src/
if (
requestRelative.startsWith('../') ||
requestRelative.startsWith('..\\')
requestRelative.startsWith('../') || requestRelative.startsWith('..\\')
) {
callback(
new Error(
Expand Down