New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pnpm/worker

Package Overview
Dependencies
Maintainers
2
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pnpm/worker - npm Package Compare versions

Comparing version 1.0.13 to 2.0.0

7

lib/index.d.ts

@@ -12,3 +12,3 @@ import { PnpmError } from '@pnpm/error';

}
type AddFilesFromDirOptions = Pick<AddDirToStoreMessage, 'cafsDir' | 'dir' | 'filesIndexFile' | 'sideEffectsCacheKey' | 'readManifest' | 'pkg' | 'files'>;
type AddFilesFromDirOptions = Pick<AddDirToStoreMessage, 'storeDir' | 'dir' | 'filesIndexFile' | 'sideEffectsCacheKey' | 'readManifest' | 'pkg' | 'files'>;
export declare function addFilesFromDir(opts: AddFilesFromDirOptions): Promise<AddFilesResult>;

@@ -30,7 +30,7 @@ export declare class TarballIntegrityError extends PnpmError {

}
type AddFilesFromTarballOptions = Pick<TarballExtractMessage, 'buffer' | 'cafsDir' | 'filesIndexFile' | 'integrity' | 'readManifest' | 'pkg'> & {
type AddFilesFromTarballOptions = Pick<TarballExtractMessage, 'buffer' | 'storeDir' | 'filesIndexFile' | 'integrity' | 'readManifest' | 'pkg'> & {
url: string;
};
export declare function addFilesFromTarball(opts: AddFilesFromTarballOptions): Promise<AddFilesResult>;
export declare function readPkgFromCafs(cafsDir: string, verifyStoreIntegrity: boolean, filesIndexFile: string, readManifest?: boolean): Promise<{
export declare function readPkgFromCafs(storeDir: string, verifyStoreIntegrity: boolean, filesIndexFile: string, readManifest?: boolean): Promise<{
verified: boolean;

@@ -50,2 +50,3 @@ pkgFilesIndex: PackageFilesIndex;

export declare function hardLinkDir(src: string, destDirs: string[]): Promise<void>;
export declare function initStoreDir(storeDir: string): Promise<void>;
export {};

@@ -15,2 +15,3 @@ "use strict";

exports.hardLinkDir = hardLinkDir;
exports.initStoreDir = initStoreDir;
// cspell:ignore checkin

@@ -69,3 +70,3 @@ const path_1 = __importDefault(require("path"));

type: 'add-dir',
cafsDir: opts.cafsDir,
storeDir: opts.storeDir,
dir: opts.dir,

@@ -122,3 +123,3 @@ filesIndexFile: opts.filesIndexFile,

buffer: opts.buffer,
cafsDir: opts.cafsDir,
storeDir: opts.storeDir,
integrity: opts.integrity,

@@ -131,3 +132,3 @@ filesIndexFile: opts.filesIndexFile,

}
async function readPkgFromCafs(cafsDir, verifyStoreIntegrity, filesIndexFile, readManifest) {
async function readPkgFromCafs(storeDir, verifyStoreIntegrity, filesIndexFile, readManifest) {
if (!workerPool) {

@@ -148,3 +149,3 @@ workerPool = createTarballWorkerPool();

type: 'readPkgFromCafs',
cafsDir,
storeDir,
filesIndexFile,

@@ -217,2 +218,22 @@ readManifest,

}
async function initStoreDir(storeDir) {
if (!workerPool) {
workerPool = createTarballWorkerPool();
}
const localWorker = await workerPool.checkoutWorkerAsync(true);
return new Promise((resolve, reject) => {
localWorker.once('message', ({ status, error }) => {
workerPool.checkinWorker(localWorker);
if (status === 'error') {
reject(new error_1.PnpmError(error.code ?? 'INIT_CAFS_FAILED', error.message));
return;
}
resolve();
});
localWorker.postMessage({
type: 'init-store',
storeDir,
});
});
}
//# sourceMappingURL=index.js.map

@@ -6,6 +6,10 @@ import { type PackageFilesResponse } from '@pnpm/cafs-types';

}
export interface InitStoreMessage {
type: 'init-store';
storeDir: string;
}
export interface TarballExtractMessage {
type: 'extract';
buffer: Buffer;
cafsDir: string;
storeDir: string;
integrity?: string;

@@ -38,3 +42,3 @@ filesIndexFile: string;

type: 'add-dir';
cafsDir: string;
storeDir: string;
dir: string;

@@ -49,3 +53,3 @@ filesIndexFile: string;

type: 'readPkgFromCafs';
cafsDir: string;
storeDir: string;
filesIndexFile: string;

@@ -52,0 +56,0 @@ readManifest: boolean;

@@ -64,4 +64,8 @@ "use strict";

}
case 'init-store': {
worker_threads_1.parentPort.postMessage(initStore(message));
break;
}
case 'readPkgFromCafs': {
let { cafsDir, filesIndexFile, readManifest, verifyStoreIntegrity } = message;
let { storeDir, filesIndexFile, readManifest, verifyStoreIntegrity } = message;
let pkgFilesIndex;

@@ -89,3 +93,3 @@ try {

if (verifyStoreIntegrity) {
verifyResult = (0, store_cafs_1.checkPkgFilesIntegrity)(cafsDir, pkgFilesIndex, readManifest);
verifyResult = (0, store_cafs_1.checkPkgFilesIntegrity)(storeDir, pkgFilesIndex, readManifest);
}

@@ -95,3 +99,3 @@ else {

passed: true,
manifest: readManifest ? (0, store_cafs_1.readManifestFromStore)(cafsDir, pkgFilesIndex) : undefined,
manifest: readManifest ? (0, store_cafs_1.readManifestFromStore)(storeDir, pkgFilesIndex) : undefined,
};

@@ -132,3 +136,3 @@ }

}
function addTarballToStore({ buffer, cafsDir, integrity, filesIndexFile }) {
function addTarballToStore({ buffer, storeDir, integrity, filesIndexFile }) {
if (integrity) {

@@ -151,6 +155,6 @@ const [, algo, integrityHash] = integrity.match(INTEGRITY_REGEX);

}
if (!cafsCache.has(cafsDir)) {
cafsCache.set(cafsDir, (0, store_cafs_1.createCafs)(cafsDir));
if (!cafsCache.has(storeDir)) {
cafsCache.set(storeDir, (0, store_cafs_1.createCafs)(storeDir));
}
const cafs = cafsCache.get(cafsDir);
const cafs = cafsCache.get(storeDir);
const { filesIndex, manifest } = cafs.addFilesFromTarball(buffer, true);

@@ -161,7 +165,27 @@ const { filesIntegrity, filesMap } = processFilesIndex(filesIndex);

}
function addFilesFromDir({ dir, cafsDir, filesIndexFile, sideEffectsCacheKey, files }) {
if (!cafsCache.has(cafsDir)) {
cafsCache.set(cafsDir, (0, store_cafs_1.createCafs)(cafsDir));
function initStore({ storeDir }) {
fs_1.default.mkdirSync(storeDir, { recursive: true });
try {
const hexChars = '0123456789abcdef'.split('');
for (const subDir of ['files', 'index']) {
const subDirPath = path_1.default.join(storeDir, subDir);
fs_1.default.mkdirSync(subDirPath);
for (const hex1 of hexChars) {
for (const hex2 of hexChars) {
fs_1.default.mkdirSync(path_1.default.join(subDirPath, `${hex1}${hex2}`));
}
}
}
}
const cafs = cafsCache.get(cafsDir);
catch {
// If a parallel process has already started creating the directories in the store,
// then we just stop.
}
return { status: 'success' };
}
function addFilesFromDir({ dir, storeDir, filesIndexFile, sideEffectsCacheKey, files }) {
if (!cafsCache.has(storeDir)) {
cafsCache.set(storeDir, (0, store_cafs_1.createCafs)(storeDir));
}
const cafs = cafsCache.get(storeDir);
const { filesIndex, manifest } = cafs.addFilesFromDir(dir, {

@@ -179,6 +203,14 @@ files,

catch {
filesIndex = { name: manifest?.name, version: manifest?.version, files: filesIntegrity };
// If there is no existing index file, then we cannot store the side effects.
return {
status: 'success',
value: {
filesIndex: filesMap,
manifest,
requiresBuild: (0, exec_pkg_requires_build_1.pkgRequiresBuild)(manifest, filesIntegrity),
},
};
}
filesIndex.sideEffects = filesIndex.sideEffects ?? {};
filesIndex.sideEffects[sideEffectsCacheKey] = filesIntegrity;
filesIndex.sideEffects[sideEffectsCacheKey] = calculateDiff(filesIndex.files, filesIntegrity);
if (filesIndex.requiresBuild == null) {

@@ -197,2 +229,24 @@ requiresBuild = (0, exec_pkg_requires_build_1.pkgRequiresBuild)(manifest, filesIntegrity);

}
function calculateDiff(baseFiles, sideEffectsFiles) {
const deleted = [];
const added = {};
for (const file of new Set([...Object.keys(baseFiles), ...Object.keys(sideEffectsFiles)])) {
if (!sideEffectsFiles[file]) {
deleted.push(file);
}
else if (!baseFiles[file] ||
baseFiles[file].integrity !== sideEffectsFiles[file].integrity ||
baseFiles[file].mode !== sideEffectsFiles[file].mode) {
added[file] = sideEffectsFiles[file];
}
}
const diff = {};
if (deleted.length > 0) {
diff.deleted = deleted;
}
if (Object.keys(added).length > 0) {
diff.added = added;
}
return diff;
}
function processFilesIndex(filesIndex) {

@@ -199,0 +253,0 @@ const filesIntegrity = {};

{
"name": "@pnpm/worker",
"version": "1.0.13",
"version": "2.0.0",
"description": "A worker for extracting package taralls to the store",

@@ -13,3 +13,3 @@ "main": "lib/index.js",

"keywords": [
"pnpm9",
"pnpm10",
"pnpm",

@@ -32,11 +32,11 @@ "tarball"

"load-json-file": "^6.2.0",
"@pnpm/cafs-types": "5.0.0",
"@pnpm/create-cafs-store": "7.0.11",
"@pnpm/error": "6.0.2",
"@pnpm/create-cafs-store": "7.0.12",
"@pnpm/cafs-types": "6.0.0",
"@pnpm/crypto.polyfill": "1.0.0",
"@pnpm/error": "6.0.3",
"@pnpm/fs.hard-link-dir": "4.0.0",
"@pnpm/exec.pkg-requires-build": "1.0.7",
"@pnpm/fs.hard-link-dir": "4.0.0",
"@pnpm/graceful-fs": "4.0.0",
"@pnpm/store.cafs": "4.0.2",
"@pnpm/symlink-dependency": "8.0.8"
"@pnpm/store.cafs": "5.0.0",
"@pnpm/symlink-dependency": "8.0.8",
"@pnpm/graceful-fs": "4.0.0"
},

@@ -46,3 +46,3 @@ "devDependencies": {

"@pnpm/types": "12.2.0",
"@pnpm/worker": "1.0.13"
"@pnpm/worker": "2.0.0"
},

@@ -49,0 +49,0 @@ "funding": "https://opencollective.com/pnpm",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc