feat(planning): grille hebdomadaire complète avec API et filtres
- Connexion API via proxy Angular (résolution CORS, base path /api) - Import CSS ng-zorro global pour les modales et composants - Filtres Camion/Show câblés sur l'affichage de la grille - Camions affichés via TrucksService (linkés au show du même créneau) - Panneau de détails : spectacles + camions du jour sélectionné - Modale de création de spectacle stylisée avec fond et centrage - Positionnement précis des events à la minute dans leur créneau - Auto-scroll vers l'heure courante au chargement - Ligne "maintenant" sur la colonne du jour actuel - Régénération des services OpenAPI (nouveaux noms de types) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+17
-155
@@ -57,17 +57,10 @@ const options = {
|
||||
|
||||
// for use when you need to clean up something when objects
|
||||
// are evicted from the cache
|
||||
dispose: (value, key, reason) => {
|
||||
dispose: (value, key) => {
|
||||
freeFromMemoryOrWhatever(value)
|
||||
},
|
||||
|
||||
// for use when you need to know that an item is being inserted
|
||||
// note that this does NOT allow you to prevent the insertion,
|
||||
// it just allows you to know about it.
|
||||
onInsert: (value, key, reason) => {
|
||||
logInsertionOrWhatever(key, value)
|
||||
},
|
||||
|
||||
// how long to live in ms
|
||||
ttl: 1000 * 60 * 5,
|
||||
|
||||
@@ -79,7 +72,11 @@ const options = {
|
||||
|
||||
// async method to use for cache.fetch(), for
|
||||
// stale-while-revalidate type of behavior
|
||||
fetchMethod: async (key, staleValue, { options, signal, context }) => {},
|
||||
fetchMethod: async (
|
||||
key,
|
||||
staleValue,
|
||||
{ options, signal, context }
|
||||
) => {},
|
||||
}
|
||||
|
||||
const cache = new LRUCache(options)
|
||||
@@ -157,7 +154,7 @@ const cache = {
|
||||
}
|
||||
cache.timers.set(
|
||||
k,
|
||||
setTimeout(() => cache.delete(k), ttl),
|
||||
setTimeout(() => cache.delete(k), ttl)
|
||||
)
|
||||
cache.data.set(k, v)
|
||||
},
|
||||
@@ -215,95 +212,9 @@ const myGet = (key, value) => {
|
||||
}
|
||||
```
|
||||
|
||||
## Tracing and Observability
|
||||
|
||||
Most methods can accept a `status` option, which is an
|
||||
[`LRUCache.Status`](https://isaacs.github.io/node-lru-cache/interfaces/LRUCache.LRUCache.Status.html)
|
||||
object that will be decorated along the operation with
|
||||
indications about what was done and why.
|
||||
|
||||
Additionally, this library is instrumented using the
|
||||
[`node:diagnostics_channel`](https://nodejs.org/api/diagnostics_channel.html)
|
||||
module on Node and other platforms that support it. In order to
|
||||
get diagnostics metrics, listen on the
|
||||
`channel('lru-cache:metrics')`. To get Tracing Channel traces,
|
||||
subscribe to the `tracingChannel('lru-cache')`. The
|
||||
[`LRUCache.Status`](https://isaacs.github.io/node-lru-cache/interfaces/LRUCache.LRUCache.Status.html)
|
||||
objects will be provided as the message context to those channel
|
||||
listeners.
|
||||
|
||||
For example, you could do the following to get comprehensive
|
||||
information about every LRUCache instance in your application:
|
||||
|
||||
```ts
|
||||
import { tracingChannel, subscribe } from 'node:diagnostics_channel'
|
||||
|
||||
subscribe('lru-cache:metrics', (message, name) => {
|
||||
// name will always be 'lru-cache:metrics'
|
||||
// message will be the LRUCache.Status object for whatever
|
||||
// synchronous operation was performed.
|
||||
console.error('LRUCache Metrics', message)
|
||||
})
|
||||
|
||||
tracingChannel('lru-cache').subscribe({
|
||||
start: status => {
|
||||
// a traced operation is starting
|
||||
},
|
||||
asyncStart: status => {
|
||||
// an async traced operation is starting
|
||||
},
|
||||
asyncEnd: status => {
|
||||
// an async traced operation is ending
|
||||
}
|
||||
error: status => {
|
||||
// a traced operation failed
|
||||
},
|
||||
end: status => {
|
||||
// a traced operation is complete
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
The async `cache.fetch()` and `cache.forceFetch` methods are
|
||||
covered by `tracingChannels`. All the other operations are
|
||||
covered by the `lru-cache:metrics` channel, because they are
|
||||
strictly synchronous, and thus don't have an asynchronous
|
||||
lifecycle to track.
|
||||
|
||||
Note that using `status` objects or using
|
||||
`node:diagnostics_channel` listeners _will_ impose a modest
|
||||
performance penalty. Creating data objects is not ever free; do
|
||||
not believe anyone who tells you otherwise. But it is as small as
|
||||
possible.
|
||||
|
||||
### Platform Compatibility Caveat
|
||||
|
||||
Not all platforms support the `node:diagnostics_channel` module.
|
||||
Currently, this is only available in Node, Bun, and Deno, and
|
||||
some edge computing platforms that provide a Node compatibility
|
||||
layer.
|
||||
|
||||
To work around this, if you are loading in a non-Node
|
||||
environment, the package.json exports will direct your module
|
||||
loader to pull in a version that starts out with a dummy
|
||||
implementation, then does a conditional dynamic `import` of the
|
||||
`node:diagnostics_channel` module, and then swaps out those
|
||||
dummy objects with the real thing if it succeeds. This means that
|
||||
cache metrics and tracing channels started in the first load-time
|
||||
tick of your application will _not_ be covered, except in
|
||||
environments that load using the `require` import
|
||||
condition, or both the `node` and `esm` import conditions
|
||||
together.
|
||||
|
||||
Top-level await _could_ be used to remove this caveat, but that
|
||||
feature is dead on arrival, unfortunately. See
|
||||
[#397](https://github.com/isaacs/node-lru-cache/issues/397) and
|
||||
[#398](https://github.com/isaacs/node-lru-cache/issues/398) for
|
||||
more details.
|
||||
|
||||
## Performance
|
||||
|
||||
As of April 2026, version 11 of this library is one of the most
|
||||
As of January 2022, version 7 of this library is one of the most
|
||||
performant LRU cache implementations in JavaScript.
|
||||
|
||||
Benchmarks can be extremely difficult to get right. In
|
||||
@@ -358,9 +269,9 @@ If performance matters to you:
|
||||
LRUCache](https://yomguithereal.github.io/mnemonist/lru-cache)
|
||||
which uses an Object as its data store.
|
||||
|
||||
2. Failing that, if you can use short non-numeric strings (ie,
|
||||
less than 256 characters) as your keys, and you do not need
|
||||
any of the other features of this library, use [mnemonist's
|
||||
2. Failing that, if at all possible, use short non-numeric
|
||||
strings (ie, less than 256 characters) as your keys, and use
|
||||
[mnemonist's
|
||||
LRUCache](https://yomguithereal.github.io/mnemonist/lru-cache).
|
||||
|
||||
3. If the types of your keys will be anything else, especially
|
||||
@@ -372,63 +283,14 @@ If performance matters to you:
|
||||
(like asynchronous fetching, a variety of TTL staleness
|
||||
options, and so on), then [mnemonist's
|
||||
LRUMap](https://yomguithereal.github.io/mnemonist/lru-map) is
|
||||
also a very good option, and just slightly faster than this
|
||||
module (since it does considerably less).
|
||||
a very good option, and just slightly faster than this module
|
||||
(since it does considerably less).
|
||||
|
||||
4. Do not use a `dispose` function, size tracking, or especially
|
||||
ttl behavior or observability features, unless absolutely
|
||||
needed. These features are convenient, and necessary in some
|
||||
use cases, and every attempt has been made to make the
|
||||
performance impact minimal, but it isn't nothing.
|
||||
|
||||
## Testing
|
||||
|
||||
When writing tests that involve TTL-related functionality, note
|
||||
that this module creates an internal reference to the global
|
||||
`performance` or `Date` objects at import time. If you import it
|
||||
statically at the top level, those references cannot be mocked or
|
||||
overridden in your test environment.
|
||||
|
||||
To avoid this, dynamically import the package within your tests
|
||||
so that the references are captured after your mocks are applied.
|
||||
For example:
|
||||
|
||||
```ts
|
||||
// ❌ Not recommended
|
||||
import { LRUCache } from 'lru-cache'
|
||||
// mocking timers, e.g. jest.useFakeTimers()
|
||||
|
||||
// ✅ Recommended for TTL tests
|
||||
// mocking timers, e.g. jest.useFakeTimers()
|
||||
const { LRUCache } = await import('lru-cache')
|
||||
```
|
||||
|
||||
This ensures that your mocked timers or time sources are
|
||||
respected when testing TTL behavior.
|
||||
|
||||
Additionally, you can pass in a `perf` option when creating your
|
||||
LRUCache instance. This option accepts any object with a `now`
|
||||
method that returns a number.
|
||||
|
||||
For example, this would be a very bare-bones time-mocking system
|
||||
you could use in your tests, without any particular test
|
||||
framework:
|
||||
|
||||
```ts
|
||||
import { LRUCache } from 'lru-cache'
|
||||
|
||||
let myClockTime = 0
|
||||
|
||||
const cache = new LRUCache<string>({
|
||||
max: 10,
|
||||
ttl: 1000,
|
||||
perf: {
|
||||
now: () => myClockTime,
|
||||
},
|
||||
})
|
||||
|
||||
// run tests, updating myClockTime as needed
|
||||
```
|
||||
ttl behavior, unless absolutely needed. These features are
|
||||
convenient, and necessary in some use cases, and every attempt
|
||||
has been made to make the performance impact minimal, but it
|
||||
isn't nothing.
|
||||
|
||||
## Breaking Changes in Version 7
|
||||
|
||||
|
||||
+33
-156
@@ -1,8 +1,6 @@
|
||||
/**
|
||||
* @module LRUCache
|
||||
*/
|
||||
import type { Perf } from './perf.js';
|
||||
export type { Perf } from './perf.js';
|
||||
declare const TYPE: unique symbol;
|
||||
export type PosInt = number & {
|
||||
[TYPE]: 'Positive Integer';
|
||||
@@ -77,20 +75,6 @@ export declare namespace LRUCache {
|
||||
* {@link OptionsBase.disposeAfter} options.
|
||||
*/
|
||||
type Disposer<K, V> = (value: V, key: K, reason: DisposeReason) => void;
|
||||
/**
|
||||
* The reason why an item was added to the cache, passed
|
||||
* to the {@link Inserter} methods.
|
||||
*
|
||||
* - `add`: the item was not found in the cache, and was added
|
||||
* - `update`: the item was in the cache, with the same value provided
|
||||
* - `replace`: the item was in the cache, and replaced
|
||||
*/
|
||||
type InsertReason = 'add' | 'update' | 'replace';
|
||||
/**
|
||||
* A method called upon item insertion, passed as the
|
||||
* {@link OptionsBase.insert}
|
||||
*/
|
||||
type Inserter<K, V> = (value: V, key: K, reason: InsertReason) => void;
|
||||
/**
|
||||
* A function that returns the effective calculated size
|
||||
* of an entry in the cache.
|
||||
@@ -118,16 +102,8 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* The `status` option should be a plain JavaScript object. The following
|
||||
* fields will be set on it appropriately, depending on the situation.
|
||||
*
|
||||
* These objects are also the context objects passed to listeners on the
|
||||
* `lru-cache:metrics` diagnostic channel, and the `lru-cache` tracing
|
||||
* channels, in platforms that support them.
|
||||
*/
|
||||
interface Status<K, V, FC = unknown> {
|
||||
/**
|
||||
* The operation being performed
|
||||
*/
|
||||
op?: 'get' | 'set' | 'memo' | 'fetch' | 'delete' | 'has' | 'peek';
|
||||
interface Status<V> {
|
||||
/**
|
||||
* The status of a set() operation.
|
||||
*
|
||||
@@ -136,37 +112,7 @@ export declare namespace LRUCache {
|
||||
* - replace: the item was in the cache, and replaced
|
||||
* - miss: the item was not added to the cache for some reason
|
||||
*/
|
||||
set?: 'add' | 'update' | 'replace' | 'miss' | 'deleted';
|
||||
/**
|
||||
* The status of a delete() operation.
|
||||
*/
|
||||
delete?: LRUCache.DisposeReason;
|
||||
/**
|
||||
* The result of a peek() operation
|
||||
*
|
||||
* - hit: the item was found and returned
|
||||
* - stale: the item is in the cache, but past its ttl and not returned
|
||||
* - miss: item not in the cache
|
||||
*/
|
||||
peek?: 'hit' | 'miss' | 'stale';
|
||||
/**
|
||||
* The status of a memo() operation.
|
||||
*
|
||||
* - 'hit': the item was found in the cache and returned
|
||||
* - 'miss': the `memoMethod` function was called
|
||||
*/
|
||||
memo?: 'hit' | 'miss';
|
||||
/**
|
||||
* The `context` option provided to a memo or fetch operation
|
||||
*
|
||||
* In practice, of course, this will be the same type as the `FC`
|
||||
* fetch context param used to instantiate the LRUCache, but the
|
||||
* convolutions of threading that through would get quite complicated,
|
||||
* and preclude forcing/forbidding the passing of a `context` param
|
||||
* where it is/isn't expected, which is more valuable for error
|
||||
* prevention.
|
||||
*/
|
||||
context?: unknown;
|
||||
set?: 'add' | 'update' | 'replace' | 'miss';
|
||||
/**
|
||||
* the ttl stored for the item, or undefined if ttls are not used.
|
||||
*/
|
||||
@@ -197,15 +143,8 @@ export declare namespace LRUCache {
|
||||
*/
|
||||
maxEntrySizeExceeded?: true;
|
||||
/**
|
||||
* The key that was set or retrieved
|
||||
*/
|
||||
key?: K;
|
||||
/**
|
||||
* The value that was set
|
||||
*/
|
||||
value?: V;
|
||||
/**
|
||||
* The old value, specified in the case of `set:'replace'`
|
||||
* The old value, specified in the case of `set:'update'` or
|
||||
* `set:'replace'`
|
||||
*/
|
||||
oldValue?: V;
|
||||
/**
|
||||
@@ -231,10 +170,6 @@ export declare namespace LRUCache {
|
||||
* {@link FetchOptions.forceRefresh} was specified.
|
||||
*/
|
||||
fetch?: 'get' | 'inflight' | 'miss' | 'hit' | 'stale' | 'refresh';
|
||||
/**
|
||||
* `forceRefresh` option was used for either a fetch or memo operation
|
||||
*/
|
||||
forceRefresh?: boolean;
|
||||
/**
|
||||
* The {@link OptionsBase.fetchMethod} was called
|
||||
*/
|
||||
@@ -256,7 +191,7 @@ export declare namespace LRUCache {
|
||||
fetchAborted?: true;
|
||||
/**
|
||||
* The abort signal received was ignored, and the fetch was allowed to
|
||||
* continue in the background.
|
||||
* continue.
|
||||
*/
|
||||
fetchAbortIgnored?: true;
|
||||
/**
|
||||
@@ -272,27 +207,15 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* - fetching: The item is currently being fetched. If a previous value
|
||||
* is present and allowed, that will be returned.
|
||||
* - stale: The item is in the cache, and is stale. If it was returned,
|
||||
* then the `returnedStale` flag will be set.
|
||||
* - stale-fetching: The value is being fetched in the background, but is
|
||||
* currently stale. If the stale value was returned, then the
|
||||
* `returnedStale` flag will be set.
|
||||
* - stale: The item is in the cache, and is stale.
|
||||
* - hit: the item is in the cache
|
||||
* - miss: the item is not in the cache
|
||||
*/
|
||||
get?: 'stale' | 'hit' | 'miss' | 'fetching' | 'stale-fetching';
|
||||
get?: 'stale' | 'hit' | 'miss';
|
||||
/**
|
||||
* A fetch or get operation returned a stale value.
|
||||
*/
|
||||
returnedStale?: true;
|
||||
/**
|
||||
* A tracingChannel trace was started for this operation
|
||||
*/
|
||||
trace?: boolean;
|
||||
/**
|
||||
* A reference to the cache instance associated with this operation
|
||||
*/
|
||||
cache?: LRUCache<K & {}, V & {}, FC>;
|
||||
}
|
||||
/**
|
||||
* options which override the options set in the LRUCache constructor
|
||||
@@ -310,7 +233,7 @@ export declare namespace LRUCache {
|
||||
* the fetchMethod is called.
|
||||
*/
|
||||
interface FetcherFetchOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
size?: Size;
|
||||
}
|
||||
/**
|
||||
@@ -332,7 +255,7 @@ export declare namespace LRUCache {
|
||||
*/
|
||||
context?: FC;
|
||||
signal?: AbortSignal;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options provided to {@link LRUCache#fetch} when the FC type is something
|
||||
@@ -345,7 +268,7 @@ export declare namespace LRUCache {
|
||||
* Options provided to {@link LRUCache#fetch} when the FC type is
|
||||
* `undefined` or `void`
|
||||
*/
|
||||
interface FetchOptionsNoContext<K, V, FC extends undefined | void = undefined> extends FetchOptions<K, V, FC> {
|
||||
interface FetchOptionsNoContext<K, V> extends FetchOptions<K, V, undefined> {
|
||||
context?: undefined;
|
||||
}
|
||||
interface MemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
||||
@@ -363,7 +286,7 @@ export declare namespace LRUCache {
|
||||
* be required.
|
||||
*/
|
||||
context?: FC;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options provided to {@link LRUCache#memo} when the FC type is something
|
||||
@@ -376,7 +299,7 @@ export declare namespace LRUCache {
|
||||
* Options provided to {@link LRUCache#memo} when the FC type is
|
||||
* `undefined` or `void`
|
||||
*/
|
||||
interface MemoOptionsNoContext<K, V, FC extends undefined | void = undefined> extends MemoOptions<K, V, FC> {
|
||||
interface MemoOptionsNoContext<K, V> extends MemoOptions<K, V, undefined> {
|
||||
context?: undefined;
|
||||
}
|
||||
/**
|
||||
@@ -397,7 +320,7 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* This is the union of {@link GetOptions} and {@link SetOptions}, plus
|
||||
* {@link MemoOptions.forceRefresh}, and
|
||||
* {@link MemoOptions.context}
|
||||
* {@link MemoerOptions.context}
|
||||
*
|
||||
* Any of these may be modified in the {@link OptionsBase.memoMethod}
|
||||
* function, but the {@link GetOptions} fields will of course have no
|
||||
@@ -405,7 +328,7 @@ export declare namespace LRUCache {
|
||||
* the memoMethod is called.
|
||||
*/
|
||||
interface MemoizerMemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
size?: Size;
|
||||
start?: Milliseconds;
|
||||
}
|
||||
@@ -413,19 +336,18 @@ export declare namespace LRUCache {
|
||||
* Options that may be passed to the {@link LRUCache#has} method.
|
||||
*/
|
||||
interface HasOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'updateAgeOnHas'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#get} method.
|
||||
*/
|
||||
interface GetOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#peek} method.
|
||||
*/
|
||||
interface PeekOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale'> {
|
||||
status?: Status<K, V, FC>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#set} method.
|
||||
@@ -446,7 +368,7 @@ export declare namespace LRUCache {
|
||||
* method is in use.
|
||||
*/
|
||||
start?: Milliseconds;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* The type signature for the {@link OptionsBase.fetchMethod} option.
|
||||
@@ -633,17 +555,6 @@ export declare namespace LRUCache {
|
||||
* `cache.clear()`, or `cache.set(key, undefined)`.
|
||||
*/
|
||||
dispose?: Disposer<K, V>;
|
||||
/**
|
||||
* Function that is called when new items are inserted into the cache,
|
||||
* as `onInsert(value, key, reason)`.
|
||||
*
|
||||
* This can be useful if you need to perform actions when an item is
|
||||
* added, such as logging or tracking insertions.
|
||||
*
|
||||
* Unlike some other options, this may _not_ be overridden by passing
|
||||
* an option to `set()`, for performance and consistency reasons.
|
||||
*/
|
||||
onInsert?: Inserter<K, V>;
|
||||
/**
|
||||
* The same as {@link OptionsBase.dispose}, but called *after* the entry
|
||||
* is completely removed and the cache is once again in a clean state.
|
||||
@@ -699,20 +610,6 @@ export declare namespace LRUCache {
|
||||
* though for most cases, only minimally.
|
||||
*/
|
||||
maxSize?: Size;
|
||||
/**
|
||||
* The effective size for background fetch promises.
|
||||
*
|
||||
* This has no effect unless `maxSize` and `sizeCalculation` are used,
|
||||
* and a {@link LRUCache.OptionsBase.fetchMethod} is provided to
|
||||
* support {@link LRUCache#fetch}.
|
||||
*
|
||||
* If a stale value is present in the cache, then the effective size of
|
||||
* the background fetch is the size of the stale item it will eventually
|
||||
* replace. If not, then this value is used as its effective size.
|
||||
*
|
||||
* @default 1
|
||||
*/
|
||||
backgroundFetchSize?: number;
|
||||
/**
|
||||
* The maximum allowed size for any single item in the cache.
|
||||
*
|
||||
@@ -899,15 +796,6 @@ export declare namespace LRUCache {
|
||||
* call to {@link LRUCache#fetch}.
|
||||
*/
|
||||
ignoreFetchAbort?: boolean;
|
||||
/**
|
||||
* In some cases, you may want to swap out the performance/Date object
|
||||
* used for TTL tracking. This should almost certainly NOT be done in
|
||||
* production environments!
|
||||
*
|
||||
* This value defaults to `global.performance` if it has a `now()` method,
|
||||
* or the `global.Date` object otherwise.
|
||||
*/
|
||||
perf?: Perf;
|
||||
}
|
||||
interface OptionsMaxLimit<K, V, FC> extends OptionsBase<K, V, FC> {
|
||||
max: Count;
|
||||
@@ -949,12 +837,8 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* Changing any of these will alter the defaults for subsequent method calls.
|
||||
*/
|
||||
export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
export declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<K, V> {
|
||||
#private;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.perf}
|
||||
*/
|
||||
get perf(): Perf;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.ttl}
|
||||
*/
|
||||
@@ -1015,8 +899,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
|
||||
*/
|
||||
ignoreFetchAbort: boolean;
|
||||
/** {@link LRUCache.OptionsBase.backgroundFetchSize} */
|
||||
backgroundFetchSize: number;
|
||||
/**
|
||||
* Do not call this method unless you need to inspect the
|
||||
* inner workings of the cache. If anything returned by this
|
||||
@@ -1029,7 +911,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
static unsafeExposeInternals<K extends {}, V extends {}, FC extends unknown = unknown>(c: LRUCache<K, V, FC>): {
|
||||
starts: ZeroArray | undefined;
|
||||
ttls: ZeroArray | undefined;
|
||||
autopurgeTimers: (NodeJS.Timeout | undefined)[] | undefined;
|
||||
sizes: ZeroArray | undefined;
|
||||
keyMap: Map<K, number>;
|
||||
keyList: (K | undefined)[];
|
||||
@@ -1039,8 +920,8 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
readonly head: Index;
|
||||
readonly tail: Index;
|
||||
free: StackLike;
|
||||
isBackgroundFetch: (p: unknown) => p is BackgroundFetch<V>;
|
||||
backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: unknown) => BackgroundFetch<V>;
|
||||
isBackgroundFetch: (p: any) => boolean;
|
||||
backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: any) => BackgroundFetch<V>;
|
||||
moveToTail: (index: number) => void;
|
||||
indexes: (options?: {
|
||||
allowStale: boolean;
|
||||
@@ -1075,10 +956,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* {@link LRUCache.OptionsBase.dispose} (read-only)
|
||||
*/
|
||||
get dispose(): LRUCache.Disposer<K, V> | undefined;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.onInsert} (read-only)
|
||||
*/
|
||||
get onInsert(): LRUCache.Inserter<K, V> | undefined;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
|
||||
*/
|
||||
@@ -1100,7 +977,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* Return a generator yielding `[key, value]` pairs,
|
||||
* in order from least recently used to most recently used.
|
||||
*/
|
||||
rentries(): Generator<(K | V)[], void, unknown>;
|
||||
rentries(): Generator<(K | V | BackgroundFetch<V> | undefined)[], void, unknown>;
|
||||
/**
|
||||
* Return a generator yielding the keys in the cache,
|
||||
* in order from most recently used to least recently used.
|
||||
@@ -1124,7 +1001,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* Return a generator yielding the values in the cache,
|
||||
* in order from least recently used to most recently used.
|
||||
*/
|
||||
rvalues(): Generator<V | undefined, void, unknown>;
|
||||
rvalues(): Generator<V | BackgroundFetch<V> | undefined, void, unknown>;
|
||||
/**
|
||||
* Iterating over the cache itself yields the same results as
|
||||
* {@link LRUCache.entries}
|
||||
@@ -1152,12 +1029,12 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
*
|
||||
* Does not update age or recenty of use, or iterate over stale values.
|
||||
*/
|
||||
forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
||||
forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any): void;
|
||||
/**
|
||||
* The same as {@link LRUCache.forEach} but items are iterated over in
|
||||
* reverse order. (ie, less recently used items are iterated over first.)
|
||||
*/
|
||||
rforEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
||||
rforEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any): void;
|
||||
/**
|
||||
* Delete any stale entries. Returns true if anything was removed,
|
||||
* false otherwise.
|
||||
@@ -1178,7 +1055,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
info(key: K): LRUCache.Entry<V> | undefined;
|
||||
/**
|
||||
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be
|
||||
* passed to {@link LRUCache#load}.
|
||||
* passed to {@link LRLUCache#load}.
|
||||
*
|
||||
* The `start` fields are calculated relative to a portable `Date.now()`
|
||||
* timestamp, even if `performance.now()` is available.
|
||||
@@ -1230,7 +1107,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* If the value is `undefined`, then this is an alias for
|
||||
* `cache.delete(key)`. `undefined` is never stored in the cache.
|
||||
*/
|
||||
set(k: K, v: V | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
|
||||
set(k: K, v: V | BackgroundFetch<V> | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
|
||||
/**
|
||||
* Evict the least recently used item, returning its value or
|
||||
* `undefined` if cache is empty.
|
||||
@@ -1346,23 +1223,23 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* the same time, because they're both waiting on the same
|
||||
* underlying fetchMethod response.
|
||||
*/
|
||||
fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
|
||||
fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<undefined | V>;
|
||||
fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
|
||||
fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<undefined | V>;
|
||||
/**
|
||||
* In some cases, `cache.fetch()` may resolve to `undefined`, either because
|
||||
* a {@link LRUCache.OptionsBase#fetchMethod} was not provided (turning
|
||||
* `cache.fetch(k)` into just an async wrapper around `cache.get(k)`) or
|
||||
* because `ignoreFetchAbort` was specified (either to the constructor or
|
||||
* in the {@link LRUCache.FetchOptions}). Also, the
|
||||
* {@link LRUCache.OptionsBase.fetchMethod} may return `undefined` or `void`, making
|
||||
* {@link OptionsBase.fetchMethod} may return `undefined` or `void`, making
|
||||
* the test even more complicated.
|
||||
*
|
||||
* Because inferring the cases where `undefined` might be returned are so
|
||||
* cumbersome, but testing for `undefined` can also be annoying, this method
|
||||
* can be used, which will reject if `this.fetch()` resolves to undefined.
|
||||
*/
|
||||
forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
|
||||
forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<V>;
|
||||
forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
|
||||
forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<V>;
|
||||
/**
|
||||
* If the key is found in the cache, then this is equivalent to
|
||||
* {@link LRUCache#get}. If not, in the cache, then calculate the value using
|
||||
@@ -1377,8 +1254,8 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* relevant in the course of fetching the data. It is only relevant for the
|
||||
* course of a single `memo()` operation, and discarded afterwards.
|
||||
*/
|
||||
memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
|
||||
memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : never): V;
|
||||
memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
|
||||
memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : never): V;
|
||||
/**
|
||||
* Return a value from the cache. Will update the recency of the cache
|
||||
* entry found.
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+244
-424
File diff suppressed because it is too large
Load Diff
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
+4
-4
File diff suppressed because one or more lines are too long
+33
-156
@@ -1,8 +1,6 @@
|
||||
/**
|
||||
* @module LRUCache
|
||||
*/
|
||||
import type { Perf } from './perf.js';
|
||||
export type { Perf } from './perf.js';
|
||||
declare const TYPE: unique symbol;
|
||||
export type PosInt = number & {
|
||||
[TYPE]: 'Positive Integer';
|
||||
@@ -77,20 +75,6 @@ export declare namespace LRUCache {
|
||||
* {@link OptionsBase.disposeAfter} options.
|
||||
*/
|
||||
type Disposer<K, V> = (value: V, key: K, reason: DisposeReason) => void;
|
||||
/**
|
||||
* The reason why an item was added to the cache, passed
|
||||
* to the {@link Inserter} methods.
|
||||
*
|
||||
* - `add`: the item was not found in the cache, and was added
|
||||
* - `update`: the item was in the cache, with the same value provided
|
||||
* - `replace`: the item was in the cache, and replaced
|
||||
*/
|
||||
type InsertReason = 'add' | 'update' | 'replace';
|
||||
/**
|
||||
* A method called upon item insertion, passed as the
|
||||
* {@link OptionsBase.insert}
|
||||
*/
|
||||
type Inserter<K, V> = (value: V, key: K, reason: InsertReason) => void;
|
||||
/**
|
||||
* A function that returns the effective calculated size
|
||||
* of an entry in the cache.
|
||||
@@ -118,16 +102,8 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* The `status` option should be a plain JavaScript object. The following
|
||||
* fields will be set on it appropriately, depending on the situation.
|
||||
*
|
||||
* These objects are also the context objects passed to listeners on the
|
||||
* `lru-cache:metrics` diagnostic channel, and the `lru-cache` tracing
|
||||
* channels, in platforms that support them.
|
||||
*/
|
||||
interface Status<K, V, FC = unknown> {
|
||||
/**
|
||||
* The operation being performed
|
||||
*/
|
||||
op?: 'get' | 'set' | 'memo' | 'fetch' | 'delete' | 'has' | 'peek';
|
||||
interface Status<V> {
|
||||
/**
|
||||
* The status of a set() operation.
|
||||
*
|
||||
@@ -136,37 +112,7 @@ export declare namespace LRUCache {
|
||||
* - replace: the item was in the cache, and replaced
|
||||
* - miss: the item was not added to the cache for some reason
|
||||
*/
|
||||
set?: 'add' | 'update' | 'replace' | 'miss' | 'deleted';
|
||||
/**
|
||||
* The status of a delete() operation.
|
||||
*/
|
||||
delete?: LRUCache.DisposeReason;
|
||||
/**
|
||||
* The result of a peek() operation
|
||||
*
|
||||
* - hit: the item was found and returned
|
||||
* - stale: the item is in the cache, but past its ttl and not returned
|
||||
* - miss: item not in the cache
|
||||
*/
|
||||
peek?: 'hit' | 'miss' | 'stale';
|
||||
/**
|
||||
* The status of a memo() operation.
|
||||
*
|
||||
* - 'hit': the item was found in the cache and returned
|
||||
* - 'miss': the `memoMethod` function was called
|
||||
*/
|
||||
memo?: 'hit' | 'miss';
|
||||
/**
|
||||
* The `context` option provided to a memo or fetch operation
|
||||
*
|
||||
* In practice, of course, this will be the same type as the `FC`
|
||||
* fetch context param used to instantiate the LRUCache, but the
|
||||
* convolutions of threading that through would get quite complicated,
|
||||
* and preclude forcing/forbidding the passing of a `context` param
|
||||
* where it is/isn't expected, which is more valuable for error
|
||||
* prevention.
|
||||
*/
|
||||
context?: unknown;
|
||||
set?: 'add' | 'update' | 'replace' | 'miss';
|
||||
/**
|
||||
* the ttl stored for the item, or undefined if ttls are not used.
|
||||
*/
|
||||
@@ -197,15 +143,8 @@ export declare namespace LRUCache {
|
||||
*/
|
||||
maxEntrySizeExceeded?: true;
|
||||
/**
|
||||
* The key that was set or retrieved
|
||||
*/
|
||||
key?: K;
|
||||
/**
|
||||
* The value that was set
|
||||
*/
|
||||
value?: V;
|
||||
/**
|
||||
* The old value, specified in the case of `set:'replace'`
|
||||
* The old value, specified in the case of `set:'update'` or
|
||||
* `set:'replace'`
|
||||
*/
|
||||
oldValue?: V;
|
||||
/**
|
||||
@@ -231,10 +170,6 @@ export declare namespace LRUCache {
|
||||
* {@link FetchOptions.forceRefresh} was specified.
|
||||
*/
|
||||
fetch?: 'get' | 'inflight' | 'miss' | 'hit' | 'stale' | 'refresh';
|
||||
/**
|
||||
* `forceRefresh` option was used for either a fetch or memo operation
|
||||
*/
|
||||
forceRefresh?: boolean;
|
||||
/**
|
||||
* The {@link OptionsBase.fetchMethod} was called
|
||||
*/
|
||||
@@ -256,7 +191,7 @@ export declare namespace LRUCache {
|
||||
fetchAborted?: true;
|
||||
/**
|
||||
* The abort signal received was ignored, and the fetch was allowed to
|
||||
* continue in the background.
|
||||
* continue.
|
||||
*/
|
||||
fetchAbortIgnored?: true;
|
||||
/**
|
||||
@@ -272,27 +207,15 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* - fetching: The item is currently being fetched. If a previous value
|
||||
* is present and allowed, that will be returned.
|
||||
* - stale: The item is in the cache, and is stale. If it was returned,
|
||||
* then the `returnedStale` flag will be set.
|
||||
* - stale-fetching: The value is being fetched in the background, but is
|
||||
* currently stale. If the stale value was returned, then the
|
||||
* `returnedStale` flag will be set.
|
||||
* - stale: The item is in the cache, and is stale.
|
||||
* - hit: the item is in the cache
|
||||
* - miss: the item is not in the cache
|
||||
*/
|
||||
get?: 'stale' | 'hit' | 'miss' | 'fetching' | 'stale-fetching';
|
||||
get?: 'stale' | 'hit' | 'miss';
|
||||
/**
|
||||
* A fetch or get operation returned a stale value.
|
||||
*/
|
||||
returnedStale?: true;
|
||||
/**
|
||||
* A tracingChannel trace was started for this operation
|
||||
*/
|
||||
trace?: boolean;
|
||||
/**
|
||||
* A reference to the cache instance associated with this operation
|
||||
*/
|
||||
cache?: LRUCache<K & {}, V & {}, FC>;
|
||||
}
|
||||
/**
|
||||
* options which override the options set in the LRUCache constructor
|
||||
@@ -310,7 +233,7 @@ export declare namespace LRUCache {
|
||||
* the fetchMethod is called.
|
||||
*/
|
||||
interface FetcherFetchOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
size?: Size;
|
||||
}
|
||||
/**
|
||||
@@ -332,7 +255,7 @@ export declare namespace LRUCache {
|
||||
*/
|
||||
context?: FC;
|
||||
signal?: AbortSignal;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options provided to {@link LRUCache#fetch} when the FC type is something
|
||||
@@ -345,7 +268,7 @@ export declare namespace LRUCache {
|
||||
* Options provided to {@link LRUCache#fetch} when the FC type is
|
||||
* `undefined` or `void`
|
||||
*/
|
||||
interface FetchOptionsNoContext<K, V, FC extends undefined | void = undefined> extends FetchOptions<K, V, FC> {
|
||||
interface FetchOptionsNoContext<K, V> extends FetchOptions<K, V, undefined> {
|
||||
context?: undefined;
|
||||
}
|
||||
interface MemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
||||
@@ -363,7 +286,7 @@ export declare namespace LRUCache {
|
||||
* be required.
|
||||
*/
|
||||
context?: FC;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options provided to {@link LRUCache#memo} when the FC type is something
|
||||
@@ -376,7 +299,7 @@ export declare namespace LRUCache {
|
||||
* Options provided to {@link LRUCache#memo} when the FC type is
|
||||
* `undefined` or `void`
|
||||
*/
|
||||
interface MemoOptionsNoContext<K, V, FC extends undefined | void = undefined> extends MemoOptions<K, V, FC> {
|
||||
interface MemoOptionsNoContext<K, V> extends MemoOptions<K, V, undefined> {
|
||||
context?: undefined;
|
||||
}
|
||||
/**
|
||||
@@ -397,7 +320,7 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* This is the union of {@link GetOptions} and {@link SetOptions}, plus
|
||||
* {@link MemoOptions.forceRefresh}, and
|
||||
* {@link MemoOptions.context}
|
||||
* {@link MemoerOptions.context}
|
||||
*
|
||||
* Any of these may be modified in the {@link OptionsBase.memoMethod}
|
||||
* function, but the {@link GetOptions} fields will of course have no
|
||||
@@ -405,7 +328,7 @@ export declare namespace LRUCache {
|
||||
* the memoMethod is called.
|
||||
*/
|
||||
interface MemoizerMemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
size?: Size;
|
||||
start?: Milliseconds;
|
||||
}
|
||||
@@ -413,19 +336,18 @@ export declare namespace LRUCache {
|
||||
* Options that may be passed to the {@link LRUCache#has} method.
|
||||
*/
|
||||
interface HasOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'updateAgeOnHas'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#get} method.
|
||||
*/
|
||||
interface GetOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#peek} method.
|
||||
*/
|
||||
interface PeekOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale'> {
|
||||
status?: Status<K, V, FC>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#set} method.
|
||||
@@ -446,7 +368,7 @@ export declare namespace LRUCache {
|
||||
* method is in use.
|
||||
*/
|
||||
start?: Milliseconds;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* The type signature for the {@link OptionsBase.fetchMethod} option.
|
||||
@@ -633,17 +555,6 @@ export declare namespace LRUCache {
|
||||
* `cache.clear()`, or `cache.set(key, undefined)`.
|
||||
*/
|
||||
dispose?: Disposer<K, V>;
|
||||
/**
|
||||
* Function that is called when new items are inserted into the cache,
|
||||
* as `onInsert(value, key, reason)`.
|
||||
*
|
||||
* This can be useful if you need to perform actions when an item is
|
||||
* added, such as logging or tracking insertions.
|
||||
*
|
||||
* Unlike some other options, this may _not_ be overridden by passing
|
||||
* an option to `set()`, for performance and consistency reasons.
|
||||
*/
|
||||
onInsert?: Inserter<K, V>;
|
||||
/**
|
||||
* The same as {@link OptionsBase.dispose}, but called *after* the entry
|
||||
* is completely removed and the cache is once again in a clean state.
|
||||
@@ -699,20 +610,6 @@ export declare namespace LRUCache {
|
||||
* though for most cases, only minimally.
|
||||
*/
|
||||
maxSize?: Size;
|
||||
/**
|
||||
* The effective size for background fetch promises.
|
||||
*
|
||||
* This has no effect unless `maxSize` and `sizeCalculation` are used,
|
||||
* and a {@link LRUCache.OptionsBase.fetchMethod} is provided to
|
||||
* support {@link LRUCache#fetch}.
|
||||
*
|
||||
* If a stale value is present in the cache, then the effective size of
|
||||
* the background fetch is the size of the stale item it will eventually
|
||||
* replace. If not, then this value is used as its effective size.
|
||||
*
|
||||
* @default 1
|
||||
*/
|
||||
backgroundFetchSize?: number;
|
||||
/**
|
||||
* The maximum allowed size for any single item in the cache.
|
||||
*
|
||||
@@ -899,15 +796,6 @@ export declare namespace LRUCache {
|
||||
* call to {@link LRUCache#fetch}.
|
||||
*/
|
||||
ignoreFetchAbort?: boolean;
|
||||
/**
|
||||
* In some cases, you may want to swap out the performance/Date object
|
||||
* used for TTL tracking. This should almost certainly NOT be done in
|
||||
* production environments!
|
||||
*
|
||||
* This value defaults to `global.performance` if it has a `now()` method,
|
||||
* or the `global.Date` object otherwise.
|
||||
*/
|
||||
perf?: Perf;
|
||||
}
|
||||
interface OptionsMaxLimit<K, V, FC> extends OptionsBase<K, V, FC> {
|
||||
max: Count;
|
||||
@@ -949,12 +837,8 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* Changing any of these will alter the defaults for subsequent method calls.
|
||||
*/
|
||||
export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
export declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<K, V> {
|
||||
#private;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.perf}
|
||||
*/
|
||||
get perf(): Perf;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.ttl}
|
||||
*/
|
||||
@@ -1015,8 +899,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
|
||||
*/
|
||||
ignoreFetchAbort: boolean;
|
||||
/** {@link LRUCache.OptionsBase.backgroundFetchSize} */
|
||||
backgroundFetchSize: number;
|
||||
/**
|
||||
* Do not call this method unless you need to inspect the
|
||||
* inner workings of the cache. If anything returned by this
|
||||
@@ -1029,7 +911,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
static unsafeExposeInternals<K extends {}, V extends {}, FC extends unknown = unknown>(c: LRUCache<K, V, FC>): {
|
||||
starts: ZeroArray | undefined;
|
||||
ttls: ZeroArray | undefined;
|
||||
autopurgeTimers: (NodeJS.Timeout | undefined)[] | undefined;
|
||||
sizes: ZeroArray | undefined;
|
||||
keyMap: Map<K, number>;
|
||||
keyList: (K | undefined)[];
|
||||
@@ -1039,8 +920,8 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
readonly head: Index;
|
||||
readonly tail: Index;
|
||||
free: StackLike;
|
||||
isBackgroundFetch: (p: unknown) => p is BackgroundFetch<V>;
|
||||
backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: unknown) => BackgroundFetch<V>;
|
||||
isBackgroundFetch: (p: any) => boolean;
|
||||
backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: any) => BackgroundFetch<V>;
|
||||
moveToTail: (index: number) => void;
|
||||
indexes: (options?: {
|
||||
allowStale: boolean;
|
||||
@@ -1075,10 +956,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* {@link LRUCache.OptionsBase.dispose} (read-only)
|
||||
*/
|
||||
get dispose(): LRUCache.Disposer<K, V> | undefined;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.onInsert} (read-only)
|
||||
*/
|
||||
get onInsert(): LRUCache.Inserter<K, V> | undefined;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
|
||||
*/
|
||||
@@ -1100,7 +977,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* Return a generator yielding `[key, value]` pairs,
|
||||
* in order from least recently used to most recently used.
|
||||
*/
|
||||
rentries(): Generator<(K | V)[], void, unknown>;
|
||||
rentries(): Generator<(K | V | BackgroundFetch<V> | undefined)[], void, unknown>;
|
||||
/**
|
||||
* Return a generator yielding the keys in the cache,
|
||||
* in order from most recently used to least recently used.
|
||||
@@ -1124,7 +1001,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* Return a generator yielding the values in the cache,
|
||||
* in order from least recently used to most recently used.
|
||||
*/
|
||||
rvalues(): Generator<V | undefined, void, unknown>;
|
||||
rvalues(): Generator<V | BackgroundFetch<V> | undefined, void, unknown>;
|
||||
/**
|
||||
* Iterating over the cache itself yields the same results as
|
||||
* {@link LRUCache.entries}
|
||||
@@ -1152,12 +1029,12 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
*
|
||||
* Does not update age or recenty of use, or iterate over stale values.
|
||||
*/
|
||||
forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
||||
forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any): void;
|
||||
/**
|
||||
* The same as {@link LRUCache.forEach} but items are iterated over in
|
||||
* reverse order. (ie, less recently used items are iterated over first.)
|
||||
*/
|
||||
rforEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
||||
rforEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any): void;
|
||||
/**
|
||||
* Delete any stale entries. Returns true if anything was removed,
|
||||
* false otherwise.
|
||||
@@ -1178,7 +1055,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
info(key: K): LRUCache.Entry<V> | undefined;
|
||||
/**
|
||||
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be
|
||||
* passed to {@link LRUCache#load}.
|
||||
* passed to {@link LRLUCache#load}.
|
||||
*
|
||||
* The `start` fields are calculated relative to a portable `Date.now()`
|
||||
* timestamp, even if `performance.now()` is available.
|
||||
@@ -1230,7 +1107,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* If the value is `undefined`, then this is an alias for
|
||||
* `cache.delete(key)`. `undefined` is never stored in the cache.
|
||||
*/
|
||||
set(k: K, v: V | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
|
||||
set(k: K, v: V | BackgroundFetch<V> | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
|
||||
/**
|
||||
* Evict the least recently used item, returning its value or
|
||||
* `undefined` if cache is empty.
|
||||
@@ -1346,23 +1223,23 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* the same time, because they're both waiting on the same
|
||||
* underlying fetchMethod response.
|
||||
*/
|
||||
fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
|
||||
fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<undefined | V>;
|
||||
fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
|
||||
fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<undefined | V>;
|
||||
/**
|
||||
* In some cases, `cache.fetch()` may resolve to `undefined`, either because
|
||||
* a {@link LRUCache.OptionsBase#fetchMethod} was not provided (turning
|
||||
* `cache.fetch(k)` into just an async wrapper around `cache.get(k)`) or
|
||||
* because `ignoreFetchAbort` was specified (either to the constructor or
|
||||
* in the {@link LRUCache.FetchOptions}). Also, the
|
||||
* {@link LRUCache.OptionsBase.fetchMethod} may return `undefined` or `void`, making
|
||||
* {@link OptionsBase.fetchMethod} may return `undefined` or `void`, making
|
||||
* the test even more complicated.
|
||||
*
|
||||
* Because inferring the cases where `undefined` might be returned are so
|
||||
* cumbersome, but testing for `undefined` can also be annoying, this method
|
||||
* can be used, which will reject if `this.fetch()` resolves to undefined.
|
||||
*/
|
||||
forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
|
||||
forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<V>;
|
||||
forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
|
||||
forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<V>;
|
||||
/**
|
||||
* If the key is found in the cache, then this is equivalent to
|
||||
* {@link LRUCache#get}. If not, in the cache, then calculate the value using
|
||||
@@ -1377,8 +1254,8 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* relevant in the course of fetching the data. It is only relevant for the
|
||||
* course of a single `memo()` operation, and discarded afterwards.
|
||||
*/
|
||||
memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
|
||||
memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : never): V;
|
||||
memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
|
||||
memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : never): V;
|
||||
/**
|
||||
* Return a value from the cache. Will update the recency of the cache
|
||||
* entry found.
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+244
-424
File diff suppressed because it is too large
Load Diff
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
+4
-4
File diff suppressed because one or more lines are too long
+44
-82
@@ -1,7 +1,10 @@
|
||||
{
|
||||
"name": "lru-cache",
|
||||
"publishConfig": {
|
||||
"tag": "legacy-v10"
|
||||
},
|
||||
"description": "A cache object that deletes the least-recently-used items.",
|
||||
"version": "11.5.0",
|
||||
"version": "10.4.3",
|
||||
"author": "Isaac Z. Schlueter <i@izs.me>",
|
||||
"keywords": [
|
||||
"mru",
|
||||
@@ -11,7 +14,7 @@
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"build": "npm run prepare",
|
||||
"prepare": "tshy && bash scripts/build.sh",
|
||||
"prepare": "tshy && bash fixup.sh",
|
||||
"pretest": "npm run prepare",
|
||||
"presnap": "npm run prepare",
|
||||
"test": "tap",
|
||||
@@ -25,130 +28,89 @@
|
||||
"prebenchmark": "npm run prepare",
|
||||
"benchmark": "make -C benchmark",
|
||||
"preprofile": "npm run prepare",
|
||||
"profile": "make -C benchmark profile",
|
||||
"lint": "oxlint --fix src test",
|
||||
"postsnap": "npm run lint",
|
||||
"postlint": "npm run format"
|
||||
"profile": "make -C benchmark profile"
|
||||
},
|
||||
"main": "./dist/commonjs/index.min.js",
|
||||
"main": "./dist/commonjs/index.js",
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"tshy": {
|
||||
"esmDialects": [
|
||||
"browser",
|
||||
"node"
|
||||
],
|
||||
"commonjsDialects": [
|
||||
"browser",
|
||||
"node"
|
||||
],
|
||||
"exports": {
|
||||
"./raw": "./src/index.ts",
|
||||
".": {
|
||||
".": "./src/index.ts",
|
||||
"./min": {
|
||||
"import": {
|
||||
"browser": {
|
||||
"types": "./dist/esm/browser/index.d.ts",
|
||||
"default": "./dist/esm/browser/index.min.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/esm/node/index.d.ts",
|
||||
"default": "./dist/esm/node/index.min.js"
|
||||
},
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.min.js"
|
||||
},
|
||||
"require": {
|
||||
"browser": {
|
||||
"types": "./dist/commonjs/browser/index.d.ts",
|
||||
"default": "./dist/commonjs/browser/index.min.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/commonjs/node/index.d.ts",
|
||||
"default": "./dist/commonjs/node/index.min.js"
|
||||
},
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.min.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"selfLink": false
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/isaacs/node-lru-cache.git"
|
||||
"url": "git://github.com/isaacs/node-lru-cache.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.2.5",
|
||||
"@types/tap": "^15.0.6",
|
||||
"benchmark": "^2.1.4",
|
||||
"esbuild": "^0.28.0",
|
||||
"esbuild": "^0.17.11",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"marked": "^4.2.12",
|
||||
"mkdirp": "^3.0.1",
|
||||
"oxlint": "^1.65.0",
|
||||
"oxlint-tsgolint": "^0.22.1",
|
||||
"prettier": "^3.8.3",
|
||||
"tap": "^21.7.4",
|
||||
"tshy": "^4.1.2",
|
||||
"typedoc": "^0.28.19"
|
||||
"mkdirp": "^2.1.5",
|
||||
"prettier": "^2.6.2",
|
||||
"tap": "^20.0.3",
|
||||
"tshy": "^2.0.0",
|
||||
"tslib": "^2.4.0",
|
||||
"typedoc": "^0.25.3",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"license": "BlueOak-1.0.0",
|
||||
"license": "ISC",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": "20 || >=22"
|
||||
"prettier": {
|
||||
"semi": false,
|
||||
"printWidth": 70,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"jsxSingleQuote": false,
|
||||
"bracketSameLine": true,
|
||||
"arrowParens": "avoid",
|
||||
"endOfLine": "lf"
|
||||
},
|
||||
"tap": {
|
||||
"node-arg": [
|
||||
"--expose-gc"
|
||||
],
|
||||
"plugin": [
|
||||
"@tapjs/clock"
|
||||
]
|
||||
},
|
||||
"exports": {
|
||||
"./raw": {
|
||||
".": {
|
||||
"import": {
|
||||
"browser": {
|
||||
"types": "./dist/esm/browser/index.d.ts",
|
||||
"default": "./dist/esm/browser/index.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/esm/node/index.d.ts",
|
||||
"default": "./dist/esm/node/index.js"
|
||||
},
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
},
|
||||
"require": {
|
||||
"browser": {
|
||||
"types": "./dist/commonjs/browser/index.d.ts",
|
||||
"default": "./dist/commonjs/browser/index.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/commonjs/node/index.d.ts",
|
||||
"default": "./dist/commonjs/node/index.js"
|
||||
},
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.js"
|
||||
}
|
||||
},
|
||||
".": {
|
||||
"./min": {
|
||||
"import": {
|
||||
"browser": {
|
||||
"types": "./dist/esm/browser/index.d.ts",
|
||||
"default": "./dist/esm/browser/index.min.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/esm/node/index.d.ts",
|
||||
"default": "./dist/esm/node/index.min.js"
|
||||
},
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.min.js"
|
||||
},
|
||||
"require": {
|
||||
"browser": {
|
||||
"types": "./dist/commonjs/browser/index.d.ts",
|
||||
"default": "./dist/commonjs/browser/index.min.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/commonjs/node/index.d.ts",
|
||||
"default": "./dist/commonjs/node/index.min.js"
|
||||
},
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.min.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": "module",
|
||||
"module": "./dist/esm/index.min.js"
|
||||
"module": "./dist/esm/index.js"
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/agent",
|
||||
"version": "4.0.0",
|
||||
"version": "3.0.0",
|
||||
"description": "the http/https agent used by the npm cli",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
@@ -25,25 +25,25 @@
|
||||
"lib/"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.25.0",
|
||||
"version": "4.23.1",
|
||||
"publish": "true"
|
||||
},
|
||||
"dependencies": {
|
||||
"agent-base": "^7.1.0",
|
||||
"http-proxy-agent": "^7.0.0",
|
||||
"https-proxy-agent": "^7.0.1",
|
||||
"lru-cache": "^11.2.1",
|
||||
"lru-cache": "^10.0.1",
|
||||
"socks-proxy-agent": "^8.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^5.0.0",
|
||||
"@npmcli/template-oss": "4.25.0",
|
||||
"minipass-fetch": "^4.0.1",
|
||||
"nock": "^14.0.3",
|
||||
"@npmcli/template-oss": "4.23.1",
|
||||
"minipass-fetch": "^3.0.3",
|
||||
"nock": "^13.2.7",
|
||||
"socksv5": "^0.0.6",
|
||||
"tap": "^16.3.0"
|
||||
},
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/fs",
|
||||
"version": "5.0.0",
|
||||
"version": "4.0.0",
|
||||
"description": "filesystem utilities for the npm cli",
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
@@ -31,18 +31,18 @@
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^5.0.0",
|
||||
"@npmcli/template-oss": "4.27.1",
|
||||
"@npmcli/template-oss": "4.23.3",
|
||||
"tap": "^16.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"semver": "^7.3.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.27.1",
|
||||
"version": "4.23.3",
|
||||
"publish": true
|
||||
},
|
||||
"tap": {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
const spawn = require('@npmcli/promise-spawn')
|
||||
const { promiseRetry } = require('@gar/promise-retry')
|
||||
const promiseRetry = require('promise-retry')
|
||||
const { log } = require('proc-log')
|
||||
const makeError = require('./make-error.js')
|
||||
const makeOpts = require('./opts.js')
|
||||
|
||||
+1
-16
@@ -1,16 +1 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../which/bin/which.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../which/bin/which.js" "$@"
|
||||
fi
|
||||
../which/bin/which.js
|
||||
+13
-19
@@ -8,24 +8,18 @@ Windows.
|
||||
## USAGE
|
||||
|
||||
```js
|
||||
// default export is a minified version that doesn't need to
|
||||
// load more than one file. Load the 'isexe/raw' export if
|
||||
// you want the non-minified version for some reason.
|
||||
import { isexe, sync } from 'isexe'
|
||||
// or require() works too
|
||||
// const { isexe } = require('isexe')
|
||||
isexe('some-file-name').then(
|
||||
isExe => {
|
||||
if (isExe) {
|
||||
console.error('this thing can be run')
|
||||
} else {
|
||||
console.error('cannot be run')
|
||||
}
|
||||
},
|
||||
err => {
|
||||
console.error('probably file doesnt exist or something')
|
||||
},
|
||||
)
|
||||
isexe('some-file-name').then(isExe => {
|
||||
if (isExe) {
|
||||
console.error('this thing can be run')
|
||||
} else {
|
||||
console.error('cannot be run')
|
||||
}
|
||||
}, (err) => {
|
||||
console.error('probably file doesnt exist or something')
|
||||
})
|
||||
|
||||
// same thing but synchronous, throws errors
|
||||
isExe = sync('some-file-name')
|
||||
@@ -72,9 +66,9 @@ The default exported implementation will be chosen based on
|
||||
import type IsexeOptions from 'isexe'
|
||||
```
|
||||
|
||||
- `ignoreErrors` Treat all errors as "no, this is not
|
||||
* `ignoreErrors` Treat all errors as "no, this is not
|
||||
executable", but don't raise them.
|
||||
- `uid` Number to use as the user id on posix
|
||||
- `gid` Number to use as the group id on posix
|
||||
- `pathExt` List of path extensions to use instead of `PATHEXT`
|
||||
* `uid` Number to use as the user id on posix
|
||||
* `gid` Number to use as the group id on posix
|
||||
* `pathExt` List of path extensions to use instead of `PATHEXT`
|
||||
environment variable on Windows.
|
||||
|
||||
+70
-52
@@ -1,78 +1,96 @@
|
||||
{
|
||||
"name": "isexe",
|
||||
"version": "4.0.0",
|
||||
"version": "3.1.1",
|
||||
"description": "Minimal module to check if a file is executable.",
|
||||
"main": "./dist/commonjs/index.min.js",
|
||||
"module": "./dist/esm/index.min.js",
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"main": "./dist/cjs/index.js",
|
||||
"module": "./dist/mjs/index.js",
|
||||
"types": "./dist/cjs/index.js",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"tshy": {
|
||||
"selfLink": false,
|
||||
"exports": {
|
||||
"./raw": "./src/index.ts",
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.min.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.min.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"exports": {
|
||||
"./raw": {
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.js"
|
||||
}
|
||||
},
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.min.js"
|
||||
"types": "./dist/mjs/index.d.ts",
|
||||
"default": "./dist/mjs/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.min.js"
|
||||
"types": "./dist/cjs/index.d.ts",
|
||||
"default": "./dist/cjs/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"./posix": {
|
||||
"import": {
|
||||
"types": "./dist/mjs/posix.d.ts",
|
||||
"default": "./dist/mjs/posix.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/cjs/posix.d.ts",
|
||||
"default": "./dist/cjs/posix.js"
|
||||
}
|
||||
},
|
||||
"./win32": {
|
||||
"import": {
|
||||
"types": "./dist/mjs/win32.d.ts",
|
||||
"default": "./dist/mjs/win32.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/cjs/win32.d.ts",
|
||||
"default": "./dist/cjs/win32.js"
|
||||
}
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.2.1",
|
||||
"esbuild": "^0.27.3",
|
||||
"prettier": "^3.8.1",
|
||||
"tap": "^21.5.1",
|
||||
"tshy": "^3.1.3",
|
||||
"typedoc": "^0.28.16"
|
||||
"@types/node": "^20.4.5",
|
||||
"@types/tap": "^15.0.8",
|
||||
"c8": "^8.0.1",
|
||||
"mkdirp": "^0.5.1",
|
||||
"prettier": "^2.8.8",
|
||||
"rimraf": "^2.5.0",
|
||||
"sync-content": "^1.0.2",
|
||||
"tap": "^16.3.8",
|
||||
"ts-node": "^10.9.1",
|
||||
"typedoc": "^0.24.8",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"scripts": {
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"prepublishOnly": "git push origin --follow-tags",
|
||||
"prepare": "tshy && bash build.sh",
|
||||
"prepare": "tsc -p tsconfig/cjs.json && tsc -p tsconfig/esm.json && bash ./scripts/fixup.sh",
|
||||
"pretest": "npm run prepare",
|
||||
"presnap": "npm run prepare",
|
||||
"test": "tap",
|
||||
"snap": "tap",
|
||||
"format": "prettier --write .",
|
||||
"typedoc": "typedoc"
|
||||
"test": "c8 tap",
|
||||
"snap": "c8 tap",
|
||||
"format": "prettier --write . --loglevel warn --ignore-path ../../.prettierignore --cache",
|
||||
"typedoc": "typedoc --tsconfig tsconfig/esm.json ./src/*.ts"
|
||||
},
|
||||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
||||
"license": "BlueOak-1.0.0",
|
||||
"license": "ISC",
|
||||
"tap": {
|
||||
"coverage": false,
|
||||
"node-arg": [
|
||||
"--enable-source-maps",
|
||||
"--no-warnings",
|
||||
"--loader",
|
||||
"ts-node/esm"
|
||||
],
|
||||
"ts": false
|
||||
},
|
||||
"prettier": {
|
||||
"semi": false,
|
||||
"printWidth": 75,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"jsxSingleQuote": false,
|
||||
"bracketSameLine": true,
|
||||
"arrowParens": "avoid",
|
||||
"endOfLine": "lf"
|
||||
},
|
||||
"repository": "https://github.com/isaacs/isexe",
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"type": "module"
|
||||
"node": ">=16"
|
||||
}
|
||||
}
|
||||
|
||||
+17
-155
@@ -57,17 +57,10 @@ const options = {
|
||||
|
||||
// for use when you need to clean up something when objects
|
||||
// are evicted from the cache
|
||||
dispose: (value, key, reason) => {
|
||||
dispose: (value, key) => {
|
||||
freeFromMemoryOrWhatever(value)
|
||||
},
|
||||
|
||||
// for use when you need to know that an item is being inserted
|
||||
// note that this does NOT allow you to prevent the insertion,
|
||||
// it just allows you to know about it.
|
||||
onInsert: (value, key, reason) => {
|
||||
logInsertionOrWhatever(key, value)
|
||||
},
|
||||
|
||||
// how long to live in ms
|
||||
ttl: 1000 * 60 * 5,
|
||||
|
||||
@@ -79,7 +72,11 @@ const options = {
|
||||
|
||||
// async method to use for cache.fetch(), for
|
||||
// stale-while-revalidate type of behavior
|
||||
fetchMethod: async (key, staleValue, { options, signal, context }) => {},
|
||||
fetchMethod: async (
|
||||
key,
|
||||
staleValue,
|
||||
{ options, signal, context }
|
||||
) => {},
|
||||
}
|
||||
|
||||
const cache = new LRUCache(options)
|
||||
@@ -157,7 +154,7 @@ const cache = {
|
||||
}
|
||||
cache.timers.set(
|
||||
k,
|
||||
setTimeout(() => cache.delete(k), ttl),
|
||||
setTimeout(() => cache.delete(k), ttl)
|
||||
)
|
||||
cache.data.set(k, v)
|
||||
},
|
||||
@@ -215,95 +212,9 @@ const myGet = (key, value) => {
|
||||
}
|
||||
```
|
||||
|
||||
## Tracing and Observability
|
||||
|
||||
Most methods can accept a `status` option, which is an
|
||||
[`LRUCache.Status`](https://isaacs.github.io/node-lru-cache/interfaces/LRUCache.LRUCache.Status.html)
|
||||
object that will be decorated along the operation with
|
||||
indications about what was done and why.
|
||||
|
||||
Additionally, this library is instrumented using the
|
||||
[`node:diagnostics_channel`](https://nodejs.org/api/diagnostics_channel.html)
|
||||
module on Node and other platforms that support it. In order to
|
||||
get diagnostics metrics, listen on the
|
||||
`channel('lru-cache:metrics')`. To get Tracing Channel traces,
|
||||
subscribe to the `tracingChannel('lru-cache')`. The
|
||||
[`LRUCache.Status`](https://isaacs.github.io/node-lru-cache/interfaces/LRUCache.LRUCache.Status.html)
|
||||
objects will be provided as the message context to those channel
|
||||
listeners.
|
||||
|
||||
For example, you could do the following to get comprehensive
|
||||
information about every LRUCache instance in your application:
|
||||
|
||||
```ts
|
||||
import { tracingChannel, subscribe } from 'node:diagnostics_channel'
|
||||
|
||||
subscribe('lru-cache:metrics', (message, name) => {
|
||||
// name will always be 'lru-cache:metrics'
|
||||
// message will be the LRUCache.Status object for whatever
|
||||
// synchronous operation was performed.
|
||||
console.error('LRUCache Metrics', message)
|
||||
})
|
||||
|
||||
tracingChannel('lru-cache').subscribe({
|
||||
start: status => {
|
||||
// a traced operation is starting
|
||||
},
|
||||
asyncStart: status => {
|
||||
// an async traced operation is starting
|
||||
},
|
||||
asyncEnd: status => {
|
||||
// an async traced operation is ending
|
||||
}
|
||||
error: status => {
|
||||
// a traced operation failed
|
||||
},
|
||||
end: status => {
|
||||
// a traced operation is complete
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
The async `cache.fetch()` and `cache.forceFetch` methods are
|
||||
covered by `tracingChannels`. All the other operations are
|
||||
covered by the `lru-cache:metrics` channel, because they are
|
||||
strictly synchronous, and thus don't have an asynchronous
|
||||
lifecycle to track.
|
||||
|
||||
Note that using `status` objects or using
|
||||
`node:diagnostics_channel` listeners _will_ impose a modest
|
||||
performance penalty. Creating data objects is not ever free; do
|
||||
not believe anyone who tells you otherwise. But it is as small as
|
||||
possible.
|
||||
|
||||
### Platform Compatibility Caveat
|
||||
|
||||
Not all platforms support the `node:diagnostics_channel` module.
|
||||
Currently, this is only available in Node, Bun, and Deno, and
|
||||
some edge computing platforms that provide a Node compatibility
|
||||
layer.
|
||||
|
||||
To work around this, if you are loading in a non-Node
|
||||
environment, the package.json exports will direct your module
|
||||
loader to pull in a version that starts out with a dummy
|
||||
implementation, then does a conditional dynamic `import` of the
|
||||
`node:diagnostics_channel` module, and then swaps out those
|
||||
dummy objects with the real thing if it succeeds. This means that
|
||||
cache metrics and tracing channels started in the first load-time
|
||||
tick of your application will _not_ be covered, except in
|
||||
environments that load using the `require` import
|
||||
condition, or both the `node` and `esm` import conditions
|
||||
together.
|
||||
|
||||
Top-level await _could_ be used to remove this caveat, but that
|
||||
feature is dead on arrival, unfortunately. See
|
||||
[#397](https://github.com/isaacs/node-lru-cache/issues/397) and
|
||||
[#398](https://github.com/isaacs/node-lru-cache/issues/398) for
|
||||
more details.
|
||||
|
||||
## Performance
|
||||
|
||||
As of April 2026, version 11 of this library is one of the most
|
||||
As of January 2022, version 7 of this library is one of the most
|
||||
performant LRU cache implementations in JavaScript.
|
||||
|
||||
Benchmarks can be extremely difficult to get right. In
|
||||
@@ -358,9 +269,9 @@ If performance matters to you:
|
||||
LRUCache](https://yomguithereal.github.io/mnemonist/lru-cache)
|
||||
which uses an Object as its data store.
|
||||
|
||||
2. Failing that, if you can use short non-numeric strings (ie,
|
||||
less than 256 characters) as your keys, and you do not need
|
||||
any of the other features of this library, use [mnemonist's
|
||||
2. Failing that, if at all possible, use short non-numeric
|
||||
strings (ie, less than 256 characters) as your keys, and use
|
||||
[mnemonist's
|
||||
LRUCache](https://yomguithereal.github.io/mnemonist/lru-cache).
|
||||
|
||||
3. If the types of your keys will be anything else, especially
|
||||
@@ -372,63 +283,14 @@ If performance matters to you:
|
||||
(like asynchronous fetching, a variety of TTL staleness
|
||||
options, and so on), then [mnemonist's
|
||||
LRUMap](https://yomguithereal.github.io/mnemonist/lru-map) is
|
||||
also a very good option, and just slightly faster than this
|
||||
module (since it does considerably less).
|
||||
a very good option, and just slightly faster than this module
|
||||
(since it does considerably less).
|
||||
|
||||
4. Do not use a `dispose` function, size tracking, or especially
|
||||
ttl behavior or observability features, unless absolutely
|
||||
needed. These features are convenient, and necessary in some
|
||||
use cases, and every attempt has been made to make the
|
||||
performance impact minimal, but it isn't nothing.
|
||||
|
||||
## Testing
|
||||
|
||||
When writing tests that involve TTL-related functionality, note
|
||||
that this module creates an internal reference to the global
|
||||
`performance` or `Date` objects at import time. If you import it
|
||||
statically at the top level, those references cannot be mocked or
|
||||
overridden in your test environment.
|
||||
|
||||
To avoid this, dynamically import the package within your tests
|
||||
so that the references are captured after your mocks are applied.
|
||||
For example:
|
||||
|
||||
```ts
|
||||
// ❌ Not recommended
|
||||
import { LRUCache } from 'lru-cache'
|
||||
// mocking timers, e.g. jest.useFakeTimers()
|
||||
|
||||
// ✅ Recommended for TTL tests
|
||||
// mocking timers, e.g. jest.useFakeTimers()
|
||||
const { LRUCache } = await import('lru-cache')
|
||||
```
|
||||
|
||||
This ensures that your mocked timers or time sources are
|
||||
respected when testing TTL behavior.
|
||||
|
||||
Additionally, you can pass in a `perf` option when creating your
|
||||
LRUCache instance. This option accepts any object with a `now`
|
||||
method that returns a number.
|
||||
|
||||
For example, this would be a very bare-bones time-mocking system
|
||||
you could use in your tests, without any particular test
|
||||
framework:
|
||||
|
||||
```ts
|
||||
import { LRUCache } from 'lru-cache'
|
||||
|
||||
let myClockTime = 0
|
||||
|
||||
const cache = new LRUCache<string>({
|
||||
max: 10,
|
||||
ttl: 1000,
|
||||
perf: {
|
||||
now: () => myClockTime,
|
||||
},
|
||||
})
|
||||
|
||||
// run tests, updating myClockTime as needed
|
||||
```
|
||||
ttl behavior, unless absolutely needed. These features are
|
||||
convenient, and necessary in some use cases, and every attempt
|
||||
has been made to make the performance impact minimal, but it
|
||||
isn't nothing.
|
||||
|
||||
## Breaking Changes in Version 7
|
||||
|
||||
|
||||
+33
-156
@@ -1,8 +1,6 @@
|
||||
/**
|
||||
* @module LRUCache
|
||||
*/
|
||||
import type { Perf } from './perf.js';
|
||||
export type { Perf } from './perf.js';
|
||||
declare const TYPE: unique symbol;
|
||||
export type PosInt = number & {
|
||||
[TYPE]: 'Positive Integer';
|
||||
@@ -77,20 +75,6 @@ export declare namespace LRUCache {
|
||||
* {@link OptionsBase.disposeAfter} options.
|
||||
*/
|
||||
type Disposer<K, V> = (value: V, key: K, reason: DisposeReason) => void;
|
||||
/**
|
||||
* The reason why an item was added to the cache, passed
|
||||
* to the {@link Inserter} methods.
|
||||
*
|
||||
* - `add`: the item was not found in the cache, and was added
|
||||
* - `update`: the item was in the cache, with the same value provided
|
||||
* - `replace`: the item was in the cache, and replaced
|
||||
*/
|
||||
type InsertReason = 'add' | 'update' | 'replace';
|
||||
/**
|
||||
* A method called upon item insertion, passed as the
|
||||
* {@link OptionsBase.insert}
|
||||
*/
|
||||
type Inserter<K, V> = (value: V, key: K, reason: InsertReason) => void;
|
||||
/**
|
||||
* A function that returns the effective calculated size
|
||||
* of an entry in the cache.
|
||||
@@ -118,16 +102,8 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* The `status` option should be a plain JavaScript object. The following
|
||||
* fields will be set on it appropriately, depending on the situation.
|
||||
*
|
||||
* These objects are also the context objects passed to listeners on the
|
||||
* `lru-cache:metrics` diagnostic channel, and the `lru-cache` tracing
|
||||
* channels, in platforms that support them.
|
||||
*/
|
||||
interface Status<K, V, FC = unknown> {
|
||||
/**
|
||||
* The operation being performed
|
||||
*/
|
||||
op?: 'get' | 'set' | 'memo' | 'fetch' | 'delete' | 'has' | 'peek';
|
||||
interface Status<V> {
|
||||
/**
|
||||
* The status of a set() operation.
|
||||
*
|
||||
@@ -136,37 +112,7 @@ export declare namespace LRUCache {
|
||||
* - replace: the item was in the cache, and replaced
|
||||
* - miss: the item was not added to the cache for some reason
|
||||
*/
|
||||
set?: 'add' | 'update' | 'replace' | 'miss' | 'deleted';
|
||||
/**
|
||||
* The status of a delete() operation.
|
||||
*/
|
||||
delete?: LRUCache.DisposeReason;
|
||||
/**
|
||||
* The result of a peek() operation
|
||||
*
|
||||
* - hit: the item was found and returned
|
||||
* - stale: the item is in the cache, but past its ttl and not returned
|
||||
* - miss: item not in the cache
|
||||
*/
|
||||
peek?: 'hit' | 'miss' | 'stale';
|
||||
/**
|
||||
* The status of a memo() operation.
|
||||
*
|
||||
* - 'hit': the item was found in the cache and returned
|
||||
* - 'miss': the `memoMethod` function was called
|
||||
*/
|
||||
memo?: 'hit' | 'miss';
|
||||
/**
|
||||
* The `context` option provided to a memo or fetch operation
|
||||
*
|
||||
* In practice, of course, this will be the same type as the `FC`
|
||||
* fetch context param used to instantiate the LRUCache, but the
|
||||
* convolutions of threading that through would get quite complicated,
|
||||
* and preclude forcing/forbidding the passing of a `context` param
|
||||
* where it is/isn't expected, which is more valuable for error
|
||||
* prevention.
|
||||
*/
|
||||
context?: unknown;
|
||||
set?: 'add' | 'update' | 'replace' | 'miss';
|
||||
/**
|
||||
* the ttl stored for the item, or undefined if ttls are not used.
|
||||
*/
|
||||
@@ -197,15 +143,8 @@ export declare namespace LRUCache {
|
||||
*/
|
||||
maxEntrySizeExceeded?: true;
|
||||
/**
|
||||
* The key that was set or retrieved
|
||||
*/
|
||||
key?: K;
|
||||
/**
|
||||
* The value that was set
|
||||
*/
|
||||
value?: V;
|
||||
/**
|
||||
* The old value, specified in the case of `set:'replace'`
|
||||
* The old value, specified in the case of `set:'update'` or
|
||||
* `set:'replace'`
|
||||
*/
|
||||
oldValue?: V;
|
||||
/**
|
||||
@@ -231,10 +170,6 @@ export declare namespace LRUCache {
|
||||
* {@link FetchOptions.forceRefresh} was specified.
|
||||
*/
|
||||
fetch?: 'get' | 'inflight' | 'miss' | 'hit' | 'stale' | 'refresh';
|
||||
/**
|
||||
* `forceRefresh` option was used for either a fetch or memo operation
|
||||
*/
|
||||
forceRefresh?: boolean;
|
||||
/**
|
||||
* The {@link OptionsBase.fetchMethod} was called
|
||||
*/
|
||||
@@ -256,7 +191,7 @@ export declare namespace LRUCache {
|
||||
fetchAborted?: true;
|
||||
/**
|
||||
* The abort signal received was ignored, and the fetch was allowed to
|
||||
* continue in the background.
|
||||
* continue.
|
||||
*/
|
||||
fetchAbortIgnored?: true;
|
||||
/**
|
||||
@@ -272,27 +207,15 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* - fetching: The item is currently being fetched. If a previous value
|
||||
* is present and allowed, that will be returned.
|
||||
* - stale: The item is in the cache, and is stale. If it was returned,
|
||||
* then the `returnedStale` flag will be set.
|
||||
* - stale-fetching: The value is being fetched in the background, but is
|
||||
* currently stale. If the stale value was returned, then the
|
||||
* `returnedStale` flag will be set.
|
||||
* - stale: The item is in the cache, and is stale.
|
||||
* - hit: the item is in the cache
|
||||
* - miss: the item is not in the cache
|
||||
*/
|
||||
get?: 'stale' | 'hit' | 'miss' | 'fetching' | 'stale-fetching';
|
||||
get?: 'stale' | 'hit' | 'miss';
|
||||
/**
|
||||
* A fetch or get operation returned a stale value.
|
||||
*/
|
||||
returnedStale?: true;
|
||||
/**
|
||||
* A tracingChannel trace was started for this operation
|
||||
*/
|
||||
trace?: boolean;
|
||||
/**
|
||||
* A reference to the cache instance associated with this operation
|
||||
*/
|
||||
cache?: LRUCache<K & {}, V & {}, FC>;
|
||||
}
|
||||
/**
|
||||
* options which override the options set in the LRUCache constructor
|
||||
@@ -310,7 +233,7 @@ export declare namespace LRUCache {
|
||||
* the fetchMethod is called.
|
||||
*/
|
||||
interface FetcherFetchOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
size?: Size;
|
||||
}
|
||||
/**
|
||||
@@ -332,7 +255,7 @@ export declare namespace LRUCache {
|
||||
*/
|
||||
context?: FC;
|
||||
signal?: AbortSignal;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options provided to {@link LRUCache#fetch} when the FC type is something
|
||||
@@ -345,7 +268,7 @@ export declare namespace LRUCache {
|
||||
* Options provided to {@link LRUCache#fetch} when the FC type is
|
||||
* `undefined` or `void`
|
||||
*/
|
||||
interface FetchOptionsNoContext<K, V, FC extends undefined | void = undefined> extends FetchOptions<K, V, FC> {
|
||||
interface FetchOptionsNoContext<K, V> extends FetchOptions<K, V, undefined> {
|
||||
context?: undefined;
|
||||
}
|
||||
interface MemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
||||
@@ -363,7 +286,7 @@ export declare namespace LRUCache {
|
||||
* be required.
|
||||
*/
|
||||
context?: FC;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options provided to {@link LRUCache#memo} when the FC type is something
|
||||
@@ -376,7 +299,7 @@ export declare namespace LRUCache {
|
||||
* Options provided to {@link LRUCache#memo} when the FC type is
|
||||
* `undefined` or `void`
|
||||
*/
|
||||
interface MemoOptionsNoContext<K, V, FC extends undefined | void = undefined> extends MemoOptions<K, V, FC> {
|
||||
interface MemoOptionsNoContext<K, V> extends MemoOptions<K, V, undefined> {
|
||||
context?: undefined;
|
||||
}
|
||||
/**
|
||||
@@ -397,7 +320,7 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* This is the union of {@link GetOptions} and {@link SetOptions}, plus
|
||||
* {@link MemoOptions.forceRefresh}, and
|
||||
* {@link MemoOptions.context}
|
||||
* {@link MemoerOptions.context}
|
||||
*
|
||||
* Any of these may be modified in the {@link OptionsBase.memoMethod}
|
||||
* function, but the {@link GetOptions} fields will of course have no
|
||||
@@ -405,7 +328,7 @@ export declare namespace LRUCache {
|
||||
* the memoMethod is called.
|
||||
*/
|
||||
interface MemoizerMemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
size?: Size;
|
||||
start?: Milliseconds;
|
||||
}
|
||||
@@ -413,19 +336,18 @@ export declare namespace LRUCache {
|
||||
* Options that may be passed to the {@link LRUCache#has} method.
|
||||
*/
|
||||
interface HasOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'updateAgeOnHas'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#get} method.
|
||||
*/
|
||||
interface GetOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#peek} method.
|
||||
*/
|
||||
interface PeekOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale'> {
|
||||
status?: Status<K, V, FC>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#set} method.
|
||||
@@ -446,7 +368,7 @@ export declare namespace LRUCache {
|
||||
* method is in use.
|
||||
*/
|
||||
start?: Milliseconds;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* The type signature for the {@link OptionsBase.fetchMethod} option.
|
||||
@@ -633,17 +555,6 @@ export declare namespace LRUCache {
|
||||
* `cache.clear()`, or `cache.set(key, undefined)`.
|
||||
*/
|
||||
dispose?: Disposer<K, V>;
|
||||
/**
|
||||
* Function that is called when new items are inserted into the cache,
|
||||
* as `onInsert(value, key, reason)`.
|
||||
*
|
||||
* This can be useful if you need to perform actions when an item is
|
||||
* added, such as logging or tracking insertions.
|
||||
*
|
||||
* Unlike some other options, this may _not_ be overridden by passing
|
||||
* an option to `set()`, for performance and consistency reasons.
|
||||
*/
|
||||
onInsert?: Inserter<K, V>;
|
||||
/**
|
||||
* The same as {@link OptionsBase.dispose}, but called *after* the entry
|
||||
* is completely removed and the cache is once again in a clean state.
|
||||
@@ -699,20 +610,6 @@ export declare namespace LRUCache {
|
||||
* though for most cases, only minimally.
|
||||
*/
|
||||
maxSize?: Size;
|
||||
/**
|
||||
* The effective size for background fetch promises.
|
||||
*
|
||||
* This has no effect unless `maxSize` and `sizeCalculation` are used,
|
||||
* and a {@link LRUCache.OptionsBase.fetchMethod} is provided to
|
||||
* support {@link LRUCache#fetch}.
|
||||
*
|
||||
* If a stale value is present in the cache, then the effective size of
|
||||
* the background fetch is the size of the stale item it will eventually
|
||||
* replace. If not, then this value is used as its effective size.
|
||||
*
|
||||
* @default 1
|
||||
*/
|
||||
backgroundFetchSize?: number;
|
||||
/**
|
||||
* The maximum allowed size for any single item in the cache.
|
||||
*
|
||||
@@ -899,15 +796,6 @@ export declare namespace LRUCache {
|
||||
* call to {@link LRUCache#fetch}.
|
||||
*/
|
||||
ignoreFetchAbort?: boolean;
|
||||
/**
|
||||
* In some cases, you may want to swap out the performance/Date object
|
||||
* used for TTL tracking. This should almost certainly NOT be done in
|
||||
* production environments!
|
||||
*
|
||||
* This value defaults to `global.performance` if it has a `now()` method,
|
||||
* or the `global.Date` object otherwise.
|
||||
*/
|
||||
perf?: Perf;
|
||||
}
|
||||
interface OptionsMaxLimit<K, V, FC> extends OptionsBase<K, V, FC> {
|
||||
max: Count;
|
||||
@@ -949,12 +837,8 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* Changing any of these will alter the defaults for subsequent method calls.
|
||||
*/
|
||||
export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
export declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<K, V> {
|
||||
#private;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.perf}
|
||||
*/
|
||||
get perf(): Perf;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.ttl}
|
||||
*/
|
||||
@@ -1015,8 +899,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
|
||||
*/
|
||||
ignoreFetchAbort: boolean;
|
||||
/** {@link LRUCache.OptionsBase.backgroundFetchSize} */
|
||||
backgroundFetchSize: number;
|
||||
/**
|
||||
* Do not call this method unless you need to inspect the
|
||||
* inner workings of the cache. If anything returned by this
|
||||
@@ -1029,7 +911,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
static unsafeExposeInternals<K extends {}, V extends {}, FC extends unknown = unknown>(c: LRUCache<K, V, FC>): {
|
||||
starts: ZeroArray | undefined;
|
||||
ttls: ZeroArray | undefined;
|
||||
autopurgeTimers: (NodeJS.Timeout | undefined)[] | undefined;
|
||||
sizes: ZeroArray | undefined;
|
||||
keyMap: Map<K, number>;
|
||||
keyList: (K | undefined)[];
|
||||
@@ -1039,8 +920,8 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
readonly head: Index;
|
||||
readonly tail: Index;
|
||||
free: StackLike;
|
||||
isBackgroundFetch: (p: unknown) => p is BackgroundFetch<V>;
|
||||
backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: unknown) => BackgroundFetch<V>;
|
||||
isBackgroundFetch: (p: any) => boolean;
|
||||
backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: any) => BackgroundFetch<V>;
|
||||
moveToTail: (index: number) => void;
|
||||
indexes: (options?: {
|
||||
allowStale: boolean;
|
||||
@@ -1075,10 +956,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* {@link LRUCache.OptionsBase.dispose} (read-only)
|
||||
*/
|
||||
get dispose(): LRUCache.Disposer<K, V> | undefined;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.onInsert} (read-only)
|
||||
*/
|
||||
get onInsert(): LRUCache.Inserter<K, V> | undefined;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
|
||||
*/
|
||||
@@ -1100,7 +977,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* Return a generator yielding `[key, value]` pairs,
|
||||
* in order from least recently used to most recently used.
|
||||
*/
|
||||
rentries(): Generator<(K | V)[], void, unknown>;
|
||||
rentries(): Generator<(K | V | BackgroundFetch<V> | undefined)[], void, unknown>;
|
||||
/**
|
||||
* Return a generator yielding the keys in the cache,
|
||||
* in order from most recently used to least recently used.
|
||||
@@ -1124,7 +1001,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* Return a generator yielding the values in the cache,
|
||||
* in order from least recently used to most recently used.
|
||||
*/
|
||||
rvalues(): Generator<V | undefined, void, unknown>;
|
||||
rvalues(): Generator<V | BackgroundFetch<V> | undefined, void, unknown>;
|
||||
/**
|
||||
* Iterating over the cache itself yields the same results as
|
||||
* {@link LRUCache.entries}
|
||||
@@ -1152,12 +1029,12 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
*
|
||||
* Does not update age or recenty of use, or iterate over stale values.
|
||||
*/
|
||||
forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
||||
forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any): void;
|
||||
/**
|
||||
* The same as {@link LRUCache.forEach} but items are iterated over in
|
||||
* reverse order. (ie, less recently used items are iterated over first.)
|
||||
*/
|
||||
rforEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
||||
rforEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any): void;
|
||||
/**
|
||||
* Delete any stale entries. Returns true if anything was removed,
|
||||
* false otherwise.
|
||||
@@ -1178,7 +1055,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
info(key: K): LRUCache.Entry<V> | undefined;
|
||||
/**
|
||||
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be
|
||||
* passed to {@link LRUCache#load}.
|
||||
* passed to {@link LRLUCache#load}.
|
||||
*
|
||||
* The `start` fields are calculated relative to a portable `Date.now()`
|
||||
* timestamp, even if `performance.now()` is available.
|
||||
@@ -1230,7 +1107,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* If the value is `undefined`, then this is an alias for
|
||||
* `cache.delete(key)`. `undefined` is never stored in the cache.
|
||||
*/
|
||||
set(k: K, v: V | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
|
||||
set(k: K, v: V | BackgroundFetch<V> | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
|
||||
/**
|
||||
* Evict the least recently used item, returning its value or
|
||||
* `undefined` if cache is empty.
|
||||
@@ -1346,23 +1223,23 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* the same time, because they're both waiting on the same
|
||||
* underlying fetchMethod response.
|
||||
*/
|
||||
fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
|
||||
fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<undefined | V>;
|
||||
fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
|
||||
fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<undefined | V>;
|
||||
/**
|
||||
* In some cases, `cache.fetch()` may resolve to `undefined`, either because
|
||||
* a {@link LRUCache.OptionsBase#fetchMethod} was not provided (turning
|
||||
* `cache.fetch(k)` into just an async wrapper around `cache.get(k)`) or
|
||||
* because `ignoreFetchAbort` was specified (either to the constructor or
|
||||
* in the {@link LRUCache.FetchOptions}). Also, the
|
||||
* {@link LRUCache.OptionsBase.fetchMethod} may return `undefined` or `void`, making
|
||||
* {@link OptionsBase.fetchMethod} may return `undefined` or `void`, making
|
||||
* the test even more complicated.
|
||||
*
|
||||
* Because inferring the cases where `undefined` might be returned are so
|
||||
* cumbersome, but testing for `undefined` can also be annoying, this method
|
||||
* can be used, which will reject if `this.fetch()` resolves to undefined.
|
||||
*/
|
||||
forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
|
||||
forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<V>;
|
||||
forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
|
||||
forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<V>;
|
||||
/**
|
||||
* If the key is found in the cache, then this is equivalent to
|
||||
* {@link LRUCache#get}. If not, in the cache, then calculate the value using
|
||||
@@ -1377,8 +1254,8 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* relevant in the course of fetching the data. It is only relevant for the
|
||||
* course of a single `memo()` operation, and discarded afterwards.
|
||||
*/
|
||||
memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
|
||||
memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : never): V;
|
||||
memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
|
||||
memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : never): V;
|
||||
/**
|
||||
* Return a value from the cache. Will update the recency of the cache
|
||||
* entry found.
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+244
-424
File diff suppressed because it is too large
Load Diff
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
+4
-4
File diff suppressed because one or more lines are too long
+33
-156
@@ -1,8 +1,6 @@
|
||||
/**
|
||||
* @module LRUCache
|
||||
*/
|
||||
import type { Perf } from './perf.js';
|
||||
export type { Perf } from './perf.js';
|
||||
declare const TYPE: unique symbol;
|
||||
export type PosInt = number & {
|
||||
[TYPE]: 'Positive Integer';
|
||||
@@ -77,20 +75,6 @@ export declare namespace LRUCache {
|
||||
* {@link OptionsBase.disposeAfter} options.
|
||||
*/
|
||||
type Disposer<K, V> = (value: V, key: K, reason: DisposeReason) => void;
|
||||
/**
|
||||
* The reason why an item was added to the cache, passed
|
||||
* to the {@link Inserter} methods.
|
||||
*
|
||||
* - `add`: the item was not found in the cache, and was added
|
||||
* - `update`: the item was in the cache, with the same value provided
|
||||
* - `replace`: the item was in the cache, and replaced
|
||||
*/
|
||||
type InsertReason = 'add' | 'update' | 'replace';
|
||||
/**
|
||||
* A method called upon item insertion, passed as the
|
||||
* {@link OptionsBase.insert}
|
||||
*/
|
||||
type Inserter<K, V> = (value: V, key: K, reason: InsertReason) => void;
|
||||
/**
|
||||
* A function that returns the effective calculated size
|
||||
* of an entry in the cache.
|
||||
@@ -118,16 +102,8 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* The `status` option should be a plain JavaScript object. The following
|
||||
* fields will be set on it appropriately, depending on the situation.
|
||||
*
|
||||
* These objects are also the context objects passed to listeners on the
|
||||
* `lru-cache:metrics` diagnostic channel, and the `lru-cache` tracing
|
||||
* channels, in platforms that support them.
|
||||
*/
|
||||
interface Status<K, V, FC = unknown> {
|
||||
/**
|
||||
* The operation being performed
|
||||
*/
|
||||
op?: 'get' | 'set' | 'memo' | 'fetch' | 'delete' | 'has' | 'peek';
|
||||
interface Status<V> {
|
||||
/**
|
||||
* The status of a set() operation.
|
||||
*
|
||||
@@ -136,37 +112,7 @@ export declare namespace LRUCache {
|
||||
* - replace: the item was in the cache, and replaced
|
||||
* - miss: the item was not added to the cache for some reason
|
||||
*/
|
||||
set?: 'add' | 'update' | 'replace' | 'miss' | 'deleted';
|
||||
/**
|
||||
* The status of a delete() operation.
|
||||
*/
|
||||
delete?: LRUCache.DisposeReason;
|
||||
/**
|
||||
* The result of a peek() operation
|
||||
*
|
||||
* - hit: the item was found and returned
|
||||
* - stale: the item is in the cache, but past its ttl and not returned
|
||||
* - miss: item not in the cache
|
||||
*/
|
||||
peek?: 'hit' | 'miss' | 'stale';
|
||||
/**
|
||||
* The status of a memo() operation.
|
||||
*
|
||||
* - 'hit': the item was found in the cache and returned
|
||||
* - 'miss': the `memoMethod` function was called
|
||||
*/
|
||||
memo?: 'hit' | 'miss';
|
||||
/**
|
||||
* The `context` option provided to a memo or fetch operation
|
||||
*
|
||||
* In practice, of course, this will be the same type as the `FC`
|
||||
* fetch context param used to instantiate the LRUCache, but the
|
||||
* convolutions of threading that through would get quite complicated,
|
||||
* and preclude forcing/forbidding the passing of a `context` param
|
||||
* where it is/isn't expected, which is more valuable for error
|
||||
* prevention.
|
||||
*/
|
||||
context?: unknown;
|
||||
set?: 'add' | 'update' | 'replace' | 'miss';
|
||||
/**
|
||||
* the ttl stored for the item, or undefined if ttls are not used.
|
||||
*/
|
||||
@@ -197,15 +143,8 @@ export declare namespace LRUCache {
|
||||
*/
|
||||
maxEntrySizeExceeded?: true;
|
||||
/**
|
||||
* The key that was set or retrieved
|
||||
*/
|
||||
key?: K;
|
||||
/**
|
||||
* The value that was set
|
||||
*/
|
||||
value?: V;
|
||||
/**
|
||||
* The old value, specified in the case of `set:'replace'`
|
||||
* The old value, specified in the case of `set:'update'` or
|
||||
* `set:'replace'`
|
||||
*/
|
||||
oldValue?: V;
|
||||
/**
|
||||
@@ -231,10 +170,6 @@ export declare namespace LRUCache {
|
||||
* {@link FetchOptions.forceRefresh} was specified.
|
||||
*/
|
||||
fetch?: 'get' | 'inflight' | 'miss' | 'hit' | 'stale' | 'refresh';
|
||||
/**
|
||||
* `forceRefresh` option was used for either a fetch or memo operation
|
||||
*/
|
||||
forceRefresh?: boolean;
|
||||
/**
|
||||
* The {@link OptionsBase.fetchMethod} was called
|
||||
*/
|
||||
@@ -256,7 +191,7 @@ export declare namespace LRUCache {
|
||||
fetchAborted?: true;
|
||||
/**
|
||||
* The abort signal received was ignored, and the fetch was allowed to
|
||||
* continue in the background.
|
||||
* continue.
|
||||
*/
|
||||
fetchAbortIgnored?: true;
|
||||
/**
|
||||
@@ -272,27 +207,15 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* - fetching: The item is currently being fetched. If a previous value
|
||||
* is present and allowed, that will be returned.
|
||||
* - stale: The item is in the cache, and is stale. If it was returned,
|
||||
* then the `returnedStale` flag will be set.
|
||||
* - stale-fetching: The value is being fetched in the background, but is
|
||||
* currently stale. If the stale value was returned, then the
|
||||
* `returnedStale` flag will be set.
|
||||
* - stale: The item is in the cache, and is stale.
|
||||
* - hit: the item is in the cache
|
||||
* - miss: the item is not in the cache
|
||||
*/
|
||||
get?: 'stale' | 'hit' | 'miss' | 'fetching' | 'stale-fetching';
|
||||
get?: 'stale' | 'hit' | 'miss';
|
||||
/**
|
||||
* A fetch or get operation returned a stale value.
|
||||
*/
|
||||
returnedStale?: true;
|
||||
/**
|
||||
* A tracingChannel trace was started for this operation
|
||||
*/
|
||||
trace?: boolean;
|
||||
/**
|
||||
* A reference to the cache instance associated with this operation
|
||||
*/
|
||||
cache?: LRUCache<K & {}, V & {}, FC>;
|
||||
}
|
||||
/**
|
||||
* options which override the options set in the LRUCache constructor
|
||||
@@ -310,7 +233,7 @@ export declare namespace LRUCache {
|
||||
* the fetchMethod is called.
|
||||
*/
|
||||
interface FetcherFetchOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
size?: Size;
|
||||
}
|
||||
/**
|
||||
@@ -332,7 +255,7 @@ export declare namespace LRUCache {
|
||||
*/
|
||||
context?: FC;
|
||||
signal?: AbortSignal;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options provided to {@link LRUCache#fetch} when the FC type is something
|
||||
@@ -345,7 +268,7 @@ export declare namespace LRUCache {
|
||||
* Options provided to {@link LRUCache#fetch} when the FC type is
|
||||
* `undefined` or `void`
|
||||
*/
|
||||
interface FetchOptionsNoContext<K, V, FC extends undefined | void = undefined> extends FetchOptions<K, V, FC> {
|
||||
interface FetchOptionsNoContext<K, V> extends FetchOptions<K, V, undefined> {
|
||||
context?: undefined;
|
||||
}
|
||||
interface MemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
|
||||
@@ -363,7 +286,7 @@ export declare namespace LRUCache {
|
||||
* be required.
|
||||
*/
|
||||
context?: FC;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options provided to {@link LRUCache#memo} when the FC type is something
|
||||
@@ -376,7 +299,7 @@ export declare namespace LRUCache {
|
||||
* Options provided to {@link LRUCache#memo} when the FC type is
|
||||
* `undefined` or `void`
|
||||
*/
|
||||
interface MemoOptionsNoContext<K, V, FC extends undefined | void = undefined> extends MemoOptions<K, V, FC> {
|
||||
interface MemoOptionsNoContext<K, V> extends MemoOptions<K, V, undefined> {
|
||||
context?: undefined;
|
||||
}
|
||||
/**
|
||||
@@ -397,7 +320,7 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* This is the union of {@link GetOptions} and {@link SetOptions}, plus
|
||||
* {@link MemoOptions.forceRefresh}, and
|
||||
* {@link MemoOptions.context}
|
||||
* {@link MemoerOptions.context}
|
||||
*
|
||||
* Any of these may be modified in the {@link OptionsBase.memoMethod}
|
||||
* function, but the {@link GetOptions} fields will of course have no
|
||||
@@ -405,7 +328,7 @@ export declare namespace LRUCache {
|
||||
* the memoMethod is called.
|
||||
*/
|
||||
interface MemoizerMemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
size?: Size;
|
||||
start?: Milliseconds;
|
||||
}
|
||||
@@ -413,19 +336,18 @@ export declare namespace LRUCache {
|
||||
* Options that may be passed to the {@link LRUCache#has} method.
|
||||
*/
|
||||
interface HasOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'updateAgeOnHas'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#get} method.
|
||||
*/
|
||||
interface GetOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet'> {
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#peek} method.
|
||||
*/
|
||||
interface PeekOptions<K, V, FC> extends Pick<OptionsBase<K, V, FC>, 'allowStale'> {
|
||||
status?: Status<K, V, FC>;
|
||||
}
|
||||
/**
|
||||
* Options that may be passed to the {@link LRUCache#set} method.
|
||||
@@ -446,7 +368,7 @@ export declare namespace LRUCache {
|
||||
* method is in use.
|
||||
*/
|
||||
start?: Milliseconds;
|
||||
status?: Status<K, V, FC>;
|
||||
status?: Status<V>;
|
||||
}
|
||||
/**
|
||||
* The type signature for the {@link OptionsBase.fetchMethod} option.
|
||||
@@ -633,17 +555,6 @@ export declare namespace LRUCache {
|
||||
* `cache.clear()`, or `cache.set(key, undefined)`.
|
||||
*/
|
||||
dispose?: Disposer<K, V>;
|
||||
/**
|
||||
* Function that is called when new items are inserted into the cache,
|
||||
* as `onInsert(value, key, reason)`.
|
||||
*
|
||||
* This can be useful if you need to perform actions when an item is
|
||||
* added, such as logging or tracking insertions.
|
||||
*
|
||||
* Unlike some other options, this may _not_ be overridden by passing
|
||||
* an option to `set()`, for performance and consistency reasons.
|
||||
*/
|
||||
onInsert?: Inserter<K, V>;
|
||||
/**
|
||||
* The same as {@link OptionsBase.dispose}, but called *after* the entry
|
||||
* is completely removed and the cache is once again in a clean state.
|
||||
@@ -699,20 +610,6 @@ export declare namespace LRUCache {
|
||||
* though for most cases, only minimally.
|
||||
*/
|
||||
maxSize?: Size;
|
||||
/**
|
||||
* The effective size for background fetch promises.
|
||||
*
|
||||
* This has no effect unless `maxSize` and `sizeCalculation` are used,
|
||||
* and a {@link LRUCache.OptionsBase.fetchMethod} is provided to
|
||||
* support {@link LRUCache#fetch}.
|
||||
*
|
||||
* If a stale value is present in the cache, then the effective size of
|
||||
* the background fetch is the size of the stale item it will eventually
|
||||
* replace. If not, then this value is used as its effective size.
|
||||
*
|
||||
* @default 1
|
||||
*/
|
||||
backgroundFetchSize?: number;
|
||||
/**
|
||||
* The maximum allowed size for any single item in the cache.
|
||||
*
|
||||
@@ -899,15 +796,6 @@ export declare namespace LRUCache {
|
||||
* call to {@link LRUCache#fetch}.
|
||||
*/
|
||||
ignoreFetchAbort?: boolean;
|
||||
/**
|
||||
* In some cases, you may want to swap out the performance/Date object
|
||||
* used for TTL tracking. This should almost certainly NOT be done in
|
||||
* production environments!
|
||||
*
|
||||
* This value defaults to `global.performance` if it has a `now()` method,
|
||||
* or the `global.Date` object otherwise.
|
||||
*/
|
||||
perf?: Perf;
|
||||
}
|
||||
interface OptionsMaxLimit<K, V, FC> extends OptionsBase<K, V, FC> {
|
||||
max: Count;
|
||||
@@ -949,12 +837,8 @@ export declare namespace LRUCache {
|
||||
*
|
||||
* Changing any of these will alter the defaults for subsequent method calls.
|
||||
*/
|
||||
export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
export declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<K, V> {
|
||||
#private;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.perf}
|
||||
*/
|
||||
get perf(): Perf;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.ttl}
|
||||
*/
|
||||
@@ -1015,8 +899,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
|
||||
*/
|
||||
ignoreFetchAbort: boolean;
|
||||
/** {@link LRUCache.OptionsBase.backgroundFetchSize} */
|
||||
backgroundFetchSize: number;
|
||||
/**
|
||||
* Do not call this method unless you need to inspect the
|
||||
* inner workings of the cache. If anything returned by this
|
||||
@@ -1029,7 +911,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
static unsafeExposeInternals<K extends {}, V extends {}, FC extends unknown = unknown>(c: LRUCache<K, V, FC>): {
|
||||
starts: ZeroArray | undefined;
|
||||
ttls: ZeroArray | undefined;
|
||||
autopurgeTimers: (NodeJS.Timeout | undefined)[] | undefined;
|
||||
sizes: ZeroArray | undefined;
|
||||
keyMap: Map<K, number>;
|
||||
keyList: (K | undefined)[];
|
||||
@@ -1039,8 +920,8 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
readonly head: Index;
|
||||
readonly tail: Index;
|
||||
free: StackLike;
|
||||
isBackgroundFetch: (p: unknown) => p is BackgroundFetch<V>;
|
||||
backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: unknown) => BackgroundFetch<V>;
|
||||
isBackgroundFetch: (p: any) => boolean;
|
||||
backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: any) => BackgroundFetch<V>;
|
||||
moveToTail: (index: number) => void;
|
||||
indexes: (options?: {
|
||||
allowStale: boolean;
|
||||
@@ -1075,10 +956,6 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* {@link LRUCache.OptionsBase.dispose} (read-only)
|
||||
*/
|
||||
get dispose(): LRUCache.Disposer<K, V> | undefined;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.onInsert} (read-only)
|
||||
*/
|
||||
get onInsert(): LRUCache.Inserter<K, V> | undefined;
|
||||
/**
|
||||
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
|
||||
*/
|
||||
@@ -1100,7 +977,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* Return a generator yielding `[key, value]` pairs,
|
||||
* in order from least recently used to most recently used.
|
||||
*/
|
||||
rentries(): Generator<(K | V)[], void, unknown>;
|
||||
rentries(): Generator<(K | V | BackgroundFetch<V> | undefined)[], void, unknown>;
|
||||
/**
|
||||
* Return a generator yielding the keys in the cache,
|
||||
* in order from most recently used to least recently used.
|
||||
@@ -1124,7 +1001,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* Return a generator yielding the values in the cache,
|
||||
* in order from least recently used to most recently used.
|
||||
*/
|
||||
rvalues(): Generator<V | undefined, void, unknown>;
|
||||
rvalues(): Generator<V | BackgroundFetch<V> | undefined, void, unknown>;
|
||||
/**
|
||||
* Iterating over the cache itself yields the same results as
|
||||
* {@link LRUCache.entries}
|
||||
@@ -1152,12 +1029,12 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
*
|
||||
* Does not update age or recenty of use, or iterate over stale values.
|
||||
*/
|
||||
forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
||||
forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any): void;
|
||||
/**
|
||||
* The same as {@link LRUCache.forEach} but items are iterated over in
|
||||
* reverse order. (ie, less recently used items are iterated over first.)
|
||||
*/
|
||||
rforEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown, thisp?: unknown): void;
|
||||
rforEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any): void;
|
||||
/**
|
||||
* Delete any stale entries. Returns true if anything was removed,
|
||||
* false otherwise.
|
||||
@@ -1178,7 +1055,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
info(key: K): LRUCache.Entry<V> | undefined;
|
||||
/**
|
||||
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be
|
||||
* passed to {@link LRUCache#load}.
|
||||
* passed to {@link LRLUCache#load}.
|
||||
*
|
||||
* The `start` fields are calculated relative to a portable `Date.now()`
|
||||
* timestamp, even if `performance.now()` is available.
|
||||
@@ -1230,7 +1107,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* If the value is `undefined`, then this is an alias for
|
||||
* `cache.delete(key)`. `undefined` is never stored in the cache.
|
||||
*/
|
||||
set(k: K, v: V | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
|
||||
set(k: K, v: V | BackgroundFetch<V> | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
|
||||
/**
|
||||
* Evict the least recently used item, returning its value or
|
||||
* `undefined` if cache is empty.
|
||||
@@ -1346,23 +1223,23 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* the same time, because they're both waiting on the same
|
||||
* underlying fetchMethod response.
|
||||
*/
|
||||
fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
|
||||
fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<undefined | V>;
|
||||
fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
|
||||
fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<undefined | V>;
|
||||
/**
|
||||
* In some cases, `cache.fetch()` may resolve to `undefined`, either because
|
||||
* a {@link LRUCache.OptionsBase#fetchMethod} was not provided (turning
|
||||
* `cache.fetch(k)` into just an async wrapper around `cache.get(k)`) or
|
||||
* because `ignoreFetchAbort` was specified (either to the constructor or
|
||||
* in the {@link LRUCache.FetchOptions}). Also, the
|
||||
* {@link LRUCache.OptionsBase.fetchMethod} may return `undefined` or `void`, making
|
||||
* {@link OptionsBase.fetchMethod} may return `undefined` or `void`, making
|
||||
* the test even more complicated.
|
||||
*
|
||||
* Because inferring the cases where `undefined` might be returned are so
|
||||
* cumbersome, but testing for `undefined` can also be annoying, this method
|
||||
* can be used, which will reject if `this.fetch()` resolves to undefined.
|
||||
*/
|
||||
forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
|
||||
forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<V>;
|
||||
forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
|
||||
forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<V>;
|
||||
/**
|
||||
* If the key is found in the cache, then this is equivalent to
|
||||
* {@link LRUCache#get}. If not, in the cache, then calculate the value using
|
||||
@@ -1377,8 +1254,8 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
|
||||
* relevant in the course of fetching the data. It is only relevant for the
|
||||
* course of a single `memo()` operation, and discarded afterwards.
|
||||
*/
|
||||
memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
|
||||
memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V, FC> : never): V;
|
||||
memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
|
||||
memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : never): V;
|
||||
/**
|
||||
* Return a value from the cache. Will update the recency of the cache
|
||||
* entry found.
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+244
-424
File diff suppressed because it is too large
Load Diff
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
+4
-4
File diff suppressed because one or more lines are too long
+44
-82
@@ -1,7 +1,10 @@
|
||||
{
|
||||
"name": "lru-cache",
|
||||
"publishConfig": {
|
||||
"tag": "legacy-v10"
|
||||
},
|
||||
"description": "A cache object that deletes the least-recently-used items.",
|
||||
"version": "11.5.0",
|
||||
"version": "10.4.3",
|
||||
"author": "Isaac Z. Schlueter <i@izs.me>",
|
||||
"keywords": [
|
||||
"mru",
|
||||
@@ -11,7 +14,7 @@
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"build": "npm run prepare",
|
||||
"prepare": "tshy && bash scripts/build.sh",
|
||||
"prepare": "tshy && bash fixup.sh",
|
||||
"pretest": "npm run prepare",
|
||||
"presnap": "npm run prepare",
|
||||
"test": "tap",
|
||||
@@ -25,130 +28,89 @@
|
||||
"prebenchmark": "npm run prepare",
|
||||
"benchmark": "make -C benchmark",
|
||||
"preprofile": "npm run prepare",
|
||||
"profile": "make -C benchmark profile",
|
||||
"lint": "oxlint --fix src test",
|
||||
"postsnap": "npm run lint",
|
||||
"postlint": "npm run format"
|
||||
"profile": "make -C benchmark profile"
|
||||
},
|
||||
"main": "./dist/commonjs/index.min.js",
|
||||
"main": "./dist/commonjs/index.js",
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"tshy": {
|
||||
"esmDialects": [
|
||||
"browser",
|
||||
"node"
|
||||
],
|
||||
"commonjsDialects": [
|
||||
"browser",
|
||||
"node"
|
||||
],
|
||||
"exports": {
|
||||
"./raw": "./src/index.ts",
|
||||
".": {
|
||||
".": "./src/index.ts",
|
||||
"./min": {
|
||||
"import": {
|
||||
"browser": {
|
||||
"types": "./dist/esm/browser/index.d.ts",
|
||||
"default": "./dist/esm/browser/index.min.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/esm/node/index.d.ts",
|
||||
"default": "./dist/esm/node/index.min.js"
|
||||
},
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.min.js"
|
||||
},
|
||||
"require": {
|
||||
"browser": {
|
||||
"types": "./dist/commonjs/browser/index.d.ts",
|
||||
"default": "./dist/commonjs/browser/index.min.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/commonjs/node/index.d.ts",
|
||||
"default": "./dist/commonjs/node/index.min.js"
|
||||
},
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.min.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"selfLink": false
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/isaacs/node-lru-cache.git"
|
||||
"url": "git://github.com/isaacs/node-lru-cache.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.2.5",
|
||||
"@types/tap": "^15.0.6",
|
||||
"benchmark": "^2.1.4",
|
||||
"esbuild": "^0.28.0",
|
||||
"esbuild": "^0.17.11",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"marked": "^4.2.12",
|
||||
"mkdirp": "^3.0.1",
|
||||
"oxlint": "^1.65.0",
|
||||
"oxlint-tsgolint": "^0.22.1",
|
||||
"prettier": "^3.8.3",
|
||||
"tap": "^21.7.4",
|
||||
"tshy": "^4.1.2",
|
||||
"typedoc": "^0.28.19"
|
||||
"mkdirp": "^2.1.5",
|
||||
"prettier": "^2.6.2",
|
||||
"tap": "^20.0.3",
|
||||
"tshy": "^2.0.0",
|
||||
"tslib": "^2.4.0",
|
||||
"typedoc": "^0.25.3",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"license": "BlueOak-1.0.0",
|
||||
"license": "ISC",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": "20 || >=22"
|
||||
"prettier": {
|
||||
"semi": false,
|
||||
"printWidth": 70,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"jsxSingleQuote": false,
|
||||
"bracketSameLine": true,
|
||||
"arrowParens": "avoid",
|
||||
"endOfLine": "lf"
|
||||
},
|
||||
"tap": {
|
||||
"node-arg": [
|
||||
"--expose-gc"
|
||||
],
|
||||
"plugin": [
|
||||
"@tapjs/clock"
|
||||
]
|
||||
},
|
||||
"exports": {
|
||||
"./raw": {
|
||||
".": {
|
||||
"import": {
|
||||
"browser": {
|
||||
"types": "./dist/esm/browser/index.d.ts",
|
||||
"default": "./dist/esm/browser/index.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/esm/node/index.d.ts",
|
||||
"default": "./dist/esm/node/index.js"
|
||||
},
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
},
|
||||
"require": {
|
||||
"browser": {
|
||||
"types": "./dist/commonjs/browser/index.d.ts",
|
||||
"default": "./dist/commonjs/browser/index.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/commonjs/node/index.d.ts",
|
||||
"default": "./dist/commonjs/node/index.js"
|
||||
},
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.js"
|
||||
}
|
||||
},
|
||||
".": {
|
||||
"./min": {
|
||||
"import": {
|
||||
"browser": {
|
||||
"types": "./dist/esm/browser/index.d.ts",
|
||||
"default": "./dist/esm/browser/index.min.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/esm/node/index.d.ts",
|
||||
"default": "./dist/esm/node/index.min.js"
|
||||
},
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.min.js"
|
||||
},
|
||||
"require": {
|
||||
"browser": {
|
||||
"types": "./dist/commonjs/browser/index.d.ts",
|
||||
"default": "./dist/commonjs/browser/index.min.js"
|
||||
},
|
||||
"node": {
|
||||
"types": "./dist/commonjs/node/index.d.ts",
|
||||
"default": "./dist/commonjs/node/index.min.js"
|
||||
},
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.min.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": "module",
|
||||
"module": "./dist/esm/index.min.js"
|
||||
"module": "./dist/esm/index.js"
|
||||
}
|
||||
|
||||
+6
-6
@@ -2,7 +2,7 @@
|
||||
"author": "GitHub Inc.",
|
||||
"name": "which",
|
||||
"description": "Like which(1) unix command. Find the first instance of an executable in the PATH.",
|
||||
"version": "6.0.1",
|
||||
"version": "5.0.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/npm/node-which.git"
|
||||
@@ -13,11 +13,11 @@
|
||||
},
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"isexe": "^4.0.0"
|
||||
"isexe": "^3.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^6.0.0",
|
||||
"@npmcli/template-oss": "4.28.1",
|
||||
"@npmcli/eslint-config": "^5.0.0",
|
||||
"@npmcli/template-oss": "4.23.3",
|
||||
"tap": "^16.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
@@ -42,11 +42,11 @@
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.28.1",
|
||||
"version": "4.23.3",
|
||||
"publish": "true"
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/git",
|
||||
"version": "7.0.2",
|
||||
"version": "6.0.3",
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
"bin/",
|
||||
@@ -33,22 +33,22 @@
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^5.0.0",
|
||||
"@npmcli/template-oss": "4.24.1",
|
||||
"npm-package-arg": "^13.0.0",
|
||||
"npm-package-arg": "^12.0.1",
|
||||
"slash": "^3.0.0",
|
||||
"tap": "^16.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@gar/promise-retry": "^1.0.0",
|
||||
"@npmcli/promise-spawn": "^9.0.0",
|
||||
"ini": "^6.0.0",
|
||||
"lru-cache": "^11.2.1",
|
||||
"npm-pick-manifest": "^11.0.1",
|
||||
"proc-log": "^6.0.0",
|
||||
"@npmcli/promise-spawn": "^8.0.0",
|
||||
"ini": "^5.0.0",
|
||||
"lru-cache": "^10.0.1",
|
||||
"npm-pick-manifest": "^10.0.0",
|
||||
"proc-log": "^5.0.0",
|
||||
"promise-retry": "^2.0.1",
|
||||
"semver": "^7.3.5",
|
||||
"which": "^6.0.0"
|
||||
"which": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/installed-package-contents",
|
||||
"version": "4.0.0",
|
||||
"version": "3.0.0",
|
||||
"description": "Get the list of files installed in a package in node_modules, including bundled dependencies",
|
||||
"author": "GitHub Inc.",
|
||||
"main": "lib/index.js",
|
||||
@@ -20,12 +20,12 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^5.0.0",
|
||||
"@npmcli/template-oss": "4.27.1",
|
||||
"@npmcli/template-oss": "4.23.3",
|
||||
"tap": "^16.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"npm-bundled": "^5.0.0",
|
||||
"npm-normalize-package-bin": "^5.0.0"
|
||||
"npm-bundled": "^4.0.0",
|
||||
"npm-normalize-package-bin": "^4.0.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -36,11 +36,11 @@
|
||||
"lib/"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.27.1",
|
||||
"version": "4.23.3",
|
||||
"publish": true
|
||||
},
|
||||
"tap": {
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/node-gyp",
|
||||
"version": "5.0.0",
|
||||
"version": "4.0.0",
|
||||
"description": "Tools for dealing with node-gyp packages",
|
||||
"scripts": {
|
||||
"test": "tap",
|
||||
@@ -30,15 +30,15 @@
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^5.0.0",
|
||||
"@npmcli/template-oss": "4.27.1",
|
||||
"@npmcli/template-oss": "4.23.3",
|
||||
"tap": "^16.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.27.1",
|
||||
"version": "4.23.3",
|
||||
"publish": true
|
||||
},
|
||||
"tap": {
|
||||
|
||||
+3
-17
@@ -144,10 +144,6 @@ Like `normalize` but intended for preparing package.json files for publish.
|
||||
|
||||
---
|
||||
|
||||
### `PackageJson.syncNormalize()`
|
||||
|
||||
This calls normalize synchronously. Most consumers of this package should avoid using this. It was added because some parts of npm were normalizing package content in class constructors and needed this affordance. It will silently ignore any asynchronous steps asked for. Again, this is a compatiblity affordance for some code in npm that is currently impossible to change without a significant semver major change, and is best not used.
|
||||
|
||||
### **static** `async PackageJson.prepare(path, opts = {})`
|
||||
|
||||
Convenience static that calls `load` before calling `prepare`
|
||||
@@ -237,20 +233,10 @@ pkgJson.content
|
||||
|
||||
---
|
||||
|
||||
### `async PackageJson.save([options])`
|
||||
### `async PackageJson.save()`
|
||||
|
||||
|
||||
Saves the current `content` to the same location used when calling `load()`.
|
||||
|
||||
- `options`: `Object` (optional)
|
||||
- `sort`: `Boolean` (optional) — If true, sorts the keys in the resulting `package.json` file for consistency and readability.
|
||||
|
||||
> [!NOTE]
|
||||
> The sort order for `package.json` is based on the conventions from
|
||||
> [sort-package-json](https://github.com/keithamus/sort-package-json/blob/main/defaultRules.md),
|
||||
> cross-checked with the official npm types and documentation:
|
||||
> - https://github.com/npm/types/blob/main/types/index.d.ts#L104
|
||||
> - https://docs.npmjs.com/cli/configuring-npm/package-json
|
||||
Saves the current `content` to the same location used when calling
|
||||
`load()`.
|
||||
|
||||
## LICENSE
|
||||
|
||||
|
||||
+16
-26
@@ -5,7 +5,7 @@ const parseJSON = require('json-parse-even-better-errors')
|
||||
const updateDeps = require('./update-dependencies.js')
|
||||
const updateScripts = require('./update-scripts.js')
|
||||
const updateWorkspaces = require('./update-workspaces.js')
|
||||
const { normalize, syncNormalize } = require('./normalize.js')
|
||||
const normalize = require('./normalize.js')
|
||||
const { read, parse } = require('./read-package.js')
|
||||
const { packageSort } = require('./sort.js')
|
||||
|
||||
@@ -25,18 +25,6 @@ const knownKeys = new Set([
|
||||
])
|
||||
|
||||
class PackageJson {
|
||||
// npm pkg fix
|
||||
static fixSteps = Object.freeze([
|
||||
'binRefs',
|
||||
'bundleDependencies',
|
||||
'fixName',
|
||||
'fixVersionField',
|
||||
'fixRepositoryField',
|
||||
'fixDependencies',
|
||||
'devDependencies',
|
||||
'scriptpath',
|
||||
])
|
||||
|
||||
static normalizeSteps = Object.freeze([
|
||||
'_id',
|
||||
'_attributes',
|
||||
@@ -46,7 +34,20 @@ class PackageJson {
|
||||
'scripts',
|
||||
'funding',
|
||||
'bin',
|
||||
'binDir',
|
||||
])
|
||||
|
||||
// npm pkg fix
|
||||
static fixSteps = Object.freeze([
|
||||
'binRefs',
|
||||
'bundleDependencies',
|
||||
'bundleDependenciesFalse',
|
||||
'fixName',
|
||||
'fixNameField',
|
||||
'fixVersionField',
|
||||
'fixRepositoryField',
|
||||
'fixDependencies',
|
||||
'devDependencies',
|
||||
'scriptpath',
|
||||
])
|
||||
|
||||
static prepareSteps = Object.freeze([
|
||||
@@ -163,11 +164,7 @@ class PackageJson {
|
||||
return this
|
||||
}
|
||||
|
||||
// Manually set data from an existing object
|
||||
fromContent (data) {
|
||||
if (!data || typeof data !== 'object') {
|
||||
throw new Error('Content data must be an object')
|
||||
}
|
||||
this.#manifest = data
|
||||
this.#canSave = false
|
||||
return this
|
||||
@@ -225,7 +222,7 @@ class PackageJson {
|
||||
this.#manifest = step({ content, originalContent: this.content })
|
||||
}
|
||||
|
||||
// unknown properties will just be overwritten
|
||||
// unknown properties will just be overwitten
|
||||
for (const [key, value] of Object.entries(content)) {
|
||||
if (!knownKeys.has(key)) {
|
||||
this.content[key] = value
|
||||
@@ -262,13 +259,6 @@ class PackageJson {
|
||||
}
|
||||
}
|
||||
|
||||
// steps is NOT overrideable here because this is a legacy function that's not being used in new places
|
||||
syncNormalize (opts = {}) {
|
||||
opts.steps = this.constructor.normalizeSteps.filter(s => s !== '_attributes')
|
||||
syncNormalize(this, opts)
|
||||
return this
|
||||
}
|
||||
|
||||
async normalize (opts = {}) {
|
||||
if (!opts.steps) {
|
||||
opts.steps = this.constructor.normalizeSteps
|
||||
|
||||
+9
-6
@@ -1,8 +1,8 @@
|
||||
// Originally normalize-package-data
|
||||
|
||||
const { URL } = require('node:url')
|
||||
const url = require('node:url')
|
||||
const hostedGitInfo = require('hosted-git-info')
|
||||
const validateLicense = require('./license.js')
|
||||
const validateLicense = require('validate-npm-package-license')
|
||||
|
||||
const typos = {
|
||||
dependancies: 'dependencies',
|
||||
@@ -123,7 +123,8 @@ function normalizeData (data, changes) {
|
||||
if (typeof data.bugs === 'string') {
|
||||
if (isEmail(data.bugs)) {
|
||||
data.bugs = { email: data.bugs }
|
||||
} else if (URL.canParse(data.bugs)) {
|
||||
/* eslint-disable-next-line node/no-deprecated-api */
|
||||
} else if (url.parse(data.bugs).protocol) {
|
||||
data.bugs = { url: data.bugs }
|
||||
} else {
|
||||
changes?.push(`Bug string field must be url, email, or {email,url}`)
|
||||
@@ -139,7 +140,8 @@ function normalizeData (data, changes) {
|
||||
const oldBugs = data.bugs
|
||||
data.bugs = {}
|
||||
if (oldBugs.url) {
|
||||
if (URL.canParse(oldBugs.url)) {
|
||||
/* eslint-disable-next-line node/no-deprecated-api */
|
||||
if (typeof (oldBugs.url) === 'string' && url.parse(oldBugs.url).protocol) {
|
||||
data.bugs.url = oldBugs.url
|
||||
} else {
|
||||
changes?.push('bugs.url field must be a string url. Deleted.')
|
||||
@@ -214,7 +216,8 @@ function normalizeData (data, changes) {
|
||||
changes?.push('homepage field must be a string url. Deleted.')
|
||||
delete data.homepage
|
||||
} else {
|
||||
if (!URL.canParse(data.homepage)) {
|
||||
/* eslint-disable-next-line node/no-deprecated-api */
|
||||
if (!url.parse(data.homepage).protocol) {
|
||||
data.homepage = 'http://' + data.homepage
|
||||
}
|
||||
}
|
||||
@@ -230,7 +233,7 @@ function normalizeData (data, changes) {
|
||||
changes?.push('No license field.')
|
||||
} else if (typeof (license) !== 'string' || license.length < 1 || license.trim() === '') {
|
||||
changes?.push('license should be a valid SPDX license expression')
|
||||
} else if (!validateLicense(license)) {
|
||||
} else if (!validateLicense(license).validForNewPackages) {
|
||||
changes?.push('license should be a valid SPDX license expression')
|
||||
}
|
||||
// fixPeople
|
||||
|
||||
+211
-224
@@ -67,7 +67,7 @@ function normalizePackageBin (pkg, changes) {
|
||||
changes?.push(`"bin[${binKey}]" was renamed to "bin[${base}]"`)
|
||||
}
|
||||
if (binTarget !== pkg.bin[binKey]) {
|
||||
changes?.push(`"bin[${base}]" script name ${binTarget} was invalid and removed`)
|
||||
changes?.push(`"bin[${base}]" script name was cleaned`)
|
||||
}
|
||||
pkg.bin[base] = binTarget
|
||||
}
|
||||
@@ -133,9 +133,15 @@ function secureAndUnixifyPath (ref) {
|
||||
return secured.startsWith('./') ? '' : secured
|
||||
}
|
||||
|
||||
// Only steps that can be ran synchronously. There are some object constructors (i.e. Aborist Node) that need synchronous normalization so here we are.
|
||||
function syncSteps (pkg, { strict, steps, changes, allowLegacyCase }) {
|
||||
// We don't want the `changes` array in here by default because this is a hot
|
||||
// path for parsing packuments during install. So the calling method passes it
|
||||
// in if it wants to track changes.
|
||||
const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase }) => {
|
||||
if (!pkg.content) {
|
||||
throw new Error('Can not normalize without content')
|
||||
}
|
||||
const data = pkg.content
|
||||
const scripts = data.scripts || {}
|
||||
const pkgId = `${data.name ?? ''}@${data.version ?? ''}`
|
||||
|
||||
// name and version are load bearing so we have to clean them up first
|
||||
@@ -189,7 +195,6 @@ function syncSteps (pkg, { strict, steps, changes, allowLegacyCase }) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove attributes that start with "_"
|
||||
if (steps.includes('_attributes')) {
|
||||
for (const key in data) {
|
||||
@@ -209,14 +214,14 @@ function syncSteps (pkg, { strict, steps, changes, allowLegacyCase }) {
|
||||
}
|
||||
|
||||
// fix bundledDependencies typo
|
||||
// normalize bundleDependencies
|
||||
if (steps.includes('bundledDependencies')) {
|
||||
if (data.bundleDependencies === undefined && data.bundledDependencies !== undefined) {
|
||||
data.bundleDependencies = data.bundledDependencies
|
||||
changes?.push(`Deleted incorrect "bundledDependencies"`)
|
||||
}
|
||||
changes?.push(`Deleted incorrect "bundledDependencies"`)
|
||||
delete data.bundledDependencies
|
||||
}
|
||||
|
||||
// expand "bundleDependencies: true or translate from object"
|
||||
if (steps.includes('bundleDependencies')) {
|
||||
const bd = data.bundleDependencies
|
||||
@@ -255,6 +260,32 @@ function syncSteps (pkg, { strict, steps, changes, allowLegacyCase }) {
|
||||
}
|
||||
}
|
||||
|
||||
// add "install" attribute if any "*.gyp" files exist
|
||||
if (steps.includes('gypfile')) {
|
||||
if (!scripts.install && !scripts.preinstall && data.gypfile !== false) {
|
||||
const files = await lazyLoadGlob()('*.gyp', { cwd: pkg.path })
|
||||
if (files.length) {
|
||||
scripts.install = 'node-gyp rebuild'
|
||||
data.scripts = scripts
|
||||
data.gypfile = true
|
||||
changes?.push(`"scripts.install" was set to "node-gyp rebuild"`)
|
||||
changes?.push(`"gypfile" was set to "true"`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add "start" attribute if "server.js" exists
|
||||
if (steps.includes('serverjs') && !scripts.start) {
|
||||
try {
|
||||
await fs.access(path.join(pkg.path, 'server.js'))
|
||||
scripts.start = 'node server.js'
|
||||
data.scripts = scripts
|
||||
changes?.push('"scripts.start" was set to "node server.js"')
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
// strip "node_modules/.bin" from scripts entries
|
||||
// remove invalid scripts entries (non-strings)
|
||||
if ((steps.includes('scripts') || steps.includes('scriptpath')) && data.scripts !== undefined) {
|
||||
@@ -282,6 +313,179 @@ function syncSteps (pkg, { strict, steps, changes, allowLegacyCase }) {
|
||||
}
|
||||
}
|
||||
|
||||
// populate "authors" attribute
|
||||
if (steps.includes('authors') && !data.contributors) {
|
||||
try {
|
||||
const authorData = await fs.readFile(path.join(pkg.path, 'AUTHORS'), 'utf8')
|
||||
const authors = authorData.split(/\r?\n/g)
|
||||
.map(line => line.replace(/^\s*#.*$/, '').trim())
|
||||
.filter(line => line)
|
||||
data.contributors = authors
|
||||
changes?.push('"contributors" was auto-populated with the contents of the "AUTHORS" file')
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
// populate "readme" attribute
|
||||
if (steps.includes('readme') && !data.readme) {
|
||||
const mdre = /\.m?a?r?k?d?o?w?n?$/i
|
||||
const files = await lazyLoadGlob()('{README,README.*}', {
|
||||
cwd: pkg.path,
|
||||
nocase: true,
|
||||
mark: true,
|
||||
})
|
||||
let readmeFile
|
||||
for (const file of files) {
|
||||
// don't accept directories.
|
||||
if (!file.endsWith(path.sep)) {
|
||||
if (file.match(mdre)) {
|
||||
readmeFile = file
|
||||
break
|
||||
}
|
||||
if (file.endsWith('README')) {
|
||||
readmeFile = file
|
||||
}
|
||||
}
|
||||
}
|
||||
if (readmeFile) {
|
||||
const readmeData = await fs.readFile(path.join(pkg.path, readmeFile), 'utf8')
|
||||
data.readme = readmeData
|
||||
data.readmeFilename = readmeFile
|
||||
changes?.push(`"readme" was set to the contents of ${readmeFile}`)
|
||||
changes?.push(`"readmeFilename" was set to ${readmeFile}`)
|
||||
}
|
||||
if (!data.readme) {
|
||||
data.readme = 'ERROR: No README data found!'
|
||||
}
|
||||
}
|
||||
|
||||
// expand directories.man
|
||||
if (steps.includes('mans')) {
|
||||
if (data.directories?.man && !data.man) {
|
||||
const manDir = secureAndUnixifyPath(data.directories.man)
|
||||
const cwd = path.resolve(pkg.path, manDir)
|
||||
const files = await lazyLoadGlob()('**/*.[0-9]', { cwd })
|
||||
data.man = files.map(man =>
|
||||
path.relative(pkg.path, path.join(cwd, man)).split(path.sep).join('/')
|
||||
)
|
||||
}
|
||||
normalizePackageMan(data, changes)
|
||||
}
|
||||
|
||||
if (steps.includes('bin') || steps.includes('binDir') || steps.includes('binRefs')) {
|
||||
normalizePackageBin(data, changes)
|
||||
}
|
||||
|
||||
// expand "directories.bin"
|
||||
if (steps.includes('binDir') && data.directories?.bin && !data.bin) {
|
||||
const binsDir = path.resolve(pkg.path, secureAndUnixifyPath(data.directories.bin))
|
||||
const bins = await lazyLoadGlob()('**', { cwd: binsDir })
|
||||
data.bin = bins.reduce((acc, binFile) => {
|
||||
if (binFile && !binFile.startsWith('.')) {
|
||||
const binName = path.basename(binFile)
|
||||
acc[binName] = path.join(data.directories.bin, binFile)
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
// *sigh*
|
||||
normalizePackageBin(data, changes)
|
||||
}
|
||||
|
||||
// populate "gitHead" attribute
|
||||
if (steps.includes('gitHead') && !data.gitHead) {
|
||||
const git = require('@npmcli/git')
|
||||
const gitRoot = await git.find({ cwd: pkg.path, root })
|
||||
let head
|
||||
if (gitRoot) {
|
||||
try {
|
||||
head = await fs.readFile(path.resolve(gitRoot, '.git/HEAD'), 'utf8')
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
let headData
|
||||
if (head) {
|
||||
if (head.startsWith('ref: ')) {
|
||||
const headRef = head.replace(/^ref: /, '').trim()
|
||||
const headFile = path.resolve(gitRoot, '.git', headRef)
|
||||
try {
|
||||
headData = await fs.readFile(headFile, 'utf8')
|
||||
headData = headData.replace(/^ref: /, '').trim()
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
if (!headData) {
|
||||
const packFile = path.resolve(gitRoot, '.git/packed-refs')
|
||||
try {
|
||||
let refs = await fs.readFile(packFile, 'utf8')
|
||||
if (refs) {
|
||||
refs = refs.split('\n')
|
||||
for (let i = 0; i < refs.length; i++) {
|
||||
const match = refs[i].match(/^([0-9a-f]{40}) (.+)$/)
|
||||
if (match && match[2].trim() === headRef) {
|
||||
headData = match[1]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
} else {
|
||||
headData = head.trim()
|
||||
}
|
||||
}
|
||||
if (headData) {
|
||||
data.gitHead = headData
|
||||
}
|
||||
}
|
||||
|
||||
// populate "types" attribute
|
||||
if (steps.includes('fillTypes')) {
|
||||
const index = data.main || 'index.js'
|
||||
|
||||
if (typeof index !== 'string') {
|
||||
throw new TypeError('The "main" attribute must be of type string.')
|
||||
}
|
||||
|
||||
// TODO exports is much more complicated than this in verbose format
|
||||
// We need to support for instance
|
||||
|
||||
// "exports": {
|
||||
// ".": [
|
||||
// {
|
||||
// "default": "./lib/npm.js"
|
||||
// },
|
||||
// "./lib/npm.js"
|
||||
// ],
|
||||
// "./package.json": "./package.json"
|
||||
// },
|
||||
// as well as conditional exports
|
||||
|
||||
// if (data.exports && typeof data.exports === 'string') {
|
||||
// index = data.exports
|
||||
// }
|
||||
|
||||
// if (data.exports && data.exports['.']) {
|
||||
// index = data.exports['.']
|
||||
// if (typeof index !== 'string') {
|
||||
// }
|
||||
// }
|
||||
const extless = path.join(path.dirname(index), path.basename(index, path.extname(index)))
|
||||
const dts = `./${extless}.d.ts`
|
||||
const hasDTSFields = 'types' in data || 'typings' in data
|
||||
if (!hasDTSFields) {
|
||||
try {
|
||||
await fs.access(path.join(pkg.path, dts))
|
||||
data.types = dts.split(path.sep).join('/')
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// "normalizeData" from "read-package-json", which was just a call through to
|
||||
// "normalize-package-data". We only call the "fixer" functions because
|
||||
// outside of that it was also clobbering _id (which we already conditionally
|
||||
@@ -379,209 +583,6 @@ function syncSteps (pkg, { strict, steps, changes, allowLegacyCase }) {
|
||||
const { normalizeData } = require('./normalize-data.js')
|
||||
normalizeData(data, changes)
|
||||
}
|
||||
}
|
||||
|
||||
// Steps that require await, distinct from sync-steps.js
|
||||
async function asyncSteps (pkg, { steps, root, changes }) {
|
||||
const data = pkg.content
|
||||
const scripts = data.scripts || {}
|
||||
const pkgId = `${data.name ?? ''}@${data.version ?? ''}`
|
||||
|
||||
// add "install" attribute if any "*.gyp" files exist
|
||||
if (steps.includes('gypfile')) {
|
||||
if (!scripts.install && !scripts.preinstall && data.gypfile !== false) {
|
||||
const files = await lazyLoadGlob()('*.gyp', { cwd: pkg.path })
|
||||
if (files.length) {
|
||||
scripts.install = 'node-gyp rebuild'
|
||||
data.scripts = scripts
|
||||
data.gypfile = true
|
||||
changes?.push(`"scripts.install" was set to "node-gyp rebuild"`)
|
||||
changes?.push(`"gypfile" was set to "true"`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add "start" attribute if "server.js" exists
|
||||
if (steps.includes('serverjs') && !scripts.start) {
|
||||
try {
|
||||
await fs.access(path.join(pkg.path, 'server.js'))
|
||||
scripts.start = 'node server.js'
|
||||
data.scripts = scripts
|
||||
changes?.push('"scripts.start" was set to "node server.js"')
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
// populate "authors" attribute
|
||||
if (steps.includes('authors') && !data.contributors) {
|
||||
try {
|
||||
const authorData = await fs.readFile(path.join(pkg.path, 'AUTHORS'), 'utf8')
|
||||
const authors = authorData.split(/\r?\n/g)
|
||||
.map(line => line.replace(/^\s*#.*$/, '').trim())
|
||||
.filter(line => line)
|
||||
data.contributors = authors
|
||||
changes?.push('"contributors" was auto-populated with the contents of the "AUTHORS" file')
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
// populate "readme" attribute
|
||||
if (steps.includes('readme') && !data.readme) {
|
||||
const mdre = /\.m?a?r?k?d?o?w?n?$/i
|
||||
const files = await lazyLoadGlob()('{README,README.*}', {
|
||||
cwd: pkg.path,
|
||||
nocase: true,
|
||||
mark: true,
|
||||
})
|
||||
let readmeFile
|
||||
for (const file of files) {
|
||||
// don't accept directories.
|
||||
if (!file.endsWith(path.sep)) {
|
||||
if (file.match(mdre)) {
|
||||
readmeFile = file
|
||||
break
|
||||
}
|
||||
if (file.endsWith('README')) {
|
||||
readmeFile = file
|
||||
}
|
||||
}
|
||||
}
|
||||
if (readmeFile) {
|
||||
const readmeData = await fs.readFile(path.join(pkg.path, readmeFile), 'utf8')
|
||||
data.readme = readmeData
|
||||
data.readmeFilename = readmeFile
|
||||
changes?.push(`"readme" was set to the contents of ${readmeFile}`)
|
||||
changes?.push(`"readmeFilename" was set to ${readmeFile}`)
|
||||
}
|
||||
if (!data.readme) {
|
||||
data.readme = 'ERROR: No README data found!'
|
||||
}
|
||||
}
|
||||
|
||||
// expand directories.man
|
||||
if (steps.includes('mans')) {
|
||||
if (data.directories?.man && !data.man) {
|
||||
const manDir = secureAndUnixifyPath(data.directories.man)
|
||||
const cwd = path.resolve(pkg.path, manDir)
|
||||
const files = await lazyLoadGlob()('**/*.[0-9]', { cwd })
|
||||
data.man = files.map(man =>
|
||||
path.relative(pkg.path, path.join(cwd, man)).split(path.sep).join('/')
|
||||
)
|
||||
}
|
||||
normalizePackageMan(data, changes)
|
||||
}
|
||||
|
||||
// expand "directories.bin"
|
||||
if (steps.includes('binDir') && data.directories?.bin && !data.bin && pkg.path) {
|
||||
const binPath = secureAndUnixifyPath(data.directories.bin)
|
||||
const bins = await lazyLoadGlob()('**', { cwd: path.resolve(pkg.path, binPath) })
|
||||
data.bin = bins.reduce((acc, binFile) => {
|
||||
if (binFile && !binFile.startsWith('.')) {
|
||||
const binName = path.basename(binFile)
|
||||
// binPath is already cleaned and unixified, no need to path.join here.
|
||||
acc[binName] = `${binPath}/${secureAndUnixifyPath(binFile)}`
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
} else if (steps.includes('bin') || steps.includes('binDir') || steps.includes('binRefs')) {
|
||||
normalizePackageBin(data, changes)
|
||||
}
|
||||
|
||||
// populate "gitHead" attribute
|
||||
if (steps.includes('gitHead') && !data.gitHead) {
|
||||
const git = require('@npmcli/git')
|
||||
const gitRoot = await git.find({ cwd: pkg.path, root })
|
||||
let head
|
||||
if (gitRoot) {
|
||||
try {
|
||||
head = await fs.readFile(path.resolve(gitRoot, '.git/HEAD'), 'utf8')
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
let headData
|
||||
if (head) {
|
||||
if (head.startsWith('ref: ')) {
|
||||
const headRef = head.replace(/^ref: /, '').trim()
|
||||
const headFile = path.resolve(gitRoot, '.git', headRef)
|
||||
try {
|
||||
headData = await fs.readFile(headFile, 'utf8')
|
||||
headData = headData.replace(/^ref: /, '').trim()
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
if (!headData) {
|
||||
const packFile = path.resolve(gitRoot, '.git/packed-refs')
|
||||
try {
|
||||
let refs = await fs.readFile(packFile, 'utf8')
|
||||
if (refs) {
|
||||
refs = refs.split('\n')
|
||||
for (let i = 0; i < refs.length; i++) {
|
||||
const match = refs[i].match(/^([0-9a-f]{40}) (.+)$/)
|
||||
if (match && match[2].trim() === headRef) {
|
||||
headData = match[1]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
} else {
|
||||
headData = head.trim()
|
||||
}
|
||||
}
|
||||
if (headData) {
|
||||
data.gitHead = headData
|
||||
}
|
||||
}
|
||||
|
||||
// populate "types" attribute
|
||||
if (steps.includes('fillTypes')) {
|
||||
const index = data.main || 'index.js'
|
||||
|
||||
if (typeof index !== 'string') {
|
||||
throw new TypeError('The "main" attribute must be of type string.')
|
||||
}
|
||||
|
||||
// TODO exports is much more complicated than this in verbose format
|
||||
// We need to support for instance
|
||||
|
||||
// "exports": {
|
||||
// ".": [
|
||||
// {
|
||||
// "default": "./lib/npm.js"
|
||||
// },
|
||||
// "./lib/npm.js"
|
||||
// ],
|
||||
// "./package.json": "./package.json"
|
||||
// },
|
||||
// as well as conditional exports
|
||||
|
||||
// if (data.exports && typeof data.exports === 'string') {
|
||||
// index = data.exports
|
||||
// }
|
||||
|
||||
// if (data.exports && data.exports['.']) {
|
||||
// index = data.exports['.']
|
||||
// if (typeof index !== 'string') {
|
||||
// }
|
||||
// }
|
||||
const extless = path.join(path.dirname(index), path.basename(index, path.extname(index)))
|
||||
const dts = `./${extless}.d.ts`
|
||||
const hasDTSFields = 'types' in data || 'typings' in data
|
||||
if (!hasDTSFields) {
|
||||
try {
|
||||
await fs.access(path.join(pkg.path, dts))
|
||||
data.types = dts.split(path.sep).join('/')
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Warn if the bin references don't point to anything. This might be better
|
||||
// in normalize-package-data if it had access to the file path.
|
||||
@@ -597,18 +598,4 @@ async function asyncSteps (pkg, { steps, root, changes }) {
|
||||
}
|
||||
}
|
||||
|
||||
// We don't want the `changes` array in here by default because this is a hot path for parsing packuments during install. The calling method passes it in if it wants to track changes.
|
||||
async function normalize (pkg, opts) {
|
||||
if (!pkg.content) {
|
||||
throw new Error('Can not normalize without content')
|
||||
}
|
||||
await asyncSteps(pkg, opts)
|
||||
// the normalizeData part of this needs to be the last thing ran, so sync comes second
|
||||
syncSteps(pkg, opts)
|
||||
}
|
||||
|
||||
function syncNormalize (pkg, opts) {
|
||||
syncSteps(pkg, opts)
|
||||
}
|
||||
|
||||
module.exports = { normalize, syncNormalize }
|
||||
module.exports = normalize
|
||||
|
||||
+13
-11
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/package-json",
|
||||
"version": "7.0.5",
|
||||
"version": "6.2.0",
|
||||
"description": "Programmatic API to update package.json",
|
||||
"keywords": [
|
||||
"npm",
|
||||
@@ -29,25 +29,27 @@
|
||||
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@npmcli/git": "^7.0.0",
|
||||
"glob": "^13.0.0",
|
||||
"hosted-git-info": "^9.0.0",
|
||||
"json-parse-even-better-errors": "^5.0.0",
|
||||
"proc-log": "^6.0.0",
|
||||
"@npmcli/git": "^6.0.0",
|
||||
"glob": "^10.2.2",
|
||||
"hosted-git-info": "^8.0.0",
|
||||
"json-parse-even-better-errors": "^4.0.0",
|
||||
"proc-log": "^5.0.0",
|
||||
"semver": "^7.5.3",
|
||||
"spdx-expression-parse": "^4.0.0"
|
||||
"validate-npm-package-license": "^3.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^6.0.0",
|
||||
"@npmcli/template-oss": "4.28.1",
|
||||
"@npmcli/eslint-config": "^5.1.0",
|
||||
"@npmcli/template-oss": "4.23.6",
|
||||
"read-package-json": "^7.0.0",
|
||||
"read-package-json-fast": "^4.0.0",
|
||||
"tap": "^16.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.28.1",
|
||||
"version": "4.23.6",
|
||||
"publish": "true"
|
||||
},
|
||||
"tap": {
|
||||
|
||||
+1
@@ -1,5 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
// this code adapted from: https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
|
||||
const cmd = (input, doubleEscape) => {
|
||||
if (!input.length) {
|
||||
|
||||
+1
-16
@@ -1,16 +1 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../which/bin/which.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../which/bin/which.js" "$@"
|
||||
fi
|
||||
../which/bin/which.js
|
||||
+13
-19
@@ -8,24 +8,18 @@ Windows.
|
||||
## USAGE
|
||||
|
||||
```js
|
||||
// default export is a minified version that doesn't need to
|
||||
// load more than one file. Load the 'isexe/raw' export if
|
||||
// you want the non-minified version for some reason.
|
||||
import { isexe, sync } from 'isexe'
|
||||
// or require() works too
|
||||
// const { isexe } = require('isexe')
|
||||
isexe('some-file-name').then(
|
||||
isExe => {
|
||||
if (isExe) {
|
||||
console.error('this thing can be run')
|
||||
} else {
|
||||
console.error('cannot be run')
|
||||
}
|
||||
},
|
||||
err => {
|
||||
console.error('probably file doesnt exist or something')
|
||||
},
|
||||
)
|
||||
isexe('some-file-name').then(isExe => {
|
||||
if (isExe) {
|
||||
console.error('this thing can be run')
|
||||
} else {
|
||||
console.error('cannot be run')
|
||||
}
|
||||
}, (err) => {
|
||||
console.error('probably file doesnt exist or something')
|
||||
})
|
||||
|
||||
// same thing but synchronous, throws errors
|
||||
isExe = sync('some-file-name')
|
||||
@@ -72,9 +66,9 @@ The default exported implementation will be chosen based on
|
||||
import type IsexeOptions from 'isexe'
|
||||
```
|
||||
|
||||
- `ignoreErrors` Treat all errors as "no, this is not
|
||||
* `ignoreErrors` Treat all errors as "no, this is not
|
||||
executable", but don't raise them.
|
||||
- `uid` Number to use as the user id on posix
|
||||
- `gid` Number to use as the group id on posix
|
||||
- `pathExt` List of path extensions to use instead of `PATHEXT`
|
||||
* `uid` Number to use as the user id on posix
|
||||
* `gid` Number to use as the group id on posix
|
||||
* `pathExt` List of path extensions to use instead of `PATHEXT`
|
||||
environment variable on Windows.
|
||||
|
||||
+70
-52
@@ -1,78 +1,96 @@
|
||||
{
|
||||
"name": "isexe",
|
||||
"version": "4.0.0",
|
||||
"version": "3.1.1",
|
||||
"description": "Minimal module to check if a file is executable.",
|
||||
"main": "./dist/commonjs/index.min.js",
|
||||
"module": "./dist/esm/index.min.js",
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"main": "./dist/cjs/index.js",
|
||||
"module": "./dist/mjs/index.js",
|
||||
"types": "./dist/cjs/index.js",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"tshy": {
|
||||
"selfLink": false,
|
||||
"exports": {
|
||||
"./raw": "./src/index.ts",
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.min.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.min.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"exports": {
|
||||
"./raw": {
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.js"
|
||||
}
|
||||
},
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.min.js"
|
||||
"types": "./dist/mjs/index.d.ts",
|
||||
"default": "./dist/mjs/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.min.js"
|
||||
"types": "./dist/cjs/index.d.ts",
|
||||
"default": "./dist/cjs/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"./posix": {
|
||||
"import": {
|
||||
"types": "./dist/mjs/posix.d.ts",
|
||||
"default": "./dist/mjs/posix.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/cjs/posix.d.ts",
|
||||
"default": "./dist/cjs/posix.js"
|
||||
}
|
||||
},
|
||||
"./win32": {
|
||||
"import": {
|
||||
"types": "./dist/mjs/win32.d.ts",
|
||||
"default": "./dist/mjs/win32.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/cjs/win32.d.ts",
|
||||
"default": "./dist/cjs/win32.js"
|
||||
}
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.2.1",
|
||||
"esbuild": "^0.27.3",
|
||||
"prettier": "^3.8.1",
|
||||
"tap": "^21.5.1",
|
||||
"tshy": "^3.1.3",
|
||||
"typedoc": "^0.28.16"
|
||||
"@types/node": "^20.4.5",
|
||||
"@types/tap": "^15.0.8",
|
||||
"c8": "^8.0.1",
|
||||
"mkdirp": "^0.5.1",
|
||||
"prettier": "^2.8.8",
|
||||
"rimraf": "^2.5.0",
|
||||
"sync-content": "^1.0.2",
|
||||
"tap": "^16.3.8",
|
||||
"ts-node": "^10.9.1",
|
||||
"typedoc": "^0.24.8",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"scripts": {
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"prepublishOnly": "git push origin --follow-tags",
|
||||
"prepare": "tshy && bash build.sh",
|
||||
"prepare": "tsc -p tsconfig/cjs.json && tsc -p tsconfig/esm.json && bash ./scripts/fixup.sh",
|
||||
"pretest": "npm run prepare",
|
||||
"presnap": "npm run prepare",
|
||||
"test": "tap",
|
||||
"snap": "tap",
|
||||
"format": "prettier --write .",
|
||||
"typedoc": "typedoc"
|
||||
"test": "c8 tap",
|
||||
"snap": "c8 tap",
|
||||
"format": "prettier --write . --loglevel warn --ignore-path ../../.prettierignore --cache",
|
||||
"typedoc": "typedoc --tsconfig tsconfig/esm.json ./src/*.ts"
|
||||
},
|
||||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
||||
"license": "BlueOak-1.0.0",
|
||||
"license": "ISC",
|
||||
"tap": {
|
||||
"coverage": false,
|
||||
"node-arg": [
|
||||
"--enable-source-maps",
|
||||
"--no-warnings",
|
||||
"--loader",
|
||||
"ts-node/esm"
|
||||
],
|
||||
"ts": false
|
||||
},
|
||||
"prettier": {
|
||||
"semi": false,
|
||||
"printWidth": 75,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"jsxSingleQuote": false,
|
||||
"bracketSameLine": true,
|
||||
"arrowParens": "avoid",
|
||||
"endOfLine": "lf"
|
||||
},
|
||||
"repository": "https://github.com/isaacs/isexe",
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"type": "module"
|
||||
"node": ">=16"
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -2,7 +2,7 @@
|
||||
"author": "GitHub Inc.",
|
||||
"name": "which",
|
||||
"description": "Like which(1) unix command. Find the first instance of an executable in the PATH.",
|
||||
"version": "6.0.1",
|
||||
"version": "5.0.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/npm/node-which.git"
|
||||
@@ -13,11 +13,11 @@
|
||||
},
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"isexe": "^4.0.0"
|
||||
"isexe": "^3.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^6.0.0",
|
||||
"@npmcli/template-oss": "4.28.1",
|
||||
"@npmcli/eslint-config": "^5.0.0",
|
||||
"@npmcli/template-oss": "4.23.3",
|
||||
"tap": "^16.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
@@ -42,11 +42,11 @@
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.28.1",
|
||||
"version": "4.23.3",
|
||||
"publish": "true"
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/promise-spawn",
|
||||
"version": "9.0.1",
|
||||
"version": "8.0.3",
|
||||
"files": [
|
||||
"bin/",
|
||||
"lib/"
|
||||
@@ -32,20 +32,20 @@
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^6.0.0",
|
||||
"@npmcli/template-oss": "4.28.0",
|
||||
"@npmcli/eslint-config": "^5.0.0",
|
||||
"@npmcli/template-oss": "4.25.0",
|
||||
"spawk": "^1.7.1",
|
||||
"tap": "^16.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.28.0",
|
||||
"version": "4.25.0",
|
||||
"publish": true
|
||||
},
|
||||
"dependencies": {
|
||||
"which": "^6.0.0"
|
||||
"which": "^5.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/redact",
|
||||
"version": "4.0.0",
|
||||
"version": "3.2.2",
|
||||
"description": "Redact sensitive npm information from output",
|
||||
"main": "lib/index.js",
|
||||
"exports": {
|
||||
@@ -31,7 +31,7 @@
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.27.1",
|
||||
"version": "4.24.3",
|
||||
"publish": true
|
||||
},
|
||||
"tap": {
|
||||
@@ -43,10 +43,10 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^5.0.0",
|
||||
"@npmcli/template-oss": "4.27.1",
|
||||
"@npmcli/template-oss": "4.24.3",
|
||||
"tap": "^16.3.10"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
}
|
||||
}
|
||||
|
||||
-8
@@ -1,4 +1,3 @@
|
||||
const { log } = require('proc-log')
|
||||
const { resolve, dirname, delimiter } = require('path')
|
||||
// the path here is relative, even though it does not need to be
|
||||
// in order to make the posix tests pass in windows
|
||||
@@ -15,13 +14,6 @@ const setPATH = (projectPath, binPaths, env) => {
|
||||
|
||||
const pathArr = []
|
||||
if (binPaths) {
|
||||
for (const bin of binPaths) {
|
||||
if (bin.includes(delimiter)) {
|
||||
const event = env.npm_lifecycle_event
|
||||
const context = event ? `"${event}" script` : 'script execution'
|
||||
log.warn('run-script', `Path contains delimiter ("${delimiter}"), ${context} may not behave as expected.`)
|
||||
}
|
||||
}
|
||||
pathArr.push(...binPaths)
|
||||
}
|
||||
// unshift the ./node_modules/.bin from every folder
|
||||
|
||||
+11
-10
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/run-script",
|
||||
"version": "10.0.4",
|
||||
"version": "9.1.0",
|
||||
"description": "Run a lifecycle script for a package (descendant of npm-lifecycle)",
|
||||
"author": "GitHub Inc.",
|
||||
"license": "ISC",
|
||||
@@ -15,17 +15,18 @@
|
||||
"template-oss-apply": "template-oss-apply --force"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^6.0.0",
|
||||
"@npmcli/template-oss": "4.29.0",
|
||||
"@npmcli/eslint-config": "^5.0.0",
|
||||
"@npmcli/template-oss": "4.24.1",
|
||||
"spawk": "^1.8.1",
|
||||
"tap": "^16.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@npmcli/node-gyp": "^5.0.0",
|
||||
"@npmcli/package-json": "^7.0.0",
|
||||
"@npmcli/promise-spawn": "^9.0.0",
|
||||
"node-gyp": "^12.1.0",
|
||||
"proc-log": "^6.0.0"
|
||||
"@npmcli/node-gyp": "^4.0.0",
|
||||
"@npmcli/package-json": "^6.0.0",
|
||||
"@npmcli/promise-spawn": "^8.0.0",
|
||||
"node-gyp": "^11.0.0",
|
||||
"proc-log": "^5.0.0",
|
||||
"which": "^5.0.0"
|
||||
},
|
||||
"files": [
|
||||
"bin/",
|
||||
@@ -37,11 +38,11 @@
|
||||
"url": "git+https://github.com/npm/run-script.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
"node": "^18.17.0 || >=20.5.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "4.29.0",
|
||||
"version": "4.24.1",
|
||||
"publish": "true"
|
||||
},
|
||||
"tap": {
|
||||
|
||||
Reference in New Issue
Block a user