Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/validate transitives #39

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,25 @@ let executeResolutionActions (cwd: string) (manager: NodeManager) (actions: Reso
| otherwise ->
ignore()

let private validateProject (library : LibraryWithNpmDeps) =
(true, library.NpmDependencies)
||> List.fold (fun (state : bool) (pkg : NpmDependency) ->
logger.Information("{Library} requires npm package {Package}", library.Name, pkg.Name)
logger.Information(" | -- Required range {Range}", pkg.RawVersion)
logger.Information(" | -- Resolution strategy '{Strategy}'", if pkg.LowestMatching then "Min" else "Max")
let isCurrentPkgOk =
match getSatisfyingPackageVersion NodeManager.Npm pkg with
| Some version ->
logger.Information(" | -- √ Found version {Version} that satisfies the required range", version)
true
| None ->
logger.Error(" | -- Could not find a version that satisfies the required range {Range}", pkg.RawVersion)
false

state && isCurrentPkgOk
)


let rec private runner (args : FemtoArgs) =

match args.Project, args.PreviewMetadata with
Expand Down Expand Up @@ -689,24 +708,21 @@ let rec private runner (args : FemtoArgs) =
| Error er ->
logger.Error("Error while analyzing the project's structure and dependencies")
FemtoResult.ValidationFailed
| Ok _ ->
let libraryName = Path.GetFileNameWithoutExtension project
let npmDependencies = Npm.parseDependencies project
if List.isEmpty npmDependencies then
logger.Warning("Project {Project} does not contain npm dependency metadata", libraryName)
FemtoResult.ProjectCrackerFailed
else
for pkg in npmDependencies do
logger.Information("{Library} requires npm package {Package}", libraryName, pkg.Name)
logger.Information(" | -- Required range {Range}", pkg.RawVersion)
logger.Information(" | -- Resolution strategy '{Strategy}'", if pkg.LowestMatching then "Min" else "Max")
match getSatisfyingPackageVersion NodeManager.Npm pkg with
| Some version ->
logger.Information(" | -- √ Found version {Version} that satisfies the required range", version)
| None ->
logger.Error(" | -- Could not find a version that satisfies the required range {Range}", pkg.RawVersion)
| Ok crackedProject ->
let libraries = findLibraryWithNpmDeps crackedProject

let isValid =
Zaid-Ajaj marked this conversation as resolved.
Show resolved Hide resolved
(true, libraries)
||> List.fold (fun (state : bool) (library : LibraryWithNpmDeps) ->
validateProject library && state
)

if isValid then
logger.Information("Validation result: Success")
FemtoResult.ValidationSucceeded
else
logger.Error("Validation result: Failed")
FemtoResult.ValidationFailed

| Some project, false ->
logger.Information("Analyzing project {Project}", project)
Expand Down Expand Up @@ -875,4 +891,4 @@ let main argv =
printUsage()
FemtoResult.InvalidArguments

int result
int result