Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tonysm/importmap-laravel
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.1.2
Choose a base ref
...
head repository: tonysm/importmap-laravel
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
8 changes: 4 additions & 4 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -10,20 +10,20 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.6.0
uses: dependabot/fetch-metadata@v2.3.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

- name: Auto-merge Dependabot PRs for semver-minor updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Auto-merge Dependabot PRs for semver-patch updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --merge "$PR_URL"
Original file line number Diff line number Diff line change
@@ -13,9 +13,7 @@ jobs:
ref: ${{ github.head_ref }}

- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs.dist.php --allow-risky=yes
uses: aglipanci/laravel-pint-action@2.3.1

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
19 changes: 10 additions & 9 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -2,25 +2,26 @@ name: run-tests

on:
push:
branches: [main]
branches:
- main
pull_request:
branches: [main]

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
php: [8.1, 8.2]
laravel: [9.45.*, 10.*]
php: [8.2, 8.3, 8.4]
laravel: [11.*, 12.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 9.45.*
testbench: 7.17.*
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*
- laravel: 12.*
testbench: 10.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

@@ -42,7 +43,7 @@ jobs:
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:^2.64.1" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
.php_cs
.php_cs.cache
.phpunit.result.cache
.phpunit.cache
build
composer.lock
coverage
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,51 @@

All notable changes to `importmap-laravel` will be documented in this file.

## 2.4.0 - 2025-03-02

### What's Changed

* Laravel 12.x Compatibility by @laravel-shift in https://github.com/tonysm/importmap-laravel/pull/59

**Full Changelog**: https://github.com/tonysm/importmap-laravel/compare/2.3.2...2.4.0

## 2.3.1 - 2024-03-13

### What's Changed

- Skip adding the `<x-importmap::tags />` component to layouts if they already exist in https://github.com/tonysm/importmap-laravel/commit/ff2019eb14b48223c985e6cdee0601455bc41d88

**Full Changelog**: https://github.com/tonysm/importmap-laravel/compare/2.3.0...2.3.1

## 2.3.0 - 2024-03-13

### What's Changed

- Skip axios installation with a warning by @tonysm in https://github.com/tonysm/importmap-laravel/commit/c77bb163d9a4b2f81d0d399b7c03323e9562b91a

**Full Changelog**: https://github.com/tonysm/importmap-laravel/compare/2.2.0...2.3.0

## 2.2.0 - 2024-03-06

### What's Changed

* Laravel 11 Support by @tonysm in https://github.com/tonysm/importmap-laravel/pull/54

**Full Changelog**: https://github.com/tonysm/importmap-laravel/compare/2.1.4...2.2.0

## 2.1.2 - 2024-02-23

### What's Changed

* Read typo fixes by @emaia in https://github.com/tonysm/importmap-laravel/pull/52
* Update the install command to either replace the vite directive or append the importmap tags before the closing head tag by @tonysm in https://github.com/tonysm/importmap-laravel/commit/ce304706a698b35aa46ef3168d6bf2db8ee2a97d

### New Contributors

* @emaia made their first contribution in https://github.com/tonysm/importmap-laravel/pull/52

**Full Changelog**: https://github.com/tonysm/importmap-laravel/compare/2.0.3...2.1.2

## 2.1.1 - 2024-02-05

### What's Changed
@@ -59,6 +104,11 @@ sed -i 's/x-importmap-tags/x-importmap::tags/g' resources/**/*.php








```
Also, ensure you have `php artisan view:cache` in your deployment script.

15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -16,20 +16,19 @@
}
],
"require": {
"php": "^8.1",
"illuminate/contracts": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"php": "^8.2",
"illuminate/contracts": "^11.0|^12.0",
"illuminate/support": "^11.0|^12.0",
"spatie/laravel-package-tools": "^1.9"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.4",
"laravel/pint": "^1.10",
"nunomaduro/collision": "^5.10|^6.0",
"orchestra/testbench": "^7.17|^8.0",
"orchestra/testbench": "^9.0|^10.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5"
"phpstan/phpstan-deprecation-rules": "^1.0|^2.0",
"phpstan/phpstan-phpunit": "^1.0|^2.0",
"phpunit/phpunit": "^10.5|^11.5.3"
},
"bin": [
"bin/importmap"
29 changes: 10 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Tonysm Test Suite">
<testsuite name="Importmap Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<logging>
<junit outputFile="build/report.junit.xml" />
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</source>
</phpunit>
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
->withPaths([
__DIR__.'/src',
__DIR__.'/tests',
])
->withPreparedSets(
deadCode: true,
codeQuality: true,
typeDeclarations: true,
privatization: true,
earlyReturn: true,
)
->withAttributesSets()
->withPhpSets()
->withPhpVersion(PhpVersion::PHP_82);
18 changes: 9 additions & 9 deletions src/Actions/FixJsImportPaths.php
Original file line number Diff line number Diff line change
@@ -15,47 +15,47 @@ public function __construct(public string $root, public ?string $output = null)
$this->output ??= $root;
}

public function __invoke()
public function __invoke(): void
{
collect(File::allFiles($this->root))
->filter(fn (SplFileInfo $file) => in_array($file->getExtension(), ['js', 'mjs']))
->filter(fn (SplFileInfo $file): bool => in_array($file->getExtension(), ['js', 'mjs']))
->each(fn (SplFileInfo $file) => File::ensureDirectoryExists($this->absoluteOutputPathFor($file)))
->each(fn (SplFileInfo $file) => File::put(
$this->absoluteOutputPathWithFileFor($file),
$this->updatedJsImports($file),
));
}

private function absoluteOutputPathFor(SplFileInfo $file)
private function absoluteOutputPathFor(SplFileInfo $file): string
{
return str_replace($this->root, $this->output, dirname($file->getRealPath()));
}

private function absoluteOutputPathWithFileFor(SplFileInfo $file)
private function absoluteOutputPathWithFileFor(SplFileInfo $file): string
{
return rtrim($this->absoluteOutputPathFor($file), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file->getFilename();
return rtrim((string) $this->absoluteOutputPathFor($file), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file->getFilename();
}

private function updatedJsImports(SplFileInfo $file)
private function updatedJsImports(SplFileInfo $file): string
{
$lines = File::lines($file->getRealPath())->all();

foreach ($lines as $index => $line) {
if (! str_starts_with($line, 'import ')) {
if (! str_starts_with((string) $line, 'import ')) {
continue;
}

try {
$lines[$index] = preg_replace_callback(
'#import.+["\']([\.]+.*)["\']#',
function ($matches) use ($file) {
function ($matches) use ($file): string {
$replaced = $this->replaceDotImports($file, $matches[1], $matches[0]);

$relative = trim(str_replace($this->root, '', $replaced), DIRECTORY_SEPARATOR);

return str_replace(DIRECTORY_SEPARATOR, '/', str_replace($matches[1], $relative, $matches[0]));
},
$line,
(string) $line,
);
} catch (FailedToFixImportStatementException $exception) {
event(new FailedToFixImportStatement($exception->file, $exception->importStatement));
15 changes: 10 additions & 5 deletions src/Actions/ReplaceOrAppendTags.php
Original file line number Diff line number Diff line change
@@ -4,22 +4,27 @@

class ReplaceOrAppendTags
{
const VITE_DIRECTIVE_PATTERN = '/(\s*)\@vite\(.+\)/';
const CLOSING_HEAD_TAG_PATTERN = '/(\s*)(<\/head>)/';
public const VITE_DIRECTIVE_PATTERN = '/(\s*)\@vite\(.*\)/';

public const CLOSING_HEAD_TAG_PATTERN = '/(\s*)(<\/head>)/';

public function __invoke(string $contents)
{
if (preg_match(self::VITE_DIRECTIVE_PATTERN, $contents)) {
if (str_contains($contents, '<x-importmap::tags />')) {
return $contents;
}

if (str_contains($contents, '@vite')) {
return preg_replace(
static::VITE_DIRECTIVE_PATTERN,
"\\1<x-importmap::tags />",
'\\1<x-importmap::tags />',
$contents,
);
}

return preg_replace(
static::CLOSING_HEAD_TAG_PATTERN,
"\n\\1 <x-importmap::tags />\\1\\2",
PHP_EOL.'\\1 <x-importmap::tags />\\1\\2',
$contents,
);
}
4 changes: 2 additions & 2 deletions src/AssetResolver.php
Original file line number Diff line number Diff line change
@@ -10,13 +10,13 @@ class AssetResolver
public function __invoke(string $fileRelativePath)
{
if (str_starts_with(trim($fileRelativePath, '/'), 'vendor/') && File::exists($absolutePath = public_path($fileRelativePath))) {
return asset($fileRelativePath).'?digest='.(new FileDigest())($absolutePath);
return asset($fileRelativePath).'?digest='.(new FileDigest)($absolutePath);
}

if (! File::exists($absolutePath = Importmap::getFileAbsolutePath('/resources/'.trim($fileRelativePath, '/')))) {
return asset($fileRelativePath);
}

return asset($fileRelativePath).'?digest='.(new FileDigest())($absolutePath);
return asset($fileRelativePath).'?digest='.(new FileDigest)($absolutePath);
}
}
6 changes: 3 additions & 3 deletions src/Commands/AuditCommand.php
Original file line number Diff line number Diff line change
@@ -28,17 +28,17 @@ public function handle(Npm $npm): int
$this->table(
['Package', 'Severity', 'Vulnerable Versions', 'Vulnerability'],
$vulnerablePackages
->map(fn (VulnerablePackage $package) => [$package->name, $package->severity, $package->vulnerableVersions, $package->vulnerability])
->map(fn (VulnerablePackage $package): array => [$package->name, $package->severity, $package->vulnerableVersions, $package->vulnerability])
->all()
);

$this->newLine();

$summary = $vulnerablePackages
->groupBy('severity')
->map(fn ($vulns) => $vulns->count())
->map(fn ($vulns): int => $vulns->count())
->sortDesc()
->map(fn ($count, $severity) => "$count {$severity}")
->map(fn ($count, $severity): string => "$count {$severity}")
->join(', ');

$this->error(sprintf(
Loading