mtcute/e2e/ts/build-esm.cjs
Alina Tumanova f5976a2d74
ESM + end-to-end tests (#11)
* feat: moved tl-runtime to esm and native ArrayBuffers

* feat: migration to esm

* fix(core): web-related fixes

* test: finally, some good fucking e2e

* chore: fixed linters etc

* ci: added e2e to ci

* build(tl): fixed gen-code on node 20

* fix: codegen Uint8Array, not Buffer

never `git reset --hard` kids

* build: only do type-aware linting for `packages/*`

* build: ignore no-unresolved in ci for e2e

* fix: node 16 doesn't have subtle crypto apparently?

* fix(tests): use Uint8Array

for gods sake please can i just merge this already

* ci: don't parallel tasks in ci

because machines are utter garbage and it may just randomly break

* ci: pass secrets to e2e tests

* ci: separate cli command for ci

apparently im retarded

* fix: run codegen in e2e

im actually retarded

* ci: more fixes for e2e

* ci: debugging stuff

* ci: still debugging

* ci: hopefully fix ci???
2023-10-16 19:23:53 +03:00

52 lines
1.3 KiB
JavaScript

/* eslint-disable no-restricted-globals */
const fs = require('fs')
const path = require('path')
const cp = require('child_process')
const glob = require('glob')
function fixForEsm() {
const modified = {}
fs.writeFileSync(path.join(__dirname, 'package.json'), JSON.stringify({ type: 'module' }))
for (const file of glob.sync('tests/**/*.ts')) {
let content = fs.readFileSync(file, 'utf8')
if (content.includes('@fix-import')) {
modified[file] = content
content = content.replace(/(?<=@fix-import\nimport.*?')(.*?)(?='$)/gms, '$1.js')
fs.writeFileSync(file, content)
}
}
return () => {
fs.writeFileSync(path.join(__dirname, 'package.json'), JSON.stringify({ type: 'commonjs' }))
for (const file of Object.keys(modified)) {
fs.writeFileSync(file, modified[file])
}
}
}
exports.fixForEsm = fixForEsm
function main() {
const restore = fixForEsm()
let error = null
try {
cp.execSync('pnpm exec tsc --outDir dist/esm', { stdio: 'inherit' })
fs.writeFileSync(path.join(__dirname, 'dist/esm/package.json'), JSON.stringify({ type: 'module' }))
} catch (e) {
error = e
}
restore()
if (error) {
throw error
}
}
if (require.main === module) {
main()
}