Skip to content

Commit 18f1208

Browse files
committed
fixing the CI
1 parent 79d054b commit 18f1208

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
node-version: [20, 22, 24]
17+
node-version: [22, 24]
1818

1919
steps:
2020
- name: Checkout code

lib/detectors/version-managers/n.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const fs = require('node:fs')
22
const path = require('node:path')
3-
const { execSync } = require('node:child_process')
4-
const { isWindows, findExecutable, extractVersionFromPath, normalizePathSeparators } = require('../../platform-utils')
3+
const { isWindows } = require('../../platform-utils')
4+
const platformUtils = require('../../platform-utils')
5+
const childProcess = require('node:child_process')
56

67
/**
78
* Try to detect Node.js version from n (Node.js version manager by TJ)
@@ -73,11 +74,11 @@ function detectNodeVersionFromN () {
7374

7475
// Strategy 4: Check where node points to n-managed version (cross-platform)
7576
try {
76-
const nodePath = findExecutable('node')
77+
const nodePath = platformUtils.findExecutable('node')
7778
if (nodePath) {
78-
const normalizedPath = normalizePathSeparators(nodePath)
79+
const normalizedPath = platformUtils.normalizePathSeparators(nodePath)
7980
if (normalizedPath.includes('/n/versions/node/')) {
80-
const version = extractVersionFromPath(normalizedPath)
81+
const version = platformUtils.extractVersionFromPath(normalizedPath)
8182
if (version) {
8283
return `v${version}`
8384
}
@@ -89,13 +90,13 @@ function detectNodeVersionFromN () {
8990

9091
// Strategy 5: Try n command as fallback (simplified, no shell redirection)
9192
try {
92-
const version = execSync('n bin', {
93+
const version = childProcess.execSync('n bin', {
9394
encoding: 'utf-8',
9495
stdio: ['pipe', 'pipe', 'ignore'],
9596
timeout: 2000
9697
}).trim()
9798

98-
const extractedVersion = extractVersionFromPath(normalizePathSeparators(version))
99+
const extractedVersion = platformUtils.extractVersionFromPath(platformUtils.normalizePathSeparators(version))
99100
if (extractedVersion) {
100101
return `v${extractedVersion}`
101102
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"engines": {
2929
"node": ">=22.0.0"
3030
},
31-
"packageManager": "pnpm@10.20.0",
31+
"packageManager": "pnpm@10.22.0",
3232
"publishConfig": {
3333
"registry": "http://packages-internal.nodesource.io"
3434
},

test/version-managers-mocked.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const { test, describe } = require('node:test')
22
const assert = require('node:assert')
3+
const sinon = require('sinon')
4+
const fs = require('node:fs')
5+
const childProcess = require('node:child_process')
6+
const platformUtils = require('../lib/platform-utils')
37

48
describe('Version Managers Mocked - Module Imports', () => {
59
test('nvm detector can be imported', () => {
@@ -95,14 +99,29 @@ describe('Version Managers Mocked - Default Behavior', () => {
9599
test('n returns null when not configured', () => {
96100
const originalNPrefix = process.env.N_PREFIX
97101

102+
// Mock dependencies to ensure clean environment regardless of actual system state
103+
const existsSyncStub = sinon.stub(fs, 'existsSync')
104+
const findExecutableStub = sinon.stub(platformUtils, 'findExecutable')
105+
const execSyncStub = sinon.stub(childProcess, 'execSync')
106+
98107
try {
99108
delete process.env.N_PREFIX
100109

110+
// Configure mocks to simulate "not found" state
111+
existsSyncStub.returns(false)
112+
findExecutableStub.returns(null)
113+
execSyncStub.throws(new Error('Command failed'))
114+
101115
const { detectNodeVersionFromN } = require('../lib/detectors/version-managers/n')
102116
const version = detectNodeVersionFromN()
103117
assert.strictEqual(version, null, 'Should return null when N not configured')
104118
} finally {
105119
if (originalNPrefix) process.env.N_PREFIX = originalNPrefix
120+
121+
// Restore stubs
122+
existsSyncStub.restore()
123+
findExecutableStub.restore()
124+
execSyncStub.restore()
106125
}
107126
})
108127
})

0 commit comments

Comments
 (0)