-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
117 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ import { | |
blue, | ||
cyan, | ||
gray, | ||
green, | ||
red, | ||
yellow, | ||
} from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
|
||
|
@@ -12,6 +14,8 @@ export const colour = { | |
file: cyan, | ||
subdued: gray, | ||
version: yellow, | ||
valid: green, | ||
invalid: red, | ||
}; | ||
|
||
export const format = (name: string, range: Range) => | ||
|
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
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,7 +1,13 @@ | ||
import { parse_declared_dependencies } from "./parse_dependencies.ts"; | ||
import { | ||
parse_declared_dependencies, | ||
parse_package_info, | ||
} from "./parse_dependencies.ts"; | ||
import { fetch_peer_dependencies } from "./fetch_peer_dependencies.ts"; | ||
import { colour } from "./colours.ts"; | ||
import { count_unsatisfied_peer_dependencies } from "./find_mismatches.ts"; | ||
import { colour, format } from "./colours.ts"; | ||
import { | ||
count_unsatisfied_peer_dependencies, | ||
format_dependencies, | ||
} from "./find_mismatches.ts"; | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
|
||
const { _: [package_file], verbose, cache } = parse(Deno.args, { | ||
|
@@ -15,41 +21,55 @@ if (typeof package_file !== "string") { | |
|
||
const filename = Deno.cwd() + "/" + package_file; | ||
|
||
const package_content = await Deno.readTextFile(filename).catch(() => ""); | ||
const package_content: unknown = await Deno.readTextFile(filename).catch(() => | ||
"" | ||
).then( | ||
(contents) => JSON.parse(contents), | ||
); | ||
|
||
if (package_content) { | ||
if (verbose) console.info(`✅ Found package.json file`); | ||
} else { | ||
if (!package_content) { | ||
console.error("🚨 No package.json found at", colour.file(filename)); | ||
Deno.exit(1); | ||
} | ||
|
||
const dependencies = parse_declared_dependencies(package_content); | ||
const { name, range } = parse_package_info(package_content); | ||
|
||
console.info(`${format(name, range)}`); | ||
|
||
if (dependencies.length === 0) { | ||
const dependencies_from_package = parse_declared_dependencies(package_content); | ||
|
||
if (dependencies_from_package.length === 0) { | ||
if (verbose) { | ||
console.info("✅ You have no dependencies and therefore no issues!"); | ||
} | ||
Deno.exit(); | ||
} | ||
|
||
const dependencies_with_peers = await fetch_peer_dependencies( | ||
dependencies, | ||
{ verbose, cache }, | ||
const dependencies_from_registry = await fetch_peer_dependencies( | ||
dependencies_from_package, | ||
{ cache }, | ||
); | ||
|
||
const number_of_mismatched_deps = count_unsatisfied_peer_dependencies( | ||
dependencies_with_peers, | ||
format_dependencies( | ||
dependencies_from_registry, | ||
verbose, | ||
); | ||
|
||
const number_of_mismatched_deps = count_unsatisfied_peer_dependencies( | ||
dependencies_from_registry, | ||
); | ||
|
||
if (number_of_mismatched_deps === 0) { | ||
if (verbose) console.info("✅ Everything is fine with your dependencies"); | ||
if (verbose) console.info("✅ Dependencies are in good shape"); | ||
} else if (number_of_mismatched_deps === 1) { | ||
console.error( | ||
`🚨 There is ${colour.file("1")} dependencies problem`, | ||
); | ||
} else { | ||
console.info( | ||
console.error( | ||
`🚨 There are ${ | ||
colour.file(String(number_of_mismatched_deps)) | ||
} unsatisfied peer dependencies`, | ||
} dependencies problems`, | ||
); | ||
} | ||
|
||
|
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