Skip to content

Commit 7cf2cf0

Browse files
committed
feat(cli): remove the '--clean-cache' parameter from the search command
1 parent c51dfb5 commit 7cf2cf0

File tree

7 files changed

+579
-846
lines changed

7 files changed

+579
-846
lines changed

lib/cli.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ program
5757
program
5858
.command("search <keyword>")
5959
.aliases(["s", "se", "find"])
60-
.option("--clean-cache", "clean local cache before search")
6160
.description("Search package by keyword")
6261
.action(async function(keyword, options) {
6362
const retCode = await search(keyword, options);

lib/cmd-search.js

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const Table = require("cli-table");
55
const { log } = require("./logger");
66
const {
77
env,
8-
cleanCache,
9-
getCache,
108
getLatestVersion,
119
getNpmFetchOptions,
1210
parseEnv
@@ -32,26 +30,10 @@ const searchEndpoint = async function(keyword, registry) {
3230
}
3331
};
3432

35-
const searchOld = async function(keyword, shouldCleanCache) {
36-
// clean cache if needed
37-
if (shouldCleanCache) cleanCache();
38-
// load cache
39-
let cache = getCache();
40-
let cacheKey = env.namespace + ".all";
41-
if (process.env.NODE_ENV == "test") cacheKey = "test." + cacheKey;
42-
cacheKey = cacheKey + ".json";
43-
let cached = cache[cacheKey] || {};
44-
let cachedLen = (cached.objects || []).length;
45-
log.verbose(
46-
"cache",
47-
`has ${cachedLen} package(s), updated at ${cached._updated}`
48-
);
33+
const searchOld = async function(keyword) {
4934
// all endpoint
50-
let serverUrl = cached._updated
51-
? `/-/all/since?stale=update_after&startkey=${cached._updated}`
52-
: `/-/all`;
5335
try {
54-
const results = await npmFetch.json(serverUrl, getNpmFetchOptions());
36+
const results = await npmFetch.json("/-/all", getNpmFetchOptions());
5537
log.verbose("endpoint.all", results);
5638
let objects = [];
5739
if (results) {
@@ -64,14 +46,8 @@ const searchOld = async function(keyword, shouldCleanCache) {
6446
objects = Object.values(results);
6547
}
6648
}
67-
// contact cached objects and remote objects
68-
const allObjects = objects.concat(cached.objects || []);
69-
// save to cache
70-
cached.objects = allObjects;
71-
cached._updated = Math.round(new Date().getTime());
72-
cache[cacheKey] = cached;
7349
// prepare rows
74-
const rows = allObjects.map(pkg => {
50+
const rows = objects.map(pkg => {
7551
let name = pkg.name;
7652
let version = getLatestVersion(pkg);
7753
let date =
@@ -107,7 +83,7 @@ module.exports = async function(keyword, options) {
10783
let results = await searchEndpoint(keyword);
10884
// search old search
10985
if (results === undefined) {
110-
results = (await searchOld(keyword, options.cleanCache)) || [];
86+
results = (await searchOld(keyword)) || [];
11187
}
11288
// search upstream
11389
// if (env.upstream) {

lib/core.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const chalk = require("chalk");
88
const mkdirp = require("mkdirp");
99
const net = require('node:net');
1010
const isWsl = require("is-wsl");
11-
const keyFileStorage = require("key-file-storage").default;
1211
const TOML = require("@iarna/toml");
1312
const yaml = require("yaml");
1413

@@ -336,25 +335,6 @@ const saveManifest = function(data) {
336335
}
337336
};
338337

339-
// Return cache object
340-
const getCache = function() {
341-
const homeDir = os.homedir();
342-
const openupmDir = path.join(homeDir, ".openupm");
343-
try {
344-
fs.mkdirSync(openupmDir);
345-
} catch (err) {
346-
if (err.code != "EEXIST") throw err;
347-
}
348-
const kfs = keyFileStorage(openupmDir);
349-
return kfs;
350-
};
351-
352-
// Clean cache
353-
const cleanCache = function() {
354-
const cache = getCache();
355-
delete cache["*"];
356-
};
357-
358338
// Get .upmconfig.toml directory
359339
const getUpmConfigDir = async function() {
360340
let dirPath = "";
@@ -486,12 +466,10 @@ const isInternalPackage = function(name) {
486466
};
487467

488468
module.exports = {
489-
cleanCache,
490469
compareEditorVersion,
491470
env,
492471
fetchPackageDependencies,
493472
fetchPackageInfo,
494-
getCache,
495473
getLatestVersion,
496474
getNpmFetchOptions,
497475
getUpmConfigDir,

0 commit comments

Comments
 (0)