[Updater > v1 > Module] Use custom wrapper instead of replacing for better handling and futureproofing
This commit is contained in:
parent
b9f3656f34
commit
4aff24376c
2 changed files with 32 additions and 3 deletions
|
@ -22,6 +22,8 @@ var _module = _interopRequireDefault(require("module"));
|
|||
|
||||
var _events = require("events");
|
||||
|
||||
var _mkdirp = _interopRequireDefault(require("../utils/mkdirp"));
|
||||
|
||||
var _process = require("process");
|
||||
|
||||
var _yauzl = _interopRequireDefault(require("yauzl"));
|
||||
|
@ -226,7 +228,7 @@ function init(_endpoint, _settings, _buildInfo) {
|
|||
installedModulesFilePath = _path.default.join(moduleInstallPath, 'installed.json');
|
||||
moduleDownloadPath = _path.default.join(moduleInstallPath, 'pending');
|
||||
|
||||
_fs.default.mkdirSync(moduleDownloadPath, { recursive: true });
|
||||
_mkdirp.default.sync(moduleDownloadPath);
|
||||
|
||||
logger.log(`Module install path: ${moduleInstallPath}`);
|
||||
logger.log(`Module installed file path: ${installedModulesFilePath}`);
|
||||
|
@ -727,7 +729,7 @@ function processUnzipQueue() {
|
|||
}
|
||||
|
||||
stream.on('error', e => onError(e, zipfile));
|
||||
_fs.default.mkdir(_path.default.join(extractRoot, _path.default.dirname(entry.fileName)), err => {
|
||||
(0, _mkdirp.default)(_path.default.join(extractRoot, _path.default.dirname(entry.fileName)), err => {
|
||||
if (err) {
|
||||
onError(err, zipfile);
|
||||
return;
|
||||
|
@ -764,7 +766,7 @@ function processUnzipQueue() {
|
|||
zipfile.readEntry();
|
||||
});
|
||||
stream.pipe(writeStream);
|
||||
}, { recursive: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
zipfile.on('error', err => {
|
||||
|
|
27
src/utils/mkdirp.js
Normal file
27
src/utils/mkdirp.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Minimal wrapper mimicking mkdirp package
|
||||
|
||||
exports.__esModule = true; // Makes moduleUpdater internals load properly
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
|
||||
const async = (path, callback) => { // async
|
||||
log('Mkdirp', 'Async:', path);
|
||||
|
||||
try {
|
||||
fs.mkdir(path, callback, { recursive: true });
|
||||
} catch (e) { } // Doesn't exist, ignore
|
||||
};
|
||||
|
||||
const sync = (path) => { // sync
|
||||
log('Mkdirp', 'Sync:', path);
|
||||
|
||||
try {
|
||||
fs.mkdirSync(path, { recursive: true });
|
||||
} catch (e) { } // Doesn't exist, ignore
|
||||
};
|
||||
|
||||
const toExport = async;
|
||||
toExport.sync = sync;
|
||||
|
||||
exports.default = toExport;
|
Loading…
Reference in a new issue