r/programare
•
u/Lonely-Session-7643
•
3h ago
•
2
Prezită-ti afacerea/proiectul Carne JavaScript Runtime (Nim + JavaScriptCore)
Un altfel de JavaScript runtime, cu un size de ~10MB, un standard library bogat și un package manager care instalează pkgs într-un global store ~/.carne/packages. Dacă ești pe mac ai deja JSCore instalat, iar pe linux îți instalezi libjavascriptcoregtk-4.1-dev și... merge! Windows e pe listă. Am început proiectul pentru a mă distanța de NPM, drama Bun, plus că toate cele necesare sunt disponibile în ecosistemul Nim. Proiectul este modular, fixând ceva la Carne, fixez și în lumea Nim.
Carne e aici ca să înlocuiască Node, Bun și Deno, dar nu urmăresc N-API-ul, cu excepția unor alias-uri, sub un viitor --compat flag. Majoritatea modulelor din stdlibs sunt native, în pur Nim, în rest vanilla JS (posibil să mai transpilez unele encodere/decodere din stdlib Nim în JS dacă reiese că JIT-ul asamblează rapid în hot loops).
- Un standard library cu de toate (env, os, http, udp, ws, archive, db (+ORM), yaml, toml, html, sql, css, gettext, mimetype, qr, și altele)
- Posibilitatea de a scrie
.addon-uri custom (ai nevoie de Nim toolchain) - Built-in pkg manager cu un git-based Package Registry
- Tone de exemple în /examples
Documentație: https://getcarne.github.io/docs/
Ecosistem
- ConCarne, Express-like web framework, optimizat și mama lui (uite exemplu streaming ~3GB Big Buck Bunny în 4K folosind zero-copy sendfile)
- Flysystem API sandbox, atomic writes, policies, virtual disks. Inspirat după Flysystem din PHP (ceva de genul am și pe Nim)
- i18n, bazat pe
std/gettext - logs, log-uri structurate, nimic interesant!
- GitHub Action, un action reutilizabil (nepublicat încă) de GitHub ca să poți rula teste
Usage
A JavaScript runtime in Nim
(c) OpenPeeps | MIT License
Build Version: 0.1.7
usage: carne <command> [args] [options]
Scripting:
run <script.js> [args] run a .js file (script args pass through verbatim)
test [file] [...] run tests/**/*.test.js (or the given file)
build <input.nim> <output> compile a native addon (.addon)
--release optimized build (-d:release)
Standard library:
std init download JS stdlib (std/*) into ~/.carne/std
std update refresh all JS stdlib files
std list show installed JS stdlib version and files
Packages:
pkg init [dir] scaffold a new package (wizard, -Y skips it)
--yes, -Y skip the wizard, use defaults
pkg install <spec> install a package by name, git URL, gh:user/repo alias, name#ref, or name + source URL
--url:<url> pin a source URL
pkg remove <name> [ver] uninstall one version, or all
--yes skip confirmation prompts
pkg update [name] update one package, or all
pkg list list installed packages
pkg develop [path] editable install from a local directory
pkg prune remove orphaned packages
--yes skip confirmation prompts
pkg refresh re-download registry data
pkg publish open a PR adding this package to the registry
--tags:<list> comma-separated tags
--web:<url> package website URL
--url:<url> pin a source URL
--dry-run no network, git, or secret changes
--yes skip confirmation prompts
Generating:
gen docs generate API reference into carnedocs/ (JSON and/or HTML)
--format:<json|html|all> docs output selection (default: all)
--out:<dir> docs output directory (default: carnedocs)
--entry:<file> document one file instead of the whole package
gen ast <file> dump the JavaScript AST of <file> (JSON or binary .ast)
--format:<json|bin> ast output selection (default: json)
--out:<dir> ast output directory (default: alongside the input)
gen addon <dir> scaffold a native addon project in <dir>
Versioning:
bump [semver] bump version in package.json (or a direct dep)
--level:<level> major, minor, or patch
--dep:<name> bump a direct dependency spec (prefix kept)
upgrade [version] self-update carne from GitHub releases (into ~/.carne/bin)
--dry-run print resolved URLs only, no changes
Inspect:
dump [pkg[@ref]] print package.json (cwd or an installed package)
options:
--isatty:<true|false> override TTY detection (default: auto-detect)
-h, --help show this help
--version show version
Benchmark-uri
Cu wrk -t4 -c100 -d10s
Runtime Requests/sec Avg latency Max RSS
carne 91330.44 1.15ms 10.9 MB
carne-workers 144029.68 739.70us 28.3 MB
node 38576.69 2.71ms 61.5 MB
bun 86878.46 1.15ms 31.1 MB
Asta e aici doar asa, de figuri, de dragul JIT-ului. Vezi în /bench
Benchmark carne node bun
fib_recursive 42.4 ms +- 0.5 85.1 ms +- 1.1 45.5 ms +- 1.0
nested_loops 9.3 ms +- 0.4 36.3 ms +- 0.7 11.9 ms +- 0.4
prime_sieve 9.2 ms +- 0.3 35.0 ms +- 0.5 11.7 ms +- 0.3
string_concat 9.4 ms +- 0.3 34.5 ms +- 0.5 11.7 ms +- 0.7
tail_recursive 9.7 ms +- 0.3 CRASHED 11.8 ms +- 0.3
range_sum 38.4 ms +- 0.4 43.8 ms +- 0.4 19.6 ms +- 0.3
collatz 51.1 ms +- 0.4 69.5 ms +- 0.7 53.4 ms +- 2.3
array_sum 14.6 ms +- 0.5 40.7 ms +- 0.9 16.8 ms +- 0.3
bubble_sort 11.8 ms +- 0.3 36.7 ms +- 0.4 14.5 ms +- 0.3
object_access 11.3 ms +- 0.3 36.9 ms +- 0.4 14.0 ms +- 0.3
float_math 12.9 ms +- 0.3 39.1 ms +- 1.0 16.5 ms +- 0.4
call_overhead 10.4 ms +- 0.2 35.5 ms +- 0.4 12.5 ms +- 0.3
fizzbuzz_count 43.8 ms +- 0.4 64.8 ms +- 0.6 38.3 ms +- 0.4
0.1.7 e disponibil în /releases, un puști este primul contribuitor! Hai și tu cu idei/feedback, și de ce nu package-uri în ecosistemul Carne!
Flag: experimental project, luați cu pâine! :))
7
u/Tall-Wasabi5030 3h ago
E drop in replacement pentru npm și bun?
8
u/Traditional-Duty-327 3h ago
Ceva legat de programare pe sub-ul ăsta? Unde te crezi, pe r/programare?
-1
u/DraculitzaMuista 3h ago
chat fa mi un rezumat in 3 randuri ce e asta si de ce as folosi