|
1 | 1 | import { ForkWorker, ScryptedStatic, SystemManager } from '@scrypted/types';
|
2 | 2 | import child_process from 'child_process';
|
3 | 3 | import fs from 'fs';
|
4 |
| -import { createRequire } from 'module'; |
5 | 4 | import path from 'path';
|
6 | 5 | import { install as installSourceMapSupport } from 'source-map-support';
|
7 | 6 | import worker_threads from 'worker_threads';
|
@@ -138,9 +137,32 @@ export function startPluginRemote(mainFilename: string, pluginId: string, peerSe
|
138 | 137 | params.console = pluginConsole;
|
139 | 138 |
|
140 | 139 | const pnp = getPluginNodePath(pluginId);
|
141 |
| - const pnpNodeModules = path.join(pnp, 'node_modules'); |
| 140 | + // const pnpNodeModules = path.join(pnp, 'node_modules'); |
142 | 141 | 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); |
144 | 166 |
|
145 | 167 | params.module = {
|
146 | 168 | exports: {},
|
|
0 commit comments