Last active
February 20, 2024 12:36
-
-
Save NightJar/7d3c0053c89f6fbc6c7de9dccfb32d83 to your computer and use it in GitHub Desktop.
FIX: silverstripe/admin moved jQuery.Entwine and now your site doesn't load because of a third-party dependency that isn't updated yet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Your\Namespace\Requirements; | |
use SilverStripe\View\Requirements_Backend; | |
class LegacyReplacementBackend extends Requirements_Backend | |
{ | |
public function javascript($file, $options = []) | |
{ | |
// Don't mind the direct coupling - the two work in tandem. References we can't control are always vendor code. | |
return parent::javascript(LegacyReplacementResource::config()->replacements[$file] ?? $file, $options); | |
} | |
public function block($file) | |
{ | |
return parent::block(LegacyReplacementResource::config()->replacements[$file] ?? $file); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Your\Namespace\Test\Requirements; | |
use Your\Namespace\Requirements\LegacyReplacementBackend; | |
use Your\Namespace\Requirements\LegacyReplacementResource; | |
use SilverStripe\Core\Config\Config; | |
use SilverStripe\Dev\SapphireTest; | |
class LegacyReplacementBackendTest extends SapphireTest | |
{ | |
private const OLD = 'silverstripe/admin: old-jquery'; | |
private const NEW = 'new-jquery'; | |
public function testLegacyJavascriptIsReplacedAtRuntime() | |
{ | |
Config::modify()->set(LegacyReplacementResource::class, 'replacements', [self::OLD => self::NEW]); | |
$backend = new LegacyReplacementBackend(); | |
$backend->javascript(self::OLD); | |
$this->assertArrayHasKey(self::NEW, $backend->getJavascript()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Your\Namespace\Requirements; | |
use SilverStripe\Core\Config\Configurable; | |
use SilverStripe\Core\Manifest\ModuleResourceLoader; | |
class LegacyReplacementResource extends ModuleResourceLoader | |
{ | |
use Configurable; | |
private static $replacements = []; | |
public function resolveResource($resource) | |
{ | |
return parent::resolveResource($this->config()->replacements[$resource] ?? $resource); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Your\Namespace\Test\Requirements; | |
use Your\Namespace\Requirements\LegacyReplacementResource; | |
use SilverStripe\Core\Config\Config; | |
use SilverStripe\Dev\SapphireTest; | |
class LegacyReplacementResourceTest extends SapphireTest | |
{ | |
private const OLD = 'silverstripe/admin: old-jquery'; | |
private const NEW = 'new-jquery'; | |
public function testLegacyJavascriptIsReplacedAtRuntime() | |
{ | |
Config::modify()->set(LegacyReplacementResource::class, 'replacements', [self::OLD => self::NEW]); | |
$moduleResourceLoader = new LegacyReplacementResource(); | |
$resource = $moduleResourceLoader->resolveResource(self::OLD); | |
$this->assertSame(self::NEW, $resource); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
Name: vendorrequiredresourcereplacements | |
After: assetscore | |
--- | |
Your\Namespace\Requirements\LegacyReplacementResource: | |
replacements: | |
silverstripe/admin:thirdparty/jquery/jquery.js: app/javascript/jquery-3.6.4.min.js | |
'silverstripe/admin: thirdparty/jquery/jquery.js': app/javascript/jquery-3.6.4.min.js | |
silverstripe/admin:thirdparty/jquery/jquery.min.js: app/javascript/jquery-3.6.4.min.js | |
'silverstripe/admin: thirdparty/jquery/jquery.min.js': app/javascript/jquery-3.6.4.min.js | |
silverstripe/admin:thirdparty/jquery-entwine/dist/jquery.entwine-dist.js: silverstripe/admin:thirdparty/jquery-entwine/jquery.entwine.js | |
'silverstripe/admin: thirdparty/jquery-entwine/dist/jquery.entwine-dist.js': silverstripe/admin:thirdparty/jquery-entwine/jquery.entwine.js | |
SilverStripe\Core\Injector\Injector: | |
SilverStripe\Core\Manifest\ModuleResourceLoader: Your\Namespace\Requirements\legacyReplacementResource | |
SilverStripe\View\Requirements_Backend: | |
class: Your\Namespace\Requirements\legacyReplacementBackend |
mspacemedia
commented
Feb 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment