@glpkg/fallback
v0.1.0
Published
Fallback registry resolver for GitLab Package Manager
Downloads
45
Maintainers
Readme
@glpkg/fallback
Local cache fallback for GitLab Package Manager.
Provides local package caching for:
- Offline access: Use cached packages when GitLab is unavailable
- Immediate install after publish: No need to wait for GitLab indexing
Installation
npm install @glpkg/fallbackUsage
Install Flow
- Try to fetch package from GitLab registry
- On failure (404, timeout, etc.) → check local cache
- Cache hit → use cached package
- Cache miss → error
import { createFallbackResolver } from '@glpkg/fallback';
const resolver = createFallbackResolver({
host: 'gitlab.example.com',
token: process.env.GITLAB_TOKEN,
projectId: 123,
groupId: 456,
});
// Resolve tarball with local cache fallback
const result = await resolver.resolveTarball(
{ name: '@scope/package', version: '1.0.0' },
adapter,
'project-first'
);
if (result.success) {
console.log(`Tarball from ${result.source}: ${result.tarballPath}`);
} else {
console.error(`Failed: ${result.error}`);
}Publish Flow
- Upload to GitLab
- Simultaneously save to local cache
- Other projects can install immediately (no GitLab indexing wait)
// After successful GitLab publish
await resolver.cacheForPublish(
'@scope/package',
'1.0.0',
'/path/to/package.tgz',
'sha512-...'
);
// Now other local projects can install immediately
// even before GitLab indexes the packageAPI
FallbackResolver
Resolves packages from GitLab with local cache fallback.
const resolver = createFallbackResolver({
host: 'gitlab.example.com',
token: 'your-token',
projectId: 123, // Optional
groupId: 456, // Optional
timeout: 30000, // Optional, default: 30s
localCacheConfig: { // Optional
cacheDir: '~/.cache/glpkg/packages'
}
});
// Get metadata from GitLab (no local cache for metadata)
const metadata = await resolver.resolve(pkg, adapter, 'project-first');
// Get tarball with local cache fallback
const tarball = await resolver.resolveTarball(pkg, adapter, 'project-first');
// Cache tarball during publish
await resolver.cacheForPublish(name, version, tarballPath, shasum);
// Access local cache directly
const cache = resolver.getLocalCache();LocalPackageCache
File system based package tarball cache.
import { createLocalPackageCache } from '@glpkg/fallback';
const cache = createLocalPackageCache({
cacheDir: '~/.cache/glpkg/packages' // Optional, this is the default
});
// Save a tarball
await cache.save('@scope/pkg', '1.0.0', '/path/to/package.tgz');
// Save from buffer
await cache.saveFromBuffer('@scope/pkg', '1.0.0', buffer, 'sha512');
// Get cached tarball path
const path = await cache.get('@scope/pkg', '1.0.0');
// Check if cached
const exists = await cache.has('@scope/pkg', '1.0.0');
// List cached versions
const versions = await cache.list('@scope/pkg');
// Delete specific version
await cache.delete('@scope/pkg', '1.0.0');
// Cleanup old packages (default: older than 30 days)
const removed = await cache.cleanup(new Date('2024-01-01'));
// Get cache statistics
const stats = await cache.getStats();
// Clear entire cache
await cache.clear();CacheManager (Memory Cache)
In-memory cache for metadata (unchanged from before).
import { createCacheManager } from '@glpkg/fallback';
const cache = createCacheManager(300000); // 5 min TTL
cache.set('key', data);
const cached = cache.get('key');Cache Structure
~/.cache/glpkg/packages/
├── @scope/
│ └── package-name/
│ ├── 1.0.0/
│ │ ├── package.tgz
│ │ └── metadata.json
│ └── 2.0.0/
│ ├── package.tgz
│ └── metadata.json
└── unscoped-package/
└── 1.0.0/
├── package.tgz
└── metadata.jsonFallback Strategies
project-first: Try project registry first, fallback to groupgroup-first: Try group registry first, fallback to projectproject-only: Only use project registrygroup-only: Only use group registryfastest: Race both registries, return first success
Types
FallbackResolverConfig- Resolver configurationLocalPackageCacheConfig- Cache configurationCacheMetadata- Metadata stored with cached tarballsLocalCacheEntry- Cache entry with path and metadataTarballResolveResult- Result from resolveTarballHealthCheckResult- Registry health check result
License
MIT
