You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.5 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
loadManifest: null,
evalManifest: null,
clearManifestCache: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
loadManifest: function() {
return loadManifest;
},
evalManifest: function() {
return evalManifest;
},
clearManifestCache: function() {
return clearManifestCache;
}
});
const _fs = require("fs");
const _vm = require("vm");
const cache = new Map();
function loadManifest(path, shouldCache = true) {
const cached = shouldCache && cache.get(path);
if (cached) {
return cached;
}
const manifest = JSON.parse((0, _fs.readFileSync)(path, "utf8"));
if (shouldCache) {
cache.set(path, manifest);
}
return manifest;
}
function evalManifest(path, shouldCache = true) {
const cached = shouldCache && cache.get(path);
if (cached) {
return cached;
}
const content = (0, _fs.readFileSync)(path, "utf8");
if (content.length === 0) {
throw new Error("Manifest file is empty");
}
const contextObject = {};
(0, _vm.runInNewContext)(content, contextObject);
if (shouldCache) {
cache.set(path, contextObject);
}
return contextObject;
}
function clearManifestCache(path) {
return cache.delete(path);
}
//# sourceMappingURL=load-manifest.js.map