Skip to content

Commit 488a661

Browse files
authored
Merge pull request #17 from mskelton/feature/special-versions
Support for special types of versions
2 parents 647ecdb + 47d25f0 commit 488a661

File tree

7 files changed

+561
-193
lines changed

7 files changed

+561
-193
lines changed

package-lock.json

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

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@
6969
"main": "./out/extension.js",
7070
"devDependencies": {
7171
"@mskelton/eslint-config": "^7.1.0",
72-
"@types/jest": "^29.2.4",
73-
"@types/node": "^18.11.17",
72+
"@types/jest": "^29.2.6",
73+
"@types/node": "^18.11.18",
7474
"@types/vscode": "^1.74.0",
75-
"@typescript-eslint/eslint-plugin": "^5.47.0",
76-
"@typescript-eslint/parser": "^5.47.0",
77-
"esbuild": "^0.16.10",
78-
"eslint": "^8.30.0",
79-
"eslint-plugin-jest": "^27.1.7",
75+
"@typescript-eslint/eslint-plugin": "^5.48.2",
76+
"@typescript-eslint/parser": "^5.48.2",
77+
"esbuild": "^0.17.3",
78+
"eslint": "^8.32.0",
79+
"eslint-plugin-jest": "^27.2.1",
8080
"eslint-plugin-promise": "^6.1.1",
8181
"jest": "^29.3.1",
82-
"prettier": "^2.8.1",
83-
"semantic-release-vsce": "^5.5.2",
84-
"ts-jest": "^29.0.3",
82+
"prettier": "^2.8.3",
83+
"semantic-release-vsce": "^5.5.5",
84+
"ts-jest": "^29.0.5",
8585
"typescript": "^4.9.4"
8686
},
8787
"dependencies": {

src/Diagnostic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export const generatePackagesDiagnostics = async (
245245
return
246246
}
247247

248-
if (packageInfo.isVersionComplex()) {
248+
if (packageInfo.isVersionComplex() || packageInfo.isVersionIgnorable()) {
249249
return
250250
}
251251

src/PackageInfo.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ const PACKAGE_NAME_REGEXP =
1717

1818
const PACKAGE_VERSION_COMPLEX_REGEXP = /\s|\|\|/
1919

20+
const PACKAGE_VERSION_PATH_REGEXP = /^(?:\.\.?|~)?\//
21+
22+
const PACKAGE_VERSION_PROTOCOL_REGEX = /^[\w+]+:/
23+
24+
const PACKAGE_VERSION_GITHUB_REGEX = /^[a-zA-Z0-9][\w-]*[a-zA-Z0-9]\//
25+
2026
const PACKAGE_DIFF_LEVELS: Record<ReleaseType, number> = {
2127
major: 2,
2228
minor: 1,
@@ -56,6 +62,16 @@ export class PackageInfo {
5662
return PACKAGE_VERSION_COMPLEX_REGEXP.test(this.version)
5763
}
5864

65+
// Check if a valid version, but not a semver.
66+
// Anyway, it will be ignored, but not marked as invalid.
67+
public isVersionIgnorable(): boolean {
68+
return (
69+
PACKAGE_VERSION_PATH_REGEXP.test(this.version) ||
70+
PACKAGE_VERSION_PROTOCOL_REGEX.test(this.version) ||
71+
PACKAGE_VERSION_GITHUB_REGEX.test(this.version)
72+
)
73+
}
74+
5975
// If the version specified by the user is a valid range.
6076
// Eg. { "package": "blah blah blah" } must be invalid and "^3.0" valid.
6177
public isVersionValidRange(): boolean {

src/TestUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { name as packageName } from "./plugin.json"
1414

1515
import * as Utils from "./Utils"
1616

17+
// eslint-disable-next-line jest/no-untyped-mock-factory
1718
jest.mock("./Utils", () => ({
1819
__esModule: true,
1920

src/Utils.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { cacheEnabled, fetchLite, lazyCallback, promiseLimit } from "./Utils"
22

3-
const TIMER_MULTIPLER = 3
3+
const TIMER_MULTIPLIER = 3
44

55
describe("utils", () => {
66
it("lazy callback: immediate call", async () => {
@@ -14,18 +14,18 @@ describe("utils", () => {
1414

1515
// Must run immediately:
1616
lazy(() => {
17-
expect(Date.now() - now).toBeLessThan(25 * TIMER_MULTIPLER)
17+
expect(Date.now() - now).toBeLessThan(25 * TIMER_MULTIPLIER)
1818
})
1919

20-
await new Promise((resolve) => setTimeout(resolve, 50 * TIMER_MULTIPLER))
20+
await new Promise((resolve) => setTimeout(resolve, 50 * TIMER_MULTIPLIER))
2121
})
2222

2323
it("lazy callback: avoid first call", async () => {
2424
expect.assertions(1)
2525

2626
const lazy = lazyCallback((callNumber: () => void) => {
2727
callNumber()
28-
}, 25 * TIMER_MULTIPLER)
28+
}, 25 * TIMER_MULTIPLIER)
2929

3030
const now = Date.now()
3131

@@ -34,27 +34,27 @@ describe("utils", () => {
3434

3535
// Must run after 25ms:
3636
lazy(() => {
37-
expect(Date.now() - now).toBeGreaterThanOrEqual(25 * TIMER_MULTIPLER)
37+
expect(Date.now() - now).toBeGreaterThanOrEqual(25 * TIMER_MULTIPLIER)
3838
})
3939

40-
await new Promise((resolve) => setTimeout(resolve, 50 * TIMER_MULTIPLER))
40+
await new Promise((resolve) => setTimeout(resolve, 50 * TIMER_MULTIPLIER))
4141
})
4242

4343
it("lazy callback: wait first call", async () => {
4444
expect.assertions(1)
4545

4646
const lazy = lazyCallback((callNumber: () => void) => {
4747
callNumber()
48-
}, 25 * TIMER_MULTIPLER)
48+
}, 25 * TIMER_MULTIPLIER)
4949

5050
const now = Date.now()
5151

5252
// Must run after 25ms:
5353
lazy(() => {
54-
expect(Date.now() - now).toBeGreaterThanOrEqual(25 * TIMER_MULTIPLER)
54+
expect(Date.now() - now).toBeGreaterThanOrEqual(25 * TIMER_MULTIPLIER)
5555
})
5656

57-
await new Promise((resolve) => setTimeout(resolve, 50 * TIMER_MULTIPLER))
57+
await new Promise((resolve) => setTimeout(resolve, 50 * TIMER_MULTIPLIER))
5858
})
5959

6060
it("lazy callback: avoid second call", async () => {
@@ -65,13 +65,13 @@ describe("utils", () => {
6565
callNumber()
6666
},
6767
0,
68-
25 * TIMER_MULTIPLER
68+
25 * TIMER_MULTIPLIER
6969
)
7070

7171
const now = Date.now()
7272

7373
// Must run immediately:
74-
lazy(() => expect(Date.now() - now).toBeLessThan(25 * TIMER_MULTIPLER))
74+
lazy(() => expect(Date.now() - now).toBeLessThan(25 * TIMER_MULTIPLIER))
7575

7676
// Must be skipped: too fast call.
7777
lazy(() => {
@@ -82,11 +82,11 @@ describe("utils", () => {
8282
lazy(() => {
8383
const nowDiff = Date.now() - now
8484

85-
expect(nowDiff).toBeGreaterThanOrEqual(25 * TIMER_MULTIPLER)
86-
expect(nowDiff).toBeLessThan(50 * TIMER_MULTIPLER)
85+
expect(nowDiff).toBeGreaterThanOrEqual(25 * TIMER_MULTIPLIER)
86+
expect(nowDiff).toBeLessThan(50 * TIMER_MULTIPLIER)
8787
})
8888

89-
await new Promise((resolve) => setTimeout(resolve, 50 * TIMER_MULTIPLER))
89+
await new Promise((resolve) => setTimeout(resolve, 50 * TIMER_MULTIPLIER))
9090
})
9191

9292
it("promise limit: prevent multiple simultaneous processes", async () => {
@@ -95,7 +95,7 @@ describe("utils", () => {
9595
const processesLimit = promiseLimit(2)
9696

9797
const delay = (): Promise<unknown> =>
98-
new Promise((resolve) => setTimeout(resolve, 25 * TIMER_MULTIPLER))
98+
new Promise((resolve) => setTimeout(resolve, 25 * TIMER_MULTIPLIER))
9999

100100
const now = Date.now()
101101

@@ -108,7 +108,7 @@ describe("utils", () => {
108108
])
109109

110110
// The total time should be 50ms.
111-
expect(Date.now() - now).toBeGreaterThanOrEqual(50 * TIMER_MULTIPLER)
111+
expect(Date.now() - now).toBeGreaterThanOrEqual(50 * TIMER_MULTIPLIER)
112112
})
113113

114114
it("promise limit: run all processes simultaneous (no limit)", async () => {
@@ -117,7 +117,7 @@ describe("utils", () => {
117117
const processesLimit = promiseLimit(0)
118118

119119
const delay = (): Promise<unknown> =>
120-
new Promise((resolve) => setTimeout(resolve, 25 * TIMER_MULTIPLER))
120+
new Promise((resolve) => setTimeout(resolve, 25 * TIMER_MULTIPLIER))
121121

122122
const now = Date.now()
123123

@@ -129,7 +129,7 @@ describe("utils", () => {
129129
])
130130

131131
// The total time should be lower than 50ms.
132-
expect(Date.now() - now).toBeLessThan(50 * TIMER_MULTIPLER)
132+
expect(Date.now() - now).toBeLessThan(50 * TIMER_MULTIPLIER)
133133
})
134134

135135
it("cache enabled (mock function-only)", () => {

src/extension.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line jest/no-untyped-mock-factory
12
jest.mock("child_process", () => ({
23
__esModule: true,
34
...jest.requireActual("child_process"),
@@ -795,4 +796,52 @@ describe("security advisories", () => {
795796
expect(decorations[0]).toHaveLength(1)
796797
expect(decorations[1]).toContain("Security advisory (HIGH/5.6):")
797798
})
799+
800+
it("ignore directory-versions", async () => {
801+
const { decorations, diagnostics } = await vscodeSimulator({
802+
packageJson: {
803+
dependencies: {
804+
"npm-outdated-2": "../src",
805+
"npm-outdated-3": "./src",
806+
"npm-outdated-4": "~/src",
807+
"npm-outdated-5": "/src",
808+
},
809+
},
810+
})
811+
812+
expect(diagnostics).toHaveLength(0)
813+
expect(decorations).toHaveLength(0)
814+
})
815+
816+
it("ignore protocol versions", async () => {
817+
const { decorations, diagnostics } = await vscodeSimulator({
818+
packageJson: {
819+
dependencies: {
820+
"npm-outdated-1": "file:/src",
821+
"npm-outdated-2": "http://...",
822+
"npm-outdated-3": "https://...",
823+
"npm-outdated-4": "git://...",
824+
"npm-outdated-5": "git+ssh://...",
825+
},
826+
},
827+
})
828+
829+
expect(diagnostics).toHaveLength(0)
830+
expect(decorations).toHaveLength(0)
831+
})
832+
833+
it("ignore github packages", async () => {
834+
const { decorations, diagnostics } = await vscodeSimulator({
835+
packageJson: {
836+
dependencies: {
837+
"npm-outdated-1": "mskelton/vscode-npm-outdated",
838+
"npm-outdated-2": "mskelton/vscode-npm-outdated#1234567890",
839+
"npm-outdated-3": "mskelton/vscode-npm-outdated#feature/branch",
840+
},
841+
},
842+
})
843+
844+
expect(diagnostics).toHaveLength(0)
845+
expect(decorations).toHaveLength(0)
846+
})
798847
})

0 commit comments

Comments
 (0)