lumeland / lume

🔥 Static site generator for Deno 🦕
https://lume.land
MIT License
1.75k stars 74 forks source link

esbuild plugin: timeout after 10 second on `deno task build` #591

Closed scarf005 closed 2 months ago

scarf005 commented 3 months ago

Version

2.1.3

Platform

ubuntu

What steps will reproduce the bug?

  1. Create project with following files: deno.json, _config.ts, main.tsx

deno.json

{
    "imports": {
        "lume/": "https://deno.land/x/lume@v2.1.3/"
    },
    "tasks": {
        "lume": "echo \"import 'lume/cli.ts'\" | deno run -A -",
        "build": "deno task lume",
        "serve": "deno task lume -s"
    },
    "compilerOptions": {
        "exactOptionalPropertyTypes": true,
        "types": [
            "lume/types.ts"
        ],
        "jsx": "precompile",
        "jsxImportSource": "https://esm.sh/preact@10.19.3"
    }
}

_config.ts

import lume from "lume/mod.ts"
import esbuild from "lume/plugins/esbuild.ts"

const site = lume()

site.use(esbuild({
    extensions: [".tsx"],
    options: { minify: false, bundle: false, splitting: true },
}))

export default site

main.tsx

import { render } from "https://esm.sh/preact@10.19.3"

const App = () => <h1>Example Page</h1>

render(<App />, document.getElementById("root")!)
  1. run deno task build.

How often does it reproduce? Is there a required condition?

it always happens.

What is the expected behavior?

after building the project must stop immediately.

What do you see instead?

$ deno task build
Task build deno task lume
Task lume echo "import 'lume/cli.ts'" | deno run -A -
Loading config file file:///home/scarf/repo/etc/esbuild-issue/_config.ts
🔥 /main.js <- /main.tsx
🍾 Site built into ./_site
  1 files generated in 0.01 seconds
WARN After waiting 10 seconds, there are some timers that avoid ending the process.
WARN They have been forcibly closed.

The plugin hangs and gets killed after 10 seconds.

Additional information

it might be that esbuild.stop() isn't called?

oscarotero commented 3 months ago

@scarf005 It was removed here https://github.com/lumeland/lume/commit/bff5800be2414b80f6288e27bc8d8e0be832117a#diff-019b7b01afa861216d127d59201e36bc7b5ccbb44be90f521af6f044808b09a1

I don't remember exactly the reason, but I got some errors importing stop so I though it wasn't needed anymore (stop only is required in Deno, in Node it works automatically).

scarf005 commented 3 months ago

As a workaround, adding this to _config.ts works:

import { stop } from "lume/deps/esbuild.ts"

const isWatch = Deno.args.some((arg) => ["-s", "--serve", "-w", "--watch"].includes(arg))
if (!isWatch) addEventListener("lume:afterBuild", stop)
oscarotero commented 3 months ago

great. Could you try if this happens with splitting: false? The plugins works differently depending on this option in the esbuild settings.

scarf005 commented 3 months ago

changing the value of splitting doesn't change the result, probably due to both code path not running esbuild.stop() as mentioned in https://esbuild.github.io/getting-started/#deno

oscarotero commented 3 months ago

@scarf005 I just restored the stop() call. Can you confirm it works fine now? You can use the latest development version with deno task lume upgrade --dev.

oscarotero commented 2 months ago

fixed in v2.1.4