Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Conversation

@chemoish
Copy link

@chemoish chemoish commented Jan 25, 2017

Attempts not to fix, but enlighten… This code is much too complicated for me to understand at face value.

Addresses: #92

const messages = defineMessages({
  test: {
    defaultMessage: 'Test',
    description: 'Test',
    id: 'test',
  },
});
let descriptors = [...reactIntl.messages.values()];
file.metadata['react-intl'] = {messages: descriptors};

console.log(opts.messagesDir, descriptors);

Current:

undefined [ { id: 'test', description: 'Test', defaultMessage: 'Test' } ]
./messages []
undefined []
./messages []

After:

undefined [ { id: 'test', description: 'Test', defaultMessage: 'Test' } ]
./messages [ { id: 'test', description: 'Test', defaultMessage: 'Test' } ]
undefined []
./messages []

It looks like the writeFileSync only will be fired once opts.messagesDir && descriptors.length > 0 succeeds. This will only succeed in the second run through. However, it probably doesn't get to the second run through if it has already been flagged as extracted.

@ericf
Copy link
Collaborator

ericf commented Jan 25, 2017

Okay, so the real problem is that people are adding the plugin to their Babel config more than once. Since this plugin causes a side-effect — messages being written to a file — the first instance of the plugin to run must have been properly configured.

I will look at this more to see if there's a way to keep the optimizations (which I want to do) and either warn or delay the extraction (no-op) if an instance of the plugin hasn't been properly configured.

@ericf ericf mentioned this pull request Jan 25, 2017
@ericf
Copy link
Collaborator

ericf commented Jan 25, 2017

Closing in favor of #96

@ericf ericf closed this Jan 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants