You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/AssetMapper/TypeScriptCompiler.php
+29-7Lines changed: 29 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,9 @@ class TypeScriptCompiler implements AssetCompilerInterface
11
11
{
12
12
privateFilesystem$fileSystem;
13
13
14
+
/**
15
+
* @param list<string> $typeScriptFilesPaths
16
+
*/
14
17
publicfunction__construct(
15
18
privatereadonlyarray$typeScriptFilesPaths,
16
19
privatereadonlystring$jsPathDirectory,
@@ -21,34 +24,53 @@ public function __construct(
21
24
22
25
publicfunctionsupports(MappedAsset$asset): bool
23
26
{
24
-
if (!str_ends_with($asset->sourcePath, '.ts')) {
27
+
$realSourcePath = realpath($asset->sourcePath);
28
+
if (false === $realSourcePath) {
29
+
returnfalse;
30
+
}
31
+
if (!str_ends_with($realSourcePath, '.ts')) {
25
32
returnfalse;
26
33
}
27
34
foreach ($this->typeScriptFilesPathsas$path) {
35
+
$realTypeScriptPath = realpath($path);
36
+
if (false === $realTypeScriptPath) {
37
+
thrownew \Exception(sprintf('The TypeScript directory "%s" does not exist', $path));
38
+
}
28
39
// If the asset matches one of the TypeScript files source paths
29
-
if (realpath($asset->sourcePath) === realpath($path)) {
40
+
if ($realSourcePath === $realTypeScriptPath) {
30
41
returntrue;
31
42
}
32
43
// If the asset is in a directory (or subdirectory) of one of the TypeScript directory source paths
33
-
if (is_dir($path) && !str_starts_with($this->fileSystem->makePathRelative(realpath($asset->sourcePath), realpath($path)), '../')) {
44
+
if (is_dir($realTypeScriptPath) && !str_starts_with($this->fileSystem->makePathRelative($realSourcePath, $realTypeScriptPath), '../')) {
34
45
returntrue;
35
46
}
36
47
}
37
48
38
-
thrownew \Exception(sprintf('The TypeScript file "%s" is not in the TypeScript files paths. Check the asset path or your "sensiolabs_typescript.source_dir" in your config', $asset->sourcePath));
49
+
thrownew \Exception(sprintf('The TypeScript file "%s" is not in the TypeScript files paths. Check the asset path or your "sensiolabs_typescript.source_dir" in your config', $realSourcePath));
thrownew \Exception(sprintf('The TypeScript file "%s" is not in the TypeScript files paths. Check the asset path or your "sensiolabs_typescript.source_dir" in your config', $asset->sourcePath));
73
+
}
52
74
$asset->addFileDependency($jsFile);
53
75
54
76
if (($content = file_get_contents($jsFile)) === false) {
0 commit comments