mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Refactored Sandbox to be singleton
no-issue
This commit is contained in:
parent
fd9fc92dd5
commit
ad9d142174
@ -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…
Reference in New Issue
Block a user