clojurific 0.12.1 → 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/README.md +3 -2
- package/cljf/launcher.js +15 -8
- package/package.json +2 -2
- package/compiler/deps.edn +0 -9
- package/compiler/src/main/cljs/cljs/analyzer/passes/and_or.cljc +0 -118
- package/compiler/src/main/cljs/cljs/analyzer/passes/lite.cljc +0 -32
- package/compiler/src/main/cljs/cljs/analyzer/passes.cljc +0 -32
- package/compiler/src/main/cljs/cljs/bootstrap_nodejs.js +0 -154
- package/compiler/src/main/cljs/cljs/core/specs/alpha.cljc +0 -272
- package/compiler/src/main/cljs/cljs/core/specs/alpha.cljs +0 -10
- package/compiler/src/main/cljs/cljs/core.cljs +0 -13194
- package/compiler/src/main/cljs/cljs/esm/goog/array.js +0 -61
- package/compiler/src/main/cljs/cljs/esm/goog/math.js +0 -1846
- package/compiler/src/main/cljs/cljs/esm/goog/object.js +0 -80
- package/compiler/src/main/cljs/cljs/esm/goog/string.js +0 -192
- package/compiler/src/main/cljs/cljs/esm/goog/userAgent/product.js +0 -10
- package/compiler/src/main/cljs/cljs/esm/goog.js +0 -90
- package/compiler/src/main/cljs/cljs/esm/karma.cljs +0 -103
- package/compiler/src/main/cljs/cljs/esm/lazy.clj +0 -51
- package/compiler/src/main/cljs/cljs/esm/lazy.cljs +0 -49
- package/compiler/src/main/cljs/cljs/esm/node_test.cljs +0 -21
- package/compiler/src/main/cljs/cljs/esm/repl_runtime.cljs +0 -353
- package/compiler/src/main/cljs/cljs/externs.js +0 -27
- package/compiler/src/main/cljs/cljs/imul.js +0 -11
- package/compiler/src/main/cljs/cljs/js.clj +0 -24
- package/compiler/src/main/cljs/cljs/js.cljs +0 -1432
- package/compiler/src/main/cljs/cljs/loader.cljs +0 -107
- package/compiler/src/main/cljs/cljs/main.clj +0 -67
- package/compiler/src/main/cljs/cljs/math.cljs +0 -869
- package/compiler/src/main/cljs/cljs/module_deps.js +0 -250
- package/compiler/src/main/cljs/cljs/nodejs.cljs +0 -27
- package/compiler/src/main/cljs/cljs/nodejs_externs.js +0 -3
- package/compiler/src/main/cljs/cljs/nodejscli.cljs +0 -22
- package/compiler/src/main/cljs/cljs/pprint.cljc +0 -167
- package/compiler/src/main/cljs/cljs/pprint.cljs +0 -3325
- package/compiler/src/main/cljs/cljs/proxy/impl.cljs +0 -32
- package/compiler/src/main/cljs/cljs/proxy.cljs +0 -184
- package/compiler/src/main/cljs/cljs/reader.clj +0 -18
- package/compiler/src/main/cljs/cljs/reader.cljs +0 -214
- package/compiler/src/main/cljs/cljs/repl.cljs +0 -206
- package/compiler/src/main/cljs/cljs/source_map/base64.cljs +0 -25
- package/compiler/src/main/cljs/cljs/source_map/base64_vlq.cljs +0 -102
- package/compiler/src/main/cljs/cljs/source_map.cljs +0 -305
- package/compiler/src/main/cljs/cljs/spec/alpha.cljc +0 -564
- package/compiler/src/main/cljs/cljs/spec/alpha.cljs +0 -1510
- package/compiler/src/main/cljs/cljs/spec/gen/alpha.cljc +0 -68
- package/compiler/src/main/cljs/cljs/spec/gen/alpha.cljs +0 -183
- package/compiler/src/main/cljs/cljs/spec/test/alpha.cljc +0 -329
- package/compiler/src/main/cljs/cljs/spec/test/alpha.cljs +0 -380
- package/compiler/src/main/cljs/cljs/stacktrace.cljc +0 -578
- package/compiler/src/main/cljs/cljs/test.cljc +0 -458
- package/compiler/src/main/cljs/cljs/test.cljs +0 -606
- package/compiler/src/main/cljs/clojure/browser/dom.cljs +0 -152
- package/compiler/src/main/cljs/clojure/browser/event.cljs +0 -101
- package/compiler/src/main/cljs/clojure/browser/net.cljs +0 -181
- package/compiler/src/main/cljs/clojure/browser/repl/preload.cljs +0 -13
- package/compiler/src/main/cljs/clojure/browser/repl.cljs +0 -283
- package/compiler/src/main/cljs/clojure/core/protocols.cljs +0 -29
- package/compiler/src/main/cljs/clojure/core/reducers.cljs +0 -312
- package/compiler/src/main/cljs/clojure/data.cljs +0 -162
- package/compiler/src/main/cljs/clojure/datafy.cljs +0 -63
- package/compiler/src/main/cljs/clojure/edn.cljs +0 -55
- package/compiler/src/main/cljs/clojure/reflect.cljs +0 -57
- package/compiler/src/main/cljs/clojure/set.cljs +0 -165
- package/compiler/src/main/cljs/clojure/string.cljs +0 -290
- package/compiler/src/main/cljs/clojure/walk.cljs +0 -98
- package/compiler/src/main/cljs/clojure/zip.cljs +0 -291
- package/compiler/src/main/cljs/process/env.cljs +0 -12
- package/compiler/src/main/cljs/shadow/resource.clj +0 -60
- package/compiler/src/main/cljs/shadow/resource.cljs +0 -10
- package/compiler/src/main/clojure/cljs/analyzer/api.cljc +0 -299
- package/compiler/src/main/clojure/cljs/analyzer/impl/namespaces.cljc +0 -68
- package/compiler/src/main/clojure/cljs/analyzer/impl.cljc +0 -59
- package/compiler/src/main/clojure/cljs/analyzer/macros.clj +0 -57
- package/compiler/src/main/clojure/cljs/analyzer/utils.clj +0 -36
- package/compiler/src/main/clojure/cljs/analyzer.cljc +0 -5292
- package/compiler/src/main/clojure/cljs/build/api.clj +0 -309
- package/compiler/src/main/clojure/cljs/cli.clj +0 -812
- package/compiler/src/main/clojure/cljs/closure.clj +0 -3440
- package/compiler/src/main/clojure/cljs/compiler/api.clj +0 -101
- package/compiler/src/main/clojure/cljs/compiler/macros.clj +0 -16
- package/compiler/src/main/clojure/cljs/compiler.cljc +0 -2748
- package/compiler/src/main/clojure/cljs/core/macros.clj +0 -43
- package/compiler/src/main/clojure/cljs/core/server.clj +0 -167
- package/compiler/src/main/clojure/cljs/core.cljc +0 -3719
- package/compiler/src/main/clojure/cljs/env/macros.clj +0 -37
- package/compiler/src/main/clojure/cljs/env.cljc +0 -102
- package/compiler/src/main/clojure/cljs/esm/repl/nrepl.clj +0 -151
- package/compiler/src/main/clojure/cljs/esm/repl.clj +0 -878
- package/compiler/src/main/clojure/cljs/esm.clj +0 -987
- package/compiler/src/main/clojure/cljs/externs/default.edn +0 -1549
- package/compiler/src/main/clojure/cljs/externs.clj +0 -479
- package/compiler/src/main/clojure/cljs/foreign/node.clj +0 -207
- package/compiler/src/main/clojure/cljs/instant.clj +0 -54
- package/compiler/src/main/clojure/cljs/js_deps.cljc +0 -412
- package/compiler/src/main/clojure/cljs/module_graph.cljc +0 -402
- package/compiler/src/main/clojure/cljs/repl/bootstrap.clj +0 -53
- package/compiler/src/main/clojure/cljs/repl/browser.clj +0 -540
- package/compiler/src/main/clojure/cljs/repl/node.clj +0 -253
- package/compiler/src/main/clojure/cljs/repl/node_repl.js +0 -114
- package/compiler/src/main/clojure/cljs/repl/reflect.clj +0 -85
- package/compiler/src/main/clojure/cljs/repl/server.clj +0 -236
- package/compiler/src/main/clojure/cljs/repl.cljc +0 -1615
- package/compiler/src/main/clojure/cljs/server/browser.clj +0 -54
- package/compiler/src/main/clojure/cljs/server/node.clj +0 -54
- package/compiler/src/main/clojure/cljs/source_map/base64.clj +0 -28
- package/compiler/src/main/clojure/cljs/source_map/base64_vlq.clj +0 -104
- package/compiler/src/main/clojure/cljs/source_map.clj +0 -369
- package/compiler/src/main/clojure/cljs/support.cljc +0 -18
- package/compiler/src/main/clojure/cljs/tagged_literals.cljc +0 -93
- package/compiler/src/main/clojure/cljs/util.cljc +0 -420
- package/compiler/src/main/clojure/cljs/vendor/bridge.clj +0 -42
- package/compiler/src/main/clojure/cljs/vendor/clojure/data/json.clj +0 -809
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/default_data_readers.clj +0 -303
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/edn.clj +0 -440
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/commons.clj +0 -131
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/errors.clj +0 -214
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/inspect.clj +0 -91
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/utils.clj +0 -127
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/reader_types.clj +0 -431
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader.clj +0 -1035
- package/compiler/src/main/clojure/cljs/vendor/cognitect/transit.clj +0 -479
- /package/{compiler/no-clojurescript → no-clojurescript}/deps.edn +0 -0
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
;; Copyright (c) Rich Hickey. All rights reserved.
|
|
2
|
-
;; The use and distribution terms for this software are covered by the
|
|
3
|
-
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
|
4
|
-
;; which can be found in the file epl-v10.html at the root of this distribution.
|
|
5
|
-
;; By using this software in any fashion, you are agreeing to be bound by
|
|
6
|
-
;; the terms of this license.
|
|
7
|
-
;; You must not remove this notice, or any other, from this software.
|
|
8
|
-
|
|
9
|
-
(ns cljs.tagged-literals
|
|
10
|
-
#?(:clj (:require [cljs.instant :as inst])
|
|
11
|
-
:cljs (:require [cljs.reader :as reader])))
|
|
12
|
-
|
|
13
|
-
(defn read-queue
|
|
14
|
-
[form]
|
|
15
|
-
(when-not (vector? form)
|
|
16
|
-
(throw
|
|
17
|
-
#?(:clj (RuntimeException.
|
|
18
|
-
"Queue literal expects a vector for its elements.")
|
|
19
|
-
:cljs (js/Error.
|
|
20
|
-
"Queue literal expects a vector for its elements."))))
|
|
21
|
-
(list 'cljs.core/into 'cljs.core.PersistentQueue.EMPTY form))
|
|
22
|
-
|
|
23
|
-
#?(:clj
|
|
24
|
-
(defn read-uuid
|
|
25
|
-
[form]
|
|
26
|
-
(when-not (string? form)
|
|
27
|
-
(throw (RuntimeException. "UUID literal expects a string as its representation.")))
|
|
28
|
-
(try
|
|
29
|
-
(java.util.UUID/fromString form)
|
|
30
|
-
(catch Throwable e
|
|
31
|
-
(throw (RuntimeException. (.getMessage e)))))))
|
|
32
|
-
|
|
33
|
-
#?(:cljs
|
|
34
|
-
(defn read-uuid
|
|
35
|
-
[form]
|
|
36
|
-
(when-not (string? form)
|
|
37
|
-
(throw (js/Error. "UUID literal expects a string as its representation.")))
|
|
38
|
-
(try
|
|
39
|
-
(uuid form)
|
|
40
|
-
(catch :default e
|
|
41
|
-
(throw (js/Error. (. e -message)))))))
|
|
42
|
-
|
|
43
|
-
#?(:clj
|
|
44
|
-
(defn read-inst
|
|
45
|
-
[form]
|
|
46
|
-
(when-not (string? form)
|
|
47
|
-
(throw (RuntimeException. "Instance literal expects a string for its timestamp.")))
|
|
48
|
-
(try
|
|
49
|
-
(inst/read-instant-instant form)
|
|
50
|
-
(catch Throwable e
|
|
51
|
-
(throw (RuntimeException. (.getMessage e)))))))
|
|
52
|
-
|
|
53
|
-
#?(:cljs
|
|
54
|
-
(defn read-inst
|
|
55
|
-
[form]
|
|
56
|
-
(when-not (string? form)
|
|
57
|
-
(throw (js/Error. "Instance literal expects a string for its timestamp.")))
|
|
58
|
-
(try
|
|
59
|
-
(#'reader/read-date form)
|
|
60
|
-
(catch :default e
|
|
61
|
-
(throw (js/Error. (. e -message)))))))
|
|
62
|
-
|
|
63
|
-
(defn valid-js-literal-key? [k]
|
|
64
|
-
(or (string? k)
|
|
65
|
-
(and (keyword? k)
|
|
66
|
-
(nil? (namespace k)))))
|
|
67
|
-
|
|
68
|
-
(deftype JSValue [val])
|
|
69
|
-
|
|
70
|
-
(defn read-js
|
|
71
|
-
[form]
|
|
72
|
-
(when-not (or (vector? form) (map? form))
|
|
73
|
-
(throw
|
|
74
|
-
#?(:clj (RuntimeException.
|
|
75
|
-
"JavaScript literal must use map or vector notation")
|
|
76
|
-
:cljs (js/Error.
|
|
77
|
-
"JavaScript literal must use map or vector notation"))))
|
|
78
|
-
(when-not (or (not (map? form))
|
|
79
|
-
(every? valid-js-literal-key? (keys form)))
|
|
80
|
-
(throw
|
|
81
|
-
#?(:clj (RuntimeException.
|
|
82
|
-
"JavaScript literal keys must be strings or unqualified keywords")
|
|
83
|
-
:cljs (js/Error.
|
|
84
|
-
"JavaScript literal keys must be strings or unqualified keywords"))))
|
|
85
|
-
(JSValue. form))
|
|
86
|
-
|
|
87
|
-
(def ^:dynamic *cljs-data-readers*
|
|
88
|
-
(merge ;; assumes we can read all data_readers
|
|
89
|
-
#?(:clj *data-readers*)
|
|
90
|
-
{'queue read-queue
|
|
91
|
-
'uuid read-uuid
|
|
92
|
-
'inst read-inst
|
|
93
|
-
'js read-js}))
|
|
@@ -1,420 +0,0 @@
|
|
|
1
|
-
; Copyright (c) Rich Hickey. All rights reserved.
|
|
2
|
-
; The use and distribution terms for this software are covered by the
|
|
3
|
-
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
|
4
|
-
; which can be found in the file epl-v10.html at the root of this distribution.
|
|
5
|
-
; By using this software in any fashion, you are agreeing to be bound by
|
|
6
|
-
; the terms of this license.
|
|
7
|
-
; You must not remove this notice, or any other, from this software.
|
|
8
|
-
|
|
9
|
-
(ns cljs.util
|
|
10
|
-
(:refer-clojure :exclude [boolean?])
|
|
11
|
-
(:require [clojure.java.io :as io]
|
|
12
|
-
[clojure.string :as string]
|
|
13
|
-
[clojure.set :as set]
|
|
14
|
-
[clojure.edn :as edn])
|
|
15
|
-
(:import [java.io File]
|
|
16
|
-
[java.net URL URLDecoder]
|
|
17
|
-
[java.security MessageDigest]))
|
|
18
|
-
|
|
19
|
-
;; next line is auto-generated by the build-script - Do not edit!
|
|
20
|
-
(def ^:dynamic *clojurescript-version*)
|
|
21
|
-
|
|
22
|
-
(defn compilation-error [cause]
|
|
23
|
-
(ex-info nil {:clojure.error/phase :compilation} cause))
|
|
24
|
-
|
|
25
|
-
(defn- main-src-directory []
|
|
26
|
-
(some (fn [file]
|
|
27
|
-
(when (= "main" (.getName file))
|
|
28
|
-
file))
|
|
29
|
-
(iterate (memfn getParentFile) (io/as-file (io/resource "cljs/util.cljc")))))
|
|
30
|
-
|
|
31
|
-
(defn- file-hash [file]
|
|
32
|
-
(if (.isDirectory file)
|
|
33
|
-
0
|
|
34
|
-
(hash (slurp file))))
|
|
35
|
-
|
|
36
|
-
(def ^:private synthethetic-version-prefix "0.0.")
|
|
37
|
-
|
|
38
|
-
(def ^:private synthetic-clojurescript-version
|
|
39
|
-
(delay (let [qualifier (fn [n]
|
|
40
|
-
(if (== n Integer/MIN_VALUE)
|
|
41
|
-
0
|
|
42
|
-
(Math/abs n)))]
|
|
43
|
-
;; the compiler's sources only, not i.e. src/main/js (Vite plugin)
|
|
44
|
-
(str synthethetic-version-prefix
|
|
45
|
-
(qualifier (reduce unchecked-add-int
|
|
46
|
-
(map file-hash
|
|
47
|
-
(mapcat #(file-seq (io/file (main-src-directory) %))
|
|
48
|
-
["clojure" "cljs"]))))))))
|
|
49
|
-
|
|
50
|
-
(defn ^String clojurescript-version
|
|
51
|
-
"Returns clojurescript version as a printable string."
|
|
52
|
-
[]
|
|
53
|
-
(if (bound? #'*clojurescript-version*)
|
|
54
|
-
(str
|
|
55
|
-
(:major *clojurescript-version*)
|
|
56
|
-
"."
|
|
57
|
-
(:minor *clojurescript-version*)
|
|
58
|
-
(when-let [i (:incremental *clojurescript-version*)]
|
|
59
|
-
(str "." i))
|
|
60
|
-
(when-let [q (:qualifier *clojurescript-version*)]
|
|
61
|
-
(str "." q))
|
|
62
|
-
(when (:interim *clojurescript-version*)
|
|
63
|
-
"-SNAPSHOT"))
|
|
64
|
-
@synthetic-clojurescript-version))
|
|
65
|
-
|
|
66
|
-
(defn synthetic-version?
|
|
67
|
-
"Returns true if clojurescript-version returns a synthetically-generated
|
|
68
|
-
version."
|
|
69
|
-
[]
|
|
70
|
-
(string/starts-with? (clojurescript-version) synthethetic-version-prefix))
|
|
71
|
-
|
|
72
|
-
(defn cljs-built-dep?
|
|
73
|
-
"Returns true if ClojureScript itself is a built dep."
|
|
74
|
-
[]
|
|
75
|
-
(not (synthetic-version?)))
|
|
76
|
-
|
|
77
|
-
(defn ^String compiled-by-version [f]
|
|
78
|
-
(with-open [reader (io/reader f)]
|
|
79
|
-
(let [match (some->> reader line-seq first
|
|
80
|
-
(re-matches #".*ClojureScript (\d+\.\d+\.\d+).*$"))]
|
|
81
|
-
(or (and match (second match)) "0.0.0000"))))
|
|
82
|
-
|
|
83
|
-
(defn build-options [^File f]
|
|
84
|
-
(with-open [reader (io/reader f)]
|
|
85
|
-
(let [match (some->> reader line-seq first
|
|
86
|
-
(re-matches #".*ClojureScript \d+\.\d+\.\d+ (.*)$"))]
|
|
87
|
-
(and match (edn/read-string (second match))))))
|
|
88
|
-
|
|
89
|
-
(defn munge-path [ss]
|
|
90
|
-
(clojure.lang.Compiler/munge (str ss)))
|
|
91
|
-
|
|
92
|
-
(defn ns->relpath
|
|
93
|
-
"Given a namespace as a symbol return the relative path. May optionally
|
|
94
|
-
provide the file extension, defaults to :cljs."
|
|
95
|
-
([ns] (ns->relpath ns :cljs))
|
|
96
|
-
([ns ext]
|
|
97
|
-
(ns->relpath ns ext \/))
|
|
98
|
-
([ns ext sep]
|
|
99
|
-
(cond-> (string/replace (munge-path ns) \. sep)
|
|
100
|
-
ext (str "." (name ext)))))
|
|
101
|
-
|
|
102
|
-
(defn ns->source
|
|
103
|
-
"Given a namespace as a symbol return the corresponding resource if it exists."
|
|
104
|
-
[ns]
|
|
105
|
-
(or (io/resource (ns->relpath ns :cljs))
|
|
106
|
-
(io/resource (ns->relpath ns :cljc))))
|
|
107
|
-
|
|
108
|
-
(defn path-seq
|
|
109
|
-
[file-str]
|
|
110
|
-
(->> File/separator
|
|
111
|
-
java.util.regex.Pattern/quote
|
|
112
|
-
re-pattern
|
|
113
|
-
(string/split file-str)))
|
|
114
|
-
|
|
115
|
-
(defn to-path
|
|
116
|
-
([parts]
|
|
117
|
-
(to-path parts File/separator))
|
|
118
|
-
([parts sep]
|
|
119
|
-
(apply str (interpose sep parts))))
|
|
120
|
-
|
|
121
|
-
(defn split-paths
|
|
122
|
-
[paths-str]
|
|
123
|
-
(string/split paths-str (re-pattern File/pathSeparator)))
|
|
124
|
-
|
|
125
|
-
(declare ext)
|
|
126
|
-
|
|
127
|
-
(defn ^File to-target-file
|
|
128
|
-
([target-dir ns-info]
|
|
129
|
-
(to-target-file target-dir ns-info "js"))
|
|
130
|
-
([target-dir {:keys [ns source-file] :as ns-info} ext]
|
|
131
|
-
(let [src-ext (if source-file
|
|
132
|
-
(cljs.util/ext source-file)
|
|
133
|
-
"cljs")
|
|
134
|
-
ns (if (or (= src-ext "clj")
|
|
135
|
-
(and (= ns 'cljs.core) (= src-ext "cljc")))
|
|
136
|
-
(symbol (str ns "$macros"))
|
|
137
|
-
ns)
|
|
138
|
-
relpath (string/split (munge-path (str ns)) #"\.")
|
|
139
|
-
parents (cond-> (butlast relpath)
|
|
140
|
-
target-dir (conj target-dir))]
|
|
141
|
-
(cond->> (io/file (str (last relpath) (str "." ext)))
|
|
142
|
-
(seq parents)
|
|
143
|
-
(io/file (to-path parents))))))
|
|
144
|
-
|
|
145
|
-
(defn mkdirs
|
|
146
|
-
"Create all parent directories for the passed file."
|
|
147
|
-
[^File f]
|
|
148
|
-
(.mkdirs (.getParentFile (.getCanonicalFile f))))
|
|
149
|
-
|
|
150
|
-
(defn output-directory
|
|
151
|
-
([opts] (output-directory opts "out"))
|
|
152
|
-
([opts default]
|
|
153
|
-
{:pre [(or (nil? opts) (map? opts))]}
|
|
154
|
-
(or (:output-dir opts) default)))
|
|
155
|
-
|
|
156
|
-
(def windows?
|
|
157
|
-
(.startsWith (.toLowerCase (System/getProperty "os.name")) "windows"))
|
|
158
|
-
|
|
159
|
-
(defn file? [f]
|
|
160
|
-
(instance? File f))
|
|
161
|
-
|
|
162
|
-
(defn url? [f]
|
|
163
|
-
(instance? URL f))
|
|
164
|
-
|
|
165
|
-
(defn ^String filename [^File f]
|
|
166
|
-
(.getName f))
|
|
167
|
-
|
|
168
|
-
;; on Windows, URLs end up having forward slashes like
|
|
169
|
-
;; /C:/Users/... - Antonio
|
|
170
|
-
(defn ^String normalize-path [^String x]
|
|
171
|
-
(-> (cond-> x
|
|
172
|
-
windows? (string/replace #"^[\\/]" ""))
|
|
173
|
-
(string/replace "\\" File/separator)
|
|
174
|
-
(string/replace "/" File/separator)))
|
|
175
|
-
|
|
176
|
-
(defn ^String path [x]
|
|
177
|
-
(cond
|
|
178
|
-
(file? x) (.getAbsolutePath ^File x)
|
|
179
|
-
(url? x) (if windows?
|
|
180
|
-
(let [f (URLDecoder/decode (.getFile x))]
|
|
181
|
-
(normalize-path f))
|
|
182
|
-
(.getPath ^URL x))
|
|
183
|
-
(string? x) x
|
|
184
|
-
:else (throw (Exception. (str "Expected file, url, or string. Got " (pr-str x))))))
|
|
185
|
-
|
|
186
|
-
(defn ^String ext
|
|
187
|
-
"Given a file, url or string return the file extension."
|
|
188
|
-
[x]
|
|
189
|
-
(let [s (cond
|
|
190
|
-
(file? x) (filename x)
|
|
191
|
-
(url? x) (path x)
|
|
192
|
-
(string? x) x
|
|
193
|
-
:else (throw (Exception. (str "Expected file, url, or string. Got " (pr-str x)))))]
|
|
194
|
-
(last (string/split s #"\."))))
|
|
195
|
-
|
|
196
|
-
(defn ^String get-name
|
|
197
|
-
"Given a file or url return the last component of the path."
|
|
198
|
-
[x]
|
|
199
|
-
{:pre [(or (file? x) (url? x))]}
|
|
200
|
-
(if (file? x)
|
|
201
|
-
(filename x)
|
|
202
|
-
(last (string/split (path x) #"[\\\/]"))))
|
|
203
|
-
|
|
204
|
-
(defn ^String relative-name
|
|
205
|
-
"Given a file return a path relative to the working directory. Given a
|
|
206
|
-
URL return the JAR relative path of the resource."
|
|
207
|
-
[x]
|
|
208
|
-
{:pre [(or (file? x) (url? x))]}
|
|
209
|
-
(letfn [(strip-user-dir [s]
|
|
210
|
-
(let [user-path (.toPath (io/file (System/getProperty "user.dir")))
|
|
211
|
-
base-count (.getNameCount user-path)
|
|
212
|
-
file-path (.toPath (io/file s))]
|
|
213
|
-
(if (.startsWith file-path user-path)
|
|
214
|
-
(str (.subpath file-path base-count (.getNameCount file-path)))
|
|
215
|
-
s)))]
|
|
216
|
-
(if (file? x)
|
|
217
|
-
(strip-user-dir (.getAbsolutePath x))
|
|
218
|
-
(let [f (URLDecoder/decode (.getFile x))]
|
|
219
|
-
(if (string/includes? f ".jar!/")
|
|
220
|
-
(last (string/split f #"\.jar!/"))
|
|
221
|
-
(strip-user-dir f))))))
|
|
222
|
-
|
|
223
|
-
(defn last-modified [src]
|
|
224
|
-
(cond
|
|
225
|
-
(file? src) (.lastModified ^File src)
|
|
226
|
-
(url? src)
|
|
227
|
-
(let [conn (.openConnection ^URL src)]
|
|
228
|
-
(try
|
|
229
|
-
(.getLastModified conn)
|
|
230
|
-
(finally
|
|
231
|
-
(let [ins (.getInputStream conn)]
|
|
232
|
-
(when ins
|
|
233
|
-
(.close ins))))))
|
|
234
|
-
:else
|
|
235
|
-
(throw
|
|
236
|
-
(IllegalArgumentException. (str "Cannot get last modified for " src)))))
|
|
237
|
-
|
|
238
|
-
(defn changed? [a b]
|
|
239
|
-
(not (== (last-modified a) (last-modified b))))
|
|
240
|
-
|
|
241
|
-
(defn file-or-resource [s]
|
|
242
|
-
(or (and (.exists (io/file s)) (io/file s))
|
|
243
|
-
(io/resource s)))
|
|
244
|
-
|
|
245
|
-
(defn topo-sort
|
|
246
|
-
([x get-deps]
|
|
247
|
-
(topo-sort x 0 (atom (sorted-map)) (memoize get-deps)))
|
|
248
|
-
([x depth state memo-get-deps]
|
|
249
|
-
(let [deps (memo-get-deps x)]
|
|
250
|
-
(swap! state update-in [depth] (fnil into #{}) deps)
|
|
251
|
-
(doseq [dep deps]
|
|
252
|
-
(topo-sort dep (inc depth) state memo-get-deps))
|
|
253
|
-
(doseq [[<depth _] (subseq @state < depth)]
|
|
254
|
-
(swap! state update-in [<depth] set/difference deps))
|
|
255
|
-
(when (= depth 0)
|
|
256
|
-
(distinct (apply concat (vals @state)))))))
|
|
257
|
-
|
|
258
|
-
(defn valid-js-id-start? [s]
|
|
259
|
-
(re-find #"(?U)^[\p{Alpha}_$]" s))
|
|
260
|
-
|
|
261
|
-
(def debug-prn-mutex (Object.))
|
|
262
|
-
|
|
263
|
-
(defn debug-prn
|
|
264
|
-
[& args]
|
|
265
|
-
(binding [*out* *err*]
|
|
266
|
-
(locking debug-prn-mutex
|
|
267
|
-
(apply println args)
|
|
268
|
-
(flush))))
|
|
269
|
-
|
|
270
|
-
(defmacro measure
|
|
271
|
-
"Like cljs.core/time but toggleable and takes a message string."
|
|
272
|
-
{:added "1.0"}
|
|
273
|
-
([msg expr] `(measure true ~msg ~expr))
|
|
274
|
-
([enable msg expr]
|
|
275
|
-
`(if ~enable
|
|
276
|
-
(let [start# (. System (nanoTime))
|
|
277
|
-
ret# ~expr]
|
|
278
|
-
(debug-prn (str ~msg ", elapsed time:") (/ (double (- (. System (nanoTime)) start#)) 1000000.0) "msecs")
|
|
279
|
-
ret#)
|
|
280
|
-
~expr)))
|
|
281
|
-
|
|
282
|
-
(defmacro compile-if
|
|
283
|
-
([exp then] `(compile-if ~exp ~then nil))
|
|
284
|
-
([exp then else]
|
|
285
|
-
(if (try (eval exp)
|
|
286
|
-
(catch Throwable _ false))
|
|
287
|
-
`(do ~then)
|
|
288
|
-
`(do ~else))))
|
|
289
|
-
|
|
290
|
-
(defmacro compile-when
|
|
291
|
-
[exp then]
|
|
292
|
-
`(compile-if ~exp ~then nil))
|
|
293
|
-
|
|
294
|
-
(defn boolean? [x]
|
|
295
|
-
(or (true? x) (false? x)))
|
|
296
|
-
|
|
297
|
-
(defn levenshtein-distance
|
|
298
|
-
"The the minimum number of single-element edits needed to
|
|
299
|
-
transform s in to t."
|
|
300
|
-
[s t]
|
|
301
|
-
(let [f (fn [f s t]
|
|
302
|
-
(cond
|
|
303
|
-
(empty? s) (count t)
|
|
304
|
-
(empty? t) (count s)
|
|
305
|
-
:else (let [cost (if (= (first s) (first t))
|
|
306
|
-
0
|
|
307
|
-
1)]
|
|
308
|
-
(min (inc (f f (rest s) t))
|
|
309
|
-
(inc (f f s (rest t)))
|
|
310
|
-
(+ cost (f f (rest s) (rest t)))))))
|
|
311
|
-
g (memoize f)]
|
|
312
|
-
(g g s t)))
|
|
313
|
-
|
|
314
|
-
(defn suggestion
|
|
315
|
-
"Provides a best suggestion for an unknown, taken from knowns,
|
|
316
|
-
minimizing the Levenshtein distance, returning nil if threshold
|
|
317
|
-
cannot be satisfied."
|
|
318
|
-
[threshold unknown knowns]
|
|
319
|
-
(let [distance (partial levenshtein-distance unknown)
|
|
320
|
-
closest (apply min-key distance knowns)
|
|
321
|
-
closest-dist (distance closest)]
|
|
322
|
-
(when (<= closest-dist threshold)
|
|
323
|
-
closest)))
|
|
324
|
-
|
|
325
|
-
(defn unknown-opts
|
|
326
|
-
"Takes a set of passed opt keys and known opt keys and for each
|
|
327
|
-
unknown opt key returns a vector of the key and its (potentially
|
|
328
|
-
nil) suggestion."
|
|
329
|
-
[passed knowns]
|
|
330
|
-
{:pre [(set? passed) (set? knowns)]}
|
|
331
|
-
(for [unknown (set/difference passed knowns)]
|
|
332
|
-
[unknown (some-> (suggestion 3 (str unknown) (map str knowns))
|
|
333
|
-
(subs 1)
|
|
334
|
-
keyword)]))
|
|
335
|
-
|
|
336
|
-
(defn distinct-by
|
|
337
|
-
([f coll]
|
|
338
|
-
(let [step (fn step [xs seen]
|
|
339
|
-
(lazy-seq
|
|
340
|
-
((fn [[x :as xs] seen]
|
|
341
|
-
(when-let [s (seq xs)]
|
|
342
|
-
(let [v (f x)]
|
|
343
|
-
(if (contains? seen v)
|
|
344
|
-
(recur (rest s) seen)
|
|
345
|
-
(cons x (step (rest s) (conj seen v)))))))
|
|
346
|
-
xs seen)))]
|
|
347
|
-
(step coll #{}))))
|
|
348
|
-
|
|
349
|
-
(def ^:private hex-digits (char-array "0123456789ABCDEF"))
|
|
350
|
-
|
|
351
|
-
(defn- bytes-to-hex-str
|
|
352
|
-
"Convert an array of bytes into a hex encoded string."
|
|
353
|
-
[^bytes bytes]
|
|
354
|
-
(loop [index (int 0)
|
|
355
|
-
buffer (StringBuilder. (int (* 2 (alength bytes))))]
|
|
356
|
-
(if (== (alength bytes) index)
|
|
357
|
-
(.toString buffer)
|
|
358
|
-
(let [byte (aget bytes index)]
|
|
359
|
-
(.append buffer (aget ^chars hex-digits (bit-and (bit-shift-right byte 4) 0xF)))
|
|
360
|
-
(.append buffer (aget ^chars hex-digits (bit-and byte 0xF)))
|
|
361
|
-
(recur (inc index) buffer)))))
|
|
362
|
-
|
|
363
|
-
(defn content-sha
|
|
364
|
-
([^String s]
|
|
365
|
-
(content-sha s nil))
|
|
366
|
-
([^String s ^Long n]
|
|
367
|
-
(let [digest (MessageDigest/getInstance "SHA-1")
|
|
368
|
-
_ (.reset digest)
|
|
369
|
-
_ (.update digest (.getBytes s "utf8"))
|
|
370
|
-
sha (bytes-to-hex-str (.digest digest))]
|
|
371
|
-
(if-not (nil? n)
|
|
372
|
-
(apply str (take n sha))
|
|
373
|
-
sha))))
|
|
374
|
-
|
|
375
|
-
(defn map-merge [a b]
|
|
376
|
-
(if (and (map? a) (map? b))
|
|
377
|
-
(loop [ks (seq (keys a)) ret a b' b]
|
|
378
|
-
(if ks
|
|
379
|
-
(let [k (first ks)]
|
|
380
|
-
(if (contains? b' k)
|
|
381
|
-
(recur
|
|
382
|
-
(next ks)
|
|
383
|
-
(assoc ret k (map-merge (get ret k) (get b' k)))
|
|
384
|
-
(dissoc b' k))
|
|
385
|
-
(recur (next ks) ret b')))
|
|
386
|
-
(merge ret b')))
|
|
387
|
-
a))
|
|
388
|
-
|
|
389
|
-
(defn conjunction-str [xs]
|
|
390
|
-
(let [xs (vec xs)]
|
|
391
|
-
(case (count xs)
|
|
392
|
-
1 (first xs)
|
|
393
|
-
2 (str (first xs) " and " (second xs))
|
|
394
|
-
(str (string/join ", " (pop xs)) " and " (peek xs)))))
|
|
395
|
-
|
|
396
|
-
(defn module-file-seq-1 [dir]
|
|
397
|
-
[dir]
|
|
398
|
-
(let [fseq (tree-seq
|
|
399
|
-
(fn [^File f]
|
|
400
|
-
(and (. f (isDirectory))
|
|
401
|
-
(not (boolean
|
|
402
|
-
(re-find #"node_modules[\\\/].*[\\\/]node_modules"
|
|
403
|
-
(.getPath f))))))
|
|
404
|
-
(fn [^File d]
|
|
405
|
-
(seq (. d (listFiles))))
|
|
406
|
-
dir)]
|
|
407
|
-
(filter (fn [^File f]
|
|
408
|
-
(let [path (.getPath f)]
|
|
409
|
-
(or (.endsWith path ".json")
|
|
410
|
-
(.endsWith path ".js")
|
|
411
|
-
(.endsWith path ".cjs"))))
|
|
412
|
-
fseq)))
|
|
413
|
-
|
|
414
|
-
(defn node-path-modules [opts]
|
|
415
|
-
(map io/file (or (:node-modules-dirs opts) [(io/file "node_modules")])))
|
|
416
|
-
|
|
417
|
-
(defn module-file-seq [opts]
|
|
418
|
-
"Return a seq of all files in `node_modules` ending in `.js` or `.json` that are
|
|
419
|
-
not in an internally nested `node_modules` dir."
|
|
420
|
-
(mapcat module-file-seq-1 (node-path-modules opts)))
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
; Copyright (c) Rich Hickey. All rights reserved.
|
|
2
|
-
; The use and distribution terms for this software are covered by the
|
|
3
|
-
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
|
4
|
-
; which can be found in the file epl-v10.html at the root of this distribution.
|
|
5
|
-
; By using this software in any fashion, you are agreeing to be bound by
|
|
6
|
-
; the terms of this license.
|
|
7
|
-
; You must not remove this notice, or any other, from this software.
|
|
8
|
-
|
|
9
|
-
(ns cljs.vendor.bridge
|
|
10
|
-
(:require [cljs.vendor.clojure.tools.reader.reader-types :as vendor]
|
|
11
|
-
[clojure.tools.reader.reader-types :as readers]))
|
|
12
|
-
|
|
13
|
-
(extend-protocol vendor/Reader
|
|
14
|
-
clojure.tools.reader.reader_types.Reader
|
|
15
|
-
(read-char [reader]
|
|
16
|
-
(readers/read-char reader))
|
|
17
|
-
(peek-char [reader]
|
|
18
|
-
(readers/peek-char reader)))
|
|
19
|
-
|
|
20
|
-
(extend-protocol vendor/IPushbackReader
|
|
21
|
-
clojure.tools.reader.reader_types.IPushbackReader
|
|
22
|
-
(unread [reader ch]
|
|
23
|
-
(readers/unread reader ch)))
|
|
24
|
-
|
|
25
|
-
(extend-protocol vendor/IndexingReader
|
|
26
|
-
clojure.tools.reader.reader_types.IndexingReader
|
|
27
|
-
(get-line-number [reader]
|
|
28
|
-
(readers/get-line-number reader))
|
|
29
|
-
(get-column-number [reader]
|
|
30
|
-
(readers/get-column-number reader))
|
|
31
|
-
(get-file-name [reader]
|
|
32
|
-
(readers/get-file-name reader)))
|
|
33
|
-
|
|
34
|
-
(extend-protocol vendor/ReaderCoercer
|
|
35
|
-
clojure.tools.reader.reader_types.ReaderCoercer
|
|
36
|
-
(to-rdr [reader]
|
|
37
|
-
(readers/to-rdr reader)))
|
|
38
|
-
|
|
39
|
-
(extend-protocol vendor/PushbackReaderCoercer
|
|
40
|
-
clojure.tools.reader.reader_types.PushbackReaderCoercer
|
|
41
|
-
(to-pbr [reader buflen]
|
|
42
|
-
(readers/to-pbr reader buflen)))
|