Socket
Socket
Sign inDemoInstall

fixpack

Package Overview
Dependencies
10
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 2.1.0

18

config.js
module.exports = {
sortToTop: ['name', 'description', 'version', 'author'],
required: ['name', 'version'],
warn: ['description', 'author', 'repository', 'keywords', 'main', 'bugs', 'homepage', 'license'],
requiredOnPrivate: [],
warnOnPrivate: ['name', 'version', 'description', 'main'],
sortedSubItems: ['dependencies', 'devDependencies', 'jshintConfig', 'scripts', 'keywords'],
quiet: false,
files: ['package.json']
};
sortToTop: ['name', 'description', 'version', 'author'],
required: ['name', 'version'],
warn: ['description', 'author', 'repository', 'keywords', 'main', 'bugs', 'homepage', 'license'],
requiredOnPrivate: [],
warnOnPrivate: ['name', 'version', 'description', 'main'],
sortedSubItems: ['dependencies', 'devDependencies', 'peerDependencies', 'jshintConfig', 'scripts', 'keywords'],
quiet: false,
files: ['package.json']
}
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var ALCE = require('alce');
var defaultConfig = require('./config');
var extend = require('extend-object');
require('colors');
var fs = require('fs')
var path = require('path')
var ALCE = require('alce')
var defaultConfig = require('./config')
var extend = require('extend-object')
require('colors')
function checkMissing(pack, config) {
var warnItems;
var required;
if (pack.private) {
warnItems = config.warnOnPrivate;
required = config.requiredOnPrivate;
} else {
warnItems = config.warn;
required = config.required;
}
required.forEach(function (key) {
if (!pack[key]) throw new Error(config.fileName + ' files must have a ' + key);
});
warnItems.forEach(function (key) {
if (!pack[key] && !config.quiet) console.log(('missing ' + key).yellow);
});
function checkMissing (pack, config) {
var warnItems
var required
if (pack.private) {
warnItems = config.warnOnPrivate
required = config.requiredOnPrivate
} else {
warnItems = config.warn
required = config.required
}
required.forEach(function (key) {
if (!pack[key]) throw new Error(config.fileName + ' files must have a ' + key)
})
warnItems.forEach(function (key) {
if (!pack[key] && !config.quiet) console.log(('missing ' + key).yellow)
})
}
function sortAlphabetically(object) {
if (Array.isArray(object)) {
object.sort();
return object;
} else {
var sorted = {};
Object.keys(object).sort().forEach(function (key) {
sorted[key] = object[key];
});
return sorted;
}
function sortAlphabetically (object) {
if (Array.isArray(object)) {
object.sort()
return object
} else {
var sorted = {}
Object.keys(object).sort().forEach(function (key) {
sorted[key] = object[key]
})
return sorted
}
}
module.exports = function (file, config) {
config = extend(defaultConfig, config || {});
if (!fs.existsSync(file)) {
if (!config.quiet) console.log(('No such file: ' + file).red);
process.exit(1);
}
config.fileName = path.basename(file);
var original = fs.readFileSync(file, {encoding: 'utf8'});
var pack = ALCE.parse(original);
var out = {};
var outputString = '';
var key;
config = extend(defaultConfig, config || {})
if (!fs.existsSync(file)) {
if (!config.quiet) console.log(('No such file: ' + file).red)
process.exit(1)
}
config.fileName = path.basename(file)
var original = fs.readFileSync(file, {encoding: 'utf8'})
var pack = ALCE.parse(original)
var out = {}
var outputString = ''
var key
// make sure we have everything
checkMissing(pack, config);
// make sure we have everything
checkMissing(pack, config)
// handle the specific ones we want, then remove
config.sortToTop.forEach(function (key) {
if (pack[key]) out[key] = pack[key];
delete pack[key];
});
// handle the specific ones we want, then remove
config.sortToTop.forEach(function (key) {
if (pack[key]) out[key] = pack[key]
delete pack[key]
})
// sort the remaining
pack = sortAlphabetically(pack);
// sort the remaining
pack = sortAlphabetically(pack)
// add in the sorted ones
for (key in pack) {
out[key] = pack[key];
}
// add in the sorted ones
for (key in pack) {
out[key] = pack[key]
}
// sort some sub items alphabetically
config.sortedSubItems.forEach(function (key) {
if (out[key]) out[key] = sortAlphabetically(out[key]);
});
// sort some sub items alphabetically
config.sortedSubItems.forEach(function (key) {
if (out[key]) out[key] = sortAlphabetically(out[key])
})
// write it out
outputString = JSON.stringify(out, null, 2) + '\n';
// write it out
outputString = JSON.stringify(out, null, 2) + '\n'
if (outputString !== original) {
fs.writeFileSync(file, outputString, {encoding: 'utf8'});
if (!config.quiet) console.log(config.fileName.bold + ' fixed'.green + '!');
} else {
if (!config.quiet) console.log(config.fileName.bold + ' already clean'.green + '!');
}
};
if (outputString !== original) {
fs.writeFileSync(file, outputString, {encoding: 'utf8'})
if (!config.quiet) console.log(config.fileName.bold + ' fixed'.green + '!')
} else {
if (!config.quiet) console.log(config.fileName.bold + ' already clean'.green + '!')
}
}
{
"name": "fixpack",
"description": "cli tool that cleans up package.json files.",
"version": "2.0.1",
"version": "2.1.0",
"author": "Henrik Joreteg <henrik@andyet.net>",

@@ -16,2 +16,5 @@ "bin": "./bin/fixpack",

},
"devDependencies": {
"standard": "^3.2.1"
},
"homepage": "https://github.com/henrikjoreteg/fixpack",

@@ -30,4 +33,4 @@ "keywords": [

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "standard && standard bin/fixpack"
}
}

@@ -107,2 +107,3 @@ # fixpack

- 2.0.1 - don't error on missing bower file by default.
- 2.0.0 - configurable via `.fixpackrc` file using rc module.

@@ -109,0 +110,0 @@ - x.x.x - unknown miscellaneous madness and poor version tracking

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc