@vercel/remote-nx
Version:
Remote caching for @nrwl/nx using Vercel Remote Cache
100 lines (94 loc) • 3.46 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
default: () => src_default
});
module.exports = __toCommonJS(src_exports);
var import_nx_remotecache_custom2 = require("nx-remotecache-custom");
// src/setup-sdk.ts
var import_nx_remotecache_custom = require("nx-remotecache-custom");
// src/remote-client.ts
var import_events = __toESM(require("events"));
var import_remote = require("@vercel/remote");
var import_chalk = require("chalk");
function getCredentials(options) {
const token = process.env.VERCEL_ARTIFACTS_TOKEN;
const teamId = process.env.VERCEL_ARTIFACTS_OWNER;
if (token && teamId) {
return {
token,
teamId
};
}
return {
token: process.env.NX_VERCEL_REMOTE_CACHE_TOKEN || options.token,
teamId: process.env.NX_VERCEL_REMOTE_CACHE_TEAM || options.teamId
};
}
function getVercelRemoteCacheClient(options) {
import_events.default.defaultMaxListeners = 500;
const { token, teamId } = getCredentials(options);
if (!token) {
throw new Error(
"Missing a Vercel access token for Vercel Remote Cache. Specify a token either in nx.json or using the environment variable NX_VERCEL_REMOTE_CACHE_TOKEN."
);
}
if (options.verbose) {
const owner = teamId ? `Team ${teamId}` : "Personal account";
console.log(
(0, import_chalk.gray)(`Initializing Vercel remote cache with scope: "${owner}".`)
);
}
return (0, import_remote.createClient)(token, { teamId, product: "nx" });
}
// src/setup-sdk.ts
var setupSDK = async (options, tasks) => {
(0, import_nx_remotecache_custom.initEnv)(options);
const remote = getVercelRemoteCacheClient(options);
return {
name: "Vercel Remote Cache",
fileExists: (filename) => remote.exists(filename).send(),
retrieveFile: (filename) => remote.get(filename).stream(),
storeFile: (filename, stream) => remote.put(filename, {
duration: totalDuration(tasks)
}).stream(stream)
};
};
function totalDuration(tasks) {
let total = 0;
for (const task of tasks) {
if (task.startTime && task.endTime) {
total += task.endTime - task.startTime;
}
}
return total;
}
// src/index.ts
var runner = (0, import_nx_remotecache_custom2.createCustomRunner)(setupSDK);
var src_default = runner;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});