@rocket.chat/apps-engine
Advanced tools
Comparing version 0.6.4 to 0.6.5
{ | ||
"name": "@rocket.chat/apps-engine", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"description": "The engine code for the Rocket.Chat Apps which manages, runs, translates, coordinates and all of that.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -30,3 +30,2 @@ import { AppManager } from '../AppManager'; | ||
private isValidFile(file); | ||
private buildCustomRequire(files); | ||
} |
@@ -13,2 +13,3 @@ "use strict"; | ||
const metadata_1 = require("@rocket.chat/apps-ts-definition/metadata"); | ||
const Utilities_1 = require("../misc/Utilities"); | ||
class AppCompiler { | ||
@@ -121,4 +122,4 @@ constructor() { | ||
// Let's ensure we search for the App's modules first | ||
if (result.files[path.normalize(moduleName).replace(/\.\.\//g, '') + '.ts']) { | ||
resolvedModules.push({ resolvedFileName: path.normalize(moduleName).replace(/\.\.\//g, '') + '.ts' }); | ||
if (result.files[Utilities_1.Utilities.transformModuleForCustomRequire(moduleName)]) { | ||
resolvedModules.push({ resolvedFileName: Utilities_1.Utilities.transformModuleForCustomRequire(moduleName) }); | ||
} | ||
@@ -224,3 +225,3 @@ else { | ||
} | ||
const customRequire = this.buildCustomRequire(files); | ||
const customRequire = Utilities_1.Utilities.buildCustomRequire(files); | ||
const context = vm.createContext({ require: customRequire, exports, process: {} }); | ||
@@ -274,15 +275,2 @@ const script = new vm.Script(files[path.normalize(storage.info.classFile)].compiled); | ||
} | ||
buildCustomRequire(files) { | ||
return function _requirer(mod) { | ||
if (files[path.normalize(mod + '.ts')]) { | ||
const ourExport = {}; | ||
const context = vm.createContext({ require, exports: ourExport, process: {} }); | ||
vm.runInContext(files[path.normalize(mod + '.ts')].compiled, context); | ||
return ourExport; | ||
} | ||
else { | ||
return require(mod); | ||
} | ||
}; | ||
} | ||
} | ||
@@ -289,0 +277,0 @@ exports.AppCompiler = AppCompiler; |
@@ -0,1 +1,2 @@ | ||
import { ICompilerFile } from '../compiler'; | ||
export declare class Utilities { | ||
@@ -5,2 +6,6 @@ static deepClone<T>(item: T): T; | ||
static deepCloneAndFreeze<T>(item: T): T; | ||
static transformModuleForCustomRequire(moduleName: string): string; | ||
static buildCustomRequire(files: { | ||
[s: string]: ICompilerFile; | ||
}): (mod: string) => {}; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const cloneDeep = require("lodash.clonedeep"); | ||
const path = require("path"); | ||
const vm = require("vm"); | ||
class Utilities { | ||
@@ -21,2 +23,22 @@ static deepClone(item) { | ||
} | ||
static transformModuleForCustomRequire(moduleName) { | ||
return path.normalize(moduleName).replace(/\.\.\//g, '') + '.ts'; | ||
} | ||
static buildCustomRequire(files) { | ||
return function _requirer(mod) { | ||
if (files[Utilities.transformModuleForCustomRequire(mod)]) { | ||
const ourExport = {}; | ||
const context = vm.createContext({ | ||
require: Utilities.buildCustomRequire(files), | ||
exports: ourExport, | ||
process: {}, | ||
}); | ||
vm.runInContext(files[Utilities.transformModuleForCustomRequire(mod)].compiled, context); | ||
return ourExport; | ||
} | ||
else { | ||
return require(mod); | ||
} | ||
}; | ||
} | ||
} | ||
@@ -23,0 +45,0 @@ exports.Utilities = Utilities; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
489747
4864