snapshot of eee7b5cfc0776c68816d7fdaa8af9d7a0e0da2e6 Annotations about the code that implements koment.

editors/vscode/binary.js

1 'use strict';
2
3 const fs = require('fs');
4 const path = require('path');
5
6 const bundledDirectory = 'bin';
7 const executableBits = 0o111;
8
9 function bundledBinary(extensionPath, platform) {
10 const name = platform === 'win32' ? 'koment.exe' : 'koment';
11 return path.join(extensionPath, bundledDirectory, name);
12 }
13
14 function resolveBinary({ configured, extensionPath, platform, exists = fs.existsSync }) {
15 const explicit = (configured ?? '').trim();
16 if (explicit) {
17 return { command: explicit, source: 'configured' };
18 }
19 const bundled = bundledBinary(extensionPath, platform);
20 if (exists(bundled)) {
21 return { command: bundled, source: 'bundled' };
22 }
23 return { command: 'koment', source: 'path' };
24 }
25
26 function ensureExecutable(binary, { platform = process.platform, stat = fs.statSync, chmod = fs.chmodSync } = {}) {
27 if (platform === 'win32') {
28 return false;
29 }
30 const { mode } = stat(binary);
31 if ((mode & executableBits) === executableBits) {
32 return false;
33 }
34 chmod(binary, mode | executableBits);
35 return true;
36 }
37
38 module.exports = { bundledBinary, ensureExecutable, resolveBinary };

Find an annotation

Search file paths, rationale, kinds, and authors.

moveEnter openEsc close