Skip to content

Commit 6b41793

Browse files
clydinvikerman
authored andcommitted
feat(@schematics/update): add initial verbose option (#12995)
Currently displays the list of potential npm/yarn rc files and which of these were found.
1 parent 69078b5 commit 6b41793

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

packages/schematics/update/update/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,11 @@ export default function(options: UpdateSchema): Rule {
783783
return observableFrom([...allDependencies.keys()]).pipe(
784784
// Grab all package.json from the npm repository. This requires a lot of HTTP calls so we
785785
// try to parallelize as many as possible.
786-
mergeMap(depName => getNpmPackageJson(depName, options.registry, logger, usingYarn)),
786+
mergeMap(depName => getNpmPackageJson(
787+
depName,
788+
logger,
789+
{ registryUrl: options.registry, usingYarn, verbose: options.verbose },
790+
)),
787791

788792
// Build a map of all dependencies and their packageJson.
789793
reduce<NpmRepositoryPackageJson, Map<string, NpmRepositoryPackageJson>>(

packages/schematics/update/update/npm.ts

+28-11
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ const npmPackageJsonCache = new Map<string, Observable<NpmRepositoryPackageJson>
2121
let npmrc: { [key: string]: string };
2222

2323

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

45-
const projectConfigLocations: string[] = [];
48+
const projectConfigLocations: string[] = [
49+
path.join(cwd, dotFilename),
50+
];
4651
const root = path.parse(cwd).root;
4752
for (let curDir = path.dirname(cwd); curDir && curDir !== root; curDir = path.dirname(curDir)) {
4853
projectConfigLocations.unshift(path.join(curDir, dotFilename));
4954
}
50-
projectConfigLocations.push(path.join(cwd, dotFilename));
55+
56+
if (showPotentials) {
57+
logger.info(`Locating potential ${baseFilename} files:`);
58+
}
5159

5260
let options: { [key: string]: string } = {};
5361
for (const location of [...defaultConfigLocations, ...projectConfigLocations]) {
5462
if (existsSync(location)) {
63+
if (showPotentials) {
64+
logger.info(`Trying '${location}'...found.`);
65+
}
66+
5567
const data = readFileSync(location, 'utf8');
5668
options = {
5769
...options,
@@ -65,6 +77,8 @@ function readOptions(yarn = false): { [key: string]: string } {
6577
options.ca = readFileSync(cafile, 'utf8').replace(/\r?\n/, '\\n');
6678
} catch { }
6779
}
80+
} else if (showPotentials) {
81+
logger.info(`Trying '${location}'...not found.`);
6882
}
6983
}
7084

@@ -86,9 +100,12 @@ function readOptions(yarn = false): { [key: string]: string } {
86100
*/
87101
export function getNpmPackageJson(
88102
packageName: string,
89-
registryUrl: string | undefined,
90-
_logger: logging.LoggerApi,
91-
usingYarn = false,
103+
logger: logging.LoggerApi,
104+
options?: {
105+
registryUrl?: string;
106+
usingYarn?: boolean;
107+
verbose?: boolean;
108+
},
92109
): Observable<Partial<NpmRepositoryPackageJson>> {
93110
const cachedResponse = npmPackageJsonCache.get(packageName);
94111
if (cachedResponse) {
@@ -97,12 +114,12 @@ export function getNpmPackageJson(
97114

98115
if (!npmrc) {
99116
try {
100-
npmrc = readOptions();
117+
npmrc = readOptions(logger, false, options && options.verbose);
101118
} catch { }
102119

103-
if (usingYarn) {
120+
if (options && options.usingYarn) {
104121
try {
105-
npmrc = { ...npmrc, ...readOptions(true) };
122+
npmrc = { ...npmrc, ...readOptions(logger, true, options && options.verbose) };
106123
} catch { }
107124
}
108125
}
@@ -112,7 +129,7 @@ export function getNpmPackageJson(
112129
{
113130
'full-metadata': true,
114131
...npmrc,
115-
registry: registryUrl,
132+
registry: options && options.registryUrl,
116133
},
117134
);
118135

packages/schematics/update/update/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
}
5555
]
5656
},
57+
"verbose": {
58+
"description": "Display additional details during the update process.",
59+
"type": "boolean"
60+
},
5761
"packageManager": {
5862
"description": "The preferred package manager configuration files to use for registry settings.",
5963
"type": "string",

0 commit comments

Comments
 (0)