@@ -14,7 +14,7 @@ class Importmap
14
14
15
15
public function __construct (public ?string $ rootPath = null )
16
16
{
17
- $ this ->rootPath = rtrim ($ this ->rootPath ?: base_path (), ' / ' );
17
+ $ this ->rootPath = rtrim ($ this ->rootPath ?: base_path (), DIRECTORY_SEPARATOR );
18
18
$ this ->packages = collect ();
19
19
$ this ->directories = collect ();
20
20
}
@@ -54,6 +54,11 @@ public function getRootPath(): string
54
54
return $ this ->rootPath ;
55
55
}
56
56
57
+ public function getFileAbsolutePath (string $ relativePath ): string
58
+ {
59
+ return $ this ->rootPath . str_replace ('/ ' , DIRECTORY_SEPARATOR , $ relativePath );
60
+ }
61
+
57
62
private function hasManifest (): bool
58
63
{
59
64
return File::exists ($ this ->manifestPath ());
@@ -106,9 +111,9 @@ private function expandDirectories(): Collection
106
111
$ moduleName = $ this ->moduleNameFrom ($ moduleFilename , $ mapping );
107
112
$ modulePath = $ this ->modulePathFrom ($ moduleFilename , $ mapping );
108
113
109
- // We're ignoring anything that starts with `vendor/ `, as that's probably
114
+ // We're ignoring anything that starts with `vendor`, as that's probably
110
115
// being mapped directly as a result of pinning with a --download flag.
111
- if (str_starts_with ($ moduleFilename , 'vendor/ ' )) {
116
+ if (str_starts_with ($ moduleFilename , 'vendor ' )) {
112
117
return null ;
113
118
}
114
119
@@ -121,10 +126,10 @@ private function expandDirectories(): Collection
121
126
private function absoluteRootOf (string $ path ): string
122
127
{
123
128
if (Str::startsWith ($ path , '/ ' )) {
124
- return $ path ;
129
+ return str_replace ( ' / ' , DIRECTORY_SEPARATOR , $ path) ;
125
130
}
126
131
127
- return $ this ->rootPath . '/ ' . $ path ;
132
+ return $ this ->rootPath . DIRECTORY_SEPARATOR . str_replace ( '/ ' , DIRECTORY_SEPARATOR , $ path) ;
128
133
}
129
134
130
135
private function findJavascriptFilesInTree (string $ absolutePath ): Collection
@@ -138,23 +143,23 @@ private function findJavascriptFilesInTree(string $absolutePath): Collection
138
143
139
144
private function relativePathFrom (string $ fileAbsolutePath , string $ folderAbsolutePath )
140
145
{
141
- return trim (Str::after ($ fileAbsolutePath , $ folderAbsolutePath ), ' / ' );
146
+ return trim (Str::after ($ fileAbsolutePath , $ folderAbsolutePath ), DIRECTORY_SEPARATOR );
142
147
}
143
148
144
149
private function moduleNameFrom (string $ moduleFileName , MappedDirectory $ mapping ): string
145
150
{
146
- return implode ('/ ' , array_filter ([
151
+ return str_replace ( DIRECTORY_SEPARATOR , ' / ' , implode ('/ ' , array_filter ([
147
152
$ mapping ->under ,
148
- preg_replace ('#(/ ?index)?\.jsm?$# ' , '' , $ moduleFileName ),
149
- ]));
153
+ preg_replace ('#([ \\ \/] ?index)?\.jsm?$# ' , '' , $ moduleFileName ),
154
+ ]))) ;
150
155
}
151
156
152
157
private function modulePathFrom (string $ moduleFilename , MappedDirectory $ mapping ): string
153
158
{
154
- return implode ('/ ' , array_filter ([
155
- rtrim ($ mapping ->path ?: $ mapping ->under , '/ ' ),
159
+ return str_replace ( DIRECTORY_SEPARATOR , ' / ' , implode ('/ ' , array_filter ([
160
+ rtrim ($ mapping ->path ?: $ mapping ->under , DIRECTORY_SEPARATOR . '/ ' ),
156
161
$ moduleFilename ,
157
- ]));
162
+ ]))) ;
158
163
}
159
164
160
165
private function resolveAssetPaths (Collection $ paths , callable $ assetResolver ): array
0 commit comments