Comparing version 3.3.7 to 3.4.0
343
out/main.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getTempName = getTempName; | ||
exports.TmpDir = void 0; | ||
function _fsExtra() { | ||
const data = require("fs-extra"); | ||
_fsExtra = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _os() { | ||
const data = require("os"); | ||
_os = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var path = _interopRequireWildcard(require("path")); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TmpDir = exports.getTempName = void 0; | ||
const fs_extra_1 = require("fs-extra"); | ||
const os_1 = require("os"); | ||
const path = require("path"); | ||
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)}`; | ||
} | ||
exports.getTempName = getTempName; | ||
let tempDirPromise; | ||
let tempBaseDir; | ||
function getBaseTempDir() { | ||
if (tempDirPromise != null) { | ||
if (tempDirPromise != null) { | ||
return tempDirPromise; | ||
} | ||
if (tempBaseDir != null) { | ||
return Promise.resolve(tempBaseDir); | ||
} | ||
const systemTmpDir = process.env.APP_BUILDER_TMP_DIR || os_1.tmpdir(); | ||
const isEnsureRemovedOnExit = process.env.TMP_DIR_MANAGER_ENSURE_REMOVED_ON_EXIT !== "false"; | ||
tempDirPromise = fs_extra_1.mkdtemp(path.join(systemTmpDir, "t-")) | ||
.then(it => fs_extra_1.realpath(it)) | ||
.then(dir => { | ||
if (isEnsureRemovedOnExit) { | ||
addExitHook(dir); | ||
} | ||
tempBaseDir = dir; | ||
return dir; | ||
}); | ||
return tempDirPromise; | ||
} | ||
if (tempBaseDir != null) { | ||
return Promise.resolve(tempBaseDir); | ||
} | ||
const systemTmpDir = process.env.APP_BUILDER_TMP_DIR || (0, _os().tmpdir)(); | ||
const isEnsureRemovedOnExit = process.env.TMP_DIR_MANAGER_ENSURE_REMOVED_ON_EXIT !== "false"; | ||
tempDirPromise = (0, _fsExtra().mkdtemp)(path.join(systemTmpDir, "t-")).then(it => (0, _fsExtra().realpath)(it)).then(dir => { | ||
if (isEnsureRemovedOnExit) { | ||
addExitHook(dir); | ||
} | ||
tempBaseDir = dir; | ||
return dir; | ||
}); | ||
return tempDirPromise; | ||
} | ||
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, _fsExtra().removeSync)(dir); | ||
} catch (e) { | ||
handleError(e, dir); | ||
} | ||
return; | ||
} | ||
Promise.all(managers.map(it => it.cleanup())).then(() => (0, _fsExtra().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 { | ||
fs_extra_1.removeSync(dir); | ||
} | ||
catch (e) { | ||
handleError(e, dir); | ||
} | ||
return; | ||
} | ||
Promise.all(managers.map(it => it.cleanup())) | ||
.then(() => fs_extra_1.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; | ||
} // noinspection JSMethodCanBeStatic,JSUnusedGlobalSymbols | ||
get rootTempDir() { | ||
return getBaseTempDir(); | ||
} | ||
getTempDir(options) { | ||
return this.getTempFile(options, true); | ||
} | ||
createTempDir(options) { | ||
return this.getTempFile(options, true).then(it => (0, _fsExtra().ensureDir)(it).then(() => it)); | ||
} | ||
getTempFile(options, isDir = false) { | ||
return getBaseTempDir().then(baseTempDir => { | ||
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 = `${baseTempDir}${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; | ||
constructor(debugName = "") { | ||
this.debugName = debugName; | ||
this.tempFiles = []; | ||
this.registered = false; | ||
} | ||
this.tempFiles = []; | ||
for (const file of tempFiles) { | ||
if (file.disposer != null) { | ||
// noinspection JSIgnoredPromiseFromCall | ||
file.disposer(file.path); | ||
continue; | ||
} | ||
try { | ||
if (file.isDir) { | ||
(0, _fsExtra().removeSync)(file.path); | ||
} else { | ||
(0, _fsExtra().unlinkSync)(file.path); | ||
// noinspection JSMethodCanBeStatic,JSUnusedGlobalSymbols | ||
get rootTempDir() { | ||
return getBaseTempDir(); | ||
} | ||
getTempDir(options) { | ||
return this.getTempFile(options, true); | ||
} | ||
createTempDir(options) { | ||
return this.getTempFile(options, true) | ||
.then(it => fs_extra_1.ensureDir(it).then(() => it)); | ||
} | ||
getTempFile(options, isDir = false) { | ||
return getBaseTempDir() | ||
.then(baseTempDir => { | ||
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 = `${baseTempDir}${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; | ||
} | ||
} catch (e) { | ||
handleError(e, file.path); | ||
} | ||
this.tempFiles = []; | ||
for (const file of tempFiles) { | ||
if (file.disposer != null) { | ||
// noinspection JSIgnoredPromiseFromCall | ||
file.disposer(file.path); | ||
continue; | ||
} | ||
try { | ||
if (file.isDir) { | ||
fs_extra_1.removeSync(file.path); | ||
} | ||
else { | ||
fs_extra_1.unlinkSync(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(); | ||
cleanup() { | ||
const tempFiles = this.tempFiles; | ||
tmpDirManagers.delete(this); | ||
this.registered = false; | ||
if (tempFiles.length === 0) { | ||
return Promise.resolve(); | ||
} | ||
this.tempFiles = []; | ||
if (tmpDirManagers.size === 0) { | ||
const dir = tempBaseDir; | ||
if (dir == null) { | ||
return Promise.resolve(); | ||
} | ||
tempBaseDir = null; | ||
tempDirPromise = null; | ||
return fs_extra_1.remove(dir); | ||
} | ||
return Promise.all(tempFiles.map(it => { | ||
if (it.disposer != null) { | ||
return it.disposer(it.path); | ||
} | ||
return (it.isDir ? fs_extra_1.remove(it.path) : fs_extra_1.unlink(it.path)) | ||
.catch(e => { | ||
handleError(e, it.path); | ||
}); | ||
})); | ||
} | ||
this.tempFiles = []; | ||
if (tmpDirManagers.size === 0) { | ||
const dir = tempBaseDir; | ||
if (dir == null) { | ||
return Promise.resolve(); | ||
} | ||
tempBaseDir = null; | ||
tempDirPromise = null; | ||
return (0, _fsExtra().remove)(dir); | ||
toString() { | ||
return this.debugName; | ||
} | ||
return Promise.all(tempFiles.map(it => { | ||
if (it.disposer != null) { | ||
return it.disposer(it.path); | ||
} | ||
return (it.isDir ? (0, _fsExtra().remove)(it.path) : (0, _fsExtra().unlink)(it.path)).catch(e => { | ||
handleError(e, it.path); | ||
}); | ||
})); | ||
} | ||
toString() { | ||
return this.debugName; | ||
} | ||
} | ||
exports.TmpDir = TmpDir; | ||
function nullize(s) { | ||
return s == null || s.length === 0 ? null : s; | ||
} | ||
// __ts-babel@6.0.4 | ||
return s == null || s.length === 0 ? null : s; | ||
} | ||
//# sourceMappingURL=main.js.map |
{ | ||
"name": "temp-file", | ||
"version": "3.3.7", | ||
"version": "3.4.0", | ||
"main": "out/main.js", | ||
@@ -14,23 +14,17 @@ "author": "Vladimir Krivosheev", | ||
"scripts": { | ||
"compile": "ts-babel", | ||
"release": "yarn compile && npm publish" | ||
"compile": "tsc", | ||
"release": "pnpm compile && pnpm publish --no-git-checks", | ||
"update-deps": "pnpm update -i -r --latest" | ||
}, | ||
"dependencies": { | ||
"async-exit-hook": "^2.0.1", | ||
"fs-extra": "^8.1.0" | ||
"fs-extra": "^10.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/fs-extra": "^8.1.0", | ||
"@types/js-yaml": "^3.12.2", | ||
"@types/node": "^13.7.7", | ||
"babel-preset-ts-node8": "^4.0.0", | ||
"ts-babel": "^6.1.7", | ||
"typescript": "^3.8.3" | ||
"@types/fs-extra": "^9.0.11", | ||
"@types/js-yaml": "^4.0.1", | ||
"@types/node": "^15.0.2", | ||
"typescript": "^4.2.4" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"babel-preset-ts-node8" | ||
] | ||
}, | ||
"typings": "./out/main.d.ts" | ||
} |
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
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
18379
4
189
+ Addedfs-extra@10.1.0(transitive)
+ Addedjsonfile@6.1.0(transitive)
+ Addeduniversalify@2.0.1(transitive)
- Removedfs-extra@8.1.0(transitive)
- Removedjsonfile@4.0.0(transitive)
- Removeduniversalify@0.1.2(transitive)
Updatedfs-extra@^10.0.0