- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 27.1k
Allow importing package.json #2468
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
Changes from 13 commits
6727da4
              d22a9df
              9ef9fcb
              d382a94
              18ee2fc
              be60e23
              c288eca
              3a27a6c
              ee51957
              077366e
              f42dba0
              c223f86
              7ac9883
              fab0f91
              daf59f4
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -13,8 +13,9 @@ const chalk = require('chalk'); | |
| const path = require('path'); | ||
|  | ||
| class ModuleScopePlugin { | ||
| constructor(appSrc) { | ||
| constructor(appSrc, allowedPaths = []) { | ||
| this.appSrc = appSrc; | ||
| this.allowedPaths = new Set(allowedPaths); | ||
|          | ||
| } | ||
|  | ||
| apply(resolver) { | ||
|  | @@ -40,15 +41,16 @@ class ModuleScopePlugin { | |
| 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 | ||
| ); | ||
| if (this.allowedPaths.has(requestFullPath)) { | ||
| return callback(); | ||
| } | ||
| // Find path from src to the requested file | ||
| // Error if in a parent directory of src/ | ||
| const requestRelative = path.relative(appSrc, requestFullPath); | ||
| if ( | ||
| requestRelative.startsWith('../') || | ||
| requestRelative.startsWith('..\\') | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -57,7 +57,7 @@ module.exports = { | |
| ``` | ||
|  | ||
|  | ||
| #### `new ModuleScopePlugin(appSrc: string)` | ||
| #### `new ModuleScopePlugin(appSrc: string, allowedPaths: [string])` | ||
|          | ||
|  | ||
| This Webpack plugin ensures that relative imports from app's source directory don't reach outside of it. | ||
|  | ||
|  | @@ -71,7 +71,7 @@ module.exports = { | |
| resolve: { | ||
| // ... | ||
| plugins: [ | ||
| new ModuleScopePlugin(paths.appSrc), | ||
| new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), | ||
| // ... | ||
| ], | ||
| // ... | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit, how about
allowedFiles? Paths makes it sound like you can give it a directory.