Skip to content

Commit

Permalink
In deno-app-compile/build: support additionalSrcPaths
Browse files Browse the repository at this point in the history
  • Loading branch information
nktpro committed Apr 15, 2024
1 parent f412391 commit ba47a2c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
10 changes: 9 additions & 1 deletion lib/deno-app-build.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ name
{ lib
, name
, src
, appSrcPath
, additionalSrcPaths ? { }
, denoRunFlags ? "--no-config --no-lock --no-prompt --no-remote --cached-only -A"
, stdenv
, deno
Expand All @@ -11,6 +13,11 @@
, writeShellScriptBin
}:
let
additionalSrcCommands = lib.mapAttrsToList
(name: value: ''
RESULT_${builtins.replaceStrings ["-"] ["_"] (lib.strings.toUpper name)}=$(${deno-app-build}/bin/deno-app-build --app-path="${value}" --out-path="$TEMP_OUT") || exit $?
'')
additionalSrcPaths;
app-build = stdenv.mkDerivation
{
inherit src;
Expand All @@ -35,6 +42,7 @@ let
mkdir $out
${preBuild}
RESULT=$(${deno-app-build}/bin/deno-app-build --app-path="${appSrcPath}" --out-path=$out) || exit $?
${lib.strings.concatStringsSep "\n" additionalSrcCommands}
${postBuild}
echo "$RESULT" > $entry
'';
Expand Down
59 changes: 36 additions & 23 deletions lib/deno-app-compile.nix
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
{ name
{ lib
, name
, src
, appSrcPath
, additionalSrcPaths ? { }
, denoCompileFlags ? "--no-config --no-lock --no-prompt --no-remote --cached-only -A"
, stdenv
, makeWrapper
, deno
, denort
, deno-app-build
, deno-cache ? null
, preBuild ? ""
, postBuild ? ""
}:
let
additionalSrcCommands = lib.mapAttrsToList
(name: value: ''
RESULT_${builtins.replaceStrings ["-"] ["_"] (lib.strings.toUpper name)}=$(${deno-app-build}/bin/deno-app-build --allow-npm-specifier --app-path="${value}" --out-path="$TEMP_OUT") || exit $?
'')
additionalSrcPaths;
in
stdenv.mkDerivation {
inherit src name;
nativeBuildInputs = [ deno ];
nativeBuildInputs = [ makeWrapper deno ];
__noChroot = true;
phases = [ "unpackPhase" "installPhase" ];
installPhase =
''
export DENO_DIR=$(mktemp -d)
${
if deno-cache != null
then
''
ln -s ${deno-cache}/deps "$DENO_DIR/deps"
ln -s ${deno-cache}/npm "$DENO_DIR/npm"
ln -s ${deno-cache}/registries "$DENO_DIR/registries"
''
else ""
}
TEMP_OUT=$(mktemp -d)
mkdir -p $out/bin
${preBuild}
RESULT=$(${deno-app-build}/bin/deno-app-build --allow-npm-specifier --app-path="${appSrcPath}" --out-path="$TEMP_OUT") || exit $?
${postBuild}
export DENORT_BIN="${denort}/bin/denort"
deno compile ${denoCompileFlags} -o "$out/bin/${name}" "$RESULT"
'';
installPhase =
''
export DENO_DIR=$(mktemp -d)
${
if deno-cache != null
then
''
ln -s ${deno-cache}/deps "$DENO_DIR/deps"
ln -s ${deno-cache}/npm "$DENO_DIR/npm"
ln -s ${deno-cache}/registries "$DENO_DIR/registries"
''
else ""
}
TEMP_OUT=$(mktemp -d)
mkdir -p $out/bin
${preBuild}
RESULT=$(${deno-app-build}/bin/deno-app-build --allow-npm-specifier --app-path="${appSrcPath}" --out-path="$TEMP_OUT") || exit $?
${lib.strings.concatStringsSep "\n" additionalSrcCommands}
${postBuild}
export DENORT_BIN="${denort}/bin/denort"
deno compile ${denoCompileFlags} -o "$out/bin/${name}" "$RESULT"
'';
}


0 comments on commit ba47a2c

Please sign in to comment.