deno2.nix/nix/make-bundled.nix

43 lines
826 B
Nix
Raw Normal View History

2022-08-03 23:32:54 +00:00
{
pkgs,
stdenv,
deno2nix,
lib,
2022-08-03 23:32:54 +00:00
...
}: {
pname,
2022-08-03 23:32:54 +00:00
version,
src,
lockfile,
output ? "bundled.js",
entrypoint,
2022-08-03 23:32:54 +00:00
importMap ? null,
additionalDenoFlags ? "",
2022-08-03 23:32:54 +00:00
}: let
inherit (deno2nix.internal) mkDepsLink;
2022-08-03 23:32:54 +00:00
in
stdenv.mkDerivation {
inherit pname version entrypoint src;
buildInputs = with pkgs; [deno jq];
2022-08-03 23:32:54 +00:00
buildPhase = ''
export DENO_DIR=`mktemp -d`
ln -s "${mkDepsLink lockfile}" $(deno info --json | jq -r .modulesCache)
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
install -t $out/dist "${output}"
2022-08-03 23:32:54 +00:00
'';
}