bridgetownrb / bridgetown

A next-generation progressive site generator & fullstack framework, powered by Ruby
https://www.bridgetownrb.com
MIT License
1.13k stars 114 forks source link

Empty lines on package.json #368

Closed eclectic-coding closed 3 years ago

eclectic-coding commented 3 years ago

When creating a new project: bridgetown new my_awesome_site, there are blank lines in the devDependencies section of the package.json. This does not affect the performance or stop the server, it is just an anomaly.

Bridgetown Version: 0.21.3

Current behavior

"devDependencies": {
    "browser-sync": "^2.26.7",
    "concurrently": "^5.2.0",
    "css-loader": "^4.3.0",
    "esbuild": "^0.12.7",
    "esbuild-loader": "^2.13.1",
    "file-loader": "^6.2.0",
    "mini-css-extract-plugin": "^1.3.1",

    "sass": "^1.32.8",
    "sass-loader": "^8.0.2",

    "webpack": "^5.39.1",
    "webpack-cli": "^4.7.2",
    "webpack-manifest-plugin": "^3.1.1",
    "webpack-merge": "^5.8.0"
  }

Additional context The blank lines are probably caused by the conditionals found in json.erb:

"devDependencies": {
    "browser-sync": "^2.26.7",
    "concurrently": "^5.2.0",
    "css-loader": "^4.3.0",
    "esbuild": "^0.12.7",
    "esbuild-loader": "^2.13.1",
    "file-loader": "^6.2.0",
    "mini-css-extract-plugin": "^1.3.1",
    <% if options["use-postcss"] %>
    "postcss": "^8.3.0",
    "postcss-flexbugs-fixes": "^4.1.0",
    "postcss-loader": "^4.3.0",
    "postcss-preset-env": "^6.7.0",
    <% else %>
    "sass": "^1.32.8",
    "sass-loader": "^8.0.2",
    <% end %>
    "webpack": "^5.39.1",
    "webpack-cli": "^4.7.2",
    "webpack-manifest-plugin": "^3.1.1",
    "webpack-merge": "^5.8.0"
  }

Computing environment (please complete the following information):

ayushn21 commented 3 years ago

Yup they're definitely caused by those conditionals. It's been annoying me for a while but I don't how how we can fix it. Any ideas?

KonnorRogers commented 3 years ago

@ayushn21 this should fix it:

    <% if options["use-postcss"] -%>
    "postcss": "^8.3.0",
    "postcss-flexbugs-fixes": "^4.1.0",
    "postcss-loader": "^4.3.0",
    "postcss-preset-env": "^6.7.0",
    <% else -%>
    "sass": "^1.32.8",
    "sass-loader": "^8.0.2",
    <% end -%>

im not at a computer to test it, but generally the - before the % will strip out new lines.

https://ruby-doc.org/stdlib-3.0.2/libdoc/erb/rdoc/ERB.html

you can also use a starting: - like this:

<%- else -%>

I think both syntaxes work.

eclectic-coding commented 3 years ago

I never knew that ... pretty slick. Thanks @ParamagicDev

@ayushn21 I will take care of the PR

ayushn21 commented 3 years ago

TIL @ParamagicDev, Thanks!

Thanks @eclectic-coding :)

ayushn21 commented 3 years ago

Could you make the change in this file at the same time as well please? @eclectic-coding

https://github.com/bridgetownrb/bridgetown/blob/main/bridgetown-core/lib/site_template/frontend/javascript/index.js.erb

Thanks :)

eclectic-coding commented 3 years ago

FYI ... <% if options["use-postcss"] -%> will only remove the empty line, but not the preceeding spaces:

"mini-css-extract-plugin": "^1.3.1",
    "postcss": "^8.3.0",

But <%- if options["use-postcss"] -%> will remove both. Pretty flexible, gotta love Ruby.