deno.land / x / ts_morph@22.0.0 / common / DenoRuntime.ts

DenoRuntime.ts
نووسراو ببینە
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import { ensureDir, ensureDirSync } from "https://deno.land/std@0.208.0/fs/ensure_dir.ts";import { expandGlob, expandGlobSync } from "https://deno.land/std@0.208.0/fs/expand_glob.ts";import * as stdPath from "https://deno.land/std@0.208.0/path/mod.ts";
// deno-lint-ignore no-explicit-any
export class DenoRuntime { fs = new DenoRuntimeFileSystem(); path = new DenoRuntimePath();
getEnvVar(name: string) { return Deno.env.get(name); }
getEndOfLine() { return Deno.build.os === "windows" ? "\r\n" : "\n"; }
getPathMatchesPattern(path: string, pattern: string) { return stdPath.globToRegExp(pattern, { extended: true, globstar: true, os: "linux", // use the same behaviour across all operating systems }).test(path); }}
class DenoRuntimePath { join(...paths: string[]) { return stdPath.join(...paths); }
normalize(path: string) { return stdPath.normalize(path); }
relative(from: string, to: string) { return stdPath.relative(from, to); }}
class DenoRuntimeFileSystem { delete(path: string) { return Deno.remove(path, { recursive: true }); }
deleteSync(path: string) { Deno.removeSync(path, { recursive: true }); }
readDirSync(dirPath: string) { return Array.from(Deno.readDirSync(dirPath)); }
readFile(filePath: string, _encoding = "utf-8") { return Deno.readTextFile(filePath); }
readFileSync(filePath: string, _encoding = "utf-8") { return Deno.readTextFileSync(filePath); }
writeFile(filePath: string, fileText: string) { return Deno.writeTextFile(filePath, fileText); }
writeFileSync(filePath: string, fileText: string) { return Deno.writeTextFileSync(filePath, fileText); }
async mkdir(dirPath: string) { await ensureDir(dirPath); }
mkdirSync(dirPath: string) { ensureDirSync(dirPath); }
move(srcPath: string, destPath: string) { return Deno.rename(srcPath, destPath); }
moveSync(srcPath: string, destPath: string) { Deno.renameSync(srcPath, destPath); }
copy(srcPath: string, destPath: string) { return Deno.copyFile(srcPath, destPath); }
copySync(srcPath: string, destPath: string) { return Deno.copyFileSync(srcPath, destPath); }
async stat(filePath: string) { try { const stat = await Deno.stat(filePath); return this.#toStat(stat); } catch (err) { if (err instanceof Deno.errors.NotFound) return undefined; else throw err; } }
statSync(path: string) { try { const stat = Deno.statSync(path); return this.#toStat(stat); } catch (err) { if (err instanceof Deno.errors.NotFound) return undefined; else throw err; } }
// deno-lint-ignore no-explicit-any #toStat(stat: any) { return { isFile() { return stat.isFile; }, isDirectory() { return stat.isDirectory; }, }; }
realpathSync(path: string) { return Deno.realPathSync(path); }
getCurrentDirectory(): string { return Deno.cwd(); }
async glob(patterns: ReadonlyArray<string>) { const { excludePatterns, pattern } = globPatternsToPattern(patterns); const result: string[] = []; const globEntries = expandGlob(pattern, { root: this.getCurrentDirectory(), extended: true, globstar: true, exclude: excludePatterns, }); for await (const globEntry of globEntries) { if (globEntry.isFile) result.push(globEntry.path); } return result; }
globSync(patterns: ReadonlyArray<string>) { const { excludePatterns, pattern } = globPatternsToPattern(patterns); const result: string[] = []; const globEntries = expandGlobSync(pattern, { root: this.getCurrentDirectory(), extended: true, globstar: true, exclude: excludePatterns, }); for (const globEntry of globEntries) { if (globEntry.isFile) result.push(globEntry.path); } return result; }
isCaseSensitive() { const platform = Deno.build.os; return platform !== "windows" && platform !== "darwin"; }}
function globPatternsToPattern(patterns: ReadonlyArray<string>) { const excludePatterns = []; const includePatterns = [];
for (const pattern of patterns) { if (isNegatedGlob(pattern)) excludePatterns.push(pattern); else includePatterns.push(pattern); }
return { excludePatterns, pattern: includePatterns.length === 0 ? "." : includePatterns.length === 1 ? includePatterns[0] : `{${includePatterns.join(",")}}`, };
function isNegatedGlob(glob: string) { // https://github.com/micromatch/is-negated-glob/blob/master/index.js return glob[0] === "!" && glob[1] !== "("; }}
ts_morph

Version Info

Tagged at
2 months ago