Skip to content

Commit 84870b4

Browse files
committed
server: revert createRequire
1 parent 339c934 commit 84870b4

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

server/src/plugin/plugin-remote-worker.ts

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ForkWorker, ScryptedStatic, SystemManager } from '@scrypted/types';
22
import child_process from 'child_process';
33
import fs from 'fs';
4-
import { createRequire } from 'module';
54
import path from 'path';
65
import { install as installSourceMapSupport } from 'source-map-support';
76
import worker_threads from 'worker_threads';
@@ -138,9 +137,32 @@ export function startPluginRemote(mainFilename: string, pluginId: string, peerSe
138137
params.console = pluginConsole;
139138

140139
const pnp = getPluginNodePath(pluginId);
141-
const pnpNodeModules = path.join(pnp, 'node_modules');
140+
// const pnpNodeModules = path.join(pnp, 'node_modules');
142141
pluginConsole?.log('node modules', pnp);
143-
params.require = createRequire(pnpNodeModules);
142+
params.require = (name: string) => {
143+
if (name === 'realfs') {
144+
return require('fs');
145+
}
146+
try {
147+
if (name.startsWith('.') && unzippedPath) {
148+
try {
149+
const c = path.join(unzippedPath, name);
150+
const module = require(c);
151+
return module;
152+
}
153+
catch (e) {
154+
}
155+
}
156+
const module = require(name);
157+
return module;
158+
}
159+
catch (e) {
160+
const c = path.join(pnp, 'node_modules', name);
161+
return require(c);
162+
}
163+
};
164+
// this breaks relative imports, which currently arent in use i think.
165+
// params.require = createRequire(pnpNodeModules);
144166

145167
params.module = {
146168
exports: {},

0 commit comments

Comments
 (0)