Skip to content

Commit

Permalink
Merge pull request #2495 from tvdeyen/6.1-fix-babel-config
Browse files Browse the repository at this point in the history
install generator: Add option to force patched babel config
  • Loading branch information
tvdeyen authored Jun 21, 2023
2 parents 269ca9d + 8b40ec6 commit a947305
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace :alchemy do
bin/rake db:create && \
bin/rake db:environment:set && \
bin/rake db:migrate:reset && \
bin/rails g alchemy:install --skip --skip-demo-files --auto-accept --skip-db-create && \
bin/rails g alchemy:install --skip --skip-demo-files --auto-accept --skip-db-create --force-babel-config && \
yarn link @alchemy_cms/admin && \
RAILS_ENV=test bin/webpack && \
cd -
Expand Down
64 changes: 64 additions & 0 deletions lib/generators/alchemy/install/files/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module.exports = function (api) {
var validEnv = ["development", "test", "production"]
var currentEnv = api.env()
var isDevelopmentEnv = api.env("development")
var isProductionEnv = api.env("production")
var isTestEnv = api.env("test")

if (!validEnv.includes(currentEnv)) {
throw new Error(
"Please specify a valid `NODE_ENV` or " +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
"."
)
}

return {
presets: [
isTestEnv && [
"@babel/preset-env",
{
targets: {
node: "current"
}
}
],
(isProductionEnv || isDevelopmentEnv) && [
"@babel/preset-env",
{
forceAllTransforms: true,
useBuiltIns: "entry",
corejs: 3,
modules: false,
exclude: ["transform-typeof-symbol"]
}
]
].filter(Boolean),
plugins: [
"babel-plugin-macros",
"@babel/plugin-syntax-dynamic-import",
isTestEnv && "babel-plugin-dynamic-import-node",
"@babel/plugin-transform-destructuring",
[
"@babel/plugin-proposal-object-rest-spread",
{
useBuiltIns: true
}
],
[
"@babel/plugin-transform-runtime",
{
helpers: false
}
],
[
"@babel/plugin-transform-regenerator",
{
async: false
}
]
].filter(Boolean)
}
}
12 changes: 12 additions & 0 deletions lib/generators/alchemy/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class InstallGenerator < ::Rails::Generators::Base
default: false,
desc: "Skip running the webpacker installer."

class_option :force_babel_config,
type: :boolean,
default: false,
desc: "Force installing a patched babel config."

class_option :skip_db_create,
type: :boolean,
default: false,
Expand Down Expand Up @@ -113,6 +118,13 @@ def run_webpacker_installer
end
end

# We need to force the babel.config.js file, because webpacker has an invalid one
def copy_babel_config
if options[:force_babel_config]
copy_file "babel.config.js", app_root.join("babel.config.js"), force: true
end
end

def add_npm_package
run "yarn add @alchemy_cms/admin@~#{Alchemy.version}"
end
Expand Down

0 comments on commit a947305

Please sign in to comment.