Skip to content

Commit

Permalink
Merge branch 'release/5.0.0-beta.2' into v5
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jan 30, 2024
2 parents 9115130 + c5f8aa2 commit d928a47
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 24 deletions.
15 changes: 15 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Do not export those files in the Composer archive (lighter dependency)
/.craftplugin export-ignore
/.gitattributes export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/codeception.yml export-ignore
/composer.lock export-ignore
/buildchain/ export-ignore
/resources/ export-ignore
/src/web/assets/src/
/tests/ export-ignore

# Auto detect text files and perform LF normalization
* text=auto
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @khalwat
34 changes: 34 additions & 0 deletions .github/workflows/code-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Code Analysis

on:
pull_request: null
push:
branches:
- develop-v5
workflow_dispatch:
permissions:
contents: read
jobs:
code_analysis:
strategy:
fail-fast: false
matrix:
actions:
-
name: 'PHPStan'
run: composer phpstan
-
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 }}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Plugin Vite Changelog

## 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))
* Add `phpstan` and `ecs` code linting
* Add `code-analysis.yaml` GitHub action

### Changed
* PHPstan code cleanup
* ECS code cleanup

## 5.0.0-beta.1 - 2024.01.21
### Added
- Initial beta release
12 changes: 11 additions & 1 deletion 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": "5.0.0-beta.1",
"version": "5.0.0-beta.2",
"keywords": [
"craftcms",
"plugin",
Expand All @@ -23,6 +23,16 @@
"require": {
"craftcms/cms": "^5.0.0-alpha.1"
},
"require-dev": {
"craftcms/ecs": "dev-main",
"craftcms/phpstan": "dev-main",
"craftcms/rector": "dev-main"
},
"scripts": {
"phpstan": "vendor/bin/phpstan --ansi --memory-limit=1G",
"check-cs": "ecs check --ansi",
"fix-cs": "ecs check --fix --ansi"
},
"config": {
"allow-plugins": {
"craftcms/plugin-installer": true,
Expand Down
13 changes: 13 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use craft\ecs\SetList;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function(ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__FILE__,
]);
$ecsConfig->parallel();
$ecsConfig->sets([SetList::CRAFT_CMS_4]);
};
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- vendor/craftcms/phpstan/phpstan.neon

parameters:
level: 5
paths:
- src
18 changes: 9 additions & 9 deletions src/helpers/FileHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Vite plugin for Craft CMS 3.x
* Vite plugin for Craft CMS
*
* Allows the use of the Vite.js next generation frontend tooling with Craft CMS
*
Expand Down Expand Up @@ -30,12 +30,12 @@ class FileHelper
// Constants
// =========================================================================

const CACHE_KEY = 'vite';
const CACHE_TAG = 'vite';
public const CACHE_KEY = 'vite';
public const CACHE_TAG = 'vite';

const DEVMODE_CACHE_DURATION = 1;
public const DEVMODE_CACHE_DURATION = 1;

const SCRIPTS_DIR = '@vendor/nystudio107/craft-plugin-vite/src/web/assets/dist/';
public const SCRIPTS_DIR = '@vendor/nystudio107/craft-plugin-vite/src/web/assets/dist/';

/**
* Return the contents of a local file (via path) or remote file (via URL),
Expand Down Expand Up @@ -63,10 +63,10 @@ public static function fetch(string $pathOrUrl, callable $callback = null, strin
$dependency = new ChainedDependency([
'dependencies' => [
new FileDependency([
'fileName' => $pathOrUrl
'fileName' => $pathOrUrl,
]),
$dependency
]
$dependency,
],
]);
}
// Set the cache duration based on devMode
Expand All @@ -77,7 +77,7 @@ public static function fetch(string $pathOrUrl, callable $callback = null, strin
$cache = Craft::$app->getCache();
return $cache->getOrSet(
self::CACHE_KEY . $cacheKeySuffix . $pathOrUrl,
function () use ($pathOrUrl, $callback) {
function() use ($pathOrUrl, $callback) {
$contents = null;
if (UrlHelper::isAbsoluteUrl($pathOrUrl)) {
$response = self::fetchResponse($pathOrUrl);
Expand Down
11 changes: 5 additions & 6 deletions src/helpers/ManifestHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Vite plugin for Craft CMS 3.x
* Vite plugin for Craft CMS
*
* Allows the use of the Vite.js next generation frontend tooling with Craft CMS
*
Expand All @@ -13,7 +13,6 @@
use Craft;
use craft\helpers\Json as JsonHelper;


/**
* @author nystudio107
* @package Vite
Expand All @@ -24,7 +23,7 @@ class ManifestHelper
// Constants
// =========================================================================

const LEGACY_EXTENSION = '-legacy.';
public const LEGACY_EXTENSION = '-legacy.';

// Protected Static Properties
// =========================================================================
Expand Down Expand Up @@ -137,7 +136,7 @@ public static function extractManifestTags(string $path, bool $asyncCss = true,
$tagOptions = array_merge(
$scriptOptions,
[
'onload' => "e=new CustomEvent('vite-script-loaded', {detail:{path: '$manifestKey'}});document.dispatchEvent(e);"
'onload' => "e=new CustomEvent('vite-script-loaded', {detail:{path: '$manifestKey'}});document.dispatchEvent(e);",
],
$integrityAttributes,
$scriptTagAttrs
Expand All @@ -146,7 +145,7 @@ public static function extractManifestTags(string $path, bool $asyncCss = true,
$tags[$manifestKey] = [
'type' => 'file',
'url' => $entry['file'],
'options' => $tagOptions
'options' => $tagOptions,
];
// Include any imports
$importFiles = [];
Expand All @@ -171,7 +170,7 @@ public static function extractManifestTags(string $path, bool $asyncCss = true,
'url' => $cssFile,
'options' => array_merge([
'rel' => 'stylesheet',
], $asyncCssOptions, $cssTagAttrs)
], $asyncCssOptions, $cssTagAttrs),
];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/VitePluginService.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Vite plugin for Craft CMS 3.x
* Vite plugin for Craft CMS
*
* Allows the use of the Vite.js next generation frontend tooling with Craft CMS
*
Expand Down
14 changes: 13 additions & 1 deletion src/services/ViteService.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Vite plugin for Craft CMS 3.x
* Vite plugin for Craft CMS
*
* Allows the use of the Vite.js next generation frontend tooling with Craft CMS
*
Expand Down Expand Up @@ -195,6 +195,18 @@ public function devServerRunning(): bool
*/
public function fetch(string $pathOrUrl, callable $callback = null): string|array|null
{
// If the devServer is running, and this is a URL, swap in the devServerInternal URL
if ($this->devServerRunning()) {
if (!filter_var($pathOrUrl, FILTER_VALIDATE_URL) === false) {
$devServerInternalUrl = str_replace($this->devServerPublic, '', $pathOrUrl);
$devServerInternalUrl = FileHelper::createUrl($this->devServerInternal, $devServerInternalUrl);
// If we get a result from the $devServerInternalUrl, return it
if ($devServerInternalResult = FileHelper::fetch($devServerInternalUrl, $callback, $this->cacheKeySuffix)) {
return $devServerInternalResult;
}
}
}

return FileHelper::fetch($pathOrUrl, $callback, $this->cacheKeySuffix);
}

Expand Down
7 changes: 3 additions & 4 deletions src/variables/ViteVariableInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Vite plugin for Craft CMS 3.x
* Vite plugin for Craft CMS
*
* Allows the use of the Vite.js next generation frontend tooling with Craft CMS
*
Expand All @@ -10,9 +10,8 @@

namespace nystudio107\pluginvite\variables;

use yii\base\InvalidConfigException;

use Twig\Markup;
use yii\base\InvalidConfigException;

/**
* @author nystudio107
Expand Down Expand Up @@ -75,7 +74,7 @@ public function asset(string $path): Markup;
*
* @param string $pathOrUrl
*
* @return string|null
* @return Markup
*/
public function inline(string $pathOrUrl): Markup;

Expand Down
4 changes: 2 additions & 2 deletions src/variables/ViteVariableTrait.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Vite plugin for Craft CMS 3.x
* Vite plugin for Craft CMS
*
* Allows the use of the Vite.js next generation frontend tooling with Craft CMS
*
Expand Down Expand Up @@ -91,7 +91,7 @@ public function entry(string $path): Markup
*
* @return Markup
*/
public function asset(string $path, bool $public=false): Markup
public function asset(string $path, bool $public = false): Markup
{
return Template::raw(
$this->viteService->asset($path, $public)
Expand Down

0 comments on commit d928a47

Please sign in to comment.