Compare commits

...

22 Commits

Author SHA1 Message Date
983a860e2f 1.0.38 2021-05-10 23:27:11 +00:00
c375d9ba10 fix(core): update 2021-05-10 23:27:11 +00:00
e874c935bb 1.0.37 2021-05-10 16:12:59 +00:00
001a79252c fix(core): update 2021-05-10 16:12:58 +00:00
634d1c3570 1.0.36 2021-05-10 16:12:11 +00:00
cd8c9bcdaa fix(core): update 2021-05-10 16:12:11 +00:00
f6d3d0987b 1.0.35 2021-05-06 10:34:45 +00:00
60a1de38ce fix(core): update 2021-05-06 10:34:44 +00:00
0ef6d0ccb2 1.0.34 2021-05-06 10:22:15 +00:00
8e538fd84d 1.0.33 2021-05-06 10:05:50 +00:00
6745115db7 fix(core): update 2021-05-06 10:05:49 +00:00
5ebce389d3 1.0.32 2021-05-06 10:04:51 +00:00
b4100688ac fix(version matching): now respecting packages without latest tag 2021-05-06 10:04:51 +00:00
77d515d915 1.0.31 2021-05-05 12:37:27 +00:00
aa71105b2d 1.0.30 2021-05-05 11:56:12 +00:00
e0ccb6c076 fix(core): update 2021-05-05 11:56:12 +00:00
af0d95f327 1.0.29 2021-05-05 10:54:32 +00:00
d0ac8f1418 fix(core): update 2021-05-05 10:54:31 +00:00
62f8106fc6 1.0.28 2021-04-29 21:20:19 +00:00
e87b8c994b fix(core): update 2021-04-29 21:20:18 +00:00
694ba7be25 1.0.27 2021-04-29 20:44:47 +00:00
952399c26e fix(core): update 2021-04-29 20:44:47 +00:00
8 changed files with 677 additions and 765 deletions

View File

@ -36,6 +36,7 @@ auditProductionDependencies:
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci

1118
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartnpm",
"version": "1.0.26",
"version": "1.0.38",
"private": false,
"description": "interface with npm to retrieve package information",
"main": "dist_ts/index.js",
@ -16,17 +16,18 @@
"@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.54",
"@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^15.0.1",
"@types/node": "^15.0.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@pushrocks/consolecolor": "^2.0.1",
"@pushrocks/levelcache": "^1.0.9",
"@pushrocks/levelcache": "^1.0.10",
"@pushrocks/smartarchive": "^2.0.4",
"@pushrocks/smartfile": "^8.0.10",
"@pushrocks/smartpromise": "^3.1.5",
"@pushrocks/smartrequest": "^1.1.51",
"@pushrocks/smarttime": "^3.0.38",
"@pushrocks/smartversion": "^2.0.7",
"package-json": "^6.5.0"
},

View File

@ -32,164 +32,25 @@ tap.test('should create a verdaccio registry', async () => {
tap.test('should get package from verdaccio', async () => {
const npmPackage = await verdaccioRegistry.getPackageInfo('@pushrocks/smartupdate');
console.log(npmPackage);
expect(npmPackage.license).to.equal('MIT');
});
tap.test('should get a specific file from a package', async () => {
const bundleFile = await verdaccioRegistry.getFileFromPackage(
const wantedFile = await verdaccioRegistry.getFileFromPackage(
'@pushrocks/websetup',
'ts/index.ts'
);
console.log(bundleFile.contentBuffer.toString());
console.log(wantedFile.contentBuffer.toString());
});
tap.test('should get a specific file from a package', async () => {
const wantedFiles = await verdaccioRegistry.getFilesFromPackage(
'@pushrocks/websetup',
'ts/'
);
for(const file of wantedFiles) {
console.log(file.path);
}
});
tap.start();
const hi = {
_id: '@pushrocks/smartversion',
_rev: '2-93b6e6391f7209fcbd1db76c92164777',
name: '@pushrocks/smartversion',
'dist-tags': { latest: '2.0.4' },
versions: {
'2.0.0': {
name: '@pushrocks/smartversion',
version: '2.0.0',
private: false,
description: 'handle semver with easy',
main: 'dist/index.js',
typings: 'dist/index.d.ts',
author: { name: 'Lossless GmbH' },
license: 'MIT',
scripts: { test: '(tstest test/)', build: '(tsbuild)' },
devDependencies: {
'@gitzone/tsbuild': '^2.0.22',
'@gitzone/tsrun': '^1.1.12',
'@gitzone/tstest': '^1.0.15',
'@pushrocks/tapbundle': '^3.0.5',
'@types/node': '^10.9.4',
},
dependencies: { '@types/semver': '^5.5.0', semver: '^5.5.1' },
gitHead: 'df6b1a9730551884aa4c4fae5577b2b11058f508',
_id: '@pushrocks/smartversion@2.0.0',
_npmVersion: '6.2.0',
_nodeVersion: '10.9.0',
_npmUser: { name: 'lossless', email: 'npm@lossless.com' },
dist: {
integrity:
'sha512-+loQHivWzEO39X/PEzi+UOptDveez0n8Eu/bDIht55wkjhav33HkNjab8MeK/g76gOia3ZHoPyqLTvD4yvXDiA==',
shasum: 'd663a39d77950de1a743adb0c2eb00e325d230df',
tarball: 'https://registry.npmjs.org/@pushrocks/smartversion/-/smartversion-2.0.0.tgz',
fileCount: 12,
unpackedSize: 12011,
'npm-signature':
'-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbi7zUCRA9TVsSAnZWagAAigcP/0gRmizQkzjE9Gw8gCeK\n56m41mJQmtl6tRvYVyVGuqfiCaiLvB/B0fkKt2r/MNsJVjC372ayWKya4nev\nTOLSg+g4e9gnkyn8i1OFVE5kr8C4MvLc6P771v2UDXJF5c3pYq6i5fSyGz/s\ngpOuy/KxyVo5wH16yasGWDq9Gl58yp+7vZKR6cc+7Rlq0UhyezhDBRBiKkB0\nk6Y/4J4KWK7CmO+3Y/QUPGBxGmoUHNSiS5cz8vWbycRP7pT11asksgxNPGdv\nyeW/VNVLZkemwrXhSuYKM0DK6aZpjJxk3A8OAyDuHGfZDzAmyaRsfUL84Mgl\nlN1S92CCfuAOyA1os8rsrJU133TV8zVTck3IdmO4AqJ8aB3WNkmNYE5IHxWf\nnmhUUo1Rv/M5fJniTHOBGaeOahFqEp+8URNW1zylC3NoFwiUon1lvnMp1Dd1\nczGPWvQ12ZAeMOR/qpO4RRzTdD45iuvvj2NRhZZN1pthnhUi8XpgMIDuCODT\n2Srew7JBkdfX3F1q/LGgk9e+RYCWTlLPgmzOBUH39ljpfa70liAH5sU+yyfk\nFLfVQlLwWAEwRnkm4j/l/xBWJcwqVG2nDOOzScfYVG3BXSBHo4PfywhFdbnc\nQ3MMrJsrJPhppfMJEEQWlQSkNSCCEV7DDPeH4oK9tKRUdmDaKJpnb6tVZqzM\nBWac\r\n=0NZU\r\n-----END PGP SIGNATURE-----\r\n',
},
maintainers: [{ name: 'lossless', email: 'npm@lossless.com' }],
directories: {},
_npmOperationalInternal: {
host: 's3://npm-registry-packages',
tmp: 'tmp/smartversion_2.0.0_1535884499821_0.9273118882229912',
},
_hasShrinkwrap: false,
},
'2.0.3': {
name: '@pushrocks/smartversion',
version: '2.0.3',
private: false,
description: 'handle semver with easy',
main: 'dist/index.js',
typings: 'dist/index.d.ts',
author: { name: 'Lossless GmbH' },
license: 'MIT',
scripts: { test: '(tstest test/)', build: '(tsbuild)' },
devDependencies: {
'@gitzone/tsbuild': '^2.1.17',
'@gitzone/tsrun': '^1.2.8',
'@gitzone/tstest': '^1.0.24',
'@pushrocks/tapbundle': '^3.0.13',
'@types/node': '^12.7.5',
},
dependencies: { '@types/semver': '^6.0.2', semver: '^6.3.0' },
gitHead: 'e364545d0ef6ef7fa1b8467fb48d2b67f09f2d07',
_id: '@pushrocks/smartversion@2.0.3',
_nodeVersion: '12.10.0',
_npmVersion: '6.11.3',
dist: {
integrity:
'sha512-nhauxBGMxjJtXj+k1Z7H2yB184ZhWhU0NKN5ATwlgfEM4zbbZNjCFRLVg/7sOXvbS2b0QU1aStRQ+6QGC2hW4A==',
shasum: '9272da89412556946c5a3d5ba3b6a253154de6ae',
tarball: 'https://registry.npmjs.org/@pushrocks/smartversion/-/smartversion-2.0.3.tgz',
fileCount: 9,
unpackedSize: 9127,
'npm-signature':
'-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdeRYfCRA9TVsSAnZWagAApCkP/RrWk6+hxpoTpflJ65x/\nm05egDhfyTs2BZKArkSnvtc+q6Fo3iDlumqiv3HRyHwDBFLgK5gAOgU0jyqW\nmhwumGMfKT4bzG65iU2z6FgS+RhEh3JaKzjgPohr1oEaLOaaKL0S9+Ybxt6u\nkwv4CgnmzQ/6zVZYJ+qFbV0v+n6iiuIbOTS8j7+X0nA/DkvvZ1Nwhng++vH8\nLm8lT78F/vcxHkSf2RfC6kabhVF+vVRBazq/cI4OQ+xjBQC2y+6YxEq/4Hsz\nKZBF9u2ZcyeI7NEuo1FaojvqvLX3lPxi9Xfw2PSO2iri+DS8KIOVgzwJ+9ih\nb1h/vpoFv8dbhZzkqSs/4rab3rvQYqy7AgvslI8mEeOQk/BhrjxQIvG0re3H\nzc0iWlNp6W3Lsf3/gmKGZbhl39ZgQxInfWLNW60ghqzUq85gyAwPDRb2yxez\nP7bMT0qb/bQSmAa63/q3qE+JAjZFQFDB6Pj6sO1p3csv0T+7mRj9T/4pSc8B\nv5rD9t0mVlAZXwmz3zDhpomct3bhUlAidw7tcax8sr9SowA2hqY3TB1uJ52y\nKPDVMQZ4Voi7kft+icYoVm1XkQMwmmedAoTbS49s52wW6dm4CWmnlBOZzzqN\neT4Q1INrTUXaMxRv/zxguk7TV8xi6gRf+EBDtnEKukITWTvvPsGq4SS9toRa\n9L6F\r\n=yVBx\r\n-----END PGP SIGNATURE-----\r\n',
},
maintainers: [{ name: 'lossless', email: 'npm@lossless.com' }],
_npmUser: { name: 'lossless', email: 'npm@lossless.com' },
directories: {},
_npmOperationalInternal: {
host: 's3://npm-registry-packages',
tmp: 'tmp/smartversion_2.0.3_1568216607132_0.9216415895294796',
},
_hasShrinkwrap: false,
},
'2.0.4': {
name: '@pushrocks/smartversion',
version: '2.0.4',
private: false,
description: 'handle semver with easy',
main: 'dist/index.js',
typings: 'dist/index.d.ts',
author: { name: 'Lossless GmbH' },
license: 'MIT',
scripts: { test: '(tstest test/)', build: '(tsbuild)' },
devDependencies: {
'@gitzone/tsbuild': '^2.1.17',
'@gitzone/tsrun': '^1.2.8',
'@gitzone/tstest': '^1.0.24',
'@pushrocks/tapbundle': '^3.0.13',
'@types/node': '^12.7.5',
tslint: '^5.20.0',
'tslint-config-prettier': '^1.18.0',
},
dependencies: { '@types/semver': '^6.0.2', semver: '^6.3.0' },
gitHead: 'bb8e7cb608f3a116e7bfb0b52dd5ce9a7c4eaec1',
_id: '@pushrocks/smartversion@2.0.4',
_nodeVersion: '12.10.0',
_npmVersion: '6.11.3',
dist: {
integrity:
'sha512-LrtaWRn1DD2zIUr8nVAsKwZ+Y55TFIVZ0z3xjwAQ46SoiTrFWooeQ2Xw18DqsEo1cEqMZyGAskaJkOaRkXHtUA==',
shasum: '7c6297f9c596e729001c2b6e2a8fa72c40ed42a9',
tarball: 'https://registry.npmjs.org/@pushrocks/smartversion/-/smartversion-2.0.4.tgz',
fileCount: 9,
unpackedSize: 9263,
'npm-signature':
'-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdeRazCRA9TVsSAnZWagAAxX0P/j12DYB5zjZQh3/IpY1t\n+vzvLmTgn2b0lhheLxUX9EYMW+cethYbd8Q8p/SOsytfB2IHCKBdkpE5ZAIK\nsv7d/myZaihZ9RHCd/UQOj99b/KfdbN/7ndtEL7V4hmcNyWUmebeRsxMhxZ5\nLRvWMZiNsgdXbKxs6JpId3iuSFuTxRgL41smiklcW0nGRp9uMieN8TC3xmOW\nsia6JcvGNQT1/LD9XN6l9U/ZWfzOMaEtjv4Hd9XzOVv0SMYT5Nyv3JQV2Jd5\nc5G5aGZe0QXSB9LwnNUcXC3mrZ9+SvmqpECcV2BTJ+JJlzp4Pny51r2nPyC6\nypdsfTfDzAL6BIq433OScEyjRMcufLC+caGXPCjUhtPW6wlf9kTFiRd2L3uk\nWhg2LmFhL4bHz67ty2wAy8XlLYOS/QFOZLEZr7bZDhINkkqR5RQd5RfkMJ6Q\n0skcsspq69tWKrgY3Uh6aK30Z+g7C4V/KGfquz6EsET9xP+7MRTVcd+FLfC1\ndfCcfe3/l49oXbCPwApH9X8ETc3HDJuSRdfVV7PVsEzbOwN4sqTIS9vAHXDN\ncjAmrhbZkhA7VD4PNjhEov1veo/UOoNB7xlN4JLuRZ40SqCSr4akVnNImUDc\nCg+b16mZhlVpLNgjVjG9rgDD7zCn+zn9EZTsq3/qL4jEcf4JY+T2YKmf7AMb\nhmej\r\n=eqby\r\n-----END PGP SIGNATURE-----\r\n',
},
maintainers: [{ name: 'lossless', email: 'npm@lossless.com' }],
_npmUser: { name: 'lossless', email: 'npm@lossless.com' },
directories: {},
_npmOperationalInternal: {
host: 's3://npm-registry-packages',
tmp: 'tmp/smartversion_2.0.4_1568216754658_0.06886864906713819',
},
_hasShrinkwrap: false,
},
},
time: {
created: '2018-09-02T10:34:59.735Z',
'2.0.0': '2018-09-02T10:34:59.913Z',
modified: '2019-09-11T15:45:58.404Z',
'2.0.3': '2019-09-11T15:43:27.294Z',
'2.0.4': '2019-09-11T15:45:54.786Z',
},
maintainers: [{ name: 'lossless', email: 'npm@lossless.com' }],
description: 'handle semver with easy',
author: { name: 'Lossless GmbH' },
license: 'MIT',
readme:
'# @pushrocks/smartversion\nhandle semver with easy\n\n## Availabililty and Links\n* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartversion)\n* [gitlab.com (source)](https://gitlab.com/pushrocks/smartversion)\n* [github.com (source mirror)](https://github.com/pushrocks/smartversion)\n* [docs (typedoc)](https://pushrocks.gitlab.io/smartversion/)\n\n## Status for master\n[![build status](https://gitlab.com/pushrocks/smartversion/badges/master/build.svg)](https://gitlab.com/pushrocks/smartversion/commits/master)\n[![coverage report](https://gitlab.com/pushrocks/smartversion/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartversion/commits/master)\n[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartversion.svg)](https://www.npmjs.com/package/@pushrocks/smartversion)\n[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartversion/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartversion)\n[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)\n[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)\n[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)\n\n## Usage\n\nUse TypeScript for best in class instellisense.\n\nFor further information read the linked docs at the top of this readme.\n\n> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)\n| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)\n\n[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)\n',
readmeFilename: 'readme.md',
};

View File

@ -91,37 +91,37 @@ export class NpmPackage {
public async saveToCache() {}
/**
* get file from package
* get files from package
*/
public async getFileFromPackage(
public async getFilesFromPackage(
filePath: string,
optionsArg?: {
optionsArg: {
distTag?: string;
version?: string;
}
): Promise<plugins.smartfile.Smartfile> {
const done = plugins.smartpromise.defer<plugins.smartfile.Smartfile>();
},
returnOnFirstArg = false
): Promise<plugins.smartfile.Smartfile[]> {
const done = plugins.smartpromise.defer<plugins.smartfile.Smartfile[]>();
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
let tarballUrl = this.dist.tarball;
if (optionsArg && (optionsArg.version || optionsArg.distTag)) {
let tarballUrl = this.dist?.tarball;
if (optionsArg?.version || optionsArg?.distTag) {
if (optionsArg.distTag && optionsArg.version) {
throw new Error('Please either sepcify version OR disttag, not both.');
throw new Error('Please either specify version OR disttag, not both.');
}
let targetVersion: plugins.smartversion.SmartVersion;
let targetVersionString: string;
if (optionsArg.distTag) {
const targetDistTag = this.allDistTags.find((distTag) => {
return distTag.name === optionsArg.distTag;
});
if (targetDistTag) {
targetVersion = new plugins.smartversion.SmartVersion(targetDistTag.targetVersion);
targetVersionString = targetDistTag.targetVersion;
}
} else {
const smartversion = plugins.smartversion.SmartVersion.fromFuzzyString(optionsArg.version);
targetVersionString = optionsArg.version;
}
// lets find the best matching release
const versionStrings = this.allVersions.map((packageVersion) => packageVersion.version);
const bestMatchingVersion = targetVersion.getBestMatch(versionStrings);
const bestMatchingVersion = this.getBestMatchingVersion(targetVersionString);
if (!bestMatchingVersion) {
return null;
}
@ -131,29 +131,57 @@ export class NpmPackage {
}
const fileObservable = await smartarchiveInstance.extractArchiveFromUrlToObservable(tarballUrl);
const wantedFilePath = plugins.path.join('package', filePath);
const allMatchingFiles: plugins.smartfile.Smartfile[] = [];
const subscription = fileObservable.subscribe(
(fileArg) => {
if (fileArg.path === wantedFilePath) {
// lets care about caching
// returnOnFirstArg requires exact match
if (returnOnFirstArg && fileArg.path === wantedFilePath) {
// lets resolve with the wanted file
done.resolve(fileArg);
done.resolve([fileArg]);
subscription.unsubscribe();
} else if(!returnOnFirstArg && fileArg.path.startsWith(wantedFilePath)) {
allMatchingFiles.push(fileArg);
}
},
(err) => {
console.log(err);
},
() => {
done.resolve(null);
done.resolve(allMatchingFiles);
subscription.unsubscribe();
}
);
return done.promise;
}
/**
* get files from package
*/
public async getFileFromPackage(
filePath: string,
optionsArg?: {
distTag?: string;
version?: string;
}
): Promise<plugins.smartfile.Smartfile> {
const result = await this.getFilesFromPackage(filePath, optionsArg, true);
return result[0];
}
/**
* updates the package with information from the registry
*/
update() {}
/** */
public getBestMatchingVersion(versionArg: string): string {
// lets find the best matching release
const targetVersion = plugins.smartversion.SmartVersion.fromFuzzyString(versionArg);
const versionStrings = this.allVersions.map((packageVersion) => packageVersion.version);
const bestMatchingVersion = targetVersion.getBestMatch(versionStrings);
if (!bestMatchingVersion) {
return null;
}
return bestMatchingVersion;
}
}

View File

@ -6,7 +6,7 @@ import { ISearchObject } from './smartnpm.interfaces';
// classes
import { NpmPackage } from './smartnpm.classes.npmpackage';
import { RegistryCache } from './smartnpm.classes.registrycache';
import { ICacheDescriptor, RegistryCache } from './smartnpm.classes.registrycache';
export interface INpmRegistryConstructorOptions {
npmRegistryUrl?: string;
@ -36,6 +36,9 @@ export class NpmRegistry {
const fullMetadata = await plugins.packageJson(packageName, {
registryUrl: this.options.npmRegistryUrl,
fullMetadata: true,
}).catch(err => {
console.log(err);
return null;
});
const versionData = await plugins.packageJson(packageName, {
registryUrl: this.options.npmRegistryUrl,
@ -59,22 +62,57 @@ export class NpmRegistry {
/**
* gets a file from a package as Smartfile
*/
public async getFileFromPackage(packageNameArg: string, filePath: string, optionsArg?: {
public async getFileFromPackage(packageNameArg: string, filePathArg: string, optionsArg?: {
distTag?: string;
version?: string;
}): Promise<plugins.smartfile.Smartfile> {
const fileId = `${this.options.npmRegistryUrl}//+//${packageNameArg}//+//${filePath}//+//${optionsArg?.distTag || optionsArg?.version}`;
const cachedFile: plugins.smartfile.Smartfile = await this.registryCache.getCachedFile(fileId);
// lets create a cache descriptor
const cacheDescriptor: ICacheDescriptor = {
registryUrl: this.options.npmRegistryUrl,
packageName: packageNameArg,
filePath: filePathArg,
distTag: optionsArg?.distTag,
version: optionsArg?.version
};
// lets see if we have something cached
const cachedFile: plugins.smartfile.Smartfile = await this.registryCache.getCachedFile(cacheDescriptor);
// lets handle both occasions
if (!cachedFile) {
const npmPackage = await this.getPackageInfo(packageNameArg);
const fileResult = await npmPackage.getFileFromPackage(filePath, optionsArg);
this.registryCache.cacheSmartFile(fileId, fileResult);
if (!optionsArg?.version && !optionsArg?.distTag) {
const latestAvailable = npmPackage.allDistTags.find(packageArg => packageArg.name === 'latest');
if (!latestAvailable) {
optionsArg = {
version: npmPackage.getBestMatchingVersion('*')
};
}
}
const fileResult = await npmPackage.getFileFromPackage(filePathArg, optionsArg);
this.registryCache.cacheSmartFile(cacheDescriptor, fileResult);
return fileResult;
} else {
return cachedFile;
}
}
public async getFilesFromPackage(packageNameArg: string, filePath: string, optionsArg?: {
distTag?: string;
version?: string;
}): Promise<plugins.smartfile.Smartfile[]> {
const npmPackage = await this.getPackageInfo(packageNameArg);
if (!optionsArg?.version && !optionsArg?.distTag) {
const latestAvailable = npmPackage.allDistTags.find(packageDistTagArg => packageDistTagArg.name === 'latest');
if (!latestAvailable) {
optionsArg = {
version: npmPackage.getBestMatchingVersion('*')
};
}
}
return npmPackage.getFilesFromPackage(filePath, optionsArg);
}
public async getPackageAsSmartfileVirtualDir(packageNameArg: string): Promise<plugins.smartfile.VirtualDirectory> {
/**
* TODO: rewrite as memory only

View File

@ -1,6 +1,15 @@
import { NpmRegistry } from './smartnpm.classes.npmregistry';
import * as plugins from './smartnpm.plugins';
export interface ICacheDescriptor {
registryUrl: string;
packageName: string;
filePath: string;
distTag?: string;
version?: string;
}
export class RegistryCache {
npmregistryRef: NpmRegistry;
public levelCache: plugins.levelcache.LevelCache;
@ -13,18 +22,29 @@ export class RegistryCache {
});
}
public async getCachedFile (fileId: string): Promise<plugins.smartfile.Smartfile> {
const cacheEntry = await this.levelCache.retrieveCacheEntryByKey(fileId);
public async getCachedFile (cacheDescriptorArg: ICacheDescriptor): Promise<plugins.smartfile.Smartfile> {
const cacheEntry = await this.levelCache.retrieveCacheEntryByKey(this.getCacheDescriptorAsString(cacheDescriptorArg));
if (cacheEntry) {
return plugins.smartfile.Smartfile.fromFoldedJson(cacheEntry.contents.toString());
}
return null;
}
public async cacheSmartFile (fileIdArg: string, smartfileArg: plugins.smartfile.Smartfile) {
await this.levelCache.storeCacheEntryByKey(fileIdArg, new plugins.levelcache.CacheEntry({
contents: Buffer.from(smartfileArg.foldToJson()),
ttl: 60000
}));
public async cacheSmartFile (cacheDescriptorArg: ICacheDescriptor, smartfileArg: plugins.smartfile.Smartfile) {
if (smartfileArg && cacheDescriptorArg.version) {
await this.levelCache.storeCacheEntryByKey(this.getCacheDescriptorAsString(cacheDescriptorArg), new plugins.levelcache.CacheEntry({
contents: Buffer.from(smartfileArg.foldToJson()),
ttl: plugins.smarttime.getMilliSecondsFromUnits({hours: 1})
}));
} else {
await this.levelCache.storeCacheEntryByKey(this.getCacheDescriptorAsString(cacheDescriptorArg), new plugins.levelcache.CacheEntry({
contents: Buffer.from(smartfileArg.foldToJson()),
ttl: plugins.smarttime.getMilliSecondsFromUnits({minutes: 1})
}));
}
}
public getCacheDescriptorAsString(cacheDescriptorArg?: ICacheDescriptor) {
return `${cacheDescriptorArg.registryUrl}//+//${cacheDescriptorArg.packageName}//+//${cacheDescriptorArg.filePath}//+//${cacheDescriptorArg.distTag || cacheDescriptorArg.version}`;
}
}

View File

@ -11,8 +11,9 @@ import * as smartfile from '@pushrocks/smartfile';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartversion from '@pushrocks/smartversion';
import * as smarttime from '@pushrocks/smarttime';
export { consolecolor, levelcache, smartarchive, smartfile, smartpromise, smartrequest, smartversion };
export { consolecolor, levelcache, smartarchive, smartfile, smartpromise, smartrequest, smartversion, smarttime };
// third party scope
import packageJson from 'package-json';