forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathext_filename.js
136 lines (125 loc) · 3.27 KB
/
ext_filename.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Generated CODE, PLEASE EDIT WITH CARE
"use strict";
var Filename = require("../stdlib/filename");
var Caml_exceptions = require("../runtime/caml_exceptions");
var Pervasives = require("../stdlib/pervasives");
var Ext_string = require("./ext_string");
var $$String = require("../stdlib/string");
var List = require("../stdlib/list");
var node_sep = "/";
var node_parent = "..";
var node_current = ".";
function absolute_path(s) {
var s$1 = Filename.is_relative(s) ? Filename.concat(/* Missing primitve */"caml_sys_getcwd", s) : s;
var aux = function (_s) {
while(true) {
var s = _s;
var base = Filename.basename(s);
var dir = Filename.dirname(s);
if (dir === s) {
return dir;
}
else {
if (base === Filename.current_dir_name) {
_s = dir;
}
else {
if (base === Filename.parent_dir_name) {
return Filename.dirname(aux(dir));
}
else {
return Filename.concat(aux(dir), base);
}
}
}
};
};
return aux(s$1);
}
function chop_extension($staropt$star, name) {
var loc = $staropt$star ? $staropt$star[1] : "";
try {
return Filename.chop_extension(name);
}
catch (exn){
if (exn[1] === Caml_exceptions.Invalid_argument) {
return Pervasives.invalid_arg("Filename.chop_extension (" + (loc + (":" + (name + ")"))));
}
else {
throw exn;
}
}
}
function try_chop_extension(s) {
try {
return Filename.chop_extension(s);
}
catch (exn){
return s;
}
}
function relative_path(file1, file2) {
var dir1 = Ext_string.split(/* None */0, Filename.dirname(file1), Filename.dir_sep.charCodeAt(0));
var dir2 = Ext_string.split(/* None */0, Filename.dirname(file2), Filename.dir_sep.charCodeAt(0));
var go = function (_dir1, _dir2) {
while(true) {
var dir2 = _dir2;
var dir1 = _dir1;
var exit = 0;
if (dir1) {
if (dir2) {
if (dir1[1] === dir2[1]) {
_dir2 = dir2[2];
_dir1 = dir1[2];
}
else {
exit = 1;
}
}
else {
exit = 1;
}
}
else {
exit = 1;
}
if (exit === 1) {
return Pervasives.$at(List.map(function () {
return node_parent;
}, dir2), dir1);
}
};
};
var ys = go(dir1, dir2);
var exit = 0;
if (ys) {
if (ys[1] === node_parent) {
return $$String.concat(node_sep, ys);
}
else {
exit = 1;
}
}
else {
exit = 1;
}
if (exit === 1) {
return $$String.concat(node_sep, [
/* :: */0,
node_current,
ys
]);
}
}
function node_relative_path(path1, path2) {
return relative_path(try_chop_extension(absolute_path(path2)), try_chop_extension(absolute_path(path1))) + (node_sep + try_chop_extension(Filename.basename(path2)));
}
exports.node_sep = node_sep;
exports.node_parent = node_parent;
exports.node_current = node_current;
exports.absolute_path = absolute_path;
exports.chop_extension = chop_extension;
exports.try_chop_extension = try_chop_extension;
exports.relative_path = relative_path;
exports.node_relative_path = node_relative_path;
/* Filename Not a pure module */