Skip to content

Commit

Permalink
refactor: extract parameter
Browse files Browse the repository at this point in the history
Make `fetchPackageDependencies` function take the npm-client as a parameter. That way it will not be recreated for each call.
  • Loading branch information
ComradeVanti committed Jan 13, 2024
1 parent e1e857c commit 2b8c1d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/cmd-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ export const add = async function (
env.upstreamRegistry,
name,
version,
true
true,
client
);
// add depsValid to pkgsInScope.
depsValid
Expand Down
7 changes: 5 additions & 2 deletions src/cmd-deps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import log from "./logger";
import { parseEnv } from "./utils/env";
import { fetchPackageDependencies } from "./registry-client";
import { fetchPackageDependencies, getNpmClient } from "./registry-client";
import { isPackageUrl } from "./types/package-url";
import {
packageReference,
Expand All @@ -26,6 +26,8 @@ export const deps = async function (
const env = await parseEnv(options, false);
if (env === null) return 1;

const client = getNpmClient();

const [name, version] = splitPackageReference(pkg);

if (version !== undefined && isPackageUrl(version))
Expand All @@ -36,7 +38,8 @@ export const deps = async function (
env.upstreamRegistry,
name,
version,
options.deep || false
options.deep || false,
client
);
depsValid
.filter((x) => !x.self)
Expand Down
5 changes: 3 additions & 2 deletions src/registry-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,20 @@ export const fetchPackument = async function (
* @param name The name of the package
* @param version The version for which to search dependencies
* @param deep Whether to search for all dependencies
* @param client The client to use for communicating with the registries
*/
export const fetchPackageDependencies = async function (
registry: Registry,
upstreamRegistry: Registry,
name: DomainName,
version: SemanticVersion | "latest" | undefined,
deep: boolean
deep: boolean,
client: NpmClient
): Promise<[Dependency[], Dependency[]]> {
log.verbose(
"dependency",
`fetch: ${packageReference(name, version)} deep=${deep}`
);
const client = getNpmClient();
// a list of pending dependency {name, version}
const pendingList: NameVersionPair[] = [{ name, version }];
// a list of processed dependency {name, version}
Expand Down

0 comments on commit 2b8c1d2

Please sign in to comment.