Skip to content

Commit 436b8bd

Browse files
feat: move nursery to typescript
part of #10
1 parent a87da53 commit 436b8bd

File tree

9 files changed

+93
-37
lines changed

9 files changed

+93
-37
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,9 @@ dist
129129
.yarn/install-state.gz
130130
.pnp.*
131131

132+
# ignore generated parser files
132133
packages/**/parser.so
134+
# do not include copied directories
133135
packages/**/src
136+
# ignore generated ts files in scripts
137+
scripts/**/*.{js, d.ts}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"version": "0.0.1",
99
"description": "Monorepo for `@ast-grep/lang-*` packages",
1010
"scripts": {
11-
"postinstall": "pnpm -r copy-src",
11+
"preprepare": "pnpm -r copy-src",
1212
"test": "echo \"Error: no test specified\" && exit 1"
1313
},
1414
"keywords": [],

packages/toml/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"copy-src": "node nursery.js copy",
88
"build": "tree-sitter build -o parser.so",
9-
"postinstall": "node postinstall.js",
9+
"prepare": "node postinstall.js",
1010
"test": "node nursery.js test"
1111
},
1212
"files": [

pnpm-lock.yaml

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/nursery/index.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

scripts/nursery/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { cp } from 'fs/promises'
2+
import { parse, registerDynamicLanguage, SgRoot, DynamicLangRegistrations } from '@ast-grep/napi'
3+
import path from 'path'
4+
5+
async function copySrc(packageName: string) {
6+
const src = path.join(process.cwd(), 'node_modules', packageName, 'src')
7+
await cp(src, 'src', { recursive: true })
8+
}
9+
10+
/** Setup ast-grep/lang package's pre-release
11+
*
12+
**/
13+
interface SetupConfig {
14+
name: string
15+
languageRegistration: DynamicLangRegistrations[string]
16+
packageName: string
17+
testRunner: (parse: (c: string) => SgRoot) => void
18+
}
19+
20+
function test(setupConfig: SetupConfig) {
21+
const { name, languageRegistration, testRunner } = setupConfig
22+
registerDynamicLanguage({ [name]: languageRegistration })
23+
testRunner((code) => parse(name, code))
24+
}
25+
26+
/** Setup ast-grep/lang package's pre-release build and test */
27+
export function setup(setupConfig: SetupConfig) {
28+
const arg = process.argv[2]
29+
if (arg === 'copy') {
30+
copySrc(setupConfig.packageName)
31+
} else if (arg === 'test') {
32+
test(setupConfig)
33+
}
34+
}

scripts/nursery/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77
"keywords": [],
88
"author": "",
99
"license": "ISC",
10+
"scripts": {
11+
"prepare": "tsc"
12+
},
1013
"dependencies": {
11-
"tree-sitter-cli": "0.24.6",
12-
"@ast-grep/napi": "0.33.0"
14+
"@ast-grep/napi": "0.33.0",
15+
"tree-sitter-cli": "0.24.6"
1316
},
1417
"publishConfig": {
1518
"access": "public",
1619
"registry": "https://registry.npmjs.org/"
20+
},
21+
"devDependencies": {
22+
"typescript": "^5.7.3",
23+
"@types/node": "22.10.5"
1724
}
1825
}

scripts/nursery/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+
}

tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"customConditions": ["dev"],
5+
"module": "nodenext",
6+
"moduleResolution": "nodenext",
7+
"strict": true,
8+
"esModuleInterop": true,
9+
"forceConsistentCasingInFileNames": true
10+
},
11+
"exclude": [
12+
"node_modules",
13+
"dist"
14+
]
15+
}

0 commit comments

Comments
 (0)