import { filepaths } from "@fig/autocomplete-generators" ; /**
 * Equivalent to the `"filepaths"` template, but boosts the priority of files
 * that match one of the names provided.
 */ function generatePreferredFilepaths ( init ) { const names = new Set ( init . names ) ; const matchPriority = init . matchPriority ?? 75 ; return { template : "filepaths" , filterTemplateSuggestions : ( paths ) => { for ( const path of paths ) { if ( names . has ( path . name ) ) { path . priority = matchPriority ; } } return paths ; } , } ; } const generateRunnableFiles = filepaths ( { matches : /\.(m?(j|t)sx?)$/i , editFileSuggestions : { priority : 75 } , } ) ; type VersionsJSON = { latest : string ; versions : string [ ] ; } ; type DenoLintRulesJSON = { code : string ; tags : string [ ] ; docs : string ; } [ ] ; const generateLintRules = { script : "deno lint --rules --json" , getQueryTerm : "," , cache : { ttl : 1000 * 60 * 60 * 24 } , postProcess : ( out ) => { const json = JSON . parse ( out ) as DenoLintRulesJSON ; return json . map ( ( rule ) => ( { name : rule . code , description : rule . docs . slice ( 0 , rule . docs . indexOf ( "\n\n" ) ) , icon : "fig://icon?type=string" , } ) ) ; } , } ; type ExclusiveOn = { exclusiveOn ? : string [ ] ; } ; const unsafelyIgnoreCertificateErrorsOption = { name : "--unsafely-ignore-certificate-errors" , description : "DANGER: Disables verification of TLS certificates" , isDangerous : true , requiresEquals : true , args : { name : "host names" , description : "Scope ignoring certificate errors to these hosts" , isOptional : true , } , } ; const permissionOptions = [ { name : [ "-A" , "--allow-all" ] , description : "Allow all permissions" , } , { name : "--allow-env" , description : "Allow environment access" , requiresEquals : true , args : { name : "variable" , description : "Comma-separated list of environment variables to allow" , isOptional : true , } , } , { name : "--allow-ffi" , description : "Allow loading dynamic libraries" , requiresEquals : true , args : { name : "library" , description : "The path of the dynamic library to allow" , isOptional : true , } , } , { name : "--allow-hrtime" , description : "Allow high resolution time measurement" , } , { name : "--allow-net" , description : "Allow network access" , requiresEquals : true , args : { name : "hosts" , isOptional : true , } , } , { name : "--allow-read" , description : "Allow file system read access" , requiresEquals : true , args : { name : "paths" , generators : { getQueryTerm : "," , trigger : "," , template : "filepaths" , } , isOptional : true , } , } , { name : "--allow-run" , description : "Allow running subprocesses" , requiresEquals : true , args : { name : "executables" , isOptional : true , } , } , { name : "--allow-write" , description : "Allow file system write access" , requiresEquals : true , args : { name : "paths" , isOptional : true , generators : { getQueryTerm : "," , trigger : "," , template : "filepaths" , } , } , } , { name : "--prompt" , description : "Fallback to prompt if required permission wasn't passed" , } , unsafelyIgnoreCertificateErrorsOption , ] ; function inspectorOptions ( options = { } ) { return [ { name : "--inspect" , description : "Activate inspector on host:port (default: 127.0.0.1:9229)" , requiresEquals : true , args : { name : "host:port" , description : "The host:port to activate the inspector on" , isOptional : true , } , exclusiveOn : options . exclusiveOn , } , { name : "--inspect-brk" , description : "Activate inspector on host:port and break at the start of user script (default: 127.0.0.1:9229)" , requiresEquals : true , args : { name : "host:port" , description : "The host:port to activate the inspector on" , isOptional : true , } , exclusiveOn : options . exclusiveOn , } , ] ; } const caFileOption = { name : "--cert" , description : "Load certificate authority from a PEM encoded file" , args : { name : "certificate file" , description : "The certificate file to load" , template : "filepaths" , } , } ; const configOption = { name : [ "-c" , "--config" ] , description : "Load a configuration file" , args : { name : "config file" , description : "The config file to load" , generators : generatePreferredFilepaths ( { names : [ "tsconfig.json" , "deno.json" , "deno.jsonc" ] , } ) , } , } ; const importMapOption = { name : "--import-map" , description : "Load an import map from a local file or remote URL" , args : { name : "source" , description : "The location of the import map (can be a URL)" , generators : generatePreferredFilepaths ( { names : [ "importmap.json" , "import_map.json" , "import-map.json" , "imports.json" , ] , } ) , } , } ; const lockOption = { name : "--lock" , description : "Check the specified lock file" , args : { name : "lock file" , description : "The location of the JSON lock file" , generators : generatePreferredFilepaths ( { names : [ "lock.json" ] } ) , } , } ; const lockWriteOption = { name : "--lock-write" , description : "Write lock file" , dependsOn : [ "--lock" ] , } ; const noCheckOption = { name : "--no-check" , description : "Skip type checking modules" , requiresEquals : true , args : { name : "type" , description : "Specify the kind of modules to skip type checking" , isOptional : true , suggestions : [ { name : "remote" , description : "Don't check remote modules" , icon : "fig://icon?type=string" , } , ] , } , } ; const noRemoteOption = { name : "--no-remote" , description : "Do not resolve remote modules" , } ; const reloadOption = { name : [ "-r" , "--reload" ] , description : "Reload source code cache (recompile TypeScript, download dependencies)" , requiresEquals : true , args : { name : "cache blocklist" , description : "A comma-separated list of URLs to block from the cache" , isOptional : true , } , } ; const seedOption = { name : "--seed" , description : "Seed Math.random()" , args : { name : "number" , description : "The number to use as the seed for Math.random()" , } , } ; const v8FlagsOption = { name : "--v8-flags" , insertValue : "--v8-flags=" , description : "Set V8 command line options (for help: --v8-flags=--help" , requiresEquals : true , args : { name : "V8 flags" , description : "Flags to pass to V8" , } , } ; function watchOption ( options ) { return { name : "--watch" , description : "UNSTABLE: Watch for file changes and restart process automatically" , exclusiveOn : options . exclusiveOn , requiresEquals : options . files ? true : undefined , args : options . files ? { name : "files" , isOptional : true , generators : { template : "filepaths" , getQueryTerm : "," , } , } : undefined , } ; } const compatOption = { name : "--compat" , dependsOn : [ "--unstable" ] , description : "Node compatibility mode. Currently only enables builtin modules like 'fs'" , } ; const locationOption = { name : "--location" , description : "Value of 'globalThis.location' used by some web APIs" , args : { name : "URL" , } , } ; const cachedOnlyOption = { name : "--cached-only" , description : "Require that remote dependencies are already cached" , } ; const compileOptions = [ importMapOption , noRemoteOption , configOption , noCheckOption , reloadOption , lockOption , lockWriteOption , caFileOption , ] ; /**
 * Generate an array of options that control runtime behavior.
 *
 * This function mirrors the `runtime_args` function:
 * https://github.com/denoland/deno/blob/930cb0a/cli/flags.rs#L1383
 */ function runtimeOptions ( init ) { const options = [ ... compileOptions , ] ; if ( init . perms ) { options . push ( ... permissionOptions ) ; } if ( init . inspector ) { const inspector = inspectorOptions ( { exclusiveOn : init . inspectorExclusiveOn , } ) ; options . push ( ... inspector ) ; } options . push ( cachedOnlyOption , locationOption , v8FlagsOption , seedOption , compatOption ) ; return options ; } const denoRun = { name : "run" , description : "Run a JavaScript or TypeScript program" , args : { name : "script" , description : "The JavaScript or TypeScript file to run" , generators : generateRunnableFiles , } , options : [ ... runtimeOptions ( { perms : true , inspector : true , inspectorExclusiveOn : [ "--watch" ] , } ) , watchOption ( { files : true , exclusiveOn : [ "--inspect" , "--inspect-brk" ] , } ) , ] , } ; const denoTest = { name : "test" , description : "Run tests using Deno's built-in test runner" , args : { name : "paths" , description : "The paths of tests to run" , isOptional : true , isVariadic : true , generators : filepaths ( { matches : /(\.|_)?test\.(m?(j|t)sx?)$/ , editFileSuggestions : { priority : 75 } , } ) , } , options : [ ... runtimeOptions ( { perms : true , inspector : true } ) , { name : "--ignore" , insertValue : "--ignore=" , description : "Ignore files" , requiresEquals : true , args : { name : "Files to ignore" , description : "Files matching this pattern will be ignored" , template : "filepaths" , } , } , { name : "--no-run" , description : "Cache test modules, but don't run tests" , exclusiveOn : [ "--watch" ] , } , { name : "--doc" , description : "UNSTABLE: Type check code blocks in documentation" , } , { name : "--fail-fast" , description : "Stop after N errors (defaults to stopping after the first error)" , requiresEquals : true , args : { name : "number" , isOptional : true , } , } , { name : "--allow-none" , description : "Don't return error code if no test files are found" , } , { name : "--filter" , description : "Run tests with this string or pattern in the test name" , args : { name : "pattern" , description : "The pattern to match against" , } , } , { name : "--shuffle" , description : "UNSTABLE: Shuffle the order in which tests are run" , requiresEquals : true , args : { name : "number" , isOptional : true , } , } , { name : "--coverage" , insertValue : "--coverage=" , description : "UNSTABLE: Collect coverage profile data into the directory" , requiresEquals : true , args : { name : "directory" , description : "The directory to use for coverage data" , template : "folders" , } , exclusiveOn : [ "--watch" ] , } , { name : [ "-j" , "--jobs" ] , description : "Set the number of parallel workers. With no value, the number of CPU cores. Defaults to 1 if omitted" , args : { name : "number" , description : "The number of parallel workers (defaults to number of CPU cores)" , isOptional : true , } , } , watchOption ( { files : false , exclusiveOn : [ "--no-run" , "--coverage" ] , } ) , ] , } ; const denoFmt = { name : "fmt" , description : "Auto-format JavaScript, TypeScript, Markdown, and JSON files" , args : { name : "files" , description : "Files to format" , isOptional : true , isVariadic : true , generators : filepaths ( { matches : /\.(mjs|jsx?|tsx?|jsonc?|md)$/i , editFileSuggestions : { priority : 75 } , } ) , } , options : [ configOption , { name : "--check" , description : "Check if the source files are formatted" , } , { name : "--ext" , description : "Set standard input (stdin) content type" , args : { name : "extension" , description : "The extension to format input as" , suggestions : [ "ts" , "tsx" , "js" , "jsx" , "md" , "json" , "jsonc" ] , } , } , { name : "--ignore" , insertValue : "--ignore=" , description : "Ignore formatting particular source files" , requiresEquals : true , args : { name : "Files to ignore" , template : "filepaths" , } , } , watchOption ( { files : false } ) , { name : "--options-use-tabs" , description : "Use tabs instead of spaces" , } , { name : "--options-line-width" , description : "Define the maximum line width" , args : { name : "width" , } , } , { name : "--options-indent-width" , description : "Set the number of spaces to use for indentation" , args : { name : "width" , } , } , { name : "--options-single-quote" , description : "Use single quotes" , } , { name : "--options-prose-wrap" , description : "Define how markdown prose should be wrapped (default: always)" , args : { default : "always" , name : "wrap" , suggestions : [ { name : "always" , icon : "fig://icon?type=string" , description : "Hard-wrap the entire file" , } , { name : "never" , icon : "fig://icon?type=string" , description : "Don't hard-wrap text" , } , { name : "preserve" , icon : "fig://icon?type=string" , description : "Hard-wrap text that's changed" , } , ] , } , } , ] , } ; const denoLint = { name : "lint" , description : "Lint JavaScript and TypeScript source code" , args : { name : "files" , description : "Files to lint" , isOptional : true , isVariadic : true , generators : generateRunnableFiles , } , options : [ configOption , { name : "--rules" , description : "List available rules" , exclusiveOn : [ "--rules-tags" , "--rules-include" , "--rules-exclude" ] , } , { name : "--ignore" , description : "Ignore linting particular source files" , requiresEquals : true , args : { name : "files" , template : "filepaths" , description : "The files to ignore" , isOptional : true , } , } , { name : "--json" , description : "Output lint result in JSON format" , } , { name : "--rules-tags" , description : "Use a set of rules with a tag" , exclusiveOn : [ "--rules" ] , args : { name : "rules" , generators : generateLintRules , } , } , { name : "--rules-include" , description : "Include lint rules" , exclusiveOn : [ "--rules" ] , args : { name : "rules" , generators : generateLintRules , } , } , { name : "--rules-exclude" , description : "Exclude lint rules" , exclusiveOn : [ "--rules" ] , args : { name : "rules" , generators : generateLintRules , } , } , watchOption ( { files : false } ) , ] , } ; type Named = { name : string ; } ; type Kind < T extends string = string > = { kind : T ; } ; type DocProperty = Named ; type DocMethod = Named & Kind ; type DocNodeModuleDoc = Named & Kind < "moduleDoc" > ; type DocNodeFunction = Named & Kind < "function" > ; type DocNodeVariable = Named & Kind < "variable" > ; type DocNodeEnum = Named & Kind < "enum" > ; type DocNodeClass = Named & Kind < "class" > & { classDef : { properties : DocProperty [ ] ; methods : DocMethod [ ] ; } ; } ; type DocNodeTypeAlias = Named & Kind < "typeAlias" > ; type DocNodeNamespace = Named & Kind < "namespace" > & { namespaceDef : { elements : DocNode [ ] ; } ; } ; type DocNodeInterface = Named & Kind < "interface" > & { interfaceDef : { properties : DocProperty [ ] ; methods : DocMethod [ ] ; } ; } ; type DocNodeImport = Named & Kind < "import" > ; type DocNode = DocNodeModuleDoc | DocNodeFunction | DocNodeVariable | DocNodeEnum | DocNodeClass | DocNodeTypeAlias | DocNodeNamespace | DocNodeInterface | DocNodeImport ; /** Any node is assignable to this type. */ type AnyNode = { name : string ; kind ? : string ; } ; function getNamePriority ( name ) { if ( /^[A-Z]/ . test ( name ) ) { return 60 ; } if ( name . startsWith ( "_" ) ) { return 40 ; } return 50 ; } function createFilterSuggestion ( name ) { return { name : name , priority : getNamePriority ( name ) , icon : "fig://icon?type=string" , } ; } function getDocNodeChildren ( node ) { if ( node . kind === "namespace" ) { return node . namespaceDef . elements ; } if ( node . kind === "interface" ) { return [ ... node . interfaceDef . methods , ... node . interfaceDef . properties ] ; } if ( node . kind === "class" ) { return [ ... node . classDef . methods , ... node . classDef . properties ] ; } return [ ] ; } const denoDoc = { name : "doc" , description : "Show documentation for a module" , args : [ { name : "scope" , description : "The scope to get documentation for" , suggestions : [ { name : "--builtin" , description : "Get documentation for built-in symbols" , icon : "fig://icon?type=option" , } , ] , generators : generateRunnableFiles , isOptional : true , } , { name : "filter" , description : "The symbol to get documentation for (must exist in scope)" , isOptional : true , generators : { script : ( tokens ) => { const command = tokens . slice ( 0 , - 1 ) ; if ( ! command . includes ( "--json" ) ) { command . push ( "--json" ) ; } const script = command . join ( " " ) ; return script ; } , trigger : ( newToken , oldToken ) => { return newToken . indexOf ( "." ) !== oldToken . indexOf ( "." ) ; } , getQueryTerm : ( token ) => { return token . slice ( token . indexOf ( "." ) + 1 ) ; } , postProcess : ( out , tokens ) => { let docNodes ; try { docNodes = JSON . parse ( out ) ; if ( ! Array . isArray ( docNodes ) ) { throw new Error ( `Output data was JSON, but was not an array` ) ; } } catch ( err ) { console . error ( "Returning early due to error:" , err ) ; return [ ] ; } const hidePrivateSymbols = ! tokens . includes ( "--private" ) ; if ( docNodes . length === 0 ) { return [ ] ; } const filterToken = tokens [ tokens . length - 1 ] ; const firstDotIndex = filterToken . indexOf ( "." ) ; const suggestTopLevelNodes = firstDotIndex === - 1 ; const suggestionNodes = [ ] ; if ( suggestTopLevelNodes ) { suggestionNodes . push ( ... docNodes ) ; } else { const filterName = filterToken . slice ( 0 , firstDotIndex ) ; const found = docNodes . filter ( ( node ) => node . name === filterName ) ; for ( const node of found ) { suggestionNodes . push ( ... getDocNodeChildren ( node ) ) ; } if ( suggestionNodes . length === 0 ) { return [ ] ; } } const names = new Set < string > ( ) ; for ( const node of suggestionNodes ) { if ( node . kind === "moduleDoc" ) { continue ; } if ( hidePrivateSymbols && node . kind === "import" ) { continue ; } names . add ( node . name ) ; } names . delete ( "<TODO>" ) ; names . delete ( "" ) ; const suggestions = [ ] ; for ( const name of names ) { suggestions . push ( createFilterSuggestion ( name ) ) ; } return suggestions ; } , } , } , ] , options : [ importMapOption , reloadOption , { name : "--json" , description : "Output documentation in JSON format" , } , { name : "--private" , description : "Output private documentation" , } , ] , } ; const denoInstall = { name : "install" , description : "Install a script as an executable" , args : [ { name : "source" , description : "A local or remote JavaScript or TypeScript file" , generators : generateRunnableFiles , } , { name : "args" , description : "Arguments that will be provided automatically when run" , isVariadic : true , isOptional : true , } , ] , options : [ ... runtimeOptions ( { perms : true , inspector : true } ) , { name : [ "-n" , "--name" ] , description : "Name of the executable" , args : { name : "name" , description : "The name the executable will have" , } , } , { name : [ "-f" , "--force" ] , description : "Forcefully overwrite an existing installation" , } , { name : "--root" , description : "The installation root" , args : { name : "directory" , description : "The directory that the script will be installed to" , template : "folders" , } , } , ] , } ; const denoUninstall = { name : "uninstall" , description : "Uninstalls an executable script in the installation root's bin directory" , args : { name : "name" , description : "Arguments that will be provided automatically when run" , isVariadic : true , } , options : [ { name : "--root" , description : "The installation root" , args : { name : "directory" , description : "The directory that the script will be uninstalled from" , template : "folders" , } , } , ] , } ; const denoLsp = { name : "lsp" , description : "Start the language server" , } ; const denoTypes = { name : "types" , description : "Print Deno's runtime TypeScript declarations" , } ; const denoUpgrade = { name : "upgrade" , description : "Upgrade the deno executable" , options : [ { name : "--version" , description : "The version to upgrade to" , args : { name : "version" , generators : { script : `curl -sL 'https://cdn.deno.land/deno/meta/versions.json'` , cache : { ttl : 1000 * 60 * 60 * 24 } , postProcess : ( out ) => { const data = JSON . parse ( out ) as VersionsJSON ; return data . versions . map ( ( version ) => ( { name : version . startsWith ( "v" ) ? version . slice ( 1 ) : version , } ) ) ; } , } , } , } , { name : "--output" , description : "Output path of the downloaded binary" , args : { name : "path" , template : "filepaths" , } , } , { name : "--dry-run" , description : "Perform all checks without replacing the old version" , } , { name : "--canary" , description : "Upgrade to a canary build" , } , caFileOption , ] , } ; const denoEval = { name : "eval" , insertValue : "eval '{cursor}'" , description : "Evaluate JavaScript from the command line" , options : [ ... runtimeOptions ( { perms : false , inspector : true } ) , { name : "--ext" , description : "Set standard input (stdin) content type" , args : { name : "extension" , description : "Interpret stdin as this type of file" , default : "ts" , suggestions : [ "ts" , "tsx" , "js" , "jsx" ] , } , } , { name : [ "-p" , "--print" ] , description : "Print the result to stdout" , } , ] , args : { name : "code" , isVariadic : true , } , } ; const denoCompletions = { name : "completions" , description : "Generate shell completions" , args : { name : "shell" , description : "Generate completions for this shell" , suggestions : [ "zsh" , "bash" , "fish" , "powershell" , "elvish" ] , } , } ; const denoCoverage = { name : "coverage" , description : "Print coverage reports from coverage profiles" , options : [ { name : "--ignore" , insertValue : "--ignore=" , description : "Ignore coverage files" , requiresEquals : true , args : { name : "pattern" , description : "Ignore files matching this regex pattern" , template : "filepaths" , } , } , { name : "--include" , insertValue : "--include=" , description : "Include source files in the report" , isRepeatable : true , requiresEquals : true , args : { name : "pattern" , description : "Include files matching this regex pattern" , template : "filepaths" , } , } , { name : "--exclude" , insertValue : "--exclude=" , description : "Exclude source files from the report" , isRepeatable : true , requiresEquals : true , args : { name : "pattern" , description : "Exclude files matching this regex pattern" , template : "filepaths" , } , } , { name : "--lcov" , description : "Output coverage in the lcov format" , } , ] , args : { name : "coverage directory" , isVariadic : true , template : "folders" , } , } ; const denoInfo = { name : "info" , description : "Show info about the cache or info related to a source file" , options : [ reloadOption , caFileOption , importMapOption , { name : "--location" , description : "Show files used for origin-bound APIs (like Web Storage)" , args : { name : "URL" , description : "Show files used for this location" , } , } , { name : "--json" , description : "UNSTABLE: Output information as JSON" , } , ] , args : { name : "file" , description : "The source file to show information for" , isOptional : true , generators : generateRunnableFiles , } , } ; const denoRepl = { name : "repl" , description : "Open an interactive read-eval-print loop" , options : [ ... runtimeOptions ( { perms : false , inspector : true } ) , unsafelyIgnoreCertificateErrorsOption , { name : "--eval" , insertValue : "--eval '{cursor}'" , description : "Evaluate this code when the REPL starts" , args : { name : "code" , description : "The code to evaluate" , } , } , ] , } ; const denoCompile = { name : "compile" , description : "UNSTABLE: Compile the script into a self-contained executable" , args : [ { name : "script" , description : "The source to be compiled" , generators : generateRunnableFiles , } , { name : "arguments" , description : "Arguments to be provided to the script" , isOptional : true , isVariadic : true , } , ] , options : [ ... runtimeOptions ( { perms : true , inspector : false } ) , { name : [ "-o" , "--output" ] , description : "Location of the output binary (default: ./<inferred-name>)" , args : { name : "destination" , template : "folders" , } , } , { name : "--target" , description : "The target OS architecture" , args : { name : "arch" , suggestions : [ { name : "x86_64-unknown-linux-gnu" , icon : "fig://icon?type=cpu" } , { name : "x86_64-pc-windows-msvc" , icon : "fig://icon?type=cpu" } , { name : "x86_64-apple-darwin" , icon : "fig://icon?type=cpu" } , { name : "aarch64-apple-darwin" , icon : "fig://icon?type=cpu" } , ] , } , } , ] , } ; const denoCache = { name : "cache" , description : "Cache and compile remote dependencies, recursively" , args : { name : "script" , description : "The script(s) to cache" , generators : generateRunnableFiles , isVariadic : true , } , options : compileOptions , } ; const denoBundle = { name : "bundle" , description : "Bundle module and dependencies into a single file" , args : [ { name : "source" , description : "The source file to bundle" , generators : generateRunnableFiles , } , { name : "output" , description : "The output file" , template : "folders" , isOptional : true , } , ] , options : compileOptions , } ; const subcommands = [ denoBundle , denoCache , denoCompile , denoCompletions , denoCoverage , denoDoc , denoEval , denoFmt , denoInfo , denoInstall , denoUninstall , denoLint , denoLsp , denoRepl , denoRun , denoTest , denoTypes , denoUpgrade , ] ; const completionSpec = { name : "deno" , description : "A secure JavaScript and TypeScript runtime" , subcommands : [ ... subcommands , { name : "help" , description : "Print help information for the CLI or a subcommand" , args : { name : "subcommand" , description : "The subcommand to get help with" , isOptional : true , suggestions : subcommands , } , } , ] , options : [ { name : [ "-h" , "--help" ] , description : "Prints help information" , isPersistent : true , priority : 40 , } , { name : [ "-L" , "--log-level" ] , description : "Set log level" , isPersistent : true , priority : 40 , args : { suggestions : [ "info" , "debug" ] , } , } , { name : [ "-q" , "--quiet" ] , description : "Suppress diagnostic output (restrict stderr messages to errors)" , isPersistent : true , } , { name : "--unstable" , description : "Enable unstable features and APIs" , isPersistent : true , } , { name : "--version" , description : "Prints version information, including TypeScript and V8" , exclusiveOn : [ "-V" ] , } , { name : "-V" , description : "Prints Deno's version" , exclusiveOn : [ "--version" ] , priority : 25 , } , ] , } ; export default completionSpec ;