@abtnode/util 1.16.49 → 1.16.50-beta-20250902-043619-201bcaed
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/security.js +42 -4
- package/package.json +6 -6
package/lib/security.js
CHANGED
|
@@ -8,6 +8,8 @@ const resolve = require('resolve/sync');
|
|
|
8
8
|
const { tmpdir, homedir } = require('os');
|
|
9
9
|
const which = require('which');
|
|
10
10
|
const { withHttps, withHttp } = require('ufo');
|
|
11
|
+
const { exec } = require('child_process');
|
|
12
|
+
const { promisify } = require('util');
|
|
11
13
|
|
|
12
14
|
const cloneDeep = require('./deep-clone');
|
|
13
15
|
|
|
@@ -71,14 +73,48 @@ function findExecutable(executable) {
|
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
// 缓存 Node.js 版本对应的权限选项
|
|
77
|
+
const permissionOptionCache = new Map();
|
|
78
|
+
|
|
79
|
+
async function getPermissionOption() {
|
|
80
|
+
// @note: 前端加载了整个文件,所以 execAsync 必须在这里创建
|
|
81
|
+
const execAsync = promisify(exec);
|
|
82
|
+
const nodeVersion = process.version;
|
|
83
|
+
|
|
84
|
+
// 检查缓存
|
|
85
|
+
if (permissionOptionCache.has(nodeVersion)) {
|
|
86
|
+
return permissionOptionCache.get(nodeVersion);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const { stdout } = await execAsync('node -h');
|
|
91
|
+
|
|
92
|
+
let permissionOption;
|
|
93
|
+
if (stdout.includes('--permission')) {
|
|
94
|
+
permissionOption = '--permission';
|
|
95
|
+
} else if (stdout.includes('--experimental-permission')) {
|
|
96
|
+
permissionOption = '--experimental-permission';
|
|
97
|
+
} else {
|
|
98
|
+
throw new Error(`Can not get permission options for this Node.js version: ${nodeVersion}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 缓存结果
|
|
102
|
+
permissionOptionCache.set(nodeVersion, permissionOption);
|
|
103
|
+
return permissionOption;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error(error);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
74
110
|
/**
|
|
75
111
|
* @description
|
|
76
112
|
* @see https://github.com/nodejs/node/issues/53621#issuecomment-2196879752
|
|
77
|
-
* @param {import('@blocklet/server-js').BlockletState & { environmentObj: [key: string]: string } } blocklet
|
|
113
|
+
* @param {import('@blocklet/server-js').BlockletState & { environmentObj: { [key: string]: string } }} blocklet
|
|
78
114
|
* @param {true | false} enableFileSystemIsolation
|
|
79
|
-
* @return {string}
|
|
115
|
+
* @return {Promise<string>}
|
|
80
116
|
*/
|
|
81
|
-
const getSecurityNodeOptions = (blocklet, enableFileSystemIsolation = true) => {
|
|
117
|
+
const getSecurityNodeOptions = async (blocklet, enableFileSystemIsolation = true) => {
|
|
82
118
|
const nodeOptions = process.env.NODE_OPTIONS ?? '';
|
|
83
119
|
|
|
84
120
|
if (
|
|
@@ -128,8 +164,10 @@ const getSecurityNodeOptions = (blocklet, enableFileSystemIsolation = true) => {
|
|
|
128
164
|
process.env.PNPM_HOME ? join(process.env.PNPM_HOME, 'global/') : '',
|
|
129
165
|
];
|
|
130
166
|
|
|
167
|
+
const permissionOption = await getPermissionOption();
|
|
168
|
+
|
|
131
169
|
options.push(
|
|
132
|
-
|
|
170
|
+
permissionOption,
|
|
133
171
|
...[
|
|
134
172
|
blocklet.environmentObj.BLOCKLET_DATA_DIR, // allow each component to write it's own data
|
|
135
173
|
blocklet.environmentObj.BLOCKLET_APP_DIR, // allow each component to write it's own source code: for example, to install dependencies
|
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.50-beta-20250902-043619-201bcaed",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,14 +18,14 @@
|
|
|
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/db-cache": "1.16.
|
|
21
|
+
"@abtnode/constant": "1.16.50-beta-20250902-043619-201bcaed",
|
|
22
|
+
"@abtnode/db-cache": "1.16.50-beta-20250902-043619-201bcaed",
|
|
23
23
|
"@arcblock/did": "1.24.0",
|
|
24
24
|
"@arcblock/event-hub": "1.24.0",
|
|
25
25
|
"@arcblock/pm2": "^6.0.12",
|
|
26
|
-
"@blocklet/constant": "1.16.
|
|
26
|
+
"@blocklet/constant": "1.16.50-beta-20250902-043619-201bcaed",
|
|
27
27
|
"@blocklet/error": "^0.2.5",
|
|
28
|
-
"@blocklet/meta": "1.16.
|
|
28
|
+
"@blocklet/meta": "1.16.50-beta-20250902-043619-201bcaed",
|
|
29
29
|
"@blocklet/xss": "^0.2.5",
|
|
30
30
|
"@ocap/client": "1.24.0",
|
|
31
31
|
"@ocap/mcrypto": "1.24.0",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"fs-extra": "^11.2.0",
|
|
92
92
|
"jest": "^29.7.0"
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "303555dda4a22370d579651b10886d05688c5533"
|
|
95
95
|
}
|