From 5ed230451b8d813535aa5dce56d9502b77021988 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 21 Nov 2018 13:28:48 -0800 Subject: [PATCH] refactor: reduce the number of dependencies (#222) --- bin/.eslintrc.yml | 3 ++ bin/install-winston2.js | 50 +++++++++++++++++++++++-------- package.json | 27 +++-------------- samples/.eslintrc.yml | 1 + samples/package.json | 2 +- samples/system-test/.eslintrc.yml | 4 --- src/common.ts | 2 +- src/winston2.ts | 4 +-- system-test/.eslintrc.yml | 3 -- system-test/errors-transport.ts | 2 +- 10 files changed, 50 insertions(+), 48 deletions(-) create mode 100644 bin/.eslintrc.yml diff --git a/bin/.eslintrc.yml b/bin/.eslintrc.yml new file mode 100644 index 00000000..a6d2f51f --- /dev/null +++ b/bin/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +rules: + no-process-exit: off diff --git a/bin/install-winston2.js b/bin/install-winston2.js index 43d5b097..0b0c499b 100755 --- a/bin/install-winston2.js +++ b/bin/install-winston2.js @@ -1,19 +1,45 @@ -#!/usr/bin/env node -const fs = require('fs') -const path = require('path') -const spawn = require('child_process').spawn +/** + * Copyright 2018 Google Inc. All Rights Reserved. + * + * 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. + */ -if(fs.existsSync(path.join(__dirname,'..','test','winston-2','node_modules','winston'))){ - process.exit(0) +const fs = require('fs'); +const path = require('path'); +const {spawn} = require('child_process'); + +if ( + fs.existsSync( + path.join(__dirname, '..', 'test', 'winston-2', 'node_modules', 'winston') + ) +) { + process.exit(0); } let proc; -if(process.env.npm_execpath){ - proc = spawn(process.env.NODE||'node',[process.env.npm_execpath,'install'],{cwd:path.join(__dirname,'..','test','winston-2'),stdio:'inherit'}) +if (process.env.npm_execpath) { + proc = spawn( + process.env.NODE || 'node', + [process.env.npm_execpath, 'install'], + {cwd: path.join(__dirname, '..', 'test', 'winston-2'), stdio: 'inherit'} + ); } else { - proc = spawn('npm',['install'],{cwd:path.join(__dirname,'..','test','winston-2'),stdio:'inherit'}) + proc = spawn('npm', ['install'], { + cwd: path.join(__dirname, '..', 'test', 'winston-2'), + stdio: 'inherit', + }); } -proc.on('close',(code)=>{ - process.exit(code||0) -}) +proc.on('close', code => { + process.exit(code || 0); +}); diff --git a/package.json b/package.json index 40a01cb4..199d65a0 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,6 @@ "files": [ "build/src", "!build/src/**/*.map", - "AUTHORS", - "CONTRIBUTORS", - "LICENSE", - "README.md", "CODE_OF_CONDUCT.md" ], "keywords": [ @@ -38,8 +34,7 @@ "scripts": { "docs": "jsdoc -c .jsdoc.js", "generate-scaffolding": "repo-tools generate all --except lib_readme", - "lint": "eslint samples/", - "prettier": "prettier --write samples/*.js samples/*/*.js", + "lint": "gts check && eslint '**/*.js'", "presamples-test": "npm run compile", "samples-test": "cd samples/ && npm link ../ && npm test && cd ../", "presystem-test": "npm run pretest", @@ -49,34 +44,27 @@ "clean": "gts clean", "compile": "tsc -p .", "postcompile": "cpy ./src/types/* ./build/src/types", - "fix": "gts fix", + "fix": "gts fix && eslint --fix '**/*.js'", "prepare": "npm run compile", "pretest": "npm run compile && node ./bin/install-winston2.js", "posttest": "npm run check" }, "dependencies": { "@google-cloud/logging": "^4.0.1", - "@sindresorhus/is": "^0.13.0", "lodash.mapvalues": "^4.6.0", - "logform": "^1.9.1", + "logform": "^1.10.0", "semver": "^5.5.1", "winston-transport": "^4.2.0" }, "devDependencies": { "@google-cloud/common": "^0.26.0", "@google-cloud/nodejs-repo-tools": "^3.0.0", - "@types/glob": "^7.0.0", - "@types/is": "0.0.21", "@types/lodash.mapvalues": "^4.6.3", "@types/mocha": "^5.2.3", - "@types/ncp": "^2.0.1", "@types/node": "^10.3.6", - "@types/once": "^1.4.0", - "@types/pify": "^3.0.2", "@types/proxyquire": "^1.3.28", - "@types/rimraf": "^2.0.2", + "@types/request": "^2.48.1", "@types/semver": "^5.5.0", - "@types/tmp": "0.0.33", "@types/uuid": "^3.4.4", "codecov": "^3.0.2", "cpy-cli": "^2.0.0", @@ -85,23 +73,16 @@ "eslint-config-prettier": "^3.0.0", "eslint-plugin-node": "^8.0.0", "eslint-plugin-prettier": "^3.0.0", - "glob": "^7.1.2", "gts": "^0.9.0", "ink-docstrap": "^1.3.2", "intelli-espower-loader": "^1.0.1", "jsdoc": "^3.5.5", "mocha": "^5.2.0", - "ncp": "^2.0.0", - "once": "^1.4.0", - "pify": "^4.0.0", "post-install-check": "0.0.1", "prettier": "^1.13.6", - "request": "^2.88.0", "require-inject": "^1.4.3", - "rimraf": "^2.6.2", "source-map-support": "^0.5.6", "teeny-request": "^3.6.0", - "tmp": "0.0.33", "typescript": "^3.0.0", "uuid": "^3.3.2", "winston": "^3.1.0" diff --git a/samples/.eslintrc.yml b/samples/.eslintrc.yml index 282535f5..0aa37ac6 100644 --- a/samples/.eslintrc.yml +++ b/samples/.eslintrc.yml @@ -1,3 +1,4 @@ --- rules: no-console: off + node/no-missing-require: off diff --git a/samples/package.json b/samples/package.json index eab11f8d..c27c285a 100644 --- a/samples/package.json +++ b/samples/package.json @@ -1,6 +1,6 @@ { "name": "nodejs-docs-samples-logging-winston", - "version": "0.0.1", + "files": ["*.js"], "private": true, "license": "Apache-2.0", "author": "Google Inc.", diff --git a/samples/system-test/.eslintrc.yml b/samples/system-test/.eslintrc.yml index 75216436..6db2a46c 100644 --- a/samples/system-test/.eslintrc.yml +++ b/samples/system-test/.eslintrc.yml @@ -1,7 +1,3 @@ --- env: mocha: true -rules: - node/no-unpublished-require: off - node/no-unsupported-features: off - no-empty: off diff --git a/src/common.ts b/src/common.ts index 180de911..e0f3fc60 100644 --- a/src/common.ts +++ b/src/common.ts @@ -18,7 +18,7 @@ import * as util from 'util'; import * as types from './types/core'; const {Logging} = require('@google-cloud/logging'); -const mapValues = require('lodash.mapvalues'); +import mapValues = require('lodash.mapvalues'); type Callback = (err: Error, apiResponse: {}) => void; diff --git a/src/winston2.ts b/src/winston2.ts index d0b1e450..b0ef75ac 100644 --- a/src/winston2.ts +++ b/src/winston2.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -import * as is from '@sindresorhus/is'; - import {LOGGING_TRACE_KEY, LoggingCommon} from './common'; import * as types from './types/core'; @@ -45,7 +43,7 @@ export class LoggingWinston extends winston.Transport { log(levelName: string, msg: string, metadata: types.Metadata, callback: Callback) { - if (is.default.function_(metadata)) { + if (typeof metadata === 'function') { callback = metadata as Callback; metadata = {}; } diff --git a/system-test/.eslintrc.yml b/system-test/.eslintrc.yml index 2e6882e4..6db2a46c 100644 --- a/system-test/.eslintrc.yml +++ b/system-test/.eslintrc.yml @@ -1,6 +1,3 @@ --- env: mocha: true -rules: - node/no-unpublished-require: off - no-console: off diff --git a/system-test/errors-transport.ts b/system-test/errors-transport.ts index 91a9d65f..42ced97b 100644 --- a/system-test/errors-transport.ts +++ b/system-test/errors-transport.ts @@ -16,7 +16,7 @@ import * as common from '@google-cloud/common'; import delay from 'delay'; -import * as request from 'request'; +import * as request from 'request'; // types only import {teenyRequest} from 'teeny-request'; const packageJson = require('../../package.json');