Skip to content

Commit

Permalink
Fix babashka#219: import relative to script (babashka#237)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Olivier <[email protected]>
  • Loading branch information
borkdude and bolivier authored Jul 13, 2022
1 parent cd1b4d7 commit 23e387f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

For a list of breaking changes, check [here](#breaking-changes).

## 0.6.125

- Fix [#219](https://github.com/babashka/nbb/issues/219): nbb doesn't resolve local node_modules when using the dynamic `js/import`

## 0.6.124

- Fix [#136](https://github.com/babashka/nbb/issues/136): allow `set!` on any var
Expand Down
6 changes: 5 additions & 1 deletion src/nbb/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@

(def sci-ctx (atom nil))

(set! (.-import goog/global) esm/dynamic-import)
(set! (.-import goog/global)
(fn [what]
;; need to resolve based on the current file
(-> ((:resolve @ctx) what)
(.then #(esm/dynamic-import %)))))

(def loaded-modules (atom {}))

Expand Down
6 changes: 6 additions & 0 deletions test-scripts/esm-test/script.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@
(await (zx/$ #js ["ls"]))

(prn (execa/execaSync "ls"))

(def term-size' (await (js/import "term-size")))
(prn (term-size'.default))

(def js-file (await (js/import "./test-js-file.mjs")))
(assert (= 10 (.-x js-file)))
1 change: 1 addition & 0 deletions test-scripts/esm-test/test-js-file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const x = 10;

0 comments on commit 23e387f

Please sign in to comment.