Skip to content

Spike lamdera live in --optimize-legible mode #20

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

Open
wants to merge 4 commits into
base: lamdera-next
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions builder/src/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ repl root details ansi (Build.ReplArtifacts home modules localizer annotations)

checkForDebugUses :: Objects -> Task ()
checkForDebugUses (Objects _ locals) =
case Map.keys (Map.filter Nitpick.hasDebugUses locals) of
[] -> return ()
m:ms -> Task.throw (Exit.GenerateCannotOptimizeDebugValues m ms)
return ()
-- case Map.keys (Map.filter Nitpick.hasDebugUses locals) of
-- [] -> return ()
-- m:ms -> Task.throw (Exit.GenerateCannotOptimizeDebugValues m ms)



Expand Down
15 changes: 14 additions & 1 deletion extra/Lamdera/Injection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ behaviors and limitations.
See extra/Lamdera/ReverseProxy.hs for the proxy itself
-}
modifiedHttp_toTask isProd =
onlyIf (not isProd)
-- onlyIf (not isProd)
-- Identical to original except for alterIfProxyRequired addition
[text|

Expand Down Expand Up @@ -314,6 +314,19 @@ injections isBackend isLocalDev =
fns: fns
} : {};
}

// Restore Debug.* from dev mode to see what happens
// $$elm$$core$$Debug$$log = _Debug_log_UNUSED;
$$elm$$core$$Debug$$log = F2(function(tag, value)
{
console.log(tag + ': ', value);
return value;
});
// $$elm$$core$$Debug$$toString = _Debug_toString_UNUSED;

// debugger
0;

|]

-- // https://github.com/elm/bytes/issues/20
Expand Down
13 changes: 6 additions & 7 deletions extra/Lamdera/Live.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@ lamderaLiveSrc =
if Ext.Common.isDebug_
then do
Lamdera.debug $ "🗿 Using debug mode lamderaLive"
userHome <- Dir.getHomeDirectory
let overrideRoot = userHome </> "dev/projects/lamdera-compiler/extra"
let overrideRoot = withCompilerRoot "extra"
overridePath = overrideRoot </> "live.js"
overridePathBuilt = overrideRoot </> "dist/live.js"
overridePathBuild = overrideRoot </> "dist/live.js"

exists <- doesFileExist overridePath
if exists
then do
Lamdera.debug $ "🗿 Using " ++ overridePathBuilt ++ " for lamderaLive"
Lamdera.debug $ "🗿 Using overridePathBuild " ++ overridePathBuild ++ " for lamderaLive"
Ext.Common.requireBinary "npm"
Ext.Common.requireBinary "esbuild"
Ext.Common.bash $ "cd " <> overrideRoot <> " && npm i && esbuild " <> overridePath <> " --bundle --minify --target=chrome58,firefox57,safari11,edge16 > " <> overridePathBuilt
-- Ext.Common.bash $ "cd " <> overrideRoot <> " && npm i && esbuild " <> overridePath <> " --bundle --target=chrome58,firefox57,safari11,edge16 > " <> overridePathBuilt
overrideM <- readUtf8Text overridePathBuilt
-- Ext.Common.bash $ "cd " <> overrideRoot <> " && npm i && esbuild " <> overridePath <> " --bundle --minify --target=chrome58,firefox57,safari11,edge16 > " <> overridePathBuild
Ext.Common.bash $ "cd " <> overrideRoot <> " && npm i && esbuild " <> overridePath <> " --bundle --target=chrome58,firefox57,safari11,edge16 > " <> overridePathBuild
overrideM <- readUtf8Text overridePathBuild
case overrideM of
Just override -> do
pure (T.encodeUtf8Builder override)
Expand Down
137 changes: 135 additions & 2 deletions extra/LocalDev/LocalDev.elm
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,136 @@ type LiveStatus
| Offline


msgToString : Msg -> String
msgToString m =
case m of
FEMsg x ->
"FEMsg " ++ Debug.toString x

BEMsg backendMsg ->
"BEMsg " ++ Debug.toString backendMsg

BEtoFE clientId toFrontend ->
"BEtoFE " ++ clientId ++ " " ++ Debug.toString toFrontend

BEtoFEDelayed clientId toFrontend ->
"BEtoFEDelayed " ++ clientId ++ " " ++ Debug.toString toFrontend

FEtoBE toBackend ->
"FEtoBE " ++ Debug.toString toBackend

FEtoBEDelayed toBackend ->
"FEtoBEDelayed " ++ Debug.toString toBackend

FENewUrl url ->
"FENewUrl " ++ Debug.toString url

OnConnection d ->
"OnConnection " ++ Debug.toString d

OnDisconnection d ->
"OnDisconnection " ++ Debug.toString d

ReceivedToBackend ( s, c, bytes ) ->
"ReceivedToBackend " ++ s ++ " " ++ c ++ " " ++ Debug.toString bytes

ReceivedToFrontend args ->
"ReceivedToFrontend " ++ Debug.toString args

ReceivedBackendModel bytes ->
"ReceivedBackendModel " ++ Debug.toString bytes

RPCIn rpcArgsJson ->
"RPCIn " ++ Debug.toString rpcArgsJson

SetNodeTypeLeader bool ->
"SetNodeTypeLeader " ++ Debug.toString bool

SetLiveStatus bool ->
"SetLiveStatus " ++ Debug.toString bool

ReceivedClientId clientId ->
"ReceivedClientId " ++ clientId

ExpandedDevbar ->
"ExpandedDevbar"

CollapsedDevbar ->
"CollapsedDevbar"

ResetDebugStoreBoth ->
"ResetDebugStoreBoth"

ResetDebugStoreFE ->
"ResetDebugStoreFE"

ResetDebugStoreBE ->
"ResetDebugStoreBE"

ToggledFreezeMode ->
"ToggledFreezeMode"

ToggledNetworkDelay ->
"ToggledNetworkDelay"

ToggledLogging ->
"ToggledLogging"

QRCodeShow ->
"QRCodeShow"

QRCodeHide ->
"QRCodeHide"

ClickedLocation ->
"ClickedLocation"

PersistBackend reload ->
"PersistBackend"

Reload ->
"Reload"

EnvClicked ->
"EnvClicked"

EnvModeSelected _ ->
"EnvModeSelected"

EnvCleared ->
"EnvCleared"

ModelResetCleared ->
"ModelResetCleared"

VersionCheck _ ->
"VersionCheck"

VersionCheckResult _ ->
"VersionCheckResult"

LoadLatestSnapshotFilename ->
"LoadLatestSnapshotFilename"

LoadLatestSnapshotFilenamesResult _ ->
"LoadLatestSnapshotFilenamesResult"

LoadSnapshot _ ->
"LoadSnapshot"

LoadSnapshotLegacy _ ->
"LoadSnapshotLegacy"

LoadedSnapshot _ ->
"LoadedSnapshot"

LoadedSnapshotLegacy _ ->
"LoadedSnapshotLegacy"

Noop ->
"Noop"


update : Msg -> Model -> ( Model, Cmd Msg )
update msg m =
let
Expand All @@ -397,9 +527,12 @@ update msg m =

else
v

_ =
Debug.log "msg" (msgToString msg)
in
-- case Debug.log "msg" msg of
case msg of
case Debug.log "msg" msg of
-- case msg of
FEMsg frontendMsg ->
let
x =
Expand Down
10 changes: 10 additions & 0 deletions extra/live.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const flushOutbound = function() {
}

const msgEmitter = function(payload) {
debugger
if (connected) {
ws.json(payload)
} else {
Expand All @@ -96,6 +97,7 @@ const flushInbound = function() {

const msgInbound = function(portname, arg) {
if (app !== null) {
debugger
app.ports[portname].send(arg)
} else {
bufferInbound.unshift({ n: portname, a: arg })
Expand Down Expand Up @@ -126,6 +128,7 @@ window.setupApp = function(name, elid) {
}
// window.app = app
app.ports.send_ToFrontend.subscribe(function (payload) {
debugger
if (payload.b !== null) {
payload.b = bytesToBase64(payload.b)
}
Expand All @@ -134,6 +137,7 @@ window.setupApp = function(name, elid) {
})

app.ports.save_BackendModel.subscribe(function (payload) {
debugger
payload.b = bytesToBase64(payload.b)
payload.f = (payload.f) ? "force" : ""
msgEmitter(payload)
Expand All @@ -144,6 +148,7 @@ window.setupApp = function(name, elid) {
})

app.ports.send_ToBackend.subscribe(function (bytes) {
debugger
var b64 = bytesToBase64(bytes)
// console.log(`[S] ToBackend`, { t:"ToBackend", s: sessionId, c: clientId, b: b64 })
msgEmitter({ t:"ToBackend", s: sessionId, c: clientId, b: b64 })
Expand Down Expand Up @@ -200,11 +205,13 @@ window.setupApp = function(name, elid) {
break;

case "ToBackend":
debugger
// console.log(`[R] ToBackend`, d)
app.ports.receive_ToBackend.send([d.s, d.c, base64ToBytes(d.b)])
break;

case "ToFrontend":
debugger
// Only process messages for our clientId, or a broadcast
if (d.c == clientId || d.c == sessionId || d.c == "b") {
// console.log(`[R] ToFrontend`, d)
Expand All @@ -219,6 +226,7 @@ window.setupApp = function(name, elid) {
break;

case "p":
debugger
if (app === null) {
// We're being given a backend state to boot up with
initBackendModel = base64ToBytes(d.b)
Expand All @@ -239,6 +247,7 @@ window.setupApp = function(name, elid) {
var response = null

const returnHandler = function(payload) {
debugger
if (payload.r === d.r) {
// console.log("got rpc resp:", payload)
response = payload
Expand All @@ -251,6 +260,7 @@ window.setupApp = function(name, elid) {
if (d.i) { d.i = JSON.parse(d.i); }
if (d.j) { d.j = JSON.parse(d.j); }

debugger
app.ports.rpcIn.send(d)

// Is there a nicer way to do this?
Expand Down
3 changes: 2 additions & 1 deletion terminal/src/Develop.hs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ serveElm sentryCache path =
compileToBuilder :: FilePath -> IO BS.ByteString
compileToBuilder path =
do
_ <- Lamdera.enableLongNames
result <- compile path

pure $
Expand Down Expand Up @@ -311,7 +312,7 @@ compile path =
Lamdera.PostCompile.check details artifacts Exit.ReactorBadBuild
Lamdera.TypeHash.buildCheckHashes artifacts

javascript <- Task.mapError Exit.ReactorBadGenerate $ Generate.dev root details artifacts
javascript <- Task.mapError Exit.ReactorBadGenerate $ Generate.prod root details artifacts
let (NE.List name _) = Build.getRootNames artifacts
return $ Html.sandwich root name javascript

Expand Down
10 changes: 7 additions & 3 deletions test/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ For more information on how to use the GHCi debugger, see the GHC User's Guide.
-- target = buildTestHarnessToProductionJs
-- target = checkProjectCompiles
-- target = previewProject
-- target = liveReloadLive
target = Test.all
target = liveReloadLive
-- target = Test.all
-- target = rerunJust "Lamdera.Evergreen.TestMigrationHarness -> .full first - (WithMigrations 2)"
-- target = checkUserConfig
-- target = Test.Wire.buildAllPackages
Expand Down Expand Up @@ -205,8 +205,12 @@ liveReloadLive = do
setEnv "LDEBUG" "1"
setEnv "EXPERIMENTAL" "1"

let p = "/Users/mario/lamdera/test/v1"
-- let p = "/Users/mario/lamdera/test/v1"
-- let p = "/Users/mario/dev/test/lamdera-init"
-- let p = "/Users/mario/dev/projects/refinable"

let p = withRuntimeRoot "test/scenario-migrations1"

-- let p = "/Users/mario/lamdera/overrides/packages/elm/bytes/1.0.8/benchmarks"

-- rmdir "/Users/mario/.elm"
Expand Down