Repository: phoenixframework/phoenix
Pull request #4475 (2021-09-10 20:17:04)

Update Gigalixir deployment guide
Fixes https://github.com/phoenixframework/phoenix/issues/4474


Patch:
diff --git a/guides/deployment/gigalixir.md b/guides/deployment/gigalixir.md
index e903b2d74..f75fefcad 100644
--- a/guides/deployment/gigalixir.md
+++ b/guides/deployment/gigalixir.md
@@ -93,16 +93,20 @@ $ echo 'erlang_version=22.3' >> elixir_buildpack.config
 $ echo 'node_version=12.16.3' > phoenix_static_buildpack.config
 ```
 
-If you are using Phoenix v1.6, there is also a `mix assets.deploy` alias in your `mix.exs` that you want to invoke post compilation:
+Phoenix v1.6 uses `esbuild` to compile your assets but all Gigalixir images come with `npm`, so we will configure `npm` directly to deploy our assets. Add a `assets/package.json` file if you don't have any with the following:
 
-```console
-$ echo 'hook_post_compile="mix assets.deploy && rm -f _build/esbuild"' >> elixir_buildpack.config
+```json
+{
+  "scripts": {
+    "deploy": "cd .. && mix assets.deploy && rm -f _build/esbuild"
+  }
+}
 ```
 
 Finally don't forget to commit:
 
 ```console
-$ git add elixir_buildpack.config phoenix_static_buildpack.config
+$ git add elixir_buildpack.config phoenix_static_buildpack.config assets/package.json
 $ git commit -m "Set Elixir, Erlang, and Node version"
 ```
 
diff --git a/guides/deployment/heroku.md b/guides/deployment/heroku.md
index 90bc807e7..63137e308 100644
--- a/guides/deployment/heroku.md
+++ b/guides/deployment/heroku.md
@@ -114,9 +114,9 @@ Finally, let's tell the build pack how to start our webserver. Create a file nam
 web: mix phx.server
 ```
 
-### Optional: Assets Buildpack
+### Optional: Node, npm, and the Phoenix Static buildpack
 
-By default, Phoenix uses `esbuild` and manages all assets for you. However, if you are using `npm`, `webpack`, `postcss`, or similar tools, you will need to install the [Phoenix Static buildpack](https://github.com/gjaldon/heroku-buildpack-phoenix-static) to handle them:
+By default, Phoenix uses `esbuild` and manages all assets for you. However, if you are using `node` and `npm`, you will need to install the [Phoenix Static buildpack](https://github.com/gjaldon/heroku-buildpack-phoenix-static) to handle them:
 
 ```console
 $ heroku buildpacks:add https://github.com/gjaldon/heroku-buildpack-phoenix-static.git
@@ -125,6 +125,18 @@ Buildpack added. Next release on mysterious-meadow-6277 will use:
   2. https://github.com/gjaldon/heroku-buildpack-phoenix-static.git
 ```
 
+When using this buildpack, you want to delegate all asset bundling to `npm`. So you must remove the `hook_post_compile` configuration from your `elixir_buildpack.config` and move it to the deploy script of your `assets/package.json`. Something like this:
+
+```javascript
+{
+  ...
+  "scripts": {
+    "deploy": "cd .. && mix assets.deploy && rm -f _build/esbuild"
+  }
+  ...
+}
+```
+
 The Phoenix Static buildpack uses a predefined Node.js version but to avoid surprises when deploying, it is best to explicitly list the Node.js version we want in production to be the same we are using during development or in your continuous integration servers. This is done by creating a config file named `phoenix_static_buildpack.config` in the root directory of your project with your target version of Node.js:
 
 ```
@@ -134,8 +146,6 @@ node_version=10.20.1
 
 Please refer to the [configuration section](https://github.com/gjaldon/heroku-buildpack-phoenix-static#configuration) for full details. You can make your own custom build script, but for now we will use the [default one provided](https://github.com/gjaldon/heroku-buildpack-phoenix-static/blob/master/compile).
 
-Important: if using this buildpack, remove `phx.digest` and any `npm` command from the "assets.deploy" hook in your `mix.exs`, as the buildpack will automatically invoke those.
-
 Finally, note that since we are using multiple buildpacks, you might run into an issue where the sequence is out of order (the Elixir buildpack needs to run before the Phoenix Static buildpack). [Heroku's docs](https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app) explain this better, but you will need to make sure the Phoenix Static buildpack comes last.
 
 ## Making our Project ready for Heroku
diff --git a/lib/mix/tasks/phx.gen.auth.ex b/lib/mix/tasks/phx.gen.auth.ex
index 4d9506514..65c12cad1 100644
--- a/lib/mix/tasks/phx.gen.auth.ex
+++ b/lib/mix/tasks/phx.gen.auth.ex
@@ -14,7 +14,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth do
 
   ## Password hashing
 
-  The password hashing mechanism defaults to `bcrypt` for
+  The password hashing mechanism defaults to `argon2` for
   Unix systems and `pbkdf2` for Windows systems. Both
   systems use the [Comeonin interface](https://hexdocs.pm/comeonin/).
 
@@ -200,7 +200,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth do
 
   defp default_hashing_library_option do
     case :os.type() do
-      {:unix, _} -> "bcrypt"
+      {:unix, _} -> "argon2"
       {:win32, _} -> "pbkdf2"
     end
   end
diff --git a/lib/phoenix/socket.ex b/lib/phoenix/socket.ex
index d52ed13ea..9d7378fcc 100644
--- a/lib/phoenix/socket.ex
+++ b/lib/phoenix/socket.ex
@@ -10,8 +10,9 @@ defmodule Phoenix.Socket do
   It is the responsibility of the socket to tie transports and channels
   together.
 
-  By default, Phoenix supports both websockets and longpoll when invoking
-  `Phoenix.Endpoint.socket/3` in your endpoint:
+  Phoenix supports `websocket` and `longpoll` options when invoking
+  `Phoenix.Endpoint.socket/3` in your endpoint. `websocket` is set by default
+  and `longpoll` can also be configured explicitly.
 
       socket "/socket", MyAppWeb.Socket, websocket: true, longpoll: false
 


Test patch:
diff --git a/priv/templates/phx.gen.auth/auth_test.exs b/priv/templates/phx.gen.auth/auth_test.exs
index 30f4f7817..bf26929a8 100644
--- a/priv/templates/phx.gen.auth/auth_test.exs
+++ b/priv/templates/phx.gen.auth/auth_test.exs
@@ -71,10 +71,7 @@ defmodule <%= inspect auth_module %>Test do
       |> put_session(:live_socket_id, live_socket_id)
       |> <%= inspect(schema.alias) %>Auth.log_out_<%= schema.singular %>()
 
-      assert_receive %Phoenix.Socket.Broadcast{
-        event: "disconnect",
-        topic: "<%= schema.plural %>_sessions:abcdef-token"
-      }
+      assert_receive %Phoenix.Socket.Broadcast{event: "disconnect", topic: ^live_socket_id}
     end
 
     test "works even if <%= schema.singular %> is already logged out", %{conn: conn} do
diff --git a/priv/templates/phx.gen.auth/session_controller_test.exs b/priv/templates/phx.gen.auth/session_controller_test.exs
index eec4b0b02..5f189f6a4 100644
--- a/priv/templates/phx.gen.auth/session_controller_test.exs
+++ b/priv/templates/phx.gen.auth/session_controller_test.exs
@@ -12,8 +12,8 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
       conn = get(conn, Routes.<%= schema.route_helper %>_session_path(conn, :new))
       response = html_response(conn, 200)
       assert response =~ "<h1>Log in</h1>"
-      assert response =~ "Log in</a>"
       assert response =~ "Register</a>"
+      assert response =~ "Forgot your password?</a>"
     end
 
     test "redirects if already logged in", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
diff --git a/test/mix/tasks/phx.gen.auth_test.exs b/test/mix/tasks/phx.gen.auth_test.exs
index 962bc4a18..5160a314c 100644
--- a/test/mix/tasks/phx.gen.auth_test.exs
+++ b/test/mix/tasks/phx.gen.auth_test.exs
@@ -83,7 +83,7 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
       )
 
       assert_file "config/test.exs", fn file ->
-        assert file =~ "config :bcrypt_elixir, :log_rounds, 1"
+        assert file =~ "config :argon2_elixir, t_cost: 1, m_cost: 8"
       end
 
       assert_file "lib/my_app/accounts.ex"
@@ -130,7 +130,7 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
       end
 
       assert_file "mix.exs", fn file ->
-        assert file =~ ~s|{:bcrypt_elixir, "~> 2.0"},|
+        assert file =~ ~s|{:argon2_elixir, "~> 2.0"},|
       end
 
       assert_file "lib/my_app_web/router.ex", fn file ->
@@ -776,11 +776,11 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
 
         assert_received {:mix_shell, :info, ["""
 
-        Add your {:bcrypt_elixir, "~> 2.0"} dependency to mix.exs:
+        Add your {:argon2_elixir, "~> 2.0"} dependency to mix.exs:
 
             defp deps do
               [
-                {:bcrypt_elixir, "~> 2.0"},
+                {:argon2_elixir, "~> 2.0"},
                 ...
               ]
             end