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

Sync #1

Merged
merged 13 commits into from Sep 1, 2019
20 changes: 13 additions & 7 deletions .eslintrc
Expand Up @@ -8,18 +8,24 @@
},

"rules": {
"consistent-return": [1],
"func-style": [0],
"global-require": [1],
"array-element-newline": 0,
"complexity": 0,
"consistent-return": 1,
"dot-notation": [2, { "allowKeywords": true }],
"func-name-matching": 1,
"func-style": 0,
"global-require": 1,
"indent": [2, 2],
"max-lines-per-function": 0,
"max-nested-callbacks": [2, 4],
"max-params": [2, 4],
"max-statements": [2, 14],
"max-statements-per-line": [2, { "max": 2 }],
"new-cap": [2, { "capIsNewExceptions": ["Range"] }],
"no-console": [0],
"no-magic-numbers": [0],
"no-process-exit": [1],
"no-use-before-define": [1]
"no-console": 0,
"no-magic-numbers": 0,
"no-process-exit": 1,
"no-use-before-define": 1,
"operator-linebreak": [2, "before"],
}
}
6 changes: 6 additions & 0 deletions .gitignore
@@ -1 +1,7 @@
# gitignore
/node_modules/

# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock
10 changes: 5 additions & 5 deletions .jscs.json
Expand Up @@ -123,7 +123,7 @@

"disallowArrowFunctions": true,

"disallowMultiLineTernary": true,
"disallowMultiLineTernary": false,

"validateOrderInObjectKeys": "asc-insensitive",

Expand Down Expand Up @@ -158,14 +158,14 @@

"requireImportAlphabetized": false,

"requireSpaceBeforeObjectValues": true,
"requireSpaceBeforeDestructuredValues": true,
"requireSpaceBeforeObjectValues": true,
"requireSpaceBeforeDestructuredValues": true,

"disallowSpacesInsideTemplateStringPlaceholders": true,

"disallowArrayDestructuringReturn": false,
"disallowArrayDestructuringReturn": false,

"requireNewlineBeforeSingleStatementsInIf": false,
"requireNewlineBeforeSingleStatementsInIf": false,

"disallowUnusedVariables": true,

Expand Down
1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
package-lock=false
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -24,9 +24,11 @@ salita
- `--no-color`: prevents colorized output
- `--json`: provides parseable JSON output (also disables colors)
- `--dry-run` / `-n`: prevents changes to `package.json`
- `--ignore-stars`: ignore updates to packages that are set to "*"
- `--update`: reflects the changes in `package.json`
- `--ignore-stars`: ignore updates to packages that are set to "`*`"
- `--ignore-pegged`: ignore updates to packages that are pegged to a single version, rather than a range
- `--check`: implies "dry-run"; and returns with an exit code matching the number of updated dependencies.
- `--only-changed`: only show packages that have (or would have) changed

### Example ###

Expand Down
2 changes: 2 additions & 0 deletions bin/salita
Expand Up @@ -25,6 +25,8 @@ var options = require('yargs')
.default('update', FALSE).alias('update', 'u')
.boolean('ignore-stars').describe('ignore-stars', 'ignore updates to packages that are set to "*"')
.boolean('ignore-pegged').describe('ignore-pegged', 'ignore updates to packages that are pegged to a single version, rather than a range')
.boolean('only-changed').describe('only-changed', 'only show packages that have (or would have) changed')
.default('only-changed', FALSE).alias('only-changed', 'o')
.boolean('check').describe('check', 'implies --dry-run and --no-update, and returns with an exit code matching the number of updated dependencies')
.default('check', FALSE).alias('check', 'c')
.help().alias('help', 'h')
Expand Down
64 changes: 43 additions & 21 deletions index.js
Expand Up @@ -32,15 +32,17 @@ var getTable = function () {
});
};

var createResultJSON = function (key) {
var createResultJSON = function (key, onlyChanged) {
return function (results) {
var obj = {};
obj[key] = results;
obj[key] = results.filter(function (result) {
return !onlyChanged || result.isChanged;
});
return obj;
};
};

var createResultTable = function (caption) {
var createResultTable = function (caption, onlyChanged) {
return function (results) {
var table = getTable();
if (results.length > 0) {
Expand All @@ -54,15 +56,17 @@ var createResultTable = function (caption) {
'to',
chalk.yellow(result.after)
];
} else if (result.error) {
}
if (result.error) {
return [
chalk.red('Package not found: '),
result.name,
'at',
chalk.yellow(result.before),
chalk.bold.red('?')
];
} else if (!result.isUpdateable && !result.isStar && !result.isPegged) {
}
if (!result.isUpdateable && !result.isStar && !result.isPegged) {
return [
chalk.red('Requested range not satisfied by: '),
result.name,
Expand All @@ -71,15 +75,17 @@ var createResultTable = function (caption) {
'to',
chalk.yellow(result.after)
];
} else {
return [
chalk.blue('Kept: '),
result.name,
'at',
chalk.yellow(result.before)
];
}
});
if (onlyChanged) {
return null;
}
return [
chalk.blue('Kept: '),
result.name,
'at',
chalk.yellow(result.before)
];
}).filter(Boolean);
table.push.apply(table, tableRows);
var sortByName = function (a, b) {
return a[1].localeCompare(b[1]);
Expand Down Expand Up @@ -108,6 +114,8 @@ var salita = function salita(dir, options, callback) {
console.log('Found package.json.');
}

var onlyChanged = !!options['only-changed'];

var deps = {
dependencies: 'Dependencies',
devDependencies: 'Development Dependencies',
Expand All @@ -119,7 +127,10 @@ var salita = function salita(dir, options, callback) {
forEach(deps, function (title, key) {
var depLookup = Promise.all(dependenciesLookup(pkg.data, key, options['ignore-stars'], options['ignore-pegged']));
depLookups.push(depLookup);
depPromises.push(depLookup.then(options.json ? createResultJSON(key) : createResultTable(title)));
var create = options.json
? createResultJSON(key, onlyChanged)
: createResultTable(title, onlyChanged);
depPromises.push(depLookup.then(create));
});

// Wait for all of them to resolve.
Expand Down Expand Up @@ -153,6 +164,22 @@ var salita = function salita(dir, options, callback) {
}).done();
};

function isVersionPegged(version) {
try {
var range = semver.Range(version);
return range.set.every(function (comparators) {
return comparators.length === 1 && String(comparators[0].operator || '') === '';
});
} catch (err) {
/*
* semver.Range doesn't support all version specifications (like git
* references), so if it raises an error, assume the dep can be left
* untouched:
*/
return true;
}
}

/**
* createDependenciesLookup
*
Expand Down Expand Up @@ -186,11 +213,7 @@ function dependenciesLookup(pkg, type, ignoreStars, ignorePegged) {
return addUntouched(name, version, { isStar: true });
}

var range = semver.Range(version);
var isPegged = range.set.every(function (comparators) {
return comparators.length === 1 && String(comparators[0].operator || '') === '';
});
if (ignorePegged && isPegged) {
if (ignorePegged && isVersionPegged(version)) {
return addUntouched(name, version, { isPegged: true });
}
return true;
Expand Down Expand Up @@ -258,8 +281,7 @@ function loadNPM() {
* @param {Function} callback - A function to call with the dist tags.
*/
function lookupDistTags(name, callback) {
// Need to require here, because NPM does all sorts of funky global
// attaching.
// Need to require here, because NPM does all sorts of funky global attaching.
var view = require('npm/lib/view');
var prefix = npm.config.get('save-prefix');

Expand Down
28 changes: 15 additions & 13 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "salita",
"bin": "bin/salita",
"version": "0.10.1",
"version": "0.11.1",
"description": "Automatically upgrade all dependencies, devDependencies, and peerDependencies",
"main": "index.js",
"scripts": {
Expand All @@ -19,22 +19,24 @@
"Jordan Harband <ljharb@gmail.com> (https://github.com/ljharb/)"
],
"dependencies": {
"chalk": "^1.1.3",
"chalk": "^2.4.2",
"cli-table": "^0.3.1",
"json-file-plus": "^3.3.0",
"npm": "^3.10.8",
"yargs": "^5.0.0",
"object.assign": "^4.0.4",
"promise": "^7.1.1",
"semver": "^5.3.0",
"for-each": "^0.3.2"
"for-each": "^0.3.3",
"json-file-plus": "^3.3.1",
"npm": "^5.10.0",
"object.assign": "^4.1.0",
"promise": "^8.0.3",
"semver": "^5.7.0",
"yargs": "^10.1.2"
},
"devDependencies": {
"jscs": "^3.0.7",
"eslint": "^3.6.1",
"@ljharb/eslint-config": "^8.0.0"
"@ljharb/eslint-config": "^13.1.1",
"eslint": "^5.16.0",
"jscs": "^3.0.7"
},
"engines": {
"node": ">= 4"
},
"author": "Tim Branyen (@tbranyen)",
"license": "MIT"
}