mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Refactored Sandbox to be singleton
no-issue
This commit is contained in:
parent
fd9fc92dd5
commit
ad9d142174
2 changed files with 5 additions and 16 deletions
|
@ -4,7 +4,7 @@ const Promise = require('bluebird');
|
|||
const config = require('../../config');
|
||||
const common = require('../../lib/common');
|
||||
const AppProxy = require('./proxy');
|
||||
const AppSandbox = require('./sandbox');
|
||||
const Sandbox = require('./sandbox');
|
||||
const AppDependencies = require('./dependencies');
|
||||
const AppPermissions = require('./permissions');
|
||||
|
||||
|
@ -27,9 +27,7 @@ function getAppRelativePath(name, relativeTo = __dirname) {
|
|||
|
||||
// Load apps through a pseudo sandbox
|
||||
function loadApp(appPath) {
|
||||
const sandbox = new AppSandbox();
|
||||
|
||||
return sandbox.loadApp(appPath);
|
||||
return Sandbox.loadApp(appPath);
|
||||
}
|
||||
|
||||
function getAppByName(name, permissions) {
|
||||
|
|
|
@ -1,22 +1,13 @@
|
|||
const Module = require('module');
|
||||
|
||||
function AppSandbox(opts) {
|
||||
this.opts = opts;
|
||||
}
|
||||
|
||||
AppSandbox.prototype.loadApp = function loadAppSandboxed(appPath) {
|
||||
// Set loaded modules parent to this
|
||||
const parentModulePath = this.opts.parent || module.parent;
|
||||
|
||||
module.exports.loadApp = function loadAppSandboxed(appPath) {
|
||||
// Resolve the modules path
|
||||
const resolvedModulePath = Module._resolveFilename(appPath, parentModulePath);
|
||||
const resolvedModulePath = Module._resolveFilename(appPath, module.parent);
|
||||
|
||||
// Instantiate a Node Module class
|
||||
const currentModule = new Module(resolvedModulePath, parentModulePath);
|
||||
const currentModule = new Module(resolvedModulePath, module.parent);
|
||||
|
||||
currentModule.load(currentModule.id);
|
||||
|
||||
return currentModule.exports;
|
||||
};
|
||||
|
||||
module.exports = AppSandbox;
|
||||
|
|
Loading…
Add table
Reference in a new issue