nwolverson / purescript-language-server

MIT License
185 stars 42 forks source link

Migrate bundling to esbuild #163

Closed wclr closed 2 years ago

wclr commented 3 years ago

Adds esbuild bundling to bundle.js, server.js now in the repo.

VScode tasks.json includes two watch tasks (tsc and bundle), that can be run in dev mode. Error matcher $esbuild-watch is available through vscode extension.

Main.js was modified to prevent require resolution by esbuild and proper possible exception handling.

Made minified esbuild bundle with external source maps in build mode.

nwolverson commented 2 years ago

Not sure that it's right that this now bakes in dependencies into the js file published on npm (I believe) but those are still listed as dependencies.

I also suppose they are small and duplication doesn't matter

wclr commented 2 years ago

Didn't think about it. Bundlers are so bundlers. There is an option --external for modules not to include, but an additional build script will be needed probably. Something like that, or to use api:

const { execSync } = require("child_process");

const externals = Object.keys(require("./package.json").dependencies);

execSync(
  [
    "npx esbuild",
    "--bundle",
    "--platform=node",
    "--outfile=bundle.js",
    ...externals.map((m) => "--external:" + m),    
    "./output/LanguageServer.IdePurescript.Main",
    ...process.argv.slice(2)
  ].join(" "),
  { stdio: "inherit" }
);

Otherwise, dependencies could be moved to devDependencies. Also bundled things should be faster to start, maybe.