Files
klz-cables.com/.pnpm-store/v10/files/61/46ca952114641ac2e1e78666f16ddee52530e3eb6cd4efc0a000c0b352e93c075dffefd99f678abb7589463b4c3b3085f12963b1e5f2c7383a3fe5375b3ec9
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

39 lines
1.3 KiB
Plaintext

import fs from 'fs/promises';
import os from 'node:os';
import path from 'node:path';
import { v4 as uuid } from 'uuid';
async function runTask(temporaryPath, callback) {
try {
return await callback(temporaryPath);
} finally{
await fs.rm(temporaryPath, {
force: true,
maxRetries: 2,
recursive: true
});
}
}
export const temporaryFileTask = async (callback, options = {})=>{
const filePath = await temporaryFile(options);
return runTask(filePath, callback);
};
async function temporaryFile(options) {
if (options.name) {
if (options.extension !== undefined && options.extension !== null) {
throw new Error('The `name` and `extension` options are mutually exclusive');
}
return path.join(await temporaryDirectory(), options.name);
}
return await getPath() + (options.extension === undefined || options.extension === null ? '' : '.' + options.extension.replace(/^\./, ''));
}
async function temporaryDirectory({ prefix = '' } = {}) {
const directory = await getPath(prefix);
await fs.mkdir(directory);
return directory;
}
async function getPath(prefix = '') {
const temporaryDirectory = await fs.realpath(os.tmpdir());
return path.join(temporaryDirectory, prefix + uuid());
}
//# sourceMappingURL=tempFile.js.map