<commit_before>import {fork} from "child_process";

import {IWorkerThreadFactory} from "../../common/worker/worker-thread-factory";
import {DefaultWorkerThread} from "../../common/worker/default-worker-thread";
import {IWorkerThread} from "../../common/worker/worker-thread";
import {DynamicFunctionRegistry} from "../../common/function/dynamic-function-registry";
import {ChildProcessWorkerThreadSlaveCommunicationChannel} from "./child-process-worker-thread-slave-communication-channel";

export class NodeWorkerThreadFactory implements IWorkerThreadFactory {
    constructor(private functionLookupTable: DynamicFunctionRegistry) {}

    public spawn(): IWorkerThread {
        const child = fork(this.getSlaveFileName());
        const workerThread = new DefaultWorkerThread(this.functionLookupTable, new ChildProcessWorkerThreadSlaveCommunicationChannel(child));
        workerThread.initialize();
        return workerThread;
    }

    /**
     * Hackedy Hack... Issue is, webpack handles calls to require resolve and replaces the call with the module id
     * but that's not what we want. We actually want the require resolve call to be left until execution.
     * NoParse is neither an option because then no requires / imports are resolved
     * @returns {string} the file name of the slave
     */
    private getSlaveFileName(): string {
        /* tslint:disable:no-eval */
        const requireResolve = eval("require.resolve") as (moduleName: string) => string;
        /* tslint:enable:no-eval */
        // TODO get es5 or es6 version
        return requireResolve("parallel-es/dist/node-slave.parallel.js");
    }
}<commit_msg>Fix module resolution for node slave<commit_after>import {fork} from "child_process";

import {IWorkerThreadFactory} from "../../common/worker/worker-thread-factory";
import {DefaultWorkerThread} from "../../common/worker/default-worker-thread";
import {IWorkerThread} from "../../common/worker/worker-thread";
import {DynamicFunctionRegistry} from "../../common/function/dynamic-function-registry";
import {ChildProcessWorkerThreadSlaveCommunicationChannel} from "./child-process-worker-thread-slave-communication-channel";

export class NodeWorkerThreadFactory implements IWorkerThreadFactory {
    constructor(private functionLookupTable: DynamicFunctionRegistry) {}

    public spawn(): IWorkerThread {
        const child = fork(this.getSlaveFileName());
        const workerThread = new DefaultWorkerThread(this.functionLookupTable, new ChildProcessWorkerThreadSlaveCommunicationChannel(child));
        workerThread.initialize();
        return workerThread;
    }

    /**
     * Hackedy Hack... Issue is, webpack handles calls to require resolve and replaces the call with the module id
     * but that's not what we want. We actually want the require resolve call to be left until execution.
     * NoParse is neither an option because then no requires / imports are resolved
     * @returns {string} the file name of the slave
     */
    private getSlaveFileName(): string {
        return eval("require").resolve("./node-slave.parallel");
    }
}
{'fraction_non_alphanumeric': 0.10528010302640052, 'fraction_numerical': 0.000643915003219575, 'mean_word_length': 3.9474522292993632, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4617891', 'n_tokens_mistral': 765, 'n_tokens_neox': 751, 'n_words': 236}