lingy

Ingy döt Net 2023-07-29T01:02:14.881029Z

I'm writing a Java to YAML transformer using my Pegex parsing library. The basic purpose is to aid in translation of clojure's java classes to other languages. Pegex in implemented fully in both Perl and JavaScript. My question here is would it be better for me to do this in JS and publish to NPM (rather than Perl and CPAN)?

Ingy döt Net 2023-07-29T01:07:20.238479Z

fwiw I'm basically converting this Java grammar https://docs.oracle.com/javase/specs/jls/se7/html/jls-18.html to Pegex. I only care that it's good enough to parse all the clojure java sources for now.

Ingy döt Net 2023-07-29T01:04:38.504119Z

Would having it on NPM make it more accessible to clojure people? I could have a clojurescript wrapper for it. Are clojurescript libaries just published to NPM? I guess there's no real point beyond me possibly learning some clojurescript.

Ingy döt Net 2023-07-29T01:05:13.197449Z

Random thoughts welcome (to my rather random queries)

hifumi123 2023-07-29T02:35:32.852399Z

i usually find clojure and cljs packages uploaded to clojars

hifumi123 2023-07-29T02:35:45.335219Z

when cljs is uploded to npm its usually some nbb script

Ingy döt Net 2023-07-29T03:40:36.527579Z

never heard of nbb

hifumi123 2023-07-29T03:47:36.826029Z

nbb = node babashka its babashka but it runs on node.js, and it lets you do ad-hoc CLJS scripting… if you have npm installed, then trying it out is as easy as running npx nbb

Ingy döt Net 2023-07-29T03:58:25.834959Z

what's npx ? :)

Ingy döt Net 2023-07-29T03:58:45.837939Z

the new npm or something?

hifumi123 2023-07-29T04:00:57.943809Z

npx is a tool for executing npm packages, built in to npm

hifumi123 2023-07-29T04:01:06.266509Z

it works like "npm run ..." but for any package

Ingy döt Net 2023-07-29T04:03:40.891609Z

can't believe I didn't know that

Ingy döt Net 2023-07-29T03:44:05.478329Z

@hifumi123 have you published stuff on clojars?

Ingy döt Net 2023-07-29T03:44:30.422089Z

and/or mavencentral?

hifumi123 2023-07-29T03:44:47.393789Z

yes to both

hifumi123 2023-07-29T03:45:23.583049Z

maven central is a lot more ceremony because you need pgp keys uploaded on a public keyserver, open a support ticket requesting access to a group id, and then finishing a challenge to get it

hifumi123 2023-07-29T03:45:42.721449Z

then deployments require you to sign the JARs with your pgp keys and what not

hifumi123 2023-07-29T03:45:56.660759Z

clojars is much more lax in that, although this is bad for security, it doesnt require pgp keys or signing anything

hifumi123 2023-07-29T03:46:16.732949Z

you just make an account and you have two group ids for free — you can get a custom group id if you own a domain name and complete an automated dns challenge IIRC

hifumi123 2023-07-29T03:46:31.314869Z

but otherwise deployment is as simple as running lein deploy, assuming you have used leiningen before

Ingy döt Net 2023-07-29T03:52:29.166839Z

I see. So source code (both clojure and java?) go to clojars, and jar files to maven? Or is it that clojure parts go to clojars and java code to maven?

Ingy döt Net 2023-07-29T03:53:36.402849Z

@hifumi123 btw I got a http://clojars.org account and a sonatype account (for maven, right?) about a year ago

Ingy döt Net 2023-07-29T03:53:59.515159Z

But yeah the pgp stuff kept me from releasing anything

Ingy döt Net 2023-07-29T03:54:23.161929Z

and I'm not sure what you mean by group ids

Ingy döt Net 2023-07-29T03:55:31.998619Z

Looks like I'm ingy on both http://clojars.org and http://sonatype.org

Ingy döt Net 2023-07-29T03:56:28.314059Z

oh huh, I guess I did upload to clojars https://clojars.org/org.clojars.ingy/ingy-prelude

hifumi123 2023-07-29T04:02:08.851359Z

re: group ids: maven by default namespaces packages. the "group id" is basically a namespace

hifumi123 2023-07-29T04:03:04.608719Z

e.g. org.clojars.ingy is one (of two) namespaces clojars gives you for free. and you can publish packages with whatever name youd like, since they will exist under this namespace that only you control

Ingy döt Net 2023-07-29T04:11:19.809759Z

I assume lein handles clojurescript as well as clojure packaging and publishing?

Ingy döt Net 2023-07-29T04:11:44.910589Z

What do Clojure people use maven for?

Ingy döt Net 2023-07-29T04:14:09.049649Z

trying to grok the matrix of multiple clojure platforms (clj and cljs) and multiple package registries (clojars and maven) and multiple assets (source and jar)

hifumi123 2023-07-29T04:20:47.015769Z

I think there is an important distinction to make between maven repositories and maven the build tool

hifumi123 2023-07-29T04:21:00.820259Z

clojure users make use of maven repositories, but not necessarily maven itself

hifumi123 2023-07-29T04:21:24.184579Z

people mostly use either leiningen or tools.deps for clojure on the jvm, and on clojurescript almost everyone uses shadow-cljs

hifumi123 2023-07-29T04:21:38.861999Z

both clojure and clojurescript tend to publish to a maven repository

hifumi123 2023-07-29T04:21:55.672649Z

in the case of clojure, most java libraries are also pushed to a maven repository (usually maven central)

hifumi123 2023-07-29T04:22:09.802759Z

for this reason, most clojure setups will default to maven central and clojars as default repositories for fetching dependencies

hifumi123 2023-07-29T04:22:19.231919Z

the vast majority of clojure/clojurescript libraries get published to clojars

hifumi123 2023-07-29T04:23:12.993959Z

in the javascript world, people tend to deploy to npm, and for that reason, shadow-cljs etc. also supports fetching dependencies from npm — this is typically meant for fetching javascript libraries rather than clojurescript libraries

hifumi123 2023-07-29T04:26:43.098719Z

if I had to simplify how this all works, I would make a table like so:

| Platform      | Repositories           | Format |
|---------------+------------------------+--------|
| Clojure       | Maven Central, Clojars | JAR    |
| ClojureScript | Maven Central, Clojars | JAR    |
| Java          | Maven Central          | JAR    |
| JavaScript    | NPM                    | TGZ    |

Ingy döt Net 2023-07-29T04:27:02.195379Z

so if I had a project with both clojure and java code, would I publish the clojure code to one place and the java to another?

hifumi123 2023-07-29T04:27:18.469839Z

if you had a project with clojure and java code, you would publish a single JAR to a maven repository

hifumi123 2023-07-29T04:27:33.697859Z

you will most likely publish to clojars since it is simpler to publish there than maven central

Ingy döt Net 2023-07-29T04:28:20.320549Z

do jars contain source and bytecode?

hifumi123 2023-07-29T04:28:39.029589Z

clojure libraries tend to be deployed as JARs with source code inside rather than classes inside

Ingy döt Net 2023-07-29T04:28:49.616539Z

ok

hifumi123 2023-07-29T04:29:20.635619Z

you can compile the java code to class files if youd like, but people typically do not compile clojure files to classes because the format may change between clojure versions

Ingy döt Net 2023-07-29T04:29:35.257019Z

ah

hifumi123 2023-07-29T04:29:38.850419Z

so for best results / best compatibility, you will typically distribute clojure code rather than compiled clojure code

hifumi123 2023-07-29T04:29:48.119699Z

i.e. you leave compilation to the user

Ingy döt Net 2023-07-29T04:29:53.454689Z

yep

Ingy döt Net 2023-07-29T04:30:16.975789Z

making a bit more sense now

Ingy döt Net 2023-07-29T04:31:44.926629Z

so clojars is a "maven" repository?

Ingy döt Net 2023-07-29T04:32:10.409319Z

when I was saying maven I meant "maven central"

Ingy döt Net 2023-07-29T04:32:38.329289Z

but that's just another maven repository it seems

Ingy döt Net 2023-07-29T04:33:31.196249Z

I guess my last question would be, What's the easiest way you know to get something on maven central?

Ingy döt Net 2023-07-29T04:33:56.535979Z

(easiest/best way to learn)

hifumi123 2023-07-29T04:39:43.651289Z

> so clojars is a “maven” repository? correct > What’s the easiest way you know to get something on maven central? personally speaking: i just avoid maven central if i can, and deploy to clojars or my own maven repos

Ingy döt Net 2023-07-29T04:40:04.613819Z

oh ok

hifumi123 2023-07-29T04:40:06.070589Z

the easiest way to deploy something for public consumption in clojure is to deploy on clojars — its less of a headache for the library maintainer and the library consumer

Ingy döt Net 2023-07-29T04:40:29.325059Z

I thought you were saying most authors publish to both

hifumi123 2023-07-29T04:40:49.371669Z

ah, no, i meant to say most clojure packages are published to clojars, with some exceptions

hifumi123 2023-07-29T04:41:00.211099Z

most of the clojure libraries you do see on maven central tend to be “first party” clojure libraries

hifumi123 2023-07-29T04:41:11.902259Z

i.e. things maintained by cognitect, such as clojure itself, core.async, core.logic, and what not

Ingy döt Net 2023-07-29T04:41:20.670919Z

great. and same for clojurescript, right?

hifumi123 2023-07-29T04:41:24.903559Z

yup

hifumi123 2023-07-29T04:41:40.062079Z

practically all of the CLJS libraries I know of are published on clojars

Ingy döt Net 2023-07-29T04:42:22.055939Z

great to know. nothing stopping me then

Ingy döt Net 2023-07-29T04:43:49.780019Z

I publish some things to npm... If i write a cljs interface for them then I can publish that to clojars?

hifumi123 2023-07-29T04:44:07.269589Z

yup

Ingy döt Net 2023-07-29T04:44:44.816889Z

hmm if that's right, then wondering if I would use a second git repo for the cljs wrapper

Ingy döt Net 2023-07-29T04:45:00.760189Z

submodules or something

hifumi123 2023-07-29T04:45:07.109939Z

well, for the cljs package, you dont need to bundle the npm deps at all

Ingy döt Net 2023-07-29T04:45:26.969019Z

it just grabs them from npm?

hifumi123 2023-07-29T04:45:35.756309Z

however, if you would like to do so anyway, you can create a deps.cljs file that contains something like this

{:npm-deps {"your-npm-library" "1.0.0"}}

hifumi123 2023-07-29T04:46:15.679649Z

well there are two ways to approach this: • you instruct ppl to run npm install stuff themselves • you add a deps.cljs file with {:npm-deps {"stuff" "1.0.0"}} inside, and CLJS will automatically fetch the npm deps for the user

Ingy döt Net 2023-07-29T04:47:14.251459Z

but either way you don't ship js files to clojars, sounds like

hifumi123 2023-07-29T05:02:15.584859Z

you can, but typically not js files from npm packages

hifumi123 2023-07-29T05:02:43.727939Z

some very old CLJS libraries may have done this + ship google closure externs (so that they can survive advanced js compiler optimizations)

hifumi123 2023-07-29T05:02:58.355649Z

but this hasnt been done since nearly everyone moved to shadow, which offers near seamless npm integration

Ingy döt Net 2023-07-29T05:05:40.563939Z

What's shadow-cljs in 10 words?

Ingy döt Net 2023-07-29T05:06:23.332809Z

I could search for all this I know, but I like hearing it from you 🙂

Ingy döt Net 2023-07-29T05:07:12.606679Z

Definitely going to be publishing stuff soon

hifumi123 2023-07-29T05:22:29.763889Z

shadow-cljs in less than 10 words: it’s a build tool for clojurescript

hifumi123 2023-07-29T05:23:43.129179Z

the longer edition: clojurescript is a language that transpiles to javascript — it leverages the google closure compiler, an optimizing compiler for javascript, to produce small and fast JS code

hifumi123 2023-07-29T05:25:53.765569Z

the pipeline from CLJS -> JS is roughly as follows: 1. code in a cljs file is parsed 2. this creates some AST 3. the cljs compiler emits specific JS code for each node of the AST 4. the JS code is organized 5. (optional) the organized JS code is sent to google closure for optimization

🙌 1
hifumi123 2023-07-29T05:26:14.778969Z

shadow-cljs covers steps 1, 4, and 5 here

hifumi123 2023-07-29T05:27:07.932899Z

it takes care of e.g. parsing npm requires, and then organizing npm code and CLJS code so that they can actually run together, and finally, it decides how to optimize npm code and cljs code