Skip to content

Commit

Permalink
[deno-app-build] Ensure wasm dependency is cached offline
Browse files Browse the repository at this point in the history
  • Loading branch information
nktpro committed May 20, 2024
1 parent 0eac6a3 commit 2b76405
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/deno-app-compile.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ in
stdenv.mkDerivation {
inherit src name;
nativeBuildInputs = [ makeWrapper deno ];
__noChroot = true;
__noChroot = deno-cache == null;
phases = [ "unpackPhase" "installPhase" ];
installPhase =
''
Expand Down
2 changes: 1 addition & 1 deletion pkgs/deno-app-build/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { transpile, type TranspileOptions } from "jsr:@deno/emit@0.40.2";
import { transpile, type TranspileOptions } from "./emit.ts";
import {
dirname,
fromFileUrl,
Expand Down
15 changes: 10 additions & 5 deletions pkgs/deno-app-build/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
, denort
, writeShellScriptBin
, runCommand
, makeWrapper
}:
let
deno-app-build-src = ./build.ts;
deno-app-build-src = ./.;
deno-app-build = runCommand "deno-app-build"
{
__noChroot = true;
nativeBuildInputs = [ deno ];
nativeBuildInputs = [ deno makeWrapper ];
}
''
mkdir -p $out/bin
mkdir -p $out/bin $out/cache
export DENO_DIR=$(mktemp -d)
export TEST_PATH=$(mktemp -d)
export DENORT_BIN="${denort}/bin/denort"
deno compile -A --check --output=$out/bin/deno-app-build ${deno-app-build-src}
deno compile -A --check --output=$out/bin/deno-app-build ${deno-app-build-src}/build.ts
wrapProgram "$out/bin/deno-app-build" --set DENO_EMIT_WASM_CACHE_HOME "$out/cache"
echo "console.log('test');" > "$TEST_PATH/test.ts"
$out/bin/deno-app-build --app-path="$TEST_PATH/test.ts" --out-path="$TEST_PATH/out"
'';
in
in
deno-app-build
20 changes: 20 additions & 0 deletions pkgs/deno-app-build/emit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
transpile as originalTranspile,
type TranspileOptions,
} from "jsr:@deno/[email protected]";
export { type TranspileOptions };

export async function transpile(
root: string | URL,
options: TranspileOptions = {},
) {
const DENO_EMIT_WASM_CACHE_HOME = Deno.env.get("DENO_EMIT_WASM_CACHE_HOME");

if (!DENO_EMIT_WASM_CACHE_HOME) {
throw new Error("DENO_EMIT_WASM_CACHE_HOME env var is not set");
}

Deno.env.set("HOME", DENO_EMIT_WASM_CACHE_HOME);
Deno.env.set("XDG_DATA_HOME", DENO_EMIT_WASM_CACHE_HOME);
return await originalTranspile(root, options);
}

0 comments on commit 2b76405

Please sign in to comment.