Skip to content

Commit a60081d

Browse files
committed
Make verbosecommits.ts compile
1 parent d7762cc commit a60081d

3 files changed

Lines changed: 45 additions & 9 deletions

File tree

src/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,10 @@ export function dirname(filePath: string): string {
112112
parts.pop();
113113
return parts.join("/");
114114
}
115+
116+
/**
117+
* Returns true if running in desktop VS Code (Node.js context), false otherwise (web context).
118+
*/
119+
export function isDesktopContext(): boolean {
120+
return typeof process !== "undefined" && !!process.versions?.node;
121+
}

src/verbosecommits.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
1+
/* global require */
2+
3+
/* eslint-disable @typescript-eslint/no-require-imports */
14
import * as vscode from "vscode";
25

3-
import * as child_process from "child_process";
4-
import * as util from "util";
5-
const execFile = util.promisify(child_process.execFile);
6+
import * as utils from "./utils";
7+
8+
// Set up execFile on desktop only
9+
type ExecFileType = (
10+
cmd: string,
11+
args: string[],
12+
) => Promise<{ stdout: string; stderr: string }>;
13+
let execFile: ExecFileType | undefined;
14+
if (utils.isDesktopContext()) {
15+
const nodeUtil = require("util");
16+
const child_process = require("child_process");
17+
execFile = nodeUtil.promisify(child_process.execFile) as ExecFileType;
18+
}
619

720
/** Tell both Git and VSCode that commit messages should contain diffs */
821
export async function enable() {
9-
return Promise.all([
10-
// Set command line verbose-commits-by-default
11-
execFile("git", ["config", "--global", "commit.verbose", "true"]),
22+
const promises = [];
1223

13-
// Tell VSCode to do verbose commits
24+
// Set command line verbose-commits-by-default only on desktop
25+
if (execFile) {
26+
promises.push(
27+
execFile("git", ["config", "--global", "commit.verbose", "true"]),
28+
);
29+
}
30+
31+
// Tell VSCode to do verbose commits
32+
promises.push(
1433
vscode.workspace
1534
.getConfiguration("git")
1635
.update("verboseCommit", true, vscode.ConfigurationTarget.Global),
17-
]);
36+
);
37+
38+
return Promise.all(promises);
1839
}
1940

2041
/**
@@ -45,6 +66,11 @@ export function doesVsCodeDoVerboseCommits(): boolean {
4566
}
4667

4768
export async function doesGitDoVerboseCommits(): Promise<boolean> {
69+
if (!execFile) {
70+
// Not desktop context, can't check git config, report that it doesn't need
71+
// changing
72+
return true;
73+
}
4874
try {
4975
const { stdout } = await execFile("git", [
5076
"config",

webpack.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ function createExtensionConfig ({ target, output, plugins }) {
2727
mainFields: ['browser', 'module', 'main'],
2828
extensions: ['.ts'],
2929
alias: {},
30-
fallback: {}
30+
fallback: {
31+
util: false,
32+
child_process: false
33+
}
3134
},
3235
module: {
3336
rules: [

0 commit comments

Comments
 (0)