Skip to content

Commit ba2753e

Browse files
committed
fix: use relative paths when importing components
1 parent 9158fc9 commit ba2753e

File tree

13 files changed

+99
-138
lines changed

13 files changed

+99
-138
lines changed

src/CacheWarmer/StorybookCacheWarmer.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public function __construct(
1717
private readonly ?string $cacheDir,
1818
private readonly bool $debug,
1919
private readonly string $projectDir,
20-
private readonly array $storybookConfig,
2120
private readonly array $twigConfig,
2221
private readonly array $twigComponentConfig,
2322
) {
@@ -54,11 +53,38 @@ private function getConfigCacheFactory(): ConfigCacheFactoryInterface
5453
private function generateSymfonyParameters(ConfigCacheInterface $cache): void
5554
{
5655
$parameters = [
57-
'storybook_bundle_config' => $this->storybookConfig,
58-
'twig_config' => $this->twigConfig,
59-
'twig_component_config' => $this->twigComponentConfig,
56+
'twig_config' => [
57+
'default_path' => $this->twigConfig['default_path'],
58+
'paths' => $this->twigConfig['paths'],
59+
],
60+
'twig_component_config' => [
61+
'anonymous_template_directory' => $this->twigComponentConfig['anonymous_template_directory'],
62+
'defaults' => $this->twigComponentConfig['defaults'],
63+
],
6064
];
6165

62-
$cache->write(json_encode($parameters, JSON_PRETTY_PRINT));
66+
$cache->write(json_encode($this->stripProjectDirectory($parameters), JSON_PRETTY_PRINT));
67+
}
68+
69+
private function stripProjectDirectory(array $array): array
70+
{
71+
$sanitizedArray = [];
72+
foreach ($array as $key => $value) {
73+
if (is_string($value) && str_starts_with($value, $this->projectDir)) {
74+
$value = str_replace($this->projectDir, '', $value);
75+
}
76+
77+
if (is_string($key) && str_starts_with($key, $this->projectDir)) {
78+
$key = str_replace($this->projectDir, '', $key);
79+
$sanitizedArray[$key] = $value;
80+
} elseif (is_array($value)) {
81+
$sanitizedArray[$key] = $this->stripProjectDirectory($value);
82+
} else {
83+
$sanitizedArray[$key] = $value;
84+
}
85+
86+
}
87+
88+
return $sanitizedArray;
6389
}
6490
}

storybook/dist/builders/webpack-builder.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

storybook/dist/builders/webpack-builder.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

storybook/dist/index.d.mts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ type FrameworkName = '@sensiolabs/storybook-symfony-webpack5';
3434
type BuilderName = '@storybook/builder-webpack5';
3535
type ProxyPaths = string[] | string;
3636
type SymfonyOptions = {
37-
/**
38-
* Symfony project directory.
39-
*/
40-
projectDir: string;
4137
/**
4238
* Storybook cache directory.
4339
*/
@@ -54,15 +50,6 @@ type SymfonyOptions = {
5450
* Additional paths to watch during compilation.
5551
*/
5652
additionalWatchPaths?: string[];
57-
/**
58-
* When Storybook and Symfony are not on the same host (e.g. Symfony is Dockerized), mounted paths may differ.
59-
* This option allows to map paths from Storybook host to Symfony host.
60-
*
61-
* Example: { __dirname: '/var/www' }
62-
*/
63-
projectPathAliases?: {
64-
[p: string]: string;
65-
};
6653
};
6754
type FrameworkOptions = {
6855
builder?: BuilderOptions;

storybook/dist/index.d.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ type FrameworkName = '@sensiolabs/storybook-symfony-webpack5';
3434
type BuilderName = '@storybook/builder-webpack5';
3535
type ProxyPaths = string[] | string;
3636
type SymfonyOptions = {
37-
/**
38-
* Symfony project directory.
39-
*/
40-
projectDir: string;
4137
/**
4238
* Storybook cache directory.
4339
*/
@@ -54,15 +50,6 @@ type SymfonyOptions = {
5450
* Additional paths to watch during compilation.
5551
*/
5652
additionalWatchPaths?: string[];
57-
/**
58-
* When Storybook and Symfony are not on the same host (e.g. Symfony is Dockerized), mounted paths may differ.
59-
* This option allows to map paths from Storybook host to Symfony host.
60-
*
61-
* Example: { __dirname: '/var/www' }
62-
*/
63-
projectPathAliases?: {
64-
[p: string]: string;
65-
};
6653
};
6754
type FrameworkOptions = {
6855
builder?: BuilderOptions;

0 commit comments

Comments
 (0)