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

feat: initial support for Deno #135

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

kurtaking
Copy link

@kurtaking kurtaking commented Aug 27, 2023

Summary

Migrate from Node to Deno.

Details

This PR migrates the CLI to leverage Deno. I could run things locally to update master -> main for a few of my older repositories. The discussion here inspired this PR and works to resolve #5.

Testing

  • Verified it's working locally with both .js and .ts files.
  • Ran scripts/script.js and scripts/script.ts against several of my older repos to update branch protection rules.
deno run -A cli.js -T $GITHUB_TOKEN -R '[repo-name]'

Remaining Tasks

  • remove pr sample files (cli.js, script.ts)
  • migrate package.json scripts (and more?) to deno.json
  • find replacements for process.arch and process.platform

chore: add env and vscode

Signed-off-by: Kurt King <kurtaking@gmail.com>

feat: add initial deno support

Signed-off-by: Kurt King <kurtaking@gmail.com>

chore: put typescript version

Signed-off-by: Kurt King <kurtaking@gmail.com>

chore: remove console.log

Signed-off-by: Kurt King <kurtaking@gmail.com>

chore: update cli.js to use ts file

Signed-off-by: Kurt King <kurtaking@gmail.com>

chore: remove -S arg from dev cmd

Signed-off-by: Kurt King <kurtaking@gmail.com>
Signed-off-by: Kurt King <kurtaking@gmail.com>
@kurtaking kurtaking marked this pull request as ready for review August 27, 2023 21:57
@gr2m
Copy link
Member

gr2m commented Aug 28, 2023

We sholudn't replace the Node CLI with Deno. The Deno CLI should be an addition and probably become the recommended way to run Octoherd scripts. But the Node version is used as dependencies in scripts today in order to run the script packages directly using npx: https://github.com/octoherd/script-hello-world/blob/dd5c0cfd6ebf93ff3348f48fc1f53329c646a1f5/package.json#L21

@kurtaking
Copy link
Author

kurtaking commented Aug 28, 2023

Hey @gr2m, I am cross-referencing your response here to consolidate the discussion.

I like the idea of having a separate repository and will continue to work on this if you like the direction. What's the next step in getting the repository set up?

edit: I'll set up the repository and we can talk about transferring at a later date.

@gr2m
Copy link
Member

gr2m commented Aug 28, 2023

I'll set up the repository and we can talk about transferring at a later date

yeah that's what I'd suggest as well, thank you!

@kurtaking
Copy link
Author

I can run things locally, so making some progress. I am definitely not as comfortable with Deno as anticipated 😬 😅

image

I could use some help if anyone is interested.
Module: https://deno.land/x/octoherdcli@v0.2.0-alpha
Repo: https://github.com/kurtaking/octoherd-cli-deno

@gr2m
Copy link
Member

gr2m commented Sep 4, 2023

thanks for the update! It's always hard in the beginning when figuring things out. Thank you for staying on it

@kurtaking
Copy link
Author

@gr2m, the issue faced now is around dynamic imports. The output of deno compile does not support dynamically importing files that were not present at compilation time [ref].

The output of deno install does not support dynamic imports.

@gr2m
Copy link
Member

gr2m commented Sep 6, 2023

around dynamic imports

Try this:

const { script } = await import("https://esm.sh/@octoherd/script-hello-world")
// now call `script(octokit, repository, options)` for every repository

Replace @octoherd/script-hello-world with the script name. The Deno CLI binary could work the same as the current Node-based CLI in terms for CLI arguments, for example:

$ deno-octoherd run -S https://esm.sh/@octoherd/script-hello-world@3.0.0

@kurtaking
Copy link
Author

@gr2m, I have things working now for scripts coming from a URL. I have not figured out how to handle the failures for local files yet. I'm at a stopping point for today, but this feels good.

Success

➜  octoherd-cli-deno git:(main) ✗ deno compile -A https://deno.land/x/octoherdcli@v0.2.18-alpha/octoherd.ts 
Check https://deno.land/x/octoherdcli@v0.2.18-alpha/octoherd.ts
Compile https://deno.land/x/octoherdcli@v0.2.18-alpha/octoherd.ts to octoherd
➜  octoherd-cli-deno git:(main) ✗ ./octoherd run -S https://esm.sh/@octoherd/script-hello-world@3.0.0 -T $GITHUB_TOKEN -R 'kurtaking/octoherd-cli'

Running @octoherd/cli v0.0.0-development (@octoherd/octokit v1.36.4, Deno: %s)

 INFO  Loading repositories ...
. INFO  Running on kurtaking/octoherd-cli ... {"octoherd":true}
 INFO  Hello, World! From kurtaking/octoherd-cli
 
Log file written to /var/folders/z9/6dw2r0590j976pxzfnpt02d00000gn/T/8b25ff11ndjson.log

--------------------------------------------------------------------------------

➜  octoherd-cli-deno git:(main) ✗ deno run -A https://deno.land/x/octoherdcli@v0.2.18-alpha/octoherd.ts run -S https://esm.sh/@octoherd/script-hello-world@3.0.0 -T $GITHUB_TOKEN -R 'kurtaking/octoherd-cli'

Running @octoherd/cli v0.0.0-development (@octoherd/octokit v1.36.4, Deno: %s)

 INFO  Loading repositories ...
. INFO  Running on kurtaking/octoherd-cli ... {"octoherd":true}
 INFO  Hello, World! From kurtaking/octoherd-cli

Log file written to /var/folders/z9/6dw2r0590j976pxzfnpt02d00000gn/T/53d46ba8ndjson.log

--------------------------------------------------------------------------------

Failures

➜  octoherd-cli-deno git:(main) ✗ deno run -A https://deno.land/x/octoherdcli@v0.2.18-alpha/octoherd.ts run -S examples/script.ts -T $GITHUB_TOKEN -R 'kurtaking/octoherd-cli' 
error: Uncaught (in promise) Error: [octoherd] /Users/kurtking/Development/Personal/octoherd-cli-deno/examples/script.ts does not exist
            throw new Error(`[octoherd] ${path} does not exist`);
                  ^
    at https://deno.land/x/octoherdcli@v0.2.18-alpha/bin/commands/run.js:99:19
    at async https://deno.land/x/octoherdcli@v0.2.18-alpha/octoherd.ts:5:14
➜  octoherd-cli-deno git:(main) ✗

--------------------------------------------------------------------------------

➜  octoherd-cli-deno git:(main) ✗ ./octoherd run -S examples/script.ts -T $GITHUB_TOKEN -R 'kurtaking/octoherd-cli'                                                           
✘ [ERROR] Unhandled media type Unknown. [plugin deno-loader]

error: Uncaught (in promise) Error: [octoherd] Error: Build failed with 1 error:
error: Unhandled media type Unknown.
    at /Users/kurtking/Development/Personal/octoherd-cli-deno/examples/script.ts
          const err = new Error(`[octoherd] ${error}\n    at ${path}`);
                      ^
    at https://deno.land/x/octoherdcli@v0.2.18-alpha/bin/commands/run.js:102:23
    at eventLoopTick (ext:core/01_core.js:183:11)
    at async https://deno.land/x/octoherdcli@v0.2.18-alpha/octoherd.ts:4:14
➜  octoherd-cli-deno git:(main) ✗

@gr2m
Copy link
Member

gr2m commented Sep 7, 2023

when importing locally, make sure to either use a relative path starting with ./, like ./examples/script.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Deno
2 participants