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

Allow typescript file to be used by sdk:execute #198

Merged
merged 5 commits into from
Dec 13, 2023

Conversation

rolljee
Copy link
Contributor

@rolljee rolljee commented Nov 23, 2023

What does this PR do?

This PR adds the possibility to use typescript file with the method sdk:execute

How should this be manually tested?

  • Step 1 : npm run build
  • Step 2 : ./bin/run sdk:execute < some-typescript-file.ts
  • Step 3 : The code from your ts file is executed
    ...

Other changes

Boyscout

@rolljee rolljee self-assigned this Nov 23, 2023
@rolljee rolljee linked an issue Nov 23, 2023 that may be closed by this pull request
src/commands/sdk/execute.ts Outdated Show resolved Hide resolved
@@ -69,33 +71,70 @@ Other

static readStdin = true;

async toJavascript(filename: string): Promise<boolean> {
return new Promise((resolve, reject) => {
exec(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to use the programmatic api in order to avoid relying on exec and to save up on temp file reading / writing.
https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#a-simple-transform-function

async beforeConnect() {
this.code = this.stdin || this.args.code || "// paste your code here";
try {
eval(this.code);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, it would be preferable to attempt evaluating in a separate V8 context
https://nodejs.org/api/vm.html#vmruninnewcontextcode-contextobject-options

@rolljee rolljee changed the base branch from master to 1-dev December 13, 2023 11:17
@rolljee rolljee merged commit ef57464 into 1-dev Dec 13, 2023
4 checks passed
@rolljee rolljee deleted the feat/add-typescript-support-sdk-execute branch December 13, 2023 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[sdk:execute] support for Typescript files
2 participants