@verdaccio/file-locking
Advanced tools
Comparing version 11.0.0-6-next.6 to 11.0.0-6-next.7
@@ -29,5 +29,3 @@ "use strict"; | ||
}); | ||
var _unclock = require("./legacy/unclock"); | ||
Object.keys(_unclock).forEach(function (key) { | ||
@@ -44,5 +42,3 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _readFile = require("./legacy/readFile"); | ||
Object.keys(_readFile).forEach(function (key) { | ||
@@ -59,5 +55,3 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _lockfile = require("./legacy/lockfile"); | ||
Object.keys(_lockfile).forEach(function (key) { | ||
@@ -74,8 +68,5 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _readFile2 = require("./readFile"); | ||
var _lockfile2 = require("./lockfile"); | ||
var _utils = require("./utils"); | ||
//# sourceMappingURL=index.js.map |
@@ -7,5 +7,3 @@ "use strict"; | ||
exports.lockFile = void 0; | ||
var _utils = require("./utils"); | ||
/** | ||
@@ -29,4 +27,3 @@ * locks a file by creating a lock file | ||
}; | ||
exports.lockFile = lockFile; | ||
//# sourceMappingURL=lockfile.js.map |
import { Callback } from '@verdaccio/types'; | ||
export declare type ReadFileOptions = { | ||
export type ReadFileOptions = { | ||
parse?: boolean; | ||
@@ -4,0 +4,0 @@ lock?: boolean; |
@@ -7,9 +7,5 @@ "use strict"; | ||
exports.readFile = readFile; | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _lockfile = require("./lockfile"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* eslint-disable no-undef */ | ||
@@ -32,6 +28,4 @@ | ||
} | ||
options.lock = options.lock || false; | ||
options.parse = options.parse || false; | ||
const lock = function (options) { | ||
@@ -42,3 +36,2 @@ return new Promise((resolve, reject) => { | ||
} | ||
(0, _lockfile.lockFile)(name, function (err) { | ||
@@ -48,3 +41,2 @@ if (err) { | ||
} | ||
return resolve(null); | ||
@@ -54,3 +46,2 @@ }); | ||
}; | ||
const read = function () { | ||
@@ -62,3 +53,2 @@ return new Promise((resolve, reject) => { | ||
} | ||
resolve(contents); | ||
@@ -68,3 +58,2 @@ }); | ||
}; | ||
const parseJSON = function (contents) { | ||
@@ -75,3 +64,2 @@ return new Promise((resolve, reject) => { | ||
} | ||
try { | ||
@@ -85,5 +73,4 @@ contents = JSON.parse(contents); | ||
}; | ||
Promise.resolve().then(() => lock(options)).then(() => read()).then(content => parseJSON(content)).then(result => callback(null, result), err => callback(err)); | ||
} | ||
//# sourceMappingURL=readFile.js.map |
@@ -7,11 +7,7 @@ "use strict"; | ||
exports.unlockFile = unlockFile; | ||
var _lockfile = _interopRequireDefault(require("lockfile")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// unlocks file by removing existing lock file | ||
function unlockFile(name, next) { | ||
const lockFileName = `${name}.lock`; | ||
_lockfile.default.unlock(lockFileName, function () { | ||
@@ -18,0 +14,0 @@ return next(null); |
@@ -7,11 +7,6 @@ "use strict"; | ||
exports.statfile = exports.statDir = exports.lockfile = void 0; | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _lockfile = _interopRequireDefault(require("lockfile")); | ||
var _path = _interopRequireDefault(require("path")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const statDir = name => { | ||
@@ -21,3 +16,2 @@ return new Promise((resolve, reject) => { | ||
const dirPath = _path.default.dirname(name); | ||
_fs.default.stat(dirPath, function (err, stats) { | ||
@@ -34,5 +28,3 @@ if (err) { | ||
}; | ||
exports.statDir = statDir; | ||
const statfile = name => { | ||
@@ -52,5 +44,3 @@ return new Promise((resolve, reject) => { | ||
}; | ||
exports.statfile = statfile; | ||
const lockfile = name => { | ||
@@ -71,3 +61,2 @@ return new Promise(resolve => { | ||
const lockFileName = `${name}.lock`; | ||
_lockfile.default.lock(lockFileName, lockOpts, () => { | ||
@@ -78,4 +67,3 @@ resolve(); | ||
}; | ||
exports.lockfile = lockfile; | ||
//# sourceMappingURL=utils.js.map |
@@ -7,5 +7,3 @@ "use strict"; | ||
exports.lockFileNext = lockFileNext; | ||
var _utils = require("./utils"); | ||
/** | ||
@@ -18,8 +16,8 @@ * locks a file by creating a lock file | ||
// 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.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,2 +0,2 @@ | ||
export declare type ReadFileOptions = { | ||
export type ReadFileOptions = { | ||
parse?: boolean; | ||
@@ -3,0 +3,0 @@ lock?: boolean; |
@@ -7,7 +7,4 @@ "use strict"; | ||
exports.readFileNext = readFileNext; | ||
var _lockfile = require("./lockfile"); | ||
var _utils = require("./utils"); | ||
async function lock(name, options) { | ||
@@ -17,10 +14,7 @@ if (!options.lock) { | ||
} | ||
await (0, _lockfile.lockFileNext)(name); | ||
} | ||
async function read(name) { | ||
return (0, _utils.readFile)(name, 'utf8'); | ||
} | ||
function parseJSON(contents, options) { | ||
@@ -31,3 +25,2 @@ return new Promise((resolve, reject) => { | ||
} | ||
try { | ||
@@ -41,2 +34,3 @@ contents = JSON.parse(contents); | ||
} | ||
/** | ||
@@ -51,4 +45,2 @@ * Reads a local file, which involves | ||
*/ | ||
async function readFileNext(name, options = {}) { | ||
@@ -55,0 +47,0 @@ const _options = { |
@@ -1,4 +0,2 @@ | ||
/// <reference types="node" /> | ||
import fs from 'fs/promises'; | ||
export declare const readFile: typeof fs.readFile; | ||
export declare const readFile: any; | ||
/** | ||
@@ -5,0 +3,0 @@ * Test to see if the directory exists |
@@ -11,19 +11,15 @@ "use strict"; | ||
exports.unlockFileNext = unlockFileNext; | ||
var _promises = _interopRequireDefault(require("fs/promises")); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _lockfile = _interopRequireDefault(require("lockfile")); | ||
var _path = _interopRequireDefault(require("path")); | ||
var _util = require("util"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const readFile = _promises.default.readFile; | ||
const fsP = _fs.default.promises ? _fs.default.promises : require('fs/promises'); | ||
const readFile = fsP.readFile; | ||
exports.readFile = readFile; | ||
const statPromise = _promises.default.stat; // https://github.com/npm/lockfile/issues/33 | ||
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); | ||
/** | ||
@@ -34,14 +30,11 @@ * Test to see if the directory exists | ||
*/ | ||
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; | ||
} | ||
/** | ||
@@ -52,13 +45,10 @@ * test to see if the directory exists | ||
*/ | ||
async function statFile(name) { | ||
const stats = await statPromise(name); | ||
if (!stats.isFile()) { | ||
throw new Error(`${_path.default.dirname(name)} is not a file`); | ||
} | ||
return; | ||
} | ||
/** | ||
@@ -68,4 +58,2 @@ * Lock a file | ||
*/ | ||
async function lockFileWithOptions(name, options) { | ||
@@ -86,5 +74,5 @@ const lockOpts = { | ||
await lfLock(`${name}.lock`, lockOpts); | ||
} // unlocks file by removing existing lock file | ||
} | ||
// unlocks file by removing existing lock file | ||
async function unlockFileNext(name) { | ||
@@ -91,0 +79,0 @@ const lockFileName = `${name}.lock`; |
{ | ||
"name": "@verdaccio/file-locking", | ||
"version": "11.0.0-6-next.6", | ||
"version": "11.0.0-6-next.7", | ||
"description": "library that handle file locking", | ||
@@ -20,4 +20,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=14", | ||
"npm": ">=6" | ||
"node": ">=12" | ||
}, | ||
@@ -44,3 +43,3 @@ "repository": { | ||
"devDependencies": { | ||
"@verdaccio/types": "11.0.0-6-next.15" | ||
"@verdaccio/types": "11.0.0-6-next.19" | ||
}, | ||
@@ -47,0 +46,0 @@ "funding": { |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
35913
442
4
1