-
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
17 changed files
with
211 additions
and
157 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
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,62 @@ | ||
import { injectable } from 'inversify'; | ||
import { ILoggerFactory } from '../../logger'; | ||
import { ILogger } from '../../logger/interfaces/ILogger'; | ||
import { IManifestParser, IManifestParserOptions } from '../interfaces/IManifestParser'; | ||
import { IPredicate } from '../../predicateBuilder/predicateBuilder'; | ||
import { DependencyType, IDependency, IPackageData } from '../types'; | ||
|
||
@injectable() | ||
export class ManifestParser extends IManifestParser { | ||
private readonly logger: ILogger; | ||
|
||
constructor(loggerFactory: ILoggerFactory) { | ||
super(); | ||
this.logger = loggerFactory.getLogger(`Manifest Parser`); | ||
} | ||
|
||
public async parse({ manifest, include, predicate }: IManifestParserOptions): Promise<IPackageData> { | ||
this.logger.info(`Reading manifest information`); | ||
const dependencies = new Set<IDependency>(); | ||
const depTypeHandler = this.getDepTypeHandler(dependencies, predicate); | ||
depTypeHandler(include.dev, manifest.devDependencies, DependencyType.DEV, `dev`); | ||
depTypeHandler(include.prod, manifest.dependencies, DependencyType.PROD, `production`); | ||
depTypeHandler(include.peer, manifest.peerDependencies, DependencyType.PEER, `peer`); | ||
depTypeHandler(include.optional, manifest.optionalDependencies, DependencyType.OPTIONAL, `optional`); | ||
this.logger.info(`Going to check ${dependencies.size} dependencies`); | ||
return { | ||
dependencies, | ||
}; | ||
} | ||
|
||
private getDepTypeHandler(deps: Set<IDependency>, predicate: IPredicate) { | ||
return ( | ||
included: boolean, | ||
currentDeps: undefined | Record<string, string>, | ||
type: DependencyType, | ||
typeStr: string | ||
): void => { | ||
if (included) { | ||
if (currentDeps) { | ||
let count = 0; | ||
for (const [name, semver] of Object.entries(currentDeps)) { | ||
if (predicate(name)) { | ||
count++; | ||
deps.add({ | ||
name, | ||
semver, | ||
dependencyType: type, | ||
}); | ||
} else { | ||
this.logger.info(`Skipping ${name}`); | ||
} | ||
} | ||
this.logger.info(`Found ${count} ${typeStr} dependencies`); | ||
} else { | ||
this.logger.info(`No ${typeStr} dependencies defined`); | ||
} | ||
} else { | ||
this.logger.info(`Skipping ${typeStr} dependencies`); | ||
} | ||
}; | ||
} | ||
} |
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,43 @@ | ||
import { injectable } from 'inversify'; | ||
import { ILoggerFactory } from '../../logger'; | ||
import { ILogger } from '../../logger/interfaces/ILogger'; | ||
import { INpmGlobalManifestParser, INpmGlobalManifestParserOptions } from '../interfaces/INpmGlobalManifestParser'; | ||
import { DependencyType, IDependency, IPackageData } from '../types'; | ||
|
||
@injectable() | ||
export class NpmGlobalManifestParser extends INpmGlobalManifestParser { | ||
private readonly logger: ILogger; | ||
|
||
constructor(loggerFactory: ILoggerFactory) { | ||
super(); | ||
this.logger = loggerFactory.getLogger(`Npm Global Manifest Parser`); | ||
} | ||
|
||
public async parse({ manifest, predicate }: INpmGlobalManifestParserOptions): Promise<IPackageData> { | ||
this.logger.info(`Reading npm global manifest information`); | ||
const dependencies = new Set<IDependency>(); | ||
const currentDeps = manifest.dependencies; | ||
if (currentDeps) { | ||
let count = 0; | ||
for (const [name, info] of Object.entries(currentDeps)) { | ||
if (predicate(name)) { | ||
count++; | ||
dependencies.add({ | ||
name, | ||
semver: info.version, | ||
dependencyType: DependencyType.GLOBAL, | ||
}); | ||
} else { | ||
this.logger.info(`Skipping ${name}`); | ||
} | ||
} | ||
this.logger.info(`Found ${count} global dependencies`); | ||
} else { | ||
this.logger.info(`No global dependencies found`); | ||
} | ||
this.logger.info(`Going to check ${dependencies.size} dependencies`); | ||
return { | ||
dependencies, | ||
}; | ||
} | ||
} |
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,15 @@ | ||
import { interfaces } from 'inversify'; | ||
import Bind = interfaces.Bind; | ||
import { IManifestParser } from './interfaces/IManifestParser'; | ||
import { ManifestParser } from './impl/manifestParser'; | ||
import { INpmGlobalManifestParser } from './interfaces/INpmGlobalManifestParser'; | ||
import { NpmGlobalManifestParser } from './impl/npmGlobalManifestParser'; | ||
|
||
export const manifestParserModulesBinder = (bind: Bind): void => { | ||
bind<IManifestParser>(IManifestParser).to(ManifestParser).inSingletonScope(); | ||
bind<INpmGlobalManifestParser>(INpmGlobalManifestParser).to(NpmGlobalManifestParser).inSingletonScope(); | ||
}; | ||
|
||
export * from './interfaces/IManifestParser'; | ||
export * from './interfaces/INpmGlobalManifestParser'; | ||
export * from './types'; |
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,18 @@ | ||
import { IPredicate } from '../../predicateBuilder/predicateBuilder'; | ||
import { Manifest } from 'pacote'; | ||
import { IPackageData } from '../types'; | ||
|
||
export interface IManifestParserOptions { | ||
manifest: Manifest; | ||
include: { | ||
prod: boolean; | ||
dev: boolean; | ||
optional: boolean; | ||
peer: boolean; | ||
}; | ||
predicate: IPredicate; | ||
} | ||
|
||
export abstract class IManifestParser { | ||
public abstract async parse(options: IManifestParserOptions): Promise<IPackageData>; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/utils/manifestParser/interfaces/INpmGlobalManifestParser.ts
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,15 @@ | ||
import { IPackageData } from '../types'; | ||
import { IPredicate } from '../../predicateBuilder/predicateBuilder'; | ||
|
||
export interface INpmGlobalManifest { | ||
dependencies?: Record<string, { version: string }>; | ||
} | ||
|
||
export interface INpmGlobalManifestParserOptions { | ||
manifest: INpmGlobalManifest; | ||
predicate: IPredicate; | ||
} | ||
|
||
export abstract class INpmGlobalManifestParser { | ||
public abstract async parse(options: INpmGlobalManifestParserOptions): Promise<IPackageData>; | ||
} |
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,17 @@ | ||
export enum DependencyType { | ||
PROD = `production`, | ||
DEV = `development`, | ||
PEER = `peer`, | ||
OPTIONAL = `optional`, | ||
GLOBAL = `global`, | ||
} | ||
|
||
export interface IDependency { | ||
semver: string; | ||
name: string; | ||
dependencyType: DependencyType; | ||
} | ||
|
||
export interface IPackageData { | ||
dependencies: Set<IDependency>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
src/utils/packageJsonParser/interfaces/IPackageJsonParser.ts
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,25 @@ | ||
import { BindingTypes, testBindings } from '../../../common/testers/bindingTester'; | ||
import { | ||
IManifestParser, | ||
INpmGlobalManifestParser, | ||
manifestParserModulesBinder, | ||
} from '../../../../src/utils/manifestParser'; | ||
import { ManifestParser } from '../../../../src/utils/manifestParser/impl/manifestParser'; | ||
import { NpmGlobalManifestParser } from '../../../../src/utils/manifestParser/impl/npmGlobalManifestParser'; | ||
|
||
testBindings({ | ||
name: `manifest parser module container`, | ||
binderFn: manifestParserModulesBinder, | ||
bindings: [ | ||
{ | ||
binder: IManifestParser, | ||
binded: ManifestParser, | ||
type: BindingTypes.SINGELTON, | ||
}, | ||
{ | ||
binder: INpmGlobalManifestParser, | ||
binded: NpmGlobalManifestParser, | ||
type: BindingTypes.SINGELTON, | ||
}, | ||
], | ||
}); |
This file was deleted.
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
Oops, something went wrong.