diff --git a/src/Module.php b/src/Module.php index c9a5770be..eb42f0364 100644 --- a/src/Module.php +++ b/src/Module.php @@ -6,6 +6,7 @@ use Illuminate\Container\Container; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; use Illuminate\Translation\Translator; @@ -86,8 +87,12 @@ public static function getAssets(): array if (file_exists('build/manifest.json')) { $files = json_decode(file_get_contents('build/manifest.json'), true); - foreach ($files as $file) { - $paths[] = $file['src']; + if (is_array($files)) { + foreach ($files as $file) { + if (isset($file['src'])) { + $paths[] = $file['src']; + } + } } } diff --git a/tests/LaravelModuleTest.php b/tests/LaravelModuleTest.php index 34e974c1b..e3933bd55 100644 --- a/tests/LaravelModuleTest.php +++ b/tests/LaravelModuleTest.php @@ -234,43 +234,7 @@ public function it_can_load_a_deferred_provider() /** @test */ public function it_can_load_assets_is_empty_when_no_manifest_exists() { - $result = $this->module->getAssets(); - - $this->assertEquals([], $result); - } - - /** @test */ - public function it_can_load_assets_when_manifest_exists() - { - mkdir('build'); - file_put_contents('build/manifest.json', '{ - "Modules/Books/resources/assets/sass/app.scss": { - "file": "assets/app-4ed993c7.js", - "isEntry": true, - "src": "Modules/Books/resources/assets/sass/app.scss" - }, - "Modules/Pages/resources/css/app.css": { - "file": "assets/app-5a5d3a39.css", - "isEntry": true, - "src": "Modules/Pages/resources/css/app.css" - }, - "resources/css/app.css": { - "file": "assets/app-3ebdfa1f.css", - "isEntry": true, - "src": "resources/css/app.css" - } - }'); - - $result = $this->module->getAssets(); - - $this->assertEquals([ - 'Modules/Books/resources/assets/sass/app.scss', - 'Modules/Pages/resources/css/app.css', - 'resources/css/app.css' - ], $result); - - unlink('build/manifest.json'); - rmdir('build'); + $this->assertEquals([], $this->module->getAssets()); } }