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

toddbluhm / env-cmd / 16075274977

04 Jul 2025 01:48PM UTC coverage: 96.807% (-1.4%) from 98.253%
16075274977

Pull #399

github

k-yle
feat: support loading TypeScript files
Pull Request #399: feat: support loading TypeScript files

292 of 319 branches covered (91.54%)

29 of 41 new or added lines in 5 files covered. (70.73%)

758 of 783 relevant lines covered (96.81%)

21.62 hits per line

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

98.39
/src/utils.ts
1
import { resolve } from 'node:path'
3✔
2
import { homedir } from 'node:os'
3✔
3
import { cwd } from 'node:process'
3✔
4

3✔
5
// Special file extensions that node can natively import
3✔
6
export const IMPORT_HOOK_EXTENSIONS = [
3✔
7
  '.json',
3✔
8
  '.js',
3✔
9
  '.cjs',
3✔
10
  '.mjs',
3✔
11
  '.ts',
3✔
12
  '.mts',
3✔
13
  '.cts',
3✔
14
  '.tsx',
3✔
15
];
3✔
16

3✔
17
/**
3✔
18
 * A simple function for resolving the path the user entered
3✔
19
 */
3✔
20
export function resolveEnvFilePath(userPath: string): string {
3✔
21
  // Make sure a home directory exist
63✔
22
  const home = homedir() as string | undefined
63✔
23
  if (home != null) {
63✔
24
    userPath = userPath.replace(/^~($|\/|\\)/, `${home}$1`)
60✔
25
  }
60✔
26
  return resolve(cwd(), userPath)
63✔
27
}
63✔
28
/**
3✔
29
 * A simple function that parses a comma separated string into an array of strings
3✔
30
 */
3✔
31
export function parseArgList(list: string): string[] {
3✔
32
  return list.split(',')
27✔
33
}
27✔
34

3✔
35
/**
3✔
36
 * A simple function to test if the value is a promise/thenable
3✔
37
 */
3✔
38
export function isPromise<T>(value?: T | PromiseLike<T>): value is PromiseLike<T> {
3✔
39
  return value != null
48✔
40
    && typeof value === 'object'
42✔
41
    && 'then' in value
33✔
42
    && typeof value.then === 'function'
15✔
43
}
48✔
44

3✔
45
/** @returns true if the error is `ERR_UNKNOWN_FILE_EXTENSION` */
3✔
46
export function isLoaderError(error: unknown): error is Error {
3✔
47
  return (
12✔
48
    error instanceof Error &&
12✔
49
    'code' in error &&
12!
NEW
50
    error.code === 'ERR_UNKNOWN_FILE_EXTENSION'
×
51
  );
12✔
52
}
12✔
53

3✔
54

3✔
55
// "Import Attributes" are only supported since node v18.20 and v20.10.
3✔
56
// For older node versions, we have to use "Import Assertions".
3✔
57
// TODO: remove this check when we drop support for node v20
3✔
58
const [major, minor] = process.version.slice(1).split('.').map(Number)
3✔
59
const legacyImportAssertions =
3✔
60
  (major === 18 && minor < 20) || (major === 20 && minor < 10)
3!
61

3✔
62
export const importAttributesKeyword = legacyImportAssertions ? 'assert' : 'with'
3!
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