rollup 2.77.0 → 3.0.0-2

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.
package/dist/rollup.d.ts CHANGED
@@ -150,10 +150,6 @@ export interface EmittedChunk {
150
150
 
151
151
  export type EmittedFile = EmittedAsset | EmittedChunk;
152
152
 
153
- export type EmitAsset = (name: string, source?: string | Uint8Array) => string;
154
-
155
- export type EmitChunk = (id: string, options?: { name?: string }) => string;
156
-
157
153
  export type EmitFile = (emittedFile: EmittedFile) => string;
158
154
 
159
155
  interface ModuleInfo extends ModuleOptions {
@@ -185,22 +181,12 @@ export interface CustomPluginOptions {
185
181
  export interface PluginContext extends MinimalPluginContext {
186
182
  addWatchFile: (id: string) => void;
187
183
  cache: PluginCache;
188
- /** @deprecated Use `this.emitFile` instead */
189
- emitAsset: EmitAsset;
190
- /** @deprecated Use `this.emitFile` instead */
191
- emitChunk: EmitChunk;
192
184
  emitFile: EmitFile;
193
185
  error: (err: RollupError | string, pos?: number | { column: number; line: number }) => never;
194
- /** @deprecated Use `this.getFileName` instead */
195
- getAssetFileName: (assetReferenceId: string) => string;
196
- /** @deprecated Use `this.getFileName` instead */
197
- getChunkFileName: (chunkReferenceId: string) => string;
198
186
  getFileName: (fileReferenceId: string) => string;
199
187
  getModuleIds: () => IterableIterator<string>;
200
188
  getModuleInfo: GetModuleInfo;
201
189
  getWatchFiles: () => string[];
202
- /** @deprecated Use `this.resolve` instead */
203
- isExternal: IsExternal;
204
190
  load: (
205
191
  options: { id: string; resolveDependencies?: boolean } & Partial<PartialNull<ModuleOptions>>
206
192
  ) => Promise<ModuleInfo>;
@@ -212,8 +198,6 @@ export interface PluginContext extends MinimalPluginContext {
212
198
  importer?: string,
213
199
  options?: { custom?: CustomPluginOptions; isEntry?: boolean; skipSelf?: boolean }
214
200
  ) => Promise<ResolvedId | null>;
215
- /** @deprecated Use `this.resolve` instead */
216
- resolveId: (source: string, importer?: string) => Promise<string | null>;
217
201
  setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void;
218
202
  warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void;
219
203
  }
@@ -291,7 +275,8 @@ export type RenderChunkHook = (
291
275
  this: PluginContext,
292
276
  code: string,
293
277
  chunk: RenderedChunk,
294
- options: NormalizedOutputOptions
278
+ options: NormalizedOutputOptions,
279
+ meta: { chunks: Record<string, RenderedChunk> }
295
280
  ) =>
296
281
  | Promise<{ code: string; map?: SourceMapInput } | null>
297
282
  | { code: string; map?: SourceMapInput }
@@ -311,23 +296,10 @@ export type ResolveImportMetaHook = (
311
296
  options: { chunkId: string; format: InternalModuleFormat; moduleId: string }
312
297
  ) => string | null | void;
313
298
 
314
- export type ResolveAssetUrlHook = (
315
- this: PluginContext,
316
- options: {
317
- assetFileName: string;
318
- chunkId: string;
319
- format: InternalModuleFormat;
320
- moduleId: string;
321
- relativeAssetPath: string;
322
- }
323
- ) => string | null | void;
324
-
325
299
  export type ResolveFileUrlHook = (
326
300
  this: PluginContext,
327
301
  options: {
328
- assetReferenceId: string | null;
329
302
  chunkId: string;
330
- chunkReferenceId: string | null;
331
303
  fileName: string;
332
304
  format: InternalModuleFormat;
333
305
  moduleId: string;
@@ -336,7 +308,10 @@ export type ResolveFileUrlHook = (
336
308
  }
337
309
  ) => string | null | void;
338
310
 
339
- export type AddonHookFunction = (this: PluginContext) => string | Promise<string>;
311
+ export type AddonHookFunction = (
312
+ this: PluginContext,
313
+ chunk: RenderedChunk
314
+ ) => string | Promise<string>;
340
315
  export type AddonHook = string | AddonHookFunction;
341
316
 
342
317
  export type ChangeEvent = 'create' | 'update' | 'delete';
@@ -390,7 +365,7 @@ export interface PluginHooks extends OutputPluginHooks {
390
365
  }
391
366
 
392
367
  interface OutputPluginHooks {
393
- augmentChunkHash: (this: PluginContext, chunk: PreRenderedChunk) => string | void;
368
+ augmentChunkHash: (this: PluginContext, chunk: RenderedChunk) => string | void;
394
369
  generateBundle: (
395
370
  this: PluginContext,
396
371
  options: NormalizedOutputOptions,
@@ -414,8 +389,6 @@ interface OutputPluginHooks {
414
389
  outputOptions: NormalizedOutputOptions,
415
390
  inputOptions: NormalizedInputOptions
416
391
  ) => Promise<void> | void;
417
- /** @deprecated Use `resolveFileUrl` instead */
418
- resolveAssetUrl: ResolveAssetUrlHook;
419
392
  resolveFileUrl: ResolveFileUrlHook;
420
393
  resolveImportMeta: ResolveImportMetaHook;
421
394
  writeBundle: (
@@ -451,7 +424,6 @@ export type SyncPluginHooks = Exclude<keyof PluginHooks, AsyncPluginHooks>;
451
424
  export type FirstPluginHooks =
452
425
  | 'load'
453
426
  | 'renderDynamicImport'
454
- | 'resolveAssetUrl'
455
427
  | 'resolveDynamicImport'
456
428
  | 'resolveFileUrl'
457
429
  | 'resolveId'
@@ -514,15 +486,13 @@ export interface TreeshakingOptions
514
486
  extends Partial<Omit<NormalizedTreeshakingOptions, 'moduleSideEffects'>> {
515
487
  moduleSideEffects?: ModuleSideEffectsOption;
516
488
  preset?: TreeshakingPreset;
517
- /** @deprecated Use `moduleSideEffects` instead */
518
- pureExternalModules?: PureModulesOption;
519
489
  }
520
490
 
521
- interface GetManualChunkApi {
491
+ interface ManualChunkMeta {
522
492
  getModuleIds: () => IterableIterator<string>;
523
493
  getModuleInfo: GetModuleInfo;
524
494
  }
525
- export type GetManualChunk = (id: string, api: GetManualChunkApi) => string | null | void;
495
+ export type GetManualChunk = (id: string, meta: ManualChunkMeta) => string | null | void;
526
496
 
527
497
  export type ExternalOption =
528
498
  | (string | RegExp)[]
@@ -654,10 +624,12 @@ export type NormalizedAmdOptions = (
654
624
  define: string;
655
625
  };
656
626
 
627
+ type AddonFunction = (chunk: RenderedChunk) => string | Promise<string>;
628
+
657
629
  export interface OutputOptions {
658
630
  amd?: AmdOptions;
659
631
  assetFileNames?: string | ((chunkInfo: PreRenderedAsset) => string);
660
- banner?: string | (() => string | Promise<string>);
632
+ banner?: string | AddonFunction;
661
633
  chunkFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
662
634
  compact?: boolean;
663
635
  // only required for bundle.write
@@ -671,7 +643,7 @@ export interface OutputOptions {
671
643
  externalLiveBindings?: boolean;
672
644
  // only required for bundle.write
673
645
  file?: string;
674
- footer?: string | (() => string | Promise<string>);
646
+ footer?: string | AddonFunction;
675
647
  format?: ModuleFormat;
676
648
  freeze?: boolean;
677
649
  generatedCode?: GeneratedCodePreset | GeneratedCodeOptions;
@@ -680,14 +652,14 @@ export interface OutputOptions {
680
652
  indent?: string | boolean;
681
653
  inlineDynamicImports?: boolean;
682
654
  interop?: InteropType | GetInterop;
683
- intro?: string | (() => string | Promise<string>);
655
+ intro?: string | AddonFunction;
684
656
  manualChunks?: ManualChunksOption;
685
657
  minifyInternalExports?: boolean;
686
658
  name?: string;
687
659
  /** @deprecated Use "generatedCode.symbols" instead. */
688
660
  namespaceToStringTag?: boolean;
689
661
  noConflict?: boolean;
690
- outro?: string | (() => string | Promise<string>);
662
+ outro?: string | AddonFunction;
691
663
  paths?: OptionsPaths;
692
664
  plugins?: (OutputPlugin | null | false | undefined)[];
693
665
  /** @deprecated Use "generatedCode.constBindings" instead. */
@@ -708,7 +680,7 @@ export interface OutputOptions {
708
680
  export interface NormalizedOutputOptions {
709
681
  amd: NormalizedAmdOptions;
710
682
  assetFileNames: string | ((chunkInfo: PreRenderedAsset) => string);
711
- banner: () => string | Promise<string>;
683
+ banner: AddonFunction;
712
684
  chunkFileNames: string | ((chunkInfo: PreRenderedChunk) => string);
713
685
  compact: boolean;
714
686
  dir: string | undefined;
@@ -720,7 +692,7 @@ export interface NormalizedOutputOptions {
720
692
  extend: boolean;
721
693
  externalLiveBindings: boolean;
722
694
  file: string | undefined;
723
- footer: () => string | Promise<string>;
695
+ footer: AddonFunction;
724
696
  format: InternalModuleFormat;
725
697
  freeze: boolean;
726
698
  generatedCode: NormalizedGeneratedCodeOptions;
@@ -729,16 +701,17 @@ export interface NormalizedOutputOptions {
729
701
  indent: true | string;
730
702
  inlineDynamicImports: boolean;
731
703
  interop: GetInterop;
732
- intro: () => string | Promise<string>;
704
+ intro: AddonFunction;
733
705
  manualChunks: ManualChunksOption;
734
706
  minifyInternalExports: boolean;
735
707
  name: string | undefined;
708
+ /** @deprecated Use "generatedCode.symbols" instead. */
736
709
  namespaceToStringTag: boolean;
737
710
  noConflict: boolean;
738
- outro: () => string | Promise<string>;
711
+ outro: AddonFunction;
739
712
  paths: OptionsPaths;
740
713
  plugins: OutputPlugin[];
741
- /** @deprecated Use the "renderDynamicImport" plugin hook instead. */
714
+ /** @deprecated Use "generatedCode.constBindings" instead. */
742
715
  preferConst: boolean;
743
716
  preserveModules: boolean;
744
717
  preserveModulesRoot: string | undefined;
@@ -771,8 +744,6 @@ export interface PreRenderedAsset {
771
744
 
772
745
  export interface OutputAsset extends PreRenderedAsset {
773
746
  fileName: string;
774
- /** @deprecated Accessing "isAsset" on files in the bundle is deprecated, please use "type === \'asset\'" instead */
775
- isAsset: true;
776
747
  }
777
748
 
778
749
  export interface RenderedModule {
@@ -789,15 +760,12 @@ export interface PreRenderedChunk {
789
760
  isDynamicEntry: boolean;
790
761
  isEntry: boolean;
791
762
  isImplicitEntry: boolean;
792
- modules: {
793
- [id: string]: RenderedModule;
794
- };
763
+ moduleIds: string[];
795
764
  name: string;
796
765
  type: 'chunk';
797
766
  }
798
767
 
799
768
  export interface RenderedChunk extends PreRenderedChunk {
800
- code?: string;
801
769
  dynamicImports: string[];
802
770
  fileName: string;
803
771
  implicitlyLoadedBefore: string[];
@@ -805,12 +773,15 @@ export interface RenderedChunk extends PreRenderedChunk {
805
773
  [imported: string]: string[];
806
774
  };
807
775
  imports: string[];
808
- map?: SourceMap;
776
+ modules: {
777
+ [id: string]: RenderedModule;
778
+ };
809
779
  referencedFiles: string[];
810
780
  }
811
781
 
812
782
  export interface OutputChunk extends RenderedChunk {
813
783
  code: string;
784
+ map: SourceMap | null;
814
785
  }
815
786
 
816
787
  export interface SerializablePluginCache {
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.77.0
4
- Fri, 15 Jul 2022 10:23:18 GMT - commit 87da8ef24f61d6601dc550026fc59f8066bbb95d
3
+ Rollup.js v3.0.0-2
4
+ Fri, 15 Jul 2022 15:25:15 GMT - commit 13b0ef8778ca5ccfd54b113ef545bf235a4c7e34
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.77.0
4
- Fri, 15 Jul 2022 10:23:18 GMT - commit 87da8ef24f61d6601dc550026fc59f8066bbb95d
3
+ Rollup.js v3.0.0-2
4
+ Fri, 15 Jul 2022 15:25:15 GMT - commit 13b0ef8778ca5ccfd54b113ef545bf235a4c7e34
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.77.0
4
- Fri, 15 Jul 2022 10:23:18 GMT - commit 87da8ef24f61d6601dc550026fc59f8066bbb95d
3
+ Rollup.js v3.0.0-2
4
+ Fri, 15 Jul 2022 15:25:15 GMT - commit 13b0ef8778ca5ccfd54b113ef545bf235a4c7e34
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -10,8 +10,10 @@
10
10
  'use strict';
11
11
 
12
12
  const require$$0 = require('path');
13
- const process$1 = require('process');
14
13
  const url = require('url');
14
+ const require$$0$1 = require('fs');
15
+ const require$$2 = require('util');
16
+ const process$1 = require('process');
15
17
  const tty = require('tty');
16
18
  const rollup = require('./rollup.js');
17
19
  const mergeOptions = require('./mergeOptions.js');
@@ -170,6 +172,122 @@ function handleError(err, recover = false) {
170
172
  process$1.exit(1);
171
173
  }
172
174
 
175
+ var getPackageType$2 = {exports: {}};
176
+
177
+ const path$2 = require$$0;
178
+
179
+ function isNodeModules$2(directory) {
180
+ let basename = path$2.basename(directory);
181
+ /* istanbul ignore next: platform specific branch */
182
+ if (path$2.sep === '\\') {
183
+ basename = basename.toLowerCase();
184
+ }
185
+
186
+ return basename === 'node_modules';
187
+ }
188
+
189
+ var isNodeModules_1 = isNodeModules$2;
190
+
191
+ var cache = new Map();
192
+
193
+ const path$1 = require$$0;
194
+ const {promisify} = require$$2;
195
+ const readFile = promisify(require$$0$1.readFile);
196
+
197
+ const isNodeModules$1 = isNodeModules_1;
198
+ const resultsCache$1 = cache;
199
+
200
+ const promiseCache = new Map();
201
+
202
+ async function getDirectoryTypeActual$1(directory) {
203
+ if (isNodeModules$1(directory)) {
204
+ return 'commonjs';
205
+ }
206
+
207
+ try {
208
+ return JSON.parse(await readFile(path$1.resolve(directory, 'package.json'))).type || 'commonjs';
209
+ } catch (_) {
210
+ }
211
+
212
+ const parent = path$1.dirname(directory);
213
+ if (parent === directory) {
214
+ return 'commonjs';
215
+ }
216
+
217
+ return getDirectoryType$1(parent);
218
+ }
219
+
220
+ async function getDirectoryType$1(directory) {
221
+ if (resultsCache$1.has(directory)) {
222
+ return resultsCache$1.get(directory);
223
+ }
224
+
225
+ if (promiseCache.has(directory)) {
226
+ return promiseCache.get(directory);
227
+ }
228
+
229
+ const promise = getDirectoryTypeActual$1(directory);
230
+ promiseCache.set(directory, promise);
231
+ const result = await promise;
232
+ resultsCache$1.set(directory, result);
233
+ promiseCache.delete(directory);
234
+
235
+ return result;
236
+ }
237
+
238
+ function getPackageType$1(filename) {
239
+ return getDirectoryType$1(path$1.resolve(path$1.dirname(filename)));
240
+ }
241
+
242
+ var async = getPackageType$1;
243
+
244
+ const path = require$$0;
245
+ const {readFileSync} = require$$0$1;
246
+
247
+ const isNodeModules = isNodeModules_1;
248
+ const resultsCache = cache;
249
+
250
+ function getDirectoryTypeActual(directory) {
251
+ if (isNodeModules(directory)) {
252
+ return 'commonjs';
253
+ }
254
+
255
+ try {
256
+ return JSON.parse(readFileSync(path.resolve(directory, 'package.json'))).type || 'commonjs';
257
+ } catch (_) {
258
+ }
259
+
260
+ const parent = path.dirname(directory);
261
+ if (parent === directory) {
262
+ return 'commonjs';
263
+ }
264
+
265
+ return getDirectoryType(parent);
266
+ }
267
+
268
+ function getDirectoryType(directory) {
269
+ if (resultsCache.has(directory)) {
270
+ return resultsCache.get(directory);
271
+ }
272
+
273
+ const result = getDirectoryTypeActual(directory);
274
+ resultsCache.set(directory, result);
275
+
276
+ return result;
277
+ }
278
+
279
+ function getPackageTypeSync$1(filename) {
280
+ return getDirectoryType(path.resolve(path.dirname(filename)));
281
+ }
282
+
283
+ var sync = getPackageTypeSync$1;
284
+
285
+ const getPackageType = async;
286
+ const getPackageTypeSync = sync;
287
+
288
+ getPackageType$2.exports = filename => getPackageType(filename);
289
+ getPackageType$2.exports.sync = getPackageTypeSync;
290
+
173
291
  function batchWarnings() {
174
292
  let count = 0;
175
293
  const deferredWarnings = new Map();
@@ -495,7 +613,7 @@ async function loadAndRegisterPlugin(inputOptions, pluginText) {
495
613
  plugin = await requireOrImport(prefix + pluginText);
496
614
  break;
497
615
  }
498
- catch (_a) {
616
+ catch {
499
617
  // if this does not work, we try requiring the actual name below
500
618
  }
501
619
  }
@@ -540,14 +658,11 @@ async function requireOrImport(pluginPath) {
540
658
  try {
541
659
  return require(pluginPath);
542
660
  }
543
- catch (_a) {
661
+ catch {
544
662
  return import(pluginPath);
545
663
  }
546
664
  }
547
665
 
548
- function supportsNativeESM() {
549
- return Number(/^v(\d+)/.exec(process$1.version)[1]) >= 13;
550
- }
551
666
  async function loadAndParseConfigFile(fileName, commandOptions = {}) {
552
667
  const configs = await loadConfigFile(fileName, commandOptions);
553
668
  const warnings = batchWarnings();
@@ -568,11 +683,10 @@ async function loadAndParseConfigFile(fileName, commandOptions = {}) {
568
683
  async function loadConfigFile(fileName, commandOptions) {
569
684
  const extension = require$$0.extname(fileName);
570
685
  const configFileExport = commandOptions.configPlugin ||
571
- !(extension === '.cjs' || (extension === '.mjs' && supportsNativeESM()))
686
+ // We always transpile the .js non-module case because many legacy code bases rely on this
687
+ (extension === '.js' && getPackageType$2.exports.sync(fileName) !== 'module')
572
688
  ? await getDefaultFromTranspiledConfigFile(fileName, commandOptions)
573
- : extension === '.cjs'
574
- ? getDefaultFromCjs(require(fileName))
575
- : (await import(url.pathToFileURL(fileName).href)).default;
689
+ : getDefaultFromCjs((await import(url.pathToFileURL(fileName).href)).default);
576
690
  return getConfigList(configFileExport, commandOptions);
577
691
  }
578
692
  function getDefaultFromCjs(namespace) {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.77.0
4
- Fri, 15 Jul 2022 10:23:18 GMT - commit 87da8ef24f61d6601dc550026fc59f8066bbb95d
3
+ Rollup.js v3.0.0-2
4
+ Fri, 15 Jul 2022 15:25:15 GMT - commit 13b0ef8778ca5ccfd54b113ef545bf235a4c7e34
5
5
 
6
6
  https://github.com/rollup/rollup
7
7