Webpacker: Adding semicolons to environment.js causes installers to silently fail

Created on 8 Jul 2019  路  3Comments  路  Source: rails/webpacker

Hello,

I ran into an issue where some of the lines from the ERB and Vue installers were not added to my environment.js, though this could apply to any of the installers.

I figured out after looking through the source that it was because I added semicolons to my environment.js

https://github.com/rails/webpacker/blob/5d5b3b867d35b376f3fa2af7c9cee3bfdf6f0f7c/lib/install/vue.rb#L6-L9

I can see a couple solutions for how to resolve this:

  • Change the behavior so that it doesn't look exclusively for a line that doesn't end in a semi-colon (ideal, and I believe I could create a PR for this)
  • Emit a warning in the console when it can't find the string it is looking for, and add documentation detailing why this error was thrown (I'm not actually sure if this is possible, I can't find any functionality like this in thor)
bug help wanted webpack

All 3 comments

I've been thinking about this some more and realized that using a standard eslint config will also change quotes from single to double.

I'm currently working on a PR, and my regex is now looking like this (with both kinds of quotes and optional semicolon):
/require\(('|")@rails\/webpacker('|")\);?\n/

Another solution I came up with is avoid the quotes and semicolon completely:
/@rails\/webpacker.*\n/

Do either of these seem like good solutions? I also thought a helper method may be useful which converts a string like "require('@rails/webpacker')\n" to a regular expression that accounts for the quotes and the semicolon so regular expressions don't have to be written for every single string.

Kind of related, is there a reason not to use semicolons (and double quotes) by default?

Kind of related, is there a reason not to use semicolons (and double quotes) by default?

It's a contentious topic amongst developers. I fall on the "include semicolons" side since there are cases where ASI does not work. That being said, I respect that this repo falls on the "omit semicolons" side.

Single/double quotes are kind of interchangeable in JS, but not in ruby. If you submit a PR, I can provide feedback there. (it's easier to discuss with file context)

Done, thanks for the feedback

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ijdickinson picture ijdickinson  路  3Comments

pioz picture pioz  路  3Comments

itay-grudev picture itay-grudev  路  3Comments

FrankFang picture FrankFang  路  3Comments

suhomlineugene picture suhomlineugene  路  3Comments