Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: esm.sh support, add Fresh example #5

Merged
merged 8 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions _sources/generated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"esbuild-aarch64-darwin": {
"cargoLocks": null,
"date": null,
"extract": null,
"name": "esbuild-aarch64-darwin",
"passthru": null,
"pinned": false,
"src": {
"sha256": "sha256-mtCCgWZi2wdbgz0gRYLP/GZfgJ/UKLnPTBvc5pxpk9g=",
"type": "tarball",
"url": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.4.tgz"
},
"version": "0.19.4"
},
"esbuild-aarch64-linux": {
"cargoLocks": null,
"date": null,
"extract": null,
"name": "esbuild-aarch64-linux",
"passthru": null,
"pinned": false,
"src": {
"sha256": "sha256-0UNPha4R8O8cCDiddB6755asI8eFzZT/wvwrN7xEKPo=",
"type": "tarball",
"url": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.4.tgz"
},
"version": "0.19.4"
},
"esbuild-x86_64-darwin": {
"cargoLocks": null,
"date": null,
"extract": null,
"name": "esbuild-x86_64-darwin",
"passthru": null,
"pinned": false,
"src": {
"sha256": "sha256-6vGfZgKyZw0DHkov07UYsIIGIy8DyeDvcn6qZSPTDxU=",
"type": "tarball",
"url": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.4.tgz"
},
"version": "0.19.4"
},
"esbuild-x86_64-linux": {
"cargoLocks": null,
"date": null,
"extract": null,
"name": "esbuild-x86_64-linux",
"passthru": null,
"pinned": false,
"src": {
"sha256": "sha256-Cf8siblPU9rrTajm88VYibOSIimM2Of0kQudINeOrew=",
"type": "tarball",
"url": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.4.tgz"
},
"version": "0.19.4"
}
}
36 changes: 36 additions & 0 deletions _sources/generated.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file was generated by nvfetcher, please do not modify it manually.
{ fetchgit, fetchurl, fetchFromGitHub, dockerTools }:
{
esbuild-aarch64-darwin = {
pname = "esbuild-aarch64-darwin";
version = "0.19.4";
src = fetchTarball {
url = "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.4.tgz";
sha256 = "sha256-mtCCgWZi2wdbgz0gRYLP/GZfgJ/UKLnPTBvc5pxpk9g=";
};
};
esbuild-aarch64-linux = {
pname = "esbuild-aarch64-linux";
version = "0.19.4";
src = fetchTarball {
url = "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.4.tgz";
sha256 = "sha256-0UNPha4R8O8cCDiddB6755asI8eFzZT/wvwrN7xEKPo=";
};
};
esbuild-x86_64-darwin = {
pname = "esbuild-x86_64-darwin";
version = "0.19.4";
src = fetchTarball {
url = "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.4.tgz";
sha256 = "sha256-6vGfZgKyZw0DHkov07UYsIIGIy8DyeDvcn6qZSPTDxU=";
};
};
esbuild-x86_64-linux = {
pname = "esbuild-x86_64-linux";
version = "0.19.4";
src = fetchTarball {
url = "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.4.tgz";
sha256 = "sha256-Cf8siblPU9rrTajm88VYibOSIimM2Of0kQudINeOrew=";
};
};
}
28 changes: 28 additions & 0 deletions ci.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
mkdir -p $out
deno run -A ./main.ts > $out/output.txt
'';
nvfetcher = pkgs.callPackage ./_sources/generated.nix {};
esbuild = nvfetcher."esbuild-${pkgs.hostPlatform.system}";
in {
# simple imports, following the `deps.ts` convention
remote-simple = pkgs.denoPlatform.mkDenoDerivation {
Expand Down Expand Up @@ -33,6 +35,32 @@ in {
inherit buildPhase;
};

# with esm.sh dependencies
esm-simple = pkgs.denoPlatform.mkDenoDerivation {
name = "esm-simple";

src = ./examples/esm-simple;

inherit buildPhase;
};

# Fresh project heavily utilizing esm.sh dependencies
fresh = pkgs.denoPlatform.mkDenoDerivation {
name = "fresh";

src = ./examples/fresh;

buildPhase = ''
deno task build
'';

env.ESBUILD_BINARY_PATH = "${esbuild.src}/bin/esbuild";

installPhase = ''
cp -r _fresh $out
'';
};

# Lume project with mixed dependencies
lume = pkgs.denoPlatform.mkDenoDerivation {
name = "lume";
Expand Down
1 change: 1 addition & 0 deletions examples/esm-simple/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 7 additions & 0 deletions examples/esm-simple/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions examples/esm-simple/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import color from "https://esm.sh/v135/[email protected]/";

const ascii = [
color.green("╺┳┓┏━╸┏┓╻┏━┓ ╻ ┏━┓┏┓╻╺┳┓"),
color.green(" ┃┃┣╸ ┃┗┫┃ ┃ ┃ ┣━┫┃┗┫ ┃┃"),
color.green("╺┻┛┗━╸╹ ╹┗━┛╹┗━╸╹ ╹╹ ╹╺┻┛"),
color.black(" ┏━┓┏┓╻"),
color.black(" ┃ ┃┃┗┫"),
color.black(" ┗━┛╹ ╹"),
color.blue(" ┏┓╻╻╻ ╻"),
color.blue(" ┃┗┫┃┏╋┛"),
color.blue(" ╹ ╹╹╹ ╹"),
].join("\n");

console.log(color.bold(color.blue(ascii)));
11 changes: 11 additions & 0 deletions examples/fresh/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# Fresh build directory
_fresh/
# npm dependencies
node_modules/
10 changes: 10 additions & 0 deletions examples/fresh/_nix-cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// just needed for the nix cache to work
import {} from "https://deno.land/x/[email protected]/src/runtime/entrypoints/deserializer.ts";
import {} from "https://deno.land/x/[email protected]/src/runtime/entrypoints/main.ts";
import {} from "https://deno.land/x/[email protected]/src/runtime/entrypoints/signals.ts";
import {} from "https://deno.land/x/[email protected]/src/runtime/polyfills.ts";
import {} from "https://deno.land/x/[email protected]/mod.d.ts";
import {} from "https://deno.land/x/[email protected]/mod.d.ts";
import {} from "https://deno.land/x/[email protected]/lib/types.d.ts";
import {} from "https://deno.land/[email protected]/io/types.d.ts";
import {} from "https://deno.land/x/[email protected]/wasm.d.ts";
12 changes: 12 additions & 0 deletions examples/fresh/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { JSX } from "preact";
import { IS_BROWSER } from "$fresh/runtime.ts";

export function Button(props: JSX.HTMLAttributes<HTMLButtonElement>) {
return (
<button
{...props}
disabled={!IS_BROWSER || props.disabled}
class="px-2 py-1 border-gray-500 border-2 rounded bg-white hover:bg-gray-200 transition-colors"
/>
);
}
29 changes: 29 additions & 0 deletions examples/fresh/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"tasks": {
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
"cli": "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -",
"manifest": "deno task cli manifest $(pwd)",
"start": "deno run -A --watch=static/,routes/ dev.ts",
"build": "deno run -A dev.ts build",
"preview": "deno run -A main.ts",
"update": "deno run -A -r https://fresh.deno.dev/update ."
},
"lint": {
"rules": {
"tags": ["fresh", "recommended"]
}
},
"exclude": ["**/_fresh/*"],
"imports": {
"$fresh/": "https://deno.land/x/[email protected]/",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
"@preact/signals": "https://esm.sh/*@preact/[email protected]",
"@preact/signals-core": "https://esm.sh/*@preact/[email protected]",
"$std/": "https://deno.land/[email protected]/"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}
Loading