squint

janezj 2024-09-09T10:32:33.931599Z

I am playing with firebase functions. below is small example of adding doc to firestore, it works in nbb, but i am getting errors with squint run The main goal of my project is to send data from frontend to backend using transit, it works with clojure app engine. And I would like to implement same stuff with nbb and squint. First I would like to have a working code in repl (nbb repl works), and then deploy it to functions emulator, and then into cloud, I don't know how to prepare compiled output that google tools will grab all generated files (I know how Jack Rusher solved it), but in my case i am afraid that loadFile will on every run load deps and compile libs; transit. Which is not good for example how to include generated js into build [squint] Compiling CLJS file: .nbb/.cache/15b1e67a44aa6dd4bb09de2e60634b85262264cb/nbb-deps/cognitect/transit.cljs [squint] Wrote file: ~/pager/functions-cljs/dist/.nbb/.cache/15b1e67a44aa6dd4bb09de2e60634b85262264cb/nbb-deps/cognitect/transit.js But to return to squint run

npx squint run index.cljc
[squint] Running index.cljc
(node:2015510) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
~/pager/functions-cljs/dist/index.js:1
import * as squint_core from 'squint-cljs/core.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1274:20)
    at Module._compile (node:internal/modules/cjs/loader:1320:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Module._load (node:internal/modules/cjs/loader:1013:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:202:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
Node.js v18.19.1 squint.edn
{:paths ["."]
 :deps {com.cognitect/transit-cljs {:mvn/version "0.8.280"}}
 :extension ".js"
 :output-dir "dist"}
nbb.edn
{:deps {com.cognitect/transit-cljs {:mvn/version "0.8.280"}}}
deps in package.json
{
  "dependencies": {
    "firebase-admin": "^12.1.0",
    "firebase-functions": "^5.0.0",
    "squint-cljs": "^0.8.113"
  }
}
(ns index
  (:require ["firebase-functions/v2/https" :refer  [onRequest]]
            ["firebase-admin$default" :as admin]
            ["firebase-admin/firestore" :refer [getFirestore Timestamp]]
            [cognitect.transit :as t]
            [nbb.core :as nbb :refer [await]]))

(def project-id  "pager")

(comment 
  (.delete (admin/app))
  )

(admin/initializeApp #js {:projectId project-id});

(def emulator? (boolean (.-FIRESTORE_EMULATOR_HOST js/process.env)))

(when emulator?
  (println "Emulator"))

(def r (t/reader :json))
(def data "[\"^ \",\"~:emo\",\":warning:\",\"~:thr\",\"7Lxmf6zpg5sEI2dkupGv\",\"~:txt\",\"aaaa\",\"~:uid\",\"NbARSXmCc4N8pOKRSORHUHlPA1VA\",\"~:msg\",null,\"~:lon\",14.5046,\"~:lat\",46.0503,\"~:pic\",null,\"~:to\",\"NbARSXmCc4N8pOKRSORHUHlPA1VA\"]")
(def xdata (.read r  data))

(-> (getFirestore)
    (.collection "msg")
    (.add (clj->js (assoc xdata :ts (Timestamp.now))))
    (.then (fn [r] (println "ID:" (.-id r))))) 

borkdude 2024-09-09T10:53:14.018539Z

As node says:

: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

borkdude 2024-09-09T10:53:38.836519Z

You've set extension to "js"

borkdude 2024-09-09T10:53:50.224529Z

but it has to be either .mjs or you have to set type: module

borkdude 2024-09-09T10:54:20.821669Z

:deps doesn't work (yet) in squint. use transit as a JS dependency

borkdude 2024-09-09T10:54:39.697029Z

nbb.core doesn't work in squint either

janezj 2024-09-09T11:18:36.172589Z

So transit is compiled because nbb downloaded it. Now I understand.

janezj 2024-09-09T11:18:46.011399Z

I understand that nbb.core is just for nbb projects I would solve differences with reader macros.

borkdude 2024-09-09T11:19:32.429989Z

transit is a built-in dependency of nbb

✔️ 1
janezj 2024-09-09T17:37:01.500159Z

nbb and squint are so interesting and nbb compiler is so fascinating, i am writing nbb code, but always looking what squint is generating. Because i have original code in js and then nbb in squint const isEmulator = process.env.FUNCTIONS_EMULATOR === 'true'; (def emulator? (boolean (.-FIRESTORE_EMULATOR_HOST js/process.env))) var emulator_QMARK_ = squint_core.boolean$(process.env.FIRESTORE_EMULATOR_HOST); You are really building impressive stack. it looks that you are going to generate, mjs or even wasm files from cljs.

borkdude 2024-09-09T18:04:09.318819Z

thanks. nbb isn't a compiler but an interpreter. wasm isn't really on my radar.

janezj 2024-09-10T07:58:50.570769Z

I just noticed, that empty deps in nbb.edn

{:deps {}}         
prevents starting nbb repl in calva, and that bb.edn is required that calva recognizes project

borkdude 2024-09-10T08:08:14.602449Z

what is the problem you're seeing?

janezj 2024-09-10T09:35:34.141199Z

I deleted redundant dep transit-cljs from nbb.edn . After a while i restarted a repl, all stopped, jack-in complained that task uberjar is missing. then I was chasing for an hour what went wrong i found out the combination that works.

borkdude 2024-09-10T09:37:06.269679Z

what bb version do you have

borkdude 2024-09-10T09:37:14.097209Z

nbb uses bb to download dependencies

janezj 2024-09-10T22:17:29.646249Z

v1.3.191

borkdude 2024-09-11T07:39:48.398199Z

can you start nbb from the command line using e.g. npx nbb ?

janezj 2024-09-12T06:54:09.674759Z

I can't reproduce the problems anymore. ➤ nbb Welcome to nbb v1.2.192! user=> ⏎ ➤ npx nbb Welcome to nbb v1.2.192! user=> ⏎