- Consolidated duplicate UndoManagers to single instance - Fixed connection promise to only resolve on 'connected' status - Fixed WebSocketProvider import (WebsocketProvider) - Added proper doc.destroy() cleanup - Renamed isPresenceInitialized property to avoid conflict Co-Authored-By: Paperclip <noreply@paperclip.ing>
67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
"use strict";
|
|
|
|
const { createHash } = require("crypto");
|
|
const fs = require("graceful-fs");
|
|
function sha1hex(content) {
|
|
return createHash("sha1").update(content).digest("hex");
|
|
}
|
|
class Worker {
|
|
#plugins;
|
|
constructor({ plugins = [] }) {
|
|
this.#plugins = plugins.map(({ modulePath, setupArgs }) => {
|
|
const PluginWorker = require(modulePath);
|
|
return new PluginWorker(setupArgs);
|
|
});
|
|
}
|
|
processFile(data) {
|
|
let content;
|
|
let sha1;
|
|
const { computeSha1, filePath, pluginsToRun } = data;
|
|
const getContent = () => {
|
|
if (content == null) {
|
|
content = fs.readFileSync(filePath);
|
|
}
|
|
return content;
|
|
};
|
|
const workerUtils = {
|
|
getContent,
|
|
};
|
|
const pluginData = pluginsToRun.map((pluginIdx) =>
|
|
this.#plugins[pluginIdx].processFile(data, workerUtils),
|
|
);
|
|
if (computeSha1) {
|
|
sha1 = sha1hex(getContent());
|
|
}
|
|
return content && data.maybeReturnContent
|
|
? {
|
|
content,
|
|
pluginData,
|
|
sha1,
|
|
}
|
|
: {
|
|
pluginData,
|
|
sha1,
|
|
};
|
|
}
|
|
}
|
|
let singletonWorker;
|
|
function setup(args) {
|
|
if (singletonWorker) {
|
|
throw new Error("metro-file-map: setup() should only be called once");
|
|
}
|
|
singletonWorker = new Worker(args);
|
|
}
|
|
function processFile(data) {
|
|
if (!singletonWorker) {
|
|
throw new Error(
|
|
"metro-file-map: setup() must be called before processFile()",
|
|
);
|
|
}
|
|
return singletonWorker.processFile(data);
|
|
}
|
|
module.exports = {
|
|
setup,
|
|
processFile,
|
|
Worker,
|
|
};
|