clojurific 0.0.0-stage → 0.12.2
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/LICENSE.html +261 -0
- package/README.md +86 -2
- package/cljf/bootstrap.js +69 -0
- package/cljf/cli.js +99 -0
- package/cljf/errors.js +8 -0
- package/cljf/files.js +96 -0
- package/cljf/java.js +227 -0
- package/cljf/launcher.js +157 -0
- package/cljf/resolver/clojurific/resolve.clj +93 -0
- package/cljf/resolver/deps.edn +10 -0
- package/cljf/resolver.lock.json +48 -0
- package/karma-esm/adapter.js +22 -0
- package/no-clojurescript/deps.edn +1 -0
- package/package.json +38 -4
- package/vite-plugin-cljs/index.js +762 -0
- package/vite-plugin-cljs/prune-worker.js +19 -0
- package/vite-plugin-cljs/prune.js +238 -0
package/LICENSE.html
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
|
|
7
|
+
<title>Eclipse Public License - Version 1.0</title>
|
|
8
|
+
<style type="text/css">
|
|
9
|
+
body {
|
|
10
|
+
size: 8.5in 11.0in;
|
|
11
|
+
margin: 0.25in 0.5in 0.25in 0.5in;
|
|
12
|
+
tab-interval: 0.5in;
|
|
13
|
+
}
|
|
14
|
+
p {
|
|
15
|
+
margin-left: auto;
|
|
16
|
+
margin-top: 0.5em;
|
|
17
|
+
margin-bottom: 0.5em;
|
|
18
|
+
}
|
|
19
|
+
p.list {
|
|
20
|
+
margin-left: 0.5in;
|
|
21
|
+
margin-top: 0.05em;
|
|
22
|
+
margin-bottom: 0.05em;
|
|
23
|
+
}
|
|
24
|
+
</style>
|
|
25
|
+
|
|
26
|
+
</head>
|
|
27
|
+
|
|
28
|
+
<body lang="EN-US">
|
|
29
|
+
|
|
30
|
+
<p align=center><b>Eclipse Public License - v 1.0</b></p>
|
|
31
|
+
|
|
32
|
+
<p>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
|
|
33
|
+
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
|
|
34
|
+
DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
|
|
35
|
+
AGREEMENT.</p>
|
|
36
|
+
|
|
37
|
+
<p><b>1. DEFINITIONS</b></p>
|
|
38
|
+
|
|
39
|
+
<p>"Contribution" means:</p>
|
|
40
|
+
|
|
41
|
+
<p class="list">a) in the case of the initial Contributor, the initial
|
|
42
|
+
code and documentation distributed under this Agreement, and</p>
|
|
43
|
+
<p class="list">b) in the case of each subsequent Contributor:</p>
|
|
44
|
+
<p class="list">i) changes to the Program, and</p>
|
|
45
|
+
<p class="list">ii) additions to the Program;</p>
|
|
46
|
+
<p class="list">where such changes and/or additions to the Program
|
|
47
|
+
originate from and are distributed by that particular Contributor. A
|
|
48
|
+
Contribution 'originates' from a Contributor if it was added to the
|
|
49
|
+
Program by such Contributor itself or anyone acting on such
|
|
50
|
+
Contributor's behalf. Contributions do not include additions to the
|
|
51
|
+
Program which: (i) are separate modules of software distributed in
|
|
52
|
+
conjunction with the Program under their own license agreement, and (ii)
|
|
53
|
+
are not derivative works of the Program.</p>
|
|
54
|
+
|
|
55
|
+
<p>"Contributor" means any person or entity that distributes
|
|
56
|
+
the Program.</p>
|
|
57
|
+
|
|
58
|
+
<p>"Licensed Patents" mean patent claims licensable by a
|
|
59
|
+
Contributor which are necessarily infringed by the use or sale of its
|
|
60
|
+
Contribution alone or when combined with the Program.</p>
|
|
61
|
+
|
|
62
|
+
<p>"Program" means the Contributions distributed in accordance
|
|
63
|
+
with this Agreement.</p>
|
|
64
|
+
|
|
65
|
+
<p>"Recipient" means anyone who receives the Program under
|
|
66
|
+
this Agreement, including all Contributors.</p>
|
|
67
|
+
|
|
68
|
+
<p><b>2. GRANT OF RIGHTS</b></p>
|
|
69
|
+
|
|
70
|
+
<p class="list">a) Subject to the terms of this Agreement, each
|
|
71
|
+
Contributor hereby grants Recipient a non-exclusive, worldwide,
|
|
72
|
+
royalty-free copyright license to reproduce, prepare derivative works
|
|
73
|
+
of, publicly display, publicly perform, distribute and sublicense the
|
|
74
|
+
Contribution of such Contributor, if any, and such derivative works, in
|
|
75
|
+
source code and object code form.</p>
|
|
76
|
+
|
|
77
|
+
<p class="list">b) Subject to the terms of this Agreement, each
|
|
78
|
+
Contributor hereby grants Recipient a non-exclusive, worldwide,
|
|
79
|
+
royalty-free patent license under Licensed Patents to make, use, sell,
|
|
80
|
+
offer to sell, import and otherwise transfer the Contribution of such
|
|
81
|
+
Contributor, if any, in source code and object code form. This patent
|
|
82
|
+
license shall apply to the combination of the Contribution and the
|
|
83
|
+
Program if, at the time the Contribution is added by the Contributor,
|
|
84
|
+
such addition of the Contribution causes such combination to be covered
|
|
85
|
+
by the Licensed Patents. The patent license shall not apply to any other
|
|
86
|
+
combinations which include the Contribution. No hardware per se is
|
|
87
|
+
licensed hereunder.</p>
|
|
88
|
+
|
|
89
|
+
<p class="list">c) Recipient understands that although each Contributor
|
|
90
|
+
grants the licenses to its Contributions set forth herein, no assurances
|
|
91
|
+
are provided by any Contributor that the Program does not infringe the
|
|
92
|
+
patent or other intellectual property rights of any other entity. Each
|
|
93
|
+
Contributor disclaims any liability to Recipient for claims brought by
|
|
94
|
+
any other entity based on infringement of intellectual property rights
|
|
95
|
+
or otherwise. As a condition to exercising the rights and licenses
|
|
96
|
+
granted hereunder, each Recipient hereby assumes sole responsibility to
|
|
97
|
+
secure any other intellectual property rights needed, if any. For
|
|
98
|
+
example, if a third party patent license is required to allow Recipient
|
|
99
|
+
to distribute the Program, it is Recipient's responsibility to acquire
|
|
100
|
+
that license before distributing the Program.</p>
|
|
101
|
+
|
|
102
|
+
<p class="list">d) Each Contributor represents that to its knowledge it
|
|
103
|
+
has sufficient copyright rights in its Contribution, if any, to grant
|
|
104
|
+
the copyright license set forth in this Agreement.</p>
|
|
105
|
+
|
|
106
|
+
<p><b>3. REQUIREMENTS</b></p>
|
|
107
|
+
|
|
108
|
+
<p>A Contributor may choose to distribute the Program in object code
|
|
109
|
+
form under its own license agreement, provided that:</p>
|
|
110
|
+
|
|
111
|
+
<p class="list">a) it complies with the terms and conditions of this
|
|
112
|
+
Agreement; and</p>
|
|
113
|
+
|
|
114
|
+
<p class="list">b) its license agreement:</p>
|
|
115
|
+
|
|
116
|
+
<p class="list">i) effectively disclaims on behalf of all Contributors
|
|
117
|
+
all warranties and conditions, express and implied, including warranties
|
|
118
|
+
or conditions of title and non-infringement, and implied warranties or
|
|
119
|
+
conditions of merchantability and fitness for a particular purpose;</p>
|
|
120
|
+
|
|
121
|
+
<p class="list">ii) effectively excludes on behalf of all Contributors
|
|
122
|
+
all liability for damages, including direct, indirect, special,
|
|
123
|
+
incidental and consequential damages, such as lost profits;</p>
|
|
124
|
+
|
|
125
|
+
<p class="list">iii) states that any provisions which differ from this
|
|
126
|
+
Agreement are offered by that Contributor alone and not by any other
|
|
127
|
+
party; and</p>
|
|
128
|
+
|
|
129
|
+
<p class="list">iv) states that source code for the Program is available
|
|
130
|
+
from such Contributor, and informs licensees how to obtain it in a
|
|
131
|
+
reasonable manner on or through a medium customarily used for software
|
|
132
|
+
exchange.</p>
|
|
133
|
+
|
|
134
|
+
<p>When the Program is made available in source code form:</p>
|
|
135
|
+
|
|
136
|
+
<p class="list">a) it must be made available under this Agreement; and</p>
|
|
137
|
+
|
|
138
|
+
<p class="list">b) a copy of this Agreement must be included with each
|
|
139
|
+
copy of the Program.</p>
|
|
140
|
+
|
|
141
|
+
<p>Contributors may not remove or alter any copyright notices contained
|
|
142
|
+
within the Program.</p>
|
|
143
|
+
|
|
144
|
+
<p>Each Contributor must identify itself as the originator of its
|
|
145
|
+
Contribution, if any, in a manner that reasonably allows subsequent
|
|
146
|
+
Recipients to identify the originator of the Contribution.</p>
|
|
147
|
+
|
|
148
|
+
<p><b>4. COMMERCIAL DISTRIBUTION</b></p>
|
|
149
|
+
|
|
150
|
+
<p>Commercial distributors of software may accept certain
|
|
151
|
+
responsibilities with respect to end users, business partners and the
|
|
152
|
+
like. While this license is intended to facilitate the commercial use of
|
|
153
|
+
the Program, the Contributor who includes the Program in a commercial
|
|
154
|
+
product offering should do so in a manner which does not create
|
|
155
|
+
potential liability for other Contributors. Therefore, if a Contributor
|
|
156
|
+
includes the Program in a commercial product offering, such Contributor
|
|
157
|
+
("Commercial Contributor") hereby agrees to defend and
|
|
158
|
+
indemnify every other Contributor ("Indemnified Contributor")
|
|
159
|
+
against any losses, damages and costs (collectively "Losses")
|
|
160
|
+
arising from claims, lawsuits and other legal actions brought by a third
|
|
161
|
+
party against the Indemnified Contributor to the extent caused by the
|
|
162
|
+
acts or omissions of such Commercial Contributor in connection with its
|
|
163
|
+
distribution of the Program in a commercial product offering. The
|
|
164
|
+
obligations in this section do not apply to any claims or Losses
|
|
165
|
+
relating to any actual or alleged intellectual property infringement. In
|
|
166
|
+
order to qualify, an Indemnified Contributor must: a) promptly notify
|
|
167
|
+
the Commercial Contributor in writing of such claim, and b) allow the
|
|
168
|
+
Commercial Contributor to control, and cooperate with the Commercial
|
|
169
|
+
Contributor in, the defense and any related settlement negotiations. The
|
|
170
|
+
Indemnified Contributor may participate in any such claim at its own
|
|
171
|
+
expense.</p>
|
|
172
|
+
|
|
173
|
+
<p>For example, a Contributor might include the Program in a commercial
|
|
174
|
+
product offering, Product X. That Contributor is then a Commercial
|
|
175
|
+
Contributor. If that Commercial Contributor then makes performance
|
|
176
|
+
claims, or offers warranties related to Product X, those performance
|
|
177
|
+
claims and warranties are such Commercial Contributor's responsibility
|
|
178
|
+
alone. Under this section, the Commercial Contributor would have to
|
|
179
|
+
defend claims against the other Contributors related to those
|
|
180
|
+
performance claims and warranties, and if a court requires any other
|
|
181
|
+
Contributor to pay any damages as a result, the Commercial Contributor
|
|
182
|
+
must pay those damages.</p>
|
|
183
|
+
|
|
184
|
+
<p><b>5. NO WARRANTY</b></p>
|
|
185
|
+
|
|
186
|
+
<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
|
|
187
|
+
PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
|
|
188
|
+
OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
|
|
189
|
+
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
|
|
190
|
+
OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
|
|
191
|
+
responsible for determining the appropriateness of using and
|
|
192
|
+
distributing the Program and assumes all risks associated with its
|
|
193
|
+
exercise of rights under this Agreement , including but not limited to
|
|
194
|
+
the risks and costs of program errors, compliance with applicable laws,
|
|
195
|
+
damage to or loss of data, programs or equipment, and unavailability or
|
|
196
|
+
interruption of operations.</p>
|
|
197
|
+
|
|
198
|
+
<p><b>6. DISCLAIMER OF LIABILITY</b></p>
|
|
199
|
+
|
|
200
|
+
<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
|
|
201
|
+
NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
|
|
202
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
|
|
203
|
+
WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
|
|
204
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
205
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
|
|
206
|
+
DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
|
|
207
|
+
HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p>
|
|
208
|
+
|
|
209
|
+
<p><b>7. GENERAL</b></p>
|
|
210
|
+
|
|
211
|
+
<p>If any provision of this Agreement is invalid or unenforceable under
|
|
212
|
+
applicable law, it shall not affect the validity or enforceability of
|
|
213
|
+
the remainder of the terms of this Agreement, and without further action
|
|
214
|
+
by the parties hereto, such provision shall be reformed to the minimum
|
|
215
|
+
extent necessary to make such provision valid and enforceable.</p>
|
|
216
|
+
|
|
217
|
+
<p>If Recipient institutes patent litigation against any entity
|
|
218
|
+
(including a cross-claim or counterclaim in a lawsuit) alleging that the
|
|
219
|
+
Program itself (excluding combinations of the Program with other
|
|
220
|
+
software or hardware) infringes such Recipient's patent(s), then such
|
|
221
|
+
Recipient's rights granted under Section 2(b) shall terminate as of the
|
|
222
|
+
date such litigation is filed.</p>
|
|
223
|
+
|
|
224
|
+
<p>All Recipient's rights under this Agreement shall terminate if it
|
|
225
|
+
fails to comply with any of the material terms or conditions of this
|
|
226
|
+
Agreement and does not cure such failure in a reasonable period of time
|
|
227
|
+
after becoming aware of such noncompliance. If all Recipient's rights
|
|
228
|
+
under this Agreement terminate, Recipient agrees to cease use and
|
|
229
|
+
distribution of the Program as soon as reasonably practicable. However,
|
|
230
|
+
Recipient's obligations under this Agreement and any licenses granted by
|
|
231
|
+
Recipient relating to the Program shall continue and survive.</p>
|
|
232
|
+
|
|
233
|
+
<p>Everyone is permitted to copy and distribute copies of this
|
|
234
|
+
Agreement, but in order to avoid inconsistency the Agreement is
|
|
235
|
+
copyrighted and may only be modified in the following manner. The
|
|
236
|
+
Agreement Steward reserves the right to publish new versions (including
|
|
237
|
+
revisions) of this Agreement from time to time. No one other than the
|
|
238
|
+
Agreement Steward has the right to modify this Agreement. The Eclipse
|
|
239
|
+
Foundation is the initial Agreement Steward. The Eclipse Foundation may
|
|
240
|
+
assign the responsibility to serve as the Agreement Steward to a
|
|
241
|
+
suitable separate entity. Each new version of the Agreement will be
|
|
242
|
+
given a distinguishing version number. The Program (including
|
|
243
|
+
Contributions) may always be distributed subject to the version of the
|
|
244
|
+
Agreement under which it was received. In addition, after a new version
|
|
245
|
+
of the Agreement is published, Contributor may elect to distribute the
|
|
246
|
+
Program (including its Contributions) under the new version. Except as
|
|
247
|
+
expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
|
|
248
|
+
rights or licenses to the intellectual property of any Contributor under
|
|
249
|
+
this Agreement, whether expressly, by implication, estoppel or
|
|
250
|
+
otherwise. All rights in the Program not expressly granted under this
|
|
251
|
+
Agreement are reserved.</p>
|
|
252
|
+
|
|
253
|
+
<p>This Agreement is governed by the laws of the State of New York and
|
|
254
|
+
the intellectual property laws of the United States of America. No party
|
|
255
|
+
to this Agreement will bring a legal action under this Agreement more
|
|
256
|
+
than one year after the cause of action arose. Each party waives its
|
|
257
|
+
rights to a jury trial in any resulting litigation.</p>
|
|
258
|
+
|
|
259
|
+
</body>
|
|
260
|
+
|
|
261
|
+
</html>
|
package/README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# clojurific
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ClojureScript compiled to ES modules, bundled by Vite.
|
|
4
|
+
|
|
5
|
+
[Clojurific](https://github.com/WhimsicalCode/clojurific) is a fork of
|
|
6
|
+
ClojureScript whose `:module-format :esm` compiles every namespace to an ES
|
|
7
|
+
module, leaving bundling, minification, npm packages and TypeScript to Vite,
|
|
8
|
+
without the Google Closure Compiler. This package has the `cljf` command, a
|
|
9
|
+
Vite plugin with hot reloading, and a Karma adapter; `cljf` gets the compiler,
|
|
10
|
+
`com.whimsical/clojurific`, from Clojars. It needs
|
|
11
|
+
Node.js 20 or later and Java 17 or later, not the Clojure CLI.
|
|
12
|
+
|
|
13
|
+
Status: experimental. Versions are `0.<minor>.<release>`: `<minor>` is the
|
|
14
|
+
ClojureScript 1.x release it's compatible with (12 for 1.12.x), `<release>`
|
|
15
|
+
counts Clojurific's releases, starting from 1.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Dependencies and source paths come from the project's `deps.edn`:
|
|
20
|
+
|
|
21
|
+
```clojure
|
|
22
|
+
{:paths ["src"]
|
|
23
|
+
:deps {reagent/reagent {:mvn/version "2.0.1"}}}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
// vite.config.mjs
|
|
28
|
+
import cljs from 'clojurific/vite';
|
|
29
|
+
|
|
30
|
+
export default {
|
|
31
|
+
plugins: [cljs({ outputDir: 'target/cljs' })],
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```html
|
|
36
|
+
<!-- index.html -->
|
|
37
|
+
<!doctype html>
|
|
38
|
+
<div id="app"></div>
|
|
39
|
+
<script type="module" src="/src/my/app.cljs"></script>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`npx vite` serves the page and hot reloads changed namespaces, `npx vite build`
|
|
43
|
+
bundles it into `dist/`. JavaScript can import namespaces too:
|
|
44
|
+
`import './my/app.cljs'`. The project's `package.json` needs `"type":
|
|
45
|
+
"module"`.
|
|
46
|
+
|
|
47
|
+
or with the command line:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
npx cljf build '{:main my.app :output-dir "out"}'
|
|
51
|
+
npx cljf -A:test watch @cljs.edn
|
|
52
|
+
npx cljf classpath
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`cljf` resolves `deps.edn` with tools.deps, adds the compiler, and removes
|
|
56
|
+
stock ClojureScript (`org.clojure/clojurescript`) that libraries depend on.
|
|
57
|
+
Dependencies are downloaded into `~/.m2/repository`, which the Clojure CLI
|
|
58
|
+
shares, and the classpath is cached in `.cljf/` until `deps.edn` changes.
|
|
59
|
+
|
|
60
|
+
## Java
|
|
61
|
+
|
|
62
|
+
`cljf` uses `CLJF_JAVA`, `JAVA_HOME` or `java` on `PATH`. Without Java 17 or
|
|
63
|
+
later it explains how to install one, or downloads Eclipse Temurin into its
|
|
64
|
+
own cache:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
npx cljf setup-java
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`CLJF_INSTALL_JDK=1` does that without asking, i.e. in CI.
|
|
71
|
+
|
|
72
|
+
## Configuration
|
|
73
|
+
|
|
74
|
+
| Variable | |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `CLJF_JAVA` | the `java` binary to use |
|
|
77
|
+
| `CLJF_INSTALL_JDK=1` | install Java with `setup-java` when there's none |
|
|
78
|
+
| `CLJF_MAVEN_REPO` | a Maven Central mirror to download the dependency resolver from; other dependencies use `:mvn/repos` |
|
|
79
|
+
| `CLJF_CACHE_DIR` | where `setup-java` installs Java |
|
|
80
|
+
|
|
81
|
+
See [ESM.md](https://github.com/WhimsicalCode/clojurific/blob/main/ESM.md) for
|
|
82
|
+
compiler options, the Vite plugin's options, the REPL and how the launcher
|
|
83
|
+
works.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
Eclipse Public License 1.0, like ClojureScript.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// The resolver's classpath: tools.deps resolves the project's dependencies,
|
|
2
|
+
// but can't download itself. Its jars are listed in resolver.lock.json with
|
|
3
|
+
// their SHA-256, and downloaded into the local Maven repository, where the
|
|
4
|
+
// Clojure CLI's are reused.
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { LauncherError } from './errors.js';
|
|
9
|
+
import { download, sha256File } from './files.js';
|
|
10
|
+
|
|
11
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
|
|
13
|
+
export const resolverDir = path.join(here, 'resolver');
|
|
14
|
+
|
|
15
|
+
export function readLock(file = path.join(here, 'resolver.lock.json')) {
|
|
16
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function inParallel(items, limit, f) {
|
|
20
|
+
const queue = [...items];
|
|
21
|
+
const errors = [];
|
|
22
|
+
await Promise.all(Array.from({ length: Math.min(limit, queue.length) }, async () => {
|
|
23
|
+
for (let item = queue.shift(); item !== undefined; item = queue.shift()) {
|
|
24
|
+
try {
|
|
25
|
+
await f(item);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
errors.push(e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
return errors;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Downloads the lock's jars missing from localRepo (or not matching their
|
|
36
|
+
* SHA-256) from repository, Maven Central or CLJF_MAVEN_REPO. Returns the
|
|
37
|
+
* jars' paths.
|
|
38
|
+
*/
|
|
39
|
+
export async function bootstrapResolver({
|
|
40
|
+
lock = readLock(),
|
|
41
|
+
localRepo,
|
|
42
|
+
repository = lock.repository,
|
|
43
|
+
log = () => {},
|
|
44
|
+
fetch,
|
|
45
|
+
}) {
|
|
46
|
+
const base = repository.replace(/\/+$/, '');
|
|
47
|
+
const missing = [];
|
|
48
|
+
await inParallel(lock.jars, 8, async jar => {
|
|
49
|
+
const file = path.join(localRepo, ...jar.path.split('/'));
|
|
50
|
+
const sha256 = await sha256File(file);
|
|
51
|
+
if (sha256 === jar.sha256) return;
|
|
52
|
+
if (sha256) log(`cljf: ${file} doesn't match resolver.lock.json, downloading it again`);
|
|
53
|
+
missing.push(jar);
|
|
54
|
+
});
|
|
55
|
+
if (missing.length) {
|
|
56
|
+
const mb = missing.reduce((sum, jar) => sum + jar.size, 0) / 1e6;
|
|
57
|
+
log(`cljf: downloading the dependency resolver, ${missing.length} jars (${mb.toFixed(1)} MB), from ${base}`);
|
|
58
|
+
const errors = await inParallel(missing, 8, jar =>
|
|
59
|
+
download(`${base}/${jar.path}`, path.join(localRepo, ...jar.path.split('/')), { sha256: jar.sha256, fetch }));
|
|
60
|
+
if (errors.length) {
|
|
61
|
+
throw new LauncherError(
|
|
62
|
+
`cljf: ${errors[0].message}${errors.length > 1 ? ` (and ${errors.length - 1} more)` : ''}\n` +
|
|
63
|
+
'Check the network connection and proxy settings. For a Maven Central mirror, set CLJF_MAVEN_REPO ' +
|
|
64
|
+
'to its URL; the project\'s own repositories come from :mvn/repos in deps.edn.',
|
|
65
|
+
{ cause: errors[0] });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return lock.jars.map(jar => path.join(localRepo, ...jar.path.split('/')));
|
|
69
|
+
}
|
package/cljf/cli.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// cljf: builds and watches ClojureScript with the compiler (cljs.esm), on the
|
|
3
|
+
// project's classpath resolved from its deps.edn. See usage below.
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { LauncherError } from './errors.js';
|
|
7
|
+
import { classpath, compilerCommand, findJava, setupJava, version } from './launcher.js';
|
|
8
|
+
|
|
9
|
+
const usage = `Usage: cljf [options] <command> [arguments]
|
|
10
|
+
|
|
11
|
+
Commands:
|
|
12
|
+
build [options...] compile once, cljs.esm's options: EDN maps, @file.edn
|
|
13
|
+
and :profile keywords (defaults to :release)
|
|
14
|
+
watch [options...] compile, then recompile on changes (defaults to :dev)
|
|
15
|
+
classpath print the project's classpath
|
|
16
|
+
setup-java [version] download Eclipse Temurin (the latest LTS by default)
|
|
17
|
+
into cljf's cache, for machines without Java
|
|
18
|
+
|
|
19
|
+
Options:
|
|
20
|
+
-A:alias1:alias2 apply deps.edn aliases, like the Clojure CLI's -A
|
|
21
|
+
--force resolve the classpath again instead of using
|
|
22
|
+
.cljf/cpcache
|
|
23
|
+
--version print cljf's version
|
|
24
|
+
|
|
25
|
+
The project is the current directory, with its deps.edn. Java 17 or later
|
|
26
|
+
comes from CLJF_JAVA, JAVA_HOME, PATH or setup-java, in that order.
|
|
27
|
+
|
|
28
|
+
cljf build '{:main my.app :output-dir "out"}'
|
|
29
|
+
cljf -A:test watch @cljs.edn :test`;
|
|
30
|
+
|
|
31
|
+
function parse(argv) {
|
|
32
|
+
const opts = { aliases: [], force: false };
|
|
33
|
+
let i = 0;
|
|
34
|
+
for (; i < argv.length; i++) {
|
|
35
|
+
const arg = argv[i];
|
|
36
|
+
if (arg.startsWith('-A')) opts.aliases.push(arg.length > 2 ? arg.slice(2) : argv[++i]);
|
|
37
|
+
else if (arg === '--force') opts.force = true;
|
|
38
|
+
else break;
|
|
39
|
+
}
|
|
40
|
+
return { opts, command: argv[i], args: argv.slice(i + 1) };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function run(command, args) {
|
|
44
|
+
const child = spawn(command, args, { stdio: 'inherit' });
|
|
45
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
46
|
+
// the terminal sends SIGINT to the JVM too, other signals are forwarded
|
|
47
|
+
process.on(signal, () => signal !== 'SIGINT' && child.kill(signal));
|
|
48
|
+
}
|
|
49
|
+
child.on('error', e => {
|
|
50
|
+
console.error(`cljf: ${command}: ${e.message}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
});
|
|
53
|
+
child.on('exit', (code, signal) => {
|
|
54
|
+
if (signal) process.kill(process.pid, signal);
|
|
55
|
+
else process.exit(code);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function main() {
|
|
60
|
+
const { opts, command, args } = parse(process.argv.slice(2));
|
|
61
|
+
const interactive = Boolean(process.stdin.isTTY && process.stderr.isTTY && !process.env.CI);
|
|
62
|
+
const log = line => process.stderr.write(`${line}\n`);
|
|
63
|
+
switch (command) {
|
|
64
|
+
case 'build':
|
|
65
|
+
case 'watch': {
|
|
66
|
+
const cmd = await compilerCommand({ ...opts, interactive, log });
|
|
67
|
+
run(cmd.command, [...cmd.args, '-m', 'cljs.esm', command, ...args]);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case 'classpath': {
|
|
71
|
+
const cp = await classpath({ ...opts, java: findJava({ interactive, log }), log });
|
|
72
|
+
console.log(cp.classpath.join(path.delimiter));
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'setup-java': {
|
|
76
|
+
const { java } = await setupJava({ version: args[0], log });
|
|
77
|
+
console.log(java);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case '--version':
|
|
81
|
+
case 'version':
|
|
82
|
+
console.log(version);
|
|
83
|
+
break;
|
|
84
|
+
case undefined:
|
|
85
|
+
case 'help':
|
|
86
|
+
case '--help':
|
|
87
|
+
case '-h':
|
|
88
|
+
console.log(usage);
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
console.error(`cljf: unknown command ${command}\n\n${usage}`);
|
|
92
|
+
process.exit(2);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
main().catch(e => {
|
|
97
|
+
console.error(e instanceof LauncherError ? e.message : e);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
});
|
package/cljf/errors.js
ADDED
package/cljf/files.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Files and directories shared by the launcher's parts.
|
|
2
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
3
|
+
import { createReadStream, createWriteStream } from 'node:fs';
|
|
4
|
+
import fs from 'node:fs/promises';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { Readable, Transform } from 'node:stream';
|
|
8
|
+
import { pipeline } from 'node:stream/promises';
|
|
9
|
+
|
|
10
|
+
// The per-user cache, for the Java runtimes setup-java installs
|
|
11
|
+
export function cacheDir(env = process.env, platform = process.platform) {
|
|
12
|
+
if (env.CLJF_CACHE_DIR) return path.resolve(env.CLJF_CACHE_DIR);
|
|
13
|
+
const home = os.homedir();
|
|
14
|
+
if (platform === 'darwin') return path.join(home, 'Library', 'Caches', 'cljf');
|
|
15
|
+
if (platform === 'win32') return path.join(env.LOCALAPPDATA || path.join(home, 'AppData', 'Local'), 'cljf');
|
|
16
|
+
return path.join(env.XDG_CACHE_HOME || path.join(home, '.cache'), 'cljf');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// The user's deps.edn, where tools.deps looks for it
|
|
20
|
+
export function userDepsEdn(env = process.env) {
|
|
21
|
+
if (env.CLJ_CONFIG) return path.join(env.CLJ_CONFIG, 'deps.edn');
|
|
22
|
+
if (env.XDG_CONFIG_HOME) return path.join(env.XDG_CONFIG_HOME, 'clojure', 'deps.edn');
|
|
23
|
+
return path.join(os.homedir(), '.clojure', 'deps.edn');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function readIfExists(file) {
|
|
27
|
+
try {
|
|
28
|
+
return await fs.readFile(file, 'utf8');
|
|
29
|
+
} catch (e) {
|
|
30
|
+
if (e.code === 'ENOENT') return null;
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The local Maven repository: :mvn/local-repo of the project's or the user's
|
|
36
|
+
// deps.edn, as tools.deps uses it, or ~/.m2/repository
|
|
37
|
+
export async function localRepository(project, env = process.env) {
|
|
38
|
+
for (const file of [path.join(project, 'deps.edn'), userDepsEdn(env)]) {
|
|
39
|
+
const match = (await readIfExists(file))?.match(/:mvn\/local-repo\s+"((?:[^"\\]|\\.)*)"/);
|
|
40
|
+
if (match) return path.resolve(project, JSON.parse(`"${match[1]}"`));
|
|
41
|
+
}
|
|
42
|
+
return path.join(os.homedir(), '.m2', 'repository');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function sha256File(file) {
|
|
46
|
+
const hash = createHash('sha256');
|
|
47
|
+
try {
|
|
48
|
+
await pipeline(createReadStream(file), hash);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (e.code === 'ENOENT') return null;
|
|
51
|
+
throw e;
|
|
52
|
+
}
|
|
53
|
+
return hash.digest('hex');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Writes content to file through a temporary file, so readers never see a
|
|
57
|
+
// partial one
|
|
58
|
+
export async function writeAtomically(file, content) {
|
|
59
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
60
|
+
const tmp = `${file}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`;
|
|
61
|
+
await fs.writeFile(tmp, content);
|
|
62
|
+
await fs.rename(tmp, file);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Downloads url to file, through a temporary file that's renamed once the
|
|
66
|
+
// download is complete and its SHA-256 is sha256 (when given). Returns the
|
|
67
|
+
// SHA-256.
|
|
68
|
+
export async function download(url, file, { sha256, fetch = globalThis.fetch } = {}) {
|
|
69
|
+
let res;
|
|
70
|
+
try {
|
|
71
|
+
res = await fetch(url);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
throw new Error(`downloading ${url} failed: ${e.cause?.message ?? e.message}`, { cause: e });
|
|
74
|
+
}
|
|
75
|
+
if (!res.ok) throw new Error(`downloading ${url} failed: HTTP ${res.status}`);
|
|
76
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
77
|
+
const tmp = `${file}.${process.pid}.${randomBytes(4).toString('hex')}.part`;
|
|
78
|
+
const hash = createHash('sha256');
|
|
79
|
+
try {
|
|
80
|
+
await pipeline(
|
|
81
|
+
Readable.fromWeb(res.body),
|
|
82
|
+
new Transform({ transform(chunk, _, done) { hash.update(chunk); done(null, chunk); } }),
|
|
83
|
+
createWriteStream(tmp),
|
|
84
|
+
);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
await fs.rm(tmp, { force: true });
|
|
87
|
+
throw new Error(`downloading ${url} failed: ${e.cause?.message ?? e.message}`, { cause: e });
|
|
88
|
+
}
|
|
89
|
+
const actual = hash.digest('hex');
|
|
90
|
+
if (sha256 && actual !== sha256) {
|
|
91
|
+
await fs.rm(tmp, { force: true });
|
|
92
|
+
throw new Error(`${url} has SHA-256 ${actual}, expected ${sha256}`);
|
|
93
|
+
}
|
|
94
|
+
await fs.rename(tmp, file);
|
|
95
|
+
return actual;
|
|
96
|
+
}
|