Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Require logic is faulty for compiled apps #40

Merged
merged 2 commits into from
Oct 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/compiler/AppsEngineValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ export class AppsEngineValidator {

const result = vm.runInContext(compilationResult.files[`${ filename }.js` as keyof ICompilerResult['files']].compiled, context);

return result || exports;
/**
* `result` will contain ONLY the result of the last line evaluated
* in the script by `vm.runInContext`, and NOT the full `exports` object.
*
* However, we need to handle this case due to backwards compatibility,
* since the main class file might export a class with an unknown name,
* which was supported in the early versions of the Apps-Engine.
*
* So here, if we find that the required file exports ONLY ONE property,
* which is what happens in the case of the main class file, we can return
* the `result`; otherwise, we return the full `exports` object.
*/
if (Object.keys(exports).length === 1) {
return result;
}
return exports;
}
}