swh-loader-npm
Software Heritage loader to ingest npm packages into the archive.
What does the loader do?
The npm loader visits and loads a npm package [1].
Each visit will result in:
- 1 snapshot (which targets n revisions ; 1 per package release version)
- 1 revision (which targets 1 directory ; the package release version uncompressed)
[1] https://docs.npmjs.com/about-packages-and-modules
First visit
Given a npm package (origin), the loader, for the first visit:
- retrieves information for the given package (notably released versions)
- then for each associated released version:
- retrieves the associated tarball (with checks)
- uncompresses locally the archive
- computes the hashes of the uncompressed directory
- then creates a revision (using
package.jsonmetadata file) targeting such directory
- finally, creates a snapshot targeting all seen revisions (uncompressed npm package released versions and metadata).
Next visit
The loader starts by checking if something changed since the last visit. If nothing changed, the visit's snapshot is left unchanged. The new visit targets the same snapshot.
If something changed, the already seen package release versions are skipped. Only the new ones are loaded. In the end, the loader creates a new snapshot based on the previous one. Thus, the new snapshot targets both the old and new package release versions.
Development
Configuration file
Location
Either:
/etc/softwareheritage/loader/npm.yml~/.config/swh/loader/npm.yml
Configuration sample
storage:
cls: remote
args:
url: http://localhost:5002/
debug: false
Local run
The built-in command-line will run the loader for a specified npm package.
For instance, to load jquery:
$ python3 -m swh.loader.npm.loader jquery
If you need more control, you can use the loader directly. It expects three arguments:
package_name(required): a npm package namepackage_url(optional): URL of the npm package description (human-readable html page) that will be used as the associated origin URL in the archiveproject_metadata_url(optional): URL of the npm package metadata information (machine-parsable JSON document)
import logging
from urllib.parse import quote
from swh.loader.npm.loader import NpmLoader
logging.basicConfig(level=logging.DEBUG)
package_name='webpack'
NpmLoader().load(package_name,
'https://www.npmjs.com/package/%s/' % package_name,
'https://replicate.npmjs.com/%s/' % quote(package_name, safe=''))
Release files for swh.loader.npm 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| swh.loader.npm-0.0.7.tar.gz | 164.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| swh.loader.npm-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 349.8 kB
Release files / swh.loader.npm-0.0.7.tar.gz
| Download URL | swh.loader.npm-0.0.7.tar.gz |
|---|---|
| Size | 164.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d9ab82a26d33be5cd2ac672e4b759c598c2d456af25ad6a98839ee74b333c4d
|
|
BLAKE2b-256 checksum How to use checksums |
46c9bd1492a819f69476fef211c293c720511395db83071a9b77870ad82423d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.3
|
Release files / swh.loader.npm-0.0.7-py3-none-any.whl
| Download URL | swh.loader.npm-0.0.7-py3-none-any.whl |
|---|---|
| Size | 185.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6e86879a8fc8fa6ba38bc618e485914495fe60cdd83696281b04bdaa1dcb3037
|
|
BLAKE2b-256 checksum How to use checksums |
662fe6aae974fbf5a2bcae27110b4dfb0e055c6280750135a5b949abba8c3679
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.3
|