-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: don't emit package-lock.json when package.json does not exist #7097
base: latest
Are you sure you want to change the base?
Conversation
Hi, there. It's my first time to contribute to the repo. Thank you very much. |
Won't this still omit the package-lock if the package.json is an empty object? |
It seems to me the root problem here is that the check for the existence of a package.json is happening too late. Arborist should never be given the task of reifying if npm is ultimately going to throw an exception. |
Thanks very much for the response, @wraithgar, I'll try to figure that out. |
1481863
to
56b9023
Compare
Hi, @wraithgar, would you take another look? |
This would need a test. |
56b9023
to
0acd2a2
Compare
Hi, @wraithgar, I have added tests, would you take a look when you have time? |
I have fixed the smoke-test proxy test. |
I took a look and I think the fact that you had to add Another wrinkle here is that I think this check is going to have to happen in Arborist. Consider this situation npm install abbrev --no-save
mkdir sub
cd sub
npm install This will generate the same error state, i.e. a package-lock written to the main folder, but this code wouldn't catch it. This is because Arborist does some tree walking to see if any parent directories are in fact the root of the module. The presence of a What's frustrating is that it appears that wherever is throwing this error is not being properly caught by npm in a way where the error stack is preserved. It appears to be generated without one. After some digging it looks like this is a failure of So. We likely have two bugs here: First, we have a situation where there is no package.json file, but Second, we have a situation where sometimes Arborist is told to reify a truly empty directory. That is, one with no package lock, package.json, OR node_modules. In that very limited situation it should not be writing the package lock file. We need a much more fine tuned test inside arborist itself to prevent this bug. Unfortunately when I made this statement
It was before we knew that there were two bugs. What we should be saying is "Arborist should not write the package-lock on a truly empty set of folders (no package.json, lock, or node_modules)" and "npm should not error when trying to run lifecycle scripts when there is no package.json" |
Also as a side task I have made npm/run-script#190 and assigned it to myself. We are obviously not done in the process of moving onto that consolidated module for all package json parsing. |
const isJsonEmptyObject = Object.keys(jsonContent).length === 0 | ||
&& jsonContent.constructor === Object | ||
|
||
const emptyJson = new Error('EEMPTYPKGJSON: package.json is empty object') |
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.
why not remove this check, let it generate empty lock file if package.json is empty. Only make sure not to generate lock file if package.json file doesn't exists
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.
If you'll read my (admittedly long) comment you'll see that this check in this place is not the right solution to begin with.
Hi, @wraithgar, I have confusion on your comment, would you mind elaborate for me?
I suspect when you mention previous module you mean the
I have search error stack on google, but I don't understand what it has to do with the current situation? The |
"that code" refers to all the code checking if what was returned was an empty object or not. That's immaterial when using The generating an error stack comment was about how hard it was to debug. Without one we have no way of knowing where that error is being thrown from. I did discover it however, and it is in fact the run-script call. |
const jsonContent = pkgJson.content | ||
const isJsonEmptyObject = Object.keys(jsonContent).length === 0 | ||
&& jsonContent.constructor === Object | ||
|
||
const emptyJson = new Error('EEMPTYPKGJSON: package.json is empty object') | ||
emptyJson.code = 'EEMPTYPKGJSON' | ||
emptyJson.path = pkgJson.filename | ||
if (isJsonEmptyObject) { | ||
throw emptyJson | ||
} |
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.
Hi, @wraithgar, that code do you mean this snippet? But it's written by me, not left over before I wrote the commit? I still don't understand, Can you point to one place of the code for example?
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.
I was trying to infer why the test for an empty object was there and assumed it was due to rpj
. The long and the short of it is we don't need that check, either package-json
returns or it doesn't, if it returns at all we read a package.json file from somewhere in the tree.
Doesn't |
npm install
in a folder that doesn't havepackage.json
doesn't writepackage-lock.json
file.References
Fixes #6986