3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2026-06-10 02:37:12 +00:00

use rollup to do bundle splitting

this uses dynamic imports for the cache provider and should thus solve the
deprecated import error when using warpbuild
This commit is contained in:
Arpad Borsos 2026-06-06 14:35:16 +02:00
parent 1fe0a60026
commit c106961fee
No known key found for this signature in database
GPG key ID: FC7BCA77824B3298
10 changed files with 333200 additions and 665905 deletions

247450
dist/cache-1jS6aShy.js vendored Normal file

File diff suppressed because one or more lines are too long

48972
dist/cache-Cb-Up9r2.js vendored Normal file

File diff suppressed because it is too large Load diff

34833
dist/cleanup-ChNUL7jL.js vendored Normal file

File diff suppressed because one or more lines are too long

332908
dist/restore.js vendored

File diff suppressed because one or more lines are too long

333049
dist/save.js vendored

File diff suppressed because one or more lines are too long

1847
dist/state-cjs-BbR-w6pp.js vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,24 +1,11 @@
// import * as fs from "node:fs";
import commonjs from "@rollup/plugin-commonjs"; import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json"; import json from "@rollup/plugin-json";
import nodeResolve from "@rollup/plugin-node-resolve"; import nodeResolve from "@rollup/plugin-node-resolve";
import type { RollupWatchOptions } from "rollup"; import type { RollupWatchOptions } from "rollup";
// const pkg = JSON.parse(fs.readFileSync("./package.json", { encoding: "utf-8" })); const config: RollupWatchOptions = {
// const external = ["node:module", "node:path", "node:fs", "node:fs/promises", "typescript", "rollup", "@babel/code-frame", "magic-string", "@jridgewell/remapping", "@jridgewell/sourcemap-codec", "convert-source-map"]; input: ["./.build/src/restore.js", "./.build/src/save.js"],
output: { dir: "./dist", format: "es" },
const config: Array<RollupWatchOptions> = [
{
input: "./.build/src/restore.js",
output: { file: "./dist/restore.js", format: "es" },
plugins: [nodeResolve({ preferBuiltins: true }), commonjs(), json()], plugins: [nodeResolve({ preferBuiltins: true }), commonjs(), json()],
}, };
{
input: "./.build/src/save.js",
output: { file: "./dist/save.js", format: "es" },
plugins: [nodeResolve({ preferBuiltins: true }), commonjs(), json()],
},
];
export default config; export default config;

View file

@ -12,7 +12,7 @@ process.on("uncaughtException", (e) => {
}); });
async function run() { async function run() {
const cacheProvider = getCacheProvider(); const cacheProvider = await getCacheProvider();
if (!cacheProvider.cache.isFeatureAvailable()) { if (!cacheProvider.cache.isFeatureAvailable()) {
setCacheHitOutput(false); setCacheHitOutput(false);
@ -42,8 +42,9 @@ async function run() {
lookupOnly, lookupOnly,
}); });
if (restoreKey) { if (restoreKey) {
const match = restoreKey.localeCompare(key, undefined, { const match =
sensitivity: "accent" restoreKey.localeCompare(key, undefined, {
sensitivity: "accent",
}) === 0; }) === 0;
core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`); core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
if (!match) { if (!match) {

View file

@ -13,7 +13,7 @@ process.on("uncaughtException", (e) => {
}); });
async function run() { async function run() {
const cacheProvider = getCacheProvider(); const cacheProvider = await getCacheProvider();
const save = core.getInput("save-if").toLowerCase() || "true"; const save = core.getInput("save-if").toLowerCase() || "true";

View file

@ -1,7 +1,5 @@
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as exec from "@actions/exec"; import * as exec from "@actions/exec";
import * as warpbuildCache from "@actions/warpbuild-cache";
import * as ghCache from "@actions/cache";
import fs from "fs"; import fs from "fs";
export function reportError(e: any) { export function reportError(e: any) {
@ -42,8 +40,8 @@ export async function getCmdOutput(cmdFormat: string, cmd: string, options: exec
} }
export interface GhCache { export interface GhCache {
isFeatureAvailable: typeof ghCache.isFeatureAvailable; isFeatureAvailable: typeof import("@actions/cache").isFeatureAvailable;
restoreCache: typeof ghCache.restoreCache; restoreCache: typeof import("@actions/cache").restoreCache;
saveCache: (paths: string[], key: string) => Promise<string | number>; saveCache: (paths: string[], key: string) => Promise<string | number>;
} }
@ -52,15 +50,15 @@ export interface CacheProvider {
cache: GhCache; cache: GhCache;
} }
export function getCacheProvider(): CacheProvider { export async function getCacheProvider(): Promise<CacheProvider> {
const cacheProvider = core.getInput("cache-provider"); const cacheProvider = core.getInput("cache-provider");
let cache: GhCache; let cache: GhCache;
switch (cacheProvider) { switch (cacheProvider) {
case "github": case "github":
cache = ghCache; cache = await import("@actions/cache");
break; break;
case "warpbuild": case "warpbuild":
cache = warpbuildCache; cache = await import("@actions/warpbuild-cache");
break; break;
default: default:
throw new Error(`The \`cache-provider\` \`${cacheProvider}\` is not valid.`); throw new Error(`The \`cache-provider\` \`${cacheProvider}\` is not valid.`);