Uh oh!
There was an error while loading. Please reload this page.
Allow importing package.json - #2468
Conversation
RohovDmytro
commented
Jun 4, 2017
It it a safe practice to do so? |
iamdoron
commented
Jun 4, 2017
@rogovdm, I guess it depends what kind of date is in the Maybe it's better to only include the version property from the |
There was a problem hiding this comment.
I don't think this is correct. descriptionFileRoot is package.json even if I import ../lol.json. And it lets me do that. So this is probably the wrong thing to look at.
I assume that the correct thing to look at would be requestRelative calculated below, and if it's equal exactly to ../package or ../package.json (since we can't use Webpack resolving mechanism yet).
| const requestRelativeToRoot = path.relative( | ||
| request.descriptionFileRoot, | ||
| requestFullPath | ||
| ); |
There was a problem hiding this comment.
@gaearon you are totally right. My previous code wasn't working . I'm not sure what I did there, but this is what I meant to do - to check this is the package.json that's in the root. I didn't want to assume package.json always lives in ../src in case the src is more than one level deep like true/src
gaearon
commented
Jun 22, 2017
I don't understand newly pushed commits. I was referring to using existing variable (which has the right thing). You renamed an old variable but it still calculates the wrong thing. |
iamdoron
commented
Jun 22, 2017
I think it's OK, but maybe I'm missing something I wanted to check this is the package.json that resides in root: constrequestRelativeToRoot=path.relative(request.descriptionFileRoot,requestFullPath); |
gaearon
commented
Jun 22, 2017
I'm not sure myself. Just make sure importing |
now when I run it:
and |
Wouldn't it be easier to simply use this variable and add: if(requestRelative===`..${path.sep}package.json`){returncallback();}I might be missing something obvious. I have not tested this. |
iamdoron
commented
Jun 22, 2017
@Timer I wanted it to check from the root and not |
Good point, @iamdoron. if(/^(..[/|\\])+package.json$/.test(requestRelative)){returncallback();} |
9be52d8 to
be60e23Compare| request.__innerRequest_request | ||
| ); | ||
| const requestRelative = path.relative(appSrc, requestFullPath); | ||
| if (/^(..[/|\\])+package(.json)?$/.test(requestRelative)) { |
There was a problem hiding this comment.
@Timer I changed it to regex, I added '?' in (.json)? to make it optional. that way you can require("../package")
There was a problem hiding this comment.
It should always include the extension no matter what.
viankakrisna
commented
Jun 22, 2017
How about adding excludes option to ModuleScopePlugin? |
Timer
commented
Jun 22, 2017
@viankakrisna that's probably best long-term; what do you think @iamdoron? |
gaearon
commented
Jun 27, 2017
What's the status on this? What are requested changes? |
Timer
commented
Jun 28, 2017
We should strictly enforce the |
| class ModuleScopePlugin { | ||
| constructor(appSrc) { | ||
| constructor(appSrc, allowedPaths = []) { |
There was a problem hiding this comment.
Small nit, how about allowedFiles? Paths makes it sound like you can give it a directory.
| #### `new ModuleScopePlugin(appSrc: string)` | ||
| #### `new ModuleScopePlugin(appSrc: string, allowedPaths: [string])` |
There was a problem hiding this comment.
Ditto, allowedFiles. And we should probably let them know it's optional allowedFiles?: string[].
br0p0p
commented
Jul 31, 2017
What's the status on this? |
@br0p0p waiting for CI to pass, now. 😄 thanks for the ping! |
Timer
commented
Aug 2, 2017
Thanks for this, @iamdoron! |
Timer
commented
Aug 9, 2017
Hi there! This change is out in |
* Allow importing package.json * Remove package.json import from App.js template * fix importing package.json * Rename variable to reflect path is relative to root * Check for both package & package.json in ModuleScopePlugin * Use regex to check relative path to package.json * Strictly enforce package.json extension on scope plugin * Add allowedPaths to ModuleScopePlugin ctor and use it to allow app package.json * Remove package.json import from App.js template * Add package.json to react-scripts/template, show package version and name in the template * Remove import package.json from template * Remove template/package.json and its references in code * Update ModuleScopePlugin.js * Update README.md
* commit 'bfaee410c502a95076a6bd89721c76ca08e15f7b': (39 commits) Publish Prepare for 1.0.11 release (react#2924) Update dev deps (react#2923) Update README.md Use env variable to disable source maps (react#2818) Make formatWebpackMessages return all messages (react#2834) Adjust the `checkIfOnline` check if in a corporate proxy environment (react#2884) Fix the order of arguments in spawned child proc (react#2913) Feature/webpack 3 4 (react#2875) Allow importing package.json (react#2468) Re-enable flowtype warning (react#2718) Format UglifyJs error (react#2650) Unstage yarn.lock pre-commit (react#2700) Update README.md Update README.md Add Electrode to alternatives (react#2728) Fix parsing HTML/JSX tags to real elements (react#2796) Update webpack version note (react#2798) Use modern syntax feature (react#2873) Allow use of scoped packages with a pinned version (react#2853) ... # Conflicts: # packages/react-scripts/config/webpack.config.dev.js # packages/react-scripts/config/webpack.config.prod.js # packages/react-scripts/package.json
* Allow importing package.json * Remove package.json import from App.js template * fix importing package.json * Rename variable to reflect path is relative to root * Check for both package & package.json in ModuleScopePlugin * Use regex to check relative path to package.json * Strictly enforce package.json extension on scope plugin * Add allowedPaths to ModuleScopePlugin ctor and use it to allow app package.json * Remove package.json import from App.js template * Add package.json to react-scripts/template, show package version and name in the template * Remove import package.json from template * Remove template/package.json and its references in code * Update ModuleScopePlugin.js * Update README.md
* Allow importing package.json * Remove package.json import from App.js template * fix importing package.json * Rename variable to reflect path is relative to root * Check for both package & package.json in ModuleScopePlugin * Use regex to check relative path to package.json * Strictly enforce package.json extension on scope plugin * Add allowedPaths to ModuleScopePlugin ctor and use it to allow app package.json * Remove package.json import from App.js template * Add package.json to react-scripts/template, show package version and name in the template * Remove import package.json from template * Remove template/package.json and its references in code * Update ModuleScopePlugin.js * Update README.md
* Allow importing package.json * Remove package.json import from App.js template * fix importing package.json * Rename variable to reflect path is relative to root * Check for both package & package.json in ModuleScopePlugin * Use regex to check relative path to package.json * Strictly enforce package.json extension on scope plugin * Add allowedPaths to ModuleScopePlugin ctor and use it to allow app package.json * Remove package.json import from App.js template * Add package.json to react-scripts/template, show package version and name in the template * Remove import package.json from template * Remove template/package.json and its references in code * Update ModuleScopePlugin.js * Update README.md

Hi,
Basically, allow to import
package.json.For example, from
src/App.js:Only the app own
package.jsonis allowed to be imported.It closes#2466