npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vercel/remote

v1.0.1

Published

An SDK for remote artifact caching on Vercel

Downloads

31,620

Readme

Vercel Remote Caching SDK

@vercel/remote

When you build your project a set of build outputs are created. These build outputs are called artifacts and many times they can be reused and shared with your team running the same build. With Vercel's Remote Cache API, you can easily share these artifacts with your team or your CI environments.

The Vercel Remote Caching SDK is a thin layer over our existing API can be added to your build system to enable remote artifact caching.

Table of Contents

Installation

npm install @vercel/remote

Getting Started

To get started you will need a Vercel Access Token and an optional team ID. You can create a vercel access token in your account settings. Your team ID can be found under your team settings page.

Every artifact on Vercel's Remote Cache is keyed by your Vercel teamId and the artifact hash.

  • A valid teamId is necessary to share artifacts with your team. Otherwise, artifacts will only be accessible from the personal account of the Vercel Access token used to initialize the client.
  • The hash is provided by your build system and is a unique indentifier for the task that generated artifacts. The hash is not a function of the artifact itself, but rather it's computed from the task graph your build system uses.

Authentication

Use a Vercel Access Token with access to the requested teamId in the RemoteClient to use this SDK.

Using buffers

import fs from 'fs-extra'
import { createClient } from '@vercel/remote'

const remote = createClient('<token>', {
  teamId: '<teamId>',
  // e.g. turbo, nx, rush, etc. 
  product: 'your-build-system'
});

async function getArtifact(hash) {
  const exists = await remote.exists(hash).send();
  if (!exists) {
    return false
  }

  // Process the incoming buffer to your local cache
  const buf = await remote.get(hash).buffer()
  await fs.writeFile(hash, buf)
  return true
}

async function putArtifact(hash, buf) {
  await remote.put(hash).buffer(buf)
}

Using streams

import fs from 'fs-extra'
import stream from 'stream'
import { promisify } from 'util';
import { createClient } from '@vercel/remote'

const pipeline = promisify(stream.pipeline);

const remote = createClient('<token>', {
  teamId: '<teamId>',
  // e.g. turbo, nx, rush, etc. 
  product: 'your-build-system'
});

async function getArtifact(hash) {
  const exists = await remote.exists(hash).send();
  if (!exists) {
    return false
  }
  const readStream = await remote.get(hash).stream()
  // Process the incoming stream to your local cache
  const writeStream = fs.createWriteStream(hash);
  await pipeline(readStream, writeStream)
  return true
}

async function putArtifact(hash) {
  // Create the artifact stream from your local cache
  const readStream = fs.createReadStream(hash);

  // Push to Vercel remote cache
  await remote.put(hash).stream(readStream)
}

Creating a Remote Cache Client


const remote = createClient('<token>', {
  // Vercel team ID. When this is not specified, the personal account 
  // associated with the provided `token` will be used. Specify a `teamId`
  // to share artifacts with the team.
  teamId: '<teamId>',
  // The build system you are using. For example turbo, nx, rush, etc.
  product: 'your-build-system'
});

Checking artifact exists

Return true if an artifact exists in the remote cache. Otherwise return false.

const exists = await remote.exists('6079a2819459d70b').send();

Retrieve artifact

Returns an artifact from the remote cache as a buffer

const buf = await remote.get('6079a2819459d70b').buffer();

Returns an artifact from the remote cache as a readable stream

const readStream = await remote.get('6079a2819459d70b').stream();

Store artifact

Uploads an artifact to the remote cache from a buffer

await remote.put('6079a2819459d70b', {
    // `duration` is the compute time to create the artifact in milliseconds
    duration: 8030,
  }).buffer(buf);

Uploads an artifact to the remote cache from a readable stream

await remote.put('6079a2819459d70b', {
    // `duration` is the compute time to create the artifact in milliseconds
    duration: 8030,
  }).stream(readStream);

Errors

Throws errors in the format and for the reasons defined on the Vercel Rest API