Compare commits
64 Commits
Author | SHA1 | Date | |
---|---|---|---|
80e50b7391 | |||
14967d6705 | |||
2344867da9 | |||
4d2349bae1 | |||
b29dc35c20 | |||
37d69e201e | |||
afa511550d | |||
e0a9e9702a | |||
85f5985249 | |||
e337241dd6 | |||
a7a1343e3c | |||
f54402aa1e | |||
b7ecd5a6b7 | |||
ba57be2fe5 | |||
2b308e8824 | |||
0b1b6deb98 | |||
d5636aaf9a | |||
0276faa949 | |||
c0d64926a0 | |||
7737014464 | |||
349360cdc6 | |||
983a860e2f | |||
c375d9ba10 | |||
e874c935bb | |||
001a79252c | |||
634d1c3570 | |||
cd8c9bcdaa | |||
f6d3d0987b | |||
60a1de38ce | |||
0ef6d0ccb2 | |||
8e538fd84d | |||
6745115db7 | |||
5ebce389d3 | |||
b4100688ac | |||
77d515d915 | |||
aa71105b2d | |||
e0ccb6c076 | |||
af0d95f327 | |||
d0ac8f1418 | |||
62f8106fc6 | |||
e87b8c994b | |||
694ba7be25 | |||
952399c26e | |||
ab1e83b8bf | |||
67980f9f41 | |||
2d34397b9b | |||
2744e1a92b | |||
b8987b7913 | |||
95ffb06e77 | |||
71abbbb5f1 | |||
9dfa1a789e | |||
c68ea1c8fd | |||
8e943512f8 | |||
c010319076 | |||
cf03e58c6f | |||
d59875f23f | |||
6b13e46947 | |||
096c38de9e | |||
7292b45d33 | |||
3ddad53d29 | |||
617b49aaba | |||
2dcd93b431 | |||
0e2dc83409 | |||
2cb227632f |
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
|
127
.gitlab-ci.yml
127
.gitlab-ci.yml
@ -1,127 +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
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
audit:
|
|
||||||
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=moderate
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# 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:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
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:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
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
|
|
||||||
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",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"projectType": {
|
"projectType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["website", "element", "service", "npm"]
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,25 @@
|
|||||||
"gitzone": {
|
"gitzone": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartnpm",
|
"gitrepo": "smartnpm",
|
||||||
"shortDescription": "interface with npm to retrieve package information",
|
"description": "A library to interface with npm for retrieving package information and manipulation.",
|
||||||
"npmPackagename": "@pushrocks/smartnpm",
|
"npmPackagename": "@push.rocks/smartnpm",
|
||||||
"license": "MIT"
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"npm",
|
||||||
|
"package",
|
||||||
|
"information",
|
||||||
|
"registry",
|
||||||
|
"search",
|
||||||
|
"metadata",
|
||||||
|
"version",
|
||||||
|
"dependencies"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
1840
package-lock.json
generated
1840
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
60
package.json
60
package.json
@ -1,32 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnpm",
|
"name": "@push.rocks/smartnpm",
|
||||||
"version": "1.0.15",
|
"version": "2.0.4",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "interface with npm to retrieve package information",
|
"description": "A library to interface with npm for retrieving package information and manipulation.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.22",
|
"@gitzone/tsbuild": "^2.1.66",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.44",
|
||||||
"@gitzone/tstest": "^1.0.28",
|
"@gitzone/tstest": "^1.0.77",
|
||||||
"@pushrocks/tapbundle": "^3.2.1",
|
"@push.rocks/tapbundle": "^5.0.12",
|
||||||
"@types/node": "^13.9.1",
|
"@types/node": "^20.4.4"
|
||||||
"tslint": "^6.1.0",
|
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/consolecolor": "^2.0.1",
|
"@push.rocks/consolecolor": "^2.0.1",
|
||||||
"@pushrocks/smartarchive": "^1.0.12",
|
"@push.rocks/levelcache": "^3.0.6",
|
||||||
"@pushrocks/smartfile": "^7.0.11",
|
"@push.rocks/smartarchive": "^3.0.6",
|
||||||
"@pushrocks/smartlog": "^2.0.21",
|
"@push.rocks/smartfile": "^10.0.28",
|
||||||
"@pushrocks/smartrequest": "^1.1.47",
|
"@push.rocks/smartpath": "^5.0.11",
|
||||||
"package-json": "^6.5.0"
|
"@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": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@ -39,5 +43,23 @@
|
|||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
]
|
],
|
||||||
}
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
],
|
||||||
|
"keywords": [
|
||||||
|
"npm",
|
||||||
|
"package",
|
||||||
|
"information",
|
||||||
|
"registry",
|
||||||
|
"search",
|
||||||
|
"metadata",
|
||||||
|
"version",
|
||||||
|
"dependencies"
|
||||||
|
],
|
||||||
|
"homepage": "https://code.foss.global/push.rocks/smartnpm",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://code.foss.global/push.rocks/smartnpm.git"
|
||||||
|
}
|
||||||
|
}
|
5228
pnpm-lock.yaml
generated
Normal file
5228
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
122
readme.md
122
readme.md
@ -1,39 +1,109 @@
|
|||||||
# @pushrocks/smartnpm
|
# @push.rocks/smartnpm
|
||||||
interface with npm to retrieve package information
|
interface with npm to retrieve package information
|
||||||
|
|
||||||
## Availabililty and Links
|
## Install
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartnpm)
|
To install `@push.rocks/smartnpm`, open your terminal and run the following command:
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartnpm)
|
```sh
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartnpm)
|
npm install @push.rocks/smartnpm --save
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnpm/)
|
```
|
||||||
|
This will add `@push.rocks/smartnpm` as a dependency to your project and you're ready to start using it.
|
||||||
## Status for master
|
|
||||||
[](https://gitlab.com/pushrocks/smartnpm/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartnpm/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartnpm)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartnpm)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://prettier.io/)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
To use `@push.rocks/smartnpm` in your project, you first need to import it in your TypeScript files. `@push.rocks/smartnpm` provides a powerful interface to interact with npm to retrieve package information, handle package downloads, and more. Below are examples showcasing how to leverage some of its features in real-world scenarios.
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
### Initialize the NpmRegistry
|
||||||
|
Before you can retrieve any package information or perform actions such as downloading packages, you need to create an instance of `NpmRegistry`. This acts as your starting point.
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
```typescript
|
||||||
|
import { NpmRegistry } from '@push.rocks/smartnpm';
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
const npmRegistry = new NpmRegistry();
|
||||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
```
|
||||||
|
|
||||||
[](https://push.rocks)
|
Optionally, you can provide a custom npm registry URL if you're not using the default npm registry:
|
||||||
|
|
||||||
## Contribution
|
```typescript
|
||||||
|
const customRegistry = new NpmRegistry({
|
||||||
|
npmRegistryUrl: 'https://custom.registry.url'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
### Retrieve Package Information
|
||||||
|
`@push.rocks/smartnpm` allows you to easily get detailed information about a package, including its versions, dist tags, and metadata. Here's how you can get information about a specific package:
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
```typescript
|
||||||
|
async function getPackageInfo() {
|
||||||
|
const packageName = 'your-package-name';
|
||||||
|
const packageInfo = await npmRegistry.getPackageInfo(packageName);
|
||||||
|
console.log(packageInfo);
|
||||||
|
}
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
getPackageInfo();
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
```
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
### Search for Packages
|
||||||
|
You can search for packages using a variety of filters such as keywords, author, maintainer, etc. Here's an example of searching for packages with specific criteria:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function searchPackages() {
|
||||||
|
const searchResults = await npmRegistry.searchOnNpm({
|
||||||
|
keywords: ['webpack-plugin'],
|
||||||
|
author: 'webpack'
|
||||||
|
});
|
||||||
|
console.log(searchResults);
|
||||||
|
}
|
||||||
|
|
||||||
|
searchPackages();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Downloading Packages
|
||||||
|
`@push.rocks/smartnpm` provides an easy way to download npm packages and extract them to a specific directory. This could be useful for creating tools that need to programmatically handle packages.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function downloadPackage() {
|
||||||
|
const packageName = 'some-package';
|
||||||
|
const targetDirectory = './path/to/targetDir';
|
||||||
|
|
||||||
|
await npmRegistry.savePackageToDisk(packageName, targetDirectory);
|
||||||
|
console.log(`${packageName} has been downloaded to ${targetDirectory}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadPackage();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Working with Package Versions and Dist Tags
|
||||||
|
You can easily retrieve detailed information about specific package versions or distribution tags. This is particularly useful for automation scripts that need to work with specific versions of a package.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function getPackageVersionDetails() {
|
||||||
|
const packageName = 'some-package';
|
||||||
|
const version = '1.0.0'; // You can also use dist tags like 'latest'
|
||||||
|
|
||||||
|
const packageInfo = await npmRegistry.getPackageInfo(packageName);
|
||||||
|
const versionInfo = packageInfo.allVersions.find(v => v.version === version);
|
||||||
|
console.log(versionInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPackageVersionDetails();
|
||||||
|
```
|
||||||
|
|
||||||
|
These examples only scratch the surface of what you can achieve with `@push.rocks/smartnpm`. By integrating this library, you have a powerful tool at your disposal for interacting with npm in a programmatic way, enabling a wide range of possibilities for automation, CI/CD, and tooling around npm packages.
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
41
test/test.ts
41
test/test.ts
@ -1,6 +1,6 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
import * as smartnpm from '../ts/index';
|
import * as smartnpm from '../ts/index.js';
|
||||||
import { NpmRegistry } from '../ts/index';
|
import { NpmRegistry } from '../ts/index.js';
|
||||||
|
|
||||||
let npmRegistry: smartnpm.NpmRegistry;
|
let npmRegistry: smartnpm.NpmRegistry;
|
||||||
let verdaccioRegistry: smartnpm.NpmRegistry;
|
let verdaccioRegistry: smartnpm.NpmRegistry;
|
||||||
@ -9,38 +9,53 @@ let testPackage: smartnpm.NpmPackage;
|
|||||||
// lets test things with the standard npm registry
|
// lets test things with the standard npm registry
|
||||||
tap.test('should create valid instances', async () => {
|
tap.test('should create valid instances', async () => {
|
||||||
npmRegistry = new smartnpm.NpmRegistry();
|
npmRegistry = new smartnpm.NpmRegistry();
|
||||||
expect(npmRegistry).to.be.instanceof(smartnpm.NpmRegistry);
|
expect(npmRegistry).toBeInstanceOf(smartnpm.NpmRegistry);
|
||||||
|
|
||||||
testPackage = new smartnpm.NpmPackage(npmRegistry);
|
testPackage = new smartnpm.NpmPackage(npmRegistry);
|
||||||
expect(testPackage).to.be.instanceof(smartnpm.NpmPackage);
|
expect(testPackage).toBeInstanceOf(smartnpm.NpmPackage);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should produce a valid search string and this return npmts', async () => {
|
tap.test('should produce a valid search string and this return npmts', async () => {
|
||||||
const packages = await npmRegistry.searchOnNpm({
|
const packages = await npmRegistry.searchOnNpm({
|
||||||
name: '@pushrocks/smartupdate'
|
name: '@pushrocks/smartupdate',
|
||||||
});
|
});
|
||||||
expect(packages[0].name).to.equal('@pushrocks/smartupdate');
|
expect(packages[0].name).toEqual('@pushrocks/smartupdate');
|
||||||
});
|
});
|
||||||
|
|
||||||
// lets test things with the verdaccio registry
|
// lets test things with the verdaccio registry
|
||||||
tap.test('should create a verdaccio registry', async () => {
|
tap.test('should create a verdaccio registry', async () => {
|
||||||
verdaccioRegistry = new NpmRegistry({
|
verdaccioRegistry = new NpmRegistry({
|
||||||
npmRegistryUrl: 'https://verdaccio.lossless.one'
|
npmRegistryUrl: 'https://verdaccio.lossless.digital',
|
||||||
});
|
});
|
||||||
expect(verdaccioRegistry).to.be.instanceOf(smartnpm.NpmRegistry);
|
expect(verdaccioRegistry).toBeInstanceOf(smartnpm.NpmRegistry);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get package from verdaccio', async () => {
|
tap.test('should get package from verdaccio', async () => {
|
||||||
const npmPackage = await verdaccioRegistry.getPackageInfo('@pushrocks/smartupdate');
|
const npmPackage = await verdaccioRegistry.getPackageInfo('@pushrocks/smartupdate');
|
||||||
console.log(npmPackage);
|
expect(npmPackage.license).toEqual('MIT');
|
||||||
expect(npmPackage.license).to.equal('MIT');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get a specific file from a package', async () => {
|
tap.test('should get a specific file from a package', async () => {
|
||||||
const bundleFile = await verdaccioRegistry.getFileFromPackage(
|
const wantedFile = await verdaccioRegistry.getFileFromPackage(
|
||||||
'@pushrocks/websetup',
|
'@pushrocks/websetup',
|
||||||
'dist_bundle/bundle.js'
|
'./ts/index.ts'
|
||||||
);
|
);
|
||||||
|
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.test('should not get a nonexisting file from a package', async () => {
|
||||||
|
const wantedFileNotThere = await verdaccioRegistry.getFileFromPackage(
|
||||||
|
'@pushrocks/websetup',
|
||||||
|
'ts/notthere'
|
||||||
|
);
|
||||||
|
expect(wantedFileNotThere).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/smartnpm',
|
||||||
|
version: '2.0.4',
|
||||||
|
description: 'interface with npm to retrieve package information'
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smartnpm.plugins';
|
import * as plugins from './smartnpm.plugins.js';
|
||||||
|
|
||||||
export * from './smartnpm.classes.npmregistry';
|
export * from './smartnpm.classes.npmregistry.js';
|
||||||
export * from './smartnpm.classes.npmpackage';
|
export * from './smartnpm.classes.npmpackage.js';
|
||||||
|
@ -1,13 +1,35 @@
|
|||||||
import * as plugins from './smartnpm.plugins';
|
import * as plugins from './smartnpm.plugins.js';
|
||||||
import { NpmRegistry } from './smartnpm.classes.npmregistry';
|
import { NpmRegistry } from './smartnpm.classes.npmregistry.js';
|
||||||
|
import { PackageDisttag } from './smartnpm.classes.packagedisttag.js';
|
||||||
|
import { PackageVersion, type IVersionData } from './smartnpm.classes.packageversion.js';
|
||||||
|
|
||||||
export class NpmPackage {
|
export class NpmPackage {
|
||||||
public static async createFromFullMetadata(
|
public static async createFromFullMetadataAndVersionData(
|
||||||
npmRegistryArg: NpmRegistry,
|
npmRegistryArg: NpmRegistry,
|
||||||
fullMetadata: plugins.packageJson.FullMetadata
|
fullMetadataArg: plugins.packageJson.FullMetadata,
|
||||||
|
versionsDataArg: {
|
||||||
|
name: string;
|
||||||
|
'dist-tags': { [key: string]: string };
|
||||||
|
versions: { [key: string]: IVersionData };
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
const npmPackage = new NpmPackage(npmRegistryArg);
|
const npmPackage = new NpmPackage(npmRegistryArg);
|
||||||
Object.assign(npmPackage, fullMetadata);
|
Object.assign(npmPackage, fullMetadataArg);
|
||||||
|
npmPackage.allVersions = [];
|
||||||
|
npmPackage.allDistTags = [];
|
||||||
|
for (const versionArg of Object.keys(versionsDataArg.versions)) {
|
||||||
|
const packageVersion = PackageVersion.createFromVersionData(
|
||||||
|
versionsDataArg.versions[versionArg]
|
||||||
|
);
|
||||||
|
npmPackage.allVersions.push(packageVersion);
|
||||||
|
}
|
||||||
|
for (const distTagArg of Object.keys(versionsDataArg['dist-tags'])) {
|
||||||
|
const packageDistTag = new PackageDisttag(
|
||||||
|
distTagArg,
|
||||||
|
versionsDataArg['dist-tags'][distTagArg]
|
||||||
|
);
|
||||||
|
npmPackage.allDistTags.push(packageDistTag);
|
||||||
|
}
|
||||||
return npmPackage;
|
return npmPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,6 +37,8 @@ export class NpmPackage {
|
|||||||
public name: string = null;
|
public name: string = null;
|
||||||
public scope: string = null;
|
public scope: string = null;
|
||||||
public version: string = null;
|
public version: string = null;
|
||||||
|
public allVersions: PackageVersion[];
|
||||||
|
public allDistTags: PackageDisttag[];
|
||||||
public description: string = null;
|
public description: string = null;
|
||||||
public keywords: string[] = null;
|
public keywords: string[] = null;
|
||||||
public date: string;
|
public date: string;
|
||||||
@ -48,9 +72,9 @@ export class NpmPackage {
|
|||||||
} = null;
|
} = null;
|
||||||
public searchScore: number = null;
|
public searchScore: number = null;
|
||||||
|
|
||||||
public npmRegistry: NpmRegistry;
|
public npmRegistryRef: NpmRegistry;
|
||||||
constructor(npmRegistryArg: NpmRegistry) {
|
constructor(npmRegistryArg: NpmRegistry) {
|
||||||
this.npmRegistry = npmRegistryArg;
|
this.npmRegistryRef = npmRegistryArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,6 +82,106 @@ export class NpmPackage {
|
|||||||
*/
|
*/
|
||||||
public async saveToDisk(targetDir: string) {
|
public async saveToDisk(targetDir: string) {
|
||||||
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
|
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
|
||||||
await smartarchiveInstance.extractArchiveFromUrl(this.dist.tarball, targetDir);
|
await smartarchiveInstance.extractArchiveFromUrlToFs(this.dist.tarball, targetDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saves the complete package to cache
|
||||||
|
*/
|
||||||
|
public async saveToCache() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get files from package
|
||||||
|
*/
|
||||||
|
public async getFilesFromPackage(
|
||||||
|
filePath: string,
|
||||||
|
optionsArg: {
|
||||||
|
distTag?: string;
|
||||||
|
version?: string;
|
||||||
|
},
|
||||||
|
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?.version || optionsArg?.distTag) {
|
||||||
|
if (optionsArg.distTag && optionsArg.version) {
|
||||||
|
throw new Error('Please either specify version OR disttag, not both.');
|
||||||
|
}
|
||||||
|
let targetVersionString: string;
|
||||||
|
if (optionsArg.distTag) {
|
||||||
|
const targetDistTag = this.allDistTags.find((distTag) => {
|
||||||
|
return distTag.name === optionsArg.distTag;
|
||||||
|
});
|
||||||
|
if (targetDistTag) {
|
||||||
|
targetVersionString = targetDistTag.targetVersion;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
targetVersionString = optionsArg.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
// lets find the best matching release
|
||||||
|
const bestMatchingVersion = this.getBestMatchingVersion(targetVersionString);
|
||||||
|
if (!bestMatchingVersion) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
tarballUrl = this.allVersions.find(
|
||||||
|
(packageVersion) => packageVersion.version === bestMatchingVersion
|
||||||
|
).dist.tarball;
|
||||||
|
}
|
||||||
|
const fileObservable = await smartarchiveInstance.extractArchiveFromUrlToObservable(tarballUrl);
|
||||||
|
const wantedFilePath = plugins.path.join('package', filePath);
|
||||||
|
const allMatchingFiles: plugins.smartfile.Smartfile[] = [];
|
||||||
|
const subscription = fileObservable.subscribe(
|
||||||
|
(fileArg) => {
|
||||||
|
// returnOnFirstArg requires exact match
|
||||||
|
if (returnOnFirstArg && fileArg.path === wantedFilePath) {
|
||||||
|
// lets resolve with the wanted file
|
||||||
|
done.resolve([fileArg]);
|
||||||
|
subscription.unsubscribe();
|
||||||
|
} else if (!returnOnFirstArg && fileArg.path.startsWith(wantedFilePath)) {
|
||||||
|
allMatchingFiles.push(fileArg);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
console.log(err);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
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] || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import * as plugins from './smartnpm.plugins';
|
import * as plugins from './smartnpm.plugins.js';
|
||||||
import * as paths from './smartnpm.paths';
|
import * as paths from './smartnpm.paths.js';
|
||||||
|
|
||||||
// interfaces
|
// interfaces
|
||||||
import { ISearchObject } from './smartnpm.interfaces';
|
import { type ISearchObject } from './smartnpm.interfaces.js';
|
||||||
|
|
||||||
// classes
|
// classes
|
||||||
import { NpmPackage } from './smartnpm.classes.npmpackage';
|
import { NpmPackage } from './smartnpm.classes.npmpackage.js';
|
||||||
|
import { type ICacheDescriptor, RegistryCache } from './smartnpm.classes.registrycache.js';
|
||||||
|
|
||||||
export interface INpmRegistryConstructorOptions {
|
export interface INpmRegistryConstructorOptions {
|
||||||
npmRegistryUrl?: string;
|
npmRegistryUrl?: string;
|
||||||
@ -13,17 +14,18 @@ export interface INpmRegistryConstructorOptions {
|
|||||||
|
|
||||||
export class NpmRegistry {
|
export class NpmRegistry {
|
||||||
public options: INpmRegistryConstructorOptions;
|
public options: INpmRegistryConstructorOptions;
|
||||||
public registry: string;
|
public registryCache: RegistryCache;
|
||||||
private searchDomain = 'https://api.npms.io/v2/search?q=';
|
private searchDomain = 'https://api.npms.io/v2/search?q=';
|
||||||
|
|
||||||
constructor(optionsArg: INpmRegistryConstructorOptions = {}) {
|
constructor(optionsArg: INpmRegistryConstructorOptions = {}) {
|
||||||
const defaultOptions: INpmRegistryConstructorOptions = {
|
const defaultOptions: INpmRegistryConstructorOptions = {
|
||||||
npmRegistryUrl: 'https://registry.npmjs.org'
|
npmRegistryUrl: 'https://registry.npmjs.org',
|
||||||
};
|
};
|
||||||
this.options = {
|
this.options = {
|
||||||
...defaultOptions,
|
...defaultOptions,
|
||||||
...optionsArg
|
...optionsArg,
|
||||||
};
|
};
|
||||||
|
this.registryCache = new RegistryCache(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,11 +33,24 @@ export class NpmRegistry {
|
|||||||
* @param packageName
|
* @param packageName
|
||||||
*/
|
*/
|
||||||
public async getPackageInfo(packageName: string): Promise<NpmPackage> {
|
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,
|
registryUrl: this.options.npmRegistryUrl,
|
||||||
fullMetadata: true
|
allVersions: true,
|
||||||
});
|
});
|
||||||
const npmPackage = await NpmPackage.createFromFullMetadata(this, fullMetadata);
|
const npmPackage = await NpmPackage.createFromFullMetadataAndVersionData(
|
||||||
|
this,
|
||||||
|
fullMetadata,
|
||||||
|
versionData as any
|
||||||
|
);
|
||||||
return npmPackage;
|
return npmPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +60,7 @@ export class NpmRegistry {
|
|||||||
* @param targetDir
|
* @param targetDir
|
||||||
*/
|
*/
|
||||||
public async savePackageToDisk(packageName: string, targetDir: string): Promise<void> {
|
public async savePackageToDisk(packageName: string, targetDir: string): Promise<void> {
|
||||||
|
plugins.smartfile.fs.ensureDirSync(paths.nogitDir);
|
||||||
const npmPackage = await this.getPackageInfo(packageName);
|
const npmPackage = await this.getPackageInfo(packageName);
|
||||||
await npmPackage.saveToDisk(targetDir);
|
await npmPackage.saveToDisk(targetDir);
|
||||||
}
|
}
|
||||||
@ -52,15 +68,85 @@ export class NpmRegistry {
|
|||||||
/**
|
/**
|
||||||
* gets a file from a package as Smartfile
|
* gets a file from a package as Smartfile
|
||||||
*/
|
*/
|
||||||
public async getFileFromPackage(packageName: string, filePath: string) {
|
public async getFileFromPackage(
|
||||||
const baseDir = plugins.path.join(paths.nogitDir, packageName.replace('/', '__'));
|
packageNameArg: string,
|
||||||
await plugins.smartfile.fs.ensureDir(baseDir);
|
filePathArg: string,
|
||||||
await this.savePackageToDisk(packageName, baseDir);
|
optionsArg?: {
|
||||||
const smartfile = await plugins.smartfile.Smartfile.fromFilePath(
|
distTag?: string;
|
||||||
plugins.path.join(baseDir, 'package', filePath)
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
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);
|
||||||
|
if (fileResult) {
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
const baseDir = plugins.path.join(paths.nogitDir, packageNameArg.replace('/', '__'));
|
||||||
|
await plugins.smartfile.fs.ensureDir(baseDir);
|
||||||
|
await this.savePackageToDisk(packageNameArg, baseDir);
|
||||||
|
const virtualDir = await plugins.smartfile.VirtualDirectory.fromFsDirPath(baseDir);
|
||||||
await plugins.smartfile.fs.remove(baseDir);
|
await plugins.smartfile.fs.remove(baseDir);
|
||||||
return smartfile;
|
return virtualDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,9 +220,8 @@ export class NpmRegistry {
|
|||||||
addToSearchString(`author:${searchObjectArg.maintenanceWeight}`);
|
addToSearchString(`author:${searchObjectArg.maintenanceWeight}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins.smartlog.defaultLogger.log(
|
console.log(
|
||||||
'info',
|
`info: Search on npm for ${plugins.consolecolor.coloredString(searchString, 'pink')}`
|
||||||
`Search on npm for ${plugins.consolecolor.coloredString(searchString, 'pink')}`
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let body: any;
|
let body: any;
|
||||||
|
11
ts/smartnpm.classes.packagedisttag.ts
Normal file
11
ts/smartnpm.classes.packagedisttag.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import * as plugins from './smartnpm.plugins.js';
|
||||||
|
|
||||||
|
export class PackageDisttag {
|
||||||
|
name: string;
|
||||||
|
targetVersion: string;
|
||||||
|
|
||||||
|
constructor(nameArg: string, targetVersionArg: string) {
|
||||||
|
this.name = nameArg;
|
||||||
|
this.targetVersion = targetVersionArg;
|
||||||
|
}
|
||||||
|
}
|
31
ts/smartnpm.classes.packageversion.ts
Normal file
31
ts/smartnpm.classes.packageversion.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import * as plugins from './smartnpm.plugins.js';
|
||||||
|
|
||||||
|
export interface IVersionData {
|
||||||
|
name: string;
|
||||||
|
version: string;
|
||||||
|
dependencies: { [key: string]: string };
|
||||||
|
devDependencies: { [key: string]: string };
|
||||||
|
dist: {
|
||||||
|
integrity: string;
|
||||||
|
shasum: string;
|
||||||
|
tarball: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export class PackageVersion implements IVersionData {
|
||||||
|
public static createFromVersionData(versionDataArg: IVersionData) {
|
||||||
|
const packageVersion = new PackageVersion();
|
||||||
|
Object.assign(packageVersion, versionDataArg);
|
||||||
|
return packageVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
name: string;
|
||||||
|
version: string;
|
||||||
|
dependencies: { [key: string]: string };
|
||||||
|
devDependencies: { [key: string]: string };
|
||||||
|
dist: {
|
||||||
|
integrity: string;
|
||||||
|
shasum: string;
|
||||||
|
tarball: string;
|
||||||
|
};
|
||||||
|
}
|
63
ts/smartnpm.classes.registrycache.ts
Normal file
63
ts/smartnpm.classes.registrycache.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import { NpmRegistry } from './smartnpm.classes.npmregistry.js';
|
||||||
|
import * as plugins from './smartnpm.plugins.js';
|
||||||
|
|
||||||
|
export interface ICacheDescriptor {
|
||||||
|
registryUrl: string;
|
||||||
|
packageName: string;
|
||||||
|
filePath: string;
|
||||||
|
distTag?: string;
|
||||||
|
version?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class RegistryCache {
|
||||||
|
npmregistryRef: NpmRegistry;
|
||||||
|
public levelCache: plugins.levelcache.LevelCache;
|
||||||
|
|
||||||
|
constructor(npmRegistryRefArg: NpmRegistry) {
|
||||||
|
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)
|
||||||
|
);
|
||||||
|
if (cacheEntry) {
|
||||||
|
return plugins.smartfile.Smartfile.fromFoldedJson(cacheEntry.contents.toString());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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}`;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
import * as plugins from './smartnpm.plugins';
|
import * as plugins from './smartnpm.plugins.js';
|
||||||
|
|
||||||
export const packageDir = plugins.path.join(__dirname, '../');
|
export const packageDir = plugins.path.join(
|
||||||
|
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||||
|
'../'
|
||||||
|
);
|
||||||
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
|
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
|
||||||
plugins.smartfile.fs.ensureDirSync(nogitDir);
|
|
||||||
|
@ -4,16 +4,29 @@ import * as path from 'path';
|
|||||||
export { path };
|
export { path };
|
||||||
|
|
||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as consolecolor from '@pushrocks/consolecolor';
|
import * as consolecolor from '@push.rocks/consolecolor';
|
||||||
import * as smartarchive from '@pushrocks/smartarchive';
|
import * as levelcache from '@push.rocks/levelcache';
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartarchive from '@push.rocks/smartarchive';
|
||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartfile from '@push.rocks/smartfile';
|
||||||
smartlog.defaultLogger.enableConsole();
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
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, smartarchive, smartfile, smartlog, smartrequest };
|
export {
|
||||||
|
consolecolor,
|
||||||
|
levelcache,
|
||||||
|
smartarchive,
|
||||||
|
smartfile,
|
||||||
|
smartpath,
|
||||||
|
smartpromise,
|
||||||
|
smartrequest,
|
||||||
|
smartversion,
|
||||||
|
smarttime,
|
||||||
|
};
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import packageJson from 'package-json';
|
import * as packageJson from 'package-json';
|
||||||
|
|
||||||
export { packageJson };
|
export { packageJson };
|
||||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user