diff --git a/internal/execute/tsc/help.go b/internal/execute/tsc/help.go index f3467a6b6d..a10eac843e 100644 --- a/internal/execute/tsc/help.go +++ b/internal/execute/tsc/help.go @@ -19,7 +19,7 @@ func PrintHelp(sys System, commandLine *tsoptions.ParsedCommandLine) { if commandLine.CompilerOptions().All.IsFalseOrUnknown() { printEasyHelp(sys, getOptionsForHelp(commandLine)) } else { - // !!! printAllHelp(sys, getOptionsForHelp(commandLine)) + printAllHelp(sys, getOptionsForHelp(commandLine)) } } @@ -107,6 +107,31 @@ func printEasyHelp(sys System, simpleOptions []*tsoptions.CommandLineOption) { } } +func printAllHelp(sys System, options []*tsoptions.CommandLineOption) { + var output []string + msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Format() + " - " + diagnostics.Version_0.Format(core.Version()) + output = append(output, getHeader(sys, msg)...) + + // ALL COMPILER OPTIONS section + afterCompilerOptions := diagnostics.You_can_learn_about_all_of_the_compiler_options_at_0.Format("https://aka.ms/tsc") + output = append(output, generateSectionOptionsOutput(sys, diagnostics.ALL_COMPILER_OPTIONS.Format(), options, true, nil, &afterCompilerOptions)...) + + // WATCH OPTIONS section + beforeWatchOptions := diagnostics.Including_watch_w_will_start_watching_the_current_project_for_the_file_changes_Once_set_you_can_config_watch_mode_with_Colon.Format() + output = append(output, generateSectionOptionsOutput(sys, diagnostics.WATCH_OPTIONS.Format(), tsoptions.OptionsForWatch, false, &beforeWatchOptions, nil)...) + + // BUILD OPTIONS section + beforeBuildOptions := diagnostics.Using_build_b_will_make_tsc_behave_more_like_a_build_orchestrator_than_a_compiler_This_is_used_to_trigger_building_composite_projects_which_you_can_learn_more_about_at_0.Format("https://aka.ms/tsc-composite-builds") + buildOptions := core.Filter(tsoptions.OptionsForBuild, func(option *tsoptions.CommandLineOption) bool { + return option != &tsoptions.TscBuildOption + }) + output = append(output, generateSectionOptionsOutput(sys, diagnostics.BUILD_OPTIONS.Format(), buildOptions, false, &beforeBuildOptions, nil)...) + + for _, chunk := range output { + fmt.Fprint(sys.Writer(), chunk) + } +} + func PrintBuildHelp(sys System, buildOptions []*tsoptions.CommandLineOption) { var output []string output = append(output, getHeader(sys, diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Format()+" - "+diagnostics.Version_0.Format(core.Version()))...) @@ -142,14 +167,19 @@ func generateSectionOptionsOutput( return output } categoryMap := make(map[string][]*tsoptions.CommandLineOption) + var categoryOrder []string for _, option := range options { if option.Category == nil { continue } curCategory := option.Category.Format() + if _, exists := categoryMap[curCategory]; !exists { + categoryOrder = append(categoryOrder, curCategory) + } categoryMap[curCategory] = append(categoryMap[curCategory], option) } - for key, value := range categoryMap { + for _, key := range categoryOrder { + value := categoryMap[key] output = append(output, "### ", key, "\n", "\n") output = append(output, generateGroupOptionOutput(sys, value)...) } diff --git a/internal/tsoptions/declsbuild.go b/internal/tsoptions/declsbuild.go index dff42a7b8e..19726e85b8 100644 --- a/internal/tsoptions/declsbuild.go +++ b/internal/tsoptions/declsbuild.go @@ -6,8 +6,6 @@ import ( "github.com/microsoft/typescript-go/internal/diagnostics" ) -var BuildOpts = slices.Concat(commonOptionsWithBuild, optionsForBuild) - var TscBuildOption = CommandLineOption{ Name: "build", Kind: "boolean", @@ -18,7 +16,7 @@ var TscBuildOption = CommandLineOption{ DefaultValueDescription: false, } -var optionsForBuild = []*CommandLineOption{ +var OptionsForBuild = []*CommandLineOption{ &TscBuildOption, { Name: "verbose", @@ -59,3 +57,5 @@ var optionsForBuild = []*CommandLineOption{ DefaultValueDescription: false, }, } + +var BuildOpts = slices.Concat(commonOptionsWithBuild, OptionsForBuild) diff --git a/internal/tsoptions/declswatch.go b/internal/tsoptions/declswatch.go index 0e7d81d793..b190a6641c 100644 --- a/internal/tsoptions/declswatch.go +++ b/internal/tsoptions/declswatch.go @@ -5,7 +5,7 @@ import ( "github.com/microsoft/typescript-go/internal/diagnostics" ) -var optionsForWatch = []*CommandLineOption{ +var OptionsForWatch = []*CommandLineOption{ { Name: "watchInterval", Kind: CommandLineOptionTypeNumber, diff --git a/internal/tsoptions/diagnostics.go b/internal/tsoptions/diagnostics.go index 9aec10d96e..73936da069 100644 --- a/internal/tsoptions/diagnostics.go +++ b/internal/tsoptions/diagnostics.go @@ -46,7 +46,7 @@ func getParseCommandLineWorkerDiagnostics(decls []*CommandLineOption) *ParseComm var watchOptionsDidYouMeanDiagnostics = &ParseCommandLineWorkerDiagnostics{ didYouMean: DidYouMeanOptionsDiagnostics{ // no alternateMode - OptionDeclarations: optionsForWatch, + OptionDeclarations: OptionsForWatch, UnknownOptionDiagnostic: diagnostics.Unknown_watch_option_0, UnknownDidYouMeanDiagnostic: diagnostics.Unknown_watch_option_0_Did_you_mean_1, }, diff --git a/internal/tsoptions/namemap.go b/internal/tsoptions/namemap.go index 31a8b98d48..6cc2785e79 100644 --- a/internal/tsoptions/namemap.go +++ b/internal/tsoptions/namemap.go @@ -9,7 +9,7 @@ import ( var ( CompilerNameMap = GetNameMapFromList(OptionsDeclarations) BuildNameMap = GetNameMapFromList(BuildOpts) - WatchNameMap = GetNameMapFromList(optionsForWatch) + WatchNameMap = GetNameMapFromList(OptionsForWatch) ) func GetNameMapFromList(optDecls []*CommandLineOption) *NameMap { diff --git a/testdata/baselines/reference/tsc/commandLine/help-all.js b/testdata/baselines/reference/tsc/commandLine/help-all.js index b96905a0a7..7739fc641c 100644 --- a/testdata/baselines/reference/tsc/commandLine/help-all.js +++ b/testdata/baselines/reference/tsc/commandLine/help-all.js @@ -5,4 +5,650 @@ Input:: tsgo --help --all ExitStatus:: Success Output:: +tsc: The TypeScript Compiler - Version FakeTSVersion + +ALL COMPILER OPTIONS + +### Command-line Options + +--all +Show all compiler options. + +--build, -b +Build one or more projects and their dependencies, if out of date + +--help, -h +Print this message. + +--help, -? + + +--init +Initializes a TypeScript project and creates a tsconfig.json file. + +--listFilesOnly +Print names of files that are part of the compilation and then stop processing. + +--locale +Set the language of the messaging from TypeScript. This does not affect emit. + +--pprofDir +Generate pprof CPU/memory profiles to the given directory. + +--project, -p +Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'. + +--quiet, -q +Do not print diagnostics. + +--showConfig +Print the final configuration instead of building. + +--singleThreaded +Run in single threaded mode. + +--version, -v +Print the compiler's version. + +--watch, -w +Watch input files. + +### Modules + +--allowArbitraryExtensions +Enable importing files with any extension, provided a declaration file is present. +type: boolean +default: false + +--allowImportingTsExtensions +Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. +type: boolean +default: false + +--allowUmdGlobalAccess +Allow accessing UMD globals from modules. +type: boolean +default: false + +--baseUrl +Specify the base directory to resolve non-relative module names. + +--customConditions +Conditions to set in addition to the resolver-specific defaults when resolving imports. + +--module, -m +Specify what module code is generated. +one of: none, commonjs, amd, system, umd, es6/es2015, es2020, es2022, esnext, node16, node18, node20, nodenext, preserve +default: undefined + +--moduleResolution +Specify how TypeScript looks up a file from a given module specifier. +one of: node16, nodenext, bundler +default: module === `AMD` or `UMD` or `System` or `ES6`, then `Classic`, Otherwise `Node` + +--moduleSuffixes +List of file name suffixes to search when resolving a module. + +--noResolve +Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. +type: boolean +default: false + +--noUncheckedSideEffectImports +Check side effect imports. +type: boolean +default: false + +--paths +Specify a set of entries that re-map imports to additional lookup locations. +default: undefined + +--resolveJsonModule +Enable importing .json files. +type: boolean +default: false + +--resolvePackageJsonExports +Use the package.json 'exports' field when resolving package imports. +type: boolean +default: `true` when 'moduleResolution' is 'node16', 'nodenext', or 'bundler'; otherwise `false`. + +--resolvePackageJsonImports +Use the package.json 'imports' field when resolving imports. +type: boolean +default: `true` when 'moduleResolution' is 'node16', 'nodenext', or 'bundler'; otherwise `false`. + +--rewriteRelativeImportExtensions +Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. +type: boolean +default: false + +--rootDir +Specify the root folder within your source files. +type: string +default: Computed from the list of input files + +--rootDirs +Allow multiple folders to be treated as one when resolving modules. +one or more: string +default: Computed from the list of input files + +--typeRoots +Specify multiple folders that act like './node_modules/@types'. + +--types +Specify type package names to be included without being referenced in a source file. + +### JavaScript Support + +--allowJs +Allow JavaScript files to be a part of your program. Use the 'checkJs' option to get errors from these files. +type: boolean +default: false + +--checkJs +Enable error reporting in type-checked JavaScript files. +type: boolean +default: false + +--maxNodeModuleJsDepth +Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. +type: number +default: 0 + +### Interop Constraints + +--allowSyntheticDefaultImports +Allow 'import x from y' when a module doesn't have a default export. +type: boolean +default: module === "system" or esModuleInterop + +--erasableSyntaxOnly +Do not allow runtime constructs that are not part of ECMAScript. +type: boolean +default: false + +--esModuleInterop +Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. +type: boolean +default: false + +--forceConsistentCasingInFileNames +Ensure that casing is correct in imports. +type: boolean +default: true + +--isolatedDeclarations +Require sufficient annotation on exports so other tools can trivially generate declaration files. +type: boolean +default: false + +--isolatedModules +Ensure that each file can be safely transpiled without relying on other imports. +type: boolean +default: false + +--preserveSymlinks +Disable resolving symlinks to their realpath. This correlates to the same flag in node. +type: boolean +default: false + +--verbatimModuleSyntax +Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. +type: boolean +default: false + +### Type Checking + +--allowUnreachableCode +Disable error reporting for unreachable code. +type: boolean +default: undefined + +--allowUnusedLabels +Disable error reporting for unused labels. +type: boolean +default: undefined + +--alwaysStrict +Ensure 'use strict' is always emitted. +type: boolean +default: `false`, unless `strict` is set + +--exactOptionalPropertyTypes +Interpret optional property types as written, rather than adding 'undefined'. +type: boolean +default: false + +--noFallthroughCasesInSwitch +Enable error reporting for fallthrough cases in switch statements. +type: boolean +default: false + +--noImplicitAny +Enable error reporting for expressions and declarations with an implied 'any' type. +type: boolean +default: `false`, unless `strict` is set + +--noImplicitOverride +Ensure overriding members in derived classes are marked with an override modifier. +type: boolean +default: false + +--noImplicitReturns +Enable error reporting for codepaths that do not explicitly return in a function. +type: boolean +default: false + +--noImplicitThis +Enable error reporting when 'this' is given the type 'any'. +type: boolean +default: `false`, unless `strict` is set + +--noPropertyAccessFromIndexSignature +Enforces using indexed accessors for keys declared using an indexed type. +type: boolean +default: false + +--noUncheckedIndexedAccess +Add 'undefined' to a type when accessed using an index. +type: boolean +default: false + +--noUnusedLocals +Enable error reporting when local variables aren't read. +type: boolean +default: false + +--noUnusedParameters +Raise an error when a function parameter isn't read. +type: boolean +default: false + +--strict +Enable all strict type-checking options. +type: boolean +default: false + +--strictBindCallApply +Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. +type: boolean +default: `false`, unless `strict` is set + +--strictBuiltinIteratorReturn +Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. +type: boolean +default: `false`, unless `strict` is set + +--strictFunctionTypes +When assigning functions, check to ensure parameters and the return values are subtype-compatible. +type: boolean +default: `false`, unless `strict` is set + +--strictNullChecks +When type checking, take into account 'null' and 'undefined'. +type: boolean +default: `false`, unless `strict` is set + +--strictPropertyInitialization +Check for class properties that are declared but not set in the constructor. +type: boolean +default: `false`, unless `strict` is set + +--useUnknownInCatchVariables +Default catch clause variables as 'unknown' instead of 'any'. +type: boolean +default: `false`, unless `strict` is set + +### Watch and Build Modes + +--assumeChangesOnlyAffectDirectDependencies +Have recompiles in projects that use 'incremental' and 'watch' mode assume that changes within a file will only affect files directly depending on it. +type: boolean +default: false + +### Projects + +--composite +Enable constraints that allow a TypeScript project to be used with project references. +type: boolean +default: false + +--disableReferencedProjectLoad +Reduce the number of projects loaded automatically by TypeScript. +type: boolean +default: false + +--disableSolutionSearching +Opt a project out of multi-project reference checking when editing. +type: boolean +default: false + +--disableSourceOfProjectReferenceRedirect +Disable preferring source files instead of declaration files when referencing composite projects. +type: boolean +default: false + +--incremental, -i +Save .tsbuildinfo files to allow for incremental compilation of projects. +type: boolean +default: `false`, unless `composite` is set + +--tsBuildInfoFile +Specify the path to .tsbuildinfo incremental compilation file. +type: string +default: .tsbuildinfo + +### Emit + +--declaration, -d +Generate .d.ts files from TypeScript and JavaScript files in your project. +type: boolean +default: `false`, unless `composite` is set + +--declarationDir +Specify the output directory for generated declaration files. + +--declarationMap +Create sourcemaps for d.ts files. +type: boolean +default: false + +--downlevelIteration +Emit more compliant, but verbose and less performant JavaScript for iteration. +type: boolean +default: false + +--emitBOM +Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. +type: boolean +default: false + +--emitDeclarationOnly +Only output d.ts files and not JavaScript files. +type: boolean +default: false + +--importHelpers +Allow importing helper functions from tslib once per project, instead of including them per-file. +type: boolean +default: false + +--inlineSourceMap +Include sourcemap files inside the emitted JavaScript. +type: boolean +default: false + +--inlineSources +Include source code in the sourcemaps inside the emitted JavaScript. +type: boolean +default: false + +--mapRoot +Specify the location where debugger should locate map files instead of generated locations. + +--newLine +Set the newline character for emitting files. +one of: crlf, lf + +--noEmit +Disable emitting files from a compilation. +type: boolean +default: false + +--noEmitHelpers +Disable generating custom helper functions like '__extends' in compiled output. +type: boolean +default: false + +--noEmitOnError +Disable emitting files if any type checking errors are reported. +type: boolean +default: false + +--outDir +Specify an output folder for all emitted files. + +--outFile +Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. + +--preserveConstEnums +Disable erasing 'const enum' declarations in generated code. +type: boolean +default: false + +--removeComments +Disable emitting comments. +type: boolean +default: false + +--sourceMap +Create source map files for emitted JavaScript files. +type: boolean +default: false + +--sourceRoot +Specify the root path for debuggers to find the reference source code. + +--stripInternal +Disable emitting declarations that have '@internal' in their JSDoc comments. +type: boolean +default: false + +### Compiler Diagnostics + +--diagnostics +Output compiler performance information after building. +type: boolean +default: false + +--explainFiles +Print files read during the compilation including why it was included. +type: boolean +default: false + +--extendedDiagnostics +Output more detailed compiler performance information after building. +type: boolean +default: false + +--generateCpuProfile +Emit a v8 CPU profile of the compiler run for debugging. +type: string +default: profile.cpuprofile + +--generateTrace +Generates an event trace and a list of types. + +--listEmittedFiles +Print the names of emitted files after a compilation. +type: boolean +default: false + +--listFiles +Print all of the files read during the compilation. +type: boolean +default: false + +--noCheck +Disable full type checking (only critical parse and emit errors will be reported). +type: boolean +default: false + +--traceResolution +Log paths used during the 'moduleResolution' process. +type: boolean +default: false + +### Editor Support + +--disableSizeLimit +Remove the 20mb cap on total source code size for JavaScript files in the TypeScript language server. +type: boolean +default: false + +--plugins +Specify a list of language service plugins to include. +one or more: +default: undefined + +### Language and Environment + +--emitDecoratorMetadata +Emit design-type metadata for decorated declarations in source files. +type: boolean +default: false + +--experimentalDecorators +Enable experimental support for legacy experimental decorators. +type: boolean +default: false + +--jsx +Specify what JSX code is generated. +one of: preserve, react-native, react-jsx, react-jsxdev, react +default: undefined + +--jsxFactory +Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. +type: string +default: `React.createElement` + +--jsxFragmentFactory +Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. +type: string +default: React.Fragment + +--jsxImportSource +Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. +type: string +default: react + +--lib +Specify a set of bundled library declaration files that describe the target runtime environment. +one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, esnext, dom, dom.iterable, dom.asynciterable, webworker, webworker.importscripts, webworker.iterable, webworker.asynciterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2016.intl, es2017.arraybuffer, es2017.date, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.string, es2022.regexp, es2023.array, es2023.collection, es2023.intl, es2024.arraybuffer, es2024.collection, es2024.object/esnext.object, es2024.promise, es2024.regexp/esnext.regexp, es2024.sharedmemory, es2024.string/esnext.string, esnext.array, esnext.collection, esnext.intl, esnext.disposable, esnext.promise, esnext.decorators, esnext.iterator, esnext.float16, esnext.error, esnext.sharedmemory, decorators, decorators.legacy +default: undefined + +--libReplacement +Enable lib replacement. +type: boolean +default: false + +--moduleDetection +Control what method is used to detect module-format JS files. +one of: auto, legacy, force +default: "auto": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node16+) as modules. + +--noLib +Disable including any library files, including the default lib.d.ts. +type: boolean +default: false + +--reactNamespace +Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. +type: string +default: `React` + +--target, -t +Set the JavaScript language version for emitted JavaScript and include compatible library declarations. +one of: es5, es6/es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, esnext +default: es5 + +--useDefineForClassFields +Emit ECMAScript-standard-compliant class fields. +type: boolean +default: `true` for ES2022 and above, including ESNext. + +### Output Formatting + +--noErrorTruncation +Disable truncating types in error messages. +type: boolean +default: false + +--preserveWatchOutput +Disable wiping the console in watch mode. +type: boolean +default: false + +--pretty +Enable color and formatting in TypeScript's output to make compiler errors easier to read. +type: boolean +default: true + +### Backwards Compatibility + +--preserveValueImports +Preserve unused imported values in the JavaScript output that would otherwise be removed. +type: boolean +default: false + +### Completeness + +--skipDefaultLibCheck +Skip type checking .d.ts files that are included with TypeScript. +type: boolean +default: false + +--skipLibCheck +Skip type checking all .d.ts files. +type: boolean +default: false + +You can learn about all of the compiler options at https://aka.ms/tsc + +WATCH OPTIONS + +Including --watch, -w will start watching the current project for the file changes. Once set, you can config watch mode with: + +--watchInterval + +type: number +default: undefined + +--watchFile +Specify how the TypeScript watch mode works. +one of: fixedpollinginterval, prioritypollinginterval, dynamicprioritypolling, fixedchunksizepolling, usefsevents, usefseventsonparentdirectory +default: usefsevents + +--watchDirectory +Specify how directories are watched on systems that lack recursive file-watching functionality. +one of: usefsevents, fixedpollinginterval, dynamicprioritypolling, fixedchunksizepolling +default: usefsevents + +--fallbackPolling +Specify what approach the watcher should use if the system runs out of native file watchers. +one of: fixedinterval, priorityinterval, dynamicpriority, fixedchunksize +default: priorityinterval + +--synchronousWatchDirectory +Synchronously call callbacks and update the state of directory watchers on platforms that don`t support recursive watching natively. +type: boolean +default: false + +--excludeDirectories +Remove a list of directories from the watch process. + +--excludeFiles +Remove a list of files from the watch mode's processing. + +BUILD OPTIONS + +Using --build, -b will make tsc behave more like a build orchestrator than a compiler. This is used to trigger building composite projects which you can learn more about at https://aka.ms/tsc-composite-builds + +--verbose, -v +Enable verbose logging. + +--dry, -d +Show what would be built (or deleted, if specified with '--clean') + +--force, -f +Build all projects, including those that appear to be up to date. + +--clean +Delete the outputs of all projects. + +--stopBuildOnErrors +Skip building downstream projects on error in upstream project. +