mirror of
https://github.com/koush/scrypted.git
synced 2026-02-10 01:02:18 +00:00
server: better stack traces that indicate plugin source
This commit is contained in:
@@ -127,8 +127,12 @@ export class PluginAPIProxy extends PluginAPIManagedListeners implements PluginA
|
||||
}
|
||||
}
|
||||
|
||||
export interface PluginRemoteLoadZipOptions {
|
||||
filename?: string;
|
||||
}
|
||||
|
||||
export interface PluginRemote {
|
||||
loadZip(packageJson: any, zipData: Buffer): Promise<any>;
|
||||
loadZip(packageJson: any, zipData: Buffer, options?: PluginRemoteLoadZipOptions): Promise<any>;
|
||||
setSystemState(state: {[id: string]: {[property: string]: SystemDeviceState}}): Promise<void>;
|
||||
setNativeId(nativeId: ScryptedNativeId, id: string, storage: {[key: string]: any}): Promise<void>;
|
||||
updateDescriptor(id: string, state: {[property: string]: SystemDeviceState}): Promise<void>;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ScryptedRuntime } from '../runtime';
|
||||
import { Plugin } from '../db-types';
|
||||
import io from 'engine.io';
|
||||
import { attachPluginRemote, setupPluginRemote } from './plugin-remote';
|
||||
import { PluginRemote } from './plugin-api';
|
||||
import { PluginRemote, PluginRemoteLoadZipOptions } from './plugin-api';
|
||||
import { Logger } from '../logger';
|
||||
import { MediaManagerImpl } from './media';
|
||||
import { getState } from '../state';
|
||||
@@ -183,7 +183,12 @@ export class PluginHost {
|
||||
|
||||
const fail = 'Plugin failed to load. Console for more information.';
|
||||
try {
|
||||
const module = await remote.loadZip(plugin.packageJson, zipBuffer);
|
||||
const loadZipOptions: PluginRemoteLoadZipOptions = {
|
||||
// if debugging, use a normalized path for sourcemap resolution, otherwise
|
||||
// prefix with module path.
|
||||
filename: pluginDebug ? '/plugin/main.nodejs.js' : `/${this.pluginId}/main.node.js`,
|
||||
};
|
||||
const module = await remote.loadZip(plugin.packageJson, zipBuffer, loadZipOptions);
|
||||
logger.log('i', `loaded ${this.pluginName}`);
|
||||
logger.clearAlert(fail)
|
||||
return { module, remote };
|
||||
@@ -602,11 +607,11 @@ class LazyRemote implements PluginRemote {
|
||||
})();
|
||||
}
|
||||
|
||||
async loadZip(packageJson: any, zipData: Buffer): Promise<any> {
|
||||
async loadZip(packageJson: any, zipData: Buffer, options?: PluginRemoteLoadZipOptions): Promise<any> {
|
||||
if (!this.remote)
|
||||
await this.init;
|
||||
|
||||
return this.remote.loadZip(packageJson, zipData);
|
||||
return this.remote.loadZip(packageJson, zipData, options);
|
||||
}
|
||||
async setSystemState(state: { [id: string]: { [property: string]: SystemDeviceState; }; }): Promise<void> {
|
||||
if (!this.remote)
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Volume } from 'memfs';
|
||||
import path from 'path';
|
||||
import { ScryptedNativeId, DeviceManager, Logger, Device, DeviceManifest, DeviceState, EndpointManager, SystemDeviceState, ScryptedStatic, SystemManager, MediaManager, ScryptedMimeTypes, ScryptedInterface, ScryptedInterfaceProperty, HttpRequest } from '@scrypted/sdk/types'
|
||||
import { getIpAddress, SCRYPTED_INSECURE_PORT, SCRYPTED_SECURE_PORT } from '../server-settings';
|
||||
import { PluginAPI, PluginLogger, PluginRemote } from './plugin-api';
|
||||
import { PluginAPI, PluginLogger, PluginRemote, PluginRemoteLoadZipOptions } from './plugin-api';
|
||||
import { SystemManagerImpl } from './system';
|
||||
import { RpcPeer } from '../rpc';
|
||||
import { BufferSerializer } from './buffer-serializer';
|
||||
@@ -368,7 +368,7 @@ export function attachPluginRemote(peer: RpcPeer, options?: PluginRemoteAttachOp
|
||||
done(ret);
|
||||
},
|
||||
|
||||
async loadZip(packageJson: any, zipData: Buffer) {
|
||||
async loadZip(packageJson: any, zipData: Buffer, options?: PluginRemoteLoadZipOptions) {
|
||||
const zip = new AdmZip(zipData);
|
||||
events?.emit('zip', zip);
|
||||
const main = zip.getEntry('main.nodejs.js');
|
||||
@@ -449,7 +449,7 @@ export function attachPluginRemote(peer: RpcPeer, options?: PluginRemoteAttachOp
|
||||
events?.emit('params', params);
|
||||
|
||||
try {
|
||||
peer.evalLocal(script, '/plugin/main.nodejs.js', params);
|
||||
peer.evalLocal(script, options?.filename || '/plugin/main.nodejs.js', params);
|
||||
events?.emit('plugin', exports.default);
|
||||
return exports.default;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user