Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make the code compatible with node 10.0.0 #1281

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Basic Authentication', () => {
const client = whenIMakeRequestTo(server);
const credential =
users.list.joe.profile.id + ':' + users.list.joe.password;
const hash = new Buffer(credential).toString('base64');
const hash = Buffer.from(credential).toString('base64');
await client
.get('/whoAmI')
.set('Authorization', 'Basic ' + hash)
Expand All @@ -58,7 +58,7 @@ describe('Basic Authentication', () => {
it('returns error for invalid credentials', async () => {
const client = whenIMakeRequestTo(server);
const credential = users.list.Simpson.profile.id + ':' + 'invalid';
const hash = new Buffer(credential).toString('base64');
const hash = Buffer.from(credential).toString('base64');
await client
.get('/whoAmI')
.set('Authorization', 'Basic ' + hash)
Expand Down
11 changes: 7 additions & 4 deletions packages/boot/src/booters/booter-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ export function isClass(target: any): target is Constructor<any> {
export function loadClassesFromFiles(files: string[]): Constructor<{}>[] {
const classes: Array<Constructor<{}>> = [];
for (const file of files) {
const data = require(file);
for (const cls of Object.values(data)) {
if (isClass(cls)) {
classes.push(cls);
const moduleObj = require(file);
// WORKAROUND: use `for in` instead of Object.values().
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the issue is fixed, I don't think we need to change this back ... it works the same so I would propose removing the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of the comment is recording keeping. When developers blame the git history, they will know why the change is made.

// See https://github.com/nodejs/node/issues/20278
for (const k in moduleObj) {
const exported = moduleObj[k];
if (isClass(exported)) {
classes.push(exported);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"nyc": "^11.7.1",
"prettier": "^1.12.1",
"rimraf": "^2.6.2",
"source-map-support": "^0.5.4",
"source-map-support": "^0.5.5",
"strong-docs": "^1.10.2",
"tslint": "^5.9.1",
"typescript": "^2.8.1"
Expand Down
20 changes: 10 additions & 10 deletions packages/repository/test/unit/type/type.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ describe('types', () => {
describe('buffer', () => {
const bufferType = new types.BufferType();
it('checks isInstance', () => {
expect(bufferType.isInstance(new Buffer([1]))).to.be.true();
expect(bufferType.isInstance(new Buffer('123'))).to.be.true();
expect(bufferType.isInstance(Buffer.from([1]))).to.be.true();
expect(bufferType.isInstance(Buffer.from('123'))).to.be.true();
expect(bufferType.isInstance('str')).to.be.false();
expect(bufferType.isInstance(null)).to.be.true();
expect(bufferType.isInstance(undefined)).to.be.true();
Expand All @@ -248,7 +248,7 @@ describe('types', () => {
expect(bufferType.isCoercible('str')).to.be.true();
expect(bufferType.isCoercible(null)).to.be.true();
expect(bufferType.isCoercible(undefined)).to.be.true();
expect(bufferType.isCoercible(new Buffer('12'))).to.be.true();
expect(bufferType.isCoercible(Buffer.from('12'))).to.be.true();
expect(bufferType.isCoercible([1, 2])).to.be.true();
expect(bufferType.isCoercible({x: 1})).to.be.false();
expect(bufferType.isCoercible(1)).to.be.false();
Expand All @@ -260,11 +260,11 @@ describe('types', () => {
});

it('coerces values', () => {
expect(bufferType.coerce('str').equals(new Buffer('str'))).to.be.true();
expect(bufferType.coerce('str').equals(Buffer.from('str'))).to.be.true();
expect(bufferType.coerce([1]).equals(Buffer.from([1]))).to.be.true();
expect(bufferType.coerce(null)).to.equal(null);
expect(bufferType.coerce(undefined)).to.equal(undefined);
const buf = new Buffer('12');
const buf = Buffer.from('12');
expect(bufferType.coerce(buf)).exactly(buf);
expect(() => bufferType.coerce(1)).to.throw(/Invalid buffer/);
expect(() => bufferType.coerce(new Date())).to.throw(/Invalid buffer/);
Expand All @@ -274,9 +274,9 @@ describe('types', () => {

it('serializes values', () => {
expect(
bufferType.serialize(new Buffer('str'), {encoding: 'utf-8'}),
bufferType.serialize(Buffer.from('str'), {encoding: 'utf-8'}),
).to.eql('str');
expect(bufferType.serialize(new Buffer('str'))).to.eql('c3Ry');
expect(bufferType.serialize(Buffer.from('str'))).to.eql('c3Ry');
expect(bufferType.serialize(null)).null();
expect(bufferType.serialize(undefined)).undefined();
});
Expand All @@ -293,7 +293,7 @@ describe('types', () => {
expect(anyType.isInstance([1, 2])).to.be.true();
expect(anyType.isInstance(1)).to.be.true();
expect(anyType.isInstance(new Date())).to.be.true();
expect(anyType.isInstance(new Buffer('123'))).to.be.true();
expect(anyType.isInstance(Buffer.from('123'))).to.be.true();
});

it('checks isCoercible', () => {
Expand All @@ -305,7 +305,7 @@ describe('types', () => {
expect(anyType.isCoercible(1)).to.be.true();
expect(anyType.isCoercible([1, '2'])).to.be.true();
expect(anyType.isCoercible(new Date())).to.be.true();
expect(anyType.isCoercible(new Buffer('123'))).to.be.true();
expect(anyType.isCoercible(Buffer.from('123'))).to.be.true();
});

it('creates defaultValue', () => {
Expand All @@ -324,7 +324,7 @@ describe('types', () => {
expect(anyType.coerce(1)).to.equal(1);
const date = new Date();
expect(anyType.coerce(date)).to.equal(date);
const buf = new Buffer('12');
const buf = Buffer.from('12');
expect(anyType.coerce(buf)).to.equal(buf);
});

Expand Down