@abtnode/util 1.16.29-next-680cf137 → 1.16.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/create-blocklet-release.js +2 -2
- package/lib/format-context.js +2 -1
- package/lib/get-ip.js +9 -0
- package/lib/get-request-ip.js +20 -0
- package/lib/run-script.js +17 -14
- package/package.json +11 -10
|
@@ -21,7 +21,7 @@ const defaultLogger = {
|
|
|
21
21
|
// TODO add dependencies
|
|
22
22
|
// TODO remove code in @abtnode/cli
|
|
23
23
|
|
|
24
|
-
const createRelease = (dir, { printError = defaultLogger.error, printInfo = defaultLogger.info } = {}) =>
|
|
24
|
+
const createRelease = (dir, { printError = defaultLogger.error, printInfo = defaultLogger.info, tarball = '' } = {}) =>
|
|
25
25
|
// eslint-disable-next-line no-async-promise-executor
|
|
26
26
|
new Promise(async (resolve, reject) => {
|
|
27
27
|
const destDir = path.join(dir, BLOCKLET_RELEASE_FOLDER_NAME);
|
|
@@ -36,7 +36,7 @@ const createRelease = (dir, { printError = defaultLogger.error, printInfo = defa
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
meta.dist = {};
|
|
39
|
-
meta.dist.tarball = `${slugify(meta.name)}-${meta.version}.tgz`;
|
|
39
|
+
meta.dist.tarball = tarball || `${slugify(meta.name)}-${meta.version}.tgz`;
|
|
40
40
|
|
|
41
41
|
const destFile = path.join(destDir, meta.dist.tarball);
|
|
42
42
|
const metaFile = path.join(destDir, BLOCKLET_RELEASE_FILE);
|
package/lib/format-context.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const omit = require('lodash/omit');
|
|
2
2
|
const get = require('lodash/get');
|
|
3
|
+
const getRequestIP = require('./get-request-ip');
|
|
3
4
|
|
|
4
5
|
// Format context: https://github.com/graphql/express-graphql
|
|
5
6
|
/**
|
|
@@ -19,7 +20,7 @@ module.exports = (ctx = {}) => {
|
|
|
19
20
|
(typeof ctx.get === 'function' ? ctx.get(key) : get(ctx, `headers[${key}]`)) || _default;
|
|
20
21
|
const port = process.env.NODE_ENV === 'production' ? safeGet('x-real-port') : '';
|
|
21
22
|
const result = {
|
|
22
|
-
ip: safeGet('x-real-ip', '127.0.0.1'),
|
|
23
|
+
ip: getRequestIP(ctx) || safeGet('x-real-ip', '127.0.0.1'),
|
|
23
24
|
ua: safeGet('user-agent'),
|
|
24
25
|
protocol: safeGet('x-real-protocol').replace(/:$/, '') || 'http',
|
|
25
26
|
user: contextUser,
|
package/lib/get-ip.js
CHANGED
|
@@ -35,6 +35,15 @@ const getIP = async ({ includeV6 = false, timeout = 5000, includeExternal = true
|
|
|
35
35
|
const [inEc2, inGCP] = await Promise.all([isEC2(), gcp.isInGCP()]);
|
|
36
36
|
debug('check env', { inEc2, inGCP });
|
|
37
37
|
|
|
38
|
+
if (process.env.ABT_NODE_HOST) {
|
|
39
|
+
return {
|
|
40
|
+
internal: process.env.ABT_NODE_HOST,
|
|
41
|
+
external: process.env.ABT_NODE_HOST,
|
|
42
|
+
internalV6: process.env.ABT_NODE_HOST,
|
|
43
|
+
externalV6: process.env.ABT_NODE_HOST,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
38
47
|
if (inEc2) {
|
|
39
48
|
debug('in ec2');
|
|
40
49
|
const [internal, external, internalV6, externalV6] = await Promise.all([
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const requestIp = require('request-ip');
|
|
2
|
+
|
|
3
|
+
const emptyIp = '';
|
|
4
|
+
|
|
5
|
+
const getRequestIP = (request) => {
|
|
6
|
+
if (!request) {
|
|
7
|
+
return emptyIp;
|
|
8
|
+
}
|
|
9
|
+
let clientIp = request?.clientIp;
|
|
10
|
+
if (!clientIp) {
|
|
11
|
+
clientIp = requestIp.getClientIp(request);
|
|
12
|
+
}
|
|
13
|
+
if (!clientIp) {
|
|
14
|
+
clientIp = request.get?.('x-real-ip');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return clientIp || emptyIp;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports = getRequestIP;
|
package/lib/run-script.js
CHANGED
|
@@ -83,7 +83,6 @@ const runScript = (script, label, options = {}) => {
|
|
|
83
83
|
const promise = new Promise((resolve, reject) => {
|
|
84
84
|
process.stdout.setMaxListeners(0);
|
|
85
85
|
process.stderr.setMaxListeners(0);
|
|
86
|
-
|
|
87
86
|
let [command, ...args] = script.split(' ');
|
|
88
87
|
if (fs.existsSync(command) === false) {
|
|
89
88
|
command = which.sync(command);
|
|
@@ -134,20 +133,8 @@ const runScript = (script, label, options = {}) => {
|
|
|
134
133
|
|
|
135
134
|
let hasUnhandledRejection = false;
|
|
136
135
|
const errorMessages = [];
|
|
137
|
-
child.stderr.on('data', (err) => {
|
|
138
|
-
errorMessages.push(err);
|
|
139
|
-
if (err.includes('UnhandledPromiseRejectionWarning')) {
|
|
140
|
-
hasUnhandledRejection = true;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
136
|
|
|
144
|
-
|
|
145
|
-
console.error(err);
|
|
146
|
-
errorMessages.push(err.message);
|
|
147
|
-
return reject(new Error(errorMessages.join('\r\n')));
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
child.on('close', (code, signal) => {
|
|
137
|
+
const handleExit = (code, signal) => {
|
|
151
138
|
if (signal) {
|
|
152
139
|
if (Date.now() - now > timeout) {
|
|
153
140
|
return reject(new Error(`Process timeout after ${timeout / 1000} seconds`));
|
|
@@ -162,7 +149,23 @@ const runScript = (script, label, options = {}) => {
|
|
|
162
149
|
}
|
|
163
150
|
|
|
164
151
|
return resolve({ code, script });
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
child.stderr.on('data', (err) => {
|
|
155
|
+
errorMessages.push(err);
|
|
156
|
+
if (err.includes('UnhandledPromiseRejectionWarning')) {
|
|
157
|
+
hasUnhandledRejection = true;
|
|
158
|
+
}
|
|
165
159
|
});
|
|
160
|
+
|
|
161
|
+
child.on('error', (err) => {
|
|
162
|
+
console.error(err);
|
|
163
|
+
errorMessages.push(err.message);
|
|
164
|
+
return reject(new Error(errorMessages.join('\r\n')));
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
child.on('close', handleExit);
|
|
168
|
+
child.on('exit', handleExit);
|
|
166
169
|
});
|
|
167
170
|
|
|
168
171
|
promise.abort = cleanup;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.29
|
|
6
|
+
"version": "1.16.29",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.16.29
|
|
22
|
-
"@abtnode/logger": "1.16.29
|
|
21
|
+
"@abtnode/constant": "1.16.29",
|
|
22
|
+
"@abtnode/logger": "1.16.29",
|
|
23
23
|
"@arcblock/pm2": "^5.4.0",
|
|
24
|
-
"@blocklet/constant": "1.16.29
|
|
25
|
-
"@blocklet/meta": "1.16.29
|
|
26
|
-
"@ocap/client": "1.18.
|
|
27
|
-
"@ocap/mcrypto": "1.18.
|
|
28
|
-
"@ocap/util": "1.18.
|
|
29
|
-
"@ocap/wallet": "1.18.
|
|
24
|
+
"@blocklet/constant": "1.16.29",
|
|
25
|
+
"@blocklet/meta": "1.16.29",
|
|
26
|
+
"@ocap/client": "1.18.128",
|
|
27
|
+
"@ocap/mcrypto": "1.18.128",
|
|
28
|
+
"@ocap/util": "1.18.128",
|
|
29
|
+
"@ocap/wallet": "1.18.128",
|
|
30
30
|
"archiver": "^7.0.1",
|
|
31
31
|
"axios": "^1.7.2",
|
|
32
32
|
"axios-mock-adapter": "^1.21.2",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"parallel-transform": "^1.2.0",
|
|
57
57
|
"public-ip": "^4.0.4",
|
|
58
58
|
"pump": "^3.0.0",
|
|
59
|
+
"request-ip": "^3.3.0",
|
|
59
60
|
"resolve": "^1.22.8",
|
|
60
61
|
"semver": "^7.6.2",
|
|
61
62
|
"semver-sort": "^1.0.0",
|
|
@@ -79,5 +80,5 @@
|
|
|
79
80
|
"fs-extra": "^11.2.0",
|
|
80
81
|
"jest": "^29.7.0"
|
|
81
82
|
},
|
|
82
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "6c49cffcab4fd0dffc6bed261a5eddf733280ae7"
|
|
83
84
|
}
|