Skip to content

add missing dep esbuild on init#30

Open
jycouet wants to merge 1 commit into
caderek:mainfrom
jycouet:fix/esbuild-dep
Open

add missing dep esbuild on init#30
jycouet wants to merge 1 commit into
caderek:mainfrom
jycouet:fix/esbuild-dep

Conversation

@jycouet

@jycouet jycouet commented Nov 30, 2023

Copy link
Copy Markdown

No description provided.

@WesleyKapow WesleyKapow left a comment

Copy link
Copy Markdown

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
Copy Markdown

@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

jycouet commented Jan 3, 2024

Copy link
Copy Markdown
Author

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
Copy Markdown

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

image

@jycouet

jycouet commented Jan 4, 2024

Copy link
Copy Markdown
Author

You probably have typescript & esbuild installed globally?

@terryaney

Copy link
Copy Markdown

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

srflp commented Dec 1, 2024

Copy link
Copy Markdown

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