Skip to content

Commit

Permalink
Wrap up version 7 changes (#301)
Browse files Browse the repository at this point in the history
* Improve contributing guideline

* Rename webpacker to shakapcker spec

* Rename backward compatiblity specs to follow rspec naming convention

* Use Thor for printing colorful warning

* Set CIs to run only with push

* Rename doc file for developing the gem

* Remove Rails 5 from CI

* Remove node 12 and add 18 in CI

* Improve readability of compile task

* Move test_app into gem spec directory

* Update contributing docs related to help wanted issues

* Reorganize Changelog

* Improve PR template
  • Loading branch information
ahangarha authored Jun 12, 2023
1 parent 83c42e8 commit e8927e0
Show file tree
Hide file tree
Showing 63 changed files with 103 additions and 101 deletions.
12 changes: 4 additions & 8 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
### Summary

_Remove this paragraph and provide a general description of the code changes in your pull
request... were there any bugs you had fixed? If so, mention them. If
these bugs have open GitHub issues, be sure to tag them here as well,
to keep the conversation linked together._
_Remove this paragraph and describe the code changes in your pull request... were there any bugs you had fixed? If so, mention them. If these bugs have open GitHub issues, tag them here as well to keep the conversation linked._

### Pull Request checklist
_Remove this line after checking all the items here. If the item is not applicable to the PR, both check it out and wrap it by `~`._
_Remove this line after checking all the items here. If the item does not apply to the PR, both check it out and wrap it by `~`._

- [ ] Add/update test to cover these changes
- [ ] Update documentation
- [ ] Update CHANGELOG file
_Add the CHANGELOG entry at the top of the file._
- [ ] Update CHANGELOG file

### Other Information

_Remove this parapraph and mention any other important and relevant information such as benchmarks._
_Remove this paragraph and mention other important and relevant information, such as benchmarks._
2 changes: 1 addition & 1 deletion .github/workflows/dummy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Dummy specs

on: [pull_request]
on: [push]

jobs:
test:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/jest.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Jest specs

on: [push, pull_request]
on: [push]

jobs:
jest:
name: Jest specs
strategy:
matrix:
os: [ubuntu-latest]
node: [12.x, 14.x, 16.x]
node: [14.x, 16.x, 18.x]

runs-on: ${{ matrix.os }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/js-lint.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: JS lint

on: [push, pull_request]
on: [push]

jobs:
lint:
name: JS Lint
strategy:
matrix:
os: [ubuntu-latest]
node: [12.x, 14.x, 16.x]
node: [14.x, 16.x, 18.x]

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Rubocop

on: [push, pull_request]
on: [push]

jobs:
rubocop:
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/ruby-backward-compatibility.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Ruby specs - Backward compatibility

on: [push, pull_request]
on: [push]

jobs:
test:
Expand All @@ -11,7 +11,6 @@ jobs:
os: [ubuntu-latest]
ruby: ['2.6', '2.7', '3.0']
gemfile:
- gemfiles/Gemfile-rails.5.2.x
- gemfiles/Gemfile-rails.6.0.x
- gemfiles/Gemfile-rails.6.1.x
- gemfiles/Gemfile-rails.7.0.x
Expand All @@ -25,9 +24,6 @@ jobs:
- ruby: 2.6
os: ubuntu-latest
gemfile: gemfiles/Gemfile-rails-edge
- ruby: 3.0
os: ubuntu-latest
gemfile: gemfiles/Gemfile-rails.5.2.x

env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Ruby specs

on: [push, pull_request]
on: [push]

jobs:
test:
Expand All @@ -11,7 +11,6 @@ jobs:
os: [ubuntu-latest]
ruby: ['2.6', '2.7', '3.0']
gemfile:
- gemfiles/Gemfile-rails.5.2.x
- gemfiles/Gemfile-rails.6.0.x
- gemfiles/Gemfile-rails.6.1.x
- gemfiles/Gemfile-rails.7.0.x
Expand All @@ -25,9 +24,6 @@ jobs:
- ruby: 2.6
os: ubuntu-latest
gemfile: gemfiles/Gemfile-rails-edge
- ruby: 3.0
os: ubuntu-latest
gemfile: gemfiles/Gemfile-rails.5.2.x

env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
Expand Down
33 changes: 14 additions & 19 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
Changes since last non-beta release.

_Please add entries here for your pull requests that are not yet released._
### Improved
- Set CSS modules mode depending on file type. [PR 261](https://github.com/shakacode/shakapacker/pull/261) by [talyuk](https://github.com/talyuk).

### Breaking changes
- Removes defaults passed to `@babel/preset-typescript`. [PR 273](https://github.com/shakacode/shakapacker/pull/273) by [tomdracz](https://github.com/tomdracz).
Expand All @@ -18,45 +16,42 @@ _Please add entries here for your pull requests that are not yet released._

- Export immutable webpackConfig function. [PR 293](https://github.com/shakacode/shakapacker/pull/293) by [tomdracz](https://github.com/tomdracz).

The `webpackConfig` property in the `shakapacker` module has been updated to be a function instead of a global mutable webpack configuration. This function now returns an immutable webpack configuration object, which ensures that any modifications made to it will not affect any other usage of the webpack configuration. If a project still requires the old mutable object, it can be accessed by replacing `webpackConfig` with `globalMutableWebpackConfig`.
The `webpackConfig` property in the `shakapacker` module has been updated to be a function instead of a global mutable webpack configuration. This function now returns an immutable webpack configuration object, which ensures that any modifications made to it will not affect any other usage of the webpack configuration. If a project still requires the old mutable object, it can be accessed by replacing `webpackConfig` with `globalMutableWebpackConfig`. Check [v7-upgrade](https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md) documentation for more detail.

### Improved
- Move compilation lock file into the working directory. [PR 272](https://github.com/shakacode/shakapacker/pull/272) by [tomdracz](https://github.com/tomdracz).
### Added
- Set CSS modules mode depending on file type. [PR 261](https://github.com/shakacode/shakapacker/pull/261) by [talyuk](https://github.com/talyuk).
- All standard webpack entries with the camelCase format are now supported in `shakapacker.yml` in snake_case format. [PR276](https://github.com/shakacode/shakapacker/pull/276) by [ahangarha](https://github.com/ahangarha).
- The `shakapacker:install` rake task now has an option to force overriding files using `FORCE=true` environment variable [PR311](https://github.com/shakacode/shakapacker/pull/311) by [ahangarha](https://github.com/ahangarha).

### Changed
- Rename Webpacker to Shakapacker in the entire project including config files, binstubs, environment variables, etc. with a high degree of backward compatibility.

This change might be breaking for certain setups and edge cases. More information: [v7 Upgrade Guide](./docs/v7_upgrade.md) [PR157](https://github.com/shakacode/shakapacker/pull/157) by [ahangarha](https://github.com/ahangarha)
- Set `source_entry_path` to `packs` and `nested_entries` to `true` in`shakapacker.yml` [PR 284](https://github.com/shakacode/shakapacker/pull/284) by [ahangarha](https://github.com/ahangarha).

### Fixed
- Process `source_entry_path` with values starting with `/` as a relative path to `source_path` [PR 284](https://github.com/shakacode/shakapacker/pull/284) by [ahangarha](https://github.com/ahangarha).

- Set `source_entry_path` to `packs` and `nested_entries` to `true` in`shakapacker.yml` [PR 284](https://github.com/shakacode/shakapacker/pull/284) by [ahangarha](https://github.com/ahangarha).
- Dev server configuration is modified to follow [webpack recommended configurations](https://webpack.js.org/configuration/dev-server/) for dev server. [PR276](https://github.com/shakacode/shakapacker/pull/276) by [ahangarha](https://github.com/ahangarha):
- Deprecated `https` entry is removed from the default configuration file, allowing to set `server` or `https` as per the project requirements. For more detail, check Webpack documentation. The `https` entry can be effective only if there is no `server` entry in the config file.
- Deprecated `https` entry is removed from the default configuration file, allowing to set `server` or `https` as per the project requirements. For more detail, check webpack documentation. The `https` entry can be effective only if there is no `server` entry in the config file.
- `allowed_hosts` is now set to `auto` instead of `all` by default.

- Removes defaults passed to `@babel/preset-typescript`. [PR 273](https://github.com/shakacode/shakapacker/pull/273) by [tomdracz](https://github.com/tomdracz).

`@babel/preset-typescript` has been initialised in default configuration with `{ allExtensions: true, isTSX: true }` - meaning every file in the codebase was treated as TSX leading to potential issues. This has been removed and returns to sensible default of the preset which is to figure out the file type from the extensions. This change might affect generated output however so it is marked as breaking.

- Remove the arbitrary stripping of the top-level directory when generating static file paths. [PR 283](https://github.com/shakacode/shakapacker/pull/283) by [tomdracz](https://github.com/tomdracz).

Prior to this change, top level directory of static assets like images and fonts was stripped. This meant that file in `app/javascript/images/image.png` would be output to `static/image.png` directory and could be referenced through helpers as `image_pack_tag("image.jpg")` or `image_pack_tag("static/image.jpg")`.

Going forward, the top level directory of static files will be retained so this will necessitate the update of file name references in asset helpers. In the example above, the file sourced from `app/javascript/images/image.png` will be now output to `static/images/image.png` and needs to be referenced as `image_pack_tag("images/image.jpg")` or `image_pack_tag("static/images/image.jpg")`.

### Fixed
- Move compilation lock file into the working directory. [PR 272](https://github.com/shakacode/shakapacker/pull/272) by [tomdracz](https://github.com/tomdracz).
- Process `source_entry_path` with values starting with `/` as a relative path to `source_path` [PR 284](https://github.com/shakacode/shakapacker/pull/284) by [ahangarha](https://github.com/ahangarha).
- Removes defaults passed to `@babel/preset-typescript` to make it possible to have projects with mix of JS and TS code [PR 273](https://github.com/shakacode/shakapacker/pull/273) by [tomdracz](https://github.com/tomdracz).

`@babel/preset-typescript` has been initialised in default configuration with `{ allExtensions: true, isTSX: true }` - meaning every file in the codebase was treated as TSX leading to potential issues. This has been removed and returns to sensible default of the preset which is to figure out the file type from the extensions. This change might affect generated output however so it is marked as breaking.

- Fixed RC version detection during installation. [PR312](https://github.com/shakacode/shakapacker/pull/312) by [ahangarha](https://github.com/ahangarha)
- Fix addition of webpack-dev-server to devDependencies during installation. [PR310](https://github.com/shakacode/shakapacker/pull/310) by [ahangarha](https://github.com/ahangarha)

### Removed
- Remove redundant enhancement for precompile task to run `yarn install` [PR 270](https://github.com/shakacode/shakapacker/pull/270) by [ahangarha](https://github.com/ahangarha).
- Remove deprecated `check_yarn_integrity` from `Shakapacker::Configuration` [PR SP288](https://github.com/shakacode/shakapacker/pull/288) by [ahangarha](https://github.com/ahangarha).

### Added
- All standard Webpack entries with the camelCase format are now supported in `shakapacker.yml` in snake_case format. [PR276](https://github.com/shakacode/shakapacker/pull/276) by [ahangarha](https://github.com/ahangarha).
- The `shakapacker:install` rake task now has an option to force overriding files using `FORCE=true` environment variable [PR311](https://github.com/shakacode/shakapacker/pull/311) by [ahangarha](https://github.com/ahangarha).

## [v6.6.0] - March 7, 2023
### Improved
- Allow configuration of webpacker.yml through env variable. [PR 254](https://github.com/shakacode/shakapacker/pull/254) by [alecslupu](https://github.com/alecslupu).
Expand Down
60 changes: 47 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,60 @@
# Contributing Guidelines

Thank you for your interest in contributing to Shakapacker! We welcome all contributions that align with our project goals and values. To ensure a smooth and productive collaboration, please follow these guidelines.

## Contents
- [Reporting Issues](#reporting-issues)
- [Submitting Pull Requests](#submitting-pull-requests)
- [Setting Up a Development Environment](#setting-up-a-development-environment)
- [Making sure your changes pass all tests](#making-sure-your-changes-pass-all-tests)
- [Testing the generator](#testing-the-generator)
- [Find existing issues](#find-existing-issues)

---
## Setting Up a Development Environment
## Reporting Issues
If you encounter any issues with the project, please first check the exisiting issues (including closed ones). If the issues is not reported before, please opening an issue on our GitHub repository. Please provide a clear and detailed description of the issue, including steps to reproduce it. Creating a demo repository to demonstrate the issue would be ideal (and in some cases necessary).

1. Install [Yarn](https://yarnpkg.com/)
If looking to contribute to the project by fixing existing issues, we recommend looking at issues, particularly with the "[help wanted](https://github.com/shakacode/shakapacker/issues?q=is%3Aissue+label%3A%22help+wanted%22)" label.

2. Run the following commands to set up the development environment.
## Submitting Pull Requests
We welcome pull requests that fix bugs, add new features, or improve existing ones. Before submitting a pull request, please make sure to:

```
bundle install
yarn
```
- Open an issue about what you want to propose before start working on.
- Fork the repository and create a new branch for your changes.
- Write clear and concise commit messages.
- Follow our code style guidelines.
- Write tests for your changes and [make sure all tests pass](#making-sure-your-changes-pass-all-tests).
- Update the documentation as needed.
- Update CHANGELOG.md if the changes affect public behavior of the project.

---
## Setting Up a Development Environment

1. Install [Yarn](https://classic.yarnpkg.com/)
2. To test your changes on a Rails test project do the following steps:
- For Ruby gem, update `Gemfile` and point the `shakapacker` to the locally developing Shakapacker project:
```ruby
gem 'shakapacker', path: "relative_or_absolute_path_to_local_shakapacker"
```
- For npm package, use `yalc` with following steps:
```bash
# In Shakapacker root directory
yalc publish
# In Rails app for testing
yalc link shakapacker
# After every chagnes in shakapacker, run the folloing in Shakapacker directory
yalc push # or yalc publish --push
```
3. Run the following commands to set up the development environment.
```
bundle install
yarn install
```
## Making sure your changes pass all tests
There are a number of automated checks which run on GitHub Actions when a pull request is created.
There are several specs, covering different aspects of Shakapacker gem. You may run them locally or rely on GitHub CI actions configured to test the gem functionality if different Ruby, Rails, and Node environment.
You can run those checks on your own locally to make sure that your changes would not break the CI build.
We request running tests locally to ensure the new changes would not break the CI build.
### 1. Check the code for JavaScript style violations
Expand All @@ -46,6 +80,8 @@ yarn test
bundle exec rake test
```
Note: For this, you need `yalc` to be installed on your local machine
#### 4.1 Run a single ruby test file
```
Expand Down Expand Up @@ -90,5 +126,3 @@ To ensure that your installer works as expected, either you can run `bundle exec

**Note:** Ensure that you use bundle exec otherwise the installed shakapacker gem will run and not the one you are working on.

## Find existing issues
You may look at the issues list to find existing known issues to be addressed. In this, we recommend looking at closed issues, particularly with the "[help wanted](https://github.com/shakacode/shakapacker/issues?q=is%3Aissue+label%3A%22help+wanted%22+is%3Aclosed+)" label.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace :run_spec do
desc "Run backward compatibility specs"
task :gem_bc do
puts "Running Shakapacker gem specs for backward compatibility"
sh("bundle exec rspec spec/backward_compatibility_specs/*_spec_bc.rb")
sh("bundle exec rspec spec/backward_compatibility_specs/*_spec.rb")
end

desc "Run specs in the dummy app"
Expand Down
File renamed without changes.
9 changes: 0 additions & 9 deletions gemfiles/Gemfile-rails.5.2.x

This file was deleted.

9 changes: 4 additions & 5 deletions lib/shakapacker/deprecation_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "thor"

module Shakapacker
DEPRECATION_GUIDE_URL = "https://github.com/shakacode/shakapacker/docs/v7_upgrade.md"
DEPRECATION_MESSAGE = <<~MSG
Expand All @@ -9,6 +11,7 @@ module Shakapacker
For more information about this process, check:
#{DEPRECATION_GUIDE_URL}
MSG
SHELL = Thor::Shell::Color.new

def get_config_file_path_with_backward_compatibility(config_path)
if config_path.to_s.end_with?("shakapacker.yml") && !File.exist?(config_path)
Expand Down Expand Up @@ -70,11 +73,7 @@ def short_deprecation_message(old_usage, new_usage)
end

def puts_deprecation_message(message)
puts <<~MSG
\e[33m
#{message}
\e[0m
MSG
SHELL.say "\n#{message}\n", :yellow
end

def puts_rake_deprecation_message(webpacker_task_name)
Expand Down
7 changes: 1 addition & 6 deletions lib/tasks/shakapacker/compile.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ namespace :shakapacker do
task compile: ["shakapacker:verify_install", :environment] do
Shakapacker.with_node_env(ENV.fetch("NODE_ENV", "production")) do
Shakapacker.ensure_log_goes_to_stdout do
if Shakapacker.compile
# Successful compilation!
else
# Failed compilation
exit!
end
exit! unless Shakapacker.compile
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion package/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const isArray = (value) => Array.isArray(value)
const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
const chdirTestApp = () => {
try {
return process.chdir('spec/test_app')
return process.chdir('spec/shakapacker/test_app')
} catch (e) {
return null
}
Expand Down
Loading

0 comments on commit e8927e0

Please sign in to comment.