Skip to content

Commit

Permalink
build: replace/remove node6 promisify helpers
Browse files Browse the repository at this point in the history
Co-authored-by: Taranveer Virk <[email protected]>
  • Loading branch information
biniam and virkt25 committed Feb 1, 2018
1 parent 5471694 commit df338ad
Show file tree
Hide file tree
Showing 11 changed files with 7 additions and 68 deletions.
3 changes: 0 additions & 3 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"packages/example-codehub/src/**",
"packages/*/dist*/*"
],
"exclude": [
"packages/core/*/promisify.*"
],
"extension": [
".js",
".ts"
Expand Down
1 change: 0 additions & 1 deletion packages/cli/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"lib/base-generator.js",
"lib/debug.js",
"lib/project-generator.js",
"lib/promisify.js",
"lib/utils.js"
],
"codeSectionDepth": 4
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/generators/example/clone-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

'use strict';

const promisify = require('../../lib/utils').promisify;

const gunzip = require('gunzip-maybe');
const path = require('path');
const request = require('request');
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const util = require('util');
const regenerate = require('regenerate');
const _ = require('lodash');
const pascalCase = require('change-case').pascalCase;
const promisify = util.promisify || require('util.promisify/implementation');
const promisify = require('util').promisify;
const camelCase = require('change-case').camelCase;
const validate = require('validate-npm-package-name');
const Conflicter = require('yeoman-generator/lib/util/conflicter');
Expand Down
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"request": "^2.83.0",
"tar-fs": "^1.16.0",
"unicode-10.0.0": "^0.7.4",
"util.promisify": "^1.0.0",
"validate-npm-package-name": "^3.0.0",
"yeoman-generator": "^2.0.1"
},
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/test/clone-example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@

('use strict');

const promisify = require('../lib/utils').promisify;
const promisify = require('util').promisify;

const cloneExampleFromGitHub = require('../generators/example/clone-example');
const expect = require('@loopback/testlab').expect;
const TestSandbox = require('@loopback/testlab').TestSandbox;
const fs = require('fs');
const glob = promisify(require('glob'));
const path = require('path');
const rimraf = promisify(require('rimraf'));

const VALID_EXAMPLE = 'getting-started';
const SANDBOX_PATH = path.resolve(__dirname, 'sandbox');
Expand Down
1 change: 0 additions & 1 deletion packages/core/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"src/component.ts",
"src/index.ts",
"src/keys.ts",
"src/promisify.ts",
"src/server.ts"
],
"codeSectionDepth": 4
Expand Down
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"dependencies": {
"@loopback/context": "^4.0.0-alpha.29",
"lodash": "^4.17.4",
"topo": "^3.0.0",
"util.promisify": "^1.0.0"
"topo": "^3.0.0"
},
"devDependencies": {
"@loopback/build": "^4.0.0-alpha.12",
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ export {Component, ProviderMap} from './component';
export {inject, Context} from '@loopback/context';
export {Server} from './server';
export * from './application';
export * from './promisify';
export * from './component';
export * from './keys';
40 changes: 0 additions & 40 deletions packages/core/src/promisify.ts

This file was deleted.

17 changes: 4 additions & 13 deletions packages/rest/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import {ServerRequest} from 'http';
import * as HttpErrors from 'http-errors';
import {OperationObject, ParameterObject} from '@loopback/openapi-spec';
import {promisify} from '@loopback/core';
import {promisify} from 'util';
import {
OperationArgs,
ParsedRequest,
Expand All @@ -15,19 +15,10 @@ import {
import {ResolvedRoute} from './router/routing-table';
type HttpError = HttpErrors.HttpError;

type jsonBodyFn = (
req: ServerRequest,
cb: (err?: Error, body?: {}) => void,
) => void;
const jsonBody: jsonBodyFn = require('body/json');

// tslint:disable:no-any
// tslint:disable-next-line:no-any
type MaybeBody = any | undefined;
// tslint:enable:no-any

const parseJsonBody: (req: ServerRequest) => Promise<MaybeBody> = promisify(
jsonBody,
);
const jsonBodyAsync = promisify(require('body/json'));

/**
* Get the content-type header value from the request
Expand Down Expand Up @@ -76,7 +67,7 @@ function loadRequestBodyIfNeeded(
return Promise.reject(err);
}

return parseJsonBody(request).catch((err: HttpError) => {
return jsonBodyAsync(request).catch((err: HttpError) => {
err.statusCode = 400;
return Promise.reject(err);
});
Expand Down

0 comments on commit df338ad

Please sign in to comment.