11#!/usr/bin/env node
2- import nanoSpawn , { SubprocessError } from "nano-spawn" ;
2+ import nanoSpawn , { SubprocessError , type Result } from "nano-spawn" ;
33import { parseArgs } from "node:util" ;
44import { basename , dirname , join , relative } from "node:path" ;
55import { cwd , exit , stdout } from "node:process" ;
66import { EOL , platform } from "node:os" ;
77import { readFileSync , writeFileSync , accessSync , truncateSync , statSync } from "node:fs" ;
88import pkg from "./package.json" with { type : "json" } ;
99import { parse } from "smol-toml" ;
10- import type { Result } from "nano-spawn" ;
1110
1211export type SemverLevel = "patch" | "minor" | "major" ;
1312
@@ -32,7 +31,7 @@ function replaceTokens(str: string, newVersion: string): string {
3231 . replace ( / _ P A T C H _ / g, patch ) ;
3332}
3433
35- function incrementSemver ( str : string , level : SemverLevel ) : string {
34+ function incrementSemver ( str : string , level : string ) : string {
3635 if ( ! isSemver ( str ) ) throw new Error ( `Invalid semver: ${ str } ` ) ;
3736 if ( level === "major" ) return str . replace ( / ( [ 0 - 9 ] + ) \. [ 0 - 9 ] + \. [ 0 - 9 ] + ( .* ) / , ( _ , m1 , m2 ) => {
3837 return `${ Number ( m1 ) + 1 } .0.0${ m2 } ` ;
@@ -45,7 +44,7 @@ function incrementSemver(str: string, level: SemverLevel): string {
4544 } ) ;
4645}
4746
48- function find ( filename : string , dir : string , stopDir ?: string ) : string | null {
47+ function findUp ( filename : string , dir : string , stopDir ?: string ) : string | null {
4948 const path = join ( dir , filename ) ;
5049
5150 try {
@@ -57,7 +56,7 @@ function find(filename: string, dir: string, stopDir?: string): string | null {
5756 if ( ( stopDir && path === stopDir ) || parent === dir ) {
5857 return null ;
5958 } else {
60- return find ( filename , parent , stopDir ) ;
59+ return findUp ( filename , parent , stopDir ) ;
6160 }
6261}
6362
@@ -232,7 +231,7 @@ async function main(): Promise<void> {
232231 }
233232
234233 const pwd = cwd ( ) ;
235- const gitDir = find ( ".git" , pwd ) ;
234+ const gitDir = findUp ( ".git" , pwd ) ;
236235 let projectRoot = gitDir ? dirname ( gitDir ) : null ;
237236 if ( ! projectRoot ) projectRoot = pwd ;
238237
@@ -269,7 +268,7 @@ async function main(): Promise<void> {
269268 files = files . map ( file => relative ( pwd , file ) ) ;
270269
271270 // set new version
272- const newVersion = incrementSemver ( baseVersion , level as SemverLevel ) ;
271+ const newVersion = incrementSemver ( baseVersion , level ) ;
273272
274273 const replacements : Array < { re : RegExp , replacement : string } > = [ ] ;
275274 if ( args . replace ?. length ) {
0 commit comments