• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 19549987525

20 Nov 2025 08:11PM UTC coverage: 80.769% (+4.3%) from 76.433%
19549987525

push

github

web-flow
ci: run tests on commits to master and next (#11783)

Co-authored-by: Oleg "OSA413" Sokolov <OSA413@users.noreply.github.com>

26500 of 32174 branches covered (82.36%)

Branch coverage included in aggregate %.

91252 of 113615 relevant lines covered (80.32%)

88980.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.21
/src/platform/PlatformTools.ts
1
import ansi from "ansis"
26✔
2
import dotenv from "dotenv"
26✔
3
import fs from "fs"
26✔
4
import path from "path"
26✔
5
import { highlight } from "sql-highlight"
26✔
6
import { format as sqlFormat } from "@sqltools/formatter"
26✔
7
import { type Config as SqlFormatterConfig } from "@sqltools/formatter/lib/core/types"
26✔
8
import { type DatabaseType } from "../driver/types/DatabaseType"
26✔
9

26✔
10
export { EventEmitter } from "events"
26✔
11
export { ReadStream } from "fs"
26✔
12
export { Readable, Writable } from "stream"
26✔
13

26✔
14
/**
26✔
15
 * Platform-specific tools.
26✔
16
 */
26✔
17
export class PlatformTools {
26✔
18
    /**
26✔
19
     * Type of the currently running platform.
26✔
20
     */
26✔
21
    static type: "browser" | "node" = "node"
26✔
22

26✔
23
    /**
26✔
24
     * Gets global variable where global stuff can be stored.
26✔
25
     */
26✔
26
    static getGlobalVariable(): any {
26✔
27
        return global
257,220✔
28
    }
257,220✔
29

26✔
30
    /**
26✔
31
     * Loads ("require"-s) given file or package.
26✔
32
     * This operation only supports on node platform
26✔
33
     */
26✔
34
    static load(name: string): any {
26✔
35
        // if name is not absolute or relative, then try to load package from the node_modules of the directory we are currently in
18,852✔
36
        // this is useful when we are using typeorm package globally installed and it accesses drivers
18,852✔
37
        // that are not installed globally
18,852✔
38

18,852✔
39
        try {
18,852✔
40
            // switch case to explicit require statements for webpack compatibility.
18,852✔
41
            switch (name) {
18,852✔
42
                /**
18,852✔
43
                 * spanner
18,852✔
44
                 */
18,852✔
45
                case "spanner":
18,852!
46
                    return require("@google-cloud/spanner")
×
47

18,852✔
48
                /**
18,852✔
49
                 * mongodb
18,852✔
50
                 */
18,852✔
51
                case "mongodb":
18,852✔
52
                    return require("mongodb")
298✔
53

18,852✔
54
                /**
18,852✔
55
                 * hana
18,852✔
56
                 */
18,852✔
57
                case "@sap/hana-client":
18,852✔
58
                    return require("@sap/hana-client")
866✔
59

18,852✔
60
                case "@sap/hana-client/extension/Stream":
18,852✔
61
                    return require("@sap/hana-client/extension/Stream")
866✔
62

18,852✔
63
                /**
18,852✔
64
                 * mysql
18,852✔
65
                 */
18,852✔
66
                case "mysql":
18,852✔
67
                    return require("mysql")
2,314✔
68

18,852✔
69
                case "mysql2":
18,852✔
70
                    return require("mysql2")
2,130✔
71

18,852✔
72
                /**
18,852✔
73
                 * oracle
18,852✔
74
                 */
18,852✔
75
                case "oracledb":
18,852✔
76
                    return require("oracledb")
904✔
77

18,852✔
78
                /**
18,852✔
79
                 * postgres
18,852✔
80
                 */
18,852✔
81
                case "pg":
18,852✔
82
                    return require("pg")
3,143✔
83

18,852✔
84
                case "pg-native":
18,852✔
85
                    return require("pg-native")
3,143✔
86

18,852✔
87
                case "pg-query-stream":
18,852✔
88
                    return require("pg-query-stream")
10✔
89

18,852✔
90
                case "typeorm-aurora-data-api-driver":
18,852!
91
                    return require("typeorm-aurora-data-api-driver")
×
92

18,852✔
93
                /**
18,852✔
94
                 * redis
18,852✔
95
                 */
18,852✔
96
                case "redis":
18,852!
97
                    return require("redis")
×
98

18,852✔
99
                case "ioredis":
18,852!
100
                    return require("ioredis")
×
101

18,852✔
102
                /**
18,852✔
103
                 * better-sqlite3
18,852✔
104
                 */
18,852✔
105
                case "better-sqlite3":
18,852✔
106
                    return require("better-sqlite3")
1,416✔
107

18,852✔
108
                /**
18,852✔
109
                 * sqlite
18,852✔
110
                 */
18,852✔
111
                case "sqlite3":
18,852✔
112
                    return require("sqlite3")
1,494✔
113

18,852✔
114
                /**
18,852✔
115
                 * sql.js
18,852✔
116
                 */
18,852✔
117
                case "sql.js":
18,852✔
118
                    return require("sql.js")
1,290✔
119

18,852✔
120
                /**
18,852✔
121
                 * sqlserver
18,852✔
122
                 */
18,852✔
123
                case "mssql":
18,852✔
124
                    return require("mssql")
978✔
125

18,852✔
126
                /**
18,852✔
127
                 * react-native-sqlite
18,852✔
128
                 */
18,852✔
129
                case "react-native-sqlite-storage":
18,852!
130
                    return require("react-native-sqlite-storage")
×
131
            }
18,852✔
132
        } catch (err) {
18,852✔
133
            return require(path.resolve(
3,143✔
134
                process.cwd() + "/node_modules/" + name,
3,143✔
135
            ))
3,143✔
136
        }
3,143✔
137

×
138
        // If nothing above matched and we get here, the package was not listed within PlatformTools
×
139
        // and is an Invalid Package.  To make it explicit that this is NOT the intended use case for
×
140
        // PlatformTools.load - it's not just a way to replace `require` all willy-nilly - let's throw
×
141
        // an error.
×
142
        throw new TypeError(`Invalid Package for PlatformTools.load: ${name}`)
×
143
    }
×
144

26✔
145
    /**
26✔
146
     * Normalizes given path. Does "path.normalize" and replaces backslashes with forward slashes on Windows.
26✔
147
     */
26✔
148
    static pathNormalize(pathStr: string): string {
26✔
149
        let normalizedPath = path.normalize(pathStr)
14,358✔
150
        if (process.platform === "win32")
14,358✔
151
            normalizedPath = normalizedPath.replace(/\\/g, "/")
14,358!
152
        return normalizedPath
14,358✔
153
    }
14,358✔
154

26✔
155
    /**
26✔
156
     * Gets file extension. Does "path.extname".
26✔
157
     */
26✔
158
    static pathExtname(pathStr: string): string {
26✔
159
        return path.extname(pathStr)
56,399✔
160
    }
56,399✔
161

26✔
162
    /**
26✔
163
     * Resolved given path. Does "path.resolve".
26✔
164
     */
26✔
165
    static pathResolve(pathStr: string): string {
26✔
166
        return path.resolve(pathStr)
28,274✔
167
    }
28,274✔
168

26✔
169
    /**
26✔
170
     * Synchronously checks if file exist. Does "fs.existsSync".
26✔
171
     */
26✔
172
    static fileExist(pathStr: string): boolean {
26✔
173
        return fs.existsSync(pathStr)
1,881✔
174
    }
1,881✔
175

26✔
176
    static readFileSync(filename: string): Buffer {
26✔
177
        return fs.readFileSync(filename)
6✔
178
    }
6✔
179

26✔
180
    static appendFileSync(filename: string, data: any): void {
26✔
181
        fs.appendFileSync(filename, data)
1,129✔
182
    }
1,129✔
183

26✔
184
    static async writeFile(path: string, data: any): Promise<void> {
26✔
185
        return fs.promises.writeFile(path, data)
42✔
186
    }
42✔
187

26✔
188
    /**
26✔
189
     * Loads a dotenv file into the environment variables.
26✔
190
     *
26✔
191
     * @param path The file to load as a dotenv configuration
26✔
192
     */
26✔
193
    static dotenv(pathStr: string): void {
26✔
194
        dotenv.config({ path: pathStr })
78✔
195
    }
78✔
196

26✔
197
    /**
26✔
198
     * Gets environment variable.
26✔
199
     */
26✔
200
    static getEnvVariable(name: string): any {
26✔
201
        return process.env[name]
2,668✔
202
    }
2,668✔
203

26✔
204
    /**
26✔
205
     * Highlights sql string to be printed in the console.
26✔
206
     */
26✔
207
    static highlightSql(sql: string) {
26✔
208
        return highlight(sql, {
14✔
209
            colors: {
14✔
210
                keyword: ansi.blueBright.open,
14✔
211
                function: ansi.magentaBright.open,
14✔
212
                number: ansi.green.open,
14✔
213
                string: ansi.white.open,
14✔
214
                identifier: ansi.white.open,
14✔
215
                special: ansi.white.open,
14✔
216
                bracket: ansi.white.open,
14✔
217
                comment: ansi.gray.open,
14✔
218
                clear: ansi.reset.open,
14✔
219
            },
14✔
220
        })
14✔
221
    }
14✔
222

26✔
223
    /**
26✔
224
     * Pretty-print sql string to be print in the console.
26✔
225
     */
26✔
226
    static formatSql(sql: string, dataSourceType?: DatabaseType): string {
26✔
227
        const databaseLanguageMap: Record<
78✔
228
            string,
78✔
229
            SqlFormatterConfig["language"]
78✔
230
        > = {
78✔
231
            oracle: "pl/sql",
78✔
232
        }
78✔
233

78✔
234
        const databaseLanguage = dataSourceType
78✔
235
            ? databaseLanguageMap[dataSourceType] || "sql"
78!
236
            : "sql"
78✔
237

78✔
238
        return sqlFormat(sql, {
78✔
239
            language: databaseLanguage,
78✔
240
            indent: "    ",
78✔
241
        })
78✔
242
    }
78✔
243

26✔
244
    /**
26✔
245
     * Logging functions needed by AdvancedConsoleLogger
26✔
246
     */
26✔
247
    static logInfo(prefix: string, info: any) {
26✔
248
        console.log(ansi.gray.underline(prefix), info)
×
249
    }
×
250

26✔
251
    static logError(prefix: string, error: any) {
26✔
252
        console.log(ansi.underline.red(prefix), error)
×
253
    }
×
254

26✔
255
    static logWarn(prefix: string, warning: any) {
26✔
256
        console.log(ansi.underline.yellow(prefix), warning)
28✔
257
    }
28✔
258

26✔
259
    static log(message: string) {
26✔
260
        console.log(ansi.underline(message))
36✔
261
    }
36✔
262

26✔
263
    static info(info: any) {
26✔
264
        return ansi.gray(info)
×
265
    }
×
266

26✔
267
    static error(error: any) {
26✔
268
        return ansi.red(error)
×
269
    }
×
270

26✔
271
    static warn(message: string) {
26✔
272
        return ansi.yellow(message)
×
273
    }
×
274

26✔
275
    static logCmdErr(prefix: string, err?: any) {
26✔
276
        console.log(ansi.black.bgRed(prefix))
×
277
        if (err) console.error(err)
×
278
    }
×
279
}
26✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc