Skip to content

Commit

Permalink
Refactor to keep things more functional (#6)
Browse files Browse the repository at this point in the history
* feat: unified package parsing

* chore(deps): use std lib v0.185.0
* chore(deps): use deno.land version of zod

* feat: allow remote packages
* fix: language for @types
* fix: combine deps

* test: fix number of expected errors
  • Loading branch information
mxdvl authored May 3, 2023
1 parent d917a47 commit f1070a3
Show file tree
Hide file tree
Showing 21 changed files with 540 additions and 325 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ jobs:
run: deno lint src

- name: Test
run: deno test src --allow-net=unpkg.com
run: |
deno test src \
--allow-net \
--allow-env=CI
working_package:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -76,7 +79,7 @@ jobs:
--allow-read=. \
src/main.ts \
fixtures/package.json \
--verbose --cache --errors=7
--verbose --cache --errors=6
failing_duplicates:
runs-on: ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ deno run \
--cache
```

> **Note**
> - The `--cache` flag should help with speedups
> - The `--verbose` flag is very verbose
Expand Down Expand Up @@ -43,4 +42,3 @@ Wikipedia.
│ ○ △ □ × │
╰─────────╯
```

3 changes: 3 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"tasks": {
"test:dcr": "deno run -A src/cli.ts https://raw.githubusercontent.com/guardian/dotcom-rendering/mxdvl/pin-versions/dotcom-rendering/package.json --cache"
},
"compilerOptions": {
"noUncheckedIndexedAccess": true,
"lib": ["deno.window"]
Expand Down
51 changes: 29 additions & 22 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fixtures/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "npm-dependencies",
"version": "0.0.1",
"private": true,
"dependencies": {
"@types/node": "~18.11",
"@guardian/source-foundations": "8.0.0",
Expand Down
115 changes: 74 additions & 41 deletions src/check_types.test.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,105 @@
import { Range } from "https://deno.land/[email protected]/semver/mod.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { matched_types, mismatches } from "./check_types.ts";

Deno.test("will not complain on types without an associated pacakge", () => {
const mismatches = matched_types([
{ name: "@types/node", range: new Range("~8.11") },
{ name: "typescript", range: new Range("^4.9") },
]);
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { mismatches, types_matching_dependencies } from "./check_types.ts";

Deno.test("will not complain on types without an associated package", () => {
const mismatches = types_matching_dependencies({
devDependencies: {
"@types/node": "~18.11",
},
dependencies: {
"typescript": "^4.9",
},
});

assertEquals(mismatches, []);
});

Deno.test("will find potential mismatches on types with an associated pacakge", () => {
const matched = matched_types([
{ name: "@types/react", range: new Range("~16.1") },
{ name: "react", range: new Range("^16.1") },
]);
Deno.test("will find potential mismatches on types with an associated package", () => {
const matched = types_matching_dependencies(
{
devDependencies: {
"@types/react": "~16.1",
},
dependencies: {
"react": "^16.1",
},
},
);

assertEquals(matched, [
{
name: "react",
range: new Range("^16.1"),
type_range: new Range("~16.1"),
name_untyped: "react",
version_untyped: ("^16.1"),
name_typed: "@types/react",
version_typed: ("~16.1"),
},
]);
});

Deno.test("will error on caret ranges", () => {
const mismatched = mismatches(matched_types([
{ name: "@types/react", range: new Range("^17") },
{ name: "react", range: new Range("^17") },
]));
const mismatched = mismatches(types_matching_dependencies({
devDependencies: {
"@types/react": "^17",
},
dependencies: {
"react": "^17.0",
},
}));

assertEquals(mismatched, [
["react", "Invalid notation. Only pinned and tilde (~) ranges allowed"],
]);
});

Deno.test("will error on wide ranges", () => {
const mismatched = mismatches(matched_types([
{ name: "@types/react", range: new Range(">=17") },
{ name: "react", range: new Range("^17") },
]));
const mismatched = mismatches(types_matching_dependencies({
devDependencies: {
"@types/react": ">=17",
},
dependencies: {
"react": "^17.0",
},
}));

assertEquals(mismatched, [
["react", "Invalid notation. Only pinned and tilde (~) ranges allowed"],
]);
});

// TODO: check that these are valid?
Deno.test("will allow pinned versions", () => {
const mismatched = mismatches(matched_types([
{ name: "@types/react", range: new Range("17") },
{ name: "react", range: new Range("17") },
]));
const mismatched = mismatches(types_matching_dependencies({
devDependencies: {
"@types/react": "17",
},
dependencies: {
"react": "17",
},
}));

assertEquals(mismatched, []);
});

Deno.test("will error on invalid major ranges", () => {
const mismatched = mismatches(matched_types([
{ name: "@types/react", range: new Range("~17.1") },
{ name: "react", range: new Range("~18.1") },
]));
const mismatched = mismatches(types_matching_dependencies({
devDependencies: { "@types/react": "~17.1" },
dependencies: { "react": "~18.1" },
}));

assertEquals(mismatched, [
["react", "Mismatching major versions"],
]);
});

Deno.test("will error on invalid minor ranges", () => {
const mismatched = mismatches(matched_types([
{ name: "@types/react", range: new Range("~17.1") },
{ name: "react", range: new Range("~17.0") },
]));
const mismatched = mismatches(types_matching_dependencies({
devDependencies: {
"@types/react": "~17.1",
},
dependencies: {
"react": "~17.0",
},
}));

assertEquals(mismatched, [
["react", "Mismatching minor versions"],
Expand All @@ -81,10 +108,16 @@ Deno.test("will error on invalid minor ranges", () => {

Deno.test("will allow known errors ", () => {
const mismatched = mismatches(
matched_types([
{ name: "@types/scheduler", range: new Range("~0.16.2") },
{ name: "scheduler", range: new Range("~0.23.0") },
]),
types_matching_dependencies(
{
devDependencies: {
"@types/scheduler": "~0.16.2",
},
dependencies: {
"scheduler": "~0.23.0",
},
},
),
{
known_issues: {
"scheduler@~0.23.0": {
Expand Down
Loading

0 comments on commit f1070a3

Please sign in to comment.