Skip to content

Commit 2428412

Browse files
committed
esbuild nonsense
1 parent 1b0d39c commit 2428412

File tree

18 files changed

+3671
-1102
lines changed

18 files changed

+3671
-1102
lines changed

extras/flake-purescript.nix

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
11
pkgs: pursProjOpts:
22
let
3-
mkFlake = projectName: purs: {
4-
packages = {
5-
"purescript:${projectName}:src" = pkgs.stdenv.mkDerivation {
6-
name = projectName;
7-
inherit (pursProjOpts) src;
8-
phases = "installPhase";
9-
installPhase = "ln -s $src $out";
3+
mkFlake = projectName: purs:
4+
{
5+
packages = {
6+
"purescript:${projectName}:src" = pkgs.stdenv.mkDerivation {
7+
name = projectName;
8+
inherit (pursProjOpts) src;
9+
phases = "installPhase";
10+
installPhase = "ln -s $src $out";
11+
};
12+
"purescript:${projectName}:lib" = purs.compiled;
13+
"purescript:${projectName}:node-modules" = purs.nodeModules;
14+
"purescript:${projectName}:webpack-web" = purs.bundlePursProjectWebpack {
15+
main = "Test.Main";
16+
entrypoint = "app/index.js";
17+
bundledModuleName = "dist/output.js";
18+
};
19+
"purescript:${projectName}:esbuild-web" = purs.bundlePursProjectEsbuild {
20+
main = "Test.Main";
21+
browserRuntime = true;
22+
};
23+
"purescript:${projectName}:esbuild-nodejs" = purs.bundlePursProjectEsbuild {
24+
main = "Test.Main";
25+
browserRuntime = false;
26+
};
27+
28+
"purescript:${projectName}:docs" = purs.buildPursDocs { };
29+
"purescript:${projectName}:docs-search" = purs.buildSearchablePursDocs { };
1030
};
11-
"purescript:${projectName}:lib" = purs.compiled;
12-
"purescript:${projectName}:node-modules" = purs.nodeModules;
13-
"purescript:${projectName}:bundle" = purs.bundlePursProject { main = "Test.Main"; entrypoint = "app/index.js"; bundledModuleName = "dist/output.js"; };
14-
"purescript:${projectName}:docs" = purs.buildPursDocs { };
15-
"purescript:${projectName}:docs-search" = purs.buildSearchablePursDocs { };
16-
};
1731

18-
checks = {
19-
"purescript:${projectName}:check" = purs.runPursTest { };
20-
};
32+
checks = {
33+
"purescript:${projectName}:check" = purs.runPursTest { testMain = "Test.Main"; };
34+
};
2135

22-
devShell = purs.devShell;
23-
};
36+
devShell = purs.devShell;
37+
};
2438
in
2539
mkFlake pursProjOpts.projectName (pkgs.purescriptProject pursProjOpts)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as esbuild from "esbuild";
2+
import { wasmLoader } from "esbuild-plugin-wasm";
3+
import { polyfillNode } from "esbuild-plugin-polyfill-node";
4+
5+
if (process.argv.length < 4) {
6+
throw `usage: node bundle.js ENTRY_POINT OUTPUT_FILENAME`;
7+
}
8+
9+
const isBrowser = !!process.env.BROWSER_RUNTIME;
10+
11+
export const buildOptions = ({ entryPoint, outfile }) => {
12+
const config = {
13+
entryPoints: [entryPoint],
14+
outfile: outfile,
15+
define: {
16+
BROWSER_RUNTIME: isBrowser ? "true" : '""',
17+
},
18+
plugins: [
19+
wasmLoader({
20+
mode: "deferred",
21+
}),
22+
],
23+
bundle: true,
24+
platform: isBrowser ? "browser" : "node",
25+
format: "esm",
26+
treeShaking: true,
27+
logLevel: "error",
28+
};
29+
30+
// https://esbuild.github.io/api/#packages
31+
if (!isBrowser) {
32+
config.packages = "external";
33+
} else {
34+
config.plugins.push(
35+
polyfillNode({
36+
polyfills: {
37+
crypto: true,
38+
fs: true,
39+
os: true,
40+
},
41+
})
42+
);
43+
}
44+
45+
return config;
46+
};
47+
48+
esbuild.build(
49+
buildOptions({
50+
entryPoint: process.argv[2],
51+
outfile: process.argv[3],
52+
})
53+
);

runtimes/purescript/lbr-plutus/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "lbr-plutus",
3+
"type": "module",
34
"version": "0.1.0",
45
"description": "LambdaBuffers Plutus runtime",
56
"main": "app/index.js",
@@ -32,7 +33,11 @@
3233
"html-webpack-plugin": "5.5.0",
3334
"webpack": "^5.88.0",
3435
"webpack-cli": "4.10",
35-
"webpack-dev-server": "^4.15.1"
36+
"webpack-dev-server": "^4.15.1",
37+
"esbuild": "0.18.11",
38+
"esbuild-plugin-polyfill-node": "^0.3.0",
39+
"esbuild-plugin-wasm": "^1.1.0",
40+
"node-polyfill-webpack-plugin": "2.0.1"
3641
},
3742
"prettier": {
3843
"arrowParens": "avoid"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as esbuild from "esbuild";
2+
import { wasmLoader } from "esbuild-plugin-wasm";
3+
import { polyfillNode } from "esbuild-plugin-polyfill-node";
4+
5+
if (process.argv.length < 4) {
6+
throw `usage: node bundle.js ENTRY_POINT OUTPUT_FILENAME`;
7+
}
8+
9+
const isBrowser = !!process.env.BROWSER_RUNTIME;
10+
11+
export const buildOptions = ({ entryPoint, outfile }) => {
12+
const config = {
13+
entryPoints: [entryPoint],
14+
outfile: outfile,
15+
define: {
16+
BROWSER_RUNTIME: isBrowser ? "true" : '""',
17+
},
18+
plugins: [
19+
wasmLoader({
20+
mode: "deferred",
21+
}),
22+
],
23+
bundle: true,
24+
platform: isBrowser ? "browser" : "node",
25+
format: "esm",
26+
treeShaking: true,
27+
logLevel: "error",
28+
};
29+
30+
// https://esbuild.github.io/api/#packages
31+
if (!isBrowser) {
32+
config.packages = "external";
33+
} else {
34+
config.plugins.push(
35+
polyfillNode({
36+
polyfills: {
37+
crypto: true,
38+
fs: true,
39+
os: true,
40+
},
41+
})
42+
);
43+
}
44+
45+
return config;
46+
};
47+
48+
esbuild.build(
49+
buildOptions({
50+
entryPoint: process.argv[2],
51+
outfile: process.argv[3],
52+
})
53+
);

0 commit comments

Comments
 (0)