Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@verdaccio/file-locking

Package Overview
Dependencies
Maintainers
4
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@verdaccio/file-locking - npm Package Compare versions

Comparing version 11.0.0-6-next.4 to 11.0.0-6-next.5

build/legacy/lockfile.d.ts

9

build/index.d.ts

@@ -1,3 +0,6 @@

export * from './unclock';
export * from './readFile';
export * from './lockfile';
export * from './legacy/unclock';
export * from './legacy/readFile';
export * from './legacy/lockfile';
export { readFileNext } from './readFile';
export { lockFileNext } from './lockfile';
export { unlockFileNext } from './utils';

@@ -6,7 +6,31 @@ "use strict";

});
var _exportNames = {
readFileNext: true,
lockFileNext: true,
unlockFileNext: true
};
Object.defineProperty(exports, "lockFileNext", {
enumerable: true,
get: function () {
return _lockfile2.lockFileNext;
}
});
Object.defineProperty(exports, "readFileNext", {
enumerable: true,
get: function () {
return _readFile2.readFileNext;
}
});
Object.defineProperty(exports, "unlockFileNext", {
enumerable: true,
get: function () {
return _utils.unlockFileNext;
}
});
var _unclock = require("./unclock");
var _unclock = require("./legacy/unclock");
Object.keys(_unclock).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _unclock[key]) return;

@@ -21,6 +45,7 @@ Object.defineProperty(exports, key, {

var _readFile = require("./readFile");
var _readFile = require("./legacy/readFile");
Object.keys(_readFile).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _readFile[key]) return;

@@ -35,6 +60,7 @@ Object.defineProperty(exports, key, {

var _lockfile = require("./lockfile");
var _lockfile = require("./legacy/lockfile");
Object.keys(_lockfile).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _lockfile[key]) return;

@@ -48,2 +74,8 @@ Object.defineProperty(exports, key, {

});
var _readFile2 = require("./readFile");
var _lockfile2 = require("./lockfile");
var _utils = require("./utils");
//# sourceMappingURL=index.js.map

@@ -1,2 +0,1 @@

import { Callback } from '@verdaccio/types';
/**

@@ -7,3 +6,2 @@ * locks a file by creating a lock file

*/
declare const lockFile: (name: string, callback: Callback) => void;
export { lockFile };
export declare function lockFileNext(name: string): Promise<void>;

@@ -6,3 +6,3 @@ "use strict";

});
exports.lockFile = void 0;
exports.lockFileNext = lockFileNext;

@@ -16,17 +16,10 @@ var _utils = require("./utils");

*/
const lockFile = function (name, callback) {
Promise.resolve().then(() => {
return (0, _utils.statDir)(name);
}).then(() => {
return (0, _utils.statfile)(name);
}).then(() => {
return (0, _utils.lockfile)(name);
}).then(() => {
callback(null);
}).catch(err => {
callback(err);
});
};
async function lockFileNext(name) {
// check if dir exist
await (0, _utils.statDir)(name); // check if file exist
exports.lockFile = lockFile;
await (0, _utils.statFile)(name); // lock fhe the file
await (0, _utils.lockFileWithOptions)(name);
}
//# sourceMappingURL=lockfile.js.map

@@ -1,2 +0,1 @@

import { Callback } from '@verdaccio/types';
export declare type ReadFileOptions = {

@@ -15,3 +14,2 @@ parse?: boolean;

*/
declare function readFile(name: string, options?: ReadFileOptions, callback?: Callback): void;
export { readFile };
export declare function readFileNext<T>(name: string, options?: ReadFileOptions): Promise<T>;

@@ -6,12 +6,34 @@ "use strict";

});
exports.readFile = readFile;
exports.readFileNext = readFileNext;
var _fs = _interopRequireDefault(require("fs"));
var _lockfile = require("./lockfile");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _utils = require("./utils");
/* eslint-disable no-undef */
async function lock(name, options) {
if (!options.lock) {
return null;
}
await (0, _lockfile.lockFileNext)(name);
}
async function read(name) {
return (0, _utils.readFile)(name, 'utf8');
}
function parseJSON(contents, options) {
return new Promise((resolve, reject) => {
if (!options.parse) {
return resolve(contents);
}
try {
contents = JSON.parse(contents);
return resolve(contents);
} catch (err) {
return reject(err);
}
});
}
/**

@@ -26,57 +48,14 @@ * Reads a local file, which involves

*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
function readFile(name, options = {}, callback = () => {}) {
if (typeof options === 'function') {
callback = options;
options = {};
}
options.lock = options.lock || false;
options.parse = options.parse || false;
const lock = function (options) {
return new Promise((resolve, reject) => {
if (!options.lock) {
return resolve(null);
}
(0, _lockfile.lockFile)(name, function (err) {
if (err) {
return reject(err);
}
return resolve(null);
});
});
async function readFileNext(name, options = {}) {
const _options = {
lock: (options === null || options === void 0 ? void 0 : options.lock) || false,
parse: (options === null || options === void 0 ? void 0 : options.parse) || false
};
const read = function () {
return new Promise((resolve, reject) => {
_fs.default.readFile(name, 'utf8', function (err, contents) {
if (err) {
return reject(err);
}
resolve(contents);
});
});
};
const parseJSON = function (contents) {
return new Promise((resolve, reject) => {
if (!options.parse) {
return resolve(contents);
}
try {
contents = JSON.parse(contents);
return resolve(contents);
} catch (err) {
return reject(err);
}
});
};
Promise.resolve().then(() => lock(options)).then(() => read()).then(content => parseJSON(content)).then(result => callback(null, result), err => callback(err));
await lock(name, _options);
const content = await read(name);
const parsed = await parseJSON(content, options);
return parsed;
}
//# sourceMappingURL=readFile.js.map

@@ -1,3 +0,21 @@

export declare const statDir: (name: string) => Promise<Error | null>;
export declare const statfile: (name: string) => Promise<Error | null>;
export declare const lockfile: (name: string) => Promise<unknown>;
/// <reference types="node" />
import fs from 'fs/promises';
export declare const readFile: typeof fs.readFile;
/**
* Test to see if the directory exists
* @param name
* @returns
*/
export declare function statDir(name: string): Promise<void>;
/**
* test to see if the directory exists
* @param name
* @returns
*/
export declare function statFile(name: string): Promise<void>;
/**
* Lock a file
* @param name name of the file to lock
*/
export declare function lockFileWithOptions(name: string, options?: any): Promise<void>;
export declare function unlockFileNext(name: string): Promise<void>;

@@ -6,71 +6,85 @@ "use strict";

});
exports.lockfile = exports.statfile = exports.statDir = void 0;
exports.lockFileWithOptions = lockFileWithOptions;
exports.readFile = void 0;
exports.statDir = statDir;
exports.statFile = statFile;
exports.unlockFileNext = unlockFileNext;
var _fs = _interopRequireDefault(require("fs"));
var _promises = _interopRequireDefault(require("fs/promises"));
var _lockfile = _interopRequireDefault(require("lockfile"));
var _path = _interopRequireDefault(require("path"));
var _lockfile = _interopRequireDefault(require("lockfile"));
var _util = require("util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const statDir = name => {
return new Promise((resolve, reject) => {
// test to see if the directory exists
const dirPath = _path.default.dirname(name);
const readFile = _promises.default.readFile;
exports.readFile = readFile;
const statPromise = _promises.default.stat; // https://github.com/npm/lockfile/issues/33
_fs.default.stat(dirPath, function (err, stats) {
if (err) {
return reject(err);
} else if (!stats.isDirectory()) {
return resolve(new Error(`${_path.default.dirname(name)} is not a directory`));
} else {
return resolve(null);
}
});
});
};
const lfLock = (0, _util.promisify)(_lockfile.default.lock);
const lfUnlock = (0, _util.promisify)(_lockfile.default.unlock);
/**
* Test to see if the directory exists
* @param name
* @returns
*/
exports.statDir = statDir;
async function statDir(name) {
const dirPath = _path.default.dirname(name);
const statfile = name => {
return new Promise((resolve, reject) => {
// test to see if the directory exists
_fs.default.stat(name, function (err, stats) {
if (err) {
return reject(err);
} else if (!stats.isFile()) {
return resolve(new Error(`${_path.default.dirname(name)} is not a file`));
} else {
return resolve(null);
}
});
});
};
const stats = await statPromise(dirPath);
exports.statfile = statfile;
if (!stats.isDirectory()) {
throw new Error(`${_path.default.dirname(name)} is not a directory`);
}
const lockfile = name => {
return new Promise(resolve => {
const lockOpts = {
// time (ms) to wait when checking for stale locks
wait: 1000,
// how often (ms) to re-check stale locks
pollPeriod: 100,
// locks are considered stale after 5 minutes
stale: 5 * 60 * 1000,
// number of times to attempt to create a lock
retries: 100,
// time (ms) between tries
retryWait: 100
};
const lockFileName = `${name}.lock`;
return;
}
/**
* test to see if the directory exists
* @param name
* @returns
*/
_lockfile.default.lock(lockFileName, lockOpts, () => {
resolve();
});
});
};
exports.lockfile = lockfile;
async function statFile(name) {
const stats = await statPromise(name);
if (!stats.isFile()) {
throw new Error(`${_path.default.dirname(name)} is not a file`);
}
return;
}
/**
* Lock a file
* @param name name of the file to lock
*/
async function lockFileWithOptions(name, options) {
const lockOpts = {
// time (ms) to wait when checking for stale locks
wait: 1000,
// how often (ms) to re-check stale locks
pollPeriod: 100,
// locks are considered stale after 5 minutes
stale: 5 * 60 * 1000,
// number of times to attempt to create a lock
retries: 100,
// time (ms) between tries
retryWait: 100,
...options
};
await lfLock(`${name}.lock`, lockOpts);
} // unlocks file by removing existing lock file
async function unlockFileNext(name) {
const lockFileName = `${name}.lock`;
return lfUnlock(lockFileName);
}
//# sourceMappingURL=utils.js.map
{
"name": "@verdaccio/file-locking",
"version": "11.0.0-6-next.4",
"description": "library that handle file locking",
"keywords": [
"private",
"package",
"repository",
"registry",
"enterprise",
"modules",
"proxy",
"server",
"verdaccio"
],
"author": "Juan Picado <juanpicado19@gmail.com>",
"license": "MIT",
"homepage": "https://verdaccio.org",
"engines": {
"node": ">=14",
"npm": ">=6"
},
"repository": {
"type": "https",
"url": "https://github.com/verdaccio/verdaccio",
"directory": "packages/core/file-locking"
},
"bugs": {
"url": "https://github.com/verdaccio/verdaccio/issues"
},
"publishConfig": {
"access": "public"
},
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
"build"
],
"dependencies": {
"lockfile": "1.0.4"
},
"devDependencies": {
"@verdaccio/types": "11.0.0-6-next.9"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/verdaccio"
},
"scripts": {
"clean": "rimraf ./build",
"test": "cross-env NODE_ENV=test BABEL_ENV=test jest",
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
"watch": "pnpm build:js -- --watch",
"build": "pnpm run build:js && pnpm run build:types"
}
}
"name": "@verdaccio/file-locking",
"version": "11.0.0-6-next.5",
"description": "library that handle file locking",
"keywords": [
"private",
"package",
"repository",
"registry",
"enterprise",
"modules",
"proxy",
"server",
"verdaccio"
],
"author": "Juan Picado <juanpicado19@gmail.com>",
"license": "MIT",
"homepage": "https://verdaccio.org",
"engines": {
"node": ">=14",
"npm": ">=6"
},
"repository": {
"type": "https",
"url": "https://github.com/verdaccio/verdaccio",
"directory": "packages/core/file-locking"
},
"bugs": {
"url": "https://github.com/verdaccio/verdaccio/issues"
},
"publishConfig": {
"access": "public"
},
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
"build"
],
"dependencies": {
"lockfile": "1.0.4"
},
"devDependencies": {
"@verdaccio/types": "11.0.0-6-next.13"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/verdaccio"
},
"scripts": {
"clean": "rimraf ./build",
"test": "jest",
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
"watch": "pnpm build:js -- --watch",
"build": "pnpm run build:js && pnpm run build:types"
},
"readme": "## Deprecated repository\n\n**This repository has been moved to a monorepo you can find in [verdaccio/monorepo](https://github.com/verdaccio/monorepo). This package is located in [`core/file-locking` folder](https://github.com/verdaccio/monorepo/tree/master/core/file-locking)**\n\n---\n\n# File Locking\n\nThis an utility to lock and unlock files\n\n[![verdaccio (latest)](https://img.shields.io/npm/v/@verdaccio/file-locking/latest.svg)](https://www.npmjs.com/package/verdaccio)\n[![docker pulls](https://img.shields.io/docker/pulls/verdaccio/verdaccio.svg?maxAge=43200)](https://verdaccio.org/docs/en/docker.html)\n[![backers](https://opencollective.com/verdaccio/tiers/backer/badge.svg?label=Backer&color=brightgreen)](https://opencollective.com/verdaccio)\n[![stackshare](https://img.shields.io/badge/Follow%20on-StackShare-blue.svg?logo=stackshare&style=flat)](https://stackshare.io/verdaccio)\n[![discord](https://img.shields.io/discord/388674437219745793.svg)](http://chat.verdaccio.org/)\n[![node](https://img.shields.io/node/v/@verdaccio/file-locking/latest.svg)](https://www.npmjs.com/package/verdaccio)\n![MIT](https://img.shields.io/github/license/mashape/apistatus.svg)\n[![Crowdin](https://d322cqt584bo4o.cloudfront.net/verdaccio/localized.svg)](https://crowdin.com/project/verdaccio)\n\n[![Twitter followers](https://img.shields.io/twitter/follow/verdaccio_npm.svg?style=social&label=Follow)](https://twitter.com/verdaccio_npm)\n[![Github](https://img.shields.io/github/stars/verdaccio/verdaccio.svg?style=social&label=Stars)](https://github.com/verdaccio/verdaccio/stargazers)\n"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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