#!/usr/bin/env -S node --experimental-strip-types --no-warnings // Usage: node --experimental-strip-types --no-warnings makeManual.mts [...testNames] import * as fs from "fs"; import * as path from "path"; const scriptsDir = import.meta.dirname; const manualTestsPath = path.join(scriptsDir, "manualTests.txt"); const genDir = path.join(scriptsDir, "../", "tests", "gen"); const manualDir = path.join(scriptsDir, "../", "tests", "manual"); const submoduleDir = path.join(scriptsDir, "../../../", "_submodules", "TypeScript", "tests", "cases", "fourslash"); function main() { const args = process.argv.slice(2); if (args.length === 0) { console.error("Please provide the name of the generated test file."); process.exit(1); } const testNames = []; for (const arg of args) { const testName = arg; const testFileName = testName; const genTestFile = path.join(genDir, testFileName + "_test.go"); const submoduleTestFile = path.join(submoduleDir, testFileName + ".ts"); const submoduleServerTestFile = path.join(submoduleDir, "server", testFileName + ".ts"); let testKind: "gen" | "submodule" | "submoduleServer" | undefined; if (fs.existsSync(genTestFile)) { testKind = "gen"; } else if (fs.existsSync(submoduleTestFile)) { testKind = "submodule"; } else if (fs.existsSync(submoduleServerTestFile)) { testKind = "submoduleServer"; } if (!testKind) { console.error( `Could not find test neither as '${genTestFile}', nor as '${submoduleTestFile}' or '${submoduleServerTestFile}'.` + `Make sure the test exists in the gen directory or in the submodule.`, ); process.exit(1); } if (!fs.existsSync(manualDir)) { fs.mkdirSync(manualDir, { recursive: true }); } if (testKind === "gen") { const manualTestFile = path.join(manualDir, path.basename(genTestFile)); markAsManual(genTestFile, manualTestFile); } testNames.push(testName); } let manualTests: string[] = []; if (fs.existsSync(manualTestsPath)) { const content = fs.readFileSync(manualTestsPath, "utf-8"); manualTests = content.split("\n").map(line => line.trim()).filter(line => line.length > 0); } for (const testName of testNames) { if (!manualTests.includes(testName)) { manualTests.push(testName); } } manualTests.sort((a, b) => a.localeCompare(b, "en-US")); fs.writeFileSync(manualTestsPath, [...manualTests, ""].join("\n"), "utf-8"); } function markAsManual(genFilePath: string, manualFilePath: string) { const content = fs.readFileSync(genFilePath, "utf-8"); const updatedContent = content .replace(/^\/\/ Code generated by convertFourslash; DO NOT EDIT\.\n\/\/ To modify this test, run .*\n\n/m, "") .replace(/^\s*fourslash\.SkipIfFailing\(t\)\s*$/m, ""); fs.writeFileSync(manualFilePath, updatedContent, "utf-8"); fs.rmSync(genFilePath); } main();