Skip to content

Commit d393a2d

Browse files
committed
[TASK] Prepare import map prefix-based URL calculation
Import map resolution without a cache-bust suffix missed to join a previously splitted path-string via slashes, when a prefix based import-declaration was used to calculate the resulting URL of a JavaScript bare module specifier (usecase: calculate the URL of a bare module specifier for usage in a `<script src="">` tag, where bare module specifiers like `@typo3/backend/foo.js` can not be used directly as browsers will not map them by importmap). Note: TYPO3 currently uses cache-bust suffixes only, as there are no cache-bust prefixes yet. Therefore all prefix-paths are recursively pre-calculated in `computeImportMaps()`, which effecively skipped the broken codepath for the current environments, which means this is a preparatory TASK and not a BUGFIX for the case when once prefix-based cache-busting is added in #98481. Resolves: #103954 Related: #98481 Releases: main, 13.4 Change-Id: Ia6046a5b9a18016cd8166bd8ec30738663c73a46 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84447 Reviewed-by: Benjamin Kott <benjamin.kott@outlook.com> Reviewed-by: Andreas Kienast <akienast@scripting-base.de> Tested-by: Benjamin Kott <benjamin.kott@outlook.com> Tested-by: Andreas Kienast <akienast@scripting-base.de> Reviewed-by: Benjamin Franzke <ben@bnf.dev> Tested-by: core-ci <typo3@b13.com> Tested-by: Benjamin Franzke <ben@bnf.dev>
1 parent e82ec8a commit d393a2d

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

typo3/sysext/core/Classes/Page/ImportMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function resolveImport(
106106
if ($loadImportConfiguration) {
107107
$this->loadDependency($package);
108108
}
109-
return $imports[$prefix] . implode(array_slice($specifierParts, $i));
109+
return $imports[$prefix] . implode('/', array_slice($specifierParts, $i));
110110
}
111111
}
112112
}

typo3/sysext/core/Tests/Unit/Page/Fixtures/ImportMap/core/Resources/Public/JavaScript/nested/module.js

Whitespace-only changes.

typo3/sysext/core/Tests/Unit/Page/ImportMapTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ public function resolveImport(): void
101101
self::assertStringStartsWith('Fixtures/ImportMap/core/Resources/Public/JavaScript/Contrib/lit/index.js?bust=', $url);
102102
}
103103

104+
#[Test]
105+
public function resolveNestedUrlImportWithBustSuffix(): void
106+
{
107+
$this->packages = ['core'];
108+
$importMap = new ImportMap($this->hashService, $this->getPackages());
109+
$nestedUrl = $importMap->resolveImport('@typo3/core/nested/module.js');
110+
111+
self::assertStringStartsWith('Fixtures/ImportMap/core/Resources/Public/JavaScript/nested/module.js?bust=', $nestedUrl);
112+
}
113+
114+
#[Test]
115+
public function resolveNestedUrlImportWithoutBustSuffix(): void
116+
{
117+
$this->packages = ['core'];
118+
119+
$importMap = new ImportMap($this->hashService, $this->getPackages(), null, '', null, false);
120+
$nestedUrl = $importMap->resolveImport('@typo3/core/nested/module.js');
121+
122+
self::assertEquals('Fixtures/ImportMap/core/Resources/Public/JavaScript/nested/module.js', $nestedUrl);
123+
}
124+
104125
#[Test]
105126
public function resolveAndImplicitlyIncludeModuleConfiguration(): void
106127
{

0 commit comments

Comments
 (0)