mirror of
https://github.com/koush/scrypted.git
synced 2026-03-06 03:12:00 +00:00
esmodule plugins: wip
This commit is contained in:
2
server/.vscode/launch.json
vendored
2
server/.vscode/launch.json
vendored
@@ -5,7 +5,7 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"autoAttachChildProcesses": false,
|
||||
"autoAttachChildProcesses": true,
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
|
||||
5
server/es-eval.js
Normal file
5
server/es-eval.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export async function eseval(script) {
|
||||
// const dataUrl = `data:text/javascript,${encodeURIComponent(script)}`;
|
||||
const module = await import(script);
|
||||
return module;
|
||||
}
|
||||
@@ -24,6 +24,8 @@ import { NodeThreadWorker } from './runtime/node-thread-worker';
|
||||
import { prepareZip } from './runtime/node-worker-common';
|
||||
import { getBuiltinRuntimeHosts } from './runtime/runtime-host';
|
||||
import { RuntimeWorker, RuntimeWorkerOptions } from './runtime/runtime-worker';
|
||||
// @ts-expect-error
|
||||
import { eseval } from '../../es-eval.js';
|
||||
|
||||
const serverVersion = require('../../package.json').version;
|
||||
|
||||
@@ -360,9 +362,17 @@ export function startPluginRemote(mainFilename: string, pluginId: string, peerSe
|
||||
|
||||
try {
|
||||
const filename = zipOptions?.debug ? pluginMainNodeJs : pluginIdMainNodeJs;
|
||||
evalLocal(peer, script, startPluginRemoteOptions?.sourceURL?.(filename) || filename, params);
|
||||
if (packageJson.type === 'module') {
|
||||
const p = path.join(unzippedPath, mainNodejs);
|
||||
const module = await eseval(p);
|
||||
params.module.exports = module;
|
||||
}
|
||||
else {
|
||||
evalLocal(peer, script, startPluginRemoteOptions?.sourceURL?.(filename) || filename, params);
|
||||
}
|
||||
|
||||
const exports = params.module.exports;
|
||||
exports.sdkInit?.(params);
|
||||
if (zipOptions?.fork) {
|
||||
// pluginConsole?.log('plugin forked');
|
||||
const fork = exports.fork;
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
// skip error: Interface 'WebGL2RenderingContext' incorrectly extends interface 'WebGL2RenderingContextBase'.
|
||||
// https://github.com/tensorflow/tfjs/issues/4201
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true
|
||||
"sourceMap": true,
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
"src/**/*", "es-eval.js",
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user