From 937cecc7d89194d8672ab62beb92827f45764c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Tue, 2 Aug 2022 14:58:53 +0900 Subject: [PATCH] fix: update dep types (fixes #9475) (#9489) --- packages/vite/types/commonjs.d.ts | 74 ++++++++++++++++++++++++----- packages/vite/types/connect.d.ts | 2 +- packages/vite/types/http-proxy.d.ts | 74 ++++++++++++++++------------- packages/vite/types/terser.d.ts | 43 +++++++++++++++++ 4 files changed, 146 insertions(+), 47 deletions(-) diff --git a/packages/vite/types/commonjs.d.ts b/packages/vite/types/commonjs.d.ts index 5891a7573112a5..01948156deb1cd 100644 --- a/packages/vite/types/commonjs.d.ts +++ b/packages/vite/types/commonjs.d.ts @@ -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. @@ -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 @@ -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. @@ -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 */ @@ -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 @@ -179,4 +220,11 @@ export interface RollupCommonJSOptions { * replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`. */ dynamicRequireTargets?: string | ReadonlyArray + /** + * 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 } diff --git a/packages/vite/types/connect.d.ts b/packages/vite/types/connect.d.ts index 2fb97ebeb494ab..74c559b6a436f5 100644 --- a/packages/vite/types/connect.d.ts +++ b/packages/vite/types/connect.d.ts @@ -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 diff --git a/packages/vite/types/http-proxy.d.ts b/packages/vite/types/http-proxy.d.ts index 81b9226a4db669..5e2717eaa0fcbd 100644 --- a/packages/vite/types/http-proxy.d.ts +++ b/packages/vite/types/http-proxy.d.ts @@ -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 = ( @@ -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 } } diff --git a/packages/vite/types/terser.d.ts b/packages/vite/types/terser.d.ts index 5c24660eb98781..a704a20cdc71ae 100644 --- a/packages/vite/types/terser.d.ts +++ b/packages/vite/types/terser.d.ts @@ -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 @@ -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?: @@ -148,6 +186,7 @@ export namespace Terser { ) => boolean) ecma?: ECMA ie8?: boolean + keep_numbers?: boolean indent_level?: number indent_start?: number inline_script?: boolean @@ -178,6 +217,7 @@ export namespace Terser { export interface MinifyOptions { compress?: boolean | CompressOptions ecma?: ECMA + enclose?: boolean | string ie8?: boolean keep_classnames?: boolean | RegExp keep_fnames?: boolean | RegExp @@ -185,6 +225,8 @@ export namespace Terser { module?: boolean nameCache?: object format?: FormatOptions + /** @deprecated deprecated */ + output?: FormatOptions parse?: ParseOptions safari10?: boolean sourceMap?: boolean | SourceMapOptions @@ -194,6 +236,7 @@ export namespace Terser { export interface MinifyOutput { code?: string map?: object | string + decoded_map?: object | null } export interface SourceMapOptions {