Skip to content

Commit

Permalink
Remove bluebird dependency (#1350)
Browse files Browse the repository at this point in the history
* remove bluebird

* Update source/server.js

Co-authored-by: Jan Pilzer <jan.pilzer@gmx.de>

* use Object.values

* update changelog

Co-authored-by: Jan Pilzer <jan.pilzer@gmx.de>
  • Loading branch information
campersau and Hirse committed May 7, 2020
1 parent ac1ca4f commit 9cc5e35
Show file tree
Hide file tree
Showing 21 changed files with 300 additions and 346 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ We are following the [Keep a Changelog](https://keepachangelog.com/) format.
### Changed
- Migrate clicktests from nightmare to puppeteer [#1336](https://github.com/FredrikNoren/ungit/pull/1336)

### Removed
- Remove bluebird dependency [#1350](https://github.com/FredrikNoren/ungit/pull/1350)

## [1.5.7](https://github.com/FredrikNoren/ungit/compare/v1.5.6...v1.5.7)

### Fixed
Expand Down
28 changes: 13 additions & 15 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const Bluebird = require('bluebird');
const browserify = require('browserify');
const childProcess = require('child_process');
const cliColor = require('ansi-color');
const electronPackager = require('electron-packager');
const path = require('path');
const pkgVersions = require('pkg-versions');
const semver = require('semver');
const fs = require('./source/utils/fs-async');
const maxConcurrency = 5;
const fs = require('fs');

module.exports = (grunt) => {
const packageJson = grunt.file.readJSON('package.json');
Expand Down Expand Up @@ -222,8 +220,8 @@ module.exports = (grunt) => {
});

grunt.registerTask('browserify-components', '', function() {
Bluebird.each(fs.readdirSync('components'), (component) => {
return new Bluebird((resolve, reject) => {
Promise.all(fs.readdirSync('components').map((component) => {
return new Promise((resolve, reject) => {
const src = `./components/${component}/${component}.js`;
if (!fs.existsSync(src)) {
grunt.log.warn(`${src} does not exist. If this component is obsolete, please remove that directory or perform a clean build.`);
Expand All @@ -238,7 +236,7 @@ module.exports = (grunt) => {
outFile.on('close', () => resolve());
b.bundle().pipe(outFile);
});
}).then(this.async());
})).then(this.async());
});

const bumpDependency = (packageJson, packageName) => {
Expand Down Expand Up @@ -286,7 +284,7 @@ module.exports = (grunt) => {
grunt.registerTask('clickParallel', 'Parallelized click tests.', function() {
const done = this.async();

fs.readdirAsync('./clicktests')
fs.promises.readdir('./clicktests')
.then((files) => files.filter((file) => file.startsWith('spec.')))
.then((tests) => {
const genericIndx = tests.indexOf('spec.generic.js');
Expand All @@ -296,12 +294,12 @@ module.exports = (grunt) => {
return tests;
}).then((tests) => {
grunt.log.writeln('Running click tests in parallel... (this will take a while...)');
return Bluebird.map(tests, (file) => {
return Promise.all(tests.map((file) => {
let output = '';
const outStream = (data) => output += data;

grunt.log.writeln(cliColor.set(`Clicktest started! \t${file}`, 'blue'));
return new Bluebird((resolve, reject) => {
return new Promise((resolve, reject) => {
const child = childProcess.execFile('./node_modules/mocha/bin/mocha', [path.join(__dirname, 'clicktests', file), '--timeout=35000', '-b'], { maxBuffer: 10*1024*1024 });
child.stdout.on('data', outStream);
child.stderr.on('data', outStream);
Expand All @@ -316,7 +314,7 @@ module.exports = (grunt) => {
grunt.log.writeln(cliColor.set(`'Clicktest fail! \t'${file}`, 'red'));
return { name: file, output: output, isSuccess: false };
});
}, { concurrency: maxConcurrency });
}));
}).then((results) => {
let isSuccess = true;
results.forEach((result) => {
Expand All @@ -337,14 +335,14 @@ module.exports = (grunt) => {
const tempPackageJson = JSON.parse(JSON.stringify(packageJson));
const keys = Object.keys(tempPackageJson.dependencies).concat(Object.keys(tempPackageJson.devDependencies));

const bumps = Bluebird.map(keys, (dep) => {
const bumps = keys.map((dep) => {
return bumpDependency(tempPackageJson, dep);
});

Bluebird.all(bumps).then(() => {
fs.writeFileSync('package.json', `${JSON.stringify(tempPackageJson, null, 2)}\n`);
grunt.log.writeln('Dependencies bumped, run npm install to install latest versions.');
}).then(() => { done(); }).catch(done);
Promise.all(bumps)
.then(() => fs.promises.writeFile('package.json', `${JSON.stringify(tempPackageJson, null, 2)}\n`))
.then(() => grunt.log.writeln('Dependencies bumped, run npm install to install latest versions.'))
.then(() => { done(); }).catch(done);
});

grunt.registerMultiTask('electron', 'Package Electron apps', function() {
Expand Down
3 changes: 1 addition & 2 deletions components/dialogs/dialogs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

const ko = require('knockout');
const components = require('ungit-components');
const Bluebird = require('bluebird');
const programEvents = require('ungit-program-events');

components.register('formdialog', args => new FormDialogViewModel(args.title));
Expand All @@ -19,7 +18,7 @@ class DialogViewModel {
this.onclose = null;
this.title = ko.observable(title);
this.taDialogName = ko.observable('');
this.closePromise = new Bluebird(resolve => {
this.closePromise = new Promise((resolve) => {
this.onclose = resolve;
});
}
Expand Down
5 changes: 2 additions & 3 deletions components/graph/git-ref.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const ko = require('knockout');
const md5 = require('blueimp-md5');
const promise = require('bluebird');
const octicons = require('octicons');
const programEvents = require('ungit-program-events');
const components = require('ungit-components');
Expand Down Expand Up @@ -152,7 +151,7 @@ class RefViewModel extends Selectable {
let url = this.isTag ? '/tags' : '/branches';
if (this.isRemote) url = `/remote${url}`;

return (isClientOnly ? promise.resolve() : this.server.delPromise(url, { path: this.graph.repoPath(), remote: this.isRemote ? this.remote : null, name: this.refName }))
return (isClientOnly ? Promise.resolve() : this.server.delPromise(url, { path: this.graph.repoPath(), remote: this.isRemote ? this.remote : null, name: this.refName }))
.then(() => {
if (this.node()) this.node().removeRef(this);
this.graph.refs.remove(this);
Expand Down Expand Up @@ -206,7 +205,7 @@ class RefViewModel extends Selectable {
const isRemote = this.isRemoteBranch;
const isLocalCurrent = this.getLocalRef() && this.getLocalRef().current();

return promise.resolve().then(() => {
return Promise.resolve().then(() => {
if (isRemote && !isLocalCurrent) {
return this.server.postPromise('/branches', {
path: this.graph.repoPath(),
Expand Down
63 changes: 31 additions & 32 deletions components/remotes/remotes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const ko = require('knockout');
const _ = require('lodash');
const promise = require('bluebird');
const octicons = require('octicons');
const components = require('ungit-components');
const programEvents = require('ungit-program-events');
Expand Down Expand Up @@ -50,45 +49,45 @@ class RemotesViewModel {
this.isFetching = true;
const tagPromise = options.tags ? this.server.getPromise('/remote/tags', { path: this.repoPath(), remote: this.currentRemote() }) : null;
const fetchPromise = options.nodes ? this.server.postPromise('/fetch', { path: this.repoPath(), remote: this.currentRemote() }) : null;
return promise.props({tag: tagPromise, fetch: fetchPromise})
return Promise.all([tagPromise, fetchPromise])
.then((result) => {
if (options.tags) {
programEvents.dispatch({ event: 'remote-tags-update', tags: result.tag });
programEvents.dispatch({ event: 'remote-tags-update', tags: result[0] });
}
if (!this.server.isInternetConnected) {
this.server.isInternetConnected = true;
}
}).catch((err) => {
let errorMessage;
let stdout;
let stderr;
try {
errorMessage = `Ungit has failed to fetch a remote. ${err.res.body.error}`;
stdout = err.res.body.stdout;
stderr = err.res.body.stderr;
} catch (e) { errorMessage = ''; }
let errorMessage;
let stdout;
let stderr;
try {
errorMessage = `Ungit has failed to fetch a remote. ${err.res.body.error}`;
stdout = err.res.body.stdout;
stderr = err.res.body.stderr;
} catch (e) { errorMessage = ''; }

if (errorMessage.includes('Could not resolve host')) {
if (this.server.isInternetConnected) {
this.server.isInternetConnected = false;
errorMessage = 'Could not resolve host. This usually means you are disconnected from internet and no longer push or fetch from remote. However, Ungit will be functional for local git operations.';
stdout = '';
stderr = '';
} else {
// Message is already seen, just return
return;
if (errorMessage.includes('Could not resolve host')) {
if (this.server.isInternetConnected) {
this.server.isInternetConnected = false;
errorMessage = 'Could not resolve host. This usually means you are disconnected from internet and no longer push or fetch from remote. However, Ungit will be functional for local git operations.';
stdout = '';
stderr = '';
} else {
// Message is already seen, just return
return;
}
}
}

programEvents.dispatch({ event: 'git-error', data: {
isWarning: true,
command: err.res.body.command,
error: err.res.body.error,
stdout,
stderr,
repoPath: err.res.body.workingDirectory
} });
}).finally(() => { this.isFetching = false; });
programEvents.dispatch({ event: 'git-error', data: {
isWarning: true,
command: err.res.body.command,
error: err.res.body.error,
stdout,
stderr,
repoPath: err.res.body.workingDirectory
} });
}).finally(() => { this.isFetching = false; });
}

updateRemotes() {
Expand Down Expand Up @@ -120,7 +119,7 @@ class RemotesViewModel {
components.create('addremotedialog')
.show()
.closeThen((diag) => {
if(diag.isSubmitted()) {
if (diag.isSubmitted()) {
return this.server.postPromise(`/remotes/${encodeURIComponent(diag.name())}`, { path: this.repoPath(), url: diag.url() })
.then(() => { this.updateRemotes(); })
.catch((e) => this.server.unhandledRejection(e));
Expand All @@ -129,7 +128,7 @@ class RemotesViewModel {
}

remoteRemove(remote) {
components.create('yesnodialog', { title: 'Are you sure?', details: `Deleting ${remote.name} remote cannot be undone with ungit.`})
components.create('yesnodialog', { title: 'Are you sure?', details: `Deleting ${remote.name} remote cannot be undone with ungit.` })
.show()
.closeThen((diag) => {
if (diag.result()) {
Expand Down
5 changes: 2 additions & 3 deletions components/staging/staging.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const ko = require('knockout');
const _ = require('lodash');
const promise = require('bluebird');
const octicons = require('octicons');
const components = require('ungit-components');
const programEvents = require('ungit-program-events');
Expand Down Expand Up @@ -113,7 +112,7 @@ class StagingViewModel {
}

refreshContent() {
return promise.all([this.server.getPromise('/head', { path: this.repoPath(), limit: 1 })
return Promise.all([this.server.getPromise('/head', { path: this.repoPath(), limit: 1 })
.then(log => {
if (log.length > 0) {
const array = log[0].message.split('\n');
Expand Down Expand Up @@ -271,7 +270,7 @@ class StagingViewModel {
if (this.commitMessageBody()) commitMessage += `\n\n${this.commitMessageBody()}`;
this.server.postPromise(apiPath, { path: this.repoPath(), message: commitMessage })
.catch((e) => this.server.unhandledRejection(e))
.finally((err) => { this.resetMessages(); });
.finally(() => { this.resetMessages(); });
}

invalidateFilesDiffs() {
Expand Down
3 changes: 1 addition & 2 deletions components/textdiff/textdiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const ko = require('knockout');
const components = require('ungit-components');
const diff2html = require('diff2html');
const promise = require("bluebird");
const sideBySideDiff = 'sidebysidediff';
const textDiff = 'textdiff';

Expand Down Expand Up @@ -125,7 +124,7 @@ class TextDiffViewModel {
}

render() {
return (!this.diffJson ? this.getDiffJson() : promise.resolve())
return (!this.diffJson ? this.getDiffJson() : Promise.resolve())
.then(() => {
if (!this.diffJson || this.diffJson.length == 0) return; // check if diffs are available (binary files do not support them)

Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
},
"dependencies": {
"@primer/octicons": "~9.6.0",
"bluebird": "~3.7.2",
"blueimp-md5": "~2.14.0",
"body-parser": "~1.19.0",
"cookie-parser": "~1.4.5",
Expand Down
4 changes: 0 additions & 4 deletions public/source/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

var programEvents = require('ungit-program-events');
var _ = require('lodash');
var Promise = require("bluebird");
var rootPath = ungit.config && ungit.config.rootPath || '';
var nprogress;
if (ungit.config.isDisableProgressBar) {
Expand Down Expand Up @@ -173,9 +172,6 @@ Server.prototype.delPromise = function(url, arg) {
Server.prototype.putPromise = function(url, arg) {
return this.queryPromise('PUT', url, arg);
}
Server.prototype.emptyPromise = function() {
return Promise.resolve();
}

Server.prototype.unhandledRejection = function(err) {
// Show a error screen for git errors (so that people have a chance to debug them)
Expand Down

0 comments on commit 9cc5e35

Please sign in to comment.