Skip to content

Commit 0c1d93d

Browse files
committed
feature #735 Changing to support next version of stimulus bridge with "fetch" mode (weaverryan)
This PR was merged into the 1.9-dev branch. Discussion ---------- Changing to support next version of stimulus bridge with "fetch" mode Partner to symfony/stimulus-bridge#15 and symfony/ux#53 The tricky part about this is that, if the user has `stimulus-bridge` 1.x, then their `controllers.json` file needs `webpackMode`. If they have `stimulus-bridge` "next" (we're thinking it'll be 2.0), then their `controllers.json` file needs `fetch`. This means that Flex has a "hard break" and sorta just needs to assume that the user has the "new" version. We made the decision - to go from `webpackMode` to `fetch` because the setting no longer is truly the same as `webpackMode`. However, if we wanted to make the upgrade path easier, we could revert that and use `webpackMode` in 2.0 as well (instead of changing to `fetch`). Commits ------- 0c452b5 Changing to support next version of stimulus bridge with "fetch" mode
2 parents 35bcd4d + 0c452b5 commit 0c1d93d

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/PackageJsonSynchronizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private function registerWebpackResources(array $phpPackages)
112112
if (!isset($previousControllersJson['controllers']['@'.$phpPackage][$controllerName])) {
113113
$config = [];
114114
$config['enabled'] = $defaultConfig['enabled'];
115-
$config['webpackMode'] = $defaultConfig['webpackMode'];
115+
$config['fetch'] = $defaultConfig['fetch'] ?? 'eager';
116116

117117
if (isset($defaultConfig['autoimport'])) {
118118
$config['autoimport'] = $defaultConfig['autoimport'];
@@ -128,7 +128,7 @@ private function registerWebpackResources(array $phpPackages)
128128

129129
$config = [];
130130
$config['enabled'] = $previousConfig['enabled'];
131-
$config['webpackMode'] = $previousConfig['webpackMode'];
131+
$config['fetch'] = $previousConfig['fetch'] ?? 'eager';
132132

133133
if (isset($defaultConfig['autoimport'])) {
134134
$config['autoimport'] = [];
@@ -149,7 +149,7 @@ private function registerWebpackResources(array $phpPackages)
149149
}
150150
}
151151

152-
file_put_contents($controllersJsonPath, json_encode($newControllersJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n");
152+
file_put_contents($controllersJsonPath, json_encode($newControllersJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)."\n");
153153
}
154154

155155
private function resolveAssetsDir(string $phpPackage)

tests/Fixtures/packageJson/vendor/symfony/existing-package/Resources/assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"controllers": {
44
"mock": {
55
"enabled": true,
6-
"webpackMode": "eager",
6+
"fetch": "eager",
77
"autoimport": {
88
"@symfony/existing-package/dist/style.css": true,
99
"@symfony/existing-package/dist/new-style.css": true

tests/Fixtures/packageJson/vendor/symfony/new-package/assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"controllers": {
44
"new": {
55
"enabled": true,
6-
"webpackMode": "lazy",
6+
"fetch": "lazy",
77
"autoimport": {
88
"@symfony/new-package/dist/style.css": true
99
}

tests/PackageJsonSynchronizerTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class PackageJsonSynchronizerTest extends TestCase
2020
private $tempDir;
2121
private $synchronizer;
2222

23-
public function setUp(): void
23+
protected function setUp(): void
2424
{
2525
$this->tempDir = sys_get_temp_dir().'/flex-package-json-'.substr(md5(uniqid('', true)), 0, 6);
2626
(new Filesystem())->mirror(__DIR__.'/Fixtures/packageJson', $this->tempDir);
2727

2828
$this->synchronizer = new PackageJsonSynchronizer($this->tempDir);
2929
}
3030

31-
public function tearDown(): void
31+
protected function tearDown(): void
3232
{
3333
(new Filesystem())->remove($this->tempDir);
3434
}
@@ -79,7 +79,8 @@ public function testSynchronizeExistingPackage()
7979
'@symfony/existing-package' => [
8080
'mock' => [
8181
'enabled' => false,
82-
'webpackMode' => 'eager',
82+
// the "fetch" replaces the old "webpackMode"
83+
'fetch' => 'eager',
8384
'autoimport' => [
8485
'@symfony/existing-package/dist/style.css' => false,
8586
'@symfony/existing-package/dist/new-style.css' => true,
@@ -116,7 +117,7 @@ public function testSynchronizeNewPackage()
116117
'@symfony/existing-package' => [
117118
'mock' => [
118119
'enabled' => false,
119-
'webpackMode' => 'eager',
120+
'fetch' => 'eager',
120121
'autoimport' => [
121122
'@symfony/existing-package/dist/style.css' => false,
122123
'@symfony/existing-package/dist/new-style.css' => true,
@@ -126,7 +127,7 @@ public function testSynchronizeNewPackage()
126127
'@symfony/new-package' => [
127128
'new' => [
128129
'enabled' => true,
129-
'webpackMode' => 'lazy',
130+
'fetch' => 'lazy',
130131
'autoimport' => [
131132
'@symfony/new-package/dist/style.css' => true,
132133
],

0 commit comments

Comments
 (0)