Skip to content

Commit f55b223

Browse files
committed
make node path resolution node friendly, also versionize bucklescript header' (#313)
1 parent 9dd9d93 commit f55b223

File tree

344 files changed

+501
-373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

344 files changed

+501
-373
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ boot
5959
coverage
6060
*.log
6161
./jscomp/output
62-
*.g.js
62+
*.g.js
63+
dist

jscomp/ext_filename.ml

+25-1
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,37 @@ let relative_path file1 file2 =
8484

8585

8686

87+
let node_modules = "node_modules"
88+
let node_modules_length = String.length "node_modules"
8789
(** path2: a/b
8890
path1: a
8991
result: ./b
9092
TODO: [Filename.concat] with care
9193
*)
9294
let node_relative_path path1 path2 =
93-
95+
let v = Ext_string.find path2 ~sub:node_modules in
96+
let len = String.length path2 in
97+
if v >= 0 then
98+
let rec skip i =
99+
if i >= len then
100+
failwith ("invalid path: " ^ path2)
101+
else
102+
match path2.[i] with
103+
| '/'
104+
| '.' -> skip (i + 1)
105+
| _ -> i
106+
(*
107+
TODO: we need do more than this suppose user
108+
input can be
109+
{[
110+
"xxxghsoghos/ghsoghso/node_modules/../buckle-stdlib/list.js"
111+
]}
112+
This seems weird though
113+
*)
114+
in
115+
Ext_string.tail_from path2
116+
(skip (v + node_modules_length))
117+
else
94118
(relative_path
95119
(try_chop_extension (absolute_path path2))
96120
(try_chop_extension (absolute_path path1))

jscomp/ext_filename.mli

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626

2727
(** Js_output is node style, which means
2828
separator is only '/'
29-
TODO: handle [node_modules]
29+
30+
if the path contains 'node_modules',
31+
[node_relative_path] will discard its prefix and
32+
just treat it as a library instead
3033
*)
3134

3235
val node_relative_path : string -> string -> string

jscomp/js_config.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ let gc = "Caml_gc"
147147
let int32 = "Caml_int32"
148148
let block = "Block"
149149
let js_primitive = "Js_primitive"
150-
150+
let version = "0.3"
151151
let runtime_set =
152152
[
153153
js_primitive;

jscomp/js_config.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ val block : string
3838
val int32 : string
3939
val gc : string
4040
val backtrace : string
41-
41+
val version : string
4242
val builtin_exceptions : string
4343
val exceptions : string
4444
val io : string

jscomp/js_dump.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1593,9 +1593,14 @@ let amd_program f
15931593
P.string f ")";
15941594
v
15951595

1596+
let bs_header =
1597+
"// GENERATED CODE BY BUCKLESCRIPT VERSION " ^
1598+
Js_config.version ^
1599+
" , PLEASE EDIT WITH CARE"
1600+
15961601
let pp_deps_program ( program : J.deps_program) (f : Ext_pp.t) =
15971602
begin
1598-
P.string f "// Generated CODE, PLEASE EDIT WITH CARE";
1603+
P.string f bs_header;
15991604
P.newline f;
16001605
P.string f L.strict_directive;
16011606
P.newline f ;

jscomp/js_program_loader.ml

+20-20
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,29 @@ let string_of_module_id (x : Lam_module_ident.t) : string =
5656
| AmdJS
5757
| NodeJS ->
5858
let filename = String.uncapitalize id.name in
59-
if String_set.mem filename Js_config.runtime_set then
60-
let path =
61-
(* For the runtime, only [JS] files are needed, and
62-
unlike the stdlib, [bsc] have some pre-built knowledge
63-
about where it is, since in general, [runtime]
64-
is *transparent* to the user
65-
*)
66-
match Sys.getenv "OCAML_JS_RUNTIME_PATH" with
67-
| exception Not_found ->
68-
Filename.concat
69-
(Filename.dirname (Filename.dirname Sys.executable_name))
70-
"runtime"
71-
| f -> f in
72-
Ext_filename.node_relative_path !Location.input_name
73-
(Filename.concat path filename)
74-
else
7559
begin match Config_util.find file with
7660
(* for some primitive files, no cmj support *)
7761
| exception Not_found ->
78-
Ext_log.warn __LOC__ "@[%s not found in search path - while compiling %s @] "
79-
file !Location.input_name ;
80-
Printf.sprintf "%s"
81-
(String.uncapitalize id.name)
62+
if String_set.mem filename Js_config.runtime_set then
63+
let path =
64+
(* For the runtime, only [JS] files are needed, and
65+
unlike the stdlib, [bsc] have some pre-built knowledge
66+
about where it is, since in general, [runtime]
67+
is *transparent* to the user
68+
*)
69+
Filename.concat
70+
(Filename.dirname (Filename.dirname Sys.executable_name))
71+
"runtime"
72+
in
73+
Ext_filename.node_relative_path !Location.input_name
74+
(Filename.concat path filename)
75+
else
76+
begin
77+
Ext_log.warn __LOC__ "@[%s not found in search path - while compiling %s @] "
78+
file !Location.input_name ;
79+
Printf.sprintf "%s"
80+
(String.uncapitalize id.name)
81+
end
8282
(* maybe from third party library*)
8383
(* Check: be consistent when generating js files
8484
A.ml -> a.js

jscomp/lib/bench.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Bench = require("benchmark");

jscomp/lib/fn.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/lib/js.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/lib/js_date.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/block.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/caml_array.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/caml_backtrace.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");

jscomp/runtime/caml_builtin_exceptions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/caml_exceptions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/caml_float.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/caml_format.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_int64 = require("./caml_int64");

jscomp/runtime/caml_gc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/caml_hash.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");

jscomp/runtime/caml_int32.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");

jscomp/runtime/caml_int64.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");

jscomp/runtime/caml_io.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");

jscomp/runtime/caml_lexer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");

jscomp/runtime/caml_md5.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/caml_obj.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");

jscomp/runtime/caml_oo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");

jscomp/runtime/caml_parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/caml_primitive.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/caml_queue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/caml_string.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");

jscomp/runtime/caml_sys.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");

jscomp/runtime/caml_utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/caml_weak.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_obj = require("./caml_obj");

jscomp/runtime/curry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_oo = require("./caml_oo");

jscomp/runtime/fn.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/js.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/js_error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/js_primitive.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/runtime/typed_array.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44

jscomp/stdlib/arg.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_obj = require("../runtime/caml_obj");

jscomp/stdlib/array.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions");

jscomp/stdlib/arrayLabels.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var $$Array = require("./array");

jscomp/stdlib/bigarray.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions");

jscomp/stdlib/buffer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Bytes = require("./bytes");

jscomp/stdlib/bytes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions");

jscomp/stdlib/bytesLabels.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Bytes = require("./bytes");

jscomp/stdlib/callback.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Obj = require("./obj");

jscomp/stdlib/camlinternalFormat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated CODE, PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Bytes = require("./bytes");

0 commit comments

Comments
 (0)