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: support shakapacker v7 #441

Merged
merged 4 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def apply_template! # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Met
apply "variants/backend-base/spec/template.rb"

# The block passed to "after_bundle" seems to run after `bundle install`
# but also after `webpacker:install` and after Rails has initialized the git
# but also after `shakapacker:install` and after Rails has initialized the git
# repo
after_bundle do
# Remove the `test/` directory because we always use RSpec which creates
Expand Down
2 changes: 1 addition & 1 deletion variants/backend-base/bin/ci-run
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
bundle exec rails webpacker:compile
bundle exec rails shakapacker:compile

SCRIPT_DIR=`dirname "$0"`
APP_DIR="${SCRIPT_DIR}/.."
Expand Down
8 changes: 4 additions & 4 deletions variants/backend-base/config/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
# accessibility and performance tests. You are encouraged to remove this hack
# as soon as it is no longer needed.
#
if defined?(Webpacker) && Rails.env.test?
# manifest paths depend on your webpacker config so we inspect it
manifest_path = Webpacker::Configuration
.new(root_path: Rails.root, config_path: Rails.root.join("config/webpacker.yml"), env: Rails.env)
if defined?(Shakapacker) && Rails.env.test?
# manifest paths depend on your shakapacker config so we inspect it
manifest_path = Shakapacker::Configuration
.new(root_path: Rails.root, config_path: Rails.root.join("config/shakapacker.yml"), env: Rails.env)
.public_manifest_path
.relative_path_from(Rails.root.join("public"))
.to_s
Expand Down
6 changes: 3 additions & 3 deletions variants/backend-base/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ services:
<<: *rails
links:
- db
- webpacker
- shakapacker
environment:
WEBPACKER_DEV_SERVER_HOST: webpacker
WEBPACKER_DEV_SERVER_HOST: shakapacker
ports:
- "3000:3000"
command: "bash -c 'rm -rf tmp/pid/server.pid && rails s --binding 0.0.0.0'"
webpacker:
shakapacker:
<<: *rails
command: "./bin/webpack-dev-server"
volumes:
Expand Down
3 changes: 2 additions & 1 deletion variants/frontend-base-typescript/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ declare module 'shakapacker' {
import { Configuration } from 'webpack';

export { merge } from 'webpack-merge';
export const webpackConfig: Configuration;
export const globalMutableWebpackConfig: Configuration;
export function generateWebpackConfig(): Configuration;
}

declare module 'shakapacker/package/babel/preset.js' {
Expand Down
4 changes: 2 additions & 2 deletions variants/frontend-base/config/webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { webpackConfig, merge } = require('shakapacker');
const { generateWebpackConfig, merge } = require('shakapacker');
const Dotenv = require('dotenv-webpack');

const customConfig = {
Expand All @@ -14,4 +14,4 @@ const customConfig = {

// See the shakacode/shakapacker README and docs directory for advice on customizing your webpackConfig.

module.exports = merge(webpackConfig, customConfig);
module.exports = merge(generateWebpackConfig(), customConfig);
23 changes: 8 additions & 15 deletions variants/frontend-base/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
remove_dir "app/assets/images"

# this will create a package.json for us
run "rails webpacker:install"
run "rails shakapacker:install"

# this is added by webpacker:install, but we've already got one (with some extra tags)
# this is added by shakapacker:install, but we've already got one (with some extra tags)
# in our template, so remove theirs otherwise the app will error when rendering this
gsub_file "app/views/layouts/application.html.erb",
" <%= javascript_pack_tag \"application\" %>\n",
Expand All @@ -30,17 +30,10 @@

copy_file "config/webpack/webpack.config.js", force: true

gsub_file "config/webpacker.yml", "source_entry_path: /", "source_entry_path: packs", force: true
gsub_file "config/webpacker.yml", "cache_path: tmp/webpacker", "cache_path: tmp/cache/webpacker", force: true
gsub_file "config/webpacker.yml", "source_path: app/javascript", "source_path: app/frontend", force: true
gsub_file "config/webpacker.yml", "ensure_consistent_versioning: false", "ensure_consistent_versioning: true", force: true

# Yarn's integrity check command is quite buggy, to the point that yarn v2 removed it
#
# The integrity check option itself has been removed in webpacker v5.1 but we
# currently pull in v4, so we just set it to false to be safe
#
gsub_file "config/webpacker.yml", "check_yarn_integrity: true", "check_yarn_integrity: false", force: true
gsub_file "config/shakapacker.yml", "source_entry_path: /", "source_entry_path: packs", force: true
gsub_file "config/shakapacker.yml", "cache_path: tmp/shakapacker", "cache_path: tmp/cache/shakapacker", force: true
gsub_file "config/shakapacker.yml", "source_path: app/javascript", "source_path: app/frontend", force: true
gsub_file "config/shakapacker.yml", "ensure_consistent_versioning: false", "ensure_consistent_versioning: true", force: true

empty_directory_with_keep_file "app/frontend/images"
copy_file "app/frontend/stylesheets/application.scss"
Expand Down Expand Up @@ -75,10 +68,10 @@
body_open_tag_with_img_example = <<~EO_IMG_EXAMPLE
<body>
<%
# An example of how to load an image via Webpacker. This image is in
# An example of how to load an image via shakapacker. This image is in
# app/frontend/images/example.png
%>
<%= image_pack_tag "example.png", alt: "Example Image" %>
<%= image_pack_tag "images/example.png", alt: "Example Image" %>
EO_IMG_EXAMPLE
gsub_file "app/views/layouts/application.html.erb", "<body>", body_open_tag_with_img_example, force: true

Expand Down
3 changes: 2 additions & 1 deletion variants/frontend-react-typescript/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ declare module 'shakapacker' {
import { Configuration } from 'webpack';

export { merge } from 'webpack-merge';
export const webpackConfig: Configuration;
export const globalMutableWebpackConfig: Configuration;
export function generateWebpackConfig(): Configuration;
}

declare module 'shakapacker/package/babel/preset.js' {
Expand Down
2 changes: 1 addition & 1 deletion variants/performance/spec/performance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
RSpec.configure do |config|
# Precompiling assets before running specs with js set to true not only helps
# to speed things up slightly but also creates an environment that we can run
# performance specs against. Without this webpacker doesn't zip the js packs
# performance specs against. Without this shakapacker doesn't zip the js packs
# and the performance specs show vastly different results to a live
# environment.
config.before(:suite) do
Expand Down
Loading