-
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.
feat: support using custom registry #70
- Loading branch information
Showing
16 changed files
with
356 additions
and
103 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 |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
"lcov", | ||
"toolbelt", | ||
"Conosla", | ||
"libnpmconfig", | ||
"packument" | ||
], | ||
"ignorePaths": [ | ||
|
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 |
---|---|---|
|
@@ -71,5 +71,6 @@ typings/ | |
# stryker temp files | ||
.stryker-tmp | ||
/reports | ||
!@types/** | ||
!/tools | ||
|
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,3 @@ | ||
declare module 'libnpmconfig' { | ||
export function read(): Record<string, any>; | ||
} |
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,50 @@ | ||
import { inject, injectable } from 'inversify'; | ||
import { ILogger } from '../../logger/interfaces/ILogger'; | ||
import { LibNpmConfig, TYPES } from '../../../container/nodeModulesContainer'; | ||
import { ILoggerFactory } from '../../logger'; | ||
import { INpmConfig, INpmConfigRetriever } from '../interfaces/INpmConfigRetriever'; | ||
import { isBoolean, isString } from 'ts-type-guards'; | ||
|
||
const coerceBoolean = (value: undefined | string | boolean): boolean => { | ||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
if (isBoolean(value)) { | ||
return value; | ||
} | ||
return value.toLowerCase() === `true`; | ||
}; | ||
|
||
@injectable() | ||
export class NpmConfigRetriever extends INpmConfigRetriever { | ||
private readonly logger: ILogger; | ||
|
||
constructor(@inject(TYPES.LibNpmConfig) private readonly libnpmconfig: LibNpmConfig, loggerFactory: ILoggerFactory) { | ||
super(); | ||
this.logger = loggerFactory.getLogger(`Npm Config Retriever`); | ||
} | ||
|
||
async retrieve(): Promise<INpmConfig> { | ||
this.logger.info(`Reading npm config`); | ||
const result = this.libnpmconfig.read(); | ||
const npmConfig: INpmConfig = {}; | ||
result.forEach((value: any, key: string) => { | ||
if (isString(value) && key.indexOf(`:`) > 0) { | ||
npmConfig[key] = value; | ||
} | ||
}); | ||
npmConfig[`always-auth`] = coerceBoolean(result[`always-auth`]); | ||
npmConfig.strictSSL = coerceBoolean(result[`strict-ssl`]); | ||
npmConfig.alwaysAuth = coerceBoolean(result.alwaysAuth); | ||
npmConfig.registry = result.registry; | ||
npmConfig.username = result.username; | ||
npmConfig.password = result.password; | ||
npmConfig.token = result.token; | ||
// eslint-disable-next-line no-underscore-dangle | ||
npmConfig._authToken = result._authToken; | ||
// eslint-disable-next-line no-underscore-dangle | ||
npmConfig._auth = result._auth; | ||
npmConfig.email = result.email; | ||
return npmConfig; | ||
} | ||
} |
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,50 @@ | ||
import { inject, injectable } from 'inversify'; | ||
import { ILogger } from '../../logger/interfaces/ILogger'; | ||
import { LibNpmConfig, TYPES } from '../../../container/nodeModulesContainer'; | ||
import { ILoggerFactory } from '../../logger'; | ||
import { INpmConfig, INpmConfigRetriever } from '../interfaces/INpmConfigRetriever'; | ||
import { isBoolean, isString } from 'ts-type-guards'; | ||
|
||
const coerceBoolean = (value: undefined | string | boolean): boolean => { | ||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
if (isBoolean(value)) { | ||
return value; | ||
} | ||
return value.toLowerCase() === `true`; | ||
}; | ||
|
||
@injectable() | ||
export class NpmConfigRetriever extends INpmConfigRetriever { | ||
private readonly logger: ILogger; | ||
|
||
constructor(@inject(TYPES.LibNpmConfig) private readonly libnpmconfig: LibNpmConfig, loggerFactory: ILoggerFactory) { | ||
super(); | ||
this.logger = loggerFactory.getLogger(`Npm Config Retriever`); | ||
} | ||
|
||
async retrieve(): Promise<INpmConfig> { | ||
this.logger.info(`Reading npm config`); | ||
const result = this.libnpmconfig.read(); | ||
const npmConfig: INpmConfig = {}; | ||
result.forEach((value: any, key: string) => { | ||
if (isString(value) && key.indexOf(`:`) > 0) { | ||
npmConfig[key] = value; | ||
} | ||
}); | ||
npmConfig[`always-auth`] = coerceBoolean(result[`always-auth`]); | ||
npmConfig.strictSSL = coerceBoolean(result[`strict-ssl`]); | ||
npmConfig.alwaysAuth = coerceBoolean(result.alwaysAuth); | ||
npmConfig.registry = result.registry; | ||
npmConfig.username = result.username; | ||
npmConfig.password = result.password; | ||
npmConfig.token = result.token; | ||
// eslint-disable-next-line no-underscore-dangle | ||
npmConfig._authToken = result._authToken; | ||
// eslint-disable-next-line no-underscore-dangle | ||
npmConfig._auth = result._auth; | ||
npmConfig.email = result.email; | ||
return npmConfig; | ||
} | ||
} |
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,7 @@ | ||
import { Options } from 'npm-registry-fetch'; | ||
|
||
export type INpmConfig = Options; | ||
|
||
export abstract class INpmConfigRetriever { | ||
public abstract async retrieve(): Promise<INpmConfig>; | ||
} |
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
12 changes: 12 additions & 0 deletions
12
test/src/utils/packageInfo/impl/npmConfigRetriever.spec.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,12 @@ | ||
import * as libnpmconfig from 'libnpmconfig'; | ||
import { loggerFactory } from '../../../../common/logger'; | ||
import { NpmConfigRetriever } from '../../../../../src/utils/packageInfo/impl/npmConfigRetriever'; | ||
|
||
describe(`npm config retriever`, () => { | ||
const npmConfigRetriever = new NpmConfigRetriever(libnpmconfig, loggerFactory); | ||
|
||
it(`should return npm config`, async () => { | ||
const result = await npmConfigRetriever.retrieve(); | ||
expect(result).toEqual({}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
"declaration": true, | ||
"outDir": "dist" | ||
}, | ||
"include": ["src"] | ||
"include": ["src", "@types/**/*.d.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
Oops, something went wrong.