@rocket.chat/apps-compiler
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -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", |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
45558
1039
0