Socket
Socket
Sign inDemoInstall

@rocket.chat/apps-compiler

Package Overview
Dependencies
38
Maintainers
9
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.4 to 0.1.5

63

AppsCompiler.js

@@ -172,3 +172,3 @@ "use strict";

if (e.token === this.ts.SyntaxKind.ExtendsKeyword) {
this.checkInheritance(src);
this.checkInheritance(src, nn.getText());
}

@@ -270,28 +270,49 @@ else if (e.token === this.ts.SyntaxKind.ImplementsKeyword) {

}
checkInheritance(src) {
checkInheritance(src, extendedSymbol) {
const allImports = [];
this.ts.forEachChild(src, (n) => {
if (this.ts.isImportDeclaration(n)) {
const appsEngine = path.join(this.wd, 'node_modules/@rocket.chat/apps-engine/definition/App');
const mainClassFile = path.join(this.wd, src.fileName);
Promise.all([Promise.resolve().then(() => __importStar(require(appsEngine))), Promise.resolve().then(() => __importStar(require(mainClassFile)))])
.then(([{ App: EngineBaseApp }, mainClassModule]) => {
const appName = src.fileName.replace(/\.ts$/, '');
if (!mainClassModule.default && !mainClassModule[appName]) {
throw new Error(`There must be an exported class "${appName}" in the main class file.`);
const renamings = new Map();
const imports = (n.importClause.namedBindings || n.importClause.name).getText()
.replace(/[{|}]/g, '')
.split(',')
.map((identifier) => {
const [exported, renamed] = identifier.split(' as ');
if (exported && renamed) {
renamings.set(renamed.trim(), exported.trim());
}
const RealApp = mainClassModule.default ? mainClassModule.default : mainClassModule[appName];
const mockInfo = { name: '', requiredApiVersion: '', author: { name: '' } };
const mockLogger = { debug: () => { } };
const realApp = new RealApp(mockInfo, mockLogger);
if (!(realApp instanceof EngineBaseApp)) {
throw new Error('App must extend apps-engine\'s "App" abstract class.'
+ ' Maybe you forgot to install dependencies? Try running `npm install`'
+ ' in your app folder to fix it.');
return identifier.replace(/^.*as/, '').trim();
});
allImports.push(...imports);
if (imports.includes(extendedSymbol)) {
try {
const appsEngineAppPath = path.join(this.wd, 'node_modules/@rocket.chat/apps-engine/definition/App');
const extendedAppShortPath = n.moduleSpecifier.getText().slice(1, -1);
const extendedAppPath = path.isAbsolute(extendedAppShortPath) ? extendedAppShortPath
: extendedAppShortPath.startsWith('.')
? path.join(this.wd, extendedAppShortPath)
: path.join(this.wd, 'node_modules', extendedAppShortPath);
const engine = Promise.resolve().then(() => __importStar(require(appsEngineAppPath)));
const extendedApp = Promise.resolve().then(() => __importStar(require(extendedAppPath)));
const importedSymbol = renamings.has(extendedSymbol) ? renamings.get(extendedSymbol) : extendedSymbol;
extendedApp.then((App) => {
engine.then((engine) => {
const mockInfo = { name: '', requiredApiVersion: '', author: { name: '' } };
const mockLogger = { debug: () => { } };
const extendedApp = new App[importedSymbol](mockInfo, mockLogger);
if (!(extendedApp instanceof engine.App)) {
throw new Error('App must extend apps-engine\'s "App" abstract class.');
}
}).catch(console.error);
});
}
}).catch((err) => {
console.error(err);
process.exit(0);
});
catch (err) {
console.error(err, 'Try to run `npm install` in your app folder to fix it.');
}
}
}
});
if (!allImports.includes(extendedSymbol)) {
throw new Error('App must extend apps-engine\'s "App" abstract class.');
}
}

@@ -298,0 +319,0 @@ isValidFile(file) {

{
"name": "@rocket.chat/apps-compiler",
"version": "0.1.4",
"version": "0.1.5",
"description": "The Rocket.Chat apps compiler",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc