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

feat(@schematics/update): add initial verbose option #12995

Merged
merged 1 commit into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/schematics/update/update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,11 @@ export default function(options: UpdateSchema): Rule {
return observableFrom([...allDependencies.keys()]).pipe(
// Grab all package.json from the npm repository. This requires a lot of HTTP calls so we
// try to parallelize as many as possible.
mergeMap(depName => getNpmPackageJson(depName, options.registry, logger, usingYarn)),
mergeMap(depName => getNpmPackageJson(
depName,
logger,
{ registryUrl: options.registry, usingYarn, verbose: options.verbose },
)),

// Build a map of all dependencies and their packageJson.
reduce<NpmRepositoryPackageJson, Map<string, NpmRepositoryPackageJson>>(
Expand Down
39 changes: 28 additions & 11 deletions packages/schematics/update/update/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ const npmPackageJsonCache = new Map<string, Observable<NpmRepositoryPackageJson>
let npmrc: { [key: string]: string };


function readOptions(yarn = false): { [key: string]: string } {
// TODO: have a way to read options without using fs directly.
function readOptions(
logger: logging.LoggerApi,
yarn = false,
showPotentials = false,
): Record<string, string> {
const cwd = process.cwd();
const baseFilename = yarn ? 'yarnrc' : 'npmrc';
const dotFilename = '.' + baseFilename;
Expand All @@ -42,16 +45,25 @@ function readOptions(yarn = false): { [key: string]: string } {
path.join(homedir(), dotFilename),
];

const projectConfigLocations: string[] = [];
const projectConfigLocations: string[] = [
path.join(cwd, dotFilename),
];
const root = path.parse(cwd).root;
for (let curDir = path.dirname(cwd); curDir && curDir !== root; curDir = path.dirname(curDir)) {
projectConfigLocations.unshift(path.join(curDir, dotFilename));
}
projectConfigLocations.push(path.join(cwd, dotFilename));

if (showPotentials) {
logger.info(`Locating potential ${baseFilename} files:`);
}

let options: { [key: string]: string } = {};
for (const location of [...defaultConfigLocations, ...projectConfigLocations]) {
if (existsSync(location)) {
if (showPotentials) {
logger.info(`Trying '${location}'...found.`);
}

const data = readFileSync(location, 'utf8');
options = {
...options,
Expand All @@ -65,6 +77,8 @@ function readOptions(yarn = false): { [key: string]: string } {
options.ca = readFileSync(cafile, 'utf8').replace(/\r?\n/, '\\n');
} catch { }
}
} else if (showPotentials) {
logger.info(`Trying '${location}'...not found.`);
}
}

Expand All @@ -81,9 +95,12 @@ function readOptions(yarn = false): { [key: string]: string } {
*/
export function getNpmPackageJson(
packageName: string,
registryUrl: string | undefined,
_logger: logging.LoggerApi,
usingYarn = false,
logger: logging.LoggerApi,
options?: {
registryUrl?: string;
usingYarn?: boolean;
verbose?: boolean;
},
): Observable<Partial<NpmRepositoryPackageJson>> {
const cachedResponse = npmPackageJsonCache.get(packageName);
if (cachedResponse) {
Expand All @@ -92,12 +109,12 @@ export function getNpmPackageJson(

if (!npmrc) {
try {
npmrc = readOptions();
npmrc = readOptions(logger, false, options && options.verbose);
} catch { }

if (usingYarn) {
if (options && options.usingYarn) {
try {
npmrc = { ...npmrc, ...readOptions(true) };
npmrc = { ...npmrc, ...readOptions(logger, true, options && options.verbose) };
} catch { }
}
}
Expand All @@ -107,7 +124,7 @@ export function getNpmPackageJson(
{
'full-metadata': true,
...npmrc,
registry: registryUrl,
registry: options && options.registryUrl,
},
);

Expand Down
4 changes: 4 additions & 0 deletions packages/schematics/update/update/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
}
]
},
"verbose": {
"description": "Display additional details during the update process.",
"type": "boolean"
},
"packageManager": {
"description": "The preferred package manager configuration files to use for registry settings.",
"type": "string",
Expand Down