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-alpha.3 to 12.0.0-next.0

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,29 @@ "use strict";

});
var _unclock = require("./unclock");
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("./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;

@@ -20,7 +42,6 @@ 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;

@@ -34,7 +55,6 @@ 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 +68,5 @@ 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,6 +6,4 @@ "use strict";

});
exports.lockFile = void 0;
exports.lockFileNext = lockFileNext;
var _utils = require("./utils");
/**

@@ -16,17 +14,10 @@ * locks a file by creating a lock file

*/
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);
});
};
exports.lockFile = lockFile;
async function lockFileNext(name) {
// check if dir exist
await (0, _utils.statDir)(name);
// check if file exist
await (0, _utils.statFile)(name);
// lock fhe the file
await (0, _utils.lockFileWithOptions)(name);
}
//# sourceMappingURL=lockfile.js.map

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

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

@@ -15,3 +14,2 @@ lock?: 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,28 @@ "use strict";

});
exports.readFile = readFile;
var _fs = _interopRequireDefault(require("fs"));
exports.readFileNext = readFileNext;
var _lockfile = require("./lockfile");
var _utils = require("./utils");
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);
}
});
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint-disable no-undef */
/**

@@ -26,57 +42,12 @@ * 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,19 @@

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>;
export declare const readFile: any;
/**
* 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,73 @@ "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 _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 fsP = _fs.default.promises ? _fs.default.promises : require('fs/promises');
const readFile = fsP.readFile;
exports.readFile = readFile;
const statPromise = fsP.stat;
// https://github.com/npm/lockfile/issues/33
const lfLock = (0, _util.promisify)(_lockfile.default.lock);
const lfUnlock = (0, _util.promisify)(_lockfile.default.unlock);
const statDir = name => {
return new Promise((resolve, reject) => {
// test to see if the directory exists
const dirPath = _path.default.dirname(name);
/**
* Test to see if the directory exists
* @param name
* @returns
*/
async function statDir(name) {
const dirPath = _path.default.dirname(name);
const stats = await statPromise(dirPath);
if (!stats.isDirectory()) {
throw new Error(`${_path.default.dirname(name)} is not a directory`);
}
return;
}
_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);
}
});
});
};
/**
* test to see if the directory exists
* @param name
* @returns
*/
async function statFile(name) {
const stats = await statPromise(name);
if (!stats.isFile()) {
throw new Error(`${_path.default.dirname(name)} is not a file`);
}
return;
}
exports.statDir = statDir;
/**
* 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);
}
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);
}
});
});
};
exports.statfile = statfile;
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`;
_lockfile.default.lock(lockFileName, lockOpts, () => {
resolve();
});
});
};
exports.lockfile = lockfile;
// 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-alpha.3",
"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": ">=10",
"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.7"
},
"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": "12.0.0-next.0",
"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": ">=12"
},
"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": "12.0.0-next.0"
},
"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"
}
}

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