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

Use .js extension for config/assets.js #122

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Hanami Command Line Interface

### Changed

- [Tim Riley] Set `"type": "module"` in package.json, enabling ES modules by default
- [Tim Riley] Rename `config/assets.mjs` to `config/assets.js` (use a plain `.js` file extension)

## v2.1.0.rc1 - 2023-11-01

### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/hanami/cli/generators/gem/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def generate_app(app, context) # rubocop:disable Metrics/AbcSize

if context.generate_assets?
fs.write("package.json", t("package.json.erb", context))
fs.write("config/assets.mjs", file("assets.mjs"))
fs.write("config/assets.js", file("assets.js"))
fs.write("app/assets/js/app.js", t("app_js.erb", context))
fs.write("app/assets/css/app.css", t("app_css.erb", context))
fs.write("app/assets/images/favicon.ico", file("favicon.ico"))
Expand Down
3 changes: 2 additions & 1 deletion lib/hanami/cli/generators/gem/app/package.json.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "<%= underscored_app_name %>",
"private": true,
"type": "module",
"scripts": {
"assets": "node config/assets.mjs"
"assets": "node config/assets.js"
},
"dependencies": {
<%= hanami_assets_npm_package %>
Expand Down
13 changes: 7 additions & 6 deletions spec/unit/hanami/cli/commands/gem/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@
{
"name": "#{app}",
"private": true,
"type": "module",
"scripts": {
"assets": "node config/assets.mjs"
"assets": "node config/assets.js"
},
"dependencies": {
"hanami-assets": "#{hanami_npm_version}"
Expand Down Expand Up @@ -200,7 +201,7 @@ class App < Hanami::App
expect(fs.read("config/app.rb")).to eq(hanami_app)
expect(output).to include("Created config/app.rb")

# config/assets.mjs
# config/assets.js
assets = <<~EXPECTED
import * as assets from "hanami-assets";

Expand All @@ -217,8 +218,8 @@ class App < Hanami::App
// }
// });
EXPECTED
expect(fs.read("config/assets.mjs")).to eq(assets)
expect(output).to include("Created config/assets.mjs")
expect(fs.read("config/assets.js")).to eq(assets)
expect(output).to include("Created config/assets.js")

# config/settings.rb
settings = <<~EXPECTED
Expand Down Expand Up @@ -504,8 +505,8 @@ module Types
# Procfile.dev
expect(fs.read("Procfile.dev")).to_not match(/hanami assets watch/)

# config/assets.mjs
expect(fs.exist?("config/assets.mjs")).to be(false)
# config/assets.js
expect(fs.exist?("config/assets.js")).to be(false)

# app/templates/layouts/app.html.erb
app_layout = fs.read("app/templates/layouts/app.html.erb")
Expand Down