Skip to content

Commit

Permalink
Avoid circular dependencies in SemVer (#957)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
sam-b-rose committed Jun 22, 2022
1 parent 64d0e5f commit 2e2658c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions client/src/node/main.ts
Expand Up @@ -8,8 +8,6 @@ import ChildProcess = cp.ChildProcess;
import * as fs from 'fs';
import * as path from 'path';

import * as SemVer from 'semver';

import { workspace as Workspace, Disposable, version as VSCodeVersion } from 'vscode';

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

// Import SemVer functions individually to avoid circular dependencies in SemVer
import semverParse = require('semver/functions/parse');
import semverSatisfies = require('semver/functions/satisfies');

export * from 'vscode-languageserver-protocol/node';
export * from '../common/api';

Expand Down Expand Up @@ -168,15 +170,15 @@ export class LanguageClient extends BaseLanguageClient {
}

private checkVersion() {
const codeVersion = SemVer.parse(VSCodeVersion);
const codeVersion = semverParse(VSCodeVersion);
if (!codeVersion) {
throw new Error(`No valid VS Code version detected. Version string is: ${VSCodeVersion}`);
}
// Remove the insider pre-release since we stay API compatible.
if (codeVersion.prerelease && codeVersion.prerelease.length > 0) {
codeVersion.prerelease = [];
}
if (!SemVer.satisfies(codeVersion, REQUIRED_VSCODE_VERSION)) {
if (!semverSatisfies(codeVersion, REQUIRED_VSCODE_VERSION)) {
throw new Error(`The language client requires VS Code version ${REQUIRED_VSCODE_VERSION} but received version ${VSCodeVersion}`);
}
}
Expand Down

0 comments on commit 2e2658c

Please sign in to comment.