#compdef node
# ------------------------------------------------------------------------------
# Copyright (c) 2018 Github zsh-users - https://github.com/zsh-users
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of the zsh-users nor the
#       names of its contributors may be used to endorse or promote products
#       derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
#  Completion script for Node.js v20.0.0 (https://nodejs.org)
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
#  * Mario Fernandez (https://github.com/sirech)
#  * Nicholas Penree (https://github.com/drudge)
#  * Masafumi Koba (https://github.com/ybiquitous)
#  * Shohei YOSHIDA (https://github.com/syohex)
#
# ------------------------------------------------------------------------------

_node_files() {
  for (( i = 2; i < CURRENT; i++)); do
    if [[ ${words[i]} == "--prof-process" ]]; then
      _files -g "*.log"
      return
    fi
  done

  _files -g "*.(js|mjs)"
}

_node_args() {
  if (( CURRENT == 2 )); then
    _alternative "_node_files" "_values 'command' 'inspect[enable inspector for debugging]'"
    return
  fi

  _node_files
}

local curcontext="$curcontext" state line ret=1
typeset -A opt_args

_arguments -C \
  '-[script read from stdin (default; interactive mode if a tty)]' \
  '--[indicate the end of node options]' \
  '--abort-on-uncaught-exception[aborting instead of exiting causes a core file to be generated for analysis]' \
  '--allow-child-process[allow use of child process when any permissions are set]' \
  '--allow-fs-read=[allow permissions to read the filesystem]: :_files' \
  '--allow-fs-write=[allow permissions to write in the filesystem]:_files' \
  '--build-snapshot[generate a snapshot blob when the process exits]' \
  '--completion-bash[print source-able bash completion script]' \
  '--cpu-prof[Start the V8 CPU profiler on start up]' \
  '--cpu-prof-dir=[directory where the V8 profiles generated by --cpu-prof]: :_files -/' \
  '--cpu-prof-name=[file name of the V8 profile generated with --cpu-prof]: :_files' \
  '--cpu-prof-interval=[sampling interval in microseconds for the V8 CPU profiler]:number' \
  '--diagnostic-dir=[set dir for all output files(default: current working directory)]:dir:_files -/' \
  '--disable-proto=[disable Object.prototype.__proto__]:mode:(delete throw)' \
  '--disallow-code-generation-from-strings[disallow eval and friends]' \
  '--dns-result-order=[set default value of verbatim in dns.lookup]: :(ipv4first verbatim)' \
  '--enable-etw-stack-walking[provides heap data to ETW Windows native tracing]' \
  '--enable-fips[enable FIPS crypto at startup]' \
  '--enable-network-family-autoselection[enable network address family autosetection algorithm]' \
  '--enable-source-maps[source map support]' \
  '--es-module-specifier-resolution=[extension resolution algorithm for es modules]:resolution algorithm:(explicit none)' \
  '--experimental-import-meta-resolve[experimental ES Module import.meta.resolve() support]' \
  '(--loader --experimental-loader)'{--loader,--experimental-loader}'=[Specify the module of a custom ECMAScript Module loader]: :_files' \
  '--experimental-network-imports[experimental https support for the ES Module loader]' \
  '--experimental-permission[enable the permission system]' \
  '--experimental-policy=[security policy file]: :_files' \
  '--experimental-sea-config=[generate a blob that can be embedded into the single executable application]: :_files' \
  '--experimental-test-coverage[enable code coverage in the test runner]' \
  '--experimental-vm-modules[experimental ES Module support in vm module]' \
  '--experimental-wasm-modules[experimental ES module support for webassembly modules]' \
  '--force-context-aware[disable loading non-context-aware addons]' \
  '--force-fips[force FIPS crypto]' \
  '--frozen-intrinsics[experimental frozen intrinsics support]' \
  '--heap-prof[Start the V8 heap profiler on start up]' \
  '--heap-prof-dir=[Directory where the V8 profiles generated by --heap-prof]: :_files -/' \
  '--heap-prof-interval=[sampling interval in bytes for the V8 heap profile]: :number' \
  '--heap-prof-name=[file name of the V8 heap profile generated]: :_files' \
  '--heapsnapshot-signal=[Generate heap snapshot on specified signal]:signals:_signals -s' \
  '--huge-max-old-generation-size[increase default maximum heap size with 16GB or more]' \
  '--icu-data-dir=[set ICU data load path to dir (overrides NODE_ICU_DATA) note: linked-in ICU data is present]: :_directories' \
  '--input-type=[set module type for string input]:module type :(commonjs module)' \
  '--insecure-http-parser[Use an insecure HTTP parser that accepts invalid HTTP headers]' \
  '--inspect-brk=-[activate inspector on host:port and break at start of user script]:[host\:]port' \
  '(--debug-port --inspect-port)'{--debug-port,--inspect-port}'=[set host:port for inspector]:[host\:]port' \
  '--inspect=-[activate inspector on host:port (default: 127.0.0.1:9229)]:[host\:]port' \
  '--inspect-publish-uid=[comma separated list of destinations for inspector uid]' \
  '--interpreted-frames-native-stack[help system profilers to translate JavaScript interpreted frames]' \
  '--jitless[Disable runtime allocation of executable memory]' \
  '--max-http-header-size=[set the maximum size of HTTP headers]: :number' \
  '--napi-modules[load N-API modules (no-op - option kept for compatibility)]' \
  '--no-addons[disable loading native addons]' \
  '--no-deprecation[silence deprecation warnings]' \
  '--no-experimental-fetch[disable experimental Fetch API]' \
  '--no-experimental-global-customevent[expose experimental CustomEvent on the global scope]' \
  '--no-experimental-global-webcrypto[expose experimental Web Crypto API on the global scope]' \
  '--no-experimental-repl-await[disable experimental await keyword support in REPL]' \
  '--no-extra-info-on-fatal-exception[hide extra information on fatal exception that causes exit]' \
  '--no-force-async-hooks-checks[disable checks for async_hooks]' \
  '--no-global-search-paths[disable global module search paths]' \
  '--no-warnings[silence all process warnings]' \
  '--node-memory-debug[run with extra debug checks for memory leaks in Node.js itself]' \
  '--openssl-config=[load OpenSSL configuration from the specified file (overrides OPENSSL_CONF)]:file:_files' \
  '--openssl-legacy-provider[enable OpenSSL 3.0 legacy provider]' \
  '--openssl-shared-config[enable OpenSSL shared configuration]' \
  '--pending-deprecation[emit pending deprecation warnings]' \
  '--policy-integrity=[ensure the security policy contents match the specified integrity]' \
  '--preserve-symlinks[preserve symbolic links when resolving]' \
  '--preserve-symlinks-main[preserve symbolic links when resolving the main module]' \
  '--prof[generate V8 profiler output]' \
  '--prof-process[process V8 profiler output generated using --prof]' \
  '--redirect-warnings=[write warnings to file instead of stderr]: :_files' \
  '--report-compact[output compact single-line JSON]' \
  '--report-directory=[custom report path]: :_files -/' \
  '--report-filename=[custom report file name]: :_files' \
  '--report-on-fatalerror[generate diagnostic report on fatal (internal) errors]' \
  '--report-on-signal=[generate diagnostic report upon receiving signals]' \
  '--report-signal=[causes diagnostic report to be produced on provided signal]:signals:_signals -s' \
  '--report-uncaught-exception[generate diagnostic report on uncaught exceptions]' \
  '--secure-heap=[total size of the OpenSSL secure heap]: :number' \
  '--secure-heap-min=[minimum allocation size from the OpenSSL secure heap]' \
  '--snapshot-blob=[path to the snapshot blob that is used to restore the application state]:snapshot:_files' \
  '--test[launch test runner on startup]' \
  '--test-name-pattern=[run tests whose name matches this regular expression]:pattern' \
  '--test-only[run tests with "only" option set]' \
  '*--test-reporter=[report test output using the given reporter]:reporter:(tap spec dot)' \
  '*--test-reporter-destination=[report given reporter to the given destination]:destination:_files' \
  '--throw-deprecation[throw an exception on deprecations]' \
  '--title=[the process title to use on startup]:process title' \
  '--tls-cipher-list=[use an alternative default TLS cipher list]:cipher list string' \
  '--tls-keylog=[log TLS decryption keys to named file for traffic analysis]: :_files' \
  '(--tls-max-v1.3)--tls-max-v1.2[set default TLS maximum to TLSv1.2]' \
  '(--tls-max-v1.2)--tls-max-v1.3[set default TLS maximum to TLSv1.3]' \
  '(--tls-min-v1.1 --tls-min-v1.2 --tls-min-v1.3)--tls-min-v1.0[set default TLS minimum to TLSv1.0]' \
  '(--tls-min-v1.0 --tls-min-v1.2 --tls-min-v1.3)--tls-min-v1.1[set default TLS minimum to TLSv1.1]' \
  '(--tls-min-v1.0 --tls-min-v1.1 --tls-min-v1.3)--tls-min-v1.2[set default TLS minimum to TLSv1.2]' \
  '(--tls-max-v1.2 --tls-min-v1.0 --tls-min-v1.1 --tls-min-v1.2)--tls-min-v1.3[set default TLS minimum to TLSv1.3]' \
  '--trace-atomics-wait[trace Atomics.wait operations]' \
  '--trace-deprecation[show stack traces on deprecations]' \
  '--trace-event-categories[comma separated list of trace event categories to record]: :{_values -s , categories node node.async_hooks node.bootstrap node.perf node.perf.usertiming node.perf.timerify node.fs.sync node.vm.script v8}' \
  '--trace-event-file-pattern[Template string specifying the filepath for the trace-events data, it supports ${rotation} and ${pid} log-rotation id. %2$u is the pid.]:template string' \
  '--trace-exit[show stack trace when an environment exits]' \
  '--trace-sigint[prints a stack trace on SIGINT]' \
  '--trace-sync-io[show stack trace when use of sync IO is detected after the first tick]' \
  '--trace-tls[prints TLS packet trace information to stderr]' \
  '--trace-uncaught[show stack traces for the throw behind uncaught exceptions]' \
  '--trace-warnings[show stack traces on process warnings]' \
  '--track-heap-objects[track heap object allocations for heap snapshots]' \
  '--unhandled-rejections=[define unhandled rejections behavior]:rejection behavior:(strict warn none)' \
  '--update-assert-snapshot[update assert snapshot files]' \
  '--use-bundled-ca[use bundled CA store (default)]' \
  '--use-largepages=[re-map the Node.js static code to large memory pages at startup]:mode:(off on silent)' \
  "--use-openssl-ca[use OpenSSL's default CA store]" \
  '(- 1 *)--v8-options[print v8 command line options]' \
  "--v8-pool-size=[set v8's thread pool size]:number" \
  "--watch[run in watch mode]" \
  "--watch-path=[path to watch]: :_node_files" \
  '--watch-preserve-output[preserve outputs on watch mode restart]' \
  '--zero-fill-buffers[automatically zero-fill all newly allocated Buffer and SlowBuffer instances]' \
  {-c,--check}'[syntax check script without executing]' \
  '(- 1 *)'{-e,--eval}'[evaluate script]:inline JavaScript' \
  '(- 1 *)'{-h,--help}'[print node command line options]' \
  {-i,--interactive}'[always enter the REPL even if stdin does not appear to be a terminal]' \
  '(- 1 *)'{-p,--print}'[evaluate script and print result]:inline JavaScript' \
  '*'{-r,--require}'[module to preload (option can be repeated)]: :_node_files' \
  '(- 1 *)'{-v,--version}'[print Node.js version]' \
  '*: :_node_args' && ret=0

return ret

# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et
