Socket
Socket
Sign inDemoInstall

temp-file

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

temp-file - npm Package Compare versions

Comparing version 3.1.1 to 3.1.2

330

out/main.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.TmpDir = undefined;
exports.getTempName = getTempName;
exports.TmpDir = void 0;
var _bluebirdLst;
function _bluebirdLst() {
const data = _interopRequireDefault(require("bluebird-lst"));
function _load_bluebirdLst() {
return _bluebirdLst = _interopRequireDefault(require("bluebird-lst"));
_bluebirdLst = function () {
return data;
};
return data;
}
var _fsExtraP;
function _fsExtraP() {
const data = require("fs-extra-p");
function _load_fsExtraP() {
return _fsExtraP = require("fs-extra-p");
_fsExtraP = function () {
return data;
};
return data;
}
var _lazyVal;
function _lazyVal() {
const data = require("lazy-val");
function _load_lazyVal() {
return _lazyVal = require("lazy-val");
_lazyVal = function () {
return data;
};
return data;
}
var _os;
function _os() {
const data = require("os");
function _load_os() {
return _os = require("os");
_os = function () {
return data;
};
return data;
}
var _path = _interopRequireWildcard(require("path"));
var path = _interopRequireWildcard(require("path"));
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

@@ -40,144 +56,178 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

let tmpFileCounter = 0;
const tmpDirManagers = new Set();
// add date to avoid use stale temp dir
const tmpDirManagers = new Set(); // add date to avoid use stale temp dir
const tempDirPrefix = `${process.pid.toString(36)}-${Date.now().toString(36)}`;
function getTempName(prefix) {
return `${prefix == null ? "" : `${prefix}-`}${tempDirPrefix}-${(tmpFileCounter++).toString(36)}`;
return `${prefix == null ? "" : `${prefix}-`}${tempDirPrefix}-${(tmpFileCounter++).toString(36)}`;
}
const tempDir = new (_lazyVal || _load_lazyVal()).Lazy(() => {
let promise;
const systemTmpDir = process.env.TEST_TMP_DIR || process.env.ELECTRON_BUILDER_TMP_DIR || process.env.ELECTRON_BUILDER_TEST_DIR || (0, (_os || _load_os()).tmpdir)();
const isEnsureRemovedOnExit = process.env.TMP_DIR_MANAGER_ENSURE_REMOVED_ON_EXIT !== "false";
if (!isEnsureRemovedOnExit) {
promise = Promise.resolve(systemTmpDir);
} else if ((_fsExtraP || _load_fsExtraP()).mkdtemp == null) {
const dir = _path.join(systemTmpDir, getTempName("temp-files"));
promise = (0, (_fsExtraP || _load_fsExtraP()).ensureDir)(dir, { mode: 448 }).then(() => dir);
} else {
promise = (0, (_fsExtraP || _load_fsExtraP()).mkdtemp)(`${_path.join(systemTmpDir, "temp-dir")}-`);
const tempDir = new (_lazyVal().Lazy)(() => {
let promise;
const systemTmpDir = process.env.TEST_TMP_DIR || process.env.ELECTRON_BUILDER_TMP_DIR || process.env.ELECTRON_BUILDER_TEST_DIR || (0, _os().tmpdir)();
const isEnsureRemovedOnExit = process.env.TMP_DIR_MANAGER_ENSURE_REMOVED_ON_EXIT !== "false";
if (!isEnsureRemovedOnExit) {
promise = Promise.resolve(systemTmpDir);
} else if (_fsExtraP().mkdtemp == null) {
const dir = path.join(systemTmpDir, getTempName("temp-files"));
promise = (0, _fsExtraP().ensureDir)(dir, {
mode: 448
}).then(() => dir);
} else {
promise = (0, _fsExtraP().mkdtemp)(`${path.join(systemTmpDir, "temp-dir")}-`);
}
return promise.then(it => (0, _fsExtraP().realpath)(it)).then(dir => {
if (isEnsureRemovedOnExit) {
addExitHook(dir);
}
return promise.then(it => (0, (_fsExtraP || _load_fsExtraP()).realpath)(it)).then(dir => {
if (isEnsureRemovedOnExit) {
addExitHook(dir);
}
return dir;
});
return dir;
});
});
function addExitHook(dir) {
require("async-exit-hook")(callback => {
const managers = Array.from(tmpDirManagers);
tmpDirManagers.clear();
if (callback == null) {
for (const manager of managers) {
manager.cleanupSync();
}
try {
(0, (_fsExtraP || _load_fsExtraP()).removeSync)(dir);
} catch (e) {
handleError(e, dir);
}
return;
}
// each instead of map to avoid fs overload
(_bluebirdLst || _load_bluebirdLst()).default.each(managers, it => it.cleanup()).then(() => (0, (_fsExtraP || _load_fsExtraP()).remove)(dir)).then(() => callback()).catch(e => {
try {
handleError(e, dir);
} finally {
callback();
}
});
require("async-exit-hook")(callback => {
const managers = Array.from(tmpDirManagers);
tmpDirManagers.clear();
if (callback == null) {
for (const manager of managers) {
manager.cleanupSync();
}
try {
(0, _fsExtraP().removeSync)(dir);
} catch (e) {
handleError(e, dir);
}
return;
} // each instead of map to avoid fs overload
_bluebirdLst().default.each(managers, it => it.cleanup()).then(() => (0, _fsExtraP().remove)(dir)).then(() => callback()).catch(e => {
try {
handleError(e, dir);
} finally {
callback();
}
});
});
}
function handleError(e, file) {
if (e.code !== "EPERM" && e.code !== "ENOENT") {
// use only console.* instead of our warn on exit (otherwise nodeEmoji can be required on request)
console.warn(`Cannot delete temporary "${file}": ${(e.stack || e).toString()}`);
}
if (e.code !== "EPERM" && e.code !== "ENOENT") {
// use only console.* instead of our warn on exit (otherwise nodeEmoji can be required on request)
console.warn(`Cannot delete temporary "${file}": ${(e.stack || e).toString()}`);
}
}
class TmpDir {
constructor(debugName = "") {
this.debugName = debugName;
this.tempFiles = [];
this.registered = false;
constructor(debugName = "") {
this.debugName = debugName;
this.tempFiles = [];
this.registered = false;
} // noinspection JSMethodCanBeStatic
// noinspection JSUnusedGlobalSymbols
get rootTempDir() {
return tempDir.value;
}
getTempDir(options) {
return this.getTempFile(options, true);
}
createTempDir(options) {
return this.getTempFile(options, true).then(it => (0, _fsExtraP().ensureDir)(it).then(() => it));
}
getTempFile(options, isDir = false) {
return tempDir.value.then(it => {
if (!this.registered) {
this.registered = true;
tmpDirManagers.add(this);
}
const prefix = nullize(options == null ? null : options.prefix);
const suffix = nullize(options == null ? null : options.suffix);
const namePrefix = prefix == null ? "" : `${prefix}-`;
const nameSuffix = suffix == null ? "" : suffix.startsWith(".") ? suffix : `-${suffix}`;
const result = `${it}${path.sep}${namePrefix}${(tmpFileCounter++).toString(36)}${nameSuffix}`;
this.tempFiles.push({
path: result,
isDir,
disposer: options == null ? null : options.disposer
});
return result;
});
}
cleanupSync() {
const tempFiles = this.tempFiles;
tmpDirManagers.delete(this);
this.registered = false;
if (tempFiles.length === 0) {
return;
}
// noinspection JSMethodCanBeStatic
// noinspection JSUnusedGlobalSymbols
get rootTempDir() {
return tempDir.value;
}
getTempDir(options) {
return this.getTempFile(options, true);
}
createTempDir(options) {
return this.getTempFile(options, true).then(it => (0, (_fsExtraP || _load_fsExtraP()).ensureDir)(it).then(() => it));
}
getTempFile(options, isDir = false) {
return tempDir.value.then(it => {
if (!this.registered) {
this.registered = true;
tmpDirManagers.add(this);
}
const prefix = nullize(options == null ? null : options.prefix);
const suffix = nullize(options == null ? null : options.suffix);
const namePrefix = prefix == null ? "" : `${prefix}-`;
const nameSuffix = suffix == null ? "" : suffix.startsWith(".") ? suffix : `-${suffix}`;
const result = `${it}${_path.sep}${namePrefix}${(tmpFileCounter++).toString(36)}${nameSuffix}`;
this.tempFiles.push({
path: result,
isDir,
disposer: options == null ? null : options.disposer
});
return result;
});
}
cleanupSync() {
const tempFiles = this.tempFiles;
tmpDirManagers.delete(this);
this.registered = false;
if (tempFiles.length === 0) {
return;
this.tempFiles = [];
for (const file of tempFiles) {
if (file.disposer != null) {
// noinspection JSIgnoredPromiseFromCall
file.disposer(file.path);
continue;
}
try {
if (file.isDir) {
(0, _fsExtraP().removeSync)(file.path);
} else {
(0, _fsExtraP().unlinkSync)(file.path);
}
this.tempFiles = [];
for (const file of tempFiles) {
if (file.disposer != null) {
// noinspection JSIgnoredPromiseFromCall
file.disposer(file.path);
continue;
}
try {
if (file.isDir) {
(0, (_fsExtraP || _load_fsExtraP()).removeSync)(file.path);
} else {
(0, (_fsExtraP || _load_fsExtraP()).unlinkSync)(file.path);
}
} catch (e) {
handleError(e, file.path);
}
}
} catch (e) {
handleError(e, file.path);
}
}
cleanup() {
const tempFiles = this.tempFiles;
tmpDirManagers.delete(this);
this.registered = false;
if (tempFiles.length === 0) {
return Promise.resolve();
}
this.tempFiles = [];
return (_bluebirdLst || _load_bluebirdLst()).default.map(tempFiles, it => {
if (it.disposer != null) {
return it.disposer(it.path);
}
return (it.isDir ? (0, (_fsExtraP || _load_fsExtraP()).remove)(it.path) : (0, (_fsExtraP || _load_fsExtraP()).unlink)(it.path)).catch(e => {
handleError(e, it.path);
});
}, { concurrency: 8 });
}
cleanup() {
const tempFiles = this.tempFiles;
tmpDirManagers.delete(this);
this.registered = false;
if (tempFiles.length === 0) {
return Promise.resolve();
}
toString() {
return this.debugName;
}
this.tempFiles = [];
return _bluebirdLst().default.map(tempFiles, it => {
if (it.disposer != null) {
return it.disposer(it.path);
}
return (it.isDir ? (0, _fsExtraP().remove)(it.path) : (0, _fsExtraP().unlink)(it.path)).catch(e => {
handleError(e, it.path);
});
}, {
concurrency: 8
});
}
toString() {
return this.debugName;
}
}
exports.TmpDir = TmpDir;
function nullize(s) {
return s == null || s.length === 0 ? null : s;
}
return s == null || s.length === 0 ? null : s;
}
//# sourceMappingURL=main.js.map
{
"name": "temp-file",
"version": "3.1.1",
"version": "3.1.2",
"main": "out/main.js",

@@ -20,11 +20,11 @@ "author": "Vladimir Krivosheev",

"bluebird-lst": "^1.0.5",
"fs-extra-p": "^4.5.0",
"fs-extra-p": "^4.6.0",
"lazy-val": "^1.0.3"
},
"devDependencies": {
"@types/js-yaml": "^3.10.1",
"@types/node": "^9.3.0",
"babel-preset-ts-node6-bluebird": "^1.0.1",
"ts-babel": "^4.1.8",
"typescript": "^2.6.2"
"@types/js-yaml": "^3.11.1",
"@types/node": "^10.0.2",
"babel-preset-ts-node6-bluebird": "^2.0.5",
"ts-babel": "^5.0.3",
"typescript": "^2.8.3"
},

@@ -31,0 +31,0 @@ "babel": {

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