Skip to content

Commit

Permalink
Merge branch 'release/1.0.33' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jan 30, 2024
2 parents 57835a7 + a832aeb commit d521220
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 17 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
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

## 1.0.33 - 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

## 1.0.32 - 2023.01.25
### Changed
* Updated the `craft.vite.asset()` function to work with Vite 3.x or later, where assets are stored as top-level entries in the `manifest.json` ([#56](https://github.com/nystudio107/craft-vite/issues/56)) ([#31](https://github.com/nystudio107/craft-vite/issues/31))
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2021 nystudio107
Copyright (c) nystudio107

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
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": "1.0.32",
"version": "1.0.33",
"keywords": [
"craftcms",
"plugin",
Expand All @@ -23,6 +23,16 @@
"require": {
"craftcms/cms": "^3.0.0"
},
"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_3]);
};
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
8 changes: 4 additions & 4 deletions src/helpers/FileHelper.php
Original file line number Diff line number Diff line change
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
7 changes: 3 additions & 4 deletions src/helpers/ManifestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Craft;
use craft\helpers\Json as JsonHelper;


/**
* @author nystudio107
* @package Vite
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
12 changes: 12 additions & 0 deletions src/services/ViteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ public function devServerRunning(): bool
*/
public function fetch(string $pathOrUrl, callable $callback = 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
6 changes: 3 additions & 3 deletions src/variables/ViteVariableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

namespace nystudio107\pluginvite\variables;

use yii\base\InvalidConfigException;

use Twig\Markup;

use yii\base\InvalidConfigException;

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

Expand Down
8 changes: 4 additions & 4 deletions src/variables/ViteVariableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

namespace nystudio107\pluginvite\variables;

use nystudio107\pluginvite\services\ViteService;

use craft\helpers\Template;

use yii\base\InvalidConfigException;
use nystudio107\pluginvite\services\ViteService;

use Twig\Markup;

use yii\base\InvalidConfigException;

/**
* @author nystudio107
* @package Vite
Expand Down Expand Up @@ -94,7 +94,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 d521220

Please sign in to comment.