Registry / devops / postinstall-cache

postinstall-cache

JSON →
library0.7.0jsnpmunverified

A caching layer for postinstall script modules used in Node.js package development. Current stable version is 0.7.0, with updates released as needed. It provides a simple cache to avoid redundant execution of 'postinstall' scripts (such as postinstall-js, postinstall-css, postinstall-browserify). Key differentiators: lightweight, zero dependencies, focuses solely on caching for the specific postinstall ecosystem. Compared to generic build caches, it is purpose-built for the postinstall pipeline.

npm install postinstall-cache
INSTALL
IMPORT
SIG · POSTINSTALL-CACHE
P
postinstall-cache
devopsjavascriptv0.7.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

postinstallCache
import postinstallCache from 'postinstall-cache'
const postinstallCache = require('postinstall-cache')
Package is ESM-only; CommonJS require will fail.
Cache
import { Cache } from 'postinstall-cache'
const { Cache } = require('postinstall-cache')
Named export for the Cache class; ESM-only.
createCache
import { createCache } from 'postinstall-cache'
const createCache = require('postinstall-cache').createCache
Factory function to create a cache instance; ESM-only.

Shows basic usage: import default, create cache, and use get/set with async operations.

import postinstallCache from 'postinstall-cache'; const cache = postinstallCache(); // Example: using cache for a postinstall script const result = await cache.get('script-id'); if (!result) { // Execute actual work result = await doWork(); cache.set('script-id', result); } function doWork() { return new Promise((resolve) => { setTimeout(() => resolve('done'), 100); }); }
Debug
Known issues
gotchaCache keys must be strings. Using non-string keys will throw a TypeError.
fix
Always convert keys to strings before using get/set.
affects: >=0.0.0
gotchaThe cache does not expire by default. Entries persist for the lifetime of the process.
fix
Implement manual eviction or use a time-to-live wrapper if temporary caching is needed.
affects: >=0.0.0
breakingIn version 0.6.0, the default export changed from a class to a factory function. Direct instantiation with 'new postinstallCache()' will fail.
fix
Use postinstallCache() as a function call, not a constructor.
affects: >=0.6.0
Errors
Common errors & fixes
TypeError: postinstallCache is not a constructor
Using 'new postinstallCache()' on versions >=0.6.0 where default export is a factory function.
fix
Remove 'new' keyword: const cache = postinstallCache();
ERR_REQUIRE_ESM
Using CommonJS require() on ESM-only package.
fix
Use dynamic import: import('postinstall-cache') or convert project to ESM.
TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string
Passing a non-string key to cache.get() or .set().
fix
Ensure keys are strings: cache.get(String(key)) or cache.set(String(key), value).
Upgrade
Version history
0.7.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
postinstall-cache — npm install postinstall-cache · libregistry