@vituum/vite-plugin-latte 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -50,7 +50,7 @@ const execSync = (cmd) => {
50
50
  }
51
51
  }
52
52
 
53
- const renderTemplate = ({ server, path, filename, cwd, packageRoot }, options, content) => {
53
+ const renderTemplate = ({ server, path, filename, cwd, packageRoot, viteServer }, options, content) => {
54
54
  const renderTransformedHtml = options.renderTransformedHtml(server ? filename.replace('.html', '') : filename)
55
55
 
56
56
  if (options.data) {
@@ -83,7 +83,7 @@ const renderTemplate = ({ server, path, filename, cwd, packageRoot }, options, c
83
83
  fs.writeFileSync(resolve(packageRoot, `temp/${timestamp}.html`), content)
84
84
  }
85
85
 
86
- const data = Object.assign({ packageRoot, cwd, isRenderTransformedHtml: renderTransformedHtml }, options)
86
+ const data = Object.assign({ packageRoot, cwd, isRenderTransformedHtml: renderTransformedHtml, viteServer }, options)
87
87
 
88
88
  return execSync(`${options.bin} ${packageRoot}/index.php ${join(options.root, server ? path.replace('.html', '') : path)} ${JSON.stringify(JSON.stringify(data))}`)
89
89
  }
@@ -159,7 +159,9 @@ const plugin = (options = {}) => {
159
159
  return content
160
160
  }
161
161
 
162
- const render = renderTemplate({ server, path, filename, cwd, packageRoot }, options, content)
162
+ const viteServer = !!server
163
+
164
+ const render = renderTemplate({ server, path, filename, cwd, packageRoot, viteServer }, options, content)
163
165
  const warningLog = render.output.includes('Warning: Undefined')
164
166
 
165
167
  if (render.error || warningLog) {
package/index.php CHANGED
@@ -29,6 +29,8 @@ if ($isDocker) {
29
29
  define("TEMPLATES_DIR", $config->cwd . '/src/templates/');
30
30
  }
31
31
 
32
+ define("VITE_SERVER", $config->viteServer);
33
+
32
34
  define("PACKAGE_DIR", str_replace($config->cwd, ROOT_DIR, $config->packageRoot));
33
35
 
34
36
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vituum/vite-plugin-latte",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -322,6 +322,7 @@ class InstalledVersions
322
322
  }
323
323
 
324
324
  $installed = array();
325
+ $copiedLocalDir = false;
325
326
 
326
327
  if (self::$canGetVendors) {
327
328
  foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
@@ -330,9 +331,11 @@ class InstalledVersions
330
331
  } elseif (is_file($vendorDir.'/composer/installed.php')) {
331
332
  /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
332
333
  $required = require $vendorDir.'/composer/installed.php';
333
- $installed[] = self::$installedByVendor[$vendorDir] = $required;
334
- if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
335
- self::$installed = $installed[count($installed) - 1];
334
+ self::$installedByVendor[$vendorDir] = $required;
335
+ $installed[] = $required;
336
+ if (strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
337
+ self::$installed = $required;
338
+ $copiedLocalDir = true;
336
339
  }
337
340
  }
338
341
  }
@@ -350,7 +353,7 @@ class InstalledVersions
350
353
  }
351
354
  }
352
355
 
353
- if (self::$installed !== array()) {
356
+ if (self::$installed !== array() && !$copiedLocalDir) {
354
357
  $installed[] = self::$installed;
355
358
  }
356
359
 
@@ -204,6 +204,7 @@ return array(
204
204
  'Nette\\NotImplementedException' => $vendorDir . '/nette/utils/src/exceptions.php',
205
205
  'Nette\\NotSupportedException' => $vendorDir . '/nette/utils/src/exceptions.php',
206
206
  'Nette\\OutOfRangeException' => $vendorDir . '/nette/utils/src/exceptions.php',
207
+ 'Nette\\ShouldNotHappenException' => $vendorDir . '/nette/utils/src/exceptions.php',
207
208
  'Nette\\SmartObject' => $vendorDir . '/nette/utils/src/SmartObject.php',
208
209
  'Nette\\StaticClass' => $vendorDir . '/nette/utils/src/StaticClass.php',
209
210
  'Nette\\UnexpectedValueException' => $vendorDir . '/nette/utils/src/exceptions.php',
@@ -205,6 +205,7 @@ class ComposerStaticInit8535741375194e2773348db6a0091487
205
205
  'Nette\\NotImplementedException' => __DIR__ . '/..' . '/nette/utils/src/exceptions.php',
206
206
  'Nette\\NotSupportedException' => __DIR__ . '/..' . '/nette/utils/src/exceptions.php',
207
207
  'Nette\\OutOfRangeException' => __DIR__ . '/..' . '/nette/utils/src/exceptions.php',
208
+ 'Nette\\ShouldNotHappenException' => __DIR__ . '/..' . '/nette/utils/src/exceptions.php',
208
209
  'Nette\\SmartObject' => __DIR__ . '/..' . '/nette/utils/src/SmartObject.php',
209
210
  'Nette\\StaticClass' => __DIR__ . '/..' . '/nette/utils/src/StaticClass.php',
210
211
  'Nette\\UnexpectedValueException' => __DIR__ . '/..' . '/nette/utils/src/exceptions.php',
@@ -91,17 +91,17 @@
91
91
  },
92
92
  {
93
93
  "name": "nette/utils",
94
- "version": "v4.0.5",
95
- "version_normalized": "4.0.5.0",
94
+ "version": "v4.0.6",
95
+ "version_normalized": "4.0.6.0",
96
96
  "source": {
97
97
  "type": "git",
98
98
  "url": "https://github.com/nette/utils.git",
99
- "reference": "736c567e257dbe0fcf6ce81b4d6dbe05c6899f96"
99
+ "reference": "ce708655043c7050eb050df361c5e313cf708309"
100
100
  },
101
101
  "dist": {
102
102
  "type": "zip",
103
- "url": "https://api.github.com/repos/nette/utils/zipball/736c567e257dbe0fcf6ce81b4d6dbe05c6899f96",
104
- "reference": "736c567e257dbe0fcf6ce81b4d6dbe05c6899f96",
103
+ "url": "https://api.github.com/repos/nette/utils/zipball/ce708655043c7050eb050df361c5e313cf708309",
104
+ "reference": "ce708655043c7050eb050df361c5e313cf708309",
105
105
  "shasum": ""
106
106
  },
107
107
  "require": {
@@ -125,7 +125,7 @@
125
125
  "ext-mbstring": "to use Strings::lower() etc...",
126
126
  "ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()"
127
127
  },
128
- "time": "2024-08-07T15:39:19+00:00",
128
+ "time": "2025-03-30T21:06:30+00:00",
129
129
  "type": "library",
130
130
  "extra": {
131
131
  "branch-alias": {
@@ -174,7 +174,7 @@
174
174
  ],
175
175
  "support": {
176
176
  "issues": "https://github.com/nette/utils/issues",
177
- "source": "https://github.com/nette/utils/tree/v4.0.5"
177
+ "source": "https://github.com/nette/utils/tree/v4.0.6"
178
178
  },
179
179
  "install-path": "../nette/utils"
180
180
  }
@@ -3,7 +3,7 @@
3
3
  'name' => '__root__',
4
4
  'pretty_version' => 'dev-main',
5
5
  'version' => 'dev-main',
6
- 'reference' => '8a6c00e087e36248e86eba645c654c3b499411cc',
6
+ 'reference' => '53b0d437bebe1b115ebfbaf941ac81a3f787bf96',
7
7
  'type' => 'library',
8
8
  'install_path' => __DIR__ . '/../../',
9
9
  'aliases' => array(),
@@ -13,7 +13,7 @@
13
13
  '__root__' => array(
14
14
  'pretty_version' => 'dev-main',
15
15
  'version' => 'dev-main',
16
- 'reference' => '8a6c00e087e36248e86eba645c654c3b499411cc',
16
+ 'reference' => '53b0d437bebe1b115ebfbaf941ac81a3f787bf96',
17
17
  'type' => 'library',
18
18
  'install_path' => __DIR__ . '/../../',
19
19
  'aliases' => array(),
@@ -29,9 +29,9 @@
29
29
  'dev_requirement' => false,
30
30
  ),
31
31
  'nette/utils' => array(
32
- 'pretty_version' => 'v4.0.5',
33
- 'version' => '4.0.5.0',
34
- 'reference' => '736c567e257dbe0fcf6ce81b4d6dbe05c6899f96',
32
+ 'pretty_version' => 'v4.0.6',
33
+ 'version' => '4.0.6.0',
34
+ 'reference' => 'ce708655043c7050eb050df361c5e313cf708309',
35
35
  'type' => 'library',
36
36
  'install_path' => __DIR__ . '/../nette/utils',
37
37
  'aliases' => array(),
@@ -277,7 +277,8 @@ class Arrays
277
277
  */
278
278
  public static function isList(mixed $value): bool
279
279
  {
280
- return is_array($value) && (PHP_VERSION_ID < 80100
280
+ return is_array($value) && (
281
+ PHP_VERSION_ID < 80100
281
282
  ? !$value || array_keys($value) === range(0, count($value) - 1)
282
283
  : array_is_list($value)
283
284
  );
@@ -271,7 +271,7 @@ final class FileSystem
271
271
  */
272
272
  public static function isAbsolute(string $path): bool
273
273
  {
274
- return (bool) preg_match('#([a-z]:)?[/\\\\]|[a-z][a-z0-9+.-]*://#Ai', $path);
274
+ return (bool) preg_match('#([a-z]:)?[/\\\]|[a-z][a-z0-9+.-]*://#Ai', $path);
275
275
  }
276
276
 
277
277
 
@@ -280,7 +280,7 @@ final class FileSystem
280
280
  */
281
281
  public static function normalizePath(string $path): string
282
282
  {
283
- $parts = $path === '' ? [] : preg_split('~[/\\\\]+~', $path);
283
+ $parts = $path === '' ? [] : preg_split('~[/\\\]+~', $path);
284
284
  $res = [];
285
285
  foreach ($parts as $part) {
286
286
  if ($part === '..' && $res && end($res) !== '..' && end($res) !== '') {
@@ -305,6 +305,19 @@ final class FileSystem
305
305
  }
306
306
 
307
307
 
308
+ /**
309
+ * Resolves a path against a base path. If the path is absolute, returns it directly, if it's relative, joins it with the base path.
310
+ */
311
+ public static function resolvePath(string $basePath, string $path): string
312
+ {
313
+ return match (true) {
314
+ self::isAbsolute($path) => self::platformSlashes($path),
315
+ $path === '' => self::platformSlashes($basePath),
316
+ default => self::joinPaths($basePath, $path),
317
+ };
318
+ }
319
+
320
+
308
321
  /**
309
322
  * Converts backslashes to slashes.
310
323
  */
@@ -505,6 +505,6 @@ class Finder implements \IteratorAggregate
505
505
  '\-' => '-',
506
506
  ],
507
507
  );
508
- return '#' . $anchor . $pattern . '$#D' . (defined('PHP_WINDOWS_VERSION_BUILD') ? 'i' : '');
508
+ return '#' . $anchor . $pattern . '$#D' . (Helpers::IsWindows ? 'i' : '');
509
509
  }
510
510
  }
@@ -14,6 +14,9 @@ use Nette;
14
14
 
15
15
  class Helpers
16
16
  {
17
+ public const IsWindows = PHP_OS_FAMILY === 'Windows';
18
+
19
+
17
20
  /**
18
21
  * Executes a callback and returns the captured output as a string.
19
22
  */
@@ -718,42 +718,27 @@ class Image
718
718
  */
719
719
  private function output(int $type, ?int $quality, ?string $file = null): void
720
720
  {
721
- switch ($type) {
722
- case ImageType::JPEG:
723
- $quality = $quality === null ? 85 : max(0, min(100, $quality));
724
- $success = @imagejpeg($this->image, $file, $quality); // @ is escalated to exception
725
- break;
726
-
727
- case ImageType::PNG:
728
- $quality = $quality === null ? 9 : max(0, min(9, $quality));
729
- $success = @imagepng($this->image, $file, $quality); // @ is escalated to exception
730
- break;
731
-
732
- case ImageType::GIF:
733
- $success = @imagegif($this->image, $file); // @ is escalated to exception
734
- break;
735
-
736
- case ImageType::WEBP:
737
- $quality = $quality === null ? 80 : max(0, min(100, $quality));
738
- $success = @imagewebp($this->image, $file, $quality); // @ is escalated to exception
739
- break;
740
-
741
- case ImageType::AVIF:
742
- $quality = $quality === null ? 30 : max(0, min(100, $quality));
743
- $success = @imageavif($this->image, $file, $quality); // @ is escalated to exception
744
- break;
745
-
746
- case ImageType::BMP:
747
- $success = @imagebmp($this->image, $file); // @ is escalated to exception
748
- break;
749
-
750
- default:
751
- throw new Nette\InvalidArgumentException("Unsupported image type '$type'.");
752
- }
753
-
754
- if (!$success) {
755
- throw new ImageException(Helpers::getLastError() ?: 'Unknown error');
756
- }
721
+ [$defQuality, $min, $max] = match ($type) {
722
+ ImageType::JPEG => [85, 0, 100],
723
+ ImageType::PNG => [9, 0, 9],
724
+ ImageType::GIF => [null, null, null],
725
+ ImageType::WEBP => [80, 0, 100],
726
+ ImageType::AVIF => [30, 0, 100],
727
+ ImageType::BMP => [null, null, null],
728
+ default => throw new Nette\InvalidArgumentException("Unsupported image type '$type'."),
729
+ };
730
+
731
+ $args = [$this->image, $file];
732
+ if ($defQuality !== null) {
733
+ $args[] = $quality === null ? $defQuality : max($min, min($max, $quality));
734
+ }
735
+
736
+ Callback::invokeSafe('image' . self::Formats[$type], $args, function (string $message) use ($file): void {
737
+ if ($file !== null) {
738
+ @unlink($file);
739
+ }
740
+ throw new ImageException($message);
741
+ });
757
742
  }
758
743
 
759
744
 
@@ -233,6 +233,7 @@ final class Iterables
233
233
  $iterable instanceof \Iterator => $iterable,
234
234
  $iterable instanceof \IteratorAggregate => self::toIterator($iterable->getIterator()),
235
235
  is_array($iterable) => new \ArrayIterator($iterable),
236
+ default => throw new Nette\ShouldNotHappenException,
236
237
  };
237
238
  }
238
239
  }
@@ -19,14 +19,14 @@ final class Reflection
19
19
  {
20
20
  use Nette\StaticClass;
21
21
 
22
- /** @deprecated use Nette\Utils\Validator::isBuiltinType() */
22
+ /** @deprecated use Nette\Utils\Validators::isBuiltinType() */
23
23
  public static function isBuiltinType(string $type): bool
24
24
  {
25
25
  return Validators::isBuiltinType($type);
26
26
  }
27
27
 
28
28
 
29
- /** @deprecated use Nette\Utils\Validator::isClassKeyword() */
29
+ /** @deprecated use Nette\Utils\Validators::isClassKeyword() */
30
30
  public static function isClassKeyword(string $name): bool
31
31
  {
32
32
  return Validators::isClassKeyword($name);
@@ -28,7 +28,7 @@ class Strings
28
28
 
29
29
 
30
30
  /**
31
- * @deprecated use Nette\Utils\Validator::isUnicode()
31
+ * @deprecated use Nette\Utils\Validators::isUnicode()
32
32
  */
33
33
  public static function checkEncoding(string $s): bool
34
34
  {
@@ -547,7 +547,6 @@ class Strings
547
547
  return $utf8 && $captureOffset
548
548
  ? self::bytesToChars($subject, [$m])[0]
549
549
  : $m;
550
-
551
550
  }
552
551
 
553
552
 
@@ -260,8 +260,8 @@ final class Type
260
260
  $subtypes,
261
261
  fn($subtype) => Validators::isBuiltinType($type)
262
262
  ? strcasecmp($type, $subtype) === 0
263
- : is_a($subtype, $type, allow_string: true)
264
- )
263
+ : is_a($subtype, $type, allow_string: true),
264
+ ),
265
265
  );
266
266
  }
267
267
  }
@@ -11,7 +11,7 @@ namespace Nette\Utils;
11
11
 
12
12
 
13
13
  /**
14
- * The exception that is thrown when an image error occurs.
14
+ * An error occurred while working with the image.
15
15
  */
16
16
  class ImageException extends \Exception
17
17
  {
@@ -19,7 +19,7 @@ class ImageException extends \Exception
19
19
 
20
20
 
21
21
  /**
22
- * The exception that indicates invalid image file.
22
+ * The image file is invalid or in an unsupported format.
23
23
  */
24
24
  class UnknownImageFileException extends ImageException
25
25
  {
@@ -27,7 +27,7 @@ class UnknownImageFileException extends ImageException
27
27
 
28
28
 
29
29
  /**
30
- * The exception that indicates error of JSON encoding/decoding.
30
+ * JSON encoding or decoding failed.
31
31
  */
32
32
  class JsonException extends \JsonException
33
33
  {
@@ -35,7 +35,7 @@ class JsonException extends \JsonException
35
35
 
36
36
 
37
37
  /**
38
- * The exception that indicates error of the last Regexp execution.
38
+ * Regular expression pattern or execution failed.
39
39
  */
40
40
  class RegexpException extends \Exception
41
41
  {
@@ -43,7 +43,7 @@ class RegexpException extends \Exception
43
43
 
44
44
 
45
45
  /**
46
- * The exception that indicates assertion error.
46
+ * Type validation failed. The value doesn't match the expected type constraints.
47
47
  */
48
48
  class AssertionException extends \Exception
49
49
  {
@@ -11,8 +11,7 @@ namespace Nette;
11
11
 
12
12
 
13
13
  /**
14
- * The exception that is thrown when the value of an argument is
15
- * outside the allowable range of values as defined by the invoked method.
14
+ * The value is outside the allowed range.
16
15
  */
17
16
  class ArgumentOutOfRangeException extends \InvalidArgumentException
18
17
  {
@@ -20,8 +19,7 @@ class ArgumentOutOfRangeException extends \InvalidArgumentException
20
19
 
21
20
 
22
21
  /**
23
- * The exception that is thrown when a method call is invalid for the object's
24
- * current state, method has been invoked at an illegal or inappropriate time.
22
+ * The object is in a state that does not allow the requested operation.
25
23
  */
26
24
  class InvalidStateException extends \RuntimeException
27
25
  {
@@ -29,7 +27,7 @@ class InvalidStateException extends \RuntimeException
29
27
 
30
28
 
31
29
  /**
32
- * The exception that is thrown when a requested method or operation is not implemented.
30
+ * The requested feature is not implemented.
33
31
  */
34
32
  class NotImplementedException extends \LogicException
35
33
  {
@@ -37,8 +35,7 @@ class NotImplementedException extends \LogicException
37
35
 
38
36
 
39
37
  /**
40
- * The exception that is thrown when an invoked method is not supported. For scenarios where
41
- * it is sometimes possible to perform the requested operation, see InvalidStateException.
38
+ * The requested operation is not supported.
42
39
  */
43
40
  class NotSupportedException extends \LogicException
44
41
  {
@@ -46,7 +43,7 @@ class NotSupportedException extends \LogicException
46
43
 
47
44
 
48
45
  /**
49
- * The exception that is thrown when a requested method or operation is deprecated.
46
+ * The requested feature is deprecated and no longer available.
50
47
  */
51
48
  class DeprecatedException extends NotSupportedException
52
49
  {
@@ -54,7 +51,7 @@ class DeprecatedException extends NotSupportedException
54
51
 
55
52
 
56
53
  /**
57
- * The exception that is thrown when accessing a class member (property or method) fails.
54
+ * Cannot access the requested class property or method.
58
55
  */
59
56
  class MemberAccessException extends \Error
60
57
  {
@@ -62,7 +59,7 @@ class MemberAccessException extends \Error
62
59
 
63
60
 
64
61
  /**
65
- * The exception that is thrown when an I/O error occurs.
62
+ * Failed to read from or write to a file or stream.
66
63
  */
67
64
  class IOException extends \RuntimeException
68
65
  {
@@ -70,7 +67,7 @@ class IOException extends \RuntimeException
70
67
 
71
68
 
72
69
  /**
73
- * The exception that is thrown when accessing a file that does not exist on disk.
70
+ * The requested file does not exist.
74
71
  */
75
72
  class FileNotFoundException extends IOException
76
73
  {
@@ -78,7 +75,7 @@ class FileNotFoundException extends IOException
78
75
 
79
76
 
80
77
  /**
81
- * The exception that is thrown when part of a file or directory cannot be found.
78
+ * The requested directory does not exist.
82
79
  */
83
80
  class DirectoryNotFoundException extends IOException
84
81
  {
@@ -86,7 +83,7 @@ class DirectoryNotFoundException extends IOException
86
83
 
87
84
 
88
85
  /**
89
- * The exception that is thrown when an argument does not match with the expected value.
86
+ * The provided argument has invalid type or format.
90
87
  */
91
88
  class InvalidArgumentException extends \InvalidArgumentException
92
89
  {
@@ -94,7 +91,7 @@ class InvalidArgumentException extends \InvalidArgumentException
94
91
 
95
92
 
96
93
  /**
97
- * The exception that is thrown when an illegal index was requested.
94
+ * The requested array or collection index does not exist.
98
95
  */
99
96
  class OutOfRangeException extends \OutOfRangeException
100
97
  {
@@ -102,8 +99,16 @@ class OutOfRangeException extends \OutOfRangeException
102
99
 
103
100
 
104
101
  /**
105
- * The exception that is thrown when a value (typically returned by function) does not match with the expected value.
102
+ * The returned value has unexpected type or format.
106
103
  */
107
104
  class UnexpectedValueException extends \UnexpectedValueException
108
105
  {
109
106
  }
107
+
108
+
109
+ /**
110
+ * Houston, we have a problem.
111
+ */
112
+ class ShouldNotHappenException extends \LogicException
113
+ {
114
+ }