Skip to content

Commit 2e2658c

Browse files
authored
Avoid circular dependencies in SemVer (#957)
A circular dependency between the Range and Comparator classes can cause issues for consumers who are trying to bundle extensions with vscode-languageclient as a dependency. See related GitHub issue from [npm/node-semver](https://github.com/npm/node-semver) - [[BUG] the package isn't compatible with Rollup due to require cycle #381](npm/node-semver#381)
1 parent 64d0e5f commit 2e2658c

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

client/src/node/main.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import ChildProcess = cp.ChildProcess;
88
import * as fs from 'fs';
99
import * as path from 'path';
1010

11-
import * as SemVer from 'semver';
12-
1311
import { workspace as Workspace, Disposable, version as VSCodeVersion } from 'vscode';
1412

1513
import * as Is from '../common/utils/is';
@@ -18,6 +16,10 @@ import { BaseLanguageClient, LanguageClientOptions, MessageTransports } from '..
1816
import { terminate } from './processes';
1917
import { StreamMessageReader, StreamMessageWriter, IPCMessageReader, IPCMessageWriter, createClientPipeTransport, generateRandomPipeName, createClientSocketTransport, InitializeParams} from 'vscode-languageserver-protocol/node';
2018

19+
// Import SemVer functions individually to avoid circular dependencies in SemVer
20+
import semverParse = require('semver/functions/parse');
21+
import semverSatisfies = require('semver/functions/satisfies');
22+
2123
export * from 'vscode-languageserver-protocol/node';
2224
export * from '../common/api';
2325

@@ -168,15 +170,15 @@ export class LanguageClient extends BaseLanguageClient {
168170
}
169171

170172
private checkVersion() {
171-
const codeVersion = SemVer.parse(VSCodeVersion);
173+
const codeVersion = semverParse(VSCodeVersion);
172174
if (!codeVersion) {
173175
throw new Error(`No valid VS Code version detected. Version string is: ${VSCodeVersion}`);
174176
}
175177
// Remove the insider pre-release since we stay API compatible.
176178
if (codeVersion.prerelease && codeVersion.prerelease.length > 0) {
177179
codeVersion.prerelease = [];
178180
}
179-
if (!SemVer.satisfies(codeVersion, REQUIRED_VSCODE_VERSION)) {
181+
if (!semverSatisfies(codeVersion, REQUIRED_VSCODE_VERSION)) {
180182
throw new Error(`The language client requires VS Code version ${REQUIRED_VSCODE_VERSION} but received version ${VSCodeVersion}`);
181183
}
182184
}

0 commit comments

Comments
 (0)