-
-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathjest.nest-esm.transform.js
More file actions
25 lines (24 loc) 路 804 Bytes
/
Copy pathjest.nest-esm.transform.js
File metadata and controls
25 lines (24 loc) 路 804 Bytes
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
// NestJS 12 ships ESM only. Compile it to CommonJS for jest, rewriting the one
// ESM-only construct it uses (`import.meta.url` in @nestjs/common's loadPackage).
// ponytail: string swap, drop this file once the specs run as native ESM or on vitest.
const ts = require('typescript');
module.exports = {
process(src, filename) {
const { outputText, sourceMapText } = ts.transpileModule(
src.replaceAll(
'import.meta.url',
"require('url').pathToFileURL(__filename).href",
),
{
fileName: filename,
compilerOptions: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2022,
esModuleInterop: true,
sourceMap: true,
},
},
);
return { code: outputText, map: sourceMapText };
},
};