@wener/unpkg
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

@wener/unpkg

Selfhost https://unpkg.com/ , https://cdn.jsdelivr.net/npm/ alternative

  • Handler Endpoints
    • Unpkg
      • GET /:pkg@:version - version metadata
      • GET /:pkg@:version/:file
    • NPM
      • GET /:pkg - registry index
      • GET /:pkg/:version - version metadata
      • GET /:pkg/-/:name-:version.tgz - tarball - redirect
    • [ ] SystemJS - With proper resolve, redirect js to system.ga.jspm.io or dynamic transfer with rollup/swc
      • GET /system/:pkg@:version
      • GET /system/:pkg@:version/:file
  • [ ] deploy to https://apis.wener.me/api/unpkg
    • with cloudflare cdn
    • vercel is blocked by China
  • Will resolve range/tag version to exact version
    • use 302 redirect
import { Unpkg } from '@wener/unpkg';
import { createBearerAuthFetch, createUnpkg, createUnpkgHandler } from '@wener/unpkg/server';

const unpkg = await createUnpkg({
  logger: fastify.log,
  url: process.env.UNPKG_REGISTRY,
  sqlite: {
    database: process.env.UNPKG_CACHE_DB,
  },
});
// for private npm registry
if (process.env.UNPKG_TOKEN) {
  unpkg.fetch = createBearerAuthFetch(process.env.UNPKG_TOKEN);
}

// for server handler
// NextJS, fastify, etc.
const handler = await createUnpkgHandler({
  unpkg,
  prefix: '/api/unpkg',
});

Links

Package Sidebar

Install

npm i @wener/unpkg

Weekly Downloads

4

Version

1.0.5

License

MIT

Unpacked Size

296 kB

Total Files

60

Last publish

Collaborators

  • wenerme