Skip to content

Commit

Permalink
fix: compile source using swc
Browse files Browse the repository at this point in the history
Can no longer compile with TypeScript with the
allowImportingTsExtensions set
  • Loading branch information
coderbyheart committed Dec 28, 2024
1 parent 8da95f0 commit ed314e1
Show file tree
Hide file tree
Showing 6 changed files with 1,774 additions and 11 deletions.
38 changes: 38 additions & 0 deletions npm-compile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Compile source for NPM
*/

import swc from '@swc/core'
import { glob } from 'glob'
import { mkdirSync, writeFileSync } from 'node:fs'
import path, { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { updateImports } from './src/updateImports.ts'

const __dirname = dirname(fileURLToPath(import.meta.url))

for (const file of glob.sync('src/**/*.ts')) {
let compiled = (
await swc.transformFile(file, {
jsc: {
parser: {
syntax: 'typescript',
},
target: 'es2024',
},
module: {
type: 'es6',
},
})
).code

compiled = updateImports(compiled)

const targetFile = path.join(__dirname, 'dist', file.replace(/\.ts$/, '.js'))

mkdirSync(dirname(targetFile), { recursive: true })

writeFileSync(targetFile, compiled, 'utf8')

console.log(file)
}
Loading

0 comments on commit ed314e1

Please sign in to comment.