rollup 3.0.0-3 → 3.0.0-6

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.0.0-2
4
- Sat, 30 Jul 2022 12:51:34 GMT - commit 41906cedefbc03640d6e8ca23ce6975f3bb5c6a1
3
+ Rollup.js v3.0.0-5
4
+ Tue, 06 Sep 2022 05:29:28 GMT - commit 1d085668121abe6be83c28c212a02c181c16d2b8
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -9,11 +9,10 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
- const require$$0 = require('path');
13
- const url = require('url');
14
- const require$$0$1 = require('fs');
15
- const require$$2 = require('util');
16
- const process$1 = require('process');
12
+ const node_fs = require('node:fs');
13
+ const node_path = require('node:path');
14
+ const process$1 = require('node:process');
15
+ const node_url = require('node:url');
17
16
  const tty = require('tty');
18
17
  const rollup = require('./rollup.js');
19
18
  const mergeOptions = require('./mergeOptions.js');
@@ -173,122 +172,6 @@ function handleError(err, recover = false) {
173
172
  process$1.exit(1);
174
173
  }
175
174
 
176
- var getPackageType$2 = {exports: {}};
177
-
178
- const path$2 = require$$0;
179
-
180
- function isNodeModules$2(directory) {
181
- let basename = path$2.basename(directory);
182
- /* istanbul ignore next: platform specific branch */
183
- if (path$2.sep === '\\') {
184
- basename = basename.toLowerCase();
185
- }
186
-
187
- return basename === 'node_modules';
188
- }
189
-
190
- var isNodeModules_1 = isNodeModules$2;
191
-
192
- var cache = new Map();
193
-
194
- const path$1 = require$$0;
195
- const {promisify} = require$$2;
196
- const readFile = promisify(require$$0$1.readFile);
197
-
198
- const isNodeModules$1 = isNodeModules_1;
199
- const resultsCache$1 = cache;
200
-
201
- const promiseCache = new Map();
202
-
203
- async function getDirectoryTypeActual$1(directory) {
204
- if (isNodeModules$1(directory)) {
205
- return 'commonjs';
206
- }
207
-
208
- try {
209
- return JSON.parse(await readFile(path$1.resolve(directory, 'package.json'))).type || 'commonjs';
210
- } catch (_) {
211
- }
212
-
213
- const parent = path$1.dirname(directory);
214
- if (parent === directory) {
215
- return 'commonjs';
216
- }
217
-
218
- return getDirectoryType$1(parent);
219
- }
220
-
221
- async function getDirectoryType$1(directory) {
222
- if (resultsCache$1.has(directory)) {
223
- return resultsCache$1.get(directory);
224
- }
225
-
226
- if (promiseCache.has(directory)) {
227
- return promiseCache.get(directory);
228
- }
229
-
230
- const promise = getDirectoryTypeActual$1(directory);
231
- promiseCache.set(directory, promise);
232
- const result = await promise;
233
- resultsCache$1.set(directory, result);
234
- promiseCache.delete(directory);
235
-
236
- return result;
237
- }
238
-
239
- function getPackageType$1(filename) {
240
- return getDirectoryType$1(path$1.resolve(path$1.dirname(filename)));
241
- }
242
-
243
- var async = getPackageType$1;
244
-
245
- const path = require$$0;
246
- const {readFileSync} = require$$0$1;
247
-
248
- const isNodeModules = isNodeModules_1;
249
- const resultsCache = cache;
250
-
251
- function getDirectoryTypeActual(directory) {
252
- if (isNodeModules(directory)) {
253
- return 'commonjs';
254
- }
255
-
256
- try {
257
- return JSON.parse(readFileSync(path.resolve(directory, 'package.json'))).type || 'commonjs';
258
- } catch (_) {
259
- }
260
-
261
- const parent = path.dirname(directory);
262
- if (parent === directory) {
263
- return 'commonjs';
264
- }
265
-
266
- return getDirectoryType(parent);
267
- }
268
-
269
- function getDirectoryType(directory) {
270
- if (resultsCache.has(directory)) {
271
- return resultsCache.get(directory);
272
- }
273
-
274
- const result = getDirectoryTypeActual(directory);
275
- resultsCache.set(directory, result);
276
-
277
- return result;
278
- }
279
-
280
- function getPackageTypeSync$1(filename) {
281
- return getDirectoryType(path.resolve(path.dirname(filename)));
282
- }
283
-
284
- var sync = getPackageTypeSync$1;
285
-
286
- const getPackageType = async;
287
- const getPackageTypeSync = sync;
288
-
289
- getPackageType$2.exports = filename => getPackageType(filename);
290
- getPackageType$2.exports.sync = getPackageTypeSync;
291
-
292
175
  function batchWarnings() {
293
176
  let count = 0;
294
177
  const deferredWarnings = new Map();
@@ -621,11 +504,11 @@ async function loadAndRegisterPlugin(inputOptions, pluginText) {
621
504
  if (!plugin) {
622
505
  try {
623
506
  if (pluginText[0] == '.')
624
- pluginText = require$$0.resolve(pluginText);
507
+ pluginText = node_path.resolve(pluginText);
625
508
  // Windows absolute paths must be specified as file:// protocol URL
626
509
  // Note that we do not have coverage for Windows-only code paths
627
510
  else if (pluginText.match(/^[A-Za-z]:\\/)) {
628
- pluginText = url.pathToFileURL(require$$0.resolve(pluginText)).href;
511
+ pluginText = node_url.pathToFileURL(node_path.resolve(pluginText)).href;
629
512
  }
630
513
  plugin = await requireOrImport(pluginText);
631
514
  }
@@ -664,7 +547,7 @@ async function requireOrImport(pluginPath) {
664
547
  }
665
548
 
666
549
  async function loadConfigFile(fileName, commandOptions = {}) {
667
- const configs = await loadConfigsFromFile(fileName, commandOptions);
550
+ const configs = await getConfigList(getDefaultFromCjs(await getConfigFileExport(fileName, commandOptions)), commandOptions);
668
551
  const warnings = batchWarnings();
669
552
  try {
670
553
  const normalizedConfigs = [];
@@ -680,77 +563,91 @@ async function loadConfigFile(fileName, commandOptions = {}) {
680
563
  throw err;
681
564
  }
682
565
  }
683
- async function loadConfigsFromFile(fileName, commandOptions) {
684
- const extension = require$$0.extname(fileName);
685
- const configFileExport = commandOptions.configPlugin ||
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')
688
- ? await getDefaultFromTranspiledConfigFile(fileName, commandOptions)
689
- : getDefaultFromCjs((await import(url.pathToFileURL(fileName).href)).default);
690
- return getConfigList(configFileExport, commandOptions);
566
+ async function getConfigFileExport(fileName, commandOptions) {
567
+ if (commandOptions.configPlugin || commandOptions.bundleConfigAsCjs) {
568
+ try {
569
+ return await loadTranspiledConfigFile(fileName, commandOptions);
570
+ }
571
+ catch (err) {
572
+ if (err.message.includes('not defined in ES module scope')) {
573
+ return rollup.error(rollup.errCannotBundleConfigAsEsm(err));
574
+ }
575
+ throw err;
576
+ }
577
+ }
578
+ let cannotLoadEsm = false;
579
+ const handleWarning = (warning) => {
580
+ if (warning.message.includes('To load an ES module')) {
581
+ cannotLoadEsm = true;
582
+ }
583
+ };
584
+ process$1.on('warning', handleWarning);
585
+ try {
586
+ const fileUrl = node_url.pathToFileURL(fileName);
587
+ if (process$1.env.ROLLUP_WATCH) {
588
+ // We are adding the current date to allow reloads in watch mode
589
+ fileUrl.search = `?${Date.now()}`;
590
+ }
591
+ return (await import(fileUrl.href)).default;
592
+ }
593
+ catch (err) {
594
+ if (cannotLoadEsm) {
595
+ return rollup.error(rollup.errCannotLoadConfigAsCjs(err));
596
+ }
597
+ if (err.message.includes('not defined in ES module scope')) {
598
+ return rollup.error(rollup.errCannotLoadConfigAsEsm(err));
599
+ }
600
+ throw err;
601
+ }
602
+ finally {
603
+ process$1.off('warning', handleWarning);
604
+ }
691
605
  }
692
606
  function getDefaultFromCjs(namespace) {
693
- return namespace.__esModule ? namespace.default : namespace;
607
+ return namespace.default || namespace;
694
608
  }
695
- async function getDefaultFromTranspiledConfigFile(fileName, commandOptions) {
609
+ async function loadTranspiledConfigFile(fileName, { bundleConfigAsCjs, configPlugin, silent }) {
696
610
  const warnings = batchWarnings();
697
611
  const inputOptions = {
698
- external: (id) => (id[0] !== '.' && !require$$0.isAbsolute(id)) || id.slice(-5, id.length) === '.json',
612
+ external: (id) => (id[0] !== '.' && !node_path.isAbsolute(id)) || id.slice(-5, id.length) === '.json',
699
613
  input: fileName,
700
614
  onwarn: warnings.add,
701
615
  plugins: [],
702
616
  treeshake: false
703
617
  };
704
- await addPluginsFromCommandOption(commandOptions.configPlugin, inputOptions);
618
+ await addPluginsFromCommandOption(configPlugin, inputOptions);
705
619
  const bundle = await rollup.rollup(inputOptions);
706
- if (!commandOptions.silent && warnings.count > 0) {
620
+ if (!silent && warnings.count > 0) {
707
621
  stderr(bold(`loaded ${rollup.relativeId(fileName)} with warnings`));
708
622
  warnings.flush();
709
623
  }
710
624
  const { output: [{ code }] } = await bundle.generate({
711
625
  exports: 'named',
712
- format: 'cjs',
626
+ format: bundleConfigAsCjs ? 'cjs' : 'es',
713
627
  plugins: [
714
628
  {
715
629
  name: 'transpile-import-meta',
716
630
  resolveImportMeta(property, { moduleId }) {
717
631
  if (property === 'url') {
718
- return `'${url.pathToFileURL(moduleId).href}'`;
632
+ return `'${node_url.pathToFileURL(moduleId).href}'`;
719
633
  }
720
634
  if (property == null) {
721
- return `{url:'${url.pathToFileURL(moduleId).href}'}`;
635
+ return `{url:'${node_url.pathToFileURL(moduleId).href}'}`;
722
636
  }
723
637
  }
724
638
  }
725
639
  ]
726
640
  });
727
- return loadConfigFromBundledFile(fileName, code);
641
+ return loadConfigFromWrittenFile(node_path.join(node_path.dirname(fileName), `rollup.config-${Date.now()}.${bundleConfigAsCjs ? 'cjs' : 'mjs'}`), code);
728
642
  }
729
- function loadConfigFromBundledFile(fileName, bundledCode) {
730
- const resolvedFileName = require.resolve(fileName);
731
- const extension = require$$0.extname(resolvedFileName);
732
- const defaultLoader = require.extensions[extension];
733
- require.extensions[extension] = (module, requiredFileName) => {
734
- if (requiredFileName === resolvedFileName) {
735
- module._compile(bundledCode, requiredFileName);
736
- }
737
- else {
738
- if (defaultLoader) {
739
- defaultLoader(module, requiredFileName);
740
- }
741
- }
742
- };
743
- delete require.cache[resolvedFileName];
643
+ async function loadConfigFromWrittenFile(bundledFileName, bundledCode) {
644
+ await node_fs.promises.writeFile(bundledFileName, bundledCode);
744
645
  try {
745
- const config = getDefaultFromCjs(require(fileName));
746
- require.extensions[extension] = defaultLoader;
747
- return config;
646
+ return (await import(node_url.pathToFileURL(bundledFileName).href)).default;
748
647
  }
749
- catch (err) {
750
- if (err.code === 'ERR_REQUIRE_ESM') {
751
- return rollup.error(rollup.errTranspiledEsmConfig(fileName));
752
- }
753
- throw err;
648
+ finally {
649
+ // Not awaiting here saves some ms while potentially hiding a non-critical error
650
+ node_fs.promises.unlink(bundledFileName);
754
651
  }
755
652
  }
756
653
  async function getConfigList(configFileExport, commandOptions) {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.0.0-2
4
- Sat, 30 Jul 2022 12:51:34 GMT - commit 41906cedefbc03640d6e8ca23ce6975f3bb5c6a1
3
+ Rollup.js v3.0.0-5
4
+ Tue, 06 Sep 2022 05:29:28 GMT - commit 1d085668121abe6be83c28c212a02c181c16d2b8
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -37,7 +37,7 @@ function mergeOptions(config, rawCommandOptions = { external: [], globals: undef
37
37
  if (outputOptionsArray.length === 0)
38
38
  outputOptionsArray.push({});
39
39
  const outputOptions = outputOptionsArray.map(singleOutputOptions => mergeOutputOptions(singleOutputOptions, command, warn));
40
- rollup.warnUnknownOptions(command, Object.keys(inputOptions).concat(Object.keys(outputOptions[0]).filter(option => option !== 'sourcemapPathTransform'), Object.keys(commandAliases), 'config', 'environment', 'plugin', 'silent', 'failAfterWarnings', 'stdin', 'waitForBundleInput', 'configPlugin'), 'CLI flags', warn, /^_$|output$|config/);
40
+ rollup.warnUnknownOptions(command, Object.keys(inputOptions).concat(Object.keys(outputOptions[0]).filter(option => option !== 'sourcemapPathTransform'), Object.keys(commandAliases), 'bundleConfigAsCjs', 'config', 'environment', 'plugin', 'silent', 'failAfterWarnings', 'stdin', 'waitForBundleInput', 'configPlugin'), 'CLI flags', warn, /^_$|output$|config/);
41
41
  inputOptions.output = outputOptions;
42
42
  return inputOptions;
43
43
  }