clojurific 0.12.8 → 0.12.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -58,7 +58,7 @@ npx cljf repl
58
58
 
59
59
  `cljf repl` is a ClojureScript REPL evaluating in the pages the dev server
60
60
  runs, through its nREPL server: `cljf({ outputDir: 'target/cljs',
61
- compilerOptions: { repl: { 'nrepl-port': 0 } } })` with `nrepl/nrepl` in
61
+ compilerOptions: { repl: { nreplPort: 0 } } })` with `nrepl/nrepl` in
62
62
  `deps.edn`.
63
63
 
64
64
  `cljf` resolves `deps.edn` with tools.deps, adds the compiler, and removes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clojurific",
3
- "version": "0.12.8",
3
+ "version": "0.12.9",
4
4
  "description": "ClojureScript compiled to ES modules, bundled by Vite",
5
5
  "license": "EPL-1.0",
6
6
  "repository": {
@@ -0,0 +1,39 @@
1
+ // Compiler options given as JavaScript values, written as EDN.
2
+ //
3
+ // Object keys are keywords: camelCase keys are written in kebab-case
4
+ // (nreplPort is :nrepl-port), others as they are ('nrepl-port', ':nrepl-port').
5
+ // Strings starting with : are keywords, with ' symbols, others strings.
6
+
7
+ // The options whose map keys are names rather than options, written as they
8
+ // are: :closure-defines' (goog.DEBUG), :js-entries' entry names and their
9
+ // :exports' JavaScript names
10
+ const NAME_KEYS = new Set(['closure-defines', 'js-entries', 'exports']);
11
+
12
+ const CAMEL_CASE = /^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)+$/;
13
+
14
+ function optionKey(key) {
15
+ if (key.startsWith(':')) return key.slice(1);
16
+ return CAMEL_CASE.test(key) ? key.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`) : key;
17
+ }
18
+
19
+ function ednString(s) {
20
+ return JSON.stringify(s);
21
+ }
22
+
23
+ /**
24
+ * The EDN of a JavaScript value.
25
+ * @param {*} v
26
+ * @param {boolean} [names] v's keys are names, written as they are
27
+ * @returns {string}
28
+ */
29
+ export function ednValue(v, names = false) {
30
+ if (Array.isArray(v)) return `[${v.map(x => ednValue(x)).join(' ')}]`;
31
+ if (typeof v === 'string') return v.startsWith(':') || v.startsWith("'") ? v.replace(/^'/, '') : ednString(v);
32
+ if (v && typeof v === 'object') {
33
+ return `{${Object.entries(v).map(([k, x]) => {
34
+ const key = names ? k.replace(/^:/, '') : optionKey(k);
35
+ return `:${key} ${ednValue(x, !names && NAME_KEYS.has(key))}`;
36
+ }).join(' ')}}`;
37
+ }
38
+ return String(v);
39
+ }
@@ -15,6 +15,7 @@ import os from 'node:os';
15
15
  import { Worker } from 'node:worker_threads';
16
16
  import { compilerCommand } from '../cljf/launcher.js';
17
17
  import { pruneChunks, propertyRenames } from './prune.js';
18
+ import { ednValue } from './edn.js';
18
19
 
19
20
  const EVENT_PREFIX = '[cljf.esm] ';
20
21
  const NPM_AS = 'cljs-npm-as:';
@@ -124,19 +125,6 @@ function inputObject(input, root) {
124
125
  }));
125
126
  }
126
127
 
127
- function ednString(s) {
128
- return JSON.stringify(s);
129
- }
130
-
131
- function ednValue(v) {
132
- if (Array.isArray(v)) return `[${v.map(ednValue).join(' ')}]`;
133
- if (typeof v === 'string') return v.startsWith(':') || v.startsWith("'") ? v.replace(/^'/, '') : ednString(v);
134
- if (v && typeof v === 'object') {
135
- return `{${Object.entries(v).map(([k, x]) => `${k.startsWith(':') ? k : ':' + k} ${ednValue(x)}`).join(' ')}}`;
136
- }
137
- return String(v);
138
- }
139
-
140
128
  // oxc's minifier shipped with Rolldown, as used by Vite
141
129
  function resolveFromProject(root, specifier, purpose) {
142
130
  const tryResolve = (base, spec) => {
@@ -238,7 +226,7 @@ export default module.exports;
238
226
  * to cwd. Pages load namespaces from it, i.e. outputDir "out" serves my.app
239
227
  * as /out/my/app.js
240
228
  * @param {object|string} [options.compilerOptions] more compiler options, an
241
- * EDN string or an object with keyword keys
229
+ * EDN string or an object with keyword keys, camelCase or kebab-case
242
230
  * @param {string|false} [options.manifest] writes the entry points' scripts
243
231
  * and preloads to this file in Vite's outDir, for server rendered pages,
244
232
  * defaults to "manifest.json"