@push.rocks/smartnpm 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/package.json +1 -1
- package/readme.md +291 -47
- package/ts/00_commitinfo_data.ts +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartnpm',
|
|
6
|
-
version: '2.0.
|
|
6
|
+
version: '2.0.6',
|
|
7
7
|
description: 'A library to interface with npm for retrieving package information and manipulation.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSxzQkFBc0I7SUFDNUIsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLHNGQUFzRjtDQUNwRyxDQUFBIn0=
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,93 +1,337 @@
|
|
|
1
1
|
# @push.rocks/smartnpm
|
|
2
|
-
|
|
2
|
+
**Smart npm interface for Node.js 🚀**
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
[](https://www.npmjs.com/package/@push.rocks/smartnpm)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
> A powerful TypeScript library to programmatically interact with npm registries, retrieve package information, search packages, and handle package downloads with full caching support.
|
|
9
|
+
|
|
10
|
+
## 🎯 Features
|
|
11
|
+
|
|
12
|
+
- 📦 **Package Information Retrieval** - Get comprehensive metadata about any npm package
|
|
13
|
+
- 🔍 **Advanced Package Search** - Search npm registry with multiple filter options
|
|
14
|
+
- 💾 **Package Downloads** - Download and extract packages to disk programmatically
|
|
15
|
+
- 📁 **File Extraction** - Extract specific files or directories from packages without full download
|
|
16
|
+
- 🏷️ **Version & Tag Management** - Work with specific versions, dist-tags, and version ranges
|
|
17
|
+
- ⚡ **Smart Caching** - Built-in caching system for improved performance
|
|
18
|
+
- 🌐 **Custom Registry Support** - Use with npm, Verdaccio, or any npm-compatible registry
|
|
19
|
+
- 🗂️ **Virtual Directory Creation** - Load packages as virtual file systems in memory
|
|
20
|
+
|
|
21
|
+
## 📥 Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
7
24
|
npm install @push.rocks/smartnpm --save
|
|
8
25
|
```
|
|
9
|
-
This will add `@push.rocks/smartnpm` as a dependency to your project and you're ready to start using it.
|
|
10
26
|
|
|
11
|
-
|
|
12
|
-
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.
|
|
27
|
+
Or using pnpm (recommended):
|
|
13
28
|
|
|
14
|
-
|
|
15
|
-
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add @push.rocks/smartnpm
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 🚀 Quick Start
|
|
16
34
|
|
|
17
35
|
```typescript
|
|
18
36
|
import { NpmRegistry } from '@push.rocks/smartnpm';
|
|
19
37
|
|
|
38
|
+
// Initialize with default npm registry
|
|
20
39
|
const npmRegistry = new NpmRegistry();
|
|
21
|
-
```
|
|
22
40
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
41
|
+
// Or use a custom registry
|
|
26
42
|
const customRegistry = new NpmRegistry({
|
|
27
|
-
npmRegistryUrl: 'https://
|
|
43
|
+
npmRegistryUrl: 'https://your-registry.example.com'
|
|
28
44
|
});
|
|
29
45
|
```
|
|
30
46
|
|
|
31
|
-
|
|
32
|
-
|
|
47
|
+
## 📘 Usage Examples
|
|
48
|
+
|
|
49
|
+
### Package Information Retrieval
|
|
50
|
+
|
|
51
|
+
Get detailed information about any npm package:
|
|
33
52
|
|
|
34
53
|
```typescript
|
|
35
|
-
|
|
36
|
-
const packageName = 'your-package-name';
|
|
37
|
-
const packageInfo = await npmRegistry.getPackageInfo(packageName);
|
|
38
|
-
console.log(packageInfo);
|
|
39
|
-
}
|
|
54
|
+
import { NpmRegistry } from '@push.rocks/smartnpm';
|
|
40
55
|
|
|
41
|
-
|
|
56
|
+
const npmRegistry = new NpmRegistry();
|
|
57
|
+
|
|
58
|
+
async function getPackageDetails() {
|
|
59
|
+
const packageInfo = await npmRegistry.getPackageInfo('@angular/core');
|
|
60
|
+
|
|
61
|
+
console.log(`Package: ${packageInfo.name}`);
|
|
62
|
+
console.log(`Latest Version: ${packageInfo.version}`);
|
|
63
|
+
console.log(`Description: ${packageInfo.description}`);
|
|
64
|
+
console.log(`License: ${packageInfo.license}`);
|
|
65
|
+
|
|
66
|
+
// Access all versions
|
|
67
|
+
packageInfo.allVersions.forEach(version => {
|
|
68
|
+
console.log(`- ${version.version}: ${version.date}`);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Access dist tags
|
|
72
|
+
packageInfo.allDistTags.forEach(tag => {
|
|
73
|
+
console.log(`Tag ${tag.name}: ${tag.targetVersion}`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
42
76
|
```
|
|
43
77
|
|
|
44
|
-
###
|
|
45
|
-
|
|
78
|
+
### 🔍 Advanced Package Search
|
|
79
|
+
|
|
80
|
+
Search the npm registry with powerful filters:
|
|
46
81
|
|
|
47
82
|
```typescript
|
|
48
83
|
async function searchPackages() {
|
|
84
|
+
// Search with multiple criteria
|
|
49
85
|
const searchResults = await npmRegistry.searchOnNpm({
|
|
50
|
-
|
|
51
|
-
|
|
86
|
+
name: 'webpack-plugin',
|
|
87
|
+
keywords: ['webpack', 'plugin', 'build'],
|
|
88
|
+
author: 'webpack-contrib',
|
|
89
|
+
maintainer: 'sokra',
|
|
90
|
+
scope: '@webpack',
|
|
91
|
+
deprecated: false,
|
|
92
|
+
unstable: false,
|
|
93
|
+
insecure: false,
|
|
94
|
+
boostExact: true,
|
|
95
|
+
scoreEffect: 15.3,
|
|
96
|
+
qualityWeight: 1.95,
|
|
97
|
+
popularityWeight: 3.3,
|
|
98
|
+
maintenanceWeight: 2.05
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
console.log(`Found ${searchResults.length} packages`);
|
|
102
|
+
|
|
103
|
+
searchResults.forEach(pkg => {
|
|
104
|
+
console.log(`📦 ${pkg.name}@${pkg.version}`);
|
|
105
|
+
console.log(` Score: ${pkg.searchScore}`);
|
|
106
|
+
console.log(` Quality: ${pkg.score.detail.quality}`);
|
|
107
|
+
console.log(` Popularity: ${pkg.score.detail.popularity}`);
|
|
108
|
+
console.log(` Maintenance: ${pkg.score.detail.maintenance}`);
|
|
52
109
|
});
|
|
53
|
-
console.log(searchResults);
|
|
54
110
|
}
|
|
55
|
-
|
|
56
|
-
searchPackages();
|
|
57
111
|
```
|
|
58
112
|
|
|
59
|
-
###
|
|
60
|
-
|
|
113
|
+
### 💾 Download Packages
|
|
114
|
+
|
|
115
|
+
Download and extract npm packages to your filesystem:
|
|
61
116
|
|
|
62
117
|
```typescript
|
|
63
118
|
async function downloadPackage() {
|
|
64
|
-
|
|
65
|
-
|
|
119
|
+
// Download latest version
|
|
120
|
+
await npmRegistry.savePackageToDisk('express', './downloads/express');
|
|
121
|
+
|
|
122
|
+
// Download specific version
|
|
123
|
+
const packageInfo = await npmRegistry.getPackageInfo('express');
|
|
124
|
+
const specificVersion = packageInfo.allVersions.find(v => v.version === '4.18.0');
|
|
125
|
+
if (specificVersion) {
|
|
126
|
+
await specificVersion.saveToDisk('./downloads/express-4.18.0');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 📁 Extract Specific Files
|
|
132
|
+
|
|
133
|
+
Extract individual files or directories from packages without downloading the entire package:
|
|
66
134
|
|
|
67
|
-
|
|
68
|
-
|
|
135
|
+
```typescript
|
|
136
|
+
async function extractSpecificFiles() {
|
|
137
|
+
// Get a single file
|
|
138
|
+
const readmeFile = await npmRegistry.getFileFromPackage(
|
|
139
|
+
'typescript',
|
|
140
|
+
'README.md'
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
if (readmeFile) {
|
|
144
|
+
console.log('README Contents:', readmeFile.contentBuffer.toString());
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Get a file from specific version
|
|
148
|
+
const packageJson = await npmRegistry.getFileFromPackage(
|
|
149
|
+
'react',
|
|
150
|
+
'package.json',
|
|
151
|
+
{ version: '18.0.0' }
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
// Get all files from a directory
|
|
155
|
+
const sourceFiles = await npmRegistry.getFilesFromPackage(
|
|
156
|
+
'@angular/core',
|
|
157
|
+
'src/',
|
|
158
|
+
{ distTag: 'latest' }
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
sourceFiles.forEach(file => {
|
|
162
|
+
console.log(`📄 ${file.path} (${file.contentBuffer.length} bytes)`);
|
|
163
|
+
});
|
|
69
164
|
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### 🏷️ Version Management
|
|
168
|
+
|
|
169
|
+
Work with specific versions and dist tags:
|
|
70
170
|
|
|
71
|
-
|
|
171
|
+
```typescript
|
|
172
|
+
async function versionManagement() {
|
|
173
|
+
const pkg = await npmRegistry.getPackageInfo('vue');
|
|
174
|
+
|
|
175
|
+
// Get best matching version for a range
|
|
176
|
+
const bestVersion = pkg.getBestMatchingVersion('^3.0.0');
|
|
177
|
+
console.log(`Best matching version: ${bestVersion}`);
|
|
178
|
+
|
|
179
|
+
// Work with dist tags
|
|
180
|
+
const latestTag = pkg.allDistTags.find(t => t.name === 'latest');
|
|
181
|
+
const nextTag = pkg.allDistTags.find(t => t.name === 'next');
|
|
182
|
+
|
|
183
|
+
console.log(`Latest: ${latestTag?.targetVersion}`);
|
|
184
|
+
console.log(`Next: ${nextTag?.targetVersion}`);
|
|
185
|
+
|
|
186
|
+
// Get files from specific dist tag
|
|
187
|
+
const files = await npmRegistry.getFilesFromPackage(
|
|
188
|
+
'vue',
|
|
189
|
+
'dist/',
|
|
190
|
+
{ distTag: 'next' }
|
|
191
|
+
);
|
|
192
|
+
}
|
|
72
193
|
```
|
|
73
194
|
|
|
74
|
-
###
|
|
75
|
-
|
|
195
|
+
### 🗂️ Virtual Directory
|
|
196
|
+
|
|
197
|
+
Load packages as virtual file systems in memory:
|
|
76
198
|
|
|
77
199
|
```typescript
|
|
78
|
-
async function
|
|
79
|
-
|
|
80
|
-
const
|
|
200
|
+
async function virtualDirectory() {
|
|
201
|
+
// Create virtual directory from package
|
|
202
|
+
const virtualDir = await npmRegistry.getPackageAsSmartfileVirtualDir('@angular/cli');
|
|
203
|
+
|
|
204
|
+
// Work with files in memory
|
|
205
|
+
const allFiles = virtualDir.getFileArray();
|
|
206
|
+
|
|
207
|
+
allFiles.forEach(file => {
|
|
208
|
+
console.log(`Virtual file: ${file.path}`);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Export virtual directory to disk if needed
|
|
212
|
+
await virtualDir.saveToDisk('./output/angular-cli');
|
|
213
|
+
}
|
|
214
|
+
```
|
|
81
215
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
216
|
+
### ⚡ Caching
|
|
217
|
+
|
|
218
|
+
The library includes built-in intelligent caching:
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
// Files are automatically cached
|
|
222
|
+
const file1 = await npmRegistry.getFileFromPackage('lodash', 'package.json');
|
|
223
|
+
// This will be served from cache
|
|
224
|
+
const file2 = await npmRegistry.getFileFromPackage('lodash', 'package.json');
|
|
225
|
+
|
|
226
|
+
// Cache is registry-specific and version-aware
|
|
227
|
+
const specificVersion = await npmRegistry.getFileFromPackage(
|
|
228
|
+
'lodash',
|
|
229
|
+
'README.md',
|
|
230
|
+
{ version: '4.17.21' }
|
|
231
|
+
);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## 🏗️ API Reference
|
|
235
|
+
|
|
236
|
+
### NpmRegistry Class
|
|
237
|
+
|
|
238
|
+
#### Constructor
|
|
239
|
+
```typescript
|
|
240
|
+
new NpmRegistry(options?: INpmRegistryConstructorOptions)
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Options:
|
|
244
|
+
- `npmRegistryUrl`: Custom registry URL (default: `https://registry.npmjs.org`)
|
|
245
|
+
|
|
246
|
+
#### Methods
|
|
247
|
+
|
|
248
|
+
##### `getPackageInfo(packageName: string): Promise<NpmPackage>`
|
|
249
|
+
Retrieves comprehensive information about a package.
|
|
250
|
+
|
|
251
|
+
##### `searchOnNpm(searchObject: ISearchObject): Promise<NpmPackage[]>`
|
|
252
|
+
Searches the npm registry with advanced filters.
|
|
253
|
+
|
|
254
|
+
##### `savePackageToDisk(packageName: string, targetDir: string): Promise<void>`
|
|
255
|
+
Downloads and extracts a package to the filesystem.
|
|
256
|
+
|
|
257
|
+
##### `getFileFromPackage(packageName: string, filePath: string, options?): Promise<SmartFile>`
|
|
258
|
+
Extracts a single file from a package.
|
|
259
|
+
|
|
260
|
+
##### `getFilesFromPackage(packageName: string, filePath: string, options?): Promise<SmartFile[]>`
|
|
261
|
+
Extracts multiple files from a package directory.
|
|
262
|
+
|
|
263
|
+
##### `getPackageAsSmartfileVirtualDir(packageName: string): Promise<VirtualDirectory>`
|
|
264
|
+
Creates an in-memory virtual directory from a package.
|
|
265
|
+
|
|
266
|
+
### NpmPackage Class
|
|
267
|
+
|
|
268
|
+
#### Properties
|
|
269
|
+
- `name`: Package name
|
|
270
|
+
- `version`: Current version
|
|
271
|
+
- `description`: Package description
|
|
272
|
+
- `license`: License type
|
|
273
|
+
- `allVersions`: Array of all available versions
|
|
274
|
+
- `allDistTags`: Array of all dist tags
|
|
275
|
+
- `dependencies`: Package dependencies
|
|
276
|
+
- `keywords`: Package keywords
|
|
277
|
+
- `maintainers`: Package maintainers
|
|
278
|
+
- `dist`: Distribution information
|
|
279
|
+
|
|
280
|
+
#### Methods
|
|
281
|
+
|
|
282
|
+
##### `getBestMatchingVersion(versionRange: string): string`
|
|
283
|
+
Finds the best matching version for a semver range.
|
|
284
|
+
|
|
285
|
+
##### `saveToDisk(targetDir: string): Promise<void>`
|
|
286
|
+
Saves the package to disk.
|
|
287
|
+
|
|
288
|
+
##### `getFileFromPackage(filePath: string, options?): Promise<SmartFile>`
|
|
289
|
+
Gets a file from the package.
|
|
290
|
+
|
|
291
|
+
##### `getFilesFromPackage(filePath: string, options?): Promise<SmartFile[]>`
|
|
292
|
+
Gets multiple files from the package.
|
|
293
|
+
|
|
294
|
+
## 🔧 Advanced Configuration
|
|
295
|
+
|
|
296
|
+
### Custom Registry with Authentication
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
const privateRegistry = new NpmRegistry({
|
|
300
|
+
npmRegistryUrl: 'https://private-registry.company.com'
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
// Note: Authentication should be configured via .npmrc or npm config
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Error Handling
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
try {
|
|
310
|
+
const pkg = await npmRegistry.getPackageInfo('non-existent-package');
|
|
311
|
+
} catch (error) {
|
|
312
|
+
console.error('Package not found:', error.message);
|
|
85
313
|
}
|
|
86
314
|
|
|
87
|
-
|
|
315
|
+
// Safe file extraction
|
|
316
|
+
const file = await npmRegistry.getFileFromPackage('express', 'README.md');
|
|
317
|
+
if (file) {
|
|
318
|
+
// File exists
|
|
319
|
+
console.log('File size:', file.contentBuffer.length);
|
|
320
|
+
} else {
|
|
321
|
+
// File doesn't exist
|
|
322
|
+
console.log('File not found');
|
|
323
|
+
}
|
|
88
324
|
```
|
|
89
325
|
|
|
90
|
-
|
|
326
|
+
## 🎯 Common Use Cases
|
|
327
|
+
|
|
328
|
+
- **CI/CD Pipelines**: Automatically download and verify package contents
|
|
329
|
+
- **Security Scanning**: Extract and analyze package files without installation
|
|
330
|
+
- **Documentation Generation**: Pull README files and docs from packages
|
|
331
|
+
- **Dependency Analysis**: Analyze package structures and dependencies
|
|
332
|
+
- **Registry Mirroring**: Sync packages between registries
|
|
333
|
+
- **Package Validation**: Verify package contents before deployment
|
|
334
|
+
- **Automated Updates**: Check for new versions and update notifications
|
|
91
335
|
|
|
92
336
|
## License and Legal Information
|
|
93
337
|
|
|
@@ -106,4 +350,4 @@ Registered at District court Bremen HRB 35230 HB, Germany
|
|
|
106
350
|
|
|
107
351
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
|
108
352
|
|
|
109
|
-
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.
|
|
353
|
+
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.
|