Skip to content

Commit

Permalink
Merge pull request #80 from alfonsogarciacaro/patch-3
Browse files Browse the repository at this point in the history
Fix #77 (again)
  • Loading branch information
Zaid-Ajaj authored Sep 30, 2021
2 parents 624911d + 4b15476 commit cc2725c
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions src/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -122,34 +122,31 @@ let findInstalledPackages (packageJson: string) : ResizeArray<InstalledNpmPackag
let rec checkPackageJsons nodeModulePath =
for dir in IO.Directory.GetDirectories nodeModulePath do
let dirname = IO.Path.GetFileName(dir)
let pkgJson = IO.Path.Combine(dir, "package.json")
// Some packages create a cache dir in node_modules starting with . like .vite
if dirname.StartsWith(".")
then ()
// Scoped packages
elif dirname.StartsWith("@")
then checkPackageJsons dir
if not (IO.File.Exists pkgJson)
then ()
if dirname.StartsWith("@") then
checkPackageJsons dir
else
let nameAndVersionDecoder = Decode.object (fun get ->
(get.Required.Field "name" Decode.string,
get.Required.Field "version" Decode.string)
)

let decoded =
File.readAllTextNonBlocking pkgJson
|> Decode.fromString nameAndVersionDecoder

match decoded with
| Ok (name, version) ->
for package in topLevelPackages do
if package.Name = name
then package.Installed <- Some (SemVer.Version version)
else ()
| Error errorMessage ->
logger.Error("Couldn't decode 'package.json' from {PackageJson}. Reason: {Message}", pkgJson, errorMessage)
()
let pkgJson = IO.Path.Combine(dir, "package.json")
// Some packages create a cache dir in node_modules starting with . like .vite
if not(dirname.StartsWith(".")) && IO.File.Exists pkgJson then
let nameAndVersionDecoder = Decode.object (fun get ->
(get.Required.Field "name" Decode.string,
get.Required.Field "version" Decode.string)
)

let decoded =
File.readAllTextNonBlocking pkgJson
|> Decode.fromString nameAndVersionDecoder

match decoded with
| Ok (name, version) ->
for package in topLevelPackages do
if package.Name = name
then package.Installed <- Some (SemVer.Version version)
else ()
| Error errorMessage ->
logger.Error("Couldn't decode 'package.json' from {PackageJson}. Reason: {Message}", pkgJson, errorMessage)
()

checkPackageJsons nodeModulePath
topLevelPackages
Expand Down

0 comments on commit cc2725c

Please sign in to comment.