mirror of
https://github.com/janet-lang/janet
synced 2024-12-11 17:20:26 +00:00
Add aliases for bundle/module - issue #1486
info.jdn -> bundle/info.jdn bundle.janet -> bundle/init.janet
This commit is contained in:
parent
6ceff6ecc9
commit
85028967d8
1
examples/sample-bundle-aliases/aliases-mod.janet
Normal file
1
examples/sample-bundle-aliases/aliases-mod.janet
Normal file
@ -0,0 +1 @@
|
|||||||
|
(defn fun [x] (range x))
|
3
examples/sample-bundle-aliases/bundle.janet
Normal file
3
examples/sample-bundle-aliases/bundle.janet
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
(defn install
|
||||||
|
[manifest &]
|
||||||
|
(bundle/add-file manifest "aliases-mod.janet"))
|
4
examples/sample-bundle-aliases/info.jdn
Normal file
4
examples/sample-bundle-aliases/info.jdn
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
@{
|
||||||
|
:name "sample-bundle-aliases"
|
||||||
|
:dependencies ["sample-dep1" "sample-dep2"]
|
||||||
|
}
|
@ -4219,7 +4219,8 @@
|
|||||||
(def check (get config :check))
|
(def check (get config :check))
|
||||||
(def s (sep))
|
(def s (sep))
|
||||||
# Check meta file for dependencies and default name
|
# Check meta file for dependencies and default name
|
||||||
(def infofile-pre (string path s "bundle" s "info.jdn"))
|
(def infofile-pre-1 (string path s "bundle" s "info.jdn"))
|
||||||
|
(def infofile-pre (if (fexists infofile-pre-1) infofile-pre-1 (string path s "info.jdn"))) # allow for alias
|
||||||
(var default-bundle-name nil)
|
(var default-bundle-name nil)
|
||||||
(when (os/stat infofile-pre :mode)
|
(when (os/stat infofile-pre :mode)
|
||||||
(def info (-> infofile-pre slurp parse))
|
(def info (-> infofile-pre slurp parse))
|
||||||
@ -4239,6 +4240,10 @@
|
|||||||
# Setup installed paths
|
# Setup installed paths
|
||||||
(prime-bundle-paths)
|
(prime-bundle-paths)
|
||||||
(os/mkdir (bundle-dir bundle-name))
|
(os/mkdir (bundle-dir bundle-name))
|
||||||
|
# Aliases for common bundle/ files
|
||||||
|
(def bundle.janet (string path s "bundle.janet"))
|
||||||
|
(when (fexists bundle.janet) (copyfile bundle.janet (bundle-file bundle-name "init.janet")))
|
||||||
|
(when (fexists infofile-pre) (copyfile infofile-pre (bundle-file bundle-name "info.jdn")))
|
||||||
# Copy some files into the new location unconditionally
|
# Copy some files into the new location unconditionally
|
||||||
(def implicit-sources (string path s "bundle"))
|
(def implicit-sources (string path s "bundle"))
|
||||||
(when (= :directory (os/stat implicit-sources :mode))
|
(when (= :directory (os/stat implicit-sources :mode))
|
||||||
|
@ -7,21 +7,31 @@
|
|||||||
|
|
||||||
(def is-verbose (os/getenv "VERBOSE"))
|
(def is-verbose (os/getenv "VERBOSE"))
|
||||||
|
|
||||||
(defn assert
|
(defn- assert-no-tail
|
||||||
"Override's the default assert with some nice error handling."
|
"Override's the default assert with some nice error handling."
|
||||||
[x &opt e]
|
[x &opt e]
|
||||||
(default e "assert error")
|
(default e "assert error")
|
||||||
(++ num-tests-run)
|
(++ num-tests-run)
|
||||||
(when x (++ num-tests-passed))
|
(when x (++ num-tests-passed))
|
||||||
(def str (string e))
|
(def str (string e))
|
||||||
(def frame (last (debug/stack (fiber/current))))
|
(def stack (debug/stack (fiber/current)))
|
||||||
|
(def frame (last stack))
|
||||||
(def line-info (string/format "%s:%d"
|
(def line-info (string/format "%s:%d"
|
||||||
(frame :source) (frame :source-line)))
|
(frame :source) (frame :source-line)))
|
||||||
(if x
|
(if x
|
||||||
(when is-verbose (eprintf "\e[32m✔\e[0m %s: %s: %v" line-info (describe e) x))
|
(when is-verbose (eprintf "\e[32m✔\e[0m %s: %s: %v" line-info (describe e) x))
|
||||||
(do (eprintf "\e[31m✘\e[0m %s: %s: %v" line-info (describe e) x) (eflush)))
|
(do
|
||||||
|
(eprintf "\e[31m✘\e[0m %s: %s: %v" line-info (describe e) x) (eflush)))
|
||||||
x)
|
x)
|
||||||
|
|
||||||
|
(defmacro assert
|
||||||
|
[x &opt e]
|
||||||
|
(def xx (gensym))
|
||||||
|
~(do
|
||||||
|
(def ,xx ,x)
|
||||||
|
(,assert-no-tail ,xx ,e)
|
||||||
|
,xx))
|
||||||
|
|
||||||
(defmacro assert-error
|
(defmacro assert-error
|
||||||
[msg & forms]
|
[msg & forms]
|
||||||
(def errsym (keyword (gensym)))
|
(def errsym (keyword (gensym)))
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
(assert true) # smoke test
|
(assert true) # smoke test
|
||||||
|
|
||||||
|
# Testing here is stateful since we are manipulating the filesystem.
|
||||||
|
|
||||||
# Copy since not exposed in boot.janet
|
# Copy since not exposed in boot.janet
|
||||||
(defn- bundle-rpath
|
(defn- bundle-rpath
|
||||||
[path]
|
[path]
|
||||||
@ -100,6 +102,13 @@
|
|||||||
(assert-error "cannot uninstall sample-dep1, breaks dependent bundles @[\"sample-bundle\"]"
|
(assert-error "cannot uninstall sample-dep1, breaks dependent bundles @[\"sample-bundle\"]"
|
||||||
(bundle/uninstall "sample-dep1"))
|
(bundle/uninstall "sample-dep1"))
|
||||||
|
|
||||||
|
# Check bundle file aliases
|
||||||
|
(assert-no-error "sample-bundle-aliases install" (bundle/install "./examples/sample-bundle-aliases"))
|
||||||
|
(assert (= 4 (length (bundle/list))) "bundles are listed correctly 5")
|
||||||
|
(assert-no-error "import aliases" (import aliases-mod))
|
||||||
|
(assert (deep= (range 12) (aliases-mod/fun 12)) "using sample-bundle-aliases")
|
||||||
|
(assert-no-error "aliases uninstall" (bundle/uninstall "sample-bundle-aliases"))
|
||||||
|
|
||||||
# Now re-install sample-bundle as auto-remove
|
# Now re-install sample-bundle as auto-remove
|
||||||
(assert-no-error "sample-bundle install" (bundle/reinstall "sample-bundle" :auto-remove true))
|
(assert-no-error "sample-bundle install" (bundle/reinstall "sample-bundle" :auto-remove true))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user