2022-08-03 23:32:54 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
2022-12-14 04:00:56 +00:00
|
|
|
lib,
|
2022-09-09 14:36:35 +00:00
|
|
|
stdenv,
|
|
|
|
deno2nix,
|
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,
|
2022-12-14 04:00:56 +00:00
|
|
|
output ? "${pname}.bundled.js",
|
2022-12-09 05:06:15 +00:00
|
|
|
outPath ? "dist",
|
2022-09-09 19:06:41 +00:00
|
|
|
entrypoint,
|
2022-12-14 04:00:56 +00:00
|
|
|
lockfile,
|
|
|
|
minify ? false,
|
2022-09-09 19:06:41 +00:00
|
|
|
additionalDenoFlags ? "",
|
2022-08-03 23:32:54 +00:00
|
|
|
}: let
|
2022-12-14 04:00:56 +00:00
|
|
|
inherit (builtins) isString;
|
|
|
|
inherit (lib.strings) concatStringsSep;
|
2022-09-09 14:36:35 +00:00
|
|
|
inherit (deno2nix.internal) mkDepsLink;
|
2022-12-14 04:00:56 +00:00
|
|
|
|
|
|
|
bundleCmd = concatStringsSep " " (
|
|
|
|
[
|
|
|
|
"deno bundle"
|
|
|
|
"--lock=${lockfile}"
|
|
|
|
# "--config=${config}"
|
|
|
|
]
|
|
|
|
++ [additionalDenoFlags]
|
|
|
|
++ [
|
|
|
|
"${entrypoint}"
|
|
|
|
"${output}"
|
|
|
|
]
|
|
|
|
);
|
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;
|
2022-12-09 07:51:41 +00:00
|
|
|
buildInputs = with pkgs; [deno jq nodePackages.uglify-js];
|
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-12-14 04:00:56 +00:00
|
|
|
ln -s "${mkDepsLink (src + "/${lockfile}")}" $(deno info --json | jq -r .modulesCache)
|
|
|
|
${bundleCmd}
|
2022-12-09 05:12:21 +00:00
|
|
|
${
|
|
|
|
if minify
|
|
|
|
then ''
|
|
|
|
mv ${output} ${output}-non-min
|
|
|
|
uglifyjs ${output}-non-min -c -m > ${output}
|
|
|
|
''
|
|
|
|
else ""
|
|
|
|
}
|
2022-08-03 23:32:54 +00:00
|
|
|
'';
|
|
|
|
installPhase = ''
|
2022-12-09 05:06:15 +00:00
|
|
|
mkdir -p $out/${outPath}
|
|
|
|
install -t $out/${outPath} "${output}"
|
2022-08-03 23:32:54 +00:00
|
|
|
'';
|
|
|
|
}
|