deno2.nix/nix/make-bundled.nix

45 lines
887 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",
outPath ? "dist",
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="/tmp/deno2nix"
mkdir -p $DENO_DIR
2022-08-03 23:32:54 +00:00
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/${outPath}
install -t $out/${outPath} "${output}"
2022-08-03 23:32:54 +00:00
'';
}