diff --git a/jscomp/bsb/bsb_pkg.ml b/jscomp/bsb/bsb_pkg.ml index 0051292252..4df0a3fa55 100644 --- a/jscomp/bsb/bsb_pkg.ml +++ b/jscomp/bsb/bsb_pkg.ml @@ -32,25 +32,42 @@ type t = Bsb_pkg_types.t when resolving [ppx-flags] *) let make_sub_path (x : t) : string = - Literals.node_modules // Bsb_pkg_types.to_string x - + Literals.node_modules // Bsb_pkg_types.to_string x +let node_paths : string list Lazy.t = + lazy (try Ext_string.split (Sys.getenv "NODE_PATH") + (if Sys.win32 then ';' else ':') + with _ -> []) (** It makes sense to have this function raise, when [bsb] could not resolve a package, it used to mean a failure *) +let check_dir dir = + match Sys.file_exists dir with + | true -> Some(dir) + | false -> None + let resolve_bs_package_aux ~cwd (pkg : t) = + (* First try to resolve recursively from the current working directory *) let sub_path = make_sub_path pkg in let rec aux cwd = - let abs_marker = cwd // sub_path in + let abs_marker = cwd // sub_path in if Sys.file_exists abs_marker then abs_marker else let another_cwd = Filename.dirname cwd in (* TODO: may non-terminating when see symlinks *) if String.length another_cwd < String.length cwd then aux another_cwd - else (* To the end try other possiblilities *) - Bsb_exception.package_not_found ~pkg ~json:None + else (* To the end try other possiblilities [NODE_PATH]*) + (match Ext_list.find_opt (Lazy.force node_paths) + (fun dir -> check_dir (dir // Bsb_pkg_types.to_string pkg)) with + | Some(resolved_dir) -> resolved_dir + | None -> Bsb_exception.package_not_found ~pkg ~json:None) in - aux cwd + aux cwd + + + + + module Coll = Hashtbl_make.Make(struct type nonrec t = t diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/.gitignore b/jscomp/build_tests/bs_dependencies_node_path_override/.gitignore new file mode 100644 index 0000000000..71c60460d7 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/.gitignore @@ -0,0 +1,29 @@ +*.exe +*.obj +*.out +*.compile +*.native +*.byte +*.cmo +*.annot +*.cmi +*.cmx +*.cmt +*.cmti +*.cma +*.a +*.cmxa +*.obj +*~ +*.annot +*.cmj +*.bak +lib/bs +*.mlast +*.mliast +.vscode +.merlin +**/*.js +!node_modules +!input.js +!testcase.js \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/README.md b/jscomp/build_tests/bs_dependencies_node_path_override/README.md new file mode 100644 index 0000000000..1c02d2a072 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/README.md @@ -0,0 +1,16 @@ + + +# Build +``` +npm run build +``` + +# Watch + +``` +npm run watch +``` + + +# Editor +If you use `vscode`, Press `Windows + Shift + B` it will build automatically \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/bsconfig.json b/jscomp/build_tests/bs_dependencies_node_path_override/bsconfig.json new file mode 100644 index 0000000000..5eb6a09cf2 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/bsconfig.json @@ -0,0 +1,23 @@ +{ + "name": "bs_dependencies_node_path_override", + "version": "0.1.0", + "sources": [ + { + "dir": "src", + "subdirs" : true + }, + { + "dir": "examples", + "type" : "dev", + "subdirs" : true + } + ], + "package-specs" : { + "module": "commonjs", + "in-source": true + }, + "namespace": true, + "bs-dependencies" : [ + "liba" + ] +} \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/examples/test.ml b/jscomp/build_tests/bs_dependencies_node_path_override/examples/test.ml new file mode 100644 index 0000000000..f5f8f9d8c1 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/examples/test.ml @@ -0,0 +1 @@ +let v = Demo.name \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/input.js b/jscomp/build_tests/bs_dependencies_node_path_override/input.js new file mode 100644 index 0000000000..863ab0f765 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/input.js @@ -0,0 +1,5 @@ +//@ts-check +var path = require('path') +var p = require('child_process') +var node_path = path.join(__dirname, "nothing_exists_here") + ":" + path.join(__dirname, "overridden_node_modules") +p.execSync(`NODE_PATH=${node_path} node ./testcase.js`, {cwd:__dirname,shell:true,encoding:'utf8',stdio:"inherit"}) \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/.gitignore b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/.gitignore new file mode 100644 index 0000000000..8f464d0527 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/.gitignore @@ -0,0 +1,25 @@ +*.exe +*.obj +*.out +*.compile +*.native +*.byte +*.cmo +*.annot +*.cmi +*.cmx +*.cmt +*.cmti +*.cma +*.a +*.cmxa +*.obj +*~ +*.annot +*.cmj +*.bak +lib/bs +*.mlast +*.mliast +.vscode +.merlin \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/README.md b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/README.md new file mode 100644 index 0000000000..1c02d2a072 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/README.md @@ -0,0 +1,16 @@ + + +# Build +``` +npm run build +``` + +# Watch + +``` +npm run watch +``` + + +# Editor +If you use `vscode`, Press `Windows + Shift + B` it will build automatically \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/bsconfig.json b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/bsconfig.json new file mode 100644 index 0000000000..f34d7ed09e --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/bsconfig.json @@ -0,0 +1,17 @@ +{ + "name": "liba", + "version": "0.1.0", + "sources": [ + { + "dir": "src", + "subdirs" : true + }, + { + "dir" : "examples", + "type": "dev", + "subdirs" : true + } + ], + "namespace": true + +} \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/examples/xx/test.ml b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/examples/xx/test.ml new file mode 100644 index 0000000000..af158a09e6 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/examples/xx/test.ml @@ -0,0 +1 @@ +let name = __FILE__ + 3 \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/examples/yy.ml b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/examples/yy.ml new file mode 100644 index 0000000000..d32a6d0646 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/examples/yy.ml @@ -0,0 +1 @@ +let name = __FILE__ \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/package.json b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/package.json new file mode 100644 index 0000000000..63c69448e0 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/package.json @@ -0,0 +1,16 @@ +{ + "name": "liba", + "version": "0.1.0", + "scripts": { + "clean": "bsb -clean-world", + "build": "bsb -make-world", + "watch": "bsb -make-world -w" + }, + "keywords": [ + "BuckleScript" + ], + "license": "MIT", + "devDependencies": { + "bs-platform": "1.9.3" + } +} \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/src/demo.ml b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/src/demo.ml new file mode 100644 index 0000000000..ca8c589c96 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/src/demo.ml @@ -0,0 +1,3 @@ + + +let name = __FILE__ \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/src/hi/fib.ml b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/src/hi/fib.ml new file mode 100644 index 0000000000..d32a6d0646 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/overridden_node_modules/liba/src/hi/fib.ml @@ -0,0 +1 @@ +let name = __FILE__ \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/package.json b/jscomp/build_tests/bs_dependencies_node_path_override/package.json new file mode 100644 index 0000000000..8d24a775bb --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/package.json @@ -0,0 +1,16 @@ +{ + "name": "bs_dependencies_node_path_override", + "version": "0.1.0", + "scripts": { + "clean": "bsb -clean-world", + "build": "bsb -make-world", + "watch": "bsb -make-world -w" + }, + "keywords": [ + "BuckleScript" + ], + "license": "MIT", + "devDependencies": { + "bs-platform": "^5.1.0-dev.3" + } +} \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/src/demo.ml b/jscomp/build_tests/bs_dependencies_node_path_override/src/demo.ml new file mode 100644 index 0000000000..1b2a37152f --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/src/demo.ml @@ -0,0 +1,3 @@ + + +let name = __FILE__ ^ Liba.Demo.name \ No newline at end of file diff --git a/jscomp/build_tests/bs_dependencies_node_path_override/testcase.js b/jscomp/build_tests/bs_dependencies_node_path_override/testcase.js new file mode 100644 index 0000000000..fdf1c492a7 --- /dev/null +++ b/jscomp/build_tests/bs_dependencies_node_path_override/testcase.js @@ -0,0 +1,7 @@ +//@ts-check +var assert = require('assert') +var path = require('path') +var p = require('child_process') +p.execSync(`bsb -make-world`, {cwd:__dirname,shell:true,encoding:'utf8',stdio:"inherit"}) +var u = require("./examples/test.js") +assert.equal(path.basename(u.v),'demo.mldemo.ml') \ No newline at end of file diff --git a/jscomp/ounit_tests/ounit_string_tests.ml b/jscomp/ounit_tests/ounit_string_tests.ml index db1507dcc2..619bb2f4dc 100644 --- a/jscomp/ounit_tests/ounit_string_tests.ml +++ b/jscomp/ounit_tests/ounit_string_tests.ml @@ -1,7 +1,7 @@ let ((>::), (>:::)) = OUnit.((>::),(>:::)) -let (=~) = OUnit.assert_equal +let (=~) = OUnit.assert_equal ~printer:Ext_obj.dump let printer_string = fun x -> x @@ -495,6 +495,11 @@ let suites = string_eq (Ext_filename.module_name "a/b/.") "" ; + end; + __LOC__ >:: begin fun _ -> + Ext_string.split "" ':' =~ []; + Ext_string.split "a:b:" ':' =~ ["a";"b"]; + Ext_string.split "a:b:" ':' ~keep_empty:true =~ ["a";"b";""] end ] diff --git a/lib/4.02.3/bsb.ml b/lib/4.02.3/bsb.ml index df303a9f66..d40a24b5c6 100644 --- a/lib/4.02.3/bsb.ml +++ b/lib/4.02.3/bsb.ml @@ -5237,25 +5237,42 @@ type t = Bsb_pkg_types.t when resolving [ppx-flags] *) let make_sub_path (x : t) : string = - Literals.node_modules // Bsb_pkg_types.to_string x - + Literals.node_modules // Bsb_pkg_types.to_string x +let node_paths : string list Lazy.t = + lazy (try Ext_string.split (Sys.getenv "NODE_PATH") + (if Sys.win32 then ';' else ':') + with _ -> []) (** It makes sense to have this function raise, when [bsb] could not resolve a package, it used to mean a failure *) +let check_dir dir = + match Sys.file_exists dir with + | true -> Some(dir) + | false -> None + let resolve_bs_package_aux ~cwd (pkg : t) = + (* First try to resolve recursively from the current working directory *) let sub_path = make_sub_path pkg in let rec aux cwd = - let abs_marker = cwd // sub_path in + let abs_marker = cwd // sub_path in if Sys.file_exists abs_marker then abs_marker else let another_cwd = Filename.dirname cwd in (* TODO: may non-terminating when see symlinks *) if String.length another_cwd < String.length cwd then aux another_cwd - else (* To the end try other possiblilities *) - Bsb_exception.package_not_found ~pkg ~json:None + else (* To the end try other possiblilities [NODE_PATH]*) + (match Ext_list.find_opt (Lazy.force node_paths) + (fun dir -> check_dir (dir // Bsb_pkg_types.to_string pkg)) with + | Some(resolved_dir) -> resolved_dir + | None -> Bsb_exception.package_not_found ~pkg ~json:None) in - aux cwd + aux cwd + + + + + module Coll = Hashtbl_make.Make(struct type nonrec t = t diff --git a/lib/4.02.3/unstable/all_ounit_tests.ml b/lib/4.02.3/unstable/all_ounit_tests.ml index 18d6a09f62..32f03c256c 100644 --- a/lib/4.02.3/unstable/all_ounit_tests.ml +++ b/lib/4.02.3/unstable/all_ounit_tests.ml @@ -17047,7 +17047,7 @@ module Ounit_string_tests let ((>::), (>:::)) = OUnit.((>::),(>:::)) -let (=~) = OUnit.assert_equal +let (=~) = OUnit.assert_equal ~printer:Ext_obj.dump let printer_string = fun x -> x @@ -17541,6 +17541,11 @@ let suites = string_eq (Ext_filename.module_name "a/b/.") "" ; + end; + __LOC__ >:: begin fun _ -> + Ext_string.split "" ':' =~ []; + Ext_string.split "a:b:" ':' =~ ["a";"b"]; + Ext_string.split "a:b:" ':' ~keep_empty:true =~ ["a";"b";""] end ] diff --git a/lib/4.02.3/unstable/bsb_native.ml b/lib/4.02.3/unstable/bsb_native.ml index f891e40851..1c23fcc9d9 100644 --- a/lib/4.02.3/unstable/bsb_native.ml +++ b/lib/4.02.3/unstable/bsb_native.ml @@ -5237,25 +5237,42 @@ type t = Bsb_pkg_types.t when resolving [ppx-flags] *) let make_sub_path (x : t) : string = - Literals.node_modules // Bsb_pkg_types.to_string x - + Literals.node_modules // Bsb_pkg_types.to_string x +let node_paths : string list Lazy.t = + lazy (try Ext_string.split (Sys.getenv "NODE_PATH") + (if Sys.win32 then ';' else ':') + with _ -> []) (** It makes sense to have this function raise, when [bsb] could not resolve a package, it used to mean a failure *) +let check_dir dir = + match Sys.file_exists dir with + | true -> Some(dir) + | false -> None + let resolve_bs_package_aux ~cwd (pkg : t) = + (* First try to resolve recursively from the current working directory *) let sub_path = make_sub_path pkg in let rec aux cwd = - let abs_marker = cwd // sub_path in + let abs_marker = cwd // sub_path in if Sys.file_exists abs_marker then abs_marker else let another_cwd = Filename.dirname cwd in (* TODO: may non-terminating when see symlinks *) if String.length another_cwd < String.length cwd then aux another_cwd - else (* To the end try other possiblilities *) - Bsb_exception.package_not_found ~pkg ~json:None + else (* To the end try other possiblilities [NODE_PATH]*) + (match Ext_list.find_opt (Lazy.force node_paths) + (fun dir -> check_dir (dir // Bsb_pkg_types.to_string pkg)) with + | Some(resolved_dir) -> resolved_dir + | None -> Bsb_exception.package_not_found ~pkg ~json:None) in - aux cwd + aux cwd + + + + + module Coll = Hashtbl_make.Make(struct type nonrec t = t diff --git a/scripts/ciTest.js b/scripts/ciTest.js index 1933ba89e0..f7f9b6539d 100644 --- a/scripts/ciTest.js +++ b/scripts/ciTest.js @@ -114,6 +114,7 @@ function main() { console.log("BSBDIR:", bsbDir) if (themeTest) { + console.log('Doing theme tests') var themeOutput = cp.execSync(`bsb -themes`,{encoding : 'ascii'}) var themes = themeOutput.split('\n').slice(1).map(x=>x.trim()).filter(x=>x) var themesDir = path.join(__dirname,'..','themes')