Skip to content

Commit f57ab9e

Browse files
dependabot[bot]Copilotchagong
authored
fix(deps): remove direct lru-cache dependency (#1926)
* chore(deps): bump lru-cache from 7.18.3 to 11.5.2 Bumps [lru-cache](https://github.com/isaacs/node-lru-cache) from 7.18.3 to 11.5.2. - [Changelog](https://github.com/isaacs/node-lru-cache/blob/main/CHANGELOG.md) - [Commits](isaacs/node-lru-cache@v7.18.3...v11.5.2) --- updated-dependencies: - dependency-name: lru-cache dependency-version: 11.5.2 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix(deps): remove direct lru-cache dependency Replace the narrow 32-entry cache usage with a local bounded LRU map so the extension retains VS Code 1.88 runtime compatibility. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: GitHub Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Changyong Gong <chagon@microsoft.com>
1 parent 49b2893 commit f57ab9e

6 files changed

Lines changed: 68 additions & 57 deletions

File tree

‎ThirdPartyNotices.txt‎

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ This project incorporates components from the projects listed below. The origina
1111
4. Eclipse Java development tools (https://www.eclipse.org/jdt/)
1212
5. Eskibear/vscode-extension-telemetry-wrapper (https://github.com/Eskibear/vscode-extension-telemetry-wrapper)
1313
6. google/gson (https://github.com/google/gson)
14-
7. isaacs/node-lru-cache (https://github.com/isaacs/node-lru-cache)
15-
8. jacoco/jacoco (https://github.com/jacoco/jacoco)
16-
9. jprichardson/node-fs-extra (https://github.com/jprichardson/node-fs-extra)
17-
10. junit-team/junit5 (https://github.com/junit-team/junit5)
18-
11. lodash/lodash (https://github.com/lodash/lodash)
19-
12. microsoft/vscode-languageserver-node (https://github.com/microsoft/vscode-languageserver-node)
20-
13. ota4j-team/opentest4j (https://github.com/ota4j-team/opentest4j)
14+
7. jacoco/jacoco (https://github.com/jacoco/jacoco)
15+
8. jprichardson/node-fs-extra (https://github.com/jprichardson/node-fs-extra)
16+
9. junit-team/junit5 (https://github.com/junit-team/junit5)
17+
10. lodash/lodash (https://github.com/lodash/lodash)
18+
11. microsoft/vscode-languageserver-node (https://github.com/microsoft/vscode-languageserver-node)
19+
12. ota4j-team/opentest4j (https://github.com/ota4j-team/opentest4j)
2120

2221
%% Apache Commons Lang NOTICES AND INFORMATION BEGIN HERE
2322
=========================================
@@ -956,26 +955,6 @@ END OF Eskibear/vscode-extension-telemetry-wrapper NOTICES AND INFORMATION
956955
=========================================
957956
END OF google/gson NOTICES AND INFORMATION
958957

959-
%% isaacs/node-lru-cache NOTICES AND INFORMATION BEGIN HERE
960-
=========================================
961-
The ISC License
962-
963-
Copyright (c) Isaac Z. Schlueter and Contributors
964-
965-
Permission to use, copy, modify, and/or distribute this software for any
966-
purpose with or without fee is hereby granted, provided that the above
967-
copyright notice and this permission notice appear in all copies.
968-
969-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
970-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
971-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
972-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
973-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
974-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
975-
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
976-
=========================================
977-
END OF isaacs/node-lru-cache NOTICES AND INFORMATION
978-
979958
%% jacoco/jacoco NOTICES AND INFORMATION BEGIN HERE
980959
=========================================
981960
License

‎package-lock.json‎

Lines changed: 6 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@
554554
"devDependencies": {
555555
"@types/fs-extra": "^9.0.13",
556556
"@types/lodash": "^4.17.25",
557-
"@types/lru-cache": "^7.10.10",
558557
"@types/minimatch": "^5.1.2",
559558
"@types/mocha": "^9.1.1",
560559
"@types/node": "^16.18.13",
@@ -576,7 +575,6 @@
576575
"fs-extra": "^10.1.0",
577576
"iconv-lite": "^0.7.3",
578577
"lodash": "^4.18.1",
579-
"lru-cache": "^7.17.0",
580578
"minimatch": "^3.1.5",
581579
"vscode-extension-telemetry-wrapper": "^0.15.3",
582580
"vscode-languageclient": "6.0.0-next.9",

‎src/controller/debouncing.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import * as LRUCache from 'lru-cache';
54
import { Uri } from 'vscode';
5+
import { BoundedCache } from '../utils/BoundedCache';
66

7-
export const lruCache: LRUCache<Uri, MovingAverage> = new LRUCache<Uri, MovingAverage>({max: 32});
7+
export const lruCache: BoundedCache<Uri, MovingAverage> = new BoundedCache<Uri, MovingAverage>(32);
88

99
// See: https://github.com/microsoft/vscode/blob/94c9ea46838a9a619aeafb7e8afd1170c967bb55/src/vs/base/common/numbers.ts
1010
export class MovingAverage {

‎src/utils/BoundedCache.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
export class BoundedCache<K, V> {
5+
6+
private readonly entries: Map<K, V> = new Map<K, V>();
7+
8+
constructor(private readonly maxSize: number) {
9+
}
10+
11+
public get(key: K): V | undefined {
12+
const value: V | undefined = this.entries.get(key);
13+
if (value !== undefined) {
14+
this.entries.delete(key);
15+
this.entries.set(key, value);
16+
}
17+
return value;
18+
}
19+
20+
public set(key: K, value: V): void {
21+
this.entries.delete(key);
22+
this.entries.set(key, value);
23+
if (this.entries.size > this.maxSize) {
24+
const oldest: IteratorResult<K> = this.entries.keys().next();
25+
if (!oldest.done) {
26+
this.entries.delete(oldest.value);
27+
}
28+
}
29+
}
30+
}

‎test/suite/debouncing.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
'use strict';
5+
6+
import * as assert from 'assert';
7+
import { BoundedCache } from '../../src/utils/BoundedCache';
8+
9+
// tslint:disable: only-arrow-functions
10+
suite('Debouncing Tests', () => {
11+
12+
test('evicts the least recently used entry', () => {
13+
const cache: BoundedCache<string, number> = new BoundedCache<string, number>(2);
14+
cache.set('first', 1);
15+
cache.set('second', 2);
16+
17+
assert.strictEqual(cache.get('first'), 1);
18+
cache.set('third', 3);
19+
20+
assert.strictEqual(cache.get('second'), undefined);
21+
assert.strictEqual(cache.get('first'), 1);
22+
assert.strictEqual(cache.get('third'), 3);
23+
});
24+
});

0 commit comments

Comments
 (0)