Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('stat: get filesystem stats for a file', async t => {
const cacheDir = path.join(testDir.path, '_cacache')
const hash = await cacache.put(cacheDir, 'eggplant:hello', 'hello world')
process.tink = {
cache: cacheDir
}
const fixture = new Tacks(Dir({
'.package-map.json': File({
path_prefix: '/node_modules',
packages: {
'eggplant': {
files: {
'hello.js': hash
}
}
}
})
}))
fixture.create(testDir.path)
.then(xs => JSON.parse(String(xs.data)))
.catch(() => null);
if (!meta || now - Date.parse(meta.date) > Number(expires)) {
const pkgReq = await fetch(`${registry}/v1/packages/package/${name}`);
meta = {
date: Date.parse(pkgReq.headers.date),
data: await pkgReq.json()
};
if (pkgReq.status > 399) {
console.log(name, meta.data);
throw new Error();
}
await cacache.put(cache, `spackage:${name}`, JSON.stringify(meta));
}
return meta.data;
}
return readFileAsync(src).then(data => {
if (opts.cache) {
return cacache.put(
opts.cache, `pacote:tarball:file:${src}`, data, {
integrity: opts.integrity
}
).then(integrity => ({ data, integrity }))
} else {
return { data }
}
}).then(info => {
if (info.integrity) { stream.emit('integrity', info.integrity) }
return readFileAsync(src).then(data => {
if (opts.cache) {
return cacache.put(
opts.cache, `pacote:tarball:file:${src}`, data, {
integrity: opts.integrity
}
).then(integrity => ({ data, integrity }))
} else {
return { data }
}
}).then(info => {
if (info.integrity) { stream.emit('integrity', info.integrity) }
async function cachePut(content: string, key: string | null, integrity?: string): Promise {
if (cachePath && key) {
await cacache.put(cachePath, key, content, {
metadata: { integrity },
});
}
}
}).then(manifest => {
const cacheKey = key || finalKey(manifest, spec)
if (!opts.cache || !cacheKey) {
return manifest
} else {
return cacache.put(
opts.cache, cacheKey, '.', {
metadata: {
id: manifest._id,
manifest,
type: 'finalized-manifest'
}
}
).then(() => manifest)
}
})
}
return generatedImage.then((result) => {
if (typeof globalOptions.cacheDir === 'string') {
return Promise.all([
cacache.put(globalOptions.cacheDir, bufferCacheKey, result.buffer),
cacache.put(
globalOptions.cacheDir,
metaCacheKey,
JSON.stringify(result.info),
),
]).then(() => result);
}
return result;
});
});
async function cachePut(
content: string,
key: string | null,
integrity?: string
): Promise {
if (cachePath && key) {
await cacache.put(cachePath, key, content, {
metadata: { integrity }
});
}
}
return generatedImage.then((result) => {
if (typeof globalOptions.cacheDir === 'string') {
return Promise.all([
cacache.put(globalOptions.cacheDir, bufferCacheKey, result.buffer),
cacache.put(
globalOptions.cacheDir,
metaCacheKey,
JSON.stringify(result.info),
),
]).then(() => result);
}
return result;
});
});
collecter.on('collect', data => {
cacache.put(
cachePath,
ckey,
data,
cacheOpts
).then(cacheWriteResolve, cacheWriteReject)
})
newBody.unshift(collecter)