esmodule plugins: wip

This commit is contained in:
Koushik Dutta
2024-11-30 09:09:38 -08:00
parent 71bb2ec80a
commit 73d2f5b408
6 changed files with 67 additions and 25 deletions

View File

@@ -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
View File

@@ -0,0 +1,5 @@
export async function eseval(script) {
// const dataUrl = `data:text/javascript,${encodeURIComponent(script)}`;
const module = await import(script);
return module;
}

View File

@@ -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;

View File

@@ -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",
],
}