Skip to content
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

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cordova/platform/addHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const cordova_util = require('../util');
const promiseutil = require('../../util/promise-util');
const platforms = require('../../platforms');
const detectIndent = require('detect-indent');
const detectNewline = require('detect-newline');
const stringifyPackage = require('stringify-package');
const writeFileAtomicSync = require('write-file-atomic').sync;
const getPlatformDetailsFromDir = require('./getPlatformDetailsFromDir');
const preparePlatforms = require('../prepare/platforms');

Expand Down Expand Up @@ -226,7 +229,8 @@ function addHelper (cmd, hooksRunner, projectRoot, targets, opts) {
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);
writeFileAtomicSync(pkgJsonPath, stringifyPackage(pkgJson, indent, newline), { encoding: 'utf8' });
}
});
}).then(function () {
Expand Down
6 changes: 5 additions & 1 deletion src/cordova/platform/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const cordova_util = require('../util');
const promiseutil = require('../../util/promise-util');
const platforms = require('../../platforms/platforms');
const detectIndent = require('detect-indent');
const detectNewline = require('detect-newline');
const stringifyPackage = require('stringify-package');
const writeFileAtomicSync = require('write-file-atomic').sync;

module.exports = remove;

Expand Down Expand Up @@ -71,7 +74,8 @@ function remove (hooksRunner, projectRoot, targets, opts) {
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);
writeFileAtomicSync(pkgJsonPath, stringifyPackage(pkgJson, indent, newline), { encoding: 'utf8' });
}
}
}).then(function () {
Expand Down
6 changes: 5 additions & 1 deletion src/cordova/plugin/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const path = require('node:path');
const semver = require('semver');
const url = require('url');
const detectIndent = require('detect-indent');
const detectNewline = require('detect-newline');
const stringifyPackage = require('stringify-package');
const writeFileAtomicSync = require('write-file-atomic').sync;
const cordova_util = require('../util');
const plugin_util = require('./util');
const cordova_pkgJson = require('../../../package.json');
Expand Down Expand Up @@ -154,7 +157,8 @@ function add (projectRoot, hooksRunner, opts) {
// 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);
writeFileAtomicSync(pkgJsonPath, stringifyPackage(pkgJson, indent, newline), { encoding: 'utf8' });
}

const src = module.exports.parseSource(target, opts);
Expand Down
6 changes: 5 additions & 1 deletion src/cordova/plugin/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const plugman = require('../../plugman/plugman');
const metadata = require('../../plugman/util/metadata');
const PluginInfoProvider = require('cordova-common').PluginInfoProvider;
const detectIndent = require('detect-indent');
const detectNewline = require('detect-newline');
const stringifyPackage = require('stringify-package');
const writeFileAtomicSync = require('write-file-atomic').sync;
const { Q_chainmap } = require('../../util/promise-util');
const preparePlatforms = require('../prepare/platforms');

Expand Down Expand Up @@ -145,7 +148,8 @@ function remove (projectRoot, targets, hooksRunner, opts) {
// 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);
writeFileAtomicSync(pkgJsonPath, stringifyPackage(pkgJson, indent, newline), { encoding: 'utf8' });
}
}
}
Expand Down
Loading