Skip to content

Commit 0519ab0

Browse files
Make surface.init compatible with phx_new 1.7.14 (#753)
1 parent 72c80e0 commit 0519ab0

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

lib/mix/tasks/surface/surface.init/file_patchers/phoenix.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ defmodule Mix.Tasks.Surface.Init.FilePatchers.Phoenix do
123123
esbuild_patcher ->
124124
esbuild_patcher
125125
|> halt_if(&find_keyword(&1, [:catalogue]), :already_patched)
126-
|> find_keyword_value([:default])
127126
|> replace_code(
128127
&"""
129128
#{&1},

lib/mix/tasks/surface/surface.init/project_patchers/js_hooks.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ defmodule Mix.Tasks.Surface.Init.ProjectPatchers.JsHooks do
5858
&FilePatchers.JS.add_import(&1, ~S[import Hooks from "./_hooks"]),
5959
&FilePatchers.Text.replace_line_text(
6060
&1,
61-
~S[let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})],
62-
~S[let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}, hooks: Hooks})]
61+
~S[ params: {_csrf_token: csrfToken}],
62+
~s[ hooks: Hooks,\n params: {_csrf_token: csrfToken}]
6363
)
6464
]
6565
}

test/mix/tasks/surface/surface.init/integration_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Mix.Tasks.Surface.Init.IntegrationTest do
44

55
alias Mix.Tasks.Surface.Init.FilePatchers
66

7-
@phx_new_version "1.7.10"
7+
@phx_new_version "1.7.14"
88

99
setup_all do
1010
{template_status, template_project_folder} = build_test_project_template("surface_init_test")

test/mix/tasks/surface/surface.init/project_patchers/catalogue_test.exs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ defmodule Mix.Tasks.Surface.Init.ProjectPatchers.CatalogueTest do
228228
end
229229

230230
test "add catalogue entry if esbuild config has already been set" do
231-
code = ~S"""
231+
profile = Enum.random(["default", "surface_init_test"])
232+
233+
code = ~s"""
232234
import Config
233235
234236
# Use Jason for JSON parsing in Phoenix
@@ -237,20 +239,20 @@ defmodule Mix.Tasks.Surface.Init.ProjectPatchers.CatalogueTest do
237239
# Configure esbuild (the version is required)
238240
config :esbuild,
239241
version: "0.14.10",
240-
default: [
242+
#{profile}: [
241243
args: ~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/assets),
242244
cd: Path.expand("../assets", __DIR__),
243245
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
244246
]
245247
246248
# Import environment specific config. This must remain at the bottom
247249
# of this file so it overrides the configuration defined above.
248-
import_config "#{config_env()}.exs"
250+
import_config "\#{config_env()}.exs"
249251
"""
250252

251253
{:patched, updated_code} = Patcher.patch_code(code, configure_catalogue_esbuild())
252254

253-
assert updated_code == ~S"""
255+
assert updated_code == ~s"""
254256
import Config
255257
256258
# Use Jason for JSON parsing in Phoenix
@@ -259,7 +261,7 @@ defmodule Mix.Tasks.Surface.Init.ProjectPatchers.CatalogueTest do
259261
# Configure esbuild (the version is required)
260262
config :esbuild,
261263
version: "0.14.10",
262-
default: [
264+
#{profile}: [
263265
args: ~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/assets),
264266
cd: Path.expand("../assets", __DIR__),
265267
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
@@ -272,7 +274,7 @@ defmodule Mix.Tasks.Surface.Init.ProjectPatchers.CatalogueTest do
272274
273275
# Import environment specific config. This must remain at the bottom
274276
# of this file so it overrides the configuration defined above.
275-
import_config "#{config_env()}.exs"
277+
import_config "\#{config_env()}.exs"
276278
"""
277279
end
278280

test/mix/tasks/surface/surface.init/project_patchers/js_hooks_test.exs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ defmodule Mix.Tasks.Surface.Init.ProjectPatchers.JSHooksTest do
1414
import topbar from "../vendor/topbar"
1515
1616
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
17-
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
17+
let liveSocket = new LiveSocket("/live", Socket, {
18+
longPollFallbackMs: 2500,
19+
params: {_csrf_token: csrfToken}
20+
})
1821
1922
// connect if there are any LiveViews on the page
2023
liveSocket.connect()
2124
2225
window.liveSocket = liveSocket
2326
"""
2427

25-
{:patched, updated_code} = Patcher.patch_code(code, js_hooks())
28+
{_patched, updated_code} = Patcher.patch_code(code, js_hooks())
2629

2730
assert updated_code == """
2831
// We import the CSS which is extracted to its own file by esbuild.
@@ -33,7 +36,11 @@ defmodule Mix.Tasks.Surface.Init.ProjectPatchers.JSHooksTest do
3336
import Hooks from "./_hooks"
3437
3538
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
36-
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}, hooks: Hooks})
39+
let liveSocket = new LiveSocket("/live", Socket, {
40+
longPollFallbackMs: 2500,
41+
hooks: Hooks,
42+
params: {_csrf_token: csrfToken}
43+
})
3744
3845
// connect if there are any LiveViews on the page
3946
liveSocket.connect()
@@ -52,7 +59,11 @@ defmodule Mix.Tasks.Surface.Init.ProjectPatchers.JSHooksTest do
5259
import Hooks from "./_hooks"
5360
5461
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
55-
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}, hooks: Hooks})
62+
let liveSocket = new LiveSocket("/live", Socket, {
63+
longPollFallbackMs: 2500,
64+
hooks: Hooks,
65+
params: {_csrf_token: csrfToken}
66+
})
5667
5768
// connect if there are any LiveViews on the page
5869
liveSocket.connect()

0 commit comments

Comments
 (0)