@@ -6,6 +6,7 @@ import { task } from "hereby";
66import assert from "node:assert" ;
77import crypto from "node:crypto" ;
88import fs from "node:fs" ;
9+ import { createRequire } from "node:module" ;
910import os from "node:os" ;
1011import path from "node:path" ;
1112import url from "node:url" ;
@@ -347,6 +348,9 @@ async function runGenerateGo() {
347348 for ( const generate of goGenerateActions ) {
348349 await generate ( ) ;
349350 }
351+ // These generators load Go packages, so all generated Go sources must be current.
352+ await runGenerateEnums ( ) ;
353+ await runGenerateAPI ( ) ;
350354}
351355
352356export const generateGo = task ( {
@@ -472,10 +476,27 @@ export const generateChecker = goGenerateTask("generate:checker", [
472476 stringerGenerator ( "tsc/internal/checker/types.go" , "SignatureKind" , "stringer_generated.go" ) ,
473477] ) ;
474478
475- export const generateCompilerOptions = goGenerateTask ( "generate:compileroptions" , [
476- stringerGenerator ( "tsc/internal/core/compileroptions.go" , "ModuleKind" , "modulekind_stringer_generated.go" , "ModuleKind" ) ,
477- stringerGenerator ( "tsc/internal/core/compileroptions.go" , "ScriptTarget" , "scripttarget_stringer_generated.go" , "ScriptTarget" ) ,
478- ] ) ;
479+ async function runGenerateOptionDefinitions ( ) {
480+ const { default : generate } = await import ( "./tools/scripts/tsc/generate-options.ts" ) ;
481+ await generate ( ! ! options . force ) ;
482+ }
483+
484+ async function runGenerateCompilerOptions ( ) {
485+ await runGenerateOptionDefinitions ( ) ;
486+ await runGoGenerator ( "generate:compileroptions" , stringerGenerator ( "tsc/internal/core/options_generated.go" , "ModuleKind" , "modulekind_stringer_generated.go" , "ModuleKind" ) ) ;
487+ await runGoGenerator ( "generate:compileroptions" , stringerGenerator ( "tsc/internal/core/options_generated.go" , "ScriptTarget" , "scripttarget_stringer_generated.go" , "ScriptTarget" ) ) ;
488+ }
489+
490+ goGenerateActions . push ( runGenerateCompilerOptions ) ;
491+ export const generateCompilerOptions = task ( {
492+ name : "generate:compileroptions" ,
493+ description : "Generates compiler options and their dependent API files. Pass --force to regenerate unchanged files." ,
494+ run : async ( ) => {
495+ await runGenerateCompilerOptions ( ) ;
496+ await runGenerateEnums ( ) ;
497+ await runGenerateAPI ( ) ;
498+ } ,
499+ } ) ;
479500
480501export const generateLanguageVariant = goGenerateTask ( "generate:languagevariant" , [
481502 stringerGenerator ( "tsc/internal/core/languagevariant.go" , "LanguageVariant" , "languagevariant_stringer_generated.go" ) ,
@@ -628,7 +649,7 @@ async function runGenerateEnums() {
628649
629650export const generateEnums = task ( {
630651 name : "generate:enums" ,
631- description : "Generates TypeScript enum files from Go source. Pass --force to regenerate unchanged files." ,
652+ description : "Generates TypeScript enums from metadata and Go source. Pass --force to regenerate unchanged files." ,
632653 run : runGenerateEnums ,
633654} ) ;
634655
@@ -689,7 +710,7 @@ async function runGenerateAPI() {
689710 "tsc/internal/tspath/path.go" ,
690711 "tools/gen-proto/*.go" ,
691712 ] ,
692- exclude : [ "**/*_test.go" , "**/*_generated.go" ] ,
713+ exclude : [ "**/*_test.go" ] ,
693714 envInputs : [ ] ,
694715 outputs : [ "packages/typescript/src/api/proto.generated.ts" ] ,
695716 commands : [
@@ -699,7 +720,11 @@ async function runGenerateAPI() {
699720 } ) ;
700721}
701722
702- export const generateAPI = goGenerateTask ( "generate:api" , runGenerateAPI ) ;
723+ export const generateAPI = task ( {
724+ name : "generate:api" ,
725+ description : "Generates API files. Pass --force to regenerate unchanged files." ,
726+ run : runGenerateAPI ,
727+ } ) ;
703728
704729const vendorJsonrpcDir = "packages/typescript/vendor/vscode-jsonrpc" ;
705730const vendorJsonrpcSrc = "node_modules/vscode-jsonrpc" ;
@@ -739,10 +764,7 @@ const generateCompiler = task({
739764 name : "generate:compiler" ,
740765 hiddenFromTaskList : true ,
741766 dependencies : [ generateAST , generateLSP ] ,
742- run : async ( ) => {
743- await runGenerateGo ( ) ;
744- await runGenerateEnums ( ) ;
745- } ,
767+ run : runGenerateGo ,
746768} ) ;
747769
748770export const generate = task ( {
@@ -985,7 +1007,7 @@ export const testCodegen = task({
9851007 description : "Runs incremental codegen tests." ,
9861008 run : async ( ) => {
9871009 await run ( "go" , [ "-C" , "tsc" , "mod" , "download" ] ) ;
988- await run ( "node" , [ "--test" , "--test-concurrency=1" , "./tools/scripts/gen/*.test.mts" ] ) ;
1010+ await run ( "node" , [ "--test" , "--test-concurrency=1" , "./tools/scripts/gen/*.test.mts" , "./tools/scripts/tsc/*.test.ts" ] ) ;
9891011 } ,
9901012} ) ;
9911013
@@ -1191,6 +1213,9 @@ export const validate = task({
11911213 }
11921214 if ( options . all ) {
11931215 await runValidation ( "test:tools" , runTestTools ) ;
1216+ await runValidation ( "test:options" , async ( ) => {
1217+ await run ( "node" , [ "--test" , "./tools/scripts/tsc/options.test.ts" ] ) ;
1218+ } ) ;
11941219 await runValidation ( "test:smoke" , runSmokeTest ) ; // in CI this is run with `--race`
11951220 }
11961221 await runValidation ( "lint" , runLint ) ;
@@ -2408,6 +2433,20 @@ async function testNativePreviewPackage(platforms) {
24082433 await cpRecursive ( hostPlatform . npmDir , platformPackageDir ) ;
24092434 await fs . promises . writeFile ( sourceFile , 'export const value: string = "value";\n' ) ;
24102435
2436+ const require = createRequire ( sourceFile ) ;
2437+ const { stdout } = await runOutput ( "npm" , [ "pack" , "--dry-run" , "--json" , mainPackageDir ] ) ;
2438+ /** @type {{ files: { path: string }[] }[] } */
2439+ const packed = JSON . parse ( stdout ) ;
2440+ for ( const name of [ "tsconfig" , "jsconfig" ] ) {
2441+ const schemaPath = `schemas/${ name } .schema.json` ;
2442+ assert ( packed [ 0 ] . files . some ( file => file . path === schemaPath ) , `Package is missing ${ schemaPath } ` ) ;
2443+ assert . deepEqual (
2444+ await fs . promises . readFile ( path . join ( mainPackageDir , schemaPath ) ) ,
2445+ await fs . promises . readFile ( path . join ( "packages/typescript" , schemaPath ) ) ,
2446+ ) ;
2447+ assert . equal ( require . resolve ( `${ mainNativePreviewPackage . npmPackageName } /${ schemaPath } ` ) , path . join ( mainPackageDir , schemaPath ) ) ;
2448+ }
2449+
24112450 const binName = publishAsTypescript ? "tsc" : "tsgo" ;
24122451 const binPath = path . join ( mainPackageDir , "bin" , binName ) ;
24132452 const { stdout : versionOutput } = await runOutput ( process . execPath , [ binPath , "--version" ] ) ;
0 commit comments