-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can no longer compile with TypeScript with the allowImportingTsExtensions set
- Loading branch information
1 parent
8da95f0
commit ed314e1
Showing
6 changed files
with
1,774 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.