Skip to content

Commit 7c20a56

Browse files
committed
fix: update dependencies
Migrate to Native TS.
1 parent 889e1d8 commit 7c20a56

9 files changed

Lines changed: 1254 additions & 179 deletions

File tree

.github/workflows/test-and-release.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ on: push
55
permissions:
66
contents: write
77
issues: write
8+
id-token: write
89

910
env:
10-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1111
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1212

1313
jobs:
@@ -20,12 +20,10 @@ jobs:
2020
with:
2121
node-version: "24.x"
2222
cache: "npm"
23-
- name: Authenticate with NPM registry
24-
run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
2523
- name: Install dependencies
2624
run: npm ci --no-audit
2725
- name: Compile
28-
run: npx tsc
26+
run: npx tsgo
2927
- name: Check source code with eslint
3028
run: npx eslint .
3129
- name: Check if source code is properly formatted

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
node_modules/
22
npm-debug.log
3-
dist/
3+
npm/

.npm/compile.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Compile source for NPM
3+
*/
4+
5+
import swc from '@swc/core'
6+
import { mkdirSync, rmSync, writeFileSync } from 'node:fs'
7+
import { glob } from 'node:fs/promises'
8+
import path, { dirname } from 'node:path'
9+
import { fileURLToPath } from 'node:url'
10+
import tsconfig from './tsconfig.npm.json' with { type: 'json' }
11+
import { updateImports } from './updateImports.ts'
12+
13+
const __dirname = dirname(fileURLToPath(import.meta.url))
14+
15+
const outDir = path.join(__dirname, '..', 'npm')
16+
17+
try {
18+
rmSync(outDir, { recursive: true, force: true })
19+
} catch {
20+
// pass
21+
}
22+
23+
for await (const file of glob(
24+
`./.npm/{${tsconfig.include.join(',')}}/**/*.ts`,
25+
)) {
26+
if (file.endsWith('.spec.ts')) continue
27+
let compiled = (
28+
await swc.transformFile(file, {
29+
jsc: {
30+
parser: {
31+
syntax: 'typescript',
32+
},
33+
target: 'es2024',
34+
},
35+
module: {
36+
type: 'es6',
37+
},
38+
})
39+
).code
40+
41+
compiled = updateImports(compiled)
42+
43+
const targetFile = path.join(outDir, file.replace(/\.ts$/, '.js'))
44+
45+
mkdirSync(dirname(targetFile), { recursive: true })
46+
47+
writeFileSync(targetFile, compiled, 'utf8')
48+
49+
console.log(file)
50+
}

.npm/tsconfig.npm.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"emitDeclarationOnly": true,
5+
"declaration": true,
6+
"noEmit": false
7+
},
8+
"include": ["../src"]
9+
}

.npm/updateImports.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import assert from 'node:assert'
2+
import { describe, it } from 'node:test'
3+
import { updateImports } from './updateImports.ts'
4+
5+
void describe('updateImports', () => {
6+
void it('replaces .ts with .js in relative imports', () => {
7+
const input = `import { foo } from './bar.ts';`
8+
const expected = `import { foo } from './bar.js';`
9+
assert.equal(updateImports(input), expected)
10+
})
11+
})

.npm/updateImports.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const updateImports = (source: string): string =>
2+
source.replace(/from ['"](.+?)\.ts['"]/g, "from '$1.js'")

0 commit comments

Comments
 (0)