-
Notifications
You must be signed in to change notification settings - Fork 244
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
Keep final new line in package.json #941
Conversation
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.
Thanks for the patch!
I know we'd adopted this pattern in a few places that were causing this issue before, but I guess we didn't get all of them
You might need to update some test mocks or stub methods to use writeFileAtomicSync |
I've replaced them with |
@@ -226,7 +228,8 @@ | |||
if (modifiedPkgJson === true) { | |||
const file = fs.readFileSync(pkgJsonPath, 'utf8'); | |||
const indent = detectIndent(file).indent || ' '; | |||
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, indent), 'utf8'); | |||
const newline = detectNewline(file); | |||
fs.writeFileSync(pkgJsonPath, stringifyPackage(pkgJson, indent, newline), 'utf8'); |
Check failure
Code scanning / CodeQL
Potential file system race condition High
was checked
@@ -71,7 +73,8 @@ | |||
if (modifiedPkgJson === true) { | |||
const file = fs.readFileSync(pkgJsonPath, 'utf8'); | |||
const indent = detectIndent(file).indent || ' '; | |||
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, indent), 'utf8'); | |||
const newline = detectNewline(file); | |||
fs.writeFileSync(pkgJsonPath, stringifyPackage(pkgJson, indent, newline), 'utf8'); |
Check failure
Code scanning / CodeQL
Potential file system race condition High
was checked
@@ -154,7 +156,8 @@ | |||
// Write to package.json | |||
const file = fs.readFileSync(pkgJsonPath, 'utf8'); | |||
const indent = detectIndent(file).indent || ' '; | |||
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, indent), 'utf8'); | |||
const newline = detectNewline(file); | |||
fs.writeFileSync(pkgJsonPath, stringifyPackage(pkgJson, indent, newline), 'utf8'); |
Check failure
Code scanning / CodeQL
Potential file system race condition High
was checked
@@ -145,7 +147,8 @@ | |||
// Write out new package.json with plugin removed correctly. | |||
const file = fs.readFileSync(pkgJsonPath, 'utf8'); | |||
const indent = detectIndent(file).indent || ' '; | |||
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, indent), 'utf8'); | |||
const newline = detectNewline(file); | |||
fs.writeFileSync(pkgJsonPath, stringifyPackage(pkgJson, indent, newline), 'utf8'); |
Check failure
Code scanning / CodeQL
Potential file system race condition High
was checked
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #941 +/- ##
==========================================
+ Coverage 87.91% 87.97% +0.06%
==========================================
Files 46 46
Lines 2134 2146 +12
==========================================
+ Hits 1876 1888 +12
Misses 258 258 ☔ View full report in Codecov by Sentry. |
How would you like me to proceed? I've not changed the semantics around the interactions with the file system. Yet the security bot is calling out a potential race condition that already exists. |
yeah, I think this is probably fine to merge as is. npm has refactored and deprecated a bunch of their tooling internally and now has a |
Thanks for the quick responses, I did not expect to get these reviewed or merged today! I assume these will be included in |
Platforms affected
Motivation and Context
Cordova removes the final new line in a package.json when running cordova commands. This causes us a problem since we have a formatting rule for final new lines.
Description
Apply the same writing rules every time the package.json is written to.
Testing
We have had the following patch in production for the last 3 months.
Patch
Checklist
(platform)
if this change only applies to one platform (e.g.(android)
)