@@ -12,9 +12,9 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
12
12
See the Apache Version 2.0 License for specific language governing permissions
13
13
and limitations under the License.
14
14
***************************************************************************** */
15
+ import * as os from "os";
16
+ import * as std from "std";
15
17
16
-
17
- "use strict";
18
18
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
19
19
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
20
20
to[j] = from[i];
@@ -4901,6 +4901,11 @@ var ts;
4901
4901
}
4902
4902
var fd;
4903
4903
try {
4904
+ // If `-` is provided as the fileName, output to stdout
4905
+ if (fileName === '-') {
4906
+ process.stdout.write(data, "gbk");
4907
+ return;
4908
+ }
4904
4909
fd = _fs.openSync(fileName, "w");
4905
4910
_fs.writeSync(fd, data, undefined, "utf8");
4906
4911
}
@@ -5025,8 +5030,154 @@ var ts;
5025
5030
return hash.digest("hex");
5026
5031
}
5027
5032
}
5033
+ function getQuickJSSystem() {
5034
+ var executable_path = scriptArgs[0];
5035
+ var args = scriptArgs.slice(1);
5036
+ var useCaseSensitiveFileNames;
5037
+ var newLine;
5038
+ var realpath = function(path) {
5039
+ var [res, err] = os.realpath(path);
5040
+ return res;
5041
+ };
5042
+ if (os.platform === "win32") {
5043
+ newLine = "\r\n";
5044
+ useCaseSensitiveFileNames = false;
5045
+ } else {
5046
+ newLine = "\n";
5047
+ useCaseSensitiveFileNames = true;
5048
+ }
5049
+ function getAccessibleFileSystemEntries(path) {
5050
+ var entries, err, st;
5051
+ [entries, err] = os.readdir(path || ".");
5052
+ if (err != 0)
5053
+ return ts.emptyFileSystemEntries;
5054
+ entries = entries.sort();
5055
+ var files = [];
5056
+ var directories = [];
5057
+ for (var i = 0; i < entries.length; i++) {
5058
+ var entry = entries[i];
5059
+ if (entry === "." || entry === "..") {
5060
+ continue;
5061
+ }
5062
+ var name = ts.combinePaths(path, entry);
5063
+ [st, err] = os.stat(name);
5064
+ if (err != 0)
5065
+ continue;
5066
+ if ((st.mode & os.S_IFMT) == os.S_IFREG) {
5067
+ files.push(entry);
5068
+ } else if ((st.mode & os.S_IFMT) == os.S_IFDIR) {
5069
+ directories.push(entry);
5070
+ }
5071
+ }
5072
+ return { files: files, directories: directories };
5073
+ }
5074
+ function getDirectories(path) {
5075
+ var entries, err, st;
5076
+ var [entries, err] = os.readdir(path);
5077
+ if (err != 0)
5078
+ return [];
5079
+ var directories = [];
5080
+ for (var i = 0; i < entries.length; i++) {
5081
+ var entry = entries[i];
5082
+ var name = ts.combinePaths(path, entry);
5083
+ [st, err] = os.stat(name);
5084
+ if (err != 0)
5085
+ continue;
5086
+ if ((st.mode & os.S_IFMT) == os.S_IFDIR) {
5087
+ directories.push(entry);
5088
+ }
5089
+ }
5090
+ return directories;
5091
+ }
5092
+
5093
+ return {
5094
+ newLine: newLine,
5095
+ args: args,
5096
+ useCaseSensitiveFileNames: useCaseSensitiveFileNames,
5097
+ write: function(s) {
5098
+ std.out.puts(s);
5099
+ },
5100
+ readFile: function (path, _encoding) {
5101
+ var f, ret;
5102
+ try {
5103
+ f = std.open(path, "r");
5104
+ ret = f.readAsString();
5105
+ f.close();
5106
+ } catch(e) {
5107
+ ret = undefined;
5108
+ }
5109
+ return ret;
5110
+ },
5111
+ writeFile: function (path, data, writeByteOrderMark) {
5112
+ var f;
5113
+ try {
5114
+ // If `-` is provided as the fileName, output to stdout
5115
+ if (path === '-') {
5116
+ std.out.puts(data);
5117
+ return;
5118
+ }
5119
+ f = std.open(path, "w");
5120
+ f.puts(data);
5121
+ f.close();
5122
+ } catch(e) {
5123
+ }
5124
+ },
5125
+ resolvePath: function (s) { return s; },
5126
+ fileExists: function(path) {
5127
+ let [st, err] = os.stat(path);
5128
+ if (err != 0)
5129
+ return false;
5130
+ return (st.mode & os.S_IFMT) == os.S_IFREG;
5131
+ },
5132
+ deleteFile: function(path) {
5133
+ os.remove(path);
5134
+ },
5135
+ getModifiedTime: function(path) {
5136
+ let [st, err] = os.stat(path);
5137
+ if (err != 0)
5138
+ throw std.Error(err);
5139
+ return st.mtime; /* ms */
5140
+ },
5141
+ setModifiedTime: function(path, time) {
5142
+ os.utimes(path, time, time);
5143
+ },
5144
+ directoryExists: function(path) {
5145
+ let [st, err] = os.stat(path);
5146
+ if (err != 0)
5147
+ return false;
5148
+ return (st.mode & os.S_IFMT) == os.S_IFDIR;
5149
+ },
5150
+ createDirectory: function(path) {
5151
+ var ret;
5152
+ ret = os.mkdir(path);
5153
+ if (ret == -std.EEXIST)
5154
+ throw new std.Error(-ret);
5155
+ },
5156
+ getExecutingFilePath: function () {
5157
+ return executable_path;
5158
+ },
5159
+ getCurrentDirectory: function () {
5160
+ var [cwd, err] = os.getcwd();
5161
+ return cwd;
5162
+ },
5163
+ getDirectories: getDirectories,
5164
+ getEnvironmentVariable: function(name) {
5165
+ return std.getenv(name) || "";
5166
+ },
5167
+ readDirectory: function (path, extensions, excludes, includes, depth) {
5168
+ let [cwd, err] = os.getcwd();
5169
+ return ts.matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, cwd, depth, getAccessibleFileSystemEntries, realpath);
5170
+ },
5171
+ exit: function (exitCode) {
5172
+ std.exit(exitCode);
5173
+ },
5174
+ realpath: realpath,
5175
+ };
5176
+ }
5028
5177
var sys;
5029
- if (typeof process !== "undefined" && process.nextTick && !process.browser && typeof require !== "undefined") {
5178
+ if (typeof os !== "undefined") {
5179
+ sys = getQuickJSSystem();
5180
+ } else if (typeof process !== "undefined" && process.nextTick && !process.browser && typeof require !== "undefined") {
5030
5181
sys = getNodeSystem();
5031
5182
}
5032
5183
if (sys) {
0 commit comments