Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use export mode "auto" by default when preserving modules #3265

Merged
merged 5 commits into from Nov 30, 2019

Conversation

lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:
Resolves #3258

Description

This will make sure all files are treated as entry points with regard to how their exports are rendered when preserving modules. More precisely, unless output.exports is used, all files will be treated as having output.exports set to auto. This only has an effect for cjs and amd output:

// input
export default 42;

// cjs output
'use strict';

var main = 42;

module.exports = main;

// amd output
define(function () { 'use strict';

  var main = 42;

  return main;

});

Files that mix default and named exports will now produce warnings for those formats, though. However, those warnings are aggregated and truncated by the CLI to reduce visual noise. To prevent those warnings other than changing your code, you can force all files to use named export mode via output.exports: named in your config. This will produce the following:

// input
export default 42;

// cjs output
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var main = 42;

exports.default = main;

// amd output
define(['exports'], function (exports) { 'use strict';

	var main = 42;

	exports.default = main;

	Object.defineProperty(exports, '__esModule', { value: true });

});

That means that the default export will need to be accessed e.g. via require(./file.js).default. Rollup will make sure that internal exports will properly respect this.

@codecov
Copy link

codecov bot commented Nov 29, 2019

Codecov Report

Merging #3265 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3265      +/-   ##
==========================================
+ Coverage   92.79%   92.83%   +0.04%     
==========================================
  Files         170      170              
  Lines        5923     5934      +11     
  Branches     1792     1793       +1     
==========================================
+ Hits         5496     5509      +13     
  Misses        223      223              
+ Partials      204      202       -2
Impacted Files Coverage Δ
cli/run/batchWarnings.ts 95.27% <100%> (+1.1%) ⬆️
src/rollup/index.ts 97.05% <100%> (+0.02%) ⬆️
src/utils/getExportMode.ts 100% <100%> (+5%) ⬆️
src/utils/error.ts 100% <100%> (ø) ⬆️
src/finalisers/shared/getExportBlock.ts 100% <100%> (ø) ⬆️
src/Chunk.ts 93.97% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c547361...f807d9d. Read the comment docs.

@lukastaegert lukastaegert force-pushed the gh-3258-auto-export-mode-preserve-modules branch from f677bef to f807d9d Compare November 30, 2019 19:38
@lukastaegert lukastaegert merged commit bdd1e03 into master Nov 30, 2019
@lukastaegert lukastaegert deleted the gh-3258-auto-export-mode-preserve-modules branch November 30, 2019 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AMD modules unnecessarily uses exports when preservedModules is enabled
1 participant