fix(core): update
This commit is contained in:
parent
e0a9e9702a
commit
afa511550d
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @gitzone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
138
.gitlab-ci.yml
138
.gitlab-ci.yml
@ -1,138 +0,0 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- 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
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartnpm",
|
||||
"shortDescription": "interface with npm to retrieve package information",
|
||||
"description": "interface with npm to retrieve package information",
|
||||
"npmPackagename": "@push.rocks/smartnpm",
|
||||
"license": "MIT"
|
||||
}
|
||||
|
13735
package-lock.json
generated
13735
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@ -10,26 +10,27 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web --allowimplicitany)"
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tsrun": "^1.2.35",
|
||||
"@gitzone/tstest": "^1.0.71",
|
||||
"@pushrocks/tapbundle": "^5.0.3",
|
||||
"@types/node": "^17.0.41"
|
||||
"@gitzone/tsbuild": "^2.1.66",
|
||||
"@gitzone/tsrun": "^1.2.44",
|
||||
"@gitzone/tstest": "^1.0.77",
|
||||
"@push.rocks/tapbundle": "^5.0.12",
|
||||
"@types/node": "^20.4.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/consolecolor": "^2.0.1",
|
||||
"@pushrocks/levelcache": "^3.0.2",
|
||||
"@pushrocks/smartarchive": "^3.0.6",
|
||||
"@pushrocks/smartfile": "^10.0.1",
|
||||
"@pushrocks/smartpath": "^5.0.5",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/smartrequest": "^1.1.56",
|
||||
"@pushrocks/smarttime": "^3.0.45",
|
||||
"@pushrocks/smartversion": "^3.0.2",
|
||||
"package-json": "^7.0.0"
|
||||
"@push.rocks/consolecolor": "^2.0.1",
|
||||
"@push.rocks/levelcache": "^3.0.6",
|
||||
"@push.rocks/smartarchive": "^3.0.6",
|
||||
"@push.rocks/smartfile": "^10.0.28",
|
||||
"@push.rocks/smartpath": "^5.0.11",
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"@push.rocks/smartrequest": "^2.0.18",
|
||||
"@push.rocks/smarttime": "^4.0.4",
|
||||
"@push.rocks/smartversion": "^3.0.2",
|
||||
"package-json": "^8.1.1"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
2034
pnpm-lock.yaml
generated
2034
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
30
readme.md
30
readme.md
@ -1,27 +1,26 @@
|
||||
# @pushrocks/smartnpm
|
||||
# @push.rocks/smartnpm
|
||||
interface with npm to retrieve package information
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartnpm)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartnpm)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartnpm)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnpm/)
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartnpm)
|
||||
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartnpm)
|
||||
* [github.com (source mirror)](https://github.com/push.rocks/smartnpm)
|
||||
* [docs (typedoc)](https://push.rocks.gitlab.io/smartnpm/)
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartnpm/badges/master/pipeline.svg)](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartnpm/badges/master/coverage.svg)](https://lossless.cloud)
|
||||
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartnpm)](https://lossless.cloud)
|
||||
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartnpm)](https://lossless.cloud)
|
||||
GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smartnpm/badges/master/pipeline.svg)](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smartnpm/badges/master/coverage.svg)](https://lossless.cloud)
|
||||
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartnpm)](https://lossless.cloud)
|
||||
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smartnpm)](https://lossless.cloud)
|
||||
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
|
||||
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartnpm)](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartnpm)](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartnpm)](https://lossless.cloud)
|
||||
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartnpm)](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartnpm)](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartnpm)](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
@ -33,7 +32,6 @@ We are always happy for code contributions. If you are not the code contributing
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
## Legal
|
||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
||||
|
11
test/test.ts
11
test/test.ts
@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartnpm from '../ts/index.js';
|
||||
import { NpmRegistry } from '../ts/index.js';
|
||||
|
||||
@ -25,7 +25,7 @@ tap.test('should produce a valid search string and this return npmts', async ()
|
||||
// lets test things with the verdaccio registry
|
||||
tap.test('should create a verdaccio registry', async () => {
|
||||
verdaccioRegistry = new NpmRegistry({
|
||||
npmRegistryUrl: 'https://verdaccio.lossless.one',
|
||||
npmRegistryUrl: 'https://verdaccio.lossless.digital',
|
||||
});
|
||||
expect(verdaccioRegistry).toBeInstanceOf(smartnpm.NpmRegistry);
|
||||
});
|
||||
@ -44,11 +44,8 @@ tap.test('should get a specific file from a package', async () => {
|
||||
});
|
||||
|
||||
tap.test('should get a specific file from a package', async () => {
|
||||
const wantedFiles = await verdaccioRegistry.getFilesFromPackage(
|
||||
'@pushrocks/websetup',
|
||||
'ts/'
|
||||
);
|
||||
for(const file of wantedFiles) {
|
||||
const wantedFiles = await verdaccioRegistry.getFilesFromPackage('@pushrocks/websetup', 'ts/');
|
||||
for (const file of wantedFiles) {
|
||||
console.log(file.path);
|
||||
}
|
||||
});
|
||||
|
@ -2,7 +2,7 @@
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartnpm',
|
||||
version: '2.0.3',
|
||||
name: '@push.rocks/smartnpm',
|
||||
version: '2.0.4',
|
||||
description: 'interface with npm to retrieve package information'
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as plugins from './smartnpm.plugins.js';
|
||||
import { NpmRegistry } from './smartnpm.classes.npmregistry.js';
|
||||
import { PackageDisttag } from './smartnpm.classes.packagedisttag.js';
|
||||
import { PackageVersion, IVersionData } from './smartnpm.classes.packageversion.js';
|
||||
import { PackageVersion, type IVersionData } from './smartnpm.classes.packageversion.js';
|
||||
|
||||
export class NpmPackage {
|
||||
public static async createFromFullMetadataAndVersionData(
|
||||
@ -139,7 +139,7 @@ export class NpmPackage {
|
||||
// lets resolve with the wanted file
|
||||
done.resolve([fileArg]);
|
||||
subscription.unsubscribe();
|
||||
} else if(!returnOnFirstArg && fileArg.path.startsWith(wantedFilePath)) {
|
||||
} else if (!returnOnFirstArg && fileArg.path.startsWith(wantedFilePath)) {
|
||||
allMatchingFiles.push(fileArg);
|
||||
}
|
||||
},
|
||||
@ -157,7 +157,7 @@ export class NpmPackage {
|
||||
/**
|
||||
* get files from package
|
||||
*/
|
||||
public async getFileFromPackage(
|
||||
public async getFileFromPackage(
|
||||
filePath: string,
|
||||
optionsArg?: {
|
||||
distTag?: string;
|
||||
|
@ -2,11 +2,11 @@ import * as plugins from './smartnpm.plugins.js';
|
||||
import * as paths from './smartnpm.paths.js';
|
||||
|
||||
// interfaces
|
||||
import { ISearchObject } from './smartnpm.interfaces.js';
|
||||
import { type ISearchObject } from './smartnpm.interfaces.js';
|
||||
|
||||
// classes
|
||||
import { NpmPackage } from './smartnpm.classes.npmpackage.js';
|
||||
import { ICacheDescriptor, RegistryCache } from './smartnpm.classes.registrycache.js';
|
||||
import { type ICacheDescriptor, RegistryCache } from './smartnpm.classes.registrycache.js';
|
||||
|
||||
export interface INpmRegistryConstructorOptions {
|
||||
npmRegistryUrl?: string;
|
||||
@ -33,18 +33,24 @@ export class NpmRegistry {
|
||||
* @param packageName
|
||||
*/
|
||||
public async getPackageInfo(packageName: string): Promise<NpmPackage> {
|
||||
const fullMetadata = await plugins.packageJson(packageName, {
|
||||
const fullMetadata = await plugins
|
||||
.packageJson.default(packageName, {
|
||||
registryUrl: this.options.npmRegistryUrl,
|
||||
fullMetadata: true,
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
return null;
|
||||
});
|
||||
const versionData = await plugins.packageJson.default(packageName, {
|
||||
registryUrl: this.options.npmRegistryUrl,
|
||||
fullMetadata: true,
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
return null;
|
||||
allVersions: true,
|
||||
});
|
||||
const versionData = await plugins.packageJson(packageName, {
|
||||
registryUrl: this.options.npmRegistryUrl,
|
||||
allVersions: true
|
||||
});
|
||||
const npmPackage = await NpmPackage.createFromFullMetadataAndVersionData(this, fullMetadata, versionData as any);
|
||||
const npmPackage = await NpmPackage.createFromFullMetadataAndVersionData(
|
||||
this,
|
||||
fullMetadata,
|
||||
versionData as any
|
||||
);
|
||||
return npmPackage;
|
||||
}
|
||||
|
||||
@ -62,30 +68,38 @@ export class NpmRegistry {
|
||||
/**
|
||||
* gets a file from a package as Smartfile
|
||||
*/
|
||||
public async getFileFromPackage(packageNameArg: string, filePathArg: string, optionsArg?: {
|
||||
distTag?: string;
|
||||
version?: string;
|
||||
}): Promise<plugins.smartfile.Smartfile> {
|
||||
public async getFileFromPackage(
|
||||
packageNameArg: string,
|
||||
filePathArg: string,
|
||||
optionsArg?: {
|
||||
distTag?: string;
|
||||
version?: string;
|
||||
}
|
||||
): Promise<plugins.smartfile.Smartfile> {
|
||||
// lets create a cache descriptor
|
||||
const cacheDescriptor: ICacheDescriptor = {
|
||||
registryUrl: this.options.npmRegistryUrl,
|
||||
packageName: packageNameArg,
|
||||
filePath: filePathArg,
|
||||
distTag: optionsArg?.distTag,
|
||||
version: optionsArg?.version
|
||||
version: optionsArg?.version,
|
||||
};
|
||||
|
||||
// lets see if we have something cached
|
||||
const cachedFile: plugins.smartfile.Smartfile = await this.registryCache.getCachedFile(cacheDescriptor);
|
||||
const cachedFile: plugins.smartfile.Smartfile = await this.registryCache.getCachedFile(
|
||||
cacheDescriptor
|
||||
);
|
||||
|
||||
// lets handle both occasions
|
||||
if (!cachedFile) {
|
||||
const npmPackage = await this.getPackageInfo(packageNameArg);
|
||||
if (!optionsArg?.version && !optionsArg?.distTag) {
|
||||
const latestAvailable = npmPackage.allDistTags.find(packageArg => packageArg.name === 'latest');
|
||||
const latestAvailable = npmPackage.allDistTags.find(
|
||||
(packageArg) => packageArg.name === 'latest'
|
||||
);
|
||||
if (!latestAvailable) {
|
||||
optionsArg = {
|
||||
version: npmPackage.getBestMatchingVersion('*')
|
||||
version: npmPackage.getBestMatchingVersion('*'),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -99,23 +113,31 @@ export class NpmRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public async getFilesFromPackage(packageNameArg: string, filePath: string, optionsArg?: {
|
||||
distTag?: string;
|
||||
version?: string;
|
||||
}): Promise<plugins.smartfile.Smartfile[]> {
|
||||
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');
|
||||
const latestAvailable = npmPackage.allDistTags.find(
|
||||
(packageDistTagArg) => packageDistTagArg.name === 'latest'
|
||||
);
|
||||
if (!latestAvailable) {
|
||||
optionsArg = {
|
||||
version: npmPackage.getBestMatchingVersion('*')
|
||||
version: npmPackage.getBestMatchingVersion('*'),
|
||||
};
|
||||
}
|
||||
}
|
||||
return npmPackage.getFilesFromPackage(filePath, optionsArg);
|
||||
}
|
||||
|
||||
public async getPackageAsSmartfileVirtualDir(packageNameArg: string): Promise<plugins.smartfile.VirtualDirectory> {
|
||||
public async getPackageAsSmartfileVirtualDir(
|
||||
packageNameArg: string
|
||||
): Promise<plugins.smartfile.VirtualDirectory> {
|
||||
/**
|
||||
* TODO: rewrite as memory only
|
||||
*/
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { NpmRegistry } from './smartnpm.classes.npmregistry.js';
|
||||
import * as plugins from './smartnpm.plugins.js';
|
||||
|
||||
|
||||
export interface ICacheDescriptor {
|
||||
registryUrl: string;
|
||||
packageName: string;
|
||||
@ -18,33 +17,47 @@ export class RegistryCache {
|
||||
this.npmregistryRef = npmRegistryRefArg;
|
||||
this.levelCache = new plugins.levelcache.LevelCache({
|
||||
cacheId: encodeURIComponent(this.npmregistryRef.options.npmRegistryUrl),
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public async getCachedFile (cacheDescriptorArg: ICacheDescriptor): Promise<plugins.smartfile.Smartfile> {
|
||||
const cacheEntry = await this.levelCache.retrieveCacheEntryByKey(this.getCacheDescriptorAsString(cacheDescriptorArg));
|
||||
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 (cacheDescriptorArg: ICacheDescriptor, smartfileArg: plugins.smartfile.Smartfile) {
|
||||
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})
|
||||
}));
|
||||
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})
|
||||
}));
|
||||
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}`;
|
||||
return `${cacheDescriptorArg.registryUrl}//+//${cacheDescriptorArg.packageName}//+//${
|
||||
cacheDescriptorArg.filePath
|
||||
}//+//${cacheDescriptorArg.distTag || cacheDescriptorArg.version}`;
|
||||
}
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
import * as plugins from './smartnpm.plugins.js';
|
||||
|
||||
export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
|
||||
export const packageDir = plugins.path.join(
|
||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
'../'
|
||||
);
|
||||
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
|
||||
|
@ -4,19 +4,29 @@ import * as path from 'path';
|
||||
export { path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as consolecolor from '@pushrocks/consolecolor';
|
||||
import * as levelcache from '@pushrocks/levelcache';
|
||||
import * as smartarchive from '@pushrocks/smartarchive';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartversion from '@pushrocks/smartversion';
|
||||
import * as smarttime from '@pushrocks/smarttime';
|
||||
import * as consolecolor from '@push.rocks/consolecolor';
|
||||
import * as levelcache from '@push.rocks/levelcache';
|
||||
import * as smartarchive from '@push.rocks/smartarchive';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
import * as smartversion from '@push.rocks/smartversion';
|
||||
import * as smarttime from '@push.rocks/smarttime';
|
||||
|
||||
export { consolecolor, levelcache, smartarchive, smartfile, smartpath, smartpromise, smartrequest, smartversion, smarttime };
|
||||
export {
|
||||
consolecolor,
|
||||
levelcache,
|
||||
smartarchive,
|
||||
smartfile,
|
||||
smartpath,
|
||||
smartpromise,
|
||||
smartrequest,
|
||||
smartversion,
|
||||
smarttime,
|
||||
};
|
||||
|
||||
// third party scope
|
||||
import packageJson from 'package-json';
|
||||
import * as packageJson from 'package-json';
|
||||
|
||||
export { packageJson };
|
||||
|
Loading…
Reference in New Issue
Block a user