@vscodium/native-keymap 3.3.7-258421 → 3.3.7-258422

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.
Files changed (3) hide show
  1. package/checksum.txt +22 -0
  2. package/install.js +262 -0
  3. package/package.json +5 -5
package/checksum.txt ADDED
@@ -0,0 +1,22 @@
1
+ 9505e246ec262faa806fb1ecdcf5a0ae4bcc0055b2e38a3cc5055db28a1290f3 native-keymap-3.3.7-258422-darwin-arm64.tar.gz
2
+ 0da60d659c535d30b2fb03a29aa41757ac42a6951bf0f595182c6c8ffed8f45b native-keymap-3.3.7-258422-darwin-x64.tar.gz
3
+ d21d3ef1dd4c4681be1e76fa3293db8ae576abcbfc5d2caf481abcd03e8ac2f5 native-keymap-3.3.7-258422-linux-arm64.tar.gz
4
+ d1519f082a6e4c2d4b3814072e79ea009438f486fad19f058a1d094337ea6129 native-keymap-3.3.7-258422-linux-armhf.tar.gz
5
+ 3e3d824ada198d38b89a7b02888f704aade66d32f2fc62b4602dbcc9f4b4bb5a native-keymap-3.3.7-258422-linux-loong64.tar.gz
6
+ 5c0b430789cd44071a9a1b8285486839f90a90a60bb3942ec326805fafe92e93 native-keymap-3.3.7-258422-linux-ppc64le.tar.gz
7
+ 01914da7d436e5c0c4d9bd815e782ce7051db37fb47ed93821fac77b730ff1a6 native-keymap-3.3.7-258422-linux-riscv64.tar.gz
8
+ 84e6bfd7b1071b8fb2cb9249fb481d7fcb3dbc99377ee49b9bff9c08137ead8d native-keymap-3.3.7-258422-linux-s390x.tar.gz
9
+ b804f1e229fc7bc0300757906f92700b809d35f665b7e65276dcc1737498fe20 native-keymap-3.3.7-258422-linux-x64.tar.gz
10
+ 5e353f423eec0a36708743be96dbfbfe28fa9c543e6e2a1b3b94e5b135fab3c1 *native-keymap-3.3.7-258422-win32-arm64.tar.gz
11
+ aa301c623a40addb828387d409923198248124a8b1bb6e46eaa0b6bc1ec5d3ea *native-keymap-3.3.7-258422-win32-x64.tar.gz
12
+ 9505e246ec262faa806fb1ecdcf5a0ae4bcc0055b2e38a3cc5055db28a1290f3 native-keymap-3.3.7-258422-darwin-arm64.tar.gz
13
+ 0da60d659c535d30b2fb03a29aa41757ac42a6951bf0f595182c6c8ffed8f45b native-keymap-3.3.7-258422-darwin-x64.tar.gz
14
+ d21d3ef1dd4c4681be1e76fa3293db8ae576abcbfc5d2caf481abcd03e8ac2f5 native-keymap-3.3.7-258422-linux-arm64.tar.gz
15
+ d1519f082a6e4c2d4b3814072e79ea009438f486fad19f058a1d094337ea6129 native-keymap-3.3.7-258422-linux-armhf.tar.gz
16
+ 3e3d824ada198d38b89a7b02888f704aade66d32f2fc62b4602dbcc9f4b4bb5a native-keymap-3.3.7-258422-linux-loong64.tar.gz
17
+ 5c0b430789cd44071a9a1b8285486839f90a90a60bb3942ec326805fafe92e93 native-keymap-3.3.7-258422-linux-ppc64le.tar.gz
18
+ 01914da7d436e5c0c4d9bd815e782ce7051db37fb47ed93821fac77b730ff1a6 native-keymap-3.3.7-258422-linux-riscv64.tar.gz
19
+ 84e6bfd7b1071b8fb2cb9249fb481d7fcb3dbc99377ee49b9bff9c08137ead8d native-keymap-3.3.7-258422-linux-s390x.tar.gz
20
+ b804f1e229fc7bc0300757906f92700b809d35f665b7e65276dcc1737498fe20 native-keymap-3.3.7-258422-linux-x64.tar.gz
21
+ 5e353f423eec0a36708743be96dbfbfe28fa9c543e6e2a1b3b94e5b135fab3c1 *native-keymap-3.3.7-258422-win32-arm64.tar.gz
22
+ aa301c623a40addb828387d409923198248124a8b1bb6e46eaa0b6bc1ec5d3ea *native-keymap-3.3.7-258422-win32-x64.tar.gz
package/install.js ADDED
@@ -0,0 +1,262 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const crypto = require('node:crypto');
5
+ const fs = require('node:fs');
6
+ const fsp = fs.promises;
7
+ const http = require('node:http');
8
+ const https = require('node:https');
9
+ const os = require('node:os');
10
+ const path = require('node:path');
11
+ const { pipeline } = require('node:stream');
12
+ const { promisify } = require('node:util');
13
+ const tar = require('tar');
14
+ const { spawnSync } = require('node:child_process');
15
+
16
+ const pipelineAsync = promisify(pipeline);
17
+ const PACKAGE_ROOT = path.resolve(__dirname);
18
+ const PACKAGE_JSON = require(path.join(PACKAGE_ROOT, 'package.json'));
19
+ const PACKAGE_VERSION = PACKAGE_JSON.version;
20
+ const RELEASE_TAG = PACKAGE_VERSION.startsWith('v') ? PACKAGE_VERSION : `v${PACKAGE_VERSION}`;
21
+ const DEFAULT_BASE_URL = 'https://github.com/VSCodium/native-keymap/releases/download';
22
+ const LOCAL_CHECKSUM_PATH = path.join(PACKAGE_ROOT, 'checksum.txt');
23
+
24
+ async function main() {
25
+ const intent = computeDownloadIntent();
26
+ if (!intent.shouldDownload) {
27
+ runNodeGypRebuild(intent.reason);
28
+ return;
29
+ }
30
+
31
+ try {
32
+ const destination = await downloadPrebuilt(intent.platform, intent.arch);
33
+ console.log(`[native-keymap] Installed prebuilt binary to ${destination}`);
34
+ } catch (error) {
35
+ console.warn(`[native-keymap] Unable to download prebuilt binary (${error.message}). Falling back to source build.`);
36
+ runNodeGypRebuild();
37
+ }
38
+ }
39
+
40
+ function computeDownloadIntent() {
41
+ if (shouldForceSourceBuild()) {
42
+ return { shouldDownload: false, reason: 'download explicitly disabled' };
43
+ }
44
+
45
+ const platform = resolvePlatform();
46
+ if (!platform) {
47
+ return { shouldDownload: false, reason: `unsupported platform (${process.platform})` };
48
+ }
49
+
50
+ const arch = resolveArch();
51
+ if (!arch) {
52
+ return { shouldDownload: false, reason: `unsupported architecture (${process.arch})` };
53
+ }
54
+
55
+ return { shouldDownload: true, platform, arch };
56
+ }
57
+
58
+ function shouldForceSourceBuild() {
59
+ return isTruthy(process.env.NATIVE_KEYMAP_SKIP_PREBUILT) ||
60
+ isTruthy(process.env.npm_config_build_from_source) ||
61
+ isTruthy(process.env.BUILD_FROM_SOURCE) ||
62
+ isTruthy(process.env.npm_config_build_from_source_native_keymap);
63
+ }
64
+
65
+ function isTruthy(value) {
66
+ if (!value) {
67
+ return false;
68
+ }
69
+ const normalized = String(value).toLowerCase();
70
+ return normalized === '1' || normalized === 'true' || normalized === 'yes';
71
+ }
72
+
73
+ function resolvePlatform() {
74
+ const rawPlatform = (process.env.npm_config_platform || process.platform || '').toLowerCase();
75
+ switch (rawPlatform) {
76
+ case 'linux':
77
+ return 'linux';
78
+ case 'darwin':
79
+ return 'darwin';
80
+ case 'win32':
81
+ return 'win32';
82
+ default:
83
+ return null;
84
+ }
85
+ }
86
+
87
+ function resolveArch() {
88
+ const rawArch = (process.env.npm_config_target_arch || process.env.npm_config_arch || process.arch || '').toLowerCase();
89
+ switch (rawArch) {
90
+ case 'x64':
91
+ return 'x64';
92
+ case 'arm64':
93
+ case 'aarch64':
94
+ return 'arm64';
95
+ case 'arm':
96
+ case 'armhf':
97
+ case 'armv7l':
98
+ return 'armhf';
99
+ case 'riscv64':
100
+ return 'riscv64';
101
+ case 'loong64':
102
+ case 'loongarch64':
103
+ return 'loong64';
104
+ case 'ppc64':
105
+ case 'ppc64le':
106
+ return 'ppc64le';
107
+ case 's390x':
108
+ return 's390x';
109
+ default:
110
+ return null;
111
+ }
112
+ }
113
+
114
+ async function downloadPrebuilt(platform, arch) {
115
+ const assetName = `native-keymap-${PACKAGE_VERSION}-${platform}-${arch}.tar.gz`;
116
+ const baseUrl = process.env.NATIVE_KEYMAP_PREBUILT_BASE_URL || DEFAULT_BASE_URL;
117
+ const downloadUrl = `${baseUrl}/${RELEASE_TAG}/${assetName}`;
118
+ console.log(`[native-keymap] Downloading ${assetName} (${platform}/${arch})`);
119
+
120
+ const tmpDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'native-keymap-'));
121
+ const archivePath = path.join(tmpDir, assetName);
122
+
123
+ try {
124
+ await downloadFile(downloadUrl, archivePath);
125
+ const checksumRaw = await loadChecksumManifest();
126
+ const expectedHash = parseChecksum(checksumRaw, assetName);
127
+ await verifySha256(archivePath, expectedHash);
128
+ await tar.x({ file: archivePath, cwd: tmpDir });
129
+ const binaryPath = path.join(tmpDir, 'keymapping.node');
130
+ await fsp.access(binaryPath, fs.constants.R_OK);
131
+
132
+ const outputDir = path.join(PACKAGE_ROOT, 'build', 'Release');
133
+ await fsp.mkdir(outputDir, { recursive: true });
134
+ const destination = path.join(outputDir, 'keymapping.node');
135
+ await fsp.copyFile(binaryPath, destination);
136
+ return destination;
137
+ } finally {
138
+ await cleanup(tmpDir);
139
+ }
140
+ }
141
+
142
+ async function downloadFile(url, destination) {
143
+ const response = await httpGet(url);
144
+ await pipelineAsync(response, fs.createWriteStream(destination));
145
+ }
146
+
147
+ async function loadChecksumManifest() {
148
+ try {
149
+ const content = await fsp.readFile(LOCAL_CHECKSUM_PATH, 'utf8');
150
+ return content;
151
+ } catch (error) {
152
+ if (error.code && error.code !== 'ENOENT') {
153
+ throw error;
154
+ }
155
+ }
156
+ }
157
+
158
+ function httpGet(url, redirects = 0) {
159
+ const parsedUrl = new URL(url);
160
+ const client = parsedUrl.protocol === 'http:' ? http : https;
161
+ const requestOptions = {
162
+ protocol: parsedUrl.protocol,
163
+ hostname: parsedUrl.hostname,
164
+ port: parsedUrl.port,
165
+ path: `${parsedUrl.pathname}${parsedUrl.search}`,
166
+ headers: {
167
+ 'User-Agent': 'native-keymap-install-script',
168
+ 'Accept': '*/*'
169
+ }
170
+ };
171
+
172
+ return new Promise((resolve, reject) => {
173
+ const request = client.get(requestOptions, (response) => {
174
+ const status = response.statusCode || 0;
175
+ if (status >= 300 && status < 400 && response.headers.location) {
176
+ response.resume();
177
+ if (redirects > 5) {
178
+ reject(new Error(`Too many redirects trying to reach ${url}`));
179
+ return;
180
+ }
181
+ const redirectUrl = new URL(response.headers.location, parsedUrl).toString();
182
+ resolve(httpGet(redirectUrl, redirects + 1));
183
+ return;
184
+ }
185
+ if (status !== 200) {
186
+ response.resume();
187
+ reject(new Error(`Request to ${url} failed with status ${status}`));
188
+ return;
189
+ }
190
+ resolve(response);
191
+ });
192
+
193
+ request.on('error', reject);
194
+ });
195
+ }
196
+
197
+ function parseChecksum(raw, assetName) {
198
+ const entries = raw
199
+ .split(/\r?\n/)
200
+ .map((line) => line.trim())
201
+ .filter(Boolean);
202
+
203
+ if (entries.length === 0) {
204
+ throw new Error('Checksum file is empty');
205
+ }
206
+
207
+ for (const entry of entries) {
208
+ const [hash, ...rest] = entry.split(/\s+/);
209
+ if (!hash) {
210
+ continue;
211
+ }
212
+ const target = rest.join(' ');
213
+ if (target === assetName) {
214
+ return hash.toLowerCase();
215
+ }
216
+ }
217
+
218
+ throw new Error(`Unable to find checksum entry for ${assetName}`);
219
+ }
220
+
221
+ async function verifySha256(filePath, expectedHash) {
222
+ const hash = crypto.createHash('sha256');
223
+ await new Promise((resolve, reject) => {
224
+ const stream = fs.createReadStream(filePath);
225
+ stream.on('data', (chunk) => hash.update(chunk));
226
+ stream.on('error', reject);
227
+ stream.on('end', resolve);
228
+ });
229
+ const digest = hash.digest('hex');
230
+ if (digest !== expectedHash) {
231
+ throw new Error(`Checksum mismatch (expected ${expectedHash}, got ${digest})`);
232
+ }
233
+ }
234
+
235
+ async function cleanup(dirPath) {
236
+ if (!dirPath) {
237
+ return;
238
+ }
239
+ try {
240
+ await fsp.rm(dirPath, { recursive: true, force: true });
241
+ } catch (error) {
242
+ console.warn(`[native-keymap] Unable to cleanup temporary files: ${error.message}`);
243
+ }
244
+ }
245
+
246
+ function runNodeGypRebuild(reason) {
247
+ if (reason) {
248
+ console.log(`[native-keymap] Skipping prebuilt download: ${reason}`);
249
+ }
250
+ const nodeGypScript = process.env.npm_config_node_gyp;
251
+ const exec = nodeGypScript ? process.execPath : (process.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp');
252
+ const args = nodeGypScript ? [nodeGypScript, 'rebuild'] : ['rebuild'];
253
+ const result = spawnSync(exec, args, { stdio: 'inherit' });
254
+ if (result.status !== 0) {
255
+ throw new Error('node-gyp rebuild failed');
256
+ }
257
+ }
258
+
259
+ main().catch((error) => {
260
+ console.error(`[native-keymap] Installation failed: ${error.stack || error.message}`);
261
+ process.exit(1);
262
+ });
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@vscodium/native-keymap",
3
- "version": "3.3.7-258421",
3
+ "version": "3.3.7-258422",
4
4
  "description": "Get OS key mapping",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
7
7
  "scripts": {
8
- "install": "prebuild-install --verbose || node-gyp rebuild --release",
8
+ "install": "node install.js",
9
9
  "release": "release-it --no-increment",
10
10
  "test": "node test/test.js"
11
11
  },
@@ -15,9 +15,6 @@
15
15
  },
16
16
  "author": "Microsoft Corporation",
17
17
  "license": "MIT",
18
- "dependencies": {
19
- "prebuild-install": "^7.1.3"
20
- },
21
18
  "devDependencies": {
22
19
  "release-it": "^19.1.0"
23
20
  },
@@ -25,5 +22,8 @@
25
22
  "branches": [
26
23
  "main"
27
24
  ]
25
+ },
26
+ "dependencies": {
27
+ "tar": "^7.5.2"
28
28
  }
29
29
  }