-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
154 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(ns cljsjs.npm.util | ||
(:require [boot.core :as boot] | ||
[clojure.string :as string])) | ||
|
||
(defn with-files | ||
"Runs middleware with filtered fileset and merges the result back into complete fileset." | ||
[p middleware] | ||
(fn [next-handler] | ||
(fn [fileset] | ||
(let [merge-fileset-handler (fn [fileset'] | ||
(next-handler (boot/commit! (assoc fileset :tree (merge (:tree fileset) (:tree fileset')))))) | ||
handler (middleware merge-fileset-handler) | ||
fileset (assoc fileset :tree (reduce-kv | ||
(fn [tree path x] | ||
(if (p x) | ||
(assoc tree path x) | ||
tree)) | ||
(empty (:tree fileset)) | ||
(:tree fileset)))] | ||
(handler fileset))))) | ||
|
||
|
||
(defn normalize-url | ||
"Simple URL normalization logic for import paths. Can normalize | ||
relative paths." | ||
[url-string] | ||
(loop [result nil | ||
parts (string/split url-string #"/")] | ||
(if (seq parts) | ||
(let [part (first parts)] | ||
(case part | ||
;; Skip empty | ||
"" (recur result (rest parts)) | ||
;; Skip "." | ||
"." (recur result (rest parts)) | ||
;; Remove previous part, if there are previous non ".." parts | ||
".." (if (and (seq result) (not= ".." (first result))) | ||
(recur (rest result) (rest parts)) | ||
(recur (conj result part) (rest parts))) | ||
(recur (conj result part) (rest parts)))) | ||
(string/join "/" (reverse result))))) | ||
|
||
(defn drop-last-url-part [path] | ||
(string/join "/" (butlast (string/split path #"/")))) |