deno2.nix/nix/mk-bundled.nix
SnO₂WMaN 21efd7ac82
feat: Update for deno2nix v2 (#21)
* move simple script to `examples/simple`

* rm vscode settings.json

* example npm

* wip

* refactoring

* Update mkExecutable

* rm custom formatter  from vscode extensions

* Add .gitignore

* Update flake.nix

* bundled/executable wip

* Update flake

* importMap

* bundled wrapper

* somerefactoring

* no more overlay(default)

* add todo

* Update README.md
2022-12-14 13:00:56 +09:00

58 lines
1.1 KiB
Nix

{
pkgs,
lib,
stdenv,
deno2nix,
...
}: {
pname,
version,
src,
output ? "${pname}.bundled.js",
outPath ? "dist",
entrypoint,
lockfile,
minify ? false,
additionalDenoFlags ? "",
}: let
inherit (builtins) isString;
inherit (lib.strings) concatStringsSep;
inherit (deno2nix.internal) mkDepsLink;
bundleCmd = concatStringsSep " " (
[
"deno bundle"
"--lock=${lockfile}"
# "--config=${config}"
]
++ [additionalDenoFlags]
++ [
"${entrypoint}"
"${output}"
]
);
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 (src + "/${lockfile}")}" $(deno info --json | jq -r .modulesCache)
${bundleCmd}
${
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}"
'';
}