rollup 3.24.0 → 3.25.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.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.24.0
4
- Wed, 07 Jun 2023 04:46:58 GMT - commit bcd64961f92535d2d6d0b663d1e17a500374358b
3
+ Rollup.js v3.25.0
4
+ Sun, 11 Jun 2023 05:02:46 GMT - commit 23c111c87145d15b0de032a6c7eeb6596764d1cf
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,9 +1,10 @@
1
- import type { MergedRollupOptions, RollupWarning } from './rollup';
1
+ import type { LogHandler, MergedRollupOptions, RollupLog } from './rollup';
2
2
 
3
3
  export interface BatchWarnings {
4
- add: (warning: RollupWarning) => void;
4
+ add: (warning: RollupLog) => void;
5
5
  readonly count: number;
6
6
  flush: () => void;
7
+ log: LogHandler;
7
8
  readonly warningOccurred: boolean;
8
9
  }
9
10
 
@@ -11,7 +12,8 @@ export type LoadConfigFile = typeof loadConfigFile;
11
12
 
12
13
  export function loadConfigFile(
13
14
  fileName: string,
14
- commandOptions: any
15
+ commandOptions: any,
16
+ watchMode?: boolean
15
17
  ): Promise<{
16
18
  options: MergedRollupOptions[];
17
19
  warnings: BatchWarnings;
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.24.0
4
- Wed, 07 Jun 2023 04:46:58 GMT - commit bcd64961f92535d2d6d0b663d1e17a500374358b
3
+ Rollup.js v3.25.0
4
+ Sun, 11 Jun 2023 05:02:46 GMT - commit 23c111c87145d15b0de032a6c7eeb6596764d1cf
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
package/dist/rollup.d.ts CHANGED
@@ -32,6 +32,7 @@ export interface RollupLog {
32
32
  line: number;
33
33
  };
34
34
  message: string;
35
+ meta?: any;
35
36
  names?: string[];
36
37
  plugin?: string;
37
38
  pluginCode?: string;
@@ -41,6 +42,9 @@ export interface RollupLog {
41
42
  url?: string;
42
43
  }
43
44
 
45
+ export type LogLevel = 'warn' | 'info' | 'debug';
46
+ export type LogLevelOption = LogLevel | 'silent';
47
+
44
48
  export type SourceMapSegment =
45
49
  | [number]
46
50
  | [number, number, number, number]
@@ -128,8 +132,14 @@ export interface PluginCache {
128
132
  set<T = any>(id: string, value: T): void;
129
133
  }
130
134
 
135
+ export type LoggingFunction = (log: RollupLog | string | (() => RollupLog | string)) => void;
136
+
131
137
  export interface MinimalPluginContext {
138
+ debug: LoggingFunction;
139
+ error: (error: RollupError | string) => never;
140
+ info: LoggingFunction;
132
141
  meta: PluginContextMeta;
142
+ warn: LoggingFunction;
133
143
  }
134
144
 
135
145
  export interface EmittedAsset {
@@ -190,15 +200,22 @@ export interface CustomPluginOptions {
190
200
  [plugin: string]: any;
191
201
  }
192
202
 
203
+ type LoggingFunctionWithPosition = (
204
+ log: RollupLog | string | (() => RollupLog | string),
205
+ pos?: number | { column: number; line: number }
206
+ ) => void;
207
+
193
208
  export interface PluginContext extends MinimalPluginContext {
194
209
  addWatchFile: (id: string) => void;
195
210
  cache: PluginCache;
211
+ debug: LoggingFunction;
196
212
  emitFile: EmitFile;
197
- error: (error: RollupError | string, pos?: number | { column: number; line: number }) => never;
213
+ error: (error: RollupError | string) => never;
198
214
  getFileName: (fileReferenceId: string) => string;
199
215
  getModuleIds: () => IterableIterator<string>;
200
216
  getModuleInfo: GetModuleInfo;
201
217
  getWatchFiles: () => string[];
218
+ info: LoggingFunction;
202
219
  load: (
203
220
  options: { id: string; resolveDependencies?: boolean } & Partial<PartialNull<ModuleOptions>>
204
221
  ) => Promise<ModuleInfo>;
@@ -216,7 +233,7 @@ export interface PluginContext extends MinimalPluginContext {
216
233
  }
217
234
  ) => Promise<ResolvedId | null>;
218
235
  setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void;
219
- warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void;
236
+ warn: LoggingFunction;
220
237
  }
221
238
 
222
239
  export interface PluginContextMeta {
@@ -279,7 +296,11 @@ export type LoadResult = SourceDescription | string | NullValue;
279
296
  export type LoadHook = (this: PluginContext, id: string) => LoadResult;
280
297
 
281
298
  export interface TransformPluginContext extends PluginContext {
299
+ debug: LoggingFunctionWithPosition;
300
+ error: (error: RollupError | string, pos?: number | { column: number; line: number }) => never;
282
301
  getCombinedSourcemap: () => SourceMap;
302
+ info: LoggingFunctionWithPosition;
303
+ warn: LoggingFunctionWithPosition;
283
304
  }
284
305
 
285
306
  export type TransformResult = string | NullValue | Partial<SourceDescription>;
@@ -369,6 +390,7 @@ export interface FunctionPluginHooks {
369
390
  ) => void;
370
391
  load: LoadHook;
371
392
  moduleParsed: ModuleParsedHook;
393
+ onLog: (this: MinimalPluginContext, level: LogLevel, log: RollupLog) => boolean | NullValue;
372
394
  options: (this: MinimalPluginContext, options: InputOptions) => InputOptions | NullValue;
373
395
  outputOptions: (this: PluginContext, options: OutputOptions) => OutputOptions | NullValue;
374
396
  renderChunk: RenderChunkHook;
@@ -417,6 +439,7 @@ export type InputPluginHooks = Exclude<keyof FunctionPluginHooks, OutputPluginHo
417
439
 
418
440
  export type SyncPluginHooks =
419
441
  | 'augmentChunkHash'
442
+ | 'onLog'
420
443
  | 'outputOptions'
421
444
  | 'renderDynamicImport'
422
445
  | 'resolveFileUrl'
@@ -436,6 +459,7 @@ export type FirstPluginHooks =
436
459
  export type SequentialPluginHooks =
437
460
  | 'augmentChunkHash'
438
461
  | 'generateBundle'
462
+ | 'onLog'
439
463
  | 'options'
440
464
  | 'outputOptions'
441
465
  | 'renderChunk'
@@ -508,16 +532,32 @@ export type ExternalOption =
508
532
  | string
509
533
  | RegExp
510
534
  | ((source: string, importer: string | undefined, isResolved: boolean) => boolean | NullValue);
511
- export type PureModulesOption = boolean | string[] | IsPureModule;
535
+
512
536
  export type GlobalsOption = { [name: string]: string } | ((name: string) => string);
537
+
513
538
  export type InputOption = string | string[] | { [entryAlias: string]: string };
539
+
514
540
  export type ManualChunksOption = { [chunkAlias: string]: string[] } | GetManualChunk;
541
+
542
+ export type LogHandlerWithDefault = (
543
+ level: LogLevel,
544
+ log: RollupLog,
545
+ defaultHandler: LogOrStringHandler
546
+ ) => void;
547
+
548
+ export type LogOrStringHandler = (level: LogLevel | 'error', log: RollupLog | string) => void;
549
+
550
+ export type LogHandler = (level: LogLevel, log: RollupLog) => void;
551
+
515
552
  export type ModuleSideEffectsOption = boolean | 'no-external' | string[] | HasModuleSideEffects;
553
+
516
554
  export type PreserveEntrySignaturesOption = false | 'strict' | 'allow-extension' | 'exports-only';
555
+
517
556
  export type SourcemapPathTransformOption = (
518
557
  relativeSourcePath: string,
519
558
  sourcemapPath: string
520
559
  ) => string;
560
+
521
561
  export type SourcemapIgnoreListOption = (
522
562
  relativeSourcePath: string,
523
563
  sourcemapPath: string
@@ -536,6 +576,7 @@ export interface InputOptions {
536
576
  /** @deprecated Use the "inlineDynamicImports" output option instead. */
537
577
  inlineDynamicImports?: boolean;
538
578
  input?: InputOption;
579
+ logLevel?: LogLevelOption;
539
580
  makeAbsoluteExternalsRelative?: boolean | 'ifRelativeSource';
540
581
  /** @deprecated Use the "manualChunks" output option instead. */
541
582
  manualChunks?: ManualChunksOption;
@@ -543,6 +584,7 @@ export interface InputOptions {
543
584
  /** @deprecated Use the "maxParallelFileOps" option instead. */
544
585
  maxParallelFileReads?: number;
545
586
  moduleContext?: ((id: string) => string | NullValue) | { [id: string]: string };
587
+ onLog?: LogHandlerWithDefault;
546
588
  onwarn?: WarningHandlerWithDefault;
547
589
  perf?: boolean;
548
590
  plugins?: InputPluginOption;
@@ -571,6 +613,7 @@ export interface NormalizedInputOptions {
571
613
  /** @deprecated Use the "inlineDynamicImports" output option instead. */
572
614
  inlineDynamicImports: boolean | undefined;
573
615
  input: string[] | { [entryAlias: string]: string };
616
+ logLevel: LogLevelOption;
574
617
  makeAbsoluteExternalsRelative: boolean | 'ifRelativeSource';
575
618
  /** @deprecated Use the "manualChunks" output option instead. */
576
619
  manualChunks: ManualChunksOption | undefined;
@@ -578,7 +621,8 @@ export interface NormalizedInputOptions {
578
621
  /** @deprecated Use the "maxParallelFileOps" option instead. */
579
622
  maxParallelFileReads: number;
580
623
  moduleContext: (id: string) => string;
581
- onwarn: WarningHandler;
624
+ onLog: LogHandler;
625
+ onwarn: (warning: RollupLog) => void;
582
626
  perf: boolean;
583
627
  plugins: Plugin[];
584
628
  preserveEntrySignatures: PreserveEntrySignaturesOption;
@@ -764,10 +808,9 @@ export interface NormalizedOutputOptions {
764
808
  }
765
809
 
766
810
  export type WarningHandlerWithDefault = (
767
- warning: RollupWarning,
768
- defaultHandler: WarningHandler
811
+ warning: RollupLog,
812
+ defaultHandler: LoggingFunction
769
813
  ) => void;
770
- export type WarningHandler = (warning: RollupWarning) => void;
771
814
 
772
815
  export interface SerializedTimings {
773
816
  [label: string]: [number, number, number];
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.24.0
4
- Wed, 07 Jun 2023 04:46:58 GMT - commit bcd64961f92535d2d6d0b663d1e17a500374358b
3
+ Rollup.js v3.25.0
4
+ Sun, 11 Jun 2023 05:02:46 GMT - commit 23c111c87145d15b0de032a6c7eeb6596764d1cf
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.24.0
4
- Wed, 07 Jun 2023 04:46:58 GMT - commit bcd64961f92535d2d6d0b663d1e17a500374358b
3
+ Rollup.js v3.25.0
4
+ Sun, 11 Jun 2023 05:02:46 GMT - commit 23c111c87145d15b0de032a6c7eeb6596764d1cf
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.24.0
4
- Wed, 07 Jun 2023 04:46:58 GMT - commit bcd64961f92535d2d6d0b663d1e17a500374358b
3
+ Rollup.js v3.25.0
4
+ Sun, 11 Jun 2023 05:02:46 GMT - commit 23c111c87145d15b0de032a6c7eeb6596764d1cf
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.24.0
4
- Wed, 07 Jun 2023 04:46:58 GMT - commit bcd64961f92535d2d6d0b663d1e17a500374358b
3
+ Rollup.js v3.25.0
4
+ Sun, 11 Jun 2023 05:02:46 GMT - commit 23c111c87145d15b0de032a6c7eeb6596764d1cf
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -15,40 +15,33 @@ const process = require('node:process');
15
15
  const node_url = require('node:url');
16
16
  const rollup = require('./rollup.js');
17
17
 
18
- function batchWarnings() {
18
+ function batchWarnings(silent) {
19
19
  let count = 0;
20
20
  const deferredWarnings = new Map();
21
21
  let warningOccurred = false;
22
+ const add = (warning) => {
23
+ count += 1;
24
+ warningOccurred = true;
25
+ if (silent)
26
+ return;
27
+ if (warning.code in deferredHandlers) {
28
+ rollup.getOrCreate(deferredWarnings, warning.code, rollup.getNewArray).push(warning);
29
+ }
30
+ else if (warning.code in immediateHandlers) {
31
+ immediateHandlers[warning.code](warning);
32
+ }
33
+ else {
34
+ title(warning.message);
35
+ defaultBody(warning);
36
+ }
37
+ };
22
38
  return {
23
- add(warning) {
24
- count += 1;
25
- warningOccurred = true;
26
- if (warning.code in deferredHandlers) {
27
- rollup.getOrCreate(deferredWarnings, warning.code, rollup.getNewArray).push(warning);
28
- }
29
- else if (warning.code in immediateHandlers) {
30
- immediateHandlers[warning.code](warning);
31
- }
32
- else {
33
- title(warning.message);
34
- if (warning.url)
35
- info(warning.url);
36
- const id = warning.loc?.file || warning.id;
37
- if (id) {
38
- const loc = warning.loc
39
- ? `${rollup.relativeId(id)} (${warning.loc.line}:${warning.loc.column})`
40
- : rollup.relativeId(id);
41
- rollup.stderr(rollup.bold(rollup.relativeId(loc)));
42
- }
43
- if (warning.frame)
44
- info(warning.frame);
45
- }
46
- },
39
+ add,
47
40
  get count() {
48
41
  return count;
49
42
  },
50
43
  flush() {
51
- if (count === 0)
44
+ if (count === 0 || silent)
52
45
  return;
53
46
  const codes = [...deferredWarnings.keys()].sort((a, b) => deferredWarnings.get(b).length - deferredWarnings.get(a).length);
54
47
  for (const code of codes) {
@@ -57,6 +50,26 @@ function batchWarnings() {
57
50
  deferredWarnings.clear();
58
51
  count = 0;
59
52
  },
53
+ log(level, log) {
54
+ switch (level) {
55
+ case rollup.LOGLEVEL_WARN: {
56
+ return add(log);
57
+ }
58
+ case rollup.LOGLEVEL_DEBUG: {
59
+ if (!silent) {
60
+ rollup.stderr(rollup.bold(rollup.blue(log.message)));
61
+ defaultBody(log);
62
+ }
63
+ return;
64
+ }
65
+ default: {
66
+ if (!silent) {
67
+ rollup.stderr(rollup.bold(rollup.cyan(log.message)));
68
+ defaultBody(log);
69
+ }
70
+ }
71
+ }
72
+ },
60
73
  get warningOccurred() {
61
74
  return warningOccurred;
62
75
  }
@@ -187,6 +200,18 @@ const deferredHandlers = {
187
200
  }
188
201
  }
189
202
  };
203
+ function defaultBody(log) {
204
+ if (log.url) {
205
+ info(rollup.getRollupUrl(log.url));
206
+ }
207
+ const id = log.loc?.file || log.id;
208
+ if (id) {
209
+ const loc = log.loc ? `${rollup.relativeId(id)} (${log.loc.line}:${log.loc.column})` : rollup.relativeId(id);
210
+ rollup.stderr(rollup.bold(rollup.relativeId(loc)));
211
+ }
212
+ if (log.frame)
213
+ info(log.frame);
214
+ }
190
215
  function title(string_) {
191
216
  rollup.stderr(rollup.bold(rollup.yellow(`(!) ${string_}`)));
192
217
  }
@@ -387,13 +412,13 @@ async function requireOrImport(pluginPath) {
387
412
  }
388
413
  }
389
414
 
390
- const loadConfigFile = async (fileName, commandOptions = {}) => {
391
- const configs = await getConfigList(getDefaultFromCjs(await getConfigFileExport(fileName, commandOptions)), commandOptions);
392
- const warnings = batchWarnings();
415
+ const loadConfigFile = async (fileName, commandOptions = {}, watchMode = false) => {
416
+ const configs = await getConfigList(getDefaultFromCjs(await getConfigFileExport(fileName, commandOptions, watchMode)), commandOptions);
417
+ const warnings = batchWarnings(commandOptions.silent);
393
418
  try {
394
419
  const normalizedConfigs = [];
395
420
  for (const config of configs) {
396
- const options = await rollup.mergeOptions(config, commandOptions, warnings.add);
421
+ const options = await rollup.mergeOptions(config, watchMode, commandOptions, warnings.log);
397
422
  await addCommandPluginsToInputOptions(options, commandOptions);
398
423
  normalizedConfigs.push(options);
399
424
  }
@@ -404,14 +429,14 @@ const loadConfigFile = async (fileName, commandOptions = {}) => {
404
429
  throw error_;
405
430
  }
406
431
  };
407
- async function getConfigFileExport(fileName, commandOptions) {
432
+ async function getConfigFileExport(fileName, commandOptions, watchMode) {
408
433
  if (commandOptions.configPlugin || commandOptions.bundleConfigAsCjs) {
409
434
  try {
410
435
  return await loadTranspiledConfigFile(fileName, commandOptions);
411
436
  }
412
437
  catch (error_) {
413
438
  if (error_.message.includes('not defined in ES module scope')) {
414
- return rollup.error(rollup.errorCannotBundleConfigAsEsm(error_));
439
+ return rollup.error(rollup.logCannotBundleConfigAsEsm(error_));
415
440
  }
416
441
  throw error_;
417
442
  }
@@ -425,7 +450,7 @@ async function getConfigFileExport(fileName, commandOptions) {
425
450
  process.on('warning', handleWarning);
426
451
  try {
427
452
  const fileUrl = node_url.pathToFileURL(fileName);
428
- if (process.env.ROLLUP_WATCH) {
453
+ if (watchMode) {
429
454
  // We are adding the current date to allow reloads in watch mode
430
455
  fileUrl.search = `?${Date.now()}`;
431
456
  }
@@ -433,10 +458,10 @@ async function getConfigFileExport(fileName, commandOptions) {
433
458
  }
434
459
  catch (error_) {
435
460
  if (cannotLoadEsm) {
436
- return rollup.error(rollup.errorCannotLoadConfigAsCjs(error_));
461
+ return rollup.error(rollup.logCannotLoadConfigAsCjs(error_));
437
462
  }
438
463
  if (error_.message.includes('not defined in ES module scope')) {
439
- return rollup.error(rollup.errorCannotLoadConfigAsEsm(error_));
464
+ return rollup.error(rollup.logCannotLoadConfigAsEsm(error_));
440
465
  }
441
466
  throw error_;
442
467
  }
@@ -448,7 +473,7 @@ function getDefaultFromCjs(namespace) {
448
473
  return namespace.default || namespace;
449
474
  }
450
475
  async function loadTranspiledConfigFile(fileName, { bundleConfigAsCjs, configPlugin, silent }) {
451
- const warnings = batchWarnings();
476
+ const warnings = batchWarnings(!!silent);
452
477
  const inputOptions = {
453
478
  external: (id) => (id[0] !== '.' && !node_path.isAbsolute(id)) || id.slice(-5, id.length) === '.json',
454
479
  input: fileName,
@@ -458,10 +483,6 @@ async function loadTranspiledConfigFile(fileName, { bundleConfigAsCjs, configPlu
458
483
  };
459
484
  await addPluginsFromCommandOption(configPlugin, inputOptions);
460
485
  const bundle = await rollup.rollup(inputOptions);
461
- if (!silent && warnings.count > 0) {
462
- rollup.stderr(rollup.bold(`loaded ${rollup.relativeId(fileName)} with warnings`));
463
- warnings.flush();
464
- }
465
486
  const { output: [{ code }] } = await bundle.generate({
466
487
  exports: 'named',
467
488
  format: bundleConfigAsCjs ? 'cjs' : 'es',
@@ -479,6 +500,10 @@ async function loadTranspiledConfigFile(fileName, { bundleConfigAsCjs, configPlu
479
500
  }
480
501
  ]
481
502
  });
503
+ if (!silent && warnings.count > 0) {
504
+ rollup.stderr(rollup.bold(`loaded ${rollup.relativeId(fileName)} with warnings`));
505
+ warnings.flush();
506
+ }
482
507
  return loadConfigFromWrittenFile(node_path.join(node_path.dirname(fileName), `rollup.config-${Date.now()}.${bundleConfigAsCjs ? 'cjs' : 'mjs'}`), code);
483
508
  }
484
509
  async function loadConfigFromWrittenFile(bundledFileName, bundledCode) {
@@ -496,7 +521,7 @@ async function getConfigList(configFileExport, commandOptions) {
496
521
  ? configFileExport(commandOptions)
497
522
  : configFileExport);
498
523
  if (Object.keys(config).length === 0) {
499
- return rollup.error(rollup.errorMissingConfig());
524
+ return rollup.error(rollup.logMissingConfig());
500
525
  }
501
526
  return Array.isArray(config) ? config : [config];
502
527
  }