Skip to content

Commit

Permalink
build!: update to latest version of gts/typescript
Browse files Browse the repository at this point in the history
BREAKING CHANGE: typescript@3.7 introduced some breaking changes
  • Loading branch information
bcoe committed Mar 23, 2020
1 parent 0d2d3b5 commit f9ae732
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts"
}
15 changes: 0 additions & 15 deletions .eslintrc.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [8, 10, 12, 13]
node: [10, 12, 13]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
Expand Down
8 changes: 5 additions & 3 deletions .prettierignore
@@ -1,3 +1,5 @@
node_modules/*
samples/node_modules/*
src/**/doc/*
**/node_modules
**/.coverage
build/
docs/
protos/
8 changes: 0 additions & 8 deletions .prettierrc

This file was deleted.

17 changes: 17 additions & 0 deletions .prettierrc.js
@@ -0,0 +1,17 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

module.exports = {
...require('gts/.prettierrc.json')
}
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -33,13 +33,14 @@
"@types/node": "^10.5.2",
"@types/sinon": "^7.0.0",
"c8": "^7.0.0",
"chai": "^4.2.0",
"codecov": "^3.0.4",
"gts": "^1.0.0",
"gts": "^2.0.0-alpha.5",
"hard-rejection": "^2.1.0",
"linkinator": "^2.0.0",
"mocha": "^7.0.0",
"mocha": "^7.1.1",
"sinon": "^9.0.0",
"typescript": "3.6.4"
"typescript": "^3.8.3"
},
"engines": {
"node": ">=8.10.0"
Expand Down
1 change: 1 addition & 0 deletions samples/package.json
Expand Up @@ -5,6 +5,7 @@
"engines": {
"node": ">=8"
},
"files": [],
"repository": "googleapis/nodejs-promisify",
"private": true,
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion samples/test/test.js
Expand Up @@ -24,4 +24,3 @@ describe('quickstart samples', () => {
assert.include(stdout, 'Well hello there, nodestronaut!');
});
});

21 changes: 10 additions & 11 deletions src/index.ts
@@ -1,3 +1,5 @@
/* eslint-disable prefer-rest-params */

// Copyright 2014 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -66,8 +68,7 @@ export function promisify(
const slice = Array.prototype.slice;

// tslint:disable-next-line:no-any
const wrapper: any = function(this: WithPromise) {
const context = this;
const wrapper: any = function (this: WithPromise) {
let last;

for (last = arguments.length - 1; last >= 0; last--) {
Expand All @@ -81,7 +82,7 @@ export function promisify(
break; // non-callback last argument found.
}

return originalMethod.apply(context, arguments);
return originalMethod.apply(this, arguments);
}

// peel trailing undefined.
Expand All @@ -93,8 +94,8 @@ export function promisify(
// Because dedupe will likely create a single install of
// @google-cloud/common to be shared amongst all modules, we need to
// localize it at the Service level.
if (context && context.Promise) {
PromiseCtor = context.Promise;
if (this && this.Promise) {
PromiseCtor = this.Promise;
}

return new PromiseCtor((resolve, reject) => {
Expand All @@ -114,7 +115,7 @@ export function promisify(
}
});

originalMethod.apply(context, args);
originalMethod.apply(this, args);
});
};

Expand Down Expand Up @@ -165,16 +166,14 @@ export function callbackify(originalMethod: CallbackMethod) {
}

// tslint:disable-next-line:no-any
const wrapper = function(this: any) {
const context = this;

const wrapper = function (this: any) {
if (typeof arguments[arguments.length - 1] !== 'function') {
return originalMethod.apply(context, arguments);
return originalMethod.apply(this, arguments);
}

const cb = Array.prototype.pop.call(arguments);

originalMethod.apply(context, arguments).then(
originalMethod.apply(this, arguments).then(
// tslint:disable-next-line:no-any
(res: any) => {
res = Array.isArray(res) ? res : [res];
Expand Down
28 changes: 16 additions & 12 deletions test/index.ts
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function,prefer-rest-params */

// Copyright 2014 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,7 +15,7 @@
// limitations under the License.

import * as assert from 'assert';
import {describe, it, afterEach} from 'mocha';
import {describe, it, afterEach, beforeEach} from 'mocha';
import * as sinon from 'sinon';
import * as util from '../src';

Expand All @@ -30,7 +32,7 @@ describe('promisifyAll', () => {
beforeEach(() => {
FakeClass = class {
methodName(callback: Function) {
callback.apply(null, fakeArgs);
callback(...fakeArgs);
}
methodSingle(callback: Function) {
callback(null, fakeArgs[1]);
Expand Down Expand Up @@ -131,7 +133,7 @@ describe('promisify', () => {

beforeEach(() => {
fakeArgs = [null, 1, 2, 3];
func = util.promisify(function(this: {}, callback: () => void) {
func = util.promisify(function (this: {}, callback: () => void) {
// tslint:disable-next-line no-any
(callback as any).apply(this, fakeArgs);
});
Expand All @@ -144,12 +146,14 @@ describe('promisify', () => {
});

it('should not return a promise in callback mode', done => {
let returnVal: {};
returnVal = func.call(fakeContext, function(this: {}) {
const args = [].slice.call(arguments);
// tslint:disable-next-line:no-any
let returnVal: any;
returnVal = func.call(fakeContext, function (this: {}) {
const args = [...arguments];
assert.deepStrictEqual(args, fakeArgs);
assert.strictEqual(this, fakeContext);
assert(!returnVal);
returnVal = null; // this is to suppress prefer-const.
done();
});
});
Expand Down Expand Up @@ -185,7 +189,7 @@ describe('promisify', () => {

func = util.promisify(
(callback: () => void) => {
// tslint:disable-next-line no-any
// tslint:disable-next-line no-any prefer-rest-params
(callback as any).apply(func, [null, fakeArg]);
},
{
Expand Down Expand Up @@ -313,7 +317,7 @@ describe('callbackify', () => {
beforeEach(() => {
fakeArgs = [1, 2, 3];

func = util.callbackify(async function(this: {}) {
func = util.callbackify(async (_this: {}) => {
return fakeArgs;
});
});
Expand All @@ -331,15 +335,15 @@ describe('callbackify', () => {
});

it('should call the callback if it is provided', done => {
func(function(this: {}) {
func(function (this: {}) {
const args = [].slice.call(arguments);
assert.deepStrictEqual(args, [null, ...fakeArgs]);
done();
});
});

it('should call the provided callback with undefined', done => {
func = util.callbackify(async function(this: {}) {});
func = util.callbackify(async (_this: {}) => {});
func((err: Error, resp: {}) => {
assert.strictEqual(err, null);
assert.strictEqual(resp, undefined);
Expand All @@ -348,10 +352,10 @@ describe('callbackify', () => {
});

it('should call the provided callback with null', done => {
func = util.callbackify(async function(this: {}) {
func = util.callbackify(async (_this: {}) => {
return null;
});
func(function(this: {}) {
func(function (this: {}) {
const args = [].slice.call(arguments);
assert.deepStrictEqual(args, [null, null]);
done();
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
@@ -1,6 +1,7 @@
{
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"lib": ["es2018", "dom"],
"rootDir": ".",
"outDir": "build",
},
Expand Down

0 comments on commit f9ae732

Please sign in to comment.