Skip to content

Commit

Permalink
refactor: drop dependency on extend (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Nov 9, 2018
1 parent 377fbaa commit e4a5a61
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 41 deletions.
5 changes: 2 additions & 3 deletions packages/google-cloud-resourcemanager/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules/*
samples/node_modules/*
src/**/doc/*
**/node_modules
docs/
build/
2 changes: 1 addition & 1 deletion packages/google-cloud-resourcemanager/.jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
source: {
excludePattern: '(^|\\/|\\\\)[._]',
include: [
'src'
'build/src'
],
includePattern: '\\.js$'
},
Expand Down
12 changes: 7 additions & 5 deletions packages/google-cloud-resourcemanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@
"scripts": {
"docs": "jsdoc -c .jsdoc.js",
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
"lint": "npm run check && eslint samples/",
"prettier": "prettier --write samples/*.js samples/*/*.js",
"lint": "npm run check && eslint '**/*.js'",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"system-test": "mocha build/system-test --timeout 600000",
"codecov": "nyc report --reporter=json && codecov -f .coverage/*.json",
"test": "nyc mocha build/test",
"check": "gts check",
"clean": "gts clean",
"compile": "tsc -p .",
"fix": "eslint 'samples/**/*.js' --fix && npm run prettier && gts fix",
"fix": "eslint '**/*.js' --fix && gts fix",
"prepare": "npm run compile",
"pretest": "npm run compile",
"presystem-test": "npm run compile"
Expand All @@ -50,13 +49,11 @@
"@google-cloud/common": "^0.26.0",
"@google-cloud/paginator": "^0.1.0",
"@google-cloud/promisify": "^0.3.0",
"extend": "^3.0.0",
"teeny-request": "^3.6.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^2.2.4",
"@types/arrify": "^1.0.4",
"@types/extend": "^3.0.0",
"@types/mocha": "^5.2.5",
"@types/proxyquire": "^1.3.28",
"@types/request": "^2.47.1",
Expand All @@ -79,5 +76,10 @@
"source-map-support": "^0.5.6",
"typescript": "~3.1.0",
"uuid": "^3.0.1"
},
"nyc": {
"exclude": [
"build/test"
]
}
}
1 change: 1 addition & 0 deletions packages/google-cloud-resourcemanager/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "Apache-2.0",
"author": "Google LLC",
"repository": "googleapis/nodejs-resource",
"files": ["*.js"],
"engines": {
"node": ">=8"
},
Expand Down
12 changes: 5 additions & 7 deletions packages/google-cloud-resourcemanager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
* limitations under the License.
*/

'use strict';

import {Service, Operation, GoogleAuthOptions} from '@google-cloud/common';
import {GoogleAuthOptions, Operation, Service} from '@google-cloud/common';
import {paginator} from '@google-cloud/paginator';
import {promisifyAll} from '@google-cloud/promisify';
import * as extend from 'extend';
import {Project} from './project';
import * as r from 'request'; // Only for type declarations.
import {teenyRequest} from 'teeny-request';

import {Project} from './project';

export type CreateProjectCallback =
(err: Error|null, project?: Project|null, operation?: Operation,
apiResponse?: r.Response) => void;
Expand Down Expand Up @@ -259,7 +257,7 @@ class Resource extends Service {
{
method: 'POST',
uri: '/projects',
json: extend({}, options, {
json: Object.assign({}, options, {
projectId: id,
}),
},
Expand Down Expand Up @@ -350,7 +348,7 @@ class Resource extends Service {
let nextQuery: GetProjectOptions;

if (resp.nextPageToken) {
nextQuery = extend({}, options, {
nextQuery = Object.assign({}, options, {
pageToken: resp.nextPageToken,
});
}
Expand Down
5 changes: 1 addition & 4 deletions packages/google-cloud-resourcemanager/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@

logging.basicConfig(level=logging.DEBUG)
common_templates = gcp.CommonTemplates()
templates = common_templates.node_library(
package_name="@google-cloud/resource",
repo_name="googleapis/nodejs-resource"
)
templates = common_templates.node_library(source_location="build/src")
s.copy(templates)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
env:
mocha: true
rules:
node/no-unpublished-require: off
no-console: off
2 changes: 0 additions & 2 deletions packages/google-cloud-resourcemanager/test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
---
env:
mocha: true
rules:
node/no-unpublished-require: off
19 changes: 9 additions & 10 deletions packages/google-cloud-resourcemanager/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
* limitations under the License.
*/

'use strict';

import {DecorateRequestOptions, Operation, util} from '@google-cloud/common';
import * as arrify from 'arrify';
import * as assert from 'assert';
import * as extend from 'extend';
import * as proxyquire from 'proxyquire';
import {util, DecorateRequestOptions, Operation} from '@google-cloud/common';
import {Response} from 'request';
import {teenyRequest} from 'teeny-request';

import {Project} from '../src';
import {Response} from 'request';

class FakeOperation {
calledWith_: IArguments;
Expand Down Expand Up @@ -78,15 +76,15 @@ const fakePromisify = {
};

let makeAuthenticatedRequestFactoryOverride: Function|null;
const fakeUtil = extend({}, util, {
const fakeUtil = Object.assign({}, util, {
makeAuthenticatedRequestFactory() {
if (makeAuthenticatedRequestFactoryOverride) {
return makeAuthenticatedRequestFactoryOverride.apply(null, arguments);
}
return util.makeAuthenticatedRequestFactory.apply(null, arguments);
},
});
const originalFakeUtil = extend(true, {}, fakeUtil);
const originalFakeUtil = Object.assign({}, fakeUtil);

describe('Resource', () => {
const PROJECT_ID = 'test-project-id';
Expand All @@ -111,7 +109,7 @@ describe('Resource', () => {
});

beforeEach(() => {
extend(fakeUtil, originalFakeUtil);
Object.assign(fakeUtil, originalFakeUtil);
makeAuthenticatedRequestFactoryOverride = null;

resource = new Resource({
Expand Down Expand Up @@ -151,7 +149,8 @@ describe('Resource', () => {
describe('createProject', () => {
const NEW_PROJECT_ID = 'new-project-id';
const OPTIONS = {a: 'b', c: 'd'};
const EXPECTED_BODY = extend({}, OPTIONS, {projectId: NEW_PROJECT_ID});
const EXPECTED_BODY =
Object.assign({}, OPTIONS, {projectId: NEW_PROJECT_ID});

it('should not require any options', done => {
const expectedBody = {projectId: NEW_PROJECT_ID};
Expand Down Expand Up @@ -295,7 +294,7 @@ describe('Resource', () => {

it('should build a nextQuery if necessary', done => {
const nextPageToken = 'next-page-token';
const apiResponseWithNextPageToken = extend({}, apiResponse, {
const apiResponseWithNextPageToken = Object.assign({}, apiResponse, {
nextPageToken,
});
const expectedNextQuery = {
Expand Down
13 changes: 5 additions & 8 deletions packages/google-cloud-resourcemanager/test/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
* limitations under the License.
*/

'use strict';

import {DecorateRequestOptions, ServiceObject, ServiceObjectConfig, util} from '@google-cloud/common';
import * as promisify from '@google-cloud/promisify';
import * as assert from 'assert';
import * as extend from 'extend';
import * as proxyquire from 'proxyquire';
import {ServiceObject, util, ServiceObjectConfig, DecorateRequestOptions} from '@google-cloud/common';
import * as promisify from '@google-cloud/promisify';
import {RequestCallback, Response} from 'request';
import {Response} from 'request';

let promisified = false;
const fakePromisify = extend({}, promisify, {
const fakePromisify = Object.assign({}, promisify, {
// tslint:disable-next-line variable-name
promisifyAll(Class: Function) {
if (Class.name === 'Project') {
Expand Down Expand Up @@ -67,7 +64,7 @@ describe('Project', () => {

describe('instantiation', () => {
it('should inherit from ServiceObject', done => {
const resourceInstance = extend({}, RESOURCE, {
const resourceInstance = Object.assign({}, RESOURCE, {
createProject: {
bind(context: {}) {
assert.strictEqual(context, resourceInstance);
Expand Down

0 comments on commit e4a5a61

Please sign in to comment.