-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathBrowserRuntime.ts
120 lines (91 loc) · 2.93 KB
/
BrowserRuntime.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
import * as minimatch from "minimatch";
import { Runtime, RuntimeDirEntry, RuntimeFileInfo, RuntimeFileSystem, RuntimePath } from "./Runtime";
const path = require("path-browserify");
export class BrowserRuntime implements Runtime {
fs = new BrowserRuntimeFileSystem();
path = new BrowserRuntimePath();
getEnvVar(_name: string) {
return undefined;
}
getEndOfLine() {
return "\n";
}
getPathMatchesPattern(path: string, pattern: string) {
return minimatch.minimatch(path, pattern);
}
}
class BrowserRuntimePath implements RuntimePath {
join(...paths: string[]) {
return path.join(...paths);
}
normalize(pathToNormalize: string) {
return path.normalize(pathToNormalize);
}
relative(from: string, to: string) {
return path.relative(from, to);
}
}
class BrowserRuntimeFileSystem implements RuntimeFileSystem {
#errorMessage =
"Access to the file system is not supported in the browser. Please use an in-memory file system (specify `useInMemoryFileSystem: true` when creating the project).";
delete(_path: string) {
return Promise.reject(new Error(this.#errorMessage));
}
deleteSync(_path: string) {
throw new Error(this.#errorMessage);
}
readDirSync(_dirPath: string): RuntimeDirEntry[] {
throw new Error(this.#errorMessage);
}
readFile(_filePath: string, _encoding?: string): Promise<string> {
return Promise.reject(new Error(this.#errorMessage));
}
readFileSync(_filePath: string, _encoding?: string): string {
throw new Error(this.#errorMessage);
}
writeFile(_filePath: string, _fileText: string) {
return Promise.reject(new Error(this.#errorMessage));
}
writeFileSync(_filePath: string, _fileText: string) {
throw new Error(this.#errorMessage);
}
mkdir(_dirPath: string) {
return Promise.reject(new Error(this.#errorMessage));
}
mkdirSync(_dirPath: string) {
throw new Error(this.#errorMessage);
}
move(_srcPath: string, _destPath: string) {
return Promise.reject(new Error(this.#errorMessage));
}
moveSync(_srcPath: string, _destPath: string) {
throw new Error(this.#errorMessage);
}
copy(_srcPath: string, _destPath: string) {
return Promise.reject(new Error(this.#errorMessage));
}
copySync(_srcPath: string, _destPath: string) {
throw new Error(this.#errorMessage);
}
stat(_path: string): Promise<RuntimeFileInfo> {
return Promise.reject(new Error(this.#errorMessage));
}
statSync(_path: string): RuntimeFileInfo {
throw new Error(this.#errorMessage);
}
realpathSync(_path: string): string {
throw new Error(this.#errorMessage);
}
getCurrentDirectory(): string {
throw new Error(this.#errorMessage);
}
glob(_patterns: ReadonlyArray<string>): Promise<string[]> {
return Promise.reject(new Error(this.#errorMessage));
}
globSync(_patterns: ReadonlyArray<string>): string[] {
throw new Error(this.#errorMessage);
}
isCaseSensitive() {
return true;
}
}