Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
networkConcurrency?: number,
packageImportMethod?: 'auto' | 'hardlink' | 'copy' | 'clone',
verifyStoreIntegrity: boolean,
},
): Promise void, saveStateSync: () => void }> {
const storeDir = initOpts.storeDir
const unlock = initOpts.locks
? await lock(initOpts.storeDir, {
locks: initOpts.locks,
stale: initOpts.lockStaleDuration || 60 * 1000, // 1 minute,
whenLocked: () => globalWarn(`waiting for the store at "${initOpts.storeDir}" to be unlocked...`),
})
: null
const storeIndex = await readStore(initOpts.storeDir) || {}
const packageRequester = createPackageRequester(resolve, fetchers, {
networkConcurrency: initOpts.networkConcurrency,
storeDir: initOpts.storeDir,
storeIndex,
verifyStoreIntegrity: initOpts.verifyStoreIntegrity,
})
return {
close: unlock ? async () => { await unlock() } : () => Promise.resolve(undefined),
closeSync: unlock ? () => unlock.sync() : () => undefined,
fetchPackage: packageRequester.fetchPackageToStore,
findPackageUsages,
getPackageLocation,
importPackage: createImportPackage(initOpts.packageImportMethod),
prune,
requestPackage: packageRequester.requestPackage,
saveState: saveStore.bind(null, initOpts.storeDir, storeIndex),
async function getPackageLocation (
packageId: string,
packageName: string,
opts: {
lockfileDir: string,
targetEngine?: string,
}
) {
if (opts.targetEngine) {
const sideEffectsCacheLocation = (await getCacheByEngine(initOpts.storeDir, packageId))[opts.targetEngine]
if (sideEffectsCacheLocation) {
return {
dir: sideEffectsCacheLocation,
isBuilt: true,
}
}
}
return {
dir: path.join(initOpts.storeDir, pkgIdToFilename(packageId, opts.lockfileDir), 'node_modules', packageName),
isBuilt: false,
}
}