This repository was archived by the owner on Oct 18, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.cts
73 lines (62 loc) · 1.47 KB
/
index.cts
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
const { fileURLToPath } = require('node:url');
async function test(description: string, testFunction: () => any | Promise<any>) {
try {
const result = await testFunction();
if (!result) { throw result; }
console.log(`✔ ${description}`);
} catch (error) {
console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`);
}
}
console.log('loaded ts-ext-cts/index.cts');
test(
'has CJS context',
() => typeof require !== 'undefined' || typeof module !== 'undefined',
);
test(
'name in error',
() => {
let nameInError;
try {
nameInError();
} catch (error) {
return error.message.includes('nameInError');
}
},
);
test(
'sourcemaps',
() => {
const stack = (new Error()).stack!;
const errorPosition = ':35:';
const isWindows = process.platform === 'win32';
let pathname = fileURLToPath(import.meta.url);
if (isWindows) {
// Remove drive letter
pathname = pathname.slice(2);
}
let pathIndex = stack.indexOf(`${pathname}${errorPosition}`);
if (
pathIndex === -1
&& isWindows
) {
// Convert backslash to slash
pathname = pathname.replace(/\\/g, '/');
pathIndex = stack.indexOf(`${pathname}${errorPosition}`);
}
return pathIndex > -1;
},
);
test(
'resolves optional node prefix',
() => import('node:fs').then(Boolean),
);
test(
'resolves required node prefix',
() => import('node:test').then(Boolean),
);
test(
'preserves names',
() => (function functionName() {}).name === 'functionName',
);
export default 1234;