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

Adds freeze option for opting-out of Object.freeze usage #1696

Merged
merged 8 commits into from
Nov 22, 2017
Merged

Adds freeze option for opting-out of Object.freeze usage #1696

merged 8 commits into from
Nov 22, 2017

Conversation

bigtimebuddy
Copy link
Contributor

@bigtimebuddy bigtimebuddy commented Nov 4, 2017

Addresses #1693

Added

This PR adds the config option freeze (defaults to true). When set to false, it will no longer use Object.freeze for imported namespaces (import * as foo from ‘foo-module’).

Provides a convenient opt-out for namespace protection in cases where it is undesirable for projects. In the attached issue, the use-case is injecting deprecation warnings for removed namespace members.

bin/src/index.js Outdated
@@ -17,6 +17,7 @@ const command = minimist( process.argv.slice( 2 ), {
h: 'help',
i: 'input',
l: 'legacy',
z: 'frozen',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think quite specific feature should have an alias. Writing the full version will be less confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

@bigtimebuddy bigtimebuddy changed the title Master Adds frozen option for opting-out of Object.freeze usage Nov 5, 2017
Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides my suggestion to only make this an output option we NEED a test before this can be merged. Otherwise there is no guarantee future refinements will not break this functionality.

If you need any help, please tell us. Otherwise I think this is something useful we could put into the next feature release.

@@ -12,6 +12,7 @@ export default function mergeOptions ( config, command ) {
const inputOptions = {
input: getOption('input'),
legacy: getOption('legacy'),
frozen: getOption('frozen'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As freezing is something that only influences the form of the output, I would consider this to be an output option only and not something that belongs to the general options as well, what do you think? Having this duplicity between input and output options seems to me rather confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, good suggestion.

@lukastaegert lukastaegert added this to the 0.52.0 milestone Nov 20, 2017
@bigtimebuddy
Copy link
Contributor Author

Definitely will add unit-test(s). Thanks for reviewing @lukastaegert.

@bigtimebuddy bigtimebuddy changed the title Adds frozen option for opting-out of Object.freeze usage Adds freeze option for opting-out of Object.freeze usage Nov 20, 2017
@bigtimebuddy
Copy link
Contributor Author

I added a unit-test for freeze (also, renamed from frozen for a more intuitive name without the tense-change).

The test was working because there, normal and "output" options are merged. In the binary, this was not working since here, output options are only passed to bundle.generate() and therefore to Bundle.render(). With this change it should work now as intended.
@lukastaegert
Copy link
Member

Thanks, great test! There was just one issue left with the handling of options, see my comment. Otherwise I think this is fine now and can go into the next version.

@bigtimebuddy
Copy link
Contributor Author

Nice work! Thanks for this

@lukastaegert lukastaegert changed the base branch from master to release-0.52 November 22, 2017 05:30
@lukastaegert lukastaegert merged commit 3bf44e8 into rollup:release-0.52 Nov 22, 2017
@lukastaegert
Copy link
Member

lukastaegert commented Nov 22, 2017

I have started to assemble a branch for the next release but it will take another few days until I release it because I there are a few more PRs I want to have in there which are not ready yet.

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.

3 participants