mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-13 13:23:31 +08:00
perf(hooks): memoize isWSL detection at module load
Avoids reading /proc/version twice (once in run(), once in findPowerShell()) by computing the result once when the module loads.
This commit is contained in:
@@ -22,14 +22,14 @@ const TITLE = 'Claude Code';
|
|||||||
const MAX_BODY_LENGTH = 100;
|
const MAX_BODY_LENGTH = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if running on WSL (Windows Subsystem for Linux).
|
* Memoized WSL detection at module load (avoids repeated /proc/version reads).
|
||||||
*/
|
*/
|
||||||
function isWSL() {
|
let isWSL = false;
|
||||||
if (process.platform !== 'linux') return false;
|
if (process.platform === 'linux') {
|
||||||
try {
|
try {
|
||||||
return require('fs').readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft');
|
isWSL = require('fs').readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft');
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
isWSL = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ function isWSL() {
|
|||||||
* Returns { path, version } or null if none available.
|
* Returns { path, version } or null if none available.
|
||||||
*/
|
*/
|
||||||
function findPowerShell() {
|
function findPowerShell() {
|
||||||
if (!isWSL()) return null;
|
if (!isWSL) return null;
|
||||||
|
|
||||||
const candidates = [
|
const candidates = [
|
||||||
'pwsh.exe', // WSL interop resolves from Windows PATH
|
'pwsh.exe', // WSL interop resolves from Windows PATH
|
||||||
@@ -135,7 +135,7 @@ function run(raw) {
|
|||||||
|
|
||||||
if (isMacOS) {
|
if (isMacOS) {
|
||||||
notifyMacOS(TITLE, summary);
|
notifyMacOS(TITLE, summary);
|
||||||
} else if (isWSL()) {
|
} else if (isWSL) {
|
||||||
// WSL: try PowerShell 7 first, then Windows PowerShell
|
// WSL: try PowerShell 7 first, then Windows PowerShell
|
||||||
const ps = findPowerShell();
|
const ps = findPowerShell();
|
||||||
if (ps && isBurntToastAvailable(ps.path)) {
|
if (ps && isBurntToastAvailable(ps.path)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user