@abtnode/util 1.16.16 → 1.16.17-beta-8cacb9b3
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/axios.js +1 -33
- package/lib/create-blocklet-release.js +90 -0
- package/lib/normalize-path-prefix.js +1 -11
- package/lib/url-path-friendly.js +1 -40
- package/package.json +14 -9
package/lib/axios.js
CHANGED
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
const axios = require('axios').default;
|
|
2
|
-
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent');
|
|
3
|
-
|
|
4
|
-
function proxyInterceptor(config) {
|
|
5
|
-
/* istanbul ignore if */
|
|
6
|
-
if (config.socketPath != null) return config;
|
|
7
|
-
|
|
8
|
-
const { proxy } = config;
|
|
9
|
-
|
|
10
|
-
/* istanbul ignore if */
|
|
11
|
-
if (proxy === false) return config;
|
|
12
|
-
|
|
13
|
-
const httpProxyUrl = process.env.HTTP_PROXY || process.env.http_proxy;
|
|
14
|
-
const httpsProxyUrl = process.env.HTTPS_PROXY || process.env.https_proxy;
|
|
15
|
-
|
|
16
|
-
const proxyOptions = Object.assign(
|
|
17
|
-
{ keepAlive: true, keepAliveMsecs: 1000, maxSockets: 256, maxFreeSockets: 256 },
|
|
18
|
-
config.proxyOptions || {}
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
if (httpProxyUrl) {
|
|
22
|
-
config.proxy = false;
|
|
23
|
-
config.httpAgent = new HttpProxyAgent({ proxy: httpProxyUrl, ...proxyOptions });
|
|
24
|
-
}
|
|
25
|
-
if (httpsProxyUrl) {
|
|
26
|
-
config.proxy = false;
|
|
27
|
-
config.httpsAgent = new HttpsProxyAgent({ proxy: httpsProxyUrl, ...proxyOptions });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return config;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
axios.interceptors.request.use(proxyInterceptor);
|
|
1
|
+
const axios = require('@blocklet/meta/lib/axios').default;
|
|
34
2
|
|
|
35
3
|
module.exports = axios;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const fs = require('fs-extra');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const ssri = require('ssri');
|
|
5
|
+
const tar = require('tar');
|
|
6
|
+
const chalk = require('chalk');
|
|
7
|
+
const slugify = require('slugify');
|
|
8
|
+
const packList = require('npm-packlist');
|
|
9
|
+
const getBlockletMeta = require('@blocklet/meta/lib/parse');
|
|
10
|
+
const {
|
|
11
|
+
BLOCKLET_RELEASE_FOLDER_NAME,
|
|
12
|
+
BLOCKLET_RELEASE_FILE,
|
|
13
|
+
BLOCKLET_BUNDLE_FOLDER_NAME,
|
|
14
|
+
} = require('@blocklet/constant');
|
|
15
|
+
|
|
16
|
+
const defaultLogger = {
|
|
17
|
+
info: console.log,
|
|
18
|
+
error: console.error,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// TODO add dependencies
|
|
22
|
+
// TODO remove code in @abtnode/cli
|
|
23
|
+
|
|
24
|
+
const createRelease = (dir, { printError = defaultLogger.error, printInfo = defaultLogger.info } = {}) =>
|
|
25
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
26
|
+
new Promise(async (resolve, reject) => {
|
|
27
|
+
const destDir = path.join(dir, BLOCKLET_RELEASE_FOLDER_NAME);
|
|
28
|
+
const srcDir = path.join(dir, BLOCKLET_BUNDLE_FOLDER_NAME);
|
|
29
|
+
|
|
30
|
+
let meta;
|
|
31
|
+
try {
|
|
32
|
+
meta = getBlockletMeta(srcDir, {});
|
|
33
|
+
} catch (err) {
|
|
34
|
+
reject(err);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
meta.dist = {};
|
|
39
|
+
meta.dist.tarball = `${slugify(meta.name)}-${meta.version}.tgz`;
|
|
40
|
+
|
|
41
|
+
const destFile = path.join(destDir, meta.dist.tarball);
|
|
42
|
+
const metaFile = path.join(destDir, BLOCKLET_RELEASE_FILE);
|
|
43
|
+
|
|
44
|
+
fs.removeSync(destDir);
|
|
45
|
+
fs.mkdirpSync(destDir);
|
|
46
|
+
|
|
47
|
+
printInfo(`Creating release for blocklet ${meta.name}@${meta.version}...`);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
// https://github.com/npm/npm-packlist
|
|
51
|
+
const files = await packList({ package: {} }, { path: srcDir });
|
|
52
|
+
|
|
53
|
+
// https://github.com/npm/node-tar/blob/master/lib/create.js
|
|
54
|
+
await tar.create(
|
|
55
|
+
{
|
|
56
|
+
cwd: srcDir,
|
|
57
|
+
prefix: 'package/',
|
|
58
|
+
portable: true,
|
|
59
|
+
gzip: true,
|
|
60
|
+
file: destFile,
|
|
61
|
+
sync: true,
|
|
62
|
+
},
|
|
63
|
+
files
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
printInfo(`Release tarball created: ${chalk.cyan(destFile)}`);
|
|
67
|
+
|
|
68
|
+
ssri
|
|
69
|
+
.fromStream(fs.createReadStream(destFile), { algorithms: ['sha512'] })
|
|
70
|
+
.then((result) => {
|
|
71
|
+
meta.dist.integrity = result.toString();
|
|
72
|
+
meta.dist.size = fs.statSync(destFile).size;
|
|
73
|
+
|
|
74
|
+
fs.writeFileSync(metaFile, JSON.stringify(meta, null, 2));
|
|
75
|
+
|
|
76
|
+
printInfo(`Release meta created: ${chalk.cyan(metaFile)}`);
|
|
77
|
+
|
|
78
|
+
return resolve({ tarball: destFile, meta });
|
|
79
|
+
})
|
|
80
|
+
.catch((err) => {
|
|
81
|
+
printError(`Failed to create blocklet integrity: ${err.message}`);
|
|
82
|
+
reject(err);
|
|
83
|
+
});
|
|
84
|
+
} catch (err) {
|
|
85
|
+
printError(`Failed to create blocklet release: ${err.message}`);
|
|
86
|
+
reject(err);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
module.exports = { createRelease };
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
const normalizePathPrefix = (prefix)
|
|
2
|
-
if (typeof prefix === 'string') {
|
|
3
|
-
if (!prefix || prefix === '/') {
|
|
4
|
-
return '/';
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
return `/${prefix}/`.replace(/\/+/g, '/');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return '/';
|
|
11
|
-
};
|
|
1
|
+
const { normalizePathPrefix } = require('@blocklet/meta/lib/normalize-path-prefix');
|
|
12
2
|
|
|
13
3
|
module.exports = normalizePathPrefix;
|
package/lib/url-path-friendly.js
CHANGED
|
@@ -1,43 +1,4 @@
|
|
|
1
|
-
const isValidUrlPath = (
|
|
2
|
-
// Check if the path contains any uppercase letters
|
|
3
|
-
if (/[A-Z]/.test(name)) {
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
// Check if the path contains any non-ASCII characters
|
|
8
|
-
if (/[^\x20-\x7F]/.test(name)) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Check if the resulting string matches the pattern of a valid URL path
|
|
13
|
-
const regex = /^[a-z0-9/\-._]*$/i;
|
|
14
|
-
return regex.test(name) && !name.includes('//');
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const urlPathFriendly = (name, { keepSlash = true } = {}) => {
|
|
18
|
-
// Replace non-URL path friendly characters with hyphens
|
|
19
|
-
const pathFriendlyStr = name
|
|
20
|
-
.trim()
|
|
21
|
-
.replace(/[^\x20-\x7F]/g, '')
|
|
22
|
-
.replace(/[^a-z0-9_.\-/]/gi, '-')
|
|
23
|
-
.toLowerCase();
|
|
24
|
-
|
|
25
|
-
// Remove consecutive hyphens
|
|
26
|
-
const noConsecutiveHyphens = pathFriendlyStr.replace(/-+/g, '-');
|
|
27
|
-
|
|
28
|
-
// Replace consecutive periods with a single period
|
|
29
|
-
const result = noConsecutiveHyphens.replace(/\.+/g, '.');
|
|
30
|
-
|
|
31
|
-
// Remove consecutive slashes if keepSlash is true
|
|
32
|
-
const noConsecutiveSlashes = result.replace(/\/+/g, '/');
|
|
33
|
-
|
|
34
|
-
// Remove leading/trailing slashes if keepSlash is false
|
|
35
|
-
if (!keepSlash) {
|
|
36
|
-
return noConsecutiveSlashes.replace(/^\/|\/$/g, '');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return noConsecutiveSlashes;
|
|
40
|
-
};
|
|
1
|
+
const { isValidUrlPath, default: urlPathFriendly } = require('@blocklet/meta/lib/url-path-friendly');
|
|
41
2
|
|
|
42
3
|
module.exports = {
|
|
43
4
|
isValidUrlPath,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.
|
|
6
|
+
"version": "1.16.17-beta-8cacb9b3",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,17 +18,19 @@
|
|
|
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.
|
|
22
|
-
"@abtnode/logger": "1.16.
|
|
23
|
-
"@blocklet/constant": "1.16.
|
|
24
|
-
"@
|
|
25
|
-
"@ocap/
|
|
26
|
-
"@ocap/
|
|
27
|
-
"@ocap/
|
|
21
|
+
"@abtnode/constant": "1.16.17-beta-8cacb9b3",
|
|
22
|
+
"@abtnode/logger": "1.16.17-beta-8cacb9b3",
|
|
23
|
+
"@blocklet/constant": "1.16.17-beta-8cacb9b3",
|
|
24
|
+
"@blocklet/meta": "1.16.17-beta-8cacb9b3",
|
|
25
|
+
"@ocap/client": "1.18.91",
|
|
26
|
+
"@ocap/mcrypto": "1.18.91",
|
|
27
|
+
"@ocap/util": "1.18.91",
|
|
28
|
+
"@ocap/wallet": "1.18.91",
|
|
28
29
|
"archiver": "^5.3.1",
|
|
29
30
|
"axios": "^0.27.2",
|
|
30
31
|
"axios-mock-adapter": "^1.21.2",
|
|
31
32
|
"axon": "^2.0.3",
|
|
33
|
+
"chalk": "^4.1.2",
|
|
32
34
|
"cookie": "^0.5.0",
|
|
33
35
|
"cookie-parser": "^1.4.6",
|
|
34
36
|
"cross-spawn": "^7.0.3",
|
|
@@ -48,6 +50,7 @@
|
|
|
48
50
|
"json-stable-stringify": "^1.0.1",
|
|
49
51
|
"lodash": "^4.17.21",
|
|
50
52
|
"multiformats": "9.9.0",
|
|
53
|
+
"npm-packlist": "^7.0.4",
|
|
51
54
|
"p-retry": "4.6.1",
|
|
52
55
|
"parallel-transform": "^1.2.0",
|
|
53
56
|
"pm2": "^5.3.0",
|
|
@@ -56,7 +59,9 @@
|
|
|
56
59
|
"semver-sort": "^1.0.0",
|
|
57
60
|
"shelljs": "^0.8.5",
|
|
58
61
|
"slugify": "^1.6.5",
|
|
62
|
+
"ssri": "^8.0.1",
|
|
59
63
|
"stream-to-promise": "^3.0.0",
|
|
64
|
+
"tar": "^6.1.11",
|
|
60
65
|
"through2-filter": "^3.0.0",
|
|
61
66
|
"through2-map": "^3.0.0",
|
|
62
67
|
"to-semver": "^3.0.0",
|
|
@@ -71,5 +76,5 @@
|
|
|
71
76
|
"fs-extra": "^10.1.0",
|
|
72
77
|
"jest": "^27.5.1"
|
|
73
78
|
},
|
|
74
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "0e3266f543b6d419a004ca94ee9efb572e3d9809"
|
|
75
80
|
}
|