Socket
Socket
Sign inDemoInstall

fixpack

Package Overview
Dependencies
17
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.6 to 4.0.0

6

config.json

@@ -42,3 +42,7 @@ {

],
"wipe": false
"dryRun": false,
"wipe": false,
"indent": null,
"newLine": null,
"finalNewLine": null
}

69

fixpack.js

@@ -5,3 +5,2 @@ #!/usr/bin/env node

const os = require('os')
const ALCE = require('alce')

@@ -11,6 +10,11 @@ const fs = require('fs')

const chalk = require('chalk')
const detectIndent = require('detect-indent')
const detectNewline = require('detect-newline')
const defaultConfig = require('./config')
function checkMissing(pack, config) {
const CRLF = '\r\n'
const LF = '\n'
function checkMissing (pack, config) {
let warnItems

@@ -25,7 +29,6 @@ let required

}
required.forEach(function(key) {
if (pack[key] == null)
throw new Error(config.fileName + ' files must have a ' + key)
required.forEach(function (key) {
if (pack[key] == null) { throw new Error(config.fileName + ' files must have a ' + key) }
})
warnItems.forEach(function(key) {
warnItems.forEach(function (key) {
if (pack[key] == null && !config.quiet) console.log(chalk.yellow('missing ' + key))

@@ -35,3 +38,3 @@ })

function sortAlphabetically(object) {
function sortAlphabetically (object) {
if (Array.isArray(object)) {

@@ -44,3 +47,3 @@ object.sort()

.sort()
.forEach(function(key) {
.forEach(function (key) {
sorted[key] = object[key]

@@ -52,10 +55,22 @@ })

module.exports = function(file, config) {
module.exports = function (file, config) {
config = Object.assign(defaultConfig, config || {})
if (!fs.existsSync(file)) {
if (!config.quiet) console.log(chalk.red('No such file: ' + file))
process.exit(1)
return 1
}
config.fileName = path.basename(file)
const original = fs.readFileSync(file, { encoding: 'utf8' })
const indent = config.indent != null
? config.indent
: detectIndent(original).indent
const newLine = config.newLine != null
? (
config.newLine === 'CRLF'
? CRLF
: LF
) : detectNewline(original)
const finalNewLine = config.finalNewLine != null
? !!config.finalNewLine
: /\n$/.test(original)
const out = {}

@@ -70,3 +85,3 @@ let pack = ALCE.parse(original)

// handle the specific ones we want, then remove
config.sortToTop.forEach(function(key) {
config.sortToTop.forEach(function (key) {
if (pack[key] != null) out[key] = pack[key]

@@ -89,3 +104,3 @@ delete pack[key]

// sort some sub items alphabetically
config.sortedSubItems.forEach(function(key) {
config.sortedSubItems.forEach(function (key) {
if (out[key] != null) out[key] = sortAlphabetically(out[key])

@@ -102,3 +117,3 @@ })

]
versionedKeys.forEach(function(key) {
versionedKeys.forEach(function (key) {
const depGroup = out[key]

@@ -114,16 +129,22 @@ if (depGroup) {

// write it out
outputString = JSON.stringify(out, null, 2) + os.EOL
outputString = JSON.stringify(out, null, indent)
if (outputString !== original) {
fs.writeFileSync(file, outputString, { encoding: 'utf8' })
if (!config.quiet) {
console.log(chalk.bold(config.fileName) + chalk.green(' fixed') + '!')
}
if (newLine === CRLF) {
outputString = outputString.replace(/\n/g, CRLF) + (finalNewLine ? CRLF : '')
} else {
if (!config.quiet) {
console.log(
chalk.bold(config.fileName) + chalk.green(' already clean') + '!'
)
}
outputString = outputString + (finalNewLine ? LF : '')
}
if (outputString === original) {
config.quiet || console.log(chalk.bold(config.fileName) + chalk.green(' already clean') + '!')
return 0
}
if (config.dryRun) {
config.quiet || console.log(chalk.bold(config.fileName) + chalk.red(' not fixed') + '!')
} else {
fs.writeFileSync(file, outputString, { encoding: 'utf8' })
config.quiet || console.log(chalk.bold(config.fileName) + chalk.green(' fixed') + '!')
}
return 1
}
{
"name": "fixpack",
"description": "cli tool that cleans up package.json files.",
"version": "3.0.6",
"version": "4.0.0",
"author": "Henrik Joreteg <henrik@andyet.net>",

@@ -12,4 +12,6 @@ "bin": "./bin/fixpack",

"dependencies": {
"alce": "1.0.0",
"chalk": "^2.4.1",
"alce": "1.2.0",
"chalk": "^3.0.0",
"detect-indent": "^6.0.0",
"detect-newline": "^3.1.0",
"extend-object": "^1.0.0",

@@ -16,0 +18,0 @@ "rc": "^1.2.8"

@@ -24,5 +24,6 @@ # fixpack

- homepage
- license'
- license
Fix all indenting to 2 spaces.
Maintain current indentation, End of Line, and Final New Line, or set them to your configured value
(see [configuration](#configuration)).

@@ -33,2 +34,4 @@ Oh, and it will tolerate improperly quoted and comma'd JSON thanks to [ALCE](https://npmjs.org/package/alce).

Oh, and it will exit with `0` when already fixed or with `1` otherwise (so combined with `--dryRun` flag it can be used as CI check)
## Usage

@@ -103,2 +106,4 @@

files: ['package.json'],
// Will not fix file, only inform if is fixed
dryRun: false,
// Will set all deps to '*'

@@ -108,3 +113,13 @@ // this may be useful because then you can

// to install latest stable releases of everything.
wipe: false
wipe: false,
// Sets the expected indentation. If number, is number of spaces,
// otherwise can be string to use as indentation (like a tab).
// if undefined/null (default), indentation is detected from file and preserved.
indent: null,
// Sets line endings to be either "LF" or "CRLF"
// if undefined/null (default), newLine is detected from file and preserved.
newLine: null,
// Boolean if there should be an empty line at the end of the file.
// if undefined/null (default), finalNewLine is detected from file and preserved.
finalNewLine: null
}

@@ -111,0 +126,0 @@

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