clojurific 0.12.7 → 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 +5 -5
- package/package.json +1 -1
- package/vite-plugin-cljs/edn.js +39 -0
- package/vite-plugin-cljs/index.js +14 -26
package/README.md
CHANGED
|
@@ -28,10 +28,10 @@ Dependencies and source paths come from the project's `deps.edn`:
|
|
|
28
28
|
|
|
29
29
|
```js
|
|
30
30
|
// vite.config.mjs
|
|
31
|
-
import
|
|
31
|
+
import cljf from 'clojurific/vite';
|
|
32
32
|
|
|
33
33
|
export default {
|
|
34
|
-
plugins: [
|
|
34
|
+
plugins: [cljf({ outputDir: 'target/cljs' })],
|
|
35
35
|
};
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -57,8 +57,8 @@ npx cljf repl
|
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
`cljf repl` is a ClojureScript REPL evaluating in the pages the dev server
|
|
60
|
-
runs, through its nREPL server: `
|
|
61
|
-
compilerOptions: { repl: {
|
|
60
|
+
runs, through its nREPL server: `cljf({ outputDir: 'target/cljs',
|
|
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
|
|
@@ -87,7 +87,7 @@ npx cljf setup-java
|
|
|
87
87
|
| `CLJF_MAVEN_REPO` | a Maven Central mirror to download the dependency resolver from; other dependencies use `:mvn/repos` |
|
|
88
88
|
| `CLJF_CACHE_DIR` | where `setup-java` installs Java |
|
|
89
89
|
|
|
90
|
-
See [
|
|
90
|
+
See [README.md](https://github.com/WhimsicalCode/clojurific/blob/main/README.md) for
|
|
91
91
|
compiler options, the Vite plugin's options, the REPL and how the launcher
|
|
92
92
|
works.
|
|
93
93
|
|
package/package.json
CHANGED
|
@@ -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"
|
|
@@ -256,7 +244,7 @@ export default module.exports;
|
|
|
256
244
|
* defaults to false: only from this machine. A proxy in front of the dev
|
|
257
245
|
* server must set X-Real-IP to the client's address.
|
|
258
246
|
*/
|
|
259
|
-
export default function
|
|
247
|
+
export default function cljf(options) {
|
|
260
248
|
const manifestName = options.manifest ?? 'manifest.json';
|
|
261
249
|
let config, proc, server, minify, root, cwd, outputDir, compiler;
|
|
262
250
|
// the namespaces of the pages' scripts, compiled as main namespaces
|
|
@@ -328,8 +316,8 @@ export default function cljs(options) {
|
|
|
328
316
|
} else if (event.type === 'compiled' || event.type === 'error') {
|
|
329
317
|
compiled();
|
|
330
318
|
const logger = config?.logger ?? console;
|
|
331
|
-
if (event.type === 'error') logger.error(`[
|
|
332
|
-
else logger.info(`[
|
|
319
|
+
if (event.type === 'error') logger.error(`[cljf] ${event.message}`);
|
|
320
|
+
else logger.info(`[cljf] compiled ${event.namespaces} namespace(s) in ${event.ms}ms`);
|
|
333
321
|
if (first && event.type === 'compiled') {
|
|
334
322
|
first = false;
|
|
335
323
|
resolve();
|
|
@@ -402,7 +390,7 @@ export default function cljs(options) {
|
|
|
402
390
|
}
|
|
403
391
|
|
|
404
392
|
return {
|
|
405
|
-
name: '
|
|
393
|
+
name: 'cljf',
|
|
406
394
|
// before Vite's resolver, which would take cljs-npm-as: specifiers
|
|
407
395
|
enforce: 'pre',
|
|
408
396
|
|
|
@@ -623,7 +611,7 @@ export default function cljs(options) {
|
|
|
623
611
|
this.warn('nothing was pruned: package.json has "type": "commonjs", so the bundler treats the project\'s ' +
|
|
624
612
|
'.js files as CommonJS and wraps the ClojureScript they import in initializers. Use "type": "module".');
|
|
625
613
|
}
|
|
626
|
-
config.logger.info(`[
|
|
614
|
+
config.logger.info(`[cljf] removed ${pruned.removed} unused statements (${pruneMs}ms), ` +
|
|
627
615
|
`renamed ${Object.keys(renames).length} properties, ` +
|
|
628
616
|
`minified (${Date.now() - start - pruneMs}ms)`);
|
|
629
617
|
}
|
|
@@ -686,7 +674,7 @@ export default function cljs(options) {
|
|
|
686
674
|
// since: a reloaded page runs the output with warnings
|
|
687
675
|
let problem = null;
|
|
688
676
|
const showProblem = err => {
|
|
689
|
-
problem = { type: 'error', err: { stack: '', plugin: '
|
|
677
|
+
problem = { type: 'error', err: { stack: '', plugin: 'cljf', ...err } };
|
|
690
678
|
server.ws.send(problem);
|
|
691
679
|
};
|
|
692
680
|
server.ws.on('connection', socket => problem && socket.send(JSON.stringify(problem)));
|
|
@@ -702,14 +690,14 @@ export default function cljs(options) {
|
|
|
702
690
|
for (const name of ssrEntries) {
|
|
703
691
|
const file = info?.entries?.[name];
|
|
704
692
|
if (!file) {
|
|
705
|
-
config.logger.error(`[
|
|
693
|
+
config.logger.error(`[cljf] ssrEntries: no :js-entries ${name}`, { timestamp: true });
|
|
706
694
|
continue;
|
|
707
695
|
}
|
|
708
696
|
try {
|
|
709
697
|
await runner.import(path.join(outputDir, file));
|
|
710
698
|
ssrEntries = ssrEntries.filter(n => n !== name);
|
|
711
699
|
} catch (e) {
|
|
712
|
-
config.logger.error(`[
|
|
700
|
+
config.logger.error(`[cljf] running ${name} (${file}): ${e.stack ?? e}`, { timestamp: true });
|
|
713
701
|
}
|
|
714
702
|
}
|
|
715
703
|
};
|
|
@@ -738,7 +726,7 @@ export default function cljs(options) {
|
|
|
738
726
|
send({
|
|
739
727
|
op: 'console-result',
|
|
740
728
|
rid: data.rid,
|
|
741
|
-
result: { error: 'cljs_eval only runs in pages on the dev server\'s machine, see the
|
|
729
|
+
result: { error: 'cljs_eval only runs in pages on the dev server\'s machine, see the cljf plugin\'s replRemoteConsole' },
|
|
742
730
|
});
|
|
743
731
|
return;
|
|
744
732
|
}
|
|
@@ -829,7 +817,7 @@ export default function cljs(options) {
|
|
|
829
817
|
const outstanding = [...warnings.values()].flat();
|
|
830
818
|
if (event.type === 'compiled' && outstanding.length) {
|
|
831
819
|
const [first] = outstanding;
|
|
832
|
-
config.logger.warn(`[
|
|
820
|
+
config.logger.warn(`[cljf] compiled ${event.namespaces} namespace(s) in ${event.ms}ms, ` +
|
|
833
821
|
`hot reload paused by ${outstanding.length} warning(s)`, { timestamp: true });
|
|
834
822
|
showProblem({
|
|
835
823
|
message: outstanding
|
|
@@ -840,7 +828,7 @@ export default function cljs(options) {
|
|
|
840
828
|
});
|
|
841
829
|
ready();
|
|
842
830
|
} else if (event.type === 'compiled') {
|
|
843
|
-
config.logger.info(`[
|
|
831
|
+
config.logger.info(`[cljf] compiled ${event.namespaces} namespace(s) in ${event.ms}ms`, { timestamp: true });
|
|
844
832
|
problem = null;
|
|
845
833
|
// the namespaces held back that this compile didn't update
|
|
846
834
|
const client = server.environments.client;
|
|
@@ -850,7 +838,7 @@ export default function cljs(options) {
|
|
|
850
838
|
runSsrEntries();
|
|
851
839
|
ready();
|
|
852
840
|
} else if (event.type === 'error') {
|
|
853
|
-
config.logger.error(`[
|
|
841
|
+
config.logger.error(`[cljf] ${event.message}`, { timestamp: true });
|
|
854
842
|
showProblem({
|
|
855
843
|
message: event.message,
|
|
856
844
|
id: event.file,
|