Dependency Problem
https://github.com/SnO2WMaN/deno2nix/issues/4#issuecomment-1241689268
For this issue I think it should not be handled by this module, because I don't think you can have knowledge of whether you should append index.js or index.ts` to it. Seems like there could be some workarounds, but I cannot find an optimal one yet.
@SnO2WMaN update, somehow esm.sh just work but not skypack, with this in the import_map.json, I can bypass that error:
{
"imports": {
"https://cdn.skypack.dev/[email protected]": "https://esm.sh/[email protected]?target=deno"
}
}
As an update nope it doesn't work. I have create a repo so that we can reproduce the issue:
https://github.com/winston0410/repro-incorrect-deps
I am able to fix that issue in this commit
https://github.com/winston0410/repro-incorrect-deps/commit/2adafcc342b58a43dbc4425c7551a4a1cdfd8289
@SnO2WMaN I have spotted a new error, reproducible by this commit
https://github.com/winston0410/repro-incorrect-deps/commit/7b8aea15375eb7271e81e993ca4e8bcdc7ff13ce
Seems like deno2nix doesn't handle relative path correctly. I am able to fix it in my own project by using an identifer in import_map.json, and import the file with it:
https://github.com/winston0410/repro-incorrect-deps/commit/a9115cc4623a1c4416d6861073a229487f09c00f
Hopefully it will help you improve this module! Good work!
@winston0410
Sorry, when I created this module, I had done the argument names and handling properly, and I am refactoring it (and losing compatibility) #8 .
Updated flake.nix is here, sorry for inconvenience.
{
description = "closesource repo flake";
# main
inputs = {
nixpkgs = {url = "github:nixos/nixpkgs/release-22.05";};
deno2nix = {url = "github:SnO2WMaN/deno2nix/string-path";};
};
# dev
inputs = {
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
flake-utils,
deno2nix,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
deno2nix.overlay
];
};
deno-api-dynamic-form = pkgs.deno2nix.mkExecutable {
pname = "deno-api-dynamic-form";
version = "0.0.0";
src = ./.;
lockfile = ./lock.json;
output = "deno-api-dynamic-form";
entrypoint = "./src/index.ts";
importMap = "./import_map.json";
additionalDenoFlags = "--allow-net --allow-env --allow-read";
};
in {
# nix build .#<appName>
packages = {
inherit deno-api-dynamic-form;
};
apps.default = flake-utils.lib.mkApp {drv = self.packages.${system}.deno-api-dynamic-form;};
});
}
That's fine. I have updated it accordingly.
I have real trouble getting this package to work as well.
nix build .#sapi
warning: Git tree '/home/jceb/Documents/Projects/sapi' is dirty
error: builder for '/nix/store/25fkp68rfm3rxp3rmg64zh1j52nf97zf-sapi-0.0.6.drv' failed with exit code 1;
last 10 log lines:
> source root is 8cszb8hw4s2gdhrdavlyzayblm67m7fr-source
> patching sources
> updateAutotoolsGnuConfigScriptsPhase
> configuring
> no configure script, doing nothing
> building
> Warning the configuration file "file:///build/8cszb8hw4s2gdhrdavlyzayblm67m7fr-source/deno.json" contains an entry for "importMap" that is being ignored.
> error: Expected a JavaScript or TypeScript module, but identified a Unknown module. Importing these types of modules is currently not supported.
> Specifier: https://esm.sh/v133/*[email protected]?target=deno
> at file:///build/8cszb8hw4s2gdhrdavlyzayblm67m7fr-source/lib.js:1:23
For full logs, run 'nix log /nix/store/25fkp68rfm3rxp3rmg64zh1j52nf97zf-sapi-0.0.6.drv'.
error: Recipe `build` failed on line 18 with exit code 1
From here I found a path forward by inspecting the downloaded dependencies and found that the metadata is empty, i.e. not set in the fetchUrl call. This is the reason for the above error. I added "content-type" = "application/javascript; charset=utf-8"; to the headers which worked to the extend that it went past the previous error and crashed at the first typescript file. From my current understanding the correct metadata needs to be determined and added to the cache to make it usable.
Could we use deno for fulling in the dependencies? Creating a fixed output derivation is probably the way to go as described here: https://ianthehenry.com/posts/how-to-learn-nix/derivations/
Since Deno doesn't support fetching from the lockfile, instead the code is required, it's a bit tedious to pass the data around. Here's a little workaround, however I can imagine that there are a bunch of annoying edge case waiting with different lockfile versions, etc.: https://github.com/denoland/deno/issues/9950#issuecomment-1157132107
This is an updated version:
import lock from "./lock.json" assert { type: "json" };
const command = new Deno.Command(Deno.execPath(), {
args: [
"cache",
// Assume we're run from the top-level directory.
"--lock=./lock.json",
"--",
...Object.keys(lock.remote),
],
});
const child = command.spawn();
const status = await child.status;
if (!status.success) {
console.log(`error: exit code ${status.code}`);
Deno.exit(status.code);
}