Skip to content

Commit

Permalink
fix: update dep types (fixes #9475) (#9489)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Aug 2, 2022
1 parent c530d16 commit 937cecc
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 47 deletions.
74 changes: 61 additions & 13 deletions packages/vite/types/commonjs.d.ts
Expand Up @@ -7,17 +7,17 @@
*/
export interface RollupCommonJSOptions {
/**
* A picomatch pattern, or array of patterns, which specifies the files in
* A minimatch pattern, or array of patterns, which specifies the files in
* the build the plugin should operate on. By default, all files with
* extension `".cjs"` or those in `extensions` are included, but you can narrow
* this list by only including specific files. These files will be analyzed
* and transpiled if either the analysis does not find ES module specific
* statements or `transformMixedEsModules` is `true`.
* extension `".cjs"` or those in `extensions` are included, but you can
* narrow this list by only including specific files. These files will be
* analyzed and transpiled if either the analysis does not find ES module
* specific statements or `transformMixedEsModules` is `true`.
* @default undefined
*/
include?: string | RegExp | readonly (string | RegExp)[]
/**
* A picomatch pattern, or array of patterns, which specifies the files in
* A minimatch pattern, or array of patterns, which specifies the files in
* the build the plugin should _ignore_. By default, all files with
* extensions other than those in `extensions` or `".cjs"` are ignored, but you
* can exclude additional files. See also the `include` option.
Expand All @@ -37,7 +37,8 @@ export interface RollupCommonJSOptions {
*/
ignoreGlobal?: boolean
/**
* If false, skips source map generation for CommonJS modules. This will improve performance.
* If false, skips source map generation for CommonJS modules. This will
* improve performance.
* @default true
*/
sourceMap?: boolean
Expand Down Expand Up @@ -65,6 +66,39 @@ export interface RollupCommonJSOptions {
* @default false
*/
transformMixedEsModules?: boolean
/**
* By default, this plugin will try to hoist `require` statements as imports
* to the top of each file. While this works well for many code bases and
* allows for very efficient ESM output, it does not perfectly capture
* CommonJS semantics as the order of side effects like log statements may
* change. But it is especially problematic when there are circular `require`
* calls between CommonJS modules as those often rely on the lazy execution of
* nested `require` calls.
*
* Setting this option to `true` will wrap all CommonJS files in functions
* which are executed when they are required for the first time, preserving
* NodeJS semantics. Note that this can have an impact on the size and
* performance of the generated code.
*
* The default value of `"auto"` will only wrap CommonJS files when they are
* part of a CommonJS dependency cycle, e.g. an index file that is required by
* many of its dependencies. All other CommonJS files are hoisted. This is the
* recommended setting for most code bases.
*
* `false` will entirely prevent wrapping and hoist all files. This may still
* work depending on the nature of cyclic dependencies but will often cause
* problems.
*
* You can also provide a minimatch pattern, or array of patterns, to only
* specify a subset of files which should be wrapped in functions for proper
* `require` semantics.
*
* `"debug"` works like `"auto"` but after bundling, it will display a warning
* containing a list of ids that have been wrapped which can be used as
* minimatch pattern for fine-tuning.
* @default "auto"
*/
strictRequires?: boolean | string | RegExp | readonly (string | RegExp)[]
/**
* Sometimes you have to leave require statements unconverted. Pass an array
* containing the IDs or a `id => boolean` function.
Expand All @@ -75,14 +109,16 @@ export interface RollupCommonJSOptions {
* In most cases, where `require` calls are inside a `try-catch` clause,
* they should be left unconverted as it requires an optional dependency
* that may or may not be installed beside the rolled up package.
* Due to the conversion of `require` to a static `import` - the call is hoisted
* to the top of the file, outside of the `try-catch` clause.
* Due to the conversion of `require` to a static `import` - the call is
* hoisted to the top of the file, outside of the `try-catch` clause.
*
* - `true`: All `require` calls inside a `try` will be left unconverted.
* - `false`: All `require` calls inside a `try` will be converted as if the `try-catch` clause is not there.
* - `false`: All `require` calls inside a `try` will be converted as if the
* `try-catch` clause is not there.
* - `remove`: Remove all `require` calls from inside any `try` block.
* - `string[]`: Pass an array containing the IDs to left unconverted.
* - `((id: string) => boolean|'remove')`: Pass a function that control individual IDs.
* - `((id: string) => boolean|'remove')`: Pass a function that control
* individual IDs.
*
* @default false
*/
Expand Down Expand Up @@ -165,12 +201,17 @@ export interface RollupCommonJSOptions {
| 'preferred'
| 'namespace'
| ((id: string) => boolean | 'auto' | 'preferred' | 'namespace')

/**
* @default "auto"
*/
defaultIsModuleExports?: boolean | 'auto' | ((id: string) => boolean | 'auto')
/**
* Some modules contain dynamic `require` calls, or require modules that
* contain circular dependencies, which are not handled well by static
* imports. Including those modules as `dynamicRequireTargets` will simulate a
* CommonJS (NodeJS-like) environment for them with support for dynamic and
* circular dependencies.
* CommonJS (NodeJS-like) environment for them with support for dynamic
* dependencies. It also enables `strictRequires` for those modules.
*
* Note: In extreme cases, this feature may result in some paths being
* rendered as absolute in the final bundle. The plugin tries to avoid
Expand All @@ -179,4 +220,11 @@ export interface RollupCommonJSOptions {
* replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`.
*/
dynamicRequireTargets?: string | ReadonlyArray<string>
/**
* To avoid long paths when using the `dynamicRequireTargets` option, you can use this option to specify a directory
* that is a common parent for all files that use dynamic require statements. Using a directory higher up such as `/`
* may lead to unnecessarily long paths in the generated code and may expose directory names on your machine like your
* home directory name. By default it uses the current working directory.
*/
dynamicRequireRoot?: string
}
2 changes: 1 addition & 1 deletion packages/vite/types/connect.d.ts
Expand Up @@ -14,7 +14,7 @@ export namespace Connect {
export type ServerHandle = HandleFunction | http.Server

export class IncomingMessage extends http.IncomingMessage {
originalUrl?: http.IncomingMessage['url']
originalUrl?: http.IncomingMessage['url'] | undefined
}

export type NextFunction = (err?: any) => void
Expand Down
74 changes: 41 additions & 33 deletions packages/vite/types/http-proxy.d.ts
Expand Up @@ -27,16 +27,16 @@ export namespace HttpProxy {
export interface ProxyTargetDetailed {
host: string
port: number
protocol?: string
hostname?: string
socketPath?: string
key?: string
passphrase?: string
pfx?: Buffer | string
cert?: string
ca?: string
ciphers?: string
secureProtocol?: string
protocol?: string | undefined
hostname?: string | undefined
socketPath?: string | undefined
key?: string | undefined
passphrase?: string | undefined
pfx?: Buffer | string | undefined
cert?: string | undefined
ca?: string | undefined
ciphers?: string | undefined
secureProtocol?: string | undefined
}

export type ErrorCallback = (
Expand Down Expand Up @@ -189,54 +189,62 @@ export namespace HttpProxy {

export interface ServerOptions {
/** URL string to be parsed with the url module. */
target?: ProxyTarget
target?: ProxyTarget | undefined
/** URL string to be parsed with the url module. */
forward?: ProxyTargetUrl
forward?: ProxyTargetUrl | undefined
/** Object to be passed to http(s).request. */
agent?: any
/** Object to be passed to https.createServer(). */
ssl?: any
/** If you want to proxy websockets. */
ws?: boolean
ws?: boolean | undefined
/** Adds x- forward headers. */
xfwd?: boolean
xfwd?: boolean | undefined
/** Verify SSL certificate. */
secure?: boolean
secure?: boolean | undefined
/** Explicitly specify if we are proxying to another proxy. */
toProxy?: boolean
toProxy?: boolean | undefined
/** Specify whether you want to prepend the target's path to the proxy path. */
prependPath?: boolean
prependPath?: boolean | undefined
/** Specify whether you want to ignore the proxy path of the incoming request. */
ignorePath?: boolean
ignorePath?: boolean | undefined
/** Local interface string to bind for outgoing connections. */
localAddress?: string
localAddress?: string | undefined
/** Changes the origin of the host header to the target URL. */
changeOrigin?: boolean
changeOrigin?: boolean | undefined
/** specify whether you want to keep letter case of response header key */
preserveHeaderKeyCase?: boolean
preserveHeaderKeyCase?: boolean | undefined
/** Basic authentication i.e. 'user:password' to compute an Authorization header. */
auth?: string
auth?: string | undefined
/** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
hostRewrite?: string
hostRewrite?: string | undefined
/** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
autoRewrite?: boolean
autoRewrite?: boolean | undefined
/** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
protocolRewrite?: string
protocolRewrite?: string | undefined
/** rewrites domain of set-cookie headers. */
cookieDomainRewrite?: false | string | { [oldDomain: string]: string }
cookieDomainRewrite?:
| false
| string
| { [oldDomain: string]: string }
| undefined
/** rewrites path of set-cookie headers. Default: false */
cookiePathRewrite?: false | string | { [oldPath: string]: string }
cookiePathRewrite?:
| false
| string
| { [oldPath: string]: string }
| undefined
/** object with extra headers to be added to target requests. */
headers?: { [header: string]: string }
headers?: { [header: string]: string } | undefined
/** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
proxyTimeout?: number
proxyTimeout?: number | undefined
/** Timeout (in milliseconds) for incoming requests */
timeout?: number
timeout?: number | undefined
/** Specify whether you want to follow redirects. Default: false */
followRedirects?: boolean
followRedirects?: boolean | undefined
/** If set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the proxyRes event */
selfHandleResponse?: boolean
selfHandleResponse?: boolean | undefined
/** Buffer */
buffer?: stream.Stream
buffer?: stream.Stream | undefined
}
}
43 changes: 43 additions & 0 deletions packages/vite/types/terser.d.ts
Expand Up @@ -39,6 +39,7 @@ export namespace Terser {

export interface ParseOptions {
bare_returns?: boolean
/** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */
ecma?: ECMA
html5_comments?: boolean
shebang?: boolean
Expand Down Expand Up @@ -113,22 +114,59 @@ export namespace Terser {
keep_classnames?: boolean | RegExp
keep_fnames?: boolean | RegExp
module?: boolean
nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
properties?: boolean | ManglePropertiesOptions
reserved?: string[]
safari10?: boolean
toplevel?: boolean
}

/**
* An identifier mangler for which the output is invariant with respect to the source code.
*/
export interface SimpleIdentifierMangler {
/**
* Obtains the nth most favored (usually shortest) identifier to rename a variable to.
* The mangler will increment n and retry until the return value is not in use in scope, and is not a reserved word.
* This function is expected to be stable; Evaluating get(n) === get(n) should always return true.
* @param n - The ordinal of the identifier.
*/
get(n: number): string
}

/**
* An identifier mangler that leverages character frequency analysis to determine identifier precedence.
*/
export interface WeightedIdentifierMangler extends SimpleIdentifierMangler {
/**
* Modifies the internal weighting of the input characters by the specified delta.
* Will be invoked on the entire printed AST, and then deduct mangleable identifiers.
* @param chars - The characters to modify the weighting of.
* @param delta - The numeric weight to add to the characters.
*/
consider(chars: string, delta: number): number
/**
* Resets character weights.
*/
reset(): void
/**
* Sorts identifiers by character frequency, in preparation for calls to get(n).
*/
sort(): void
}

export interface ManglePropertiesOptions {
builtins?: boolean
debug?: boolean
keep_quoted?: boolean | 'strict'
nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
regex?: RegExp | string
reserved?: string[]
}

export interface FormatOptions {
ascii_only?: boolean
/** @deprecated Not implemented anymore */
beautify?: boolean
braces?: boolean
comments?:
Expand All @@ -148,6 +186,7 @@ export namespace Terser {
) => boolean)
ecma?: ECMA
ie8?: boolean
keep_numbers?: boolean
indent_level?: number
indent_start?: number
inline_script?: boolean
Expand Down Expand Up @@ -178,13 +217,16 @@ export namespace Terser {
export interface MinifyOptions {
compress?: boolean | CompressOptions
ecma?: ECMA
enclose?: boolean | string
ie8?: boolean
keep_classnames?: boolean | RegExp
keep_fnames?: boolean | RegExp
mangle?: boolean | MangleOptions
module?: boolean
nameCache?: object
format?: FormatOptions
/** @deprecated deprecated */
output?: FormatOptions
parse?: ParseOptions
safari10?: boolean
sourceMap?: boolean | SourceMapOptions
Expand All @@ -194,6 +236,7 @@ export namespace Terser {
export interface MinifyOutput {
code?: string
map?: object | string
decoded_map?: object | null
}

export interface SourceMapOptions {
Expand Down

0 comments on commit 937cecc

Please sign in to comment.