Skip to content

Commit

Permalink
refactor: no lodash (#115)
Browse files Browse the repository at this point in the history
* refactor: remove lodash usages

* refactor: remove lodash usages

* deps: remove lodash
  • Loading branch information
ComradeVanti authored Jan 15, 2024
1 parent fe2b994 commit be0361d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 27 deletions.
15 changes: 3 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"@types/cli-table": "^0.3.2",
"@types/fs-extra": "^11.0.3",
"@types/libnpmsearch": "^2.0.4",
"@types/lodash": "^4.14.199",
"@types/mocha": "^10.0.3",
"@types/node": "^16.18.68",
"@types/node-fetch": "^2.6.9",
Expand Down Expand Up @@ -78,7 +77,6 @@
"fs-extra": "^10.1.0",
"is-wsl": "^2.2.0",
"libnpmsearch": "^5.0.3",
"lodash": "^4.17.21",
"mkdirp": "^3.0.1",
"npm-registry-fetch": "^13.1.1",
"npmlog": "^6.0.2",
Expand Down
6 changes: 2 additions & 4 deletions src/cmd-login.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from "fs";
import path from "path";
import _ from "lodash";
import { assertIsNpmClientError, getNpmClient } from "./registry-client";
import log from "./logger";
import {
Expand Down Expand Up @@ -106,8 +105,7 @@ const npmLogin = async function (
email,
},
});
if (_.isString(data.ok)) log.notice("auth", data.ok);
else if (data.ok) {
if (data.ok) {
log.notice("auth", `you are authenticated as '${username}'`);
const token = data.token;
return { code: 0, token };
Expand Down Expand Up @@ -170,7 +168,7 @@ export const generateNpmrcLines = function (
let registryUrl = registry.slice(registry.search(/:\/\//) + 1);
// add trailing slash
if (!registryUrl.endsWith("/")) registryUrl = registryUrl + "/";
const index = _.findIndex(lines, function (element, index) {
const index = lines.findIndex(function (element, index) {
if (element.indexOf(registryUrl + ":_authToken=") !== -1) {
// If an entry for the auth token is found, replace it
lines[index] = element.replace(
Expand Down
19 changes: 10 additions & 9 deletions src/registry-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import RegClient, {
import log from "./logger";
import request from "request";
import assert, { AssertionError } from "assert";
import _ from "lodash";
import { tryGetLatestVersion, UnityPackument } from "./types/packument";
import { DomainName, isInternalPackage } from "./types/domain-name";
import { SemanticVersion } from "./types/semantic-version";
Expand Down Expand Up @@ -156,7 +155,7 @@ export const fetchPackageDependencies = async function (
// a list of pending dependency {name, version}
const pendingList: NameVersionPair[] = [{ name, version }];
// a list of processed dependency {name, version}
const processedList = [];
const processedList = Array.of<NameVersionPair>();
// a list of dependency entry exists on the registry
const depsValid = [];
// a list of dependency entry doesn't exist on the registry
Expand All @@ -169,7 +168,10 @@ export const fetchPackageDependencies = async function (
while (pendingList.length > 0) {
// NOTE: Guaranteed defined because of while loop logic
const entry = pendingList.shift() as NameVersionPair;
if (processedList.find((x) => _.isEqual(x, entry)) === undefined) {
const isProcessed = processedList.some(
(x) => x.name === entry.name && x.version === entry.version
);
if (!isProcessed) {
// add entry to processed list
processedList.push(entry);
// create valid dependency structure
Expand All @@ -188,10 +190,10 @@ export const fetchPackageDependencies = async function (
};
if (!depObj.internal) {
// try fetching package info from cache
const getResult = _.get(cachedPackageInfoDict, entry.name, {
const getResult = cachedPackageInfoDict[entry.name] ?? {
packument: null,
upstream: false,
});
};
let packument = getResult.packument;
const upstream = getResult.upstream;
if (packument !== null) {
Expand Down Expand Up @@ -252,10 +254,9 @@ export const fetchPackageDependencies = async function (
// add dependencies to pending list
if (depObj.self || deep) {
const deps: NameVersionPair[] = (
_.toPairs(packument.versions[entry.version]!["dependencies"]) as [
DomainName,
SemanticVersion
][]
Object.entries(
packument.versions[entry.version]!["dependencies"] || {}
) as [DomainName, SemanticVersion][]
).map((x): NameVersionPair => {
return {
name: x[0],
Expand Down

0 comments on commit be0361d

Please sign in to comment.