diff --git a/.github/workflows/code-analysis.yaml b/.github/workflows/code-analysis.yaml index b571cde..a6a6066 100644 --- a/.github/workflows/code-analysis.yaml +++ b/.github/workflows/code-analysis.yaml @@ -14,21 +14,27 @@ jobs: fail-fast: false matrix: actions: - - - name: 'PHPStan' + - name: 'PHPStan' run: composer phpstan - - - name: 'Coding Standards' + - name: 'Coding Standards' run: composer fix-cs name: ${{ matrix.actions.name }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - # see https://github.com/shivammathur/setup-php - - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - coverage: none - # composer install cache - https://github.com/ramsey/composer-install - - uses: "ramsey/composer-install@v2" - - run: ${{ matrix.actions.run }} + - uses: actions/checkout@v4 + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: /tmp/composer-cache + key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + - name: Setup PHP + id: setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: 'ctype,curl,dom,iconv,imagick,intl,json,mbstring,openssl,pcre,pdo,reflection,spl,zip' + ini-values: post_max_size=256M, max_execution_time=180, memory_limit=512M + tools: composer:v2 + - name: Install Composer dependencies + run: composer install --no-interaction --no-ansi --no-progress + - run: ${{ matrix.actions.run }} diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 0000000..8e33492 --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,21 @@ +name: Create Release +run-name: Create release for ${{ github.event.client_payload.version }} + +on: + repository_dispatch: + types: + - craftcms/new-release + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: ncipollo/release-action@v1 + with: + body: ${{ github.event.client_payload.notes }} + makeLatest: ${{ github.event.client_payload.latest }} + name: ${{ github.event.client_payload.version }} + prerelease: ${{ github.event.client_payload.prerelease }} + tag: ${{ github.event.client_payload.tag }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a6add4..4f63f12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Plugin Vite Changelog +## 5.0.0-beta.3 - 2024.03.02 +### Fixed +* Fixed an issue where `craft.vite.entry()` would fail if you were using Vite 5 or later, due to the `ManifestHelper::fileNameWithoutHash()` function not working correctly ([#24](https://github.com/nystudio107/craft-plugin-vite/issues/24)) + ## 5.0.0-beta.2 - 2024.01.30 ### Added * If the `devServer` is running, the `ViteService::fetch()` method will try to use the `devServerInternal` URL first, falling back on the `devServerPublic` so that `craft.vite.inline()` can pull from the `devServer` if it is running ([#22](https://github.com/nystudio107/craft-plugin-vite/issues/22)) diff --git a/composer.json b/composer.json index 011594e..dc5d8b5 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "nystudio107/craft-plugin-vite", "description": "Plugin Vite is the conduit between Craft CMS plugins and Vite, with manifest.json & HMR support", - "version": "5.0.0-beta.2", + "version": "5.0.0-beta.3", "keywords": [ "craftcms", "plugin", @@ -21,7 +21,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "craftcms/cms": "^5.0.0-alpha.1" + "craftcms/cms": "^5.0.0-beta.1" }, "require-dev": { "craftcms/ecs": "dev-main", @@ -29,7 +29,7 @@ "craftcms/rector": "dev-main" }, "scripts": { - "phpstan": "vendor/bin/phpstan --ansi --memory-limit=1G", + "phpstan": "phpstan --ansi --memory-limit=1G", "check-cs": "ecs check --ansi", "fix-cs": "ecs check --fix --ansi" }, diff --git a/phpstan.neon b/phpstan.neon index 44554e4..9ad1308 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ includes: - - vendor/craftcms/phpstan/phpstan.neon + - %currentWorkingDirectory%/vendor/craftcms/phpstan/phpstan.neon parameters: level: 5 diff --git a/src/helpers/ManifestHelper.php b/src/helpers/ManifestHelper.php index 789406c..d132267 100644 --- a/src/helpers/ManifestHelper.php +++ b/src/helpers/ManifestHelper.php @@ -178,55 +178,6 @@ public static function extractManifestTags(string $path, bool $asyncCss = true, return $tags; } - /** - * Extract any import files from entries recursively - * - * @param array $manifest - * @param string $manifestKey - * @param array $importFiles - * - * @return array - */ - protected static function extractImportFiles(array $manifest, string $manifestKey, array &$importFiles): array - { - $entry = $manifest[$manifestKey] ?? null; - if (!$entry) { - return []; - } - - $imports = $entry['imports'] ?? []; - foreach ($imports as $import) { - $importFiles[$import] = $manifest[$import]['file']; - self::extractImportFiles($manifest, $import, $importFiles); - } - - return $importFiles; - } - - /** - * Extract any CSS files from entries recursively - * - * @param array $manifest - * @param string $manifestKey - * @param array $cssFiles - * - * @return array - */ - protected static function extractCssFiles(array $manifest, string $manifestKey, array &$cssFiles): array - { - $entry = $manifest[$manifestKey] ?? null; - if (!$entry) { - return []; - } - $cssFiles = array_merge($cssFiles, $entry['css'] ?? []); - $imports = $entry['imports'] ?? []; - foreach ($imports as $import) { - self::extractCssFiles($manifest, $import, $cssFiles); - } - - return $cssFiles; - } - /** * Return an array of tags from the manifest, for both modern and legacy builds * @@ -250,9 +201,6 @@ public static function legacyManifestTags(string $path, bool $asyncCss = true, a return self::extractManifestTags($legacyPath, $asyncCss, $scriptTagAttrs, $cssTagAttrs, true); } - // Protected Static Methods - // ========================================================================= - /** * Extract an entry file URL from all of the entries in the manifest * @@ -285,28 +233,6 @@ public static function extractEntry(string $path): string return ''; } - /** - * Return a file name from the passed in $path, with any version hash removed from it - * - * @param string $path - * @return string - */ - protected static function filenameWithoutHash(string $path): string - { - // Get just the file name - $filenameParts = explode('/', $path); - $filename = end($filenameParts); - // If there is a version hash, remove it - $filenameParts = explode('.', $filename); - $dotSegments = count($filenameParts); - if ($dotSegments > 2) { - unset($filenameParts[$dotSegments - 2]); - $filename = implode('.', $filenameParts); - } - - return (string)$filename; - } - /** * Extract any asset files from all of the entries in the manifest * @@ -330,4 +256,78 @@ public static function extractAssetFiles(): array return $assetFiles; } + + // Protected Static Methods + // ========================================================================= + + /** + * Extract any import files from entries recursively + * + * @param array $manifest + * @param string $manifestKey + * @param array $importFiles + * + * @return array + */ + protected static function extractImportFiles(array $manifest, string $manifestKey, array &$importFiles): array + { + $entry = $manifest[$manifestKey] ?? null; + if (!$entry) { + return []; + } + + $imports = $entry['imports'] ?? []; + foreach ($imports as $import) { + $importFiles[$import] = $manifest[$import]['file']; + self::extractImportFiles($manifest, $import, $importFiles); + } + + return $importFiles; + } + + /** + * Extract any CSS files from entries recursively + * + * @param array $manifest + * @param string $manifestKey + * @param array $cssFiles + * + * @return array + */ + protected static function extractCssFiles(array $manifest, string $manifestKey, array &$cssFiles): array + { + $entry = $manifest[$manifestKey] ?? null; + if (!$entry) { + return []; + } + $cssFiles = array_merge($cssFiles, $entry['css'] ?? []); + $imports = $entry['imports'] ?? []; + foreach ($imports as $import) { + self::extractCssFiles($manifest, $import, $cssFiles); + } + + return $cssFiles; + } + + /** + * Return a file name from the passed in $path, with any version hash removed from it + * + * @param string $path + * @return string + */ + protected static function filenameWithoutHash(string $path): string + { + $pathInfo = pathinfo($path); + $filename = $pathInfo['filename']; + $extension = $pathInfo['extension']; + $hashPos = strpos($filename, '.') ?: strlen($filename); + $hash = substr($filename, $hashPos); + // Vite 5 now uses a `-` to separate the version hash, so account for that as well + if (empty($hash) && str_contains($filename, '-')) { + $hash = substr($filename, strpos($filename, '-')); + } + $filename = str_replace($hash, '', $filename); + + return implode('.', [$filename, $extension]); + } }