20
20
use Composer \Package \BasePackage ;
21
21
use Composer \Script \Event ;
22
22
use Exception ;
23
- use OpenMage \ComposerPlugin \Copy \Composer as Composer ;
24
- use OpenMage \ComposerPlugin \Copy \Npm as Npm ;
25
23
use Symfony \Component \Filesystem \Exception \IOException ;
26
24
use Symfony \Component \Filesystem \Filesystem ;
27
25
use Symfony \Component \Finder \Finder ;
@@ -68,7 +66,7 @@ public function __construct(Event $event)
68
66
public function processComposerInstall (): void
69
67
{
70
68
$ copySourcePath = null ;
71
- if ($ this instanceof Composer \PluginInterface ) {
69
+ if ($ this instanceof CopyFromComposerInterface ) {
72
70
$ package = $ this ->getComposerPackage ();
73
71
if (!$ package ) {
74
72
return ;
@@ -78,15 +76,15 @@ public function processComposerInstall(): void
78
76
79
77
$ filesystem = new Filesystem ();
80
78
81
- if ($ this instanceof Npm \PluginInterface && (!$ copySourcePath || !$ filesystem ->exists ($ copySourcePath ))) {
79
+ if ($ this instanceof CopyFromNpmInterface && (!$ copySourcePath || !$ filesystem ->exists ($ copySourcePath ))) {
82
80
if ($ this ->event ->getIO ()->isVerbose ()) {
83
81
$ this ->event ->getIO ()->write (sprintf ('Fallback to NPM for %s ' , $ this ->getNpmPackageName ()));
84
82
}
85
83
$ this ->processNpmInstall ();
86
84
return ;
87
85
}
88
86
89
- if ($ copySourcePath && $ this instanceof Composer \PluginInterface ) {
87
+ if ($ copySourcePath && $ this instanceof CopyFromComposerInterface ) {
90
88
$ finder = Finder::create ()
91
89
->files ()
92
90
->in ($ copySourcePath )
@@ -113,8 +111,11 @@ public function processComposerInstall(): void
113
111
*/
114
112
public function processNpmInstall (): void
115
113
{
116
- if ($ this instanceof Npm \PluginInterface) {
117
- $ filesystem = new Filesystem ();
114
+ if ($ this instanceof CopyFromNpmInterface) {
115
+ if (!$ this ->getVersion ()) {
116
+ return ;
117
+ }
118
+
118
119
$ sourcePath = $ this ->getNpmFilePath ();
119
120
120
121
if ($ this ->event ->getIO ()->isVerbose ()) {
@@ -134,14 +135,14 @@ public function processNpmInstall(): void
134
135
$ this ->event ->getIO ()->write ($ errorException ->getMessage ());
135
136
return ;
136
137
}
137
- $ content = file_get_contents ($ sourceFilePath );
138
138
139
139
if (!$ content ) {
140
140
$ this ->event ->getIO ()->write (sprintf ('Could not read from %s ' , $ sourceFilePath ));
141
141
return ;
142
142
}
143
143
144
144
try {
145
+ $ filesystem = new Filesystem ();
145
146
$ targetFilePath = $ this ->getCopyTargetPath () . '/ ' . $ fileName ;
146
147
$ filesystem ->dumpFile ($ targetFilePath , $ content );
147
148
if ($ this ->event ->getIO ()->isVerbose ()) {
@@ -157,7 +158,7 @@ public function processNpmInstall(): void
157
158
158
159
public function getComposerPackage (): ?BasePackage
159
160
{
160
- if ($ this instanceof Composer \PluginInterface ) {
161
+ if ($ this instanceof CopyFromComposerInterface ) {
161
162
$ vendorName = $ this ->getComposerPackageName ();
162
163
$ module = $ this ->getInstalledComposerPackage ($ vendorName );
163
164
if ($ module ) {
@@ -185,7 +186,7 @@ public function getComposerPackage(): ?BasePackage
185
186
*/
186
187
public function getNpmPackage (): ?array
187
188
{
188
- if ($ this instanceof Npm \PluginInterface ) {
189
+ if ($ this instanceof CopyFromNpmInterface ) {
189
190
$ vendorName = $ this ->getNpmPackageName ();
190
191
191
192
$ locker = $ this ->event ->getComposer ()->getLocker ();
@@ -229,10 +230,10 @@ public function getNpmPackage(): ?array
229
230
*/
230
231
protected function getNpmFilePath (): string
231
232
{
232
- if ($ this instanceof Npm \PluginInterface ) {
233
+ if ($ this instanceof CopyFromNpmInterface ) {
233
234
$ search = ['{{package}} ' , '{{version}} ' ];
234
235
$ replace = [$ this ->getNpmPackageName (), $ this ->getVersion ()];
235
- return str_replace ($ search , $ replace , Npm \PluginInterface ::NPM_FALLBACK_URL );
236
+ return str_replace ($ search , $ replace , CopyFromNpmInterface ::NPM_FALLBACK_URL );
236
237
}
237
238
return '' ;
238
239
}
@@ -245,11 +246,11 @@ private function getVersion(): string
245
246
if (is_null ($ this ->version )) {
246
247
$ version = '' ;
247
248
switch (true ) {
248
- case $ this instanceof Composer \PluginInterface :
249
+ case $ this instanceof CopyFromComposerInterface :
249
250
$ package = $ this ->getComposerPackage ();
250
251
$ version = $ package ? $ package ->getPrettyVersion () : '' ;
251
252
break ;
252
- case $ this instanceof Npm \PluginInterface :
253
+ case $ this instanceof CopyFromNpmInterface :
253
254
$ package = $ this ->getNpmPackage ();
254
255
$ version = $ package ? $ package ['version ' ] : '' ;
255
256
break ;
@@ -301,7 +302,7 @@ protected function getMageRootDirectoryFromComposer(): string
301
302
302
303
protected function getCopySourcePath (): string
303
304
{
304
- if ($ this instanceof Composer \PluginInterface ) {
305
+ if ($ this instanceof CopyFromComposerInterface ) {
305
306
return sprintf (
306
307
'%s/%s/%s ' ,
307
308
$ this ->getVendorDirectoryFromComposer (),
0 commit comments