Skip to content

Commit

Permalink
Merge branch 'release/4.0.10' into v4
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Mar 2, 2024
2 parents b6f727e + a3cb803 commit 4ff8dfa
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 86 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/code-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ jobs:
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.0
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 }}
21 changes: 21 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Plugin Vite Changelog

## 4.0.10 - 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))

## 4.0.9 - 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))
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "4.0.9",
"version": "4.0.10",
"keywords": [
"craftcms",
"plugin",
Expand Down Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- vendor/craftcms/phpstan/phpstan.neon
- %currentWorkingDirectory%/vendor/craftcms/phpstan/phpstan.neon

parameters:
level: 5
Expand Down
148 changes: 74 additions & 74 deletions src/helpers/ManifestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down Expand Up @@ -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
*
Expand All @@ -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]);
}
}

0 comments on commit 4ff8dfa

Please sign in to comment.