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 3.0.1 to 4.0.0

6

package.json
{
"name": "@netlify/cache-utils",
"version": "3.0.1",
"version": "4.0.0",
"description": "Utility for caching files in Netlify Build",
"main": "src/main.js",
"type": "module",
"exports": "./src/main.js",
"main": "./src/main.js",
"files": [

@@ -7,0 +9,0 @@ "src/**/*.js"

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

'use strict'
import { resolve } from 'path'
const { resolve } = require('path')
// Retrieve the cache directory location
const getCacheDir = function ({ cacheDir = DEFAULT_CACHE_DIR, cwd = '.' } = {}) {
export const getCacheDir = function ({ cacheDir = DEFAULT_CACHE_DIR, cwd = '.' } = {}) {
return resolve(cwd, cacheDir)

@@ -11,3 +9,1 @@ }

const DEFAULT_CACHE_DIR = '.netlify/cache/'
module.exports = { getCacheDir }

@@ -1,5 +0,3 @@

'use strict'
// Retrieve the expiration date when caching a file
const getExpires = function (ttl) {
export const getExpires = function (ttl) {
if (!Number.isInteger(ttl) || ttl < 1) {

@@ -15,6 +13,4 @@ return

// Check if a file about to be restored is expired
const checkExpires = function (expires) {
export const checkExpires = function (expires) {
return expires !== undefined && Date.now() > expires
}
module.exports = { getExpires, checkExpires }

@@ -1,16 +0,14 @@

'use strict'
import { stat } from 'fs'
import { basename, dirname } from 'path'
import { promisify } from 'util'
const { stat } = require('fs')
const { basename, dirname } = require('path')
const { promisify } = require('util')
import cpy from 'cpy'
import globby from 'globby'
import junk from 'junk'
import moveFile from 'move-file'
const cpy = require('cpy')
const globby = require('globby')
const junk = require('junk')
const moveFile = require('move-file')
const pStat = promisify(stat)
// Move or copy a cached file/directory from/to a local one
const moveCacheFile = async function (src, dest, move) {
export const moveCacheFile = async function (src, dest, move) {
// Moving is faster but removes the source files locally

@@ -26,3 +24,3 @@ if (move) {

// Non-existing files and empty directories are always skipped
const hasFiles = async function (src) {
export const hasFiles = async function (src) {
const { srcGlob, cwd, isDir } = await getSrcGlob(src)

@@ -67,3 +65,1 @@ return srcGlob !== undefined && !(await isEmptyDir({ srcGlob, cwd, isDir }))

}
module.exports = { moveCacheFile, hasFiles }

@@ -1,13 +0,11 @@

'use strict'
import { createHash } from 'crypto'
import { createReadStream } from 'fs'
const { createHash } = require('crypto')
const { createReadStream } = require('fs')
import getStream from 'get-stream'
import locatePath from 'locate-path'
const getStream = require('get-stream')
const locatePath = require('locate-path')
// Caching a big directory like `node_modules` is slow. However those can
// sometime be represented by a digest file such as `package-lock.json`. If this
// has not changed, we don't need to save cache again.
const getHash = async function (digests, move) {
export const getHash = async function (digests, move) {
// Moving files is faster than computing hashes

@@ -39,3 +37,1 @@ if (move || digests.length === 0) {

const HASH_ALGO = 'sha1'
module.exports = { getHash }

@@ -1,13 +0,11 @@

'use strict'
import { join } from 'path'
const { join } = require('path')
import readdirp from 'readdirp'
const readdirp = require('readdirp')
import { getCacheDir } from './dir.js'
import { isManifest } from './manifest.js'
import { getBases } from './path.js'
const { getCacheDir } = require('./dir')
const { isManifest } = require('./manifest')
const { getBases } = require('./path')
// List all cached files/directories, at the top-level
const list = async function ({ cacheDir, cwd: cwdOpt, depth = DEFAULT_DEPTH } = {}) {
export const list = async function ({ cacheDir, cwd: cwdOpt, depth = DEFAULT_DEPTH } = {}) {
const bases = await getBases(cwdOpt)

@@ -32,3 +30,1 @@ const cacheDirA = getCacheDir({ cacheDir, cwd: cwdOpt })

}
module.exports = { list }

@@ -1,10 +0,11 @@

'use strict'
import del from 'del'
const del = require('del')
import { getCacheDir } from './dir.js'
import { moveCacheFile, hasFiles } from './fs.js'
import { list } from './list.js'
import { getManifestInfo, writeManifest, removeManifest, isExpired } from './manifest.js'
import { parsePath } from './path.js'
const { getCacheDir } = require('./dir')
const { moveCacheFile, hasFiles } = require('./fs')
const { list } = require('./list')
const { getManifestInfo, writeManifest, removeManifest, isExpired } = require('./manifest')
const { parsePath } = require('./path')
export { getCacheDir } from './dir.js'
export { list } from './list.js'

@@ -87,9 +88,9 @@ // Cache a file

const save = allowMany.bind(null, saveOne)
const restore = allowMany.bind(null, restoreOne)
const remove = allowMany.bind(null, removeOne)
const has = allowMany.bind(null, hasOne)
export const save = allowMany.bind(null, saveOne)
export const restore = allowMany.bind(null, restoreOne)
export const remove = allowMany.bind(null, removeOne)
export const has = allowMany.bind(null, hasOne)
// Change `opts` default values
const bindOpts = function (opts) {
export const bindOpts = function (opts) {
return {

@@ -104,3 +105,1 @@ save: (paths, optsA) => save(paths, { ...opts, ...optsA }),

}
module.exports = { save, restore, remove, has, list, getCacheDir, bindOpts }

@@ -1,14 +0,12 @@

'use strict'
import { writeFile, readFile } from 'fs'
import { dirname } from 'path'
import { promisify } from 'util'
const { writeFile, readFile } = require('fs')
const { dirname } = require('path')
const { promisify } = require('util')
import del from 'del'
import makeDir from 'make-dir'
import pathExists from 'path-exists'
const del = require('del')
const makeDir = require('make-dir')
const pathExists = require('path-exists')
import { getExpires, checkExpires } from './expire.js'
import { getHash } from './hash.js'
const { getExpires, checkExpires } = require('./expire')
const { getHash } = require('./hash')
const pWriteFile = promisify(writeFile)

@@ -19,3 +17,3 @@ const pReadFile = promisify(readFile)

// contents hash and the `expires` date.
const getManifestInfo = async function ({ cachePath, move, ttl, digests }) {
export const getManifestInfo = async function ({ cachePath, move, ttl, digests }) {
const manifestPath = getManifestPath(cachePath)

@@ -41,3 +39,3 @@ const expires = getExpires(ttl)

// Persist the cache manifest to filesystem
const writeManifest = async function ({ manifestPath, manifestString }) {
export const writeManifest = async function ({ manifestPath, manifestString }) {
await makeDir(dirname(manifestPath))

@@ -48,3 +46,3 @@ await pWriteFile(manifestPath, manifestString)

// Remove the cache manifest from filesystem
const removeManifest = async function (cachePath) {
export const removeManifest = async function (cachePath) {
const manifestPath = getManifestPath(cachePath)

@@ -59,3 +57,3 @@ await del(manifestPath, { force: true })

const isManifest = function (filePath) {
export const isManifest = function (filePath) {
return filePath.endsWith(CACHE_EXTENSION)

@@ -67,3 +65,3 @@ }

// Check whether a file/directory is expired by checking its cache manifest
const isExpired = async function (cachePath) {
export const isExpired = async function (cachePath) {
const manifestPath = getManifestPath(cachePath)

@@ -84,3 +82,1 @@ if (!(await pathExists(manifestPath))) {

}
module.exports = { getManifestInfo, writeManifest, removeManifest, isManifest, isExpired }

@@ -1,11 +0,9 @@

'use strict'
import { homedir } from 'os'
import { resolve, isAbsolute, join, sep } from 'path'
const { homedir } = require('os')
const { resolve, isAbsolute, join, sep } = require('path')
import { getCacheDir } from './dir.js'
import { safeGetCwd } from './utils/cwd.js'
const { getCacheDir } = require('./dir')
const { safeGetCwd } = require('./utils/cwd')
// Find the paths of the file before/after caching
const parsePath = async function ({ path, cacheDir, cwdOpt }) {
export const parsePath = async function ({ path, cacheDir, cwdOpt }) {
const srcPath = await getSrcPath(path, cwdOpt)

@@ -97,3 +95,3 @@ const cachePath = await getCachePath({ srcPath, cacheDir, cwdOpt })

const getBases = async function (cwdOpt) {
export const getBases = async function (cwdOpt) {
const cwdBase = await getCwdBase(cwdOpt)

@@ -111,3 +109,1 @@ return [...cwdBase, { name: 'home', base: homedir() }, { name: 'root', base: sep }]

}
module.exports = { parsePath, getBases }

@@ -1,10 +0,8 @@

'use strict'
import { normalize } from 'path'
import process from 'process'
const { normalize } = require('path')
const process = require('process')
import pathExists from 'path-exists'
const pathExists = require('path-exists')
// Like `process.cwd()` but safer when current directory is wrong
const safeGetCwd = async function (cwdOpt) {
export const safeGetCwd = async function (cwdOpt) {
try {

@@ -26,3 +24,1 @@ const cwd = getCwdValue(cwdOpt)

}
module.exports = { safeGetCwd }
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