Skip to content

Conversation

@jycouet
Copy link

@jycouet jycouet commented Nov 30, 2023

No description provided.

Copy link

@WesleyKapow WesleyKapow left a comment

Choose a reason for hiding this comment

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

I had to add esbuild manually. This would have saved me that debug step.

@terryaney
Copy link

@WesleyKapow

What do you mean by this?

I had to add esbuild manually. This would have saved me that debug step.

This enables 'debugging' the index.ts files?

@jycouet
Copy link
Author

jycouet commented Jan 3, 2024

If your run the setup and select typescript, you NEED esbuild, if not, the runner will not run.

So today, each people running the setup selecting typescript need to find out that there is a missing dep: esbuild.

This PR fix this. (not related to debugging.)

@terryaney
Copy link

Interesting. I am running Typescript and runner works fine. Here is my package.json:

image

@jycouet
Copy link
Author

jycouet commented Jan 4, 2024

You probably have typescript & esbuild installed globally?

@terryaney
Copy link

Yeah, must have. I have other 'real' typescript projects. And my son started messing with AOC and we needed to do exactly this :) Thanks.

@srflp
Copy link

srflp commented Dec 1, 2024

A better solution is to properly find a path of esbuild and run it from there, since it's already installed in aocrunner. There's no need to install in template too.

buildSource.ts file:

 import { spawnSync } from "child_process"
 import path from "path"
+import { fileURLToPath } from "url"

 const buildSource = (input: string | string[], sourcemap: boolean = true) => {
   const files = Array.isArray(input) ? input : [input]
   const outDir = Array.isArray(input)
     ? "dist"
     : path.parse(input).dir.replace(/^src/, "dist")

   console.log("Transpiling...\n")

+  const esbuild = fileURLToPath(import.meta.resolve("esbuild/bin/esbuild"))

   spawnSync(
     "npx",
     [
-      "esbuild",
+      esbuild,
       ...files,
       "--format=esm",
       `--outdir=${outDir}`,
       "--platform=node",
       "--target=node16",
       ...(sourcemap ? ["--sourcemap"] : []),
     ],
     { stdio: "inherit", shell: true },
   )
 }

export default buildSource

I tested it with node 22 (bumped all deps) and pnpm in both aocrunner and my template and it worked fine.

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.

4 participants