deno2.nix/nix/make-bundled.nix
SnO₂WMaN 9f8afeffb2
ci: Not triggered on pull request (#20)
* ci: not triggered on pull request

* fmt

* nomore flake-compat

* Revert "nomore flake-compat"

This reverts commit f3c85c80d2e2b9d56bd675661c9e35a0b99c656c.
2022-12-09 16:51:41 +09:00

55 lines
1.1 KiB
Nix

{
pkgs,
stdenv,
deno2nix,
lib,
...
}: {
pname,
version,
src,
lockfile,
output ? "bundled.js",
outPath ? "dist",
minify ? false,
entrypoint,
importMap ? null,
additionalDenoFlags ? "",
}: let
inherit (deno2nix.internal) mkDepsLink;
in
stdenv.mkDerivation {
inherit pname version entrypoint src;
buildInputs = with pkgs; [deno jq nodePackages.uglify-js];
buildPhase = ''
export DENO_DIR="/tmp/deno2nix"
mkdir -p $DENO_DIR
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}"
${
if minify
then ''
mv ${output} ${output}-non-min
uglifyjs ${output}-non-min -c -m > ${output}
''
else ""
}
'';
installPhase = ''
mkdir -p $out/${outPath}
install -t $out/${outPath} "${output}"
'';
}