feat(registry): modernize npm registry file handling and package extraction APIs
This commit is contained in:
@@ -12,6 +12,7 @@ export interface ICacheDescriptor {
|
||||
export class RegistryCache {
|
||||
npmregistryRef: NpmRegistry;
|
||||
public levelCache: plugins.levelcache.LevelCache;
|
||||
public smartFileFactory = plugins.smartfile.SmartFileFactory.nodeFs();
|
||||
|
||||
constructor(npmRegistryRefArg: NpmRegistry) {
|
||||
this.npmregistryRef = npmRegistryRefArg;
|
||||
@@ -22,12 +23,12 @@ export class RegistryCache {
|
||||
|
||||
public async getCachedFile(
|
||||
cacheDescriptorArg: ICacheDescriptor
|
||||
): Promise<plugins.smartfile.SmartFile> {
|
||||
): Promise<plugins.smartfile.SmartFile | null> {
|
||||
const cacheEntry = await this.levelCache.retrieveCacheEntryByKey(
|
||||
this.getCacheDescriptorAsString(cacheDescriptorArg)
|
||||
);
|
||||
if (cacheEntry) {
|
||||
return plugins.smartfile.SmartFile.fromFoldedJson(cacheEntry.contents.toString());
|
||||
return this.smartFileFactory.fromFoldedJson(cacheEntry.contents.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -55,7 +56,7 @@ export class RegistryCache {
|
||||
}
|
||||
}
|
||||
|
||||
public getCacheDescriptorAsString(cacheDescriptorArg?: ICacheDescriptor) {
|
||||
public getCacheDescriptorAsString(cacheDescriptorArg: ICacheDescriptor) {
|
||||
return `${cacheDescriptorArg.registryUrl}//+//${cacheDescriptorArg.packageName}//+//${
|
||||
cacheDescriptorArg.filePath
|
||||
}//+//${cacheDescriptorArg.distTag || cacheDescriptorArg.version}`;
|
||||
|
||||
Reference in New Issue
Block a user