Compare commits

..

No commits in common. "0b54d6ce4424039951c1c12cc4319836b76c1eaf" and "b42f691c27304f5e2e3d2e5b33aaf0373954589d" have entirely different histories.

36 changed files with 298 additions and 440 deletions

View file

@ -2,9 +2,6 @@ name: CI
on:
push:
branches:
- main
pull_request:
jobs:
flake-check:
@ -13,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18
- uses: cachix/cachix-action@v12
- uses: cachix/cachix-action@v11
with:
name: sno2wman
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
@ -25,7 +22,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18
- uses: cachix/cachix-action@v12
- uses: cachix/cachix-action@v11
with:
name: sno2wman
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"

3
.gitignore vendored
View file

@ -2,6 +2,3 @@
result
dist
# VSCode
**/.vscode/settings.json

View file

@ -3,6 +3,7 @@
"jnoortheen.nix-ide",
"arrterian.nix-env-selector",
"tamasfe.even-better-toml",
"jkillian.custom-local-formatters",
"denoland.vscode-deno"
]
}

59
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,59 @@
{
"nixEnvSelector.nixFile": "${workspaceRoot}/shell.nix",
"deno.enable": true,
"deno.lint": true,
"deno.importMap": "./import_map.json",
"deno.config": "./deno.jsonc",
"json.schemas": [
{
"fileMatch": ["deno.jsonc"],
"url": "https://deno.land/x/deno/cli/schemas/config-file.v1.json"
}
],
"customLocalFormatters.formatters": [
{
"command": "treefmt -q --stdin ${file}",
"languages": [
"json",
"jsonc",
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"markdown",
"nix",
"toml"
]
}
],
"[toml]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[nix]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[markdown]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[json]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[jsonc]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[javascript]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[javascriptreact]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[typescript]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[typescriptreact]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
}
}

21
LICENSE
View file

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2022 SnO₂WMaN
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -4,7 +4,17 @@
## Usage
There is a [sample project](/examples/simple).
- lockfile -> `./lock.json`
- import map -> `./import_map.json`
- entrypoint -> `./mod.ts`
### Update `lock.json` for caching
```bash
deno cache --import-map=./import_map.json --lock lock.json --lock-write ./mod.ts
```
### Setup for nix flake (example)
```nix
{
@ -23,28 +33,42 @@ There is a [sample project](/examples/simple).
inherit system;
overlays = with inputs; [
devshell.overlay
deno2nix.overlays.default
deno2nix.overlay
];
};
in {
packages.executable = deno2nix.mkExecutable {
pname = "simple-executable";
version = "0.1.0";
pname = "example-executable";
version = "0.1.2";
src = ./.;
bin = "simple";
lockfile = ./lock.json;
output = "example";
entrypoint = "./mod.ts";
lockfile = "./deno.lock";
config = "./deno.jsonc";
allow = {
all = true;
importMap = "./import_map.json";
};
});
}
```
### `deno2nix.mkExecutable`
#### Args
```nix
{
pname,
version,
src,
lockfile,
output ? pname, # generate binary name
entrypoint,
importMap ? null, # ex. "./import_map.json" to $src/${importMap}
additionalDenoFlags ? "", # ex. "--allow-net"
}
```
## Thanks
- [esselius/nix-deno](https://github.com/esselius/nix-deno)

View file

@ -1,8 +1,8 @@
{
"importMap": "./import_map.json",
"tasks": {
"run": "deno run ./mod.ts",
"compile": "deno compile ./mod.ts"
"run": "deno run --import-map=./import_map.json ./mod.ts",
"compile": "deno compile --import-map=./import_map.json ./mod.ts",
"cache": "deno cache --import-map=./import_map.json --lock lock.json --lock-write ./mod.ts"
},
"fmt": {
"options": {

View file

@ -1,20 +0,0 @@
{
"importMap": "./import_map.json",
"tasks": {
"run": "deno run -A ./mod.ts",
"compile": "deno compile -A ./mod.ts"
},
"fmt": {
"options": {
"lineWidth": 120,
"indentWidth": 2,
"singleQuote": false,
"useTabs": false
},
"files": {
"exclude": [
"./lock.json"
]
}
}
}

View file

@ -1,15 +0,0 @@
{
"version": "2",
"remote": {
"https://deno.land/std@0.118.0/fmt/colors.ts": "8368ddf2d48dfe413ffd04cdbb7ae6a1009cf0dccc9c7ff1d76259d9c61a0621"
},
"npm": {
"specifiers": { "chalk": "chalk@5.2.0" },
"packages": {
"chalk@5.2.0": {
"integrity": "sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==",
"dependencies": {}
}
}
}
}

View file

@ -1,5 +0,0 @@
{
"imports": {
"chalk": "npm:chalk"
}
}

View file

@ -1,36 +0,0 @@
import chalk from "chalk";
console.log(`Hello!`);
console.log(
`This script was written for ${chalk.bgBlack(chalk.white("deno"))}${chalk.black("2")}${
chalk.rgb(126, 126, 255)("Nix")
} with npm ${chalk.italic("chalk")} module.`,
);
// https://github.com/dylanaraps/neofetch/blob/ccd5d9f52609bbdcd5d8fa78c4fdb0f12954125f/neofetch#L8976-L8998
const c1 = (t: string) => chalk.rgb(71, 111, 182)(t);
const c2 = (t: string) => chalk.rgb(126, 182, 225)(t);
console.log(
[
c1(" ▗▄▄▄ ") + c2("▗▄▄▄▄ ▄▄▄▖"),
c1(" ▜███▙ ") + c2("▜███▙ ▟███▛"),
c1(" ▜███▙ ") + c2("▜███▙▟███▛"),
c1(" ▜███▙ ") + c2("▜██████▛"),
c1(" ▟█████████████████▙ ") + c2("▜████▛ ") + c1("▟▙"),
c1(" ▟███████████████████▙ ") + c2("▜███▙ ") + c1("▟██▙"),
c2(" ▄▄▄▄▖ ") + c2("▜███▙ ") + c1("▟███▛"),
c2(" ▟███▛ ") + c2("▜██▛ ") + c1("▟███▛"),
c2(" ▟███▛ ") + c2("▜▛ ") + c1("▟███▛"),
c2("▟███████████▛ ") + c1("▟██████████▙"),
c2("▜██████████▛ ") + c1("▟███████████▛"),
c2(" ▟███▛") + c1(" ▟▙ ") + c1("▟███▛"),
c2(" ▟███▛") + c1(" ▟██▙ ") + c1("▟███▛"),
c2(" ▟███▛") + c1(" ▜███▙ ") + c1("▝▀▀▀▀"),
c2(" ▜██▛") + c1(" ▜███▙ ") + c2("▜██████████████████▛"),
c2(" ▜▛") + c1(" ▟████▙ ") + c2("▜████████████████▛"),
c1(" ▟██████▙ ") + c2("▜███▙"),
c1(" ▟███▛▜███▙ ") + c2("▜███▙"),
c1(" ▟███▛ ▜███▙ ") + c2("▜███▙"),
c1(" ▝▀▀▀ ▀▀▀▀▘ ") + c2("▀▀▀▘"),
].join("\n"),
);

View file

@ -1 +0,0 @@
simple

View file

@ -1,11 +0,0 @@
{deno2nix}:
deno2nix.mkBundledWrapper {
pname = "simple-bundled";
version = "0.1.0";
src = ./.;
bin = "simple";
entrypoint = "./mod.ts";
lockfile = "./deno.lock";
}

View file

@ -1,11 +0,0 @@
{deno2nix}:
deno2nix.mkBundled {
pname = "simple-bundled";
version = "0.1.0";
src = ./.;
output = "bundled.js";
entrypoint = "./mod.ts";
lockfile = "./deno.lock";
}

View file

@ -1,6 +0,0 @@
{
"version": "2",
"remote": {
"https://deno.land/std@0.167.0/fmt/colors.ts": "03ad95e543d2808bc43c17a3dd29d25b43d0f16287fe562a0be89bf632454a12"
}
}

View file

@ -1 +0,0 @@
{deno2nix}: deno2nix.internal.mkDepsLink ./deno.lock

View file

@ -1,16 +0,0 @@
{deno2nix}:
deno2nix.mkExecutable {
pname = "simple-executable";
version = "0.1.0";
src = ./.;
bin = "simple";
entrypoint = "./mod.ts";
lockfile = "./deno.lock";
config = "./deno.jsonc";
allow = {
all = true;
};
}

View file

@ -1,5 +0,0 @@
{
"imports": {
"std/": "https://deno.land/std@0.167.0/"
}
}

View file

@ -1,32 +0,0 @@
import { bgBlack, black, rgb24, white } from "std/fmt/colors.ts";
console.log(`Hello!`);
console.log(`This script was written for ${bgBlack(white("deno"))}${black("2")}${rgb24("Nix", 0x7E7EFF)}.`);
// https://github.com/dylanaraps/neofetch/blob/ccd5d9f52609bbdcd5d8fa78c4fdb0f12954125f/neofetch#L8976-L8998
const c1 = (t: string) => rgb24(t, 0x4D6FB6);
const c2 = (t: string) => rgb24(t, 0x7EB6E1);
console.log(
[
c1(" ▗▄▄▄ ") + c2("▗▄▄▄▄ ▄▄▄▖"),
c1(" ▜███▙ ") + c2("▜███▙ ▟███▛"),
c1(" ▜███▙ ") + c2("▜███▙▟███▛"),
c1(" ▜███▙ ") + c2("▜██████▛"),
c1(" ▟█████████████████▙ ") + c2("▜████▛ ") + c1("▟▙"),
c1(" ▟███████████████████▙ ") + c2("▜███▙ ") + c1("▟██▙"),
c2(" ▄▄▄▄▖ ") + c2("▜███▙ ") + c1("▟███▛"),
c2(" ▟███▛ ") + c2("▜██▛ ") + c1("▟███▛"),
c2(" ▟███▛ ") + c2("▜▛ ") + c1("▟███▛"),
c2("▟███████████▛ ") + c1("▟██████████▙"),
c2("▜██████████▛ ") + c1("▟███████████▛"),
c2(" ▟███▛") + c1(" ▟▙ ") + c1("▟███▛"),
c2(" ▟███▛") + c1(" ▟██▙ ") + c1("▟███▛"),
c2(" ▟███▛") + c1(" ▜███▙ ") + c1("▝▀▀▀▀"),
c2(" ▜██▛") + c1(" ▜███▙ ") + c2("▜██████████████████▛"),
c2(" ▜▛") + c1(" ▟████▙ ") + c2("▜████████████████▛"),
c1(" ▟██████▙ ") + c2("▜███▙"),
c1(" ▟███▛▜███▙ ") + c2("▜███▙"),
c1(" ▟███▛ ▜███▙ ") + c2("▜███▙"),
c1(" ▝▀▀▀ ▀▀▀▀▘ ") + c2("▀▀▀▘"),
].join("\n"),
);

View file

@ -10,11 +10,11 @@
]
},
"locked": {
"lastModified": 1667210711,
"narHash": "sha256-IoErjXZAkzYWHEpQqwu/DeRNJGFdR7X2OGbkhMqMrpw=",
"lastModified": 1654858401,
"narHash": "sha256-53bw34DtVJ2bnF6WEwy6Tym+qY0pNEiEwARUlvmTZjs=",
"owner": "numtide",
"repo": "devshell",
"rev": "96a9dd12b8a447840cc246e17a47b81a4268bba7",
"rev": "f55e05c6d3bbe9acc7363bc8fc739518b2f02976",
"type": "github"
},
"original": {
@ -26,11 +26,11 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1668681692,
"narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=",
"lastModified": 1650374568,
"narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "009399224d5e398d03b22badca40a37ac85412a1",
"rev": "b4a34015c698c7793d592d66adbab377907a2be8",
"type": "github"
},
"original": {
@ -41,11 +41,11 @@
},
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"lastModified": 1653893745,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
"type": "github"
},
"original": {
@ -56,11 +56,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1670332253,
"narHash": "sha256-O5SmhlIUt1s+vK4NXeGYqwcBIMwbBPAEZ3GHE3XT28c=",
"lastModified": 1655400192,
"narHash": "sha256-49OBVVRgb9H/PSmNT9W61+NRdDbuSJVuDDflwXlaUKU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "1c9ffcf70786f0966982ce0fc76ec05df2e1dec2",
"rev": "3d7435c638baffaa826b85459df0fff47f12317d",
"type": "github"
},
"original": {

View file

@ -26,6 +26,7 @@
} @ inputs:
{
overlays.default = import ./nix/overlay.nix;
overlay = self.overlays.default;
}
// flake-utils.lib.eachSystem [
"x86_64-linux"
@ -44,33 +45,49 @@
];
};
in {
/*
TODO: It can't but I don't why
packages = flake-utils.lib.flattenTree {
simple = {
deps-link = pkgs.callPackage ./examples/simple/deps-link.nix {};
executable = pkgs.callPackage ./examples/simple/executable.nix {};
packages.depslink = deno2nix.internal.mkDepsLink ./lock.json;
packages.bundled = deno2nix.mkBundled {
pname = "example-bundled";
version = "0.1.0";
src = ./.;
lockfile = ./lock.json;
output = "bundled.js";
entrypoint = "./mod.ts";
importMap = "./import_map.json";
};
packages.bundled-wrapper = deno2nix.mkBundledWrapper {
pname = "example-bundled-wrapper";
version = "0.1.0";
src = ./.;
lockfile = ./lock.json;
output = "bundled.js";
entrypoint = "./mod.ts";
importMap = "./import_map.json";
};
*/
packages = {
"simple/deps-link" = pkgs.callPackage ./examples/simple/deps-link.nix {};
"simple/bundled" = pkgs.callPackage ./examples/simple/bundled.nix {};
"simple/bundled-wrapper" = pkgs.callPackage ./examples/simple/bundled-wrapper.nix {};
"simple/executable" = pkgs.callPackage ./examples/simple/executable.nix {};
};
apps = {
"simple/executable" = flake-utils.lib.mkApp {
drv = self.packages.${system}."simple/executable";
name = "simple";
};
"simple/bundled-wrapper" = flake-utils.lib.mkApp {
drv = self.packages.${system}."simple/bundled-wrapper";
name = "simple";
};
packages.executable = deno2nix.mkExecutable {
pname = "example-executable";
version = "0.1.2";
src = ./.;
lockfile = ./lock.json;
output = "example";
entrypoint = "./mod.ts";
importMap = "./import_map.json";
};
packages.default = self.packages.${system}.executable;
defaultPackage = self.packages.${system}.default;
apps.bundled-wrapper = flake-utils.lib.mkApp {drv = self.packages.${system}.bundled-wrapper;};
apps.executable = flake-utils.lib.mkApp {drv = self.packages.${system}.executable;};
apps.default = self.apps.${system}.executable;
checks = self.packages.${system};
devShells.default = pkgs.devshell.mkShell {
packages = with pkgs; [
alejandra
@ -78,6 +95,12 @@
treefmt
taplo-cli
];
commands = [
{
package = "treefmt";
category = "formatters";
}
];
};
}
);

5
import_map.json Normal file
View file

@ -0,0 +1,5 @@
{
"imports": {
"std/": "https://deno.land/std@0.118.0/"
}
}

3
lock.json Normal file
View file

@ -0,0 +1,3 @@
{
"https://deno.land/std@0.118.0/fmt/colors.ts": "8368ddf2d48dfe413ffd04cdbb7ae6a1009cf0dccc9c7ff1d76259d9c61a0621"
}

3
mod.ts Normal file
View file

@ -0,0 +1,3 @@
import { green, italic } from "std/fmt/colors.ts";
console.log(`Hello ${italic(green("World"))}!`);

View file

@ -1,16 +1,27 @@
{
pkgs,
lib,
linkFarm,
writeText,
deno2nix,
...
}: let
inherit (builtins) split elemAt fetchurl toJSON hashString baseNameOf;
inherit (lib) flatten mapAttrsToList importJSON;
inherit (lib.strings) sanitizeDerivationName;
inherit (deno2nix.internal) artifactPath;
in
lockfile: (
# https://deno.land/std@0.118.0/fmt/colors.ts
#
# 0. "https"
# 1. "deno.land"
# 2. "/std@0.118.0/fmt/colors.ts"
urlPart = url: elemAt (flatten (split "://([a-z0-9\.]*)" url));
# https://deno.land/std@0.118.0/fmt/colors.ts
#
# https/deno.land/<sha256 "/std@0.118.0/fmt/colors.ts">
artifactPath = url: let up = urlPart url; in "${up 0}/${up 1}/${hashString "sha256" (up 2)}";
in {
mkDepsLink = lockfile: (
linkFarm "deps" (flatten (
mapAttrsToList
(
@ -32,6 +43,7 @@ in
}
]
)
(importJSON lockfile).remote
(importJSON lockfile)
))
)
);
}

View file

@ -1,14 +0,0 @@
{
lib,
deno2nix,
...
}: let
inherit (builtins) hashString;
inherit (deno2nix.internal) urlPart;
in
# input: https://deno.land/std@0.118.0/fmt/colors.ts
#
# output: https/deno.land/<sha256 "/std@0.118.0/fmt/colors.ts">
url: let
up = urlPart url;
in "${up 0}/${up 1}/${hashString "sha256" (up 2)}"

View file

@ -1,7 +0,0 @@
{pkgs, ...}: {
urlPart = pkgs.callPackage ./url-part.nix {};
artifactPath = pkgs.callPackage ./artifact-path.nix {};
mkDepsLink = pkgs.callPackage ./mk-deps-link.nix {};
findImportMap =
pkgs.callPackage ./find-import-map.nix {};
}

View file

@ -1,10 +0,0 @@
{lib, ...}: let
inherit (lib) importJSON;
in
{
src,
config,
importMap,
}:
# TODO: if importMap is exists, fallback
((importJSON (src + "/${config}")).importMap)

View file

@ -1,11 +0,0 @@
{lib, ...}: let
inherit (builtins) split elemAt;
inherit (lib) flatten;
in
# input: https://deno.land/std@0.118.0/fmt/colors.ts
#
# output:
# 0. "https"
# 1. "deno.land"
# 2. "/std@0.118.0/fmt/colors.ts"
url: elemAt (flatten (split "://([a-z0-9\.]*)" url))

View file

@ -0,0 +1,17 @@
{
pkgs,
deno,
deno2nix,
writeShellScriptBin,
...
}: {
pname,
bin ? pname,
output ? "bundled.js",
...
} @ args: let
bundled = deno2nix.mkBundled args;
in
writeShellScriptBin
bin
"${deno}/bin/deno run ${bundled}/dist/${output}"

43
nix/make-bundled.nix Normal file
View file

@ -0,0 +1,43 @@
{
pkgs,
stdenv,
deno2nix,
lib,
...
}: {
pname,
version,
src,
lockfile,
output ? "bundled.js",
entrypoint,
importMap ? null,
additionalDenoFlags ? "",
}: let
inherit (deno2nix.internal) mkDepsLink;
in
stdenv.mkDerivation {
inherit pname version entrypoint src;
buildInputs = with pkgs; [deno jq];
buildPhase = ''
export DENO_DIR="/tmp/deno2nix"
mkdir -p $DENO_DIR
ln -s "${mkDepsLink lockfile}" $(deno info --json | jq -r .modulesCache)
deno bundle \
--lock="${lockfile}" \
${
if importMap != null
then "--import-map=\"$src/${importMap}\""
else ""
} \
${additionalDenoFlags} \
"$src/${entrypoint}" \
"${output}"
'';
installPhase = ''
mkdir -p $out/dist
install -t $out/dist "${output}"
'';
}

45
nix/make-executable.nix Normal file
View file

@ -0,0 +1,45 @@
{
pkgs,
stdenv,
deno2nix,
...
}: {
pname,
version,
src,
lockfile,
output ? pname,
entrypoint,
importMap ? null,
additionalDenoFlags ? "",
}: let
inherit (deno2nix.internal) mkDepsLink;
in
stdenv.mkDerivation {
inherit pname version src;
dontFixup = true;
buildInputs = with pkgs; [deno jq];
buildPhase = ''
export DENO_DIR="/tmp/deno2nix"
mkdir -p $DENO_DIR
ln -s "${mkDepsLink lockfile}" $(deno info --json | jq -r .modulesCache)
deno compile \
--cached-only \
--lock="${lockfile}" \
--output="${output}" \
${
if importMap != null
then "--import-map=\"$src/${importMap}\""
else ""
} \
${additionalDenoFlags} \
"$src/${entrypoint}"
'';
installPhase = ''
mkdir -p $out/bin
cp "${output}" "$out/bin/"
'';
}

View file

@ -1,19 +0,0 @@
{
lib,
deno,
deno2nix,
writeShellScriptBin,
...
}: {
pname,
bin ? pname,
output ? "${pname}.bundled.js",
outPath ? "dist",
...
} @ args: let
inherit (lib) filterAttrs;
bundled = deno2nix.mkBundled (filterAttrs (n: v: n != "bin") args);
in
writeShellScriptBin
bin
"${deno}/bin/deno run ${bundled}/${outPath}/${output}"

View file

@ -1,57 +0,0 @@
{
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}"
'';
}

View file

@ -1,73 +0,0 @@
{
pkgs,
lib,
stdenv,
deno2nix,
...
}: {
pname,
version,
src,
bin ? pname,
buildInputs ? [],
entrypoint,
lockfile,
config,
allow ? {},
additionalDenoFlags ? "",
} @ inputs: let
inherit (builtins) isString;
inherit (lib) importJSON concatStringsSep;
inherit (deno2nix.internal) mkDepsLink findImportMap;
allowflag = flag: (
if (allow ? flag) && allow."${flag}"
then ["--allow-${flag}"]
else []
);
importMap = findImportMap {
inherit (inputs) src config importMap;
};
compileCmd = concatStringsSep " " (
[
"deno compile --cached-only"
"--lock=${lockfile}"
"--output=${bin}"
# "--config=${config}"
]
++ (
if (isString importMap)
then ["--import-map=${importMap}"]
else []
)
++ (allowflag "all")
++ (allowflag "env")
++ (allowflag "ffi")
++ (allowflag "hrtime")
++ (allowflag "net")
++ (allowflag "read")
++ (allowflag "run")
++ (allowflag "sys")
++ (allowflag "write")
++ [additionalDenoFlags]
++ ["${entrypoint}"]
);
in
stdenv.mkDerivation {
inherit pname version src;
dontFixup = true;
buildInputs = with pkgs; [deno jq] ++ buildInputs;
buildPhase = ''
export DENO_DIR="/tmp/deno2nix"
mkdir -p $DENO_DIR
ln -s "${mkDepsLink (src + "/${lockfile}")}" $(deno info --json | jq -r .modulesCache)
${compileCmd}
'';
installPhase = ''
mkdir -p $out/bin
cp "${bin}" "$out/bin/"
'';
}

View file

@ -1,9 +1,9 @@
final: prev: {
deno2nix = {
mkBundled = final.callPackage ./mk-bundled.nix {};
mkBundledWrapper = final.callPackage ./mk-bundled-wrapper.nix {};
mkExecutable = final.callPackage ./mk-executable.nix {};
mkBundled = final.callPackage ./make-bundled.nix {};
mkBundledWrapper = final.callPackage ./make-bundled-wrapper.nix {};
mkExecutable = final.callPackage ./make-executable.nix {};
internal = final.callPackage ./internal {};
internal = final.callPackage ./internal.nix {};
};
}