11
2- import { readFileSync , writeFileSync } from "node:fs" ;
2+ import { readdirSync , readFileSync , writeFileSync } from "node:fs" ;
33import { Biome , Distribution } from "@biomejs/js-api" ;
4- import { config , createResultFilePath , errorFilePath , finalResultPath , formatterErrorFilePath , shouldTakeABreath , startFilePath } from "./config" ;
4+ import { config , createResultFilePath , errorFilePath , finalResultPath , formatterErrorFilePath , resultsDirectory , resumeMode , shouldTakeABreath , startFilePath } from "./config" ;
55import { VirtualTypeScriptEnvironment } from "@typescript/vfs" ;
66import ts from "typescript" ;
77import { inspect } from "node:util" ;
8+ import { join } from "node:path" ;
89
910export interface ProgramRun {
1011 env : VirtualTypeScriptEnvironment ;
@@ -172,7 +173,8 @@ export const finalizeProgram = async ({
172173 resultTypeName : string ;
173174 env : VirtualTypeScriptEnvironment ;
174175} ) => {
175- const relativeLastResult = createResultFilePath ( lastInstructionCount )
176+ const absoluteLastResult = createResultFilePath ( lastInstructionCount )
177+ const relativeLastResult = absoluteLastResult . replace ( resultsDirectory , "." ) ;
176178
177179 const readStringImportLine = config . readStringFromMemory
178180 ? [
@@ -252,4 +254,27 @@ export const printType = (typeString: string) => {
252254 }
253255
254256 return output ;
255- } ;
257+ } ;
258+
259+ export const getStartFilePath = ( ) => {
260+ if ( ! resumeMode ) {
261+ return startFilePath ;
262+ }
263+
264+ const files = readdirSync ( resultsDirectory ) ;
265+
266+ const resumeIndex = process . argv . indexOf ( "--resume" ) ;
267+ const maybeResumeFile = process . argv [ resumeIndex + 1 ] ;
268+ if ( maybeResumeFile ) {
269+ if ( ! files . includes ( maybeResumeFile ) ) {
270+ throw new Error ( `specified resume file '${ maybeResumeFile } ' not found in ${ resultsDirectory } ` ) ;
271+ }
272+ return join ( resultsDirectory , maybeResumeFile ) ;
273+ }
274+
275+ const filenames = files . filter ( file => {
276+ return file . startsWith ( "result-" ) && file . endsWith ( ".ts" ) ;
277+ } ) . sort ( ) ;
278+
279+ return join ( resultsDirectory , filenames [ filenames . length - 1 ] ) ;
280+ }
0 commit comments