Skip to content

Commit

Permalink
feat: rollback for removing third-party dependencies (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyj1991 authored Dec 11, 2024
1 parent 5e159a2 commit 995f992
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .autod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module.exports = {
'test',
],
dep: [
'address',
'formstream',
'moment',
'nounou',
'p-map',
Expand Down
22 changes: 2 additions & 20 deletions common/utils.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
'use strict';

const os = require('os');
const address = require('address');
const crypto = require('crypto');
const { promisify } = require('util');
const path = require('path');

exports.getIp = function getIp() {
const interfaces = os.networkInterfaces();
for (const interfaceItems of Object.values(interfaces)) {
for (const item of interfaceItems) {
// skip local network ip
if (item.address.startsWith('10.') ||
item.address.startsWith('172.16.') ||
item.address.startsWith('192.168.') ||
item.address.startsWith('169.254.')) {
continue;
}
if (item.family === 'IPv4' && !item.internal) {
return item.address;
}
}
}
return '127.0.0.1';
};

exports.regularWsServer = function(server) {
return server.startsWith('ws://') || server.startsWith('wss://');
};
Expand All @@ -40,7 +22,7 @@ exports.getAgentId = function(customAgent, ipMode) {
if (!ipMode) {
return `${os.hostname()}`;
}
return `${exports.getIp()}::${os.hostname()}`;
return `${address.ip()}::${os.hostname()}`;
};

exports.sign = function(message, secret) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"homepage": "https://github.com/X-Profiler/xtransit#readme",
"dependencies": {
"address": "^1.1.2",
"form-data": "^4.0.0",
"moment": "^2.28.0",
"nounou": "^1.2.1",
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/files/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/fixtures/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
},
"homepage": "https://github.com/X-Profiler/xtransit#readme",
"dependencies": {
"address": "^1.1.2",
"formstream": "^1.1.0",
"moment": "^2.26.0",
"nounou": "^1.2.1",
"p-map": "^4.0.0",
Expand Down
Empty file removed test/fixtures/files/test_error
Empty file.

0 comments on commit 995f992

Please sign in to comment.