clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2020-10-29T00:16:11.368600Z

Thank you, that was the other one I was considering too 🙂

Markus Str 2020-10-29T12:05:35.373700Z

Is there a canonical way to develop and test browser extensions with cljs? We're currently using chromex+shadow-cljs to develop and tests+puppeter to mock the browser; but that's still very far away from REPL-driven dev

Markus Str 2020-10-30T14:57:24.425100Z

ahh I see. Will give it a look - thanks for the pointer

unbalanced 2020-10-29T13:53:03.374Z

Are you testing the browser APIs or just the effect on the web page?

unbalanced 2020-10-29T13:53:38.374200Z

This isn't a canonical answer by any stretch but boy do I get a ton of mileage of chrepl: https://www.chrepl.app/

🔥 1
unbalanced 2020-10-29T13:54:25.374400Z

You can at least test most of the logic you would need on a page. I don't think it gives you access to the browser APIs but I'm not sure

unbalanced 2020-10-29T13:54:35.374600Z

Figwheel, though, I think

dnolen 2020-10-29T14:16:12.375600Z

@strasser.ms couldn't you make a REPL server that runs in the extension?

dnolen 2020-10-29T14:16:53.376200Z

if you focus on the core functionality this is not that hard to implement - you can improve it later.

Markus Str 2020-10-29T14:36:43.376500Z

Thank you! We currently use #dirac for that and it's great so far. You're right if we separate the concerns about 80% is repl-able

Markus Str 2020-10-29T14:37:55.378Z

Yes, we have a REPL in the chrome developer console running (dirac); it's just annoying to always have to reload the page when you recompile the extension code. If we developed our new code directly in the REPL it would work, but then we don't get the nice IDE features ofc

Markus Str 2020-10-29T14:38:06.378200Z

ahh the trade-offs 🙂

dnolen 2020-10-29T14:43:11.378500Z

I mean REPL server that runs inside the extension

dnolen 2020-10-29T14:43:20.378800Z

then you would get a REPL driven dev

dnolen 2020-10-29T14:43:40.379100Z

this is not as complicated as it sounds

dnolen 2020-10-29T14:43:58.379600Z

you get JavaScript from ClojureScript over a connection - and you eval - that's almost all there is too it

2020-10-29T15:41:44.381900Z

@strasser.ms a few years back when I was developing a chrome extension in cljs figwheel worked for me to do live code update on code changes, the only problem was with content scripts

Markus Str 2020-10-29T15:52:36.385300Z

@dnolen thanks yes I think that's what we have since today! (intellij remote REPL where dirac has access to namespace) @darwin that's a good setup yes. We got the same hot reloading working now with #shadow-cljs. So yes, the only problem left is the content-script - for every change in there we have to reload the page. We're currently setting up a headless chrome with Puppeter for that; will report back how it works

Markus Str 2020-10-30T14:57:57.425300Z

Yes that seems to be it

Markus Str 2020-10-30T15:04:25.425900Z

@posobin have you found a way to reload to background script on file save? So that you don't have to reload the tab/extension?

Gleb Posobin 2020-10-30T17:18:49.435100Z

Background script does get reloaded for me on save.

1
dnolen 2020-10-29T15:54:44.385600Z

ah, sorry wasn't clear from what you said earlier that the issue was more specific

Markus Str 2020-10-29T15:56:13.385800Z

my bad; thanks for your help

2020-10-29T15:57:19.386Z

not sure if this article is still relevant: https://medium.com/@wilkerlucio/setting-up-figwheel-for-chrome-extensions-content-scripts-f1631d8e782a

cap10morgan 2020-10-29T17:27:11.387700Z

I have a webworker entrypoint in a target bundle project, but I'm not sure what the right way to configure the build is since :bundle and :webworker are different values of the :target key. It seems like I need to combine the two. Anyone have experience with this?

Markus Str 2020-10-29T17:29:16.387800Z

will try that out. Thank you!

unbalanced 2020-10-29T17:58:33.389800Z

encountering a... situation. When stringifying this json file, what would you expect the resulting javascript object to be (in ClojureScript)?

{"@testing-library/react": "^9.3.2",
 "react": "^16.13.1"}
for me it is
#js {:react "^9.3.2"}
and that's turning out to be rather problematic

unbalanced 2020-10-29T18:01:11.391Z

this is node, btw. Relevant code:

(-> (str cwd "/" app-name "/package.json")
     fs-read-file!
     <p!
     .toString
      js/JSON.parse)
does anyone have any suggestions for alternatives to js/JSON.parse that won't trash the keys or perhaps leave them as strings?

lilactown 2020-10-29T18:02:19.391600Z

Is the result of .toString correct?

lilactown 2020-10-29T18:03:26.392300Z

Try logging that out

orestis 2020-10-30T18:50:45.438400Z

I still can’t see how reading a file and getting back a buffer would do any JSON processing let alone trample data :thinking_face:

unbalanced 2020-10-29T18:46:38.392800Z

actually seems like it's a problem even when it's just at fs-read-file!, which is just

(def fs-read-file! (promisify (.-readFile fs)))

unbalanced 2020-10-29T18:46:51.393Z

=> #object[Buffer {
  "eslintConfig": {
    "extends": "react-app"
  },
  "private": true,
  "name": "myapp",
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "run-scripts test:unit test:lint test:build",
    "eject": "react-scripts eject",
    "test:build": "run-scripts build",
    "test:lint": "eslint .",
    "test:unit": "cross-env CI=1 react-scripts test --env=jsdom",
    "test:watch": "react-scripts test --env=jsdom"
  },
  "registry": "<https://artifacts.rackspace.net/artifactory/api/npm/sbdevs-npm-local/>",
  "access": "public",
  "version": "0.1.0",
  "browserslist": {
    "production": [
      "&gt;0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "dependencies": {
    "eslint-config-standard-react": "^9.2.0",
    "react-cron-generator": "^1.2.6",
    "eslint-plugin-import": "^2.18.2",
    "babel-eslint": "^10.0.3",
    "react": "^9.3.2",
    "cypress": "^4.12.0",
    "eslint-plugin-node": "^11.0.0",
    "typescript": "^4.0.2",
    "react-redux": "^7.1.3",
    "eslint-config-prettier": "^6.7.0",
    "eslint-config-standard": "^14.1.0",
    "user-event": "^7.1.2",
    "cross-env": "^7.0.2",
    "antd": "^4.5.2",
    "prettier": "^2.0.4",
    "react-icons": "^3.10.0",
    "react-scripts": "3.4.3",
    "eslint-plugin-standard": "^4.0.1",
    "run-scripts": "^0.4.0",
    "eslint": "^6.8.0",
    "react-dom": "^16.13.1",
    "jest-dom": "^4.2.4",
    "toolkit": "^1.1.0",
    "eslint-plugin-react": "^7.17.0",
    "eslint-plugin-promise": "^4.2.1",
    "react-moment": "^0.9.7",
    "eslint-plugin-prettier": "^3.1.1"
  }
}]

unbalanced 2020-10-29T18:47:03.393200Z

notice that the keys are already trashed

unbalanced 2020-10-29T18:47:10.393400Z

fascinating

orestis 2020-10-29T18:49:04.394Z

Are you sure you’re reading the correct file?

unbalanced 2020-10-29T18:50:11.394200Z

100% sure. original file:

{
  "name": "myapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@reduxjs/toolkit": "^1.1.0",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "antd": "^4.5.2",
    "babel-eslint": "^10.0.3",
    "cross-env": "^7.0.2",
    "cypress": "^4.12.0",
    "eslint": "^6.8.0",
    "eslint-config-prettier": "^6.7.0",
    "eslint-config-standard": "^14.1.0",
    "eslint-config-standard-react": "^9.2.0",
    "eslint-plugin-import": "^2.18.2",
    "eslint-plugin-node": "^11.0.0",
    "eslint-plugin-prettier": "^3.1.1",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-react": "^7.17.0",
    "eslint-plugin-standard": "^4.0.1",
    "prettier": "^2.0.4",
    "react": "^16.13.1",
    "react-cron-generator": "^1.2.6",
    "react-dom": "^16.13.1",
    "react-icons": "^3.10.0",
    "react-moment": "^0.9.7",
    "react-redux": "^7.1.3",
    "react-scripts": "3.4.3",
    "run-scripts": "^0.4.0",
    "typescript": "^4.0.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "run-scripts test:unit test:lint test:build",
    "eject": "react-scripts eject",
    "test:build": "run-scripts build",
    "test:lint": "eslint .",
    "test:unit": "cross-env CI=1 react-scripts test --env=jsdom",
    "test:watch": "react-scripts test --env=jsdom"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      "&gt;0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "access": "public"
}

unbalanced 2020-10-29T18:51:09.394500Z

ugh hang on

unbalanced 2020-10-29T18:51:12.394700Z

copy/paste problems

unbalanced 2020-10-29T18:52:44.395200Z

fixed.

unbalanced 2020-10-29T18:53:34.395400Z

The key details is "react" and "@testing-library/react" get trashed, with the former losing the "namespace qualifier" or whatever and overwriting "react"

unbalanced 2020-10-29T18:54:10.395600Z

I'll try a different tool for reading files and see if that goes better

unbalanced 2020-10-29T19:14:33.395800Z

interesting. same problem with a different tool

unbalanced 2020-10-29T19:23:59.396Z

this most excellent library did the trick: https://github.com/pkpkpk/cljs-node-io

unbalanced 2020-10-29T19:24:44.396700Z

thank you @pkpkpk, whoever you are. for solving my problem ☝️ https://github.com/pkpkpk/cljs-node-io

unbalanced 2020-10-29T19:51:48.396800Z

I just want to clarify, chrepl is very different. It lets you use the repl from your editor

unbalanced 2020-10-29T19:52:04.397Z

And you can load in arbitrary libraries or an arbitrary project.

unbalanced 2020-10-29T19:52:24.397200Z

It's like developing your own page but... using someone else's html/css. It works on any webpage, not just the page you are developing