Skip to content

Commit afe72ad

Browse files
committed
chore: make the code compatible with node 10.0.0
- Replace new Buffer() with Buffer.from() - Work around nodejs/node#20278 - Upgrade to source-map-support@0.5.5
1 parent 49b9a82 commit afe72ad

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

packages/authentication/test/acceptance/basic-auth.acceptance.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Basic Authentication', () => {
4848
const client = whenIMakeRequestTo(server);
4949
const credential =
5050
users.list.joe.profile.id + ':' + users.list.joe.password;
51-
const hash = new Buffer(credential).toString('base64');
51+
const hash = Buffer.from(credential).toString('base64');
5252
await client
5353
.get('/whoAmI')
5454
.set('Authorization', 'Basic ' + hash)
@@ -58,7 +58,7 @@ describe('Basic Authentication', () => {
5858
it('returns error for invalid credentials', async () => {
5959
const client = whenIMakeRequestTo(server);
6060
const credential = users.list.Simpson.profile.id + ':' + 'invalid';
61-
const hash = new Buffer(credential).toString('base64');
61+
const hash = Buffer.from(credential).toString('base64');
6262
await client
6363
.get('/whoAmI')
6464
.set('Authorization', 'Basic ' + hash)

packages/boot/src/booters/booter-utils.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ export function isClass(target: any): target is Constructor<any> {
4545
export function loadClassesFromFiles(files: string[]): Constructor<{}>[] {
4646
const classes: Array<Constructor<{}>> = [];
4747
for (const file of files) {
48-
const data = require(file);
49-
for (const cls of Object.values(data)) {
50-
if (isClass(cls)) {
51-
classes.push(cls);
48+
const moduleObj = require(file);
49+
// WORKAROUND: use `for in` instead of Object.values().
50+
// See https://github.com/nodejs/node/issues/20278
51+
for (const k in moduleObj) {
52+
const exported = moduleObj[k];
53+
if (isClass(exported)) {
54+
classes.push(exported);
5255
}
5356
}
5457
}

packages/build/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"nyc": "^11.7.1",
2424
"prettier": "^1.12.1",
2525
"rimraf": "^2.6.2",
26-
"source-map-support": "^0.5.4",
26+
"source-map-support": "^0.5.5",
2727
"strong-docs": "^1.10.2",
2828
"tslint": "^5.9.1",
2929
"typescript": "^2.8.1"

packages/repository/test/unit/type/type.unit.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ describe('types', () => {
231231
describe('buffer', () => {
232232
const bufferType = new types.BufferType();
233233
it('checks isInstance', () => {
234-
expect(bufferType.isInstance(new Buffer([1]))).to.be.true();
235-
expect(bufferType.isInstance(new Buffer('123'))).to.be.true();
234+
expect(bufferType.isInstance(Buffer.from([1]))).to.be.true();
235+
expect(bufferType.isInstance(Buffer.from('123'))).to.be.true();
236236
expect(bufferType.isInstance('str')).to.be.false();
237237
expect(bufferType.isInstance(null)).to.be.true();
238238
expect(bufferType.isInstance(undefined)).to.be.true();
@@ -248,7 +248,7 @@ describe('types', () => {
248248
expect(bufferType.isCoercible('str')).to.be.true();
249249
expect(bufferType.isCoercible(null)).to.be.true();
250250
expect(bufferType.isCoercible(undefined)).to.be.true();
251-
expect(bufferType.isCoercible(new Buffer('12'))).to.be.true();
251+
expect(bufferType.isCoercible(Buffer.from('12'))).to.be.true();
252252
expect(bufferType.isCoercible([1, 2])).to.be.true();
253253
expect(bufferType.isCoercible({x: 1})).to.be.false();
254254
expect(bufferType.isCoercible(1)).to.be.false();
@@ -260,11 +260,11 @@ describe('types', () => {
260260
});
261261

262262
it('coerces values', () => {
263-
expect(bufferType.coerce('str').equals(new Buffer('str'))).to.be.true();
263+
expect(bufferType.coerce('str').equals(Buffer.from('str'))).to.be.true();
264264
expect(bufferType.coerce([1]).equals(Buffer.from([1]))).to.be.true();
265265
expect(bufferType.coerce(null)).to.equal(null);
266266
expect(bufferType.coerce(undefined)).to.equal(undefined);
267-
const buf = new Buffer('12');
267+
const buf = Buffer.from('12');
268268
expect(bufferType.coerce(buf)).exactly(buf);
269269
expect(() => bufferType.coerce(1)).to.throw(/Invalid buffer/);
270270
expect(() => bufferType.coerce(new Date())).to.throw(/Invalid buffer/);
@@ -274,9 +274,9 @@ describe('types', () => {
274274

275275
it('serializes values', () => {
276276
expect(
277-
bufferType.serialize(new Buffer('str'), {encoding: 'utf-8'}),
277+
bufferType.serialize(Buffer.from('str'), {encoding: 'utf-8'}),
278278
).to.eql('str');
279-
expect(bufferType.serialize(new Buffer('str'))).to.eql('c3Ry');
279+
expect(bufferType.serialize(Buffer.from('str'))).to.eql('c3Ry');
280280
expect(bufferType.serialize(null)).null();
281281
expect(bufferType.serialize(undefined)).undefined();
282282
});
@@ -293,7 +293,7 @@ describe('types', () => {
293293
expect(anyType.isInstance([1, 2])).to.be.true();
294294
expect(anyType.isInstance(1)).to.be.true();
295295
expect(anyType.isInstance(new Date())).to.be.true();
296-
expect(anyType.isInstance(new Buffer('123'))).to.be.true();
296+
expect(anyType.isInstance(Buffer.from('123'))).to.be.true();
297297
});
298298

299299
it('checks isCoercible', () => {
@@ -305,7 +305,7 @@ describe('types', () => {
305305
expect(anyType.isCoercible(1)).to.be.true();
306306
expect(anyType.isCoercible([1, '2'])).to.be.true();
307307
expect(anyType.isCoercible(new Date())).to.be.true();
308-
expect(anyType.isCoercible(new Buffer('123'))).to.be.true();
308+
expect(anyType.isCoercible(Buffer.from('123'))).to.be.true();
309309
});
310310

311311
it('creates defaultValue', () => {
@@ -324,7 +324,7 @@ describe('types', () => {
324324
expect(anyType.coerce(1)).to.equal(1);
325325
const date = new Date();
326326
expect(anyType.coerce(date)).to.equal(date);
327-
const buf = new Buffer('12');
327+
const buf = Buffer.from('12');
328328
expect(anyType.coerce(buf)).to.equal(buf);
329329
});
330330

0 commit comments

Comments
 (0)