Skip to content

Commit 9346e04

Browse files
feat: migrate setup to ts
fix #10
1 parent a26eaa3 commit 9346e04

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

pnpm-lock.yaml

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/nursery/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"author": "",
99
"license": "ISC",
1010
"scripts": {
11-
"compile": "tsc"
11+
"compile": "tsc",
12+
"prepublishOnly": "tsc"
1213
},
1314
"dependencies": {
1415
"@ast-grep/napi": "0.33.0",
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
const { execSync } = require('child_process')
2-
const fs = require('fs')
3-
const path = require('path')
1+
import { execSync } from 'child_process'
2+
import fs from 'fs'
3+
import path from 'path'
44

55
/**
66
* Log to console
7-
* @param {...string} args
87
*/
9-
function log(...args) {
8+
function log(...args: unknown[]) {
109
console.debug(`@ast-grep/lang:`, ...args)
1110
}
1211

1312
/**
1413
* Move prebuild or build parser
15-
* @param {string} dir
1614
*/
17-
async function postinstall(dir) {
15+
async function postinstall(dir: string) {
1816
const parser = path.join(dir, 'parser.so')
1917
if (fs.existsSync(parser)) {
2018
log('parser already exists, skipping build')
@@ -29,28 +27,27 @@ async function postinstall(dir) {
2927
log('building parser')
3028
try {
3129
execSync('npm run build')
32-
} catch (e) {
30+
} catch (e: unknown) {
3331
log('build failed, please ensure tree-sitter-cli is installed as peer dependency')
3432
log(e)
3533
}
3634
}
3735

38-
const PLATFORM_MAP = {
36+
const PLATFORM_MAP: Record<string, string> = {
3937
darwin: 'macOS',
4038
linux: 'Linux',
4139
win32: 'Windows',
4240
}
4341

44-
const ARCH_MAP = {
42+
const ARCH_MAP: Record<string, string> = {
4543
x64: 'x64',
4644
arm64: 'ARM64',
4745
}
4846

4947
/**
5048
* Resolve prebuild path
51-
* @param {string} dir
5249
*/
53-
function resolvePrebuild(dir) {
50+
function resolvePrebuild(dir: string) {
5451
const os = PLATFORM_MAP[process.platform]
5552
const arch = ARCH_MAP[process.arch]
5653
const prebuild = path.join(dir, 'prebuilds', `prebuild-${os}-${arch}`, 'parser.so')
@@ -62,4 +59,4 @@ function resolvePrebuild(dir) {
6259
return prebuild
6360
}
6461

65-
exports.postinstall = postinstall
62+
export { postinstall }

scripts/setup/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@
77
"keywords": [],
88
"author": "",
99
"license": "ISC",
10+
"scripts": {
11+
"compile": "tsc",
12+
"prepublishOnly": "tsc"
13+
},
1014
"publishConfig": {
1115
"access": "public",
1216
"registry": "https://registry.npmjs.org/"
17+
},
18+
"devDependencies": {
19+
"typescript": "^5.7.3",
20+
"@types/node": "22.10.5"
1321
}
1422
}

scripts/setup/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../tsconfig.json"
3+
}

0 commit comments

Comments
 (0)