Skip to content

Commit

Permalink
chore(dep)!: upgrade typescript/gts (#97)
Browse files Browse the repository at this point in the history
BFREAKING CHANGE: typescript@3.7.x introduces breaking changes in generated code
  • Loading branch information
summer-ji-eng committed Mar 26, 2020
1 parent 4c4cd2d commit 59ca2de
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
**/node_modules
src/**/doc/*
**/.coverage
build/
docs/
protos/
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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@v2
- uses: actions/setup-node@v1
Expand Down
8 changes: 5 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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')
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"@types/mocha": "^7.0.0",
"@types/node": "^10.5.2",
"@types/sinon": "^7.0.5",
"c8": "^7.0.0",
"codecov": "^3.0.4",
"gts": "^1.0.0",
"gts": "next",
"mocha": "^7.0.0",
"c8": "^7.0.0",
"sinon": "^9.0.0",
"typescript": "3.6.4"
"typescript": "^3.8.3"
},
"engines": {
"node": ">=10"
"node": ">=10.4.0"
}
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export class PreciseDate extends Date {
return;
}

// eslint-disable-next-line prefer-rest-params
const args: number[] = Array.from(arguments);
const dateFields = args.slice(0, 7) as DateFields;
const date = new Date(...dateFields);
Expand Down Expand Up @@ -302,7 +303,7 @@ export class PreciseDate extends Date {

const sign = Math.sign(Number(time));

time = time.replace(/^\-/, '');
time = time.replace(/^-/, '');

const seconds = Number(time.substr(0, time.length - 9)) * sign;
const nanos = Number(time.substr(-9)) * sign;
Expand Down
18 changes: 10 additions & 8 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import * as assert from 'assert';
import {describe, it} from 'mocha';
import {describe, it, before, beforeEach, after, afterEach} from 'mocha';
import * as sinon from 'sinon';

import {DateTuple, PreciseDate} from '../src';
Expand All @@ -34,7 +34,7 @@ function bigIntFactory(value: number | string): FakeBigInt {
// while BigInt can't be used as a constructor, Node 11+ will attempt to read
// members from its prototype chain. We could declare FakeBigInt as a function
// prototype but that seems to be difficult (impossible?) to do in TypeScript.
bigIntFactory.prototype.valueOf = function(): number | string {
bigIntFactory.prototype.valueOf = function (): number | string {
return this.value;
};

Expand All @@ -56,7 +56,7 @@ describe('PreciseDate', () => {
let RealBigInt: typeof BigInt;
let date: PreciseDate;

const NO_BIG_INT_ERR = /BigInt only available in Node \>\= v10\.7. Consider using getFullTimeString instead\./;
const NO_BIG_INT_ERR = /BigInt only available in Node >= v10\.7. Consider using getFullTimeString instead\./;

const SECS = 1547253035;
const NANOS = 381101032;
Expand All @@ -77,18 +77,18 @@ describe('PreciseDate', () => {
const NANOSECONDS = 32;

before(() => {
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
RealBigInt = (global as any).BigInt;
});

beforeEach(() => {
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).BigInt = bigIntFactory;
date = new PreciseDate(TIME_STRING);
});

after(() => {
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).BigInt = RealBigInt;
});

Expand All @@ -104,6 +104,7 @@ describe('PreciseDate', () => {
.withArgs(TIME_STRING)
.returns(fakeTimestamp);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const date = new PreciseDate(TIME_STRING);
const [timestamp] = setStub.lastCall.args;
assert.strictEqual(timestamp, fakeTimestamp);
Expand All @@ -114,6 +115,7 @@ describe('PreciseDate', () => {
const microsStub = sandbox.stub(PreciseDate.prototype, 'setMicroseconds');
const nanosStub = sandbox.stub(PreciseDate.prototype, 'setNanoseconds');

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const date = new PreciseDate(
YEAR,
MONTH,
Expand Down Expand Up @@ -141,7 +143,7 @@ describe('PreciseDate', () => {
});

it('should throw an error if BigInt is unavailable', () => {
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (global as any).BigInt;

assert.throws(() => date.getFullTime(), NO_BIG_INT_ERR);
Expand Down Expand Up @@ -453,7 +455,7 @@ describe('PreciseDate', () => {

describe('.fullUTC()', () => {
it('should throw an error if BigInt is unavailable', () => {
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (global as any).BigInt;

assert.throws(() => PreciseDate.fullUTC(), NO_BIG_INT_ERR);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"rootDir": ".",
"outDir": "build",
"lib": [
"es2016",
"es2018",
"esnext.bigint"
]
},
Expand Down

0 comments on commit 59ca2de

Please sign in to comment.