Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@netlify/cache-utils

Package Overview
Dependencies
Maintainers
15
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netlify/cache-utils - npm Package Compare versions

Comparing version 4.0.0 to 4.1.0

3

package.json
{
"name": "@netlify/cache-utils",
"version": "4.0.0",
"version": "4.1.0",
"description": "Utility for caching files in Netlify Build",

@@ -54,3 +54,2 @@ "type": "module",

"locate-path": "^6.0.0",
"make-dir": "^3.1.0",
"move-file": "^2.0.0",

@@ -57,0 +56,0 @@ "path-exists": "^4.0.0",

@@ -11,17 +11,16 @@ [![Coverage Status](https://codecov.io/gh/netlify/build/branch/main/graph/badge.svg)](https://codecov.io/gh/netlify/build)

```js
module.exports = {
// Restore file/directory cached in previous builds.
// Does not do anything if:
// - the file/directory already exists locally
// - the file/directory has not been cached yet
async onPreBuild({ utils }) {
await utils.cache.restore('./path/to/file')
},
// Cache file/directory for future builds.
// Does not do anything if:
// - the file/directory does not exist locally
async onPostBuild({ utils }) {
await utils.cache.save('./path/to/file')
},
// Restore file/directory cached in previous builds.
// Does not do anything if:
// - the file/directory already exists locally
// - the file/directory has not been cached yet
export const onPreBuild = async function ({ utils }) {
await utils.cache.restore('./path/to/file')
}
// Cache file/directory for future builds.
// Does not do anything if:
// - the file/directory does not exist locally
export const onPostBuild = async function ({ utils }) {
await utils.cache.save('./path/to/file')
}
```

@@ -33,10 +32,9 @@

// Restore/cache several files/directories
module.exports = {
async onPreBuild({ utils }) {
await utils.cache.restore(['./path/to/file', './path/to/other'])
},
async onPostBuild({ utils }) {
await utils.cache.save(['./path/to/file', './path/to/other'])
},
export const onPreBuild = async function ({ utils }) {
await utils.cache.restore(['./path/to/file', './path/to/other'])
}
export const onPostBuild = async function ({ utils }) {
await utils.cache.save(['./path/to/file', './path/to/other'])
}
```

@@ -69,11 +67,10 @@

// Only cache the following file/directory for 1 hour
module.exports = {
async onPreBuild({ utils }) {
await utils.cache.restore('./path/to/file')
},
async onPostBuild({ utils }) {
const ttl = 3600
await utils.cache.save('./path/to/file', { ttl })
},
export const onPreBuild = async function ({ utils }) {
await utils.cache.restore('./path/to/file')
}
export const onPostBuild = async function ({ utils }) {
const ttl = 3600
await utils.cache.save('./path/to/file', { ttl })
}
```

@@ -94,12 +91,11 @@

// `node_modules` directory.
module.exports = {
async onPreBuild({ utils }) {
await utils.cache.restore('node_modules')
},
async onPostBuild({ utils }) {
await utils.cache.save('node_modules', {
digests: ['package-lock.json', 'yarn.lock'],
})
},
export const onPreBuild = async function ({ utils }) {
await utils.cache.restore('node_modules')
}
export const onPostBuild = async function ({ utils }) {
await utils.cache.save('node_modules', {
digests: ['package-lock.json', 'yarn.lock'],
})
}
```

@@ -146,6 +142,4 @@

```js
module.exports = {
async onPostBuild({ utils }) {
await utils.cache.remove('./path/to/file')
},
export const onPostBuild = async function ({ utils }) {
await utils.cache.remove('./path/to/file')
}

@@ -175,20 +169,19 @@ ```

module.exports = {
async onPreBuild({ utils }) {
if (!(await utils.cache.has(path))) {
console.log(`File ${path} not cached`)
return
}
export const onPreBuild = async function ({ utils }) {
if (!(await utils.cache.has(path))) {
console.log(`File ${path} not cached`)
return
}
console.log(`About to restore cached file ${path}...`)
if (await utils.cache.restore('./path/to/file')) {
console.log(`Restored cached file ${path}`)
}
},
async onPostBuild({ utils }) {
if (await utils.cache.save('./path/to/file')) {
console.log(`Saved cached file ${path}`)
}
},
console.log(`About to restore cached file ${path}...`)
if (await utils.cache.restore('./path/to/file')) {
console.log(`Restored cached file ${path}`)
}
}
export const onPostBuild = async function ({ utils }) {
if (await utils.cache.save('./path/to/file')) {
console.log(`Saved cached file ${path}`)
}
}
```

@@ -213,7 +206,5 @@

```js
module.exports = {
async onPreBuild({ utils }) {
const files = await utils.cache.list()
console.log('Cached files', files)
},
export const onPreBuild = async function ({ utils }) {
const files = await utils.cache.list()
console.log('Cached files', files)
}

@@ -220,0 +211,0 @@ ```

@@ -62,3 +62,3 @@ import { stat } from 'fs'

return await pStat(src)
} catch (error) {}
} catch {}
}

@@ -1,7 +0,5 @@

import { writeFile, readFile } from 'fs'
import { promises as fs } from 'fs'
import { dirname } from 'path'
import { promisify } from 'util'
import del from 'del'
import makeDir from 'make-dir'
import pathExists from 'path-exists'

@@ -12,5 +10,2 @@

const pWriteFile = promisify(writeFile)
const pReadFile = promisify(readFile)
// Retrieve cache manifest of a file to cache, which contains the file/directory

@@ -34,3 +29,3 @@ // contents hash and the `expires` date.

const oldManifestString = await pReadFile(manifestPath, 'utf8')
const oldManifestString = await fs.readFile(manifestPath, 'utf8')
return oldManifestString === manifestString

@@ -41,4 +36,4 @@ }

export const writeManifest = async function ({ manifestPath, manifestString }) {
await makeDir(dirname(manifestPath))
await pWriteFile(manifestPath, manifestString)
await fs.mkdir(dirname(manifestPath), { recursive: true })
await fs.writeFile(manifestPath, manifestString)
}

@@ -76,5 +71,5 @@

const manifestPath = getManifestPath(cachePath)
const manifestString = await pReadFile(manifestPath, 'utf8')
const manifestString = await fs.readFile(manifestPath)
const manifest = JSON.parse(manifestString)
return manifest
}

@@ -16,3 +16,3 @@ import { normalize } from 'path'

return cwd
} catch (error) {
} catch {
return ''

@@ -19,0 +19,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc