@@ -78,12 +78,12 @@ private function removePackageJsonLinks(array $packageJson): bool
7878
7979 private function addPackageJsonLink (string $ phpPackage ): bool
8080 {
81- if (!$ assetsDir = $ this ->resolveAssetsDir ($ phpPackage )) {
81+ if (!$ packageJson = $ this ->resolvePackageJson ($ phpPackage )) {
8282 return false ;
8383 }
8484
8585 $ manipulator = new JsonManipulator (file_get_contents ($ this ->rootDir .'/package.json ' ));
86- $ manipulator ->addSubNode ('devDependencies ' , '@ ' .$ phpPackage , 'file: ' .$ this -> vendorDirname . ' / ' . $ phpPackage . $ assetsDir );
86+ $ manipulator ->addSubNode ('devDependencies ' , '@ ' .$ phpPackage , 'file: ' .substr ( $ packageJson -> getPath (), 1 + \strlen ( $ this -> rootDir ), - 13 ) );
8787
8888 $ content = json_decode ($ manipulator ->getContents (), true );
8989
@@ -109,15 +109,11 @@ private function registerWebpackResources(array $phpPackages)
109109 ];
110110
111111 foreach ($ phpPackages as $ phpPackage ) {
112- if (!$ assetsDir = $ this ->resolveAssetsDir ($ phpPackage )) {
112+ if (!$ packageJson = $ this ->resolvePackageJson ($ phpPackage )) {
113113 continue ;
114114 }
115115
116- // Register in config
117- $ packageJsonPath = $ this ->rootDir .'/ ' .$ this ->vendorDirname .'/ ' .$ phpPackage .$ assetsDir .'/package.json ' ;
118- $ packageJson = (new JsonFile ($ packageJsonPath ))->read ();
119-
120- foreach ($ packageJson ['symfony ' ]['controllers ' ] ?? [] as $ controllerName => $ defaultConfig ) {
116+ foreach ($ packageJson ->read ()['symfony ' ]['controllers ' ] ?? [] as $ controllerName => $ defaultConfig ) {
121117 // If the package has just been added (no config), add the default config provided by the package
122118 if (!isset ($ previousControllersJson ['controllers ' ]['@ ' .$ phpPackage ][$ controllerName ])) {
123119 $ config = [];
@@ -152,7 +148,7 @@ private function registerWebpackResources(array $phpPackages)
152148 $ newControllersJson ['controllers ' ]['@ ' .$ phpPackage ][$ controllerName ] = $ config ;
153149 }
154150
155- foreach ($ packageJson ['symfony ' ]['entrypoints ' ] ?? [] as $ entrypoint => $ filename ) {
151+ foreach ($ packageJson-> read () ['symfony ' ]['entrypoints ' ] ?? [] as $ entrypoint => $ filename ) {
156152 if (!isset ($ newControllersJson ['entrypoints ' ][$ entrypoint ])) {
157153 $ newControllersJson ['entrypoints ' ][$ entrypoint ] = $ filename ;
158154 }
@@ -167,15 +163,13 @@ public function registerPeerDependencies(array $phpPackages)
167163 $ peerDependencies = [];
168164
169165 foreach ($ phpPackages as $ phpPackage ) {
170- if (!$ assetsDir = $ this ->resolveAssetsDir ($ phpPackage )) {
166+ if (!$ packageJson = $ this ->resolvePackageJson ($ phpPackage )) {
171167 continue ;
172168 }
173169
174- $ packageJsonPath = $ this ->rootDir .'/ ' .$ this ->vendorDirname .'/ ' .$ phpPackage .$ assetsDir .'/package.json ' ;
175- $ packageJson = (new JsonFile ($ packageJsonPath ))->read ();
176170 $ versionParser = new VersionParser ();
177171
178- foreach ($ packageJson ['peerDependencies ' ] ?? [] as $ peerDependency => $ constraint ) {
172+ foreach ($ packageJson-> read () ['peerDependencies ' ] ?? [] as $ peerDependency => $ constraint ) {
179173 $ peerDependencies [$ peerDependency ][$ constraint ] = $ versionParser ->parseConstraints ($ constraint );
180174 }
181175 }
@@ -197,12 +191,22 @@ public function registerPeerDependencies(array $phpPackages)
197191 file_put_contents ($ this ->rootDir .'/package.json ' , $ manipulator ->getContents ());
198192 }
199193
200- private function resolveAssetsDir (string $ phpPackage )
194+ private function resolvePackageJson (string $ phpPackage ): ? JsonFile
201195 {
196+ $ packageDir = $ this ->rootDir .'/ ' .$ this ->vendorDirname .'/ ' .$ phpPackage ;
197+
198+ if (!\in_array ('symfony-ux ' , json_decode (file_get_contents ($ packageDir .'/composer.json ' ), true )['keywords ' ] ?? [], true )) {
199+ return null ;
200+ }
201+
202202 foreach (['/assets ' , '/Resources/assets ' ] as $ subdir ) {
203- if (file_exists ($ this ->rootDir .'/ ' .$ this ->vendorDirname .'/ ' .$ phpPackage .$ subdir .'/package.json ' )) {
204- return $ subdir ;
203+ $ packageJsonPath = $ packageDir .$ subdir .'/package.json ' ;
204+
205+ if (!file_exists ($ packageJsonPath )) {
206+ continue ;
205207 }
208+
209+ return new JsonFile ($ packageJsonPath );
206210 }
207211
208212 return null ;
0 commit comments