Skip to content

Commit c0b48db

Browse files
committed
fix version comparison
1 parent 18281cb commit c0b48db

File tree

5 files changed

+24
-54
lines changed

5 files changed

+24
-54
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
"dependencies": {
123123
"@octokit/rest": "^19.0.11",
124124
"chokidar": "^3.5.3",
125-
"compare-versions": "^6.1.0",
126125
"date-fns": "^2.30.0",
127126
"extract-zip": "^2.0.1",
128127
"fs-extra": "11.1.1",
@@ -133,6 +132,7 @@
133132
"lodash.debounce": "^4.0.8",
134133
"lodash.pick": "^4.4.0",
135134
"micromatch": "^4.0.5",
135+
"semver": "^7.5.4",
136136
"tmp-promise": "^3.0.3",
137137
"tslib": "^2.6.2"
138138
},
@@ -148,7 +148,7 @@
148148
"@typescript-eslint/parser": "^6.7.5",
149149
"cross-env": "^7.0.3",
150150
"eslint": "^8.51.0",
151-
"eslint-config-zoro": "^6.0.0",
151+
"eslint-config-zoro": "^6.0.1",
152152
"eslint-plugin-node": "^11.1.0",
153153
"eslint-webpack-plugin": "^4.0.1",
154154
"fork-ts-checker-webpack-plugin": "^9.0.0",

src/core/Environment.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ export class Environment
5757
public readonly snippetsDirectory: string;
5858

5959
/**
60-
* Gets the full path of VSCode's `.obsolete file`.
60+
* Gets the full path of VSCode's `.obsolete` file.
6161
*/
6262
public readonly obsoleteFilePath: string;
6363

64+
/**
65+
* Gets the full path of VSCode's `extensions.json` file.
66+
*/
67+
public readonly extensionsFilePath: string;
68+
6469
private static _instance: Environment;
6570

6671
private constructor()
@@ -76,6 +81,7 @@ export class Environment
7681
this.userDirectory = path.join(this.dataDirectory, "User");
7782
this.snippetsDirectory = this.getSettingsFilePath("snippets");
7883
this.obsoleteFilePath = path.join(this.extensionsDirectory, ".obsolete");
84+
this.extensionsFilePath = path.join(this.extensionsDirectory, "extensions.json");
7985
}
8086

8187
/**

src/core/Extension.ts

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class Extension
151151
}
152152

153153
// Added since VSCode v1.20.
154-
await this.updateObsolete(added, updated, removed);
154+
await this.removeVSCodeExtensionFiles();
155155

156156
return result as ISyncedItem;
157157
}
@@ -233,52 +233,21 @@ export class Extension
233233
}
234234

235235
/**
236-
* Updates the VSCode `.obsolete` file.
236+
* Removes VSCode `.obsolete` and `extensions.json` file.
237237
*/
238-
public async updateObsolete(
239-
added: IExtension[] = [],
240-
removed: IExtension[] = [],
241-
updated: IExtension[] = []
242-
): Promise<void>
238+
public async removeVSCodeExtensionFiles(): Promise<void>
243239
{
244-
const filepath = this._env.obsoleteFilePath;
245-
// Record<extensionFolderName, boolean>
246-
let obsolete: Record<string, boolean> | undefined;
247240
try
248241
{
249-
obsolete = await fs.readJson(filepath);
250-
}
251-
catch
252-
{
242+
await fs.remove(this._env.obsoleteFilePath);
253243
}
244+
catch { }
254245

255-
if (obsolete != null)
246+
try
256247
{
257-
for (const ext of [...added, ...updated])
258-
{
259-
delete obsolete[this._env.getExtensionDirectoryName(ext)];
260-
}
261-
262-
for (const ext of removed)
263-
{
264-
obsolete[this._env.getExtensionDirectoryName(ext)] = true;
265-
}
266-
267-
try
268-
{
269-
if (Object.keys(obsolete).length > 0)
270-
{
271-
await fs.outputJson(filepath, obsolete);
272-
}
273-
else
274-
{
275-
await fs.remove(filepath);
276-
}
277-
}
278-
catch
279-
{
280-
}
248+
await fs.remove(this._env.extensionsFilePath);
281249
}
250+
catch { }
282251
}
283252

284253
/**

src/utils/vscodeWebAPI.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { satisfies } from "compare-versions";
1+
import { coerce, satisfies } from "semver";
22
import * as vscode from "vscode";
33

44
import { CaseInsensitiveMap } from "../collections";
@@ -101,10 +101,10 @@ export function isVSIXSupported(version: ExtensionVersion, includePreRelease: bo
101101
}
102102
}
103103

104-
const requiredVersion = version.properties?.find(p => p.key === ExtensionPropertyType.ENGINE)?.value;
104+
const requiredVersion = coerce(version.properties?.find(p => p.key === ExtensionPropertyType.ENGINE)?.value)?.version;
105105
try
106106
{
107-
return requiredVersion == null ? true : satisfies(vscode.version, requiredVersion);
107+
return requiredVersion == null ? true : satisfies(vscode.version, `^${requiredVersion}`);
108108
}
109109
catch
110110
{

yarn.lock

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,11 +1875,6 @@ commander@^2.20.0:
18751875
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
18761876
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
18771877

1878-
compare-versions@^6.1.0:
1879-
version "6.1.0"
1880-
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-6.1.0.tgz#3f2131e3ae93577df111dba133e6db876ffe127a"
1881-
integrity sha512-LNZQXhqUvqUTotpZ00qLSaify3b4VFD588aRr8MKFw4CMUr98ytzCW5wDH5qx/DEY5kCDXcbcRuCqL0szEf2tg==
1882-
18831878
18841879
version "0.0.1"
18851880
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@@ -2107,10 +2102,10 @@ escape-string-regexp@^4.0.0:
21072102
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"
21082103
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==
21092104

2110-
eslint-config-zoro@^6.0.0:
2111-
version "6.0.0"
2112-
resolved "https://registry.yarnpkg.com/eslint-config-zoro/-/eslint-config-zoro-6.0.0.tgz#b62949dfbc1be452c6bfd33a5c7218f4400c5db6"
2113-
integrity sha512-6KrqejHH2JbUaG4KnmJW8cvaoAEf0th7c05uVRZiE2lWB4WXEaN/G3y0b5tTYIon/UBtAYRv3RS8zmsEBTVLwg==
2105+
eslint-config-zoro@^6.0.1:
2106+
version "6.0.1"
2107+
resolved "https://registry.yarnpkg.com/eslint-config-zoro/-/eslint-config-zoro-6.0.1.tgz#4c38bafc2525d13c4edef2a7f1bf17cdc9fe7e80"
2108+
integrity sha512-LlLyeF/l5gTROo7le5iVVPUf2eFcwM4i60g7zXv+1WwIYP1KaZ0M08RCvjTBorHYcSsh3drSWKw+fh29SUEdhw==
21142109

21152110
eslint-plugin-es@^3.0.0:
21162111
version "3.0.1"

0 commit comments

Comments
 (0)