@tochii/build 2.1.0 → 2.2.0

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