Skip to content

Commit

Permalink
fix package json formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
aidant committed Dec 16, 2024
1 parent db5c8c0 commit bdd81cf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
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

0 comments on commit bdd81cf

Please sign in to comment.