Skip to content

Commit

Permalink
feat: update dependencies and remove vulnerabilities (#86)
Browse files Browse the repository at this point in the history
* npm update

* Manual updates pt. 1

* updtr assisted updates 🎉

* Update eslint-* before --fix

* eslint --fix

* Ignore some eslint issues

* updtr assisted updates pt 2

* Update snapshot

* Another round of self assisted updates

* Update eslint-config-peerigon and turn off `import/extensions`

* And another round of self love

* Revert "Update snapshot"

This reverts commit 9c2d8f4.

* fix: change test expectation to match apparent change in npm outdated

* fix: change introduced single quotes to double quotes

* chore: change travis build node targets

* feat: change babel node target and add nvmrc

* chore: add missing parameter to writeFile in test to trigger intended error

* chore: upgrade appveyor node versions

* feat: testing updtr by upgrading packages

* fix: take suggestion to optimize regex that caused build fail

* chore: attempt to run appveyor only in x86 because that is what it used to be in

* fix: revert regex and eslint disable optimize for that line

* Revert "feat: testing updtr by upgrading packages"

This reverts commit 1ba38b1.

* Revert "Revert "feat: testing updtr by upgrading packages""

This reverts commit 58b0b7a.

* replace EOL character with newline in yarn split

* fixes eslint errors

* npm audit fix

* updtrception

* upgrade standard version

* use named exports of updated sinon

Co-authored-by: tannerbaum <hoisington.tanner@gmail.com>
  • Loading branch information
moritzjacobs and tannerbaum committed Aug 20, 2021
1 parent a47d547 commit eb7a1ef
Show file tree
Hide file tree
Showing 48 changed files with 8,813 additions and 6,320 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"env": {
"node": true
},
"rules": {
"import/extensions": "off"
},
"root": true
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12.20.1
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ language: node_js
os:
- linux
node_js:
- 10
- 8
- 6
- 16
- 14
- 12

script:
- npm install
Expand Down
9 changes: 5 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
environment:
matrix:
- nodejs_version: 8
- nodejs_version: 6
# Node 4 doesn't work because of an AppVeyor bug
# - nodejs_version: 4
- nodejs_version: 14
- nodejs_version: 12

platform:
- x86

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function (api) {
"@babel/preset-env",
{
targets: {
node: 6,
node: 12,
},
},
],
Expand Down
14,860 changes: 8,617 additions & 6,243 deletions package-lock.json

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,42 @@
"updtr": "./bin/updtr"
},
"dependencies": {
"@babel/runtime": "^7.1.2",
"ansi-escapes": "^3.1.0",
"chalk": "^2.4.1",
"cli-cursor": "^2.1.0",
"cli-spinners": "^1.0.0",
"detect-indent": "^5.0.0",
"@babel/runtime": "^7.15.3",
"ansi-escapes": "^4.3.0",
"chalk": "^4.1.2",
"cli-cursor": "^3.1.0",
"cli-spinners": "^2.6.0",
"detect-indent": "^6.0.0",
"es6-error": "^4.0.2",
"pify": "^4.0.0",
"semver": "^5.3.0",
"string-width": "^2.0.0",
"pify": "^4.0.1",
"semver": "^7.3.5",
"string-width": "^4.2.0",
"unicons": "0.0.3",
"yargs": "^12.0.2"
"yargs": "^15.1.0"
},
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/node": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"@babel/core": "^7.15.0",
"@babel/node": "^7.14.9",
"@babel/plugin-transform-runtime": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"@babel/register": "^7.15.3",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"babel-jest": "^27.0.6",
"clone": "^2.1.1",
"cross-env": "^5.0.1",
"eslint": "^5.6.1",
"eslint-config-peerigon": "^15.0.2",
"eslint-plugin-jest": "^21.24.1",
"jest": "^23.6.0",
"rimraf": "^2.6.1",
"rollup": "^0.66.2",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-node-resolve": "^3.0.0",
"sinon": "^6.3.4",
"standard-version": "^4.2.0",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-peerigon": "^25.3.1",
"eslint-plugin-jest": "^23.6.0",
"jest": "^25.1.0",
"rimraf": "^3.0.2",
"rollup": "^1.31.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"sinon": "^8.1.1",
"standard-version": "^9.3.1",
"stream-buffers": "^3.0.1",
"temp": "^0.8.3",
"wrap-ansi": "^4.0.0"
"temp": "^0.9.4",
"wrap-ansi": "^6.2.0"
},
"engines": {
"node": ">= 4.0.0",
Expand Down
10 changes: 10 additions & 0 deletions src/Updtr.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable jsdoc/no-undefined-types */
import EventEmitter from "events";
import path from "path";
import fs from "./util/fs";
Expand Down Expand Up @@ -65,15 +66,19 @@ export default class Updtr extends EventEmitter {

const cwd = config.cwd;
const registry = config.registry;

const packageManager = config.use === undefined ?
USE_OPTIONS[0] :
config.use;

const updateTo = config.updateTo === undefined ?
UPDATE_TO_OPTIONS[0] :
config.updateTo;

const exclude = Array.isArray(config.exclude) === true ?
config.exclude :
[];

const save = config.save === undefined ? SAVE_OPTIONS[0] : config.save;

checkCwd(cwd);
Expand Down Expand Up @@ -101,6 +106,7 @@ export default class Updtr extends EventEmitter {
};
}
}

async canAccessPackageJson() {
let result = true;

Expand All @@ -115,18 +121,22 @@ export default class Updtr extends EventEmitter {

return result;
}

exec(cmd) {
return exec(this.config.cwd, cmd);
}

readFile(filenameInCwd) {
return fs.readFile(path.join(this.config.cwd, filenameInCwd), "utf8");
}

writeFile(filenameInCwd, contents) {
return fs.writeFile(
path.join(this.config.cwd, filenameInCwd),
contents
);
}

dispose() {
this.removeAllListeners();
}
Expand Down
2 changes: 2 additions & 0 deletions src/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {create, run} from "..";
async function start() {
const cwd = process.cwd();
const config = {...argv};

const reporterConfig = {
stream: process.stdout,
testStdout: argv.testStdout,
};

const reporter = reporters[argv.reporter];

config.cwd = cwd;
Expand Down
13 changes: 9 additions & 4 deletions src/exec/parse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {EOL} from "os";

const STRING_PROPERTIES = ["name", "current", "wanted", "latest"];

function isNotEmptyString(value) {
Expand Down Expand Up @@ -53,23 +51,30 @@ function npmParser(stdout) {
return JSON.parse(trimmed);
}

export function splitYarnLines(stdout) {
// Yarn is using \n on all platforms now in their stdout
return stdout.split("\n");
}

function yarnParser(stdout, wantedTypeProperty) {
try {
return npmParser(stdout);
} catch (error) {
/* in some cases (e.g. when printing the outdated result), yarn prints for each line a separate JSON object */
/* in that case, we need to look for a { type: "table" } object which holds the interesting data to display */
}
const dataLine = stdout
.split(EOL)
const dataLine = splitYarnLines(stdout)
.map(line => line.trim())
.filter(line => line !== "")
.find(line => {
try {
console.log(line);
const parsedLine = JSON.parse(line);

return parsedLine.type === wantedTypeProperty;
} catch (error) {
console.log(error);

return false;
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/reporters/util/Indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export default class Indicator {
constructor(initialState) {
this.state = initialState;
}

valueOf() {
return COLORS[this.state](unicons.cli("circle"));
}

toString() {
return this.valueOf();
}
Expand Down
2 changes: 2 additions & 0 deletions src/reporters/util/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default class Message {
this.template = template;
this.variables = variables;
}

valueOf() {
const split = this.template.split(/%s/g);

Expand All @@ -11,6 +12,7 @@ export default class Message {
""
);
}

toString() {
return this.valueOf();
}
Expand Down
2 changes: 2 additions & 0 deletions src/reporters/util/Projector.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class Projector {
this.delay = Math.floor(1000 / frameRate);
this.timeoutId = null;
}

display(frame) {
if (this.timeoutId !== null) {
this.stop();
Expand All @@ -21,6 +22,7 @@ export default class Projector {
this.display(frame);
}, this.delay);
}

stop() {
if (this.timeoutId === null) {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/reporters/util/Spinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export default class Spinner {
this.interval = spinner.interval;
this.length = Math.max(...this.frames.map(frame => frame.length));
}

valueOf() {
const currentInterval = Math.floor(Date.now() / this.interval);
const currentFrame = currentInterval % this.frames.length;

return this.frames[currentFrame];
}

toString() {
return this.valueOf();
}
Expand Down
2 changes: 2 additions & 0 deletions src/reporters/util/Terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class Terminal {
this.hasBeenResized = true;
});
}

append(lines) {
if (lines.length === 0) {
return;
Expand All @@ -44,6 +45,7 @@ export default class Terminal {
this.stream.write(content + "\n");
this.hasBeenResized = false;
}

rewind() {
const removedLines = this.lines.pop();
const rows = calcNumOfRows(removedLines, this.stream.columns);
Expand Down
2 changes: 2 additions & 0 deletions src/reporters/util/configList.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ const configNames = {
updateTo: "update to",
save: "save",
};

const configValues = {
exclude: list => list.join(", "),
};

const configFilter = {
cwd: () => false,
use: option => option !== USE_OPTIONS[0],
Expand Down
2 changes: 2 additions & 0 deletions src/tasks/batchUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function update(sequence, updateTasks) {
success = false;
}

// eslint-disable-next-line require-atomic-updates
sequence.baseEvent.success = success;

if (success === false && updateTasks.length > 1) {
Expand All @@ -58,6 +59,7 @@ export default (async function batchUpdate(updtr, updateTasks) {
const sequence = new Sequence("batch-update", updtr, {
updateTasks,
});

let success = true;

if (updateTasks.length > 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/tasks/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ export default (async function init(updtr) {
outdatedCmd,
stdout.trim()
);

const filterResults = allUpdateTasks.map(updateTask =>
filterUpdateTask(updateTask, updtr.config));

const result = {
updateTasks: allUpdateTasks.filter(
(updateTask, index) => filterResults[index] === null
Expand Down
2 changes: 2 additions & 0 deletions src/tasks/sequentialUpdate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable require-atomic-updates */
import Sequence from "./util/Sequence";
import createUpdateResult from "./util/createUpdateResult";
import updateTo from "./util/updateTo";
Expand Down Expand Up @@ -31,6 +32,7 @@ async function runUpdateTask(sequence, updateTasks, i, previousUpdateResults) {
const updateResults = await previousUpdateResults;
const previousUpdateResult = updateResults[updateResults.length - 1];
const updateTask = updateTasks[i];

// If the previous update was a failure, we don't need to update now because
// during the rollback, the next update is also installed in parallel
const updateNecessary = previousUpdateResult === undefined ?
Expand Down
1 change: 1 addition & 0 deletions src/tasks/updatePackageJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default (async function updatePackageJson(updtr, updateResults) {
},
"Error while trying to read the package.json: "
);

const newPackageJson = createUpdatedPackageJson(
oldPackageJson,
updateResults,
Expand Down
4 changes: 4 additions & 0 deletions src/tasks/util/Sequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export default class Sequence {
this.baseEvent = baseEvent;
this.isRunning = false;
}

start() {
this.isRunning = true;
this.emit("start");
}

emit(eventName, event = {}) {
const fullEventName = this.name + "/" + eventName;

Expand All @@ -22,11 +24,13 @@ export default class Sequence {
...event,
});
}

exec(step, cmd) {
this.emit(step, {cmd});

return this.updtr.exec(cmd);
}

end(result) {
this.emit("end", result);
this.isRunning = false;
Expand Down
1 change: 1 addition & 0 deletions src/tasks/util/createUpdatedPackageJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function createUpdatedPackageJson(
const update = successfulUpdates.find(
({name}) => name === moduleName
);

const oldVersionRange = dependencies[moduleName];

newDependencies[moduleName] = update === undefined ?
Expand Down
Loading

0 comments on commit eb7a1ef

Please sign in to comment.