@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.
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartnpm',
6
- version: '2.0.5',
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@push.rocks/smartnpm",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "private": false,
5
5
  "description": "A library to interface with npm for retrieving package information and manipulation.",
6
6
  "main": "dist_ts/index.js",
package/readme.md CHANGED
@@ -1,93 +1,337 @@
1
1
  # @push.rocks/smartnpm
2
- interface with npm to retrieve package information
2
+ **Smart npm interface for Node.js 🚀**
3
3
 
4
- ## Install
5
- To install `@push.rocks/smartnpm`, open your terminal and run the following command:
6
- ```sh
4
+ [![npm](https://img.shields.io/npm/v/@push.rocks/smartnpm.svg)](https://www.npmjs.com/package/@push.rocks/smartnpm)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-4.x-blue.svg)](https://www.typescriptlang.org/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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
- ## Usage
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
- ### Initialize the NpmRegistry
15
- 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.
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
- Optionally, you can provide a custom npm registry URL if you're not using the default npm registry:
24
-
25
- ```typescript
41
+ // Or use a custom registry
26
42
  const customRegistry = new NpmRegistry({
27
- npmRegistryUrl: 'https://custom.registry.url'
43
+ npmRegistryUrl: 'https://your-registry.example.com'
28
44
  });
29
45
  ```
30
46
 
31
- ### Retrieve Package Information
32
- `@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:
47
+ ## 📘 Usage Examples
48
+
49
+ ### Package Information Retrieval
50
+
51
+ Get detailed information about any npm package:
33
52
 
34
53
  ```typescript
35
- async function getPackageInfo() {
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
- getPackageInfo();
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
- ### Search for Packages
45
- 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:
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
- keywords: ['webpack-plugin'],
51
- author: 'webpack'
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
- ### Downloading Packages
60
- `@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.
113
+ ### 💾 Download Packages
114
+
115
+ Download and extract npm packages to your filesystem:
61
116
 
62
117
  ```typescript
63
118
  async function downloadPackage() {
64
- const packageName = 'some-package';
65
- const targetDirectory = './path/to/targetDir';
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
- await npmRegistry.savePackageToDisk(packageName, targetDirectory);
68
- console.log(`${packageName} has been downloaded to ${targetDirectory}`);
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
- downloadPackage();
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
- ### Working with Package Versions and Dist Tags
75
- 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.
195
+ ### 🗂️ Virtual Directory
196
+
197
+ Load packages as virtual file systems in memory:
76
198
 
77
199
  ```typescript
78
- async function getPackageVersionDetails() {
79
- const packageName = 'some-package';
80
- const version = '1.0.0'; // You can also use dist tags like 'latest'
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
- const packageInfo = await npmRegistry.getPackageInfo(packageName);
83
- const versionInfo = packageInfo.allVersions.find(v => v.version === version);
84
- console.log(versionInfo);
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
- getPackageVersionDetails();
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
- 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.
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.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartnpm',
6
- version: '2.0.5',
6
+ version: '2.0.6',
7
7
  description: 'A library to interface with npm for retrieving package information and manipulation.'
8
8
  }