Skip to content

Commit c467f31

Browse files
committed
Initial commit of jsaddle-run.
0 parents  commit c467f31

File tree

11 files changed

+236
-0
lines changed

11 files changed

+236
-0
lines changed

.github/workflows/main.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: jsaddle-run CI
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
8+
env:
9+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
if: github.ref != 'refs/heads/master'
15+
steps:
16+
- uses: DeterminateSystems/nix-installer-action@main
17+
- uses: actions/[email protected]
18+
- uses: cachix/install-nix-action@v25
19+
with:
20+
nix_path: nixpkgs=channel:nixpkgs-unstable
21+
- name: Cancel Previous Runs
22+
uses: styfle/[email protected]
23+
with:
24+
access_token: ${{ github.token }}
25+
- uses: cachix/cachix-action@v16
26+
with:
27+
name: haskell-miso-cachix
28+
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
29+
30+
- name: Nix channel update
31+
run: nix-channel --update
32+
33+
- name: Build
34+
run: nix-build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*~

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for jsaddle-run
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.

LICENSE

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Copyright (c) 2016-2025, David M. Johnson
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
6+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9+
10+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
jsaddle-run
2+
===================
3+
4+
An abstraction over jsaddle for various backends (GHCJS, WASM, GHC)
5+
6+
Abstracts over:
7+
- [jsaddle-wasm](https://github.com/amesgen/jsaddle-wasm)
8+
- [jsaddle-warp](https://hackage.haskell.org/package/jsaddle-warp)
9+
10+
### Dev
11+
12+
```nix-shell
13+
$ nix-shell
14+
```
15+
16+
### Build
17+
18+
```nix-shell
19+
$ nix-build
20+
```
21+
22+
### Usage
23+
24+
```haskell
25+
module Main where
26+
27+
import Language.Javascript.JSaddle (run)
28+
29+
main :: IO ()
30+
main = run code
31+
32+
code :: JSM ()
33+
code = undefined -- your code goes here
34+
```
35+
36+
37+

default.nix

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
with (builtins.fromJSON (builtins.readFile ./nixpkgs.json));
2+
3+
{ nixpkgs ? builtins.fetchTarball {
4+
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
5+
inherit sha256;
6+
}
7+
}:
8+
9+
let
10+
pkgs = import nixpkgs {};
11+
source = {
12+
jsaddle = pkgs.fetchFromGitHub {
13+
owner = "ghcjs";
14+
repo = "jsaddle";
15+
rev = "2513cd19184376ac8a2f0e3797a1ae7d2e522e87";
16+
hash = "sha256-xJ3BLiFtQmH92Y0jqIgdzJqidQHm3M1ZKHRAUEgNZF0=";
17+
};
18+
jsaddle-run = ./.;
19+
};
20+
21+
overrides = self: super: with pkgs.haskell.lib; {
22+
jsaddle-run =
23+
self.callCabal2nix "jsaddle-run" source.jsaddle-run {};
24+
jsaddle =
25+
self.callCabal2nix "jsaddle" "${source.jsaddle}/jsaddle" {};
26+
jsaddle-warp =
27+
dontCheck (self.callCabal2nix "jsaddle-warp" "${source.jsaddle}/jsaddle-warp" {});
28+
};
29+
30+
hPkgs =
31+
pkgs.haskellPackages.override { inherit overrides; };
32+
33+
in
34+
35+
{
36+
inherit (hPkgs) jsaddle-run;
37+
}

jsaddle-run.cabal

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
cabal-version: 2.2
2+
name: jsaddle-run
3+
version: 0.1.0.0
4+
synopsis: Abstraction over various jsaddle backends
5+
description: Transparently execute JSM in either WASM, GHCJS and GHC
6+
homepage: https://github.com/haskell-miso/jsaddle-run
7+
license: BSD-3-Clause
8+
license-file: LICENSE
9+
author: dmjio
10+
maintainer: [email protected]
11+
copyright: dmjio @ 2025
12+
category: Web
13+
build-type: Simple
14+
extra-doc-files: CHANGELOG.md
15+
16+
common cpp
17+
if impl(ghcjs) || arch(javascript)
18+
cpp-options:
19+
-DGHCJS_BOTH
20+
if impl(ghcjs)
21+
cpp-options:
22+
-DGHCJS_OLD
23+
elif arch(javascript)
24+
cpp-options:
25+
-DGHCJS_NEW
26+
elif arch(wasm32)
27+
cpp-options:
28+
-DWASM
29+
else
30+
cpp-options:
31+
-DNATIVE
32+
33+
common jsaddle
34+
if !(impl(ghcjs) || arch(javascript) || arch(wasm32))
35+
build-depends:
36+
jsaddle-warp < 0.10
37+
38+
if !(impl(ghcjs) || arch(javascript))
39+
build-depends:
40+
file-embed < 0.1
41+
42+
if arch(wasm32)
43+
build-depends:
44+
jsaddle-wasm >= 0.1.2 && < 0.2
45+
46+
library
47+
imports:
48+
cpp, jsaddle
49+
exposed-modules:
50+
Language.Javascript.JSaddle.Run
51+
build-depends:
52+
base, jsaddle
53+
hs-source-dirs:
54+
src
55+
default-language:
56+
Haskell2010

nixpkgs.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"rev" : "b594b289740a2bc917ed9c66fef5d905f389cb96",
3+
"sha256" : "sha256:1p25582cbrjlqv4kr64481m776vgppgxghinrdjpfjglkjj3aw2w"
4+
}

shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(import ./default.nix {}).env
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
-----------------------------------------------------------------------------
2+
{-# LANGUAGE CPP #-}
3+
{-# LANGUAGE OverloadedStrings #-}
4+
-----------------------------------------------------------------------------
5+
-- |
6+
-- Module : Language.Javascript.JSaddle.Run
7+
-- Copyright : (C) 2016-2025 David M. Johnson
8+
-- License : BSD3-style (see the file LICENSE)
9+
-- Maintainer : David M. Johnson <[email protected]>
10+
-- Stability : experimental
11+
-- Portability : non-portable
12+
----------------------------------------------------------------------------
13+
module Language.Javascript.JSaddle.Run
14+
( -- ** Execution
15+
run
16+
) where
17+
-----------------------------------------------------------------------------
18+
#ifdef WASM
19+
import qualified Language.Javascript.JSaddle.Wasm as J
20+
#elif !GHCJS_BOTH
21+
import Data.Maybe
22+
import System.Environment
23+
import Text.Read
24+
import qualified Language.Javascript.JSaddle.Warp as J
25+
#endif
26+
import Language.Javascript.JSaddle
27+
-----------------------------------------------------------------------------
28+
-- | When compiling with jsaddle on native platforms
29+
-- 'run' will start a web server for live reload
30+
-- of your application.
31+
--
32+
-- When compiling to WASM this will use 'jsaddle-wasm'.
33+
-- When compiling to JS (via jsaddle-warp) no special package is
34+
-- required (simply the 'id' function). JSM becomes a type synonym for IO.
35+
run :: JSM () -> IO ()
36+
#ifdef WASM
37+
run = J.run
38+
#elif GHCJS_BOTH
39+
run = id
40+
#else
41+
run action = do
42+
port <- fromMaybe 8008 . (readMaybe =<<) <$> lookupEnv "PORT"
43+
isGhci <- (== "<interactive>") <$> getProgName
44+
putStrLn $ "Running on port " <> show port <> "..."
45+
(if isGhci then J.debug else J.run) port action
46+
#endif
47+
-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)