2022-08-03 23:32:54 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
2022-09-09 14:36:35 +00:00
|
|
|
stdenv,
|
|
|
|
deno2nix,
|
|
|
|
lib,
|
2022-08-03 23:32:54 +00:00
|
|
|
...
|
|
|
|
}: {
|
2022-09-09 19:06:41 +00:00
|
|
|
pname,
|
2022-08-03 23:32:54 +00:00
|
|
|
version,
|
|
|
|
src,
|
|
|
|
lockfile,
|
2022-09-09 19:06:41 +00:00
|
|
|
output ? "bundled.js",
|
|
|
|
entrypoint,
|
2022-08-03 23:32:54 +00:00
|
|
|
importMap ? null,
|
2022-09-09 19:06:41 +00:00
|
|
|
additionalDenoFlags ? "",
|
2022-08-03 23:32:54 +00:00
|
|
|
}: let
|
2022-09-09 14:36:35 +00:00
|
|
|
inherit (deno2nix.internal) mkDepsLink;
|
2022-08-03 23:32:54 +00:00
|
|
|
in
|
2022-09-09 14:36:35 +00:00
|
|
|
stdenv.mkDerivation {
|
2022-09-09 19:06:41 +00:00
|
|
|
inherit pname version entrypoint src;
|
|
|
|
buildInputs = with pkgs; [deno jq];
|
2022-08-03 23:32:54 +00:00
|
|
|
|
|
|
|
buildPhase = ''
|
2022-10-14 13:39:17 +00:00
|
|
|
export DENO_DIR="/tmp/deno2nix"
|
|
|
|
mkdir -p $DENO_DIR
|
2022-08-03 23:32:54 +00:00
|
|
|
ln -s "${mkDepsLink lockfile}" $(deno info --json | jq -r .modulesCache)
|
|
|
|
|
2022-09-09 19:06:41 +00:00
|
|
|
deno bundle \
|
|
|
|
--lock="${lockfile}" \
|
|
|
|
${
|
|
|
|
if importMap != null
|
|
|
|
then "--import-map=\"$src/${importMap}\""
|
|
|
|
else ""
|
|
|
|
} \
|
|
|
|
${additionalDenoFlags} \
|
|
|
|
"$src/${entrypoint}" \
|
|
|
|
"${output}"
|
2022-08-03 23:32:54 +00:00
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/dist
|
2022-09-09 19:06:41 +00:00
|
|
|
install -t $out/dist "${output}"
|
2022-08-03 23:32:54 +00:00
|
|
|
'';
|
|
|
|
}
|