Skip to content

Commit

Permalink
Migrate uProxy to Typescript v2
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna authored Oct 5, 2016
2 parents 6f90c37 + b310a48 commit 859fb5a
Show file tree
Hide file tree
Showing 41 changed files with 130 additions and 129 deletions.
40 changes: 9 additions & 31 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,38 +636,12 @@ module.exports = function(grunt) {
}
},

// One pass for code running inside freedom.js modules and another
// for code running outside, due to the differences in the meaning
// of the (global) freedom object between the two environments.
ts: {
options: {
target: 'es5',
comments: true,
noImplicitAny: true,
sourceMap: false,
module: 'commonjs',
fast: 'always',
rootDir: '.'
},
moduleEnv: {
src: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/lib/build-tools/**/*',
'!src/integration/**/*',
'!src/**/*.core-env.ts',
'!src/**/*.core-env.spec.ts'
],
outDir: 'build'
},
coreEnv: {
src: [
'src/**/*.core-env.ts',
'src/**/*.core-env.spec.ts',
'!src/lib/build-tools/**/*.ts',
'!src/integration/**/*.ts'
],
outDir: 'build'
default: {
tsconfig: {
tsconfig: 'tsconfig.json',
passThrough: true
}
}
},
browserify: {
Expand Down Expand Up @@ -1400,6 +1374,10 @@ module.exports = function(grunt) {
]);
registerTask(grunt, 'lint', ['jshint', 'tslint']);

grunt.registerTask('printConfig', function() {
grunt.log.writeln(JSON.stringify(grunt.config.getRaw(), null, 2));
});

//-------------------------------------------------------------------------
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-clean');
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@
}
],
"devDependencies": {
"@types/chrome": "0.0.34",
"@types/circular-json": "^0.1.30",
"@types/compare-version": "^0.1.30",
"@types/filesystem": "0.0.28",
"@types/filewriter": "0.0.28",
"@types/jasmine": "^2.2.34",
"@types/ssh2": "0.0.31",
"@types/xregexp": "^3.0.28",
"bower": "^1.4.1",
"browserify-zlib": "^0.1.4",
"cca": "^0.8.0",
"circular-json": "^0.3.0",
"compare-version": "^0.1.2",
"es6-promise": "^3.2.1",
"es6-promise": "^4.0.5",
"forge-min": "^0.6.20",
"freedom": "^0.6.31",
"freedom-for-chrome": "^0.4.25",
Expand Down Expand Up @@ -58,7 +66,7 @@
"grunt-string-replace": "^1.0.0",
"grunt-subgrunt": "^1.2.0",
"grunt-template-jasmine-istanbul": "^0.3.0",
"grunt-ts": "^5.4.0",
"grunt-ts": "^6.0.0-beta.3",
"grunt-tslint": "^3.1.0",
"grunt-verbosity": "^1.0.1",
"grunt-vulcanize": "^0.6.0",
Expand All @@ -73,7 +81,7 @@
"ssh2": "0.5.0",
"time-grunt": "^1.4.0",
"tslint": "^3.10.2",
"typescript": "~1.8.10",
"typescript": "^2.0.3",
"typings": "^1.3.2",
"uparams": "^1.2.0",
"xregexp": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/cca/app/scripts/cordova_core_connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CordovaCoreConnector implements browser_connector.CoreBrowserConnector {
console.log('trying to connect to app');
if (this.status.connected) {
console.warn('Already connected.');
return Promise.resolve<void>();
return Promise.resolve();
}

return this.connect_().then(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/chrome/extension/scripts/chrome_browser_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class ChromeBrowserApi implements BrowserAPI {
} else if (this.popupState_ == PopupState.LAUNCHED) {
// If the popup is already open, simply focus on it.
chrome.windows.update(this.popupWindowId_, {focused: true});
return Promise.resolve<void>();
return Promise.resolve();
} else {
console.log('Waiting for popup to launch...');
return this.onceLaunched_;
Expand Down
2 changes: 1 addition & 1 deletion src/chrome/extension/scripts/chrome_core_connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ChromeCoreConnector implements browser_connector.CoreBrowserConnector {
console.log('trying to connect to app');
if (this.status.connected) {
console.warn('Already connected.');
return Promise.resolve<void>();
return Promise.resolve();
}

return this.connect_().then(this.flushQueue).then(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/firefox/data/scripts/firefox_connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class FirefoxConnector implements browser_connector.CoreBrowserConnector {

public connect = () :Promise<void> => {
this.emit('core_connect');
this.onceConnected = Promise.resolve<void>();
return Promise.resolve<void>();
this.onceConnected = Promise.resolve();
return Promise.resolve();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/generic_core/remote-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var generateProxyingSessionId_ = (): string => {
log.info('proxying session %1 initiated by remote peer', message.proxyingId);
this.proxyingId_ = message.proxyingId;
}
return Promise.resolve<void>();
return Promise.resolve();
}

// Forwards a signalling message to the RemoteConnection.
Expand Down Expand Up @@ -199,7 +199,7 @@ var generateProxyingSessionId_ = (): string => {
public stopShare = () :Promise<void> => {
if (this.localSharingWithRemote === social.SharingState.NONE) {
log.warn('Cannot stop sharing when neither sharing nor trying to share.');
return Promise.resolve<void>();
return Promise.resolve();
}

this.localSharingWithRemote = social.SharingState.NONE;
Expand Down
6 changes: 3 additions & 3 deletions src/generic_core/remote-instance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('remote_instance.RemoteInstance', () => {
expect(aliceState.localGettingFromRemote).toEqual(social.GettingState.NONE);
alice.user.consent.localRequestsAccessFromRemote = true;
alice.wireConsentFromRemote.isOffering = true;
spyOn(socksToRtc, 'start').and.returnValue(Promise.resolve<void>());
spyOn(socksToRtc, 'start').and.returnValue(Promise.resolve());

alice.start().then(() => {
aliceState = alice.currentStateForUi();
Expand Down Expand Up @@ -230,7 +230,7 @@ describe('remote_instance.RemoteInstance', () => {

beforeEach(() => {
alice = new remote_instance.RemoteInstance(user, 'instance-alice');
alice['connection_'].onceSharerCreated = Promise.resolve<void>();
alice['connection_'].onceSharerCreated = Promise.resolve();

user.consent.localGrantsAccessToRemote = true;

Expand Down Expand Up @@ -259,7 +259,7 @@ describe('remote_instance.RemoteInstance', () => {

it('handles signal from server peer as client', (done) => {
alice.wireConsentFromRemote.isOffering = true;
spyOn(socksToRtc, 'start').and.returnValue(Promise.resolve<void>());
spyOn(socksToRtc, 'start').and.returnValue(Promise.resolve());

alice.start().then(() => {
alice.handleSignal({
Expand Down
8 changes: 4 additions & 4 deletions src/generic_core/remote-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ import ui = ui_connector.connector;
// If the remote peer sent signal as the client, we act as server.
if (!this.user.consent.localGrantsAccessToRemote) {
log.warn('Remote side attempted access without permission');
return Promise.resolve<void>();
return Promise.resolve();
}

// Create a new RtcToNet instance each time a new round of client peer
Expand Down Expand Up @@ -289,7 +289,7 @@ import ui = ui_connector.connector;
type: type,
data: signalFromRemote
});
return Promise.resolve<void>();
return Promise.resolve();
}

public verifyUser = (firstMsg ?:any) : void => {
Expand Down Expand Up @@ -381,7 +381,7 @@ import ui = ui_connector.connector;
log.debug('startShare_');
if (this.connection_.localSharingWithRemote === social.SharingState.NONE) {
// Stop any existing sharing attempts with this instance.
sharingStopped = Promise.resolve<void>();
sharingStopped = Promise.resolve();
} else {
// Implies that the SharingState is TRYING_TO_SHARE_ACCESS because
// the client peer should never be able to try to get if they are
Expand Down Expand Up @@ -421,7 +421,7 @@ import ui = ui_connector.connector;
log.debug('stopShare()');
if (this.connection_.localSharingWithRemote === social.SharingState.NONE) {
log.warn('Cannot stop sharing while currently not sharing.');
return Promise.resolve<void>();
return Promise.resolve();
}

if (this.connection_.localSharingWithRemote === social.SharingState.TRYING_TO_SHARE_ACCESS) {
Expand Down
2 changes: 1 addition & 1 deletion src/generic_core/social.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ export function notifyUI(networkName :string, userId :string) {
user.saveToStorage();
// No need to update UI until they accept our invite.
}
return Promise.resolve<void>();
return Promise.resolve();
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/generic_core/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Storage {
return Promise.reject('non-existing key');
}
log.debug('Loaded [%1]: %2', key, result);
return <T>JSON.parse(result);
return Promise.resolve(<T>JSON.parse(result));
});
}

Expand Down Expand Up @@ -80,10 +80,10 @@ export class Storage {
log.debug('Removing key %1 from storage ', key);
return fStorage.remove(key).then((result :string) => {
log.debug('Successfully removed key %1 from storage', key);
return Promise.resolve<void>();
return Promise.resolve();
}).catch((e) => {
log.warn('Destroy operation failed', e.message);
return Promise.resolve<void>();
return Promise.resolve();
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/generic_core/ui_connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ export class UIConnector {
console.warn('Unexpected return value from command ' + cmd + ' with ' +
'no way to send result');
}
return Promise.resolve<void>();
return Promise.resolve();
}

if (!result) {
this.fulfillPromise_(args.promiseId, cmd, null);
log.warn('Handler for command ' + cmd + ' did not return the expected ' +
'value');
return Promise.resolve<void>();
return Promise.resolve();
}

if (!(<Promise<any>>result).then) {
log.warn('Handler for command ' + cmd + ' returned a value instead of ' +
'a promise');
this.fulfillPromise_(args.promiseId, cmd, result);
return Promise.resolve<void>();
return Promise.resolve();
}

return (<Promise<any>>result).then((result?:any) => {
Expand Down
2 changes: 1 addition & 1 deletion src/generic_core/uproxy_core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Core', () => {
network.getUser = null;
network.getStorePath = function() { return 'network-store-path'; };
network['login'] = (loginType :uproxy_core_api.LoginType) => {
return Promise.resolve<void>();
return Promise.resolve();
};
network['myInstance'] =
new local_instance.LocalInstance(network, 'localUserId');
Expand Down
2 changes: 1 addition & 1 deletion src/generic_core/uproxy_core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,6 @@ export class uProxyCore implements uproxy_core_api.CoreApi {
log.info('Successfully logged out of %1 network because roster is empty', network.name);
});
}
return Promise.resolve<void>();
return Promise.resolve();
}
} // class uProxyCore
2 changes: 1 addition & 1 deletion src/generic_ui/polymer/cloud-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Polymer({
}).catch((e: Error) => {
// Locally created cloud server does not exist
// so no need to remove contact
return Promise.resolve<void>();
return Promise.resolve();
});
}).then(() => this.createServer());
},
Expand Down
2 changes: 1 addition & 1 deletion src/generic_ui/polymer/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Polymer({
});
});
}
return Promise.resolve<void>();
return Promise.resolve();
},
ready: function() {
this.ui = ui_context.ui;
Expand Down
2 changes: 1 addition & 1 deletion src/generic_ui/polymer/network-in-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Polymer({
}
}

var confirmLogout = Promise.resolve<void>();
var confirmLogout = Promise.resolve();
if (isGettingForThisNetwork || isSharingForThisNetwork) {
var confirmationMessage = dialogs.getLogoutConfirmationMessage(isGettingForThisNetwork, isSharingForThisNetwork);
confirmLogout = this.$.state.openDialog(dialogs.getConfirmationDialogDescription('', confirmationMessage));
Expand Down
2 changes: 1 addition & 1 deletion src/generic_ui/polymer/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var RTL_LANGUAGES :string[] = ['ar', 'fa', 'ur', 'he'];
// The Promise is fulfilled by default, and also after a
// "core-overlay-open-completed" event is observed.
// The Promise is reset each time we open the dialog.
var reusableDialogClosedPromise = Promise.resolve<void>();
var reusableDialogClosedPromise = Promise.resolve();
var fulfillReusableDialogClosed :Function;

Polymer({
Expand Down
2 changes: 1 addition & 1 deletion src/generic_ui/polymer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Polymer({
var isGetting = ui.isGettingAccess();
var isSharing = ui.isGivingAccess();
var confirmationMessage: string = null;
var confirmLogout = Promise.resolve<void>();
var confirmLogout = Promise.resolve();

if (isGetting || isSharing) {
var confirmationMessage = dialogs.getLogoutConfirmationMessage(ui.isGettingAccess(), ui.isGivingAccess());
Expand Down
2 changes: 1 addition & 1 deletion src/generic_ui/polymer/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Background {
var network = ui_context.model.getNetwork(networkInfo.name);
if (!network) {
console.warn('Network is not logged in');
return Promise.resolve<void>();
return Promise.resolve();
}

network.logoutExpected = true;
Expand Down
4 changes: 2 additions & 2 deletions src/generic_ui/scripts/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export class UserInterface implements ui_constants.UiApi {
return Promise.reject('Error parsing invite token');
}

var getConfirmation = Promise.resolve<void>();
var getConfirmation = Promise.resolve();
if (showConfirmation) {
if (networkName === 'Cloud') {
userName = this.i18n_t('CLOUD_VIRTUAL_MACHINE');
Expand Down Expand Up @@ -556,7 +556,7 @@ export class UserInterface implements ui_constants.UiApi {

if (networkName == 'Cloud') {
// Log into cloud if needed.
var loginPromise = Promise.resolve<void>();
var loginPromise = Promise.resolve();
if (!this.model.getNetwork('Cloud')) {
loginPromise = this.login('Cloud');
}
Expand Down
4 changes: 2 additions & 2 deletions src/integration/integration_test_connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class IntegrationTestConnector implements browser_connector.CoreBrowserConnector
}

public connect = () :Promise<void> => {
this.onceConnected = Promise.resolve<void>();
return Promise.resolve<void>();
this.onceConnected = Promise.resolve();
return Promise.resolve();
}

public onUpdate = (update :uproxy_core_api.Update, handler :Function) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bridge/bridge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import peerconnection_types = require('../webrtc/signals');
// For mocking async functions.
////////

var voidPromise = Promise.resolve<void>();
var voidPromise = Promise.resolve();
var noopPromise = new Promise<void>((F, R) => {});

////////
Expand Down
Loading

0 comments on commit 859fb5a

Please sign in to comment.