laravel-packager icon indicating copy to clipboard operation
laravel-packager copied to clipboard

Avoid to change path of composer.json

Open thewebartisan7 opened this issue 3 years ago • 5 comments

Right now in composer.json path are added with full path of local environment which should be changed when you move project.

Now is:

    "repositories": {
        "vendor/package": {
            "type": "path",
            "url": "/Users/me/Projects/laravel/packages/vendor/package"
        }
    }

But better would be:

    "repositories": [{
        "type": "path",
        "url": "packages/*/*/",
        "options": {
            "symlink": true
        }
    }],

and in require:

    "require": {
        "vendor/package": "dev-master"
    },

What do you think?

thewebartisan7 avatar Sep 01 '20 12:09 thewebartisan7

There is already a PR for this : #115

A better way is to set

    "require": {
        "vendor/package": "@dev"
    },

This rule allow all dev branches like dev-*. This is useful if you have many branches of your package

I thought of putting packages/*/* when I wrote the PR, but this would require checking that the last package is removed to remove the rule. After that it's still possible to do like this, any opinion on this ?

sebastienheyd avatar Sep 02 '20 06:09 sebastienheyd

I like the idea of allowing all dev branches, however I tested with your same package monolog/monolog. The package was downloaded in packages folder but in vendor is not symlinked.

Screenshot:

Screenshot 2020-09-02 at 12 58 32

But using "monolog/monolog": "dev-master" did the symlink.

Then I tested with custom package MyVendor/MyPackage and I can see in composer:

    "repositories": {
        "myvendor/mypackage": {
            "type": "path",
            "url": "/Users/me/Projects/laravel/packages/MyVendor/MyPackage",
            "options": {
                "symlink": true
            }
        }
    }
    "require": {
        "myvendor/mypackage": "@dev"
    },

There is still full URL in repositories.

If I move to server, I need to change composer.json

What I mean here is that URL is rather like this:

    "repositories": {
        "myvendor/mypackage": {
            "type": "path",
            "url": "packages/MyVendor/MyPackage",
            "options": {
                "symlink": true
            }
        }
    }

but also like this:

    "repositories": [{
        "type": "path",
        "url": "packages/*/*/",
        "options": {
            "symlink": true
        }
    }],

Last doesn't require to edit for each package the "repositories", like now you have for each package:

    "repositories": {
        "myvendor/mypackage": {
            "type": "path",
            "url": "/Users/me/Projects/laravel/packages/MyVendor/MyPackage",
            "options": {
                "symlink": true
            }
        },
        "myvendor/mypackage2": {
            "type": "path",
            "url": "/Users/me/Projects/laravel/packages/MyVendor/MyPackage2",
            "options": {
                "symlink": true
            }
        }
        "myvendor2/mypackage": {
            "type": "path",
            "url": "/Users/me/Projects/laravel/packages/MyVendor1/MyPackage",
            "options": {
                "symlink": true
            }
        }
    }

etc... for each package

thewebartisan7 avatar Sep 02 '20 11:09 thewebartisan7

I see and you're right.

In one of my other PR I propose to set the path of the folder in the configuration file

https://github.com/sebastienheyd/laravel-packager/blob/e878f092b9c14dc5dba62b1496b42c8b20ad887d/config/packager.php#L4-L7

My first idea was to set a relative path here instead of the full one (with the call to basepath() ).

But I'm agree, the simpliest way is to set only one repository rule with packages/*/*/

I'm just waiting now to see if my PR will be merged or not, after that I can do another PR for the "unique rule"

sebastienheyd avatar Sep 02 '20 11:09 sebastienheyd

@sebastienheyd did you create a PR for this, actually I was not able to locate the same.

karmendra avatar Mar 11 '21 19:03 karmendra

I'm not sure if this is the same or a different issue. Im working in WSL with a Docker container providing my webserver. When I run artisan packager:new acme supercool, my composer is updated with the full path

    "repositories": {
        "acme/supercool": {
            "type": "path",
            "url": "/home/some-guy/test/packages/acme/supercool",
            "options": {
                "symlink": true
            }
        }
    }

Because my webserver mounts test as /var/www/html, the package is no longer a valid path for composer. What would resolve this for me is if the default path was relative. Eg.

    "repositories": {
        "acme/supercool": {
            "type": "path",
            "url": "./packages/acme/supercool",
            "options": {
                "symlink": true
            }
        }
    }

When I manually change, bother WSL & the webserver are happy. This also would allow the files to commited or moved to a different path (or even system) without breaking.

I think "url": "packages/*/*/", is a little too much. It's hard to know when / if you can remove it.

tyler36 avatar Jul 30 '21 04:07 tyler36