From 46065f20849d8b20bcba7959b4d16b63af92c8d5 Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Fri, 29 Oct 2021 15:03:15 -0400 Subject: [PATCH] chore(typescript): add typings for `@vercel/ncc` --- .eslintrc.base.cjs | 1 + typings/@vercel/ncc/index.d.ts | 207 +++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 typings/@vercel/ncc/index.d.ts diff --git a/.eslintrc.base.cjs b/.eslintrc.base.cjs index 8c561dd5..38d1d131 100644 --- a/.eslintrc.base.cjs +++ b/.eslintrc.base.cjs @@ -127,6 +127,7 @@ module.exports = { 'postinstall', 'prepack', 'rimraf', + 'stringified', 'tgz', 'tsc', 'tsconfig', diff --git a/typings/@vercel/ncc/index.d.ts b/typings/@vercel/ncc/index.d.ts new file mode 100644 index 00000000..12b79b26 --- /dev/null +++ b/typings/@vercel/ncc/index.d.ts @@ -0,0 +1,207 @@ +declare module '@vercel/ncc' { + import type { NumberString } from '@flex-development/tutils' + + export type NccOptions = { + /** + * Build assets (including those in `existingAssetNames`) with `ncc`. + * + * @default false + */ + assetBuilds?: boolean + + /** + * Path to custom cache directory or `false` to disable caching. + */ + cache?: string | false + + /** + * [Custom functional asset emitter][1]. + * + * [1]: https://github.com/vercel/webpack-asset-relocator-loader#usage-1 + * + * @default undefined + */ + customEmit?: ( + path: string, + context: { id: string; isRequire: boolean } + ) => false | string + + /** + * Enable debug logging. + * + * @default false + */ + debugLog?: boolean + + /** + * Enable ES module output. + * + * If building a `.mjs` or `.js` module inside a `"type": "module"` [package + * boundary][1], an ES module output will be created automatically. + * + * [1]: https://nodejs.org/api/packages.html#packages_package_json_and_file_extensions + */ + esm?: boolean + + /** + * Names of existing build assets. + */ + existingAssetNames?: string[] + + /** + * Dependencies to leave as requires of the build. + * + * @default [] + */ + externals?: string[] + + /** + * Bundle filename. + * + * @default index.(cjs|js|mjs) + */ + filename?: string + + /** + * Directory outside of which never to emit assets. + * + * @default process.cwd() + */ + filterAssetBase?: string + + /** + * Name of file containing licensing information. + * + * @default '' + */ + license?: string + + /** + * Use [`terser`][1] to mangle and compress build output. + * + * [1]: https://github.com/terser/terser + * + * @default false + */ + minify?: boolean + + /** + * Create bundle for production environment. + * + * @default false + */ + production?: boolean + + /** + * Disable logging. + * + * @default false + */ + quiet?: boolean + + /** + * Enable source mapping. + * + * @default false + */ + sourceMap?: boolean + + /** + * Base directory prefix. Use to create `;// CONCATENATED MODULE:` comments. + * + * The default treats sources as output-relative. + * + * @default '../' + */ + sourceMapBasePrefix?: string + + /** + * When outputting a sourcemap, include [`source-map-support`][1] in the + * output file (increases output by `32kB`). + * + * [1]: https://github.com/evanw/node-source-map-support + * + * @default true + */ + sourceMapRegister?: boolean + + /** + * Build [target][1]. + * + * [1]: https://www.typescriptlang.org/tsconfig#target + */ + target?: `es${number | 'next'}` + + /** + * Disable type-checking. + * + * @default false + */ + transpileOnly?: boolean + + /** + * Use the [v8 cache]. Not supported for ES modules. + * + * [1]: https://nodejs.org/api/vm.html#scriptcreatecacheddata + * + * @default false + */ + v8cache?: boolean + + /** + * Rebuild project when changes to the input entry are detected. + * + * @default false + */ + watch?: boolean + } + + export type NccBuild = { + /** + * Emitted assets map. + */ + assets: Record + + /** + * Bundle output. + */ + code: string + + /** + * Stringified sourcemap. + */ + map: string | undefined + } + + export type NccWatcher = { + /** + * Close the watcher. + */ + close(): void + + /** + * Handler re-run on each build completion. + * + * Watch errors are reported on `err`. + */ + handler(context: { + assets: NccBuild['assets'] + code: NccBuild['code'] + err: Error + map: NccBuild['map'] + }): void + + /** + * Handler re-run on each rebuild start. + */ + rebuild(): void + } + + export type NccResult = + NonNullable['watch'] extends true ? NccWatcher : NccBuild + + export default function ( + entry: string, + options?: NccOptions + ): Promise> +}