-
Notifications
You must be signed in to change notification settings - Fork 5
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 files are not POSIX compliant #156
Comments
This same issue ( Also wondering if there's an issue with how UNIX vs Windows define a line's "terminating character". https://stackoverflow.com/questions/52604191/how-to-prevent-npm-install-change-package-json?noredirect=1&lq=1 |
So this is a requirement for all files (not just package.json)? I have a Sublime Text setting
and can set to true if this is required. |
When I run
|
Same result (no change to package.json) after I updated to npm |
@samreid your OS and version? My npm settings are....
I ran
|
I have Windows 10, npm version 6.13.4. When running npm install in natural-selection or others I don't see any changes to package.json. |
macOS 10.15.1
|
@pixelzoom Just chiming in to note that contrary to popular belief, POSIX does not mandate files to end with a trailing newline, so your
|
Thanks @Kdex! |
I've generally included a newline at the end, and I'm fine with whatever others decide. |
Another interesting side-effect.... Because PhET package.json files don't end with a newline, inspecting (e.g.) natural-selection/package.json in an editor shows that it contains 25 lines. But some shell tools have a problem with this and don't read the last line. Examples...
This script to read each line of the file only reads the first 24 lines: #!/bin/bash
input="natural-selection/package.json"
while IFS= read -r line
do
echo "$line"
done < "$input" This seems like a potential problem for PhET's toolchain. |
@pixelzoom I don't know enough about this project to be heavily invested in this issue, though I'd still like to clarify the probable misconception of The
If you want to count the lines (as opposed to newline characters) in a file instead, you might want to count the beginnings of a line as opposed to endings: $ grep -c ^ natural-selection/package.json As for your second example where you iterate through a file using Basically, all that's needed is #!/bin/bash
input="natural-selection/package.json"
-while IFS= read -r line; do
+while IFS= read -r line || [ -n "$line" ]; do
echo "$line"
done < "$input" No matter which EOF flavor you end up picking, I'd definitely recommend making your scripts work with both, as it allows you (and the maintainers after you) to change personal preferences without touching the toolchain later on. |
Thanks (again!) @Kdex. The clarifications are much appreciated. Any thoughts on why |
@pixelzoom Sure thing! The newline issue is a long-standing bug in The reason why this happens is that It used to be much worse; some time ago, Unfortunately, the repository from above has been archived. I can remember somebody having made a PR to fix Nevertheless, you can currently avoid this bug by running |
Awesome, thanks @Kdex. |
|
This work-around did not work for me, nor did the
|
I opened an issue in the new npm repo back in April, but it hasn't received any traction: npm/cli#3044 |
This seems to be related to Node 15, which is no longer supported. Using Node 14 or 16 solved the problem, so I'm going to leave this closed. |
It looks like PhET's package.json files do not conform to the POSIX specification, and are therefore being modified by newer versions of npm.
I'm running npm 6.1.21.. When I run
npm install
in any repo directory, it changes package.json, adding an extra blank line at the end. It does this each and every time. If I generate a patch using WebStorm for the modified package.json, I see this:Note the "\ No newline at end of file".
Apparently PhET's package.json files don't conform to the POSIX standard. According to StackOverflow and opengroup.org, the definition of a "Line" in a file is:
So I'm guessing that npm is writing a POSIX compliant package.json, and adding a newline after the final '}'.
Should we update all package.json files to be POSIX compliant? Eagerly? Lazily?
The text was updated successfully, but these errors were encountered: