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

Fix: solidus:install adds the frontend assets even if the repo does not have solidus_frontend #4251

Conversation

gsmendoza
Copy link
Contributor

Expected behavior

Given I have a Rails app

And the Rails app only has the following Solidus gems:

  • solidus_core
  • solidus_backend
  • solidus_api
  • solidus_sample

When I run bin/rails generate solidus:install --auto-accept

Then I should see that the vendor/assets/*/spree directories do not include frontend directories with its assets.

Actual behavior

The vendor/assets/*/spree directories include the frontend directories with their assets.

Cause

The defined? Spree::Frontend || Rails.env.test? in https://github.com/solidusio/solidus/blob/f524772df264fc4fffa971b992d2724f5060c1b7/core/lib/generators/solidus/install/install_generator.rb returns "expression".

Fix

Wrapping the argument of the defined? call in a parenthesis fixes the issue, for example:

defined?(Spree::Frontend) || Rails.env.test?

Similar issues

The backend assets have the same issue and fix.

Tested in

  • Ruby 2.5.3p105
  • Rails 6.1.4.4
  • Solidus master (7e0a386)

Demo

https://drive.google.com/file/d/1R-rWkHXfTmVOmv32_jV3QliMybFJ2YSP/view?usp=sharing

(Sorry, my lips are not in sync with the audio.)

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • N/A: I have updated Guides and README accordingly to this change (if needed)
  • N/A: I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

…ot have solidus_frontend

Expected behavior
-----------------

Given I have a Rails app

And the Rails app only has the following Solidus gems:

* solidus_core
* solidus_backend
* solidus_api
* solidus_sample

When I run `bin/rails generate solidus:install --auto-accept`

Then I should see that the `vendor/assets/*/spree` directories do not include frontend directories with its assets.

Actual behavior
---------------

The `vendor/assets/*/spree` directories include the frontend directories with their assets.

Cause
-----

The `defined? Spree::Frontend || Rails.env.test?` in https://github.com/solidusio/solidus/blob/f524772df264fc4fffa971b992d2724f5060c1b7/core/lib/generators/solidus/install/install_generator.rb returns `"expression"`.

Fix
---

Wrapping the argument of the `defined?` call in a parenthesis fixes the issue, for example:

```rb
defined?(Spree::Frontend) || Rails.env.test?
```

Similar issues
--------------

The backend assets have the same issue and fix.

Tested in
---------

* Ruby 2.5.3p105
* Rails 6.1.4.4
* Solidus master (7e0a386)
@gsmendoza gsmendoza marked this pull request as ready for review January 27, 2022 06:48
@jarednorman
Copy link
Member

Thanks @gsmendoza, and great work on your talk at the conference!

Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks, @gsmendoza!

@waiting-for-dev waiting-for-dev merged commit e9ca0fb into solidusio:master Jan 31, 2022
@waiting-for-dev waiting-for-dev deleted the gsmendoza/eng-288-fix-solidusinstall-adds-the-frontend branch January 31, 2022 04:01
gsmendoza added a commit to solidusio/solidus_starter_frontend that referenced this pull request Feb 21, 2022
Goal
----

We want the frontend assets and directories added to a Solidus app because
Solidus extensions assume that these files and directories exist. The Solidus
extensions typically link these pre-existing files to their assets.

Expected behavior
-----------------

Given I have a Solidus app without a frontend

When I apply the SolidusStarterFrontend template to the app

Then I should see the following frontend assets and directories added to the
app:

* `vendor/assets/images/spree/frontend`
* `vendor/assets/javascripts/spree/frontend/all.js`
* `vendor/assets/stylesheets/spree/frontend/all.css`

Current behavior
----------------

SolidusStarterFrontend doesn't add the frontend assets and directories to the
app's vendor directory.

Bug cause
---------

Prior to solidusio/solidus#4251, the Solidus Install
generator was adding the frontend assets during installation even if the app
didn't have `solidus_frontend` in its bundle. With the issue fixed,
SolidusStarterFrontend has to be updated to add these frontend assets by
itself.
gsmendoza added a commit to solidusio/solidus_starter_frontend that referenced this pull request Feb 22, 2022
Goal
----

We want the frontend assets and directories added to a Solidus app because
Solidus extensions assume that these files and directories exist. The Solidus
extensions typically link these pre-existing files to their assets.

Expected behavior
-----------------

Given I have a Solidus app without a frontend

When I apply the SolidusStarterFrontend template to the app

Then I should see the following frontend assets and directories added to the
app:

* `vendor/assets/images/spree/frontend`
* `vendor/assets/javascripts/spree/frontend/all.js`
* `vendor/assets/stylesheets/spree/frontend/all.css`

Current behavior
----------------

SolidusStarterFrontend doesn't add the frontend assets and directories to the
app's vendor directory.

Bug cause
---------

Prior to solidusio/solidus#4251, the Solidus Install
generator was adding the frontend assets during installation even if the app
didn't have `solidus_frontend` in its bundle. With the issue fixed,
SolidusStarterFrontend has to be updated to add these frontend assets by
itself.
gsmendoza added a commit to solidusio/solidus_starter_frontend that referenced this pull request Feb 22, 2022
Goal
----

We want the frontend assets and directories added to a Solidus app because
Solidus extensions assume that these files and directories exist. The Solidus
extensions typically link these pre-existing files to their assets.

Expected behavior
-----------------

Given I have a Solidus app without a frontend

When I apply the SolidusStarterFrontend template to the app

Then I should see the following frontend assets and directories added to the
app:

* `vendor/assets/images/spree/frontend`
* `vendor/assets/javascripts/spree/frontend/all.js`
* `vendor/assets/stylesheets/spree/frontend/all.css`

Current behavior
----------------

SolidusStarterFrontend doesn't add the frontend assets and directories to the
app's vendor directory.

Bug cause
---------

Prior to solidusio/solidus#4251, the Solidus Install
generator was adding the frontend assets during installation even if the app
didn't have `solidus_frontend` in its bundle. With the issue fixed,
SolidusStarterFrontend has to be updated to add these frontend assets by
itself.
gsmendoza added a commit to solidusio/solidus_starter_frontend that referenced this pull request Feb 22, 2022
Goal
----

We want the frontend assets and directories added to a Solidus app because
Solidus extensions assume that these files and directories exist. The Solidus
extensions typically link these pre-existing files to their assets.

Expected behavior
-----------------

Given I have a Solidus app without a frontend

When I apply the SolidusStarterFrontend template to the app

Then I should see the following frontend assets and directories added to the
app:

* `vendor/assets/images/spree/frontend`
* `vendor/assets/javascripts/spree/frontend/all.js`
* `vendor/assets/stylesheets/spree/frontend/all.css`

Current behavior
----------------

SolidusStarterFrontend doesn't add the frontend assets and directories to the
app's vendor directory.

Bug cause
---------

Prior to solidusio/solidus#4251, the Solidus Install
generator was adding the frontend assets during installation even if the app
didn't have `solidus_frontend` in its bundle. With the issue fixed,
SolidusStarterFrontend has to be updated to add these frontend assets by
itself.
gsmendoza added a commit to solidusio/solidus_starter_frontend that referenced this pull request Feb 22, 2022
Goal
----

We want the frontend assets and directories added to a Solidus app because
Solidus extensions assume that these files and directories exist. The Solidus
extensions typically link these pre-existing files to their assets.

Expected behavior
-----------------

Given I have a Solidus app without a frontend

When I apply the SolidusStarterFrontend template to the app

Then I should see the following frontend assets and directories added to the
app:

* `vendor/assets/images/spree/frontend`
* `vendor/assets/javascripts/spree/frontend/all.js`
* `vendor/assets/stylesheets/spree/frontend/all.css`

Current behavior
----------------

SolidusStarterFrontend doesn't add the frontend assets and directories to the
app's vendor directory.

Bug cause
---------

Prior to solidusio/solidus#4251, the Solidus Install
generator was adding the frontend assets during installation even if the app
didn't have `solidus_frontend` in its bundle. With the issue fixed,
SolidusStarterFrontend has to be updated to add these frontend assets by
itself.

Implementation
--------------

This copies as-is the vendored assets of solidus_frontend from
https://github.com/solidusio/solidus/tree/master/core/lib/generators/solidus/install/templates/vendor/assets.
gsmendoza added a commit to solidusio/solidus_starter_frontend that referenced this pull request Feb 22, 2022
Goal
----

We want the frontend assets and directories added to a Solidus app because
Solidus extensions assume that these files and directories exist. The Solidus
extensions typically link these pre-existing files to their assets.

Expected behavior
-----------------

Given I have a Solidus app without a frontend

When I apply the SolidusStarterFrontend template to the app

Then I should see the following frontend assets and directories added to the
app:

* `vendor/assets/images/spree/frontend`
* `vendor/assets/javascripts/spree/frontend/all.js`
* `vendor/assets/stylesheets/spree/frontend/all.css`

Current behavior
----------------

SolidusStarterFrontend doesn't add the frontend assets and directories to the
app's vendor directory.

Bug cause
---------

Prior to solidusio/solidus#4251, the Solidus Install
generator was adding the frontend assets during installation even if the app
didn't have `solidus_frontend` in its bundle. With the issue fixed,
SolidusStarterFrontend has to be updated to add these frontend assets by
itself.

Implementation
--------------

This copies as-is the vendored assets of solidus_frontend from
https://github.com/solidusio/solidus/tree/master/core/lib/generators/solidus/install/templates/vendor/assets.
gsmendoza added a commit to solidusio/solidus_dev_support that referenced this pull request Jun 8, 2022
This fixes the following error when running `bundle exec rake` in
SolidusPaypalCommercePlatform:

```
An error occurred in a `before(:suite)` hook.
Failure/Error: //= link spree/backend/all.js

Sprockets::FileNotFound:
  couldn't find file 'spree/backend/all.js'
  Checked in these paths:
    /home/gsmendoza/repos/solidusio-contrib/solidus_paypal_commerce_platform/spec/dummy/app/assets/config
    /home/gsmendoza/repos/solidusio-contrib/solidus_paypal_commerce_platform/spec/dummy/app/assets/images
    /home/gsmendoza/repos/solidusio-contrib/solidus_paypal_commerce_platform/spec/dummy/app/assets/stylesheets
    /home/gsmendoza/repos/solidusio-contrib/solidus_paypal_commerce_platform/app/assets/javascripts
    /home/gsmendoza/repos/solidusio-contrib/solidus_paypal_commerce_platform/app/assets/stylesheets
```

Cause
-----

`extension:specs`, the default rake task of SolidusPaypalCommercePlatform,
executes the rake tasks and Ruby methods below in the given order:

* The `extension` namespace defined in
  `SolidusDevSupport::RakeTasks#install_test_app_task`. This namespace invokes
  the `extension:test_app` task
  (https://github.com/solidusio/solidus_dev_support/blob/e5fec9c039607ab9e97c3f821cc49f9bbec08796/lib/solidus_dev_support/rake_tasks.rb#L47).

* The Solidus `extension:test_app` task
  (https://github.com/solidusio/solidus/blob/07c88ddd1603699939ac0343965fa88dc2e1851a/core/lib/spree/testing_support/extension_rake.rb#L7)

* The `common:test_app` rake task in `CommonRakeTasks#initialize`
  (https://github.com/solidusio/solidus/blob/07c88ddd1603699939ac0343965fa88dc2e1851a/core/lib/spree/testing_support/common_rake.rb#L14)

* `Solidus::InstallGenerator#setup_assets`
  (https://github.com/solidusio/solidus/blob/07c88ddd1603699939ac0343965fa88dc2e1851a/core/lib/generators/solidus/install/install_generator.rb#L81)

The `setup_assets` method would only install the `all.*` frontend and backend
assets if either

* `Spree::Frontend` and `Spree::Backend` are loaded, or
* The Rails environment is test.

Currently, when we run `bundle exec rake` in SolidusPaypalCommercePlatform,
neither condition is met:

* `Spree::Frontend` and `Spree::Backend` are NOT loaded.
* The Rails environment is development.

Trigger
-------

This bug surfaced after we applied
solidusio/solidus#4251 (Fix: solidus:install
adds the frontend assets even if the repo does not have
`solidus_frontend`).

Solution
--------

Considering that the `extension:test_app` rake task generates the
`spec/dummy` directory, we can assume that it is expected to run under
test environment.
gsmendoza added a commit to gsmendoza/solidus that referenced this pull request Jun 9, 2022
This fixes the following error when running `bundle exec rake` in
SolidusPaypalCommercePlatform:

```
An error occurred in a `before(:suite)` hook.
Failure/Error: //= link spree/backend/all.js

Sprockets::FileNotFound:
  couldn't find file 'spree/backend/all.js'
  Checked in these paths:
    /home/gsmendoza/repos/solidusio-contrib/solidus_paypal_commerce_platform/spec/dummy/app/assets/config
    /home/gsmendoza/repos/solidusio-contrib/solidus_paypal_commerce_platform/spec/dummy/app/assets/images
    /home/gsmendoza/repos/solidusio-contrib/solidus_paypal_commerce_platform/spec/dummy/app/assets/stylesheets
    /home/gsmendoza/repos/solidusio-contrib/solidus_paypal_commerce_platform/app/assets/javascripts
    /home/gsmendoza/repos/solidusio-contrib/solidus_paypal_commerce_platform/app/assets/stylesheets
```

Cause
-----

`bundle exec rake` executes [`Solidus::InstallGenerator#setup_assets`](https://github.com/solidusio/solidus/blob/07c88ddd1603699939ac0343965fa88dc2e1851a/core/lib/generators/solidus/install/install_generator.rb#L81),
which would only install the `all.*` frontend and backend assets if either

* `Spree::Frontend` and `Spree::Backend` are loaded, or
* The Rails environment is test.

Currently, when `bundle exec rake` executes
[`common:test_app`](https://github.com/solidusio/solidus/blob/07c88ddd1603699939ac0343965fa88dc2e1851a/core/lib/spree/testing_support/common_rake.rb)
to build the dummy app, it assigns the `RAILS_ENV` environment variable to
`'test'`. However, if `Rails.env` has already been called, for example, in the
`require ENV['LIB_NAME']` statement before the `RAILS_ENV` assigment, then
`Rails.env` would
[retain its value](https://github.com/rails/rails/blob/3872bc0e54d32e8bf3a6299b0bfe173d94b072fc/railties/lib/rails.rb#L72),
which would most likely be `'development'`.

Trigger
-------

This bug surfaced after we applied
solidusio#4251 (Fix: solidus:install adds the
frontend assets even if the repo does not have `solidus_frontend`).
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