UNPKG

16.7 kBTypeScriptView Raw
1import { BuildOptions, Metafile, Plugin as Plugin$1, Loader } from 'esbuild';
2import { SourceMap as SourceMap$1, TreeshakingOptions, TreeshakingPreset, InputOption } from 'rollup';
3import { RawSourceMap } from 'source-map';
4
5declare type GeneratedColumn = number;
6declare type SourcesIndex = number;
7declare type SourceLine = number;
8declare type SourceColumn = number;
9declare type NamesIndex = number;
10declare type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
11
12declare class TraceMap implements SourceMap {
13 version: SourceMapV3['version'];
14 file: SourceMapV3['file'];
15 names: SourceMapV3['names'];
16 sourceRoot: SourceMapV3['sourceRoot'];
17 sources: SourceMapV3['sources'];
18 sourcesContent: SourceMapV3['sourcesContent'];
19 resolvedSources: string[];
20 private _encoded;
21 private _decoded;
22 private _decodedMemo;
23 private _bySources;
24 private _bySourceMemos;
25 constructor(map: SourceMapInput, mapUrl?: string | null);
26}
27
28interface SourceMapV3 {
29 file?: string | null;
30 names: string[];
31 sourceRoot?: string;
32 sources: (string | null)[];
33 sourcesContent?: (string | null)[];
34 version: 3;
35}
36interface EncodedSourceMap extends SourceMapV3 {
37 mappings: string;
38}
39interface DecodedSourceMap extends SourceMapV3 {
40 mappings: SourceMapSegment[][];
41}
42interface Section {
43 offset: {
44 line: number;
45 column: number;
46 };
47 map: EncodedSourceMap | DecodedSourceMap | SectionedSourceMap;
48}
49interface SectionedSourceMap {
50 file?: string | null;
51 sections: Section[];
52 version: 3;
53}
54declare type SourceMapInput = string | Ro<EncodedSourceMap> | Ro<DecodedSourceMap> | TraceMap;
55declare type SectionedSourceMapInput = SourceMapInput | Ro<SectionedSourceMap>;
56declare abstract class SourceMap {
57 version: SourceMapV3['version'];
58 file: SourceMapV3['file'];
59 names: SourceMapV3['names'];
60 sourceRoot: SourceMapV3['sourceRoot'];
61 sources: SourceMapV3['sources'];
62 sourcesContent: SourceMapV3['sourcesContent'];
63 resolvedSources: SourceMapV3['sources'];
64}
65declare type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
66declare type RoArray<T> = Ro<T>[];
67declare type RoObject<T> = {
68 [K in keyof T]: T[K] | Ro<T[K]>;
69};
70
71/// <reference lib="es2015" />
72
73
74
75type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;
76
77interface ParseOptions {
78 bare_returns?: boolean;
79 /** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */
80 ecma?: ECMA;
81 html5_comments?: boolean;
82 shebang?: boolean;
83}
84
85interface CompressOptions {
86 arguments?: boolean;
87 arrows?: boolean;
88 booleans_as_integers?: boolean;
89 booleans?: boolean;
90 collapse_vars?: boolean;
91 comparisons?: boolean;
92 computed_props?: boolean;
93 conditionals?: boolean;
94 dead_code?: boolean;
95 defaults?: boolean;
96 directives?: boolean;
97 drop_console?: boolean;
98 drop_debugger?: boolean;
99 ecma?: ECMA;
100 evaluate?: boolean;
101 expression?: boolean;
102 global_defs?: object;
103 hoist_funs?: boolean;
104 hoist_props?: boolean;
105 hoist_vars?: boolean;
106 ie8?: boolean;
107 if_return?: boolean;
108 inline?: boolean | InlineFunctions;
109 join_vars?: boolean;
110 keep_classnames?: boolean | RegExp;
111 keep_fargs?: boolean;
112 keep_fnames?: boolean | RegExp;
113 keep_infinity?: boolean;
114 loops?: boolean;
115 module?: boolean;
116 negate_iife?: boolean;
117 passes?: number;
118 properties?: boolean;
119 pure_funcs?: string[];
120 pure_getters?: boolean | 'strict';
121 reduce_funcs?: boolean;
122 reduce_vars?: boolean;
123 sequences?: boolean | number;
124 side_effects?: boolean;
125 switches?: boolean;
126 toplevel?: boolean;
127 top_retain?: null | string | string[] | RegExp;
128 typeofs?: boolean;
129 unsafe_arrows?: boolean;
130 unsafe?: boolean;
131 unsafe_comps?: boolean;
132 unsafe_Function?: boolean;
133 unsafe_math?: boolean;
134 unsafe_symbols?: boolean;
135 unsafe_methods?: boolean;
136 unsafe_proto?: boolean;
137 unsafe_regexp?: boolean;
138 unsafe_undefined?: boolean;
139 unused?: boolean;
140}
141
142declare enum InlineFunctions {
143 Disabled = 0,
144 SimpleFunctions = 1,
145 WithArguments = 2,
146 WithArgumentsAndVariables = 3
147}
148
149interface MangleOptions {
150 eval?: boolean;
151 keep_classnames?: boolean | RegExp;
152 keep_fnames?: boolean | RegExp;
153 module?: boolean;
154 nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler;
155 properties?: boolean | ManglePropertiesOptions;
156 reserved?: string[];
157 safari10?: boolean;
158 toplevel?: boolean;
159}
160
161/**
162 * An identifier mangler for which the output is invariant with respect to the source code.
163 */
164interface SimpleIdentifierMangler {
165 /**
166 * Obtains the nth most favored (usually shortest) identifier to rename a variable to.
167 * The mangler will increment n and retry until the return value is not in use in scope, and is not a reserved word.
168 * This function is expected to be stable; Evaluating get(n) === get(n) should always return true.
169 * @param n The ordinal of the identifier.
170 */
171 get(n: number): string;
172}
173
174/**
175 * An identifier mangler that leverages character frequency analysis to determine identifier precedence.
176 */
177interface WeightedIdentifierMangler extends SimpleIdentifierMangler {
178 /**
179 * Modifies the internal weighting of the input characters by the specified delta.
180 * Will be invoked on the entire printed AST, and then deduct mangleable identifiers.
181 * @param chars The characters to modify the weighting of.
182 * @param delta The numeric weight to add to the characters.
183 */
184 consider(chars: string, delta: number): number;
185 /**
186 * Resets character weights.
187 */
188 reset(): void;
189 /**
190 * Sorts identifiers by character frequency, in preparation for calls to get(n).
191 */
192 sort(): void;
193}
194
195interface ManglePropertiesOptions {
196 builtins?: boolean;
197 debug?: boolean;
198 keep_quoted?: boolean | 'strict';
199 nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler;
200 regex?: RegExp | string;
201 reserved?: string[];
202}
203
204interface FormatOptions {
205 ascii_only?: boolean;
206 /** @deprecated Not implemented anymore */
207 beautify?: boolean;
208 braces?: boolean;
209 comments?: boolean | 'all' | 'some' | RegExp | ( (node: any, comment: {
210 value: string,
211 type: 'comment1' | 'comment2' | 'comment3' | 'comment4',
212 pos: number,
213 line: number,
214 col: number,
215 }) => boolean );
216 ecma?: ECMA;
217 ie8?: boolean;
218 keep_numbers?: boolean;
219 indent_level?: number;
220 indent_start?: number;
221 inline_script?: boolean;
222 keep_quoted_props?: boolean;
223 max_line_len?: number | false;
224 preamble?: string;
225 preserve_annotations?: boolean;
226 quote_keys?: boolean;
227 quote_style?: OutputQuoteStyle;
228 safari10?: boolean;
229 semicolons?: boolean;
230 shebang?: boolean;
231 shorthand?: boolean;
232 source_map?: SourceMapOptions;
233 webkit?: boolean;
234 width?: number;
235 wrap_iife?: boolean;
236 wrap_func_args?: boolean;
237}
238
239declare enum OutputQuoteStyle {
240 PreferDouble = 0,
241 AlwaysSingle = 1,
242 AlwaysDouble = 2,
243 AlwaysOriginal = 3
244}
245
246interface MinifyOptions {
247 compress?: boolean | CompressOptions;
248 ecma?: ECMA;
249 enclose?: boolean | string;
250 ie8?: boolean;
251 keep_classnames?: boolean | RegExp;
252 keep_fnames?: boolean | RegExp;
253 mangle?: boolean | MangleOptions;
254 module?: boolean;
255 nameCache?: object;
256 format?: FormatOptions;
257 /** @deprecated */
258 output?: FormatOptions;
259 parse?: ParseOptions;
260 safari10?: boolean;
261 sourceMap?: boolean | SourceMapOptions;
262 toplevel?: boolean;
263}
264
265interface SourceMapOptions {
266 /** Source map object, 'inline' or source map file content */
267 content?: SectionedSourceMapInput | string;
268 includeSources?: boolean;
269 filename?: string;
270 root?: string;
271 url?: string | 'inline';
272}
273
274/** Mark some properties as required, leaving others unchanged */
275declare type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> & Required<Pick<T, RK>>;
276
277type Logger = ReturnType<typeof createLogger>;
278declare const createLogger: (name?: string) => {
279 setName(_name: string): void;
280 success(label: string, ...args: any[]): void;
281 info(label: string, ...args: any[]): void;
282 error(label: string, ...args: any[]): void;
283 warn(label: string, ...args: any[]): void;
284 log(label: string, type: 'info' | 'success' | 'error' | 'warn', ...data: unknown[]): void;
285};
286
287type ChunkInfo = {
288 type: 'chunk';
289 code: string;
290 map?: string | RawSourceMap | null;
291 path: string;
292 /**
293 * Sets the file mode
294 */
295 mode?: number;
296 entryPoint?: string;
297 exports?: string[];
298 imports?: Metafile['outputs'][string]['imports'];
299};
300type RenderChunk = (this: PluginContext, code: string, chunkInfo: ChunkInfo) => MaybePromise<{
301 code: string;
302 map?: object | string | SourceMap$1 | null;
303} | undefined | null | void>;
304type BuildStart = (this: PluginContext) => MaybePromise<void>;
305type BuildEnd = (this: PluginContext, ctx: {
306 writtenFiles: WrittenFile[];
307}) => MaybePromise<void>;
308type ModifyEsbuildOptions = (this: PluginContext, options: BuildOptions) => void;
309type Plugin = {
310 name: string;
311 esbuildOptions?: ModifyEsbuildOptions;
312 buildStart?: BuildStart;
313 renderChunk?: RenderChunk;
314 buildEnd?: BuildEnd;
315};
316type PluginContext = {
317 format: Format;
318 splitting?: boolean;
319 options: NormalizedOptions;
320 logger: Logger;
321};
322type WrittenFile = {
323 readonly name: string;
324 readonly size: number;
325};
326
327type TreeshakingStrategy = boolean | TreeshakingOptions | TreeshakingPreset;
328
329type KILL_SIGNAL = 'SIGKILL' | 'SIGTERM';
330type Format = 'cjs' | 'esm' | 'iife';
331type ContextForOutPathGeneration = {
332 options: NormalizedOptions;
333 format: Format;
334 /** "type" field in project's package.json */
335 pkgType?: string;
336};
337type OutExtensionObject = {
338 js?: string;
339 dts?: string;
340};
341type OutExtensionFactory = (ctx: ContextForOutPathGeneration) => OutExtensionObject;
342type DtsConfig = {
343 entry?: InputOption;
344 /** Resolve external types used in dts files from node_modules */
345 resolve?: boolean | (string | RegExp)[];
346 /** Emit declaration files only */
347 only?: boolean;
348 /** Insert at the top of each output .d.ts file */
349 banner?: string;
350 /** Insert at the bottom */
351 footer?: string;
352 /**
353 * Overrides `compilerOptions`
354 * This option takes higher priority than `compilerOptions` in tsconfig.json
355 */
356 compilerOptions?: any;
357};
358type ExperimentalDtsConfig = {
359 entry?: InputOption;
360 /**
361 * Overrides `compilerOptions`
362 * This option takes higher priority than `compilerOptions` in tsconfig.json
363 */
364 compilerOptions?: any;
365};
366type BannerOrFooter = {
367 js?: string;
368 css?: string;
369} | ((ctx: {
370 format: Format;
371}) => {
372 js?: string;
373 css?: string;
374} | undefined);
375type BrowserTarget = 'chrome' | 'deno' | 'edge' | 'firefox' | 'hermes' | 'ie' | 'ios' | 'node' | 'opera' | 'rhino' | 'safari';
376type BrowserTargetWithVersion = `${BrowserTarget}${number}` | `${BrowserTarget}${number}.${number}` | `${BrowserTarget}${number}.${number}.${number}`;
377type EsTarget = 'es3' | 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext';
378type Target = BrowserTarget | BrowserTargetWithVersion | EsTarget;
379type Entry = string[] | Record<string, string>;
380/**
381 * The options available in tsup.config.ts
382 * Not all of them are available from CLI flags
383 */
384type Options = {
385 /** Optional config name to show in CLI output */
386 name?: string;
387 /**
388 * @deprecated Use `entry` instead
389 */
390 entryPoints?: Entry;
391 entry?: Entry;
392 /**
393 * Output different formats to different folder instead of using different extensions
394 */
395 legacyOutput?: boolean;
396 /**
397 * Compile target
398 *
399 * default to `node16`
400 */
401 target?: Target | Target[];
402 minify?: boolean | 'terser';
403 terserOptions?: MinifyOptions;
404 minifyWhitespace?: boolean;
405 minifyIdentifiers?: boolean;
406 minifySyntax?: boolean;
407 keepNames?: boolean;
408 watch?: boolean | string | (string | boolean)[];
409 ignoreWatch?: string[] | string;
410 onSuccess?: string | (() => Promise<void | undefined | (() => void | Promise<void>)>);
411 jsxFactory?: string;
412 jsxFragment?: string;
413 outDir?: string;
414 outExtension?: OutExtensionFactory;
415 format?: Format[] | Format;
416 globalName?: string;
417 env?: {
418 [k: string]: string;
419 };
420 define?: {
421 [k: string]: string;
422 };
423 dts?: boolean | string | DtsConfig;
424 experimentalDts?: boolean | string | ExperimentalDtsConfig;
425 sourcemap?: boolean | 'inline';
426 /** Always bundle modules matching given patterns */
427 noExternal?: (string | RegExp)[];
428 /** Don't bundle these modules */
429 external?: (string | RegExp)[];
430 /**
431 * Replace `process.env.NODE_ENV` with `production` or `development`
432 * `production` when the bundled is minified, `development` otherwise
433 */
434 replaceNodeEnv?: boolean;
435 /**
436 * Code splitting
437 * Default to `true` for ESM, `false` for CJS.
438 *
439 * You can set it to `true` explicitly, and may want to disable code splitting sometimes: [`#255`](https://github.com/egoist/tsup/issues/255)
440 */
441 splitting?: boolean;
442 /**
443 * Clean output directory before each build
444 */
445 clean?: boolean | string[];
446 esbuildPlugins?: Plugin$1[];
447 esbuildOptions?: (options: BuildOptions, context: {
448 format: Format;
449 }) => void;
450 /**
451 * Suppress non-error logs (excluding "onSuccess" process output)
452 */
453 silent?: boolean;
454 /**
455 * Skip node_modules bundling
456 * Will still bundle modules matching the `noExternal` option
457 */
458 skipNodeModulesBundle?: boolean;
459 /**
460 * @see https://esbuild.github.io/api/#pure
461 */
462 pure?: string | string[];
463 /**
464 * Disable bundling, default to true
465 */
466 bundle?: boolean;
467 /**
468 * This option allows you to automatically replace a global variable with an import from another file.
469 * @see https://esbuild.github.io/api/#inject
470 */
471 inject?: string[];
472 /**
473 * Emit esbuild metafile
474 * @see https://esbuild.github.io/api/#metafile
475 */
476 metafile?: boolean;
477 footer?: BannerOrFooter;
478 banner?: BannerOrFooter;
479 /**
480 * Target platform
481 * @default `node`
482 */
483 platform?: 'node' | 'browser' | 'neutral';
484 /**
485 * Esbuild loader option
486 */
487 loader?: Record<string, Loader>;
488 /**
489 * Disable config file with `false`
490 * Or pass a custom config filename
491 */
492 config?: boolean | string;
493 /**
494 * Use a custom tsconfig
495 */
496 tsconfig?: string;
497 /**
498 * Inject CSS as style tags to document head
499 * @default {false}
500 */
501 injectStyle?: boolean | ((css: string, fileId: string) => string);
502 /**
503 * Inject cjs and esm shims if needed
504 * @default false
505 */
506 shims?: boolean;
507 /**
508 * TSUP plugins
509 * @experimental
510 * @alpha
511 */
512 plugins?: Plugin[];
513 /**
514 * By default esbuild already does treeshaking
515 *
516 * But this option allow you to perform additional treeshaking with Rollup
517 *
518 * This can result in smaller bundle size
519 */
520 treeshake?: TreeshakingStrategy;
521 /**
522 * Copy the files inside `publicDir` to output directory
523 */
524 publicDir?: string | boolean;
525 killSignal?: KILL_SIGNAL;
526 /**
527 * Interop default within `module.exports` in cjs
528 * @default false
529 */
530 cjsInterop?: boolean;
531};
532interface NormalizedExperimentalDtsConfig {
533 entry: {
534 [entryAlias: string]: string;
535 };
536 compilerOptions?: any;
537}
538type NormalizedOptions = Omit<MarkRequired<Options, 'entry' | 'outDir'>, 'dts' | 'experimentalDts' | 'format'> & {
539 dts?: DtsConfig;
540 experimentalDts?: NormalizedExperimentalDtsConfig;
541 tsconfigResolvePaths: Record<string, string[]>;
542 tsconfigDecoratorMetadata?: boolean;
543 format: Format[];
544};
545
546type MaybePromise<T> = T | Promise<T>;
547
548declare const defineConfig: (options: Options | Options[] | ((overrideOptions: Options) => MaybePromise<Options | Options[]>)) => Options | Options[] | ((overrideOptions: Options) => MaybePromise<Options | Options[]>);
549declare function build(_options: Options): Promise<void>;
550
551export { Format, NormalizedOptions, Options, build, defineConfig };
552
\No newline at end of file