-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check for unsupported node versions
- Loading branch information
Showing
14 changed files
with
227 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Severity } from "@html-validate/stylish/dist/severity"; | ||
import PackageJson from "../types/package-json"; | ||
import { outdatedEngines } from "./outdated-engines"; | ||
|
||
let pkg: PackageJson; | ||
const ruleId = "outdated-engines"; | ||
const severity = Severity.ERROR; | ||
|
||
beforeEach(() => { | ||
pkg = { | ||
name: "mock-package", | ||
version: "1.2.3", | ||
engines: {}, | ||
}; | ||
}); | ||
|
||
describe("should return error when unsupported version satisfies engines.node", () => { | ||
it.each` | ||
range | description | date | ||
${">= 0.10.x"} | ${"Node 0.10"} | ${"2016-10-31"} | ||
${">= 0.12.x"} | ${"Node 0.12"} | ${"2016-12-31"} | ||
${">= 4.x"} | ${"Node 4"} | ${"2018-04-30"} | ||
${">= 5.x"} | ${"Node 5"} | ${"2016-06-30"} | ||
${">= 6.x"} | ${"Node 6"} | ${"2019-04-30"} | ||
${">= 7.x"} | ${"Node 7"} | ${"2017-06-30"} | ||
${">= 8.x"} | ${"Node 8"} | ${"2019-12-31"} | ||
${">= 9.x"} | ${"Node 9"} | ${"2018-06-30"} | ||
`("$description", ({ range, description, date }) => { | ||
expect.assertions(1); | ||
pkg.engines.node = range; | ||
expect(Array.from(outdatedEngines(pkg))).toEqual([ | ||
{ | ||
ruleId: "outdated-engines", | ||
severity: Severity.ERROR, | ||
message: `engines.node is satisfied by ${description} (EOL since ${date})`, | ||
line: 1, | ||
column: 1, | ||
}, | ||
]); | ||
}); | ||
}); | ||
|
||
it("should return error engines.node is not a valid semver range", () => { | ||
expect.assertions(1); | ||
pkg.engines.node = "foobar"; | ||
expect(Array.from(outdatedEngines(pkg))).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"column": 1, | ||
"line": 1, | ||
"message": "engines.node \\"foobar\\" is not a valid semver range", | ||
"ruleId": "outdated-engines", | ||
"severity": 2, | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it("should return error engines.node is missing", () => { | ||
expect.assertions(1); | ||
delete pkg.engines.node; | ||
expect(Array.from(outdatedEngines(pkg))).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"column": 1, | ||
"line": 1, | ||
"message": "Missing engines.node field", | ||
"ruleId": "outdated-engines", | ||
"severity": 2, | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it("should return error engines is missing", () => { | ||
expect.assertions(1); | ||
delete pkg.engines; | ||
expect(Array.from(outdatedEngines(pkg))).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"column": 1, | ||
"line": 1, | ||
"message": "Missing engines.node field", | ||
"ruleId": "outdated-engines", | ||
"severity": 2, | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it("should not return error when engines.node only supports active versions", () => { | ||
expect.assertions(1); | ||
pkg.engines.node = ">= 10"; | ||
expect(Array.from(outdatedEngines(pkg))).toMatchInlineSnapshot(`Array []`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import semver from "semver"; | ||
import { Severity } from "@html-validate/stylish/dist/severity"; | ||
import { Message } from "../message"; | ||
import PackageJson from "../types/package-json"; | ||
|
||
const ruleId = "outdated-engines"; | ||
const severity = Severity.ERROR; | ||
|
||
interface EOLDescriptor { | ||
date: string; | ||
} | ||
|
||
const EOL: [string, EOLDescriptor][] = [ | ||
["0.10.99", { date: "2016-10-31" }], | ||
["0.12.99", { date: "2016-12-31" }], | ||
["4.99.99", { date: "2018-04-30" }], | ||
["5.99.99", { date: "2016-06-30" }], | ||
["6.99.99", { date: "2019-04-30" }], | ||
["7.99.99", { date: "2017-06-30" }], | ||
["8.99.99", { date: "2019-12-31" }], | ||
["9.99.99", { date: "2018-06-30" }], | ||
]; | ||
|
||
export function* outdatedEngines(pkg: PackageJson): Generator<Message> { | ||
if (!pkg.engines || !pkg.engines.node) { | ||
yield { | ||
ruleId, | ||
severity, | ||
message: "Missing engines.node field", | ||
line: 1, | ||
column: 1, | ||
}; | ||
return; | ||
} | ||
|
||
const range = pkg.engines.node; | ||
if (!semver.validRange(range)) { | ||
yield { | ||
ruleId, | ||
severity, | ||
message: `engines.node "${range}" is not a valid semver range`, | ||
line: 1, | ||
column: 1, | ||
}; | ||
return; | ||
} | ||
|
||
for (const [version, descriptor] of EOL) { | ||
const parsed = semver.parse(version); | ||
if (semver.satisfies(version, range)) { | ||
yield { | ||
ruleId, | ||
severity, | ||
message: `engines.node is satisfied by Node ${ | ||
parsed.major || `0.${parsed.minor}` | ||
} (EOL since ${descriptor.date})`, | ||
line: 1, | ||
column: 1, | ||
}; | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,8 @@ | |
"author": "", | ||
"repository": {}, | ||
"main": "", | ||
"license": "" | ||
"license": "", | ||
"engines": { | ||
"node": ">= 10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"name": "missing-fields", | ||
"version": "1.0.0", | ||
"files": [] | ||
"files": [], | ||
"engines": { | ||
"node": ">= 10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters