| 52 | /(const|let|var)\s+__filename\s*=\s*(?:(\/\*\s*@__PURE__\s*\*\/)\s*)?getFilename\s*\(\s*\)\s*;?/g, |
| 53 | ]; |
| 54 | function tryTransform(filename, content, tsx = true) { |
| 55 | for (const regex of remove) content = content.replace(regex, ''); |
| 56 | return esbuild.transformSync(content, { |
| 57 | tsconfigRaw: '{"compilerOptions":{"experimentalDecorators":true}}', |
| 58 | sourcefile: filename, |
| 59 | sourcemap: 'both', |
| 60 | format: 'cjs', |
| 61 | loader: tsx ? 'tsx' : 'ts', |
| 62 | target: `node${major}.${minor}`, |
| 63 | jsx: 'transform', |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | function transform(filename, tsx = true) { |
| 68 | const code = fs.readFileSync(filename, 'utf-8'); |