Skip to content

Commit

Permalink
Loading plugins via application sandbox
Browse files Browse the repository at this point in the history
Pr-URL: #1762
  • Loading branch information
georgolden authored and tshemsedinov committed Jul 26, 2022
1 parent c21d862 commit a911979
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const assignNamespace = (container, name, value) => {
container[camelKey] = value;
};

const loadPlugins = (lib) => {
for (const plugin of Object.keys(lib.plugins)) {
lib.plugins[plugin] = String(lib.plugins[plugin]);
}
};

for (const name of dependencies) {
if (name === 'impress') continue;
let lib = null;
Expand All @@ -45,6 +51,7 @@ for (const name of dependencies) {
}
continue;
}
if (lib.plugins) loadPlugins(lib);
if (internals.includes(name)) {
assignNamespace(node, name, lib);
continue;
Expand Down
9 changes: 5 additions & 4 deletions lib/interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Interfaces extends Cache {

async change(filePath) {
if (!filePath.endsWith('.js')) return;
let script = await this.createScript(filePath);
const script = await this.createScript(filePath);
if (!script) return;
const proc = new Procedure(script, 'method', this.application);
let iface = proc.exports;
Expand All @@ -84,10 +84,11 @@ class Interfaces extends Cache {
if (!lib || !lib.plugins) return;
const plugin = lib.plugins[name];
if (!plugin) return;
script = plugin(iface);
iface = script();
const context = this.application.sandbox;
const { exports } = metavm.createScript(name, plugin, { context });
iface = exports(iface);
}
for (const name of Object.keys(iface)) {
for (const [name, script] of Object.entries(iface)) {
const proc = new Procedure(script, name, this.application);
this.changeInterface(interfaceName, name, proc);
}
Expand Down

0 comments on commit a911979

Please sign in to comment.