WIP: Link command #1017

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
Contributor

fprochazka commented Aug 20, 2012

First of all, this pullrequest is a work in progress.

I'm determined to finish this, but I've got stuck for three days now. I have no clue how to force the composer to use the package, that has installation-source: link that I've provided. The DependencyResolver is just a gibberish to me.

If you guys could just push me in the right direction I'd be really happy to finish this. #601

This pull request fails (merged f48887b into ab38ee3).

jmather commented Oct 11, 2012

Does this alter the composer.json at all? Also -- where are you at on this? What needs to be done still?

@stof stof commented on the diff Oct 11, 2012

src/Composer/Command/LinkCommand.php
+ <comment>%command.full_name% --remove</comment>
+
+When you request installation of a package, that is not yet in <info>composer.json</info> it will be added as a dependency.
+Also, composer will not change the version of the linked package. You have to do that manually using your vcs.
+EOT
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $package = $input->getArgument('package');
+ if (preg_match('~^\w[\w.-]*/\w[\w.-]*$~i', $package)) {
+ return $this->installFromLocalLink($input, $output, $package);
+
+ } elseif ($package) {
@stof

stof Oct 11, 2012

Contributor

This should simply be if as the previous if returns

@fprochazka

fprochazka Oct 12, 2012

Contributor

You really care about the coding standard, even if it doesn't work?

@ericclemmons

ericclemmons Aug 19, 2013

I was looking for the equivalent of npm link for composer & found this. It made me LOL. That's totally @stof's MO :D

@stof stof commented on the diff Oct 11, 2012

src/Composer/Command/LinkCommand.php
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $package = $input->getArgument('package');
+ if (preg_match('~^\w[\w.-]*/\w[\w.-]*$~i', $package)) {
+ return $this->installFromLocalLink($input, $output, $package);
+
+ } elseif ($package) {
+ $packageDir = realpath($package);
+ if (false === $packageDir || !is_dir($packageDir)) {
+ $output->writeln('<error>Package directory ' . $input->getArgument('package') . ' not found.</error>');
+ return 1;
+ }
+
+ $command = sprintf("%s link", escapeshellarg($_SERVER['PHP_SELF'])); // todo: will this work in phar?
+ $out = NULL;
@stof

stof Oct 11, 2012

Contributor

please lowercase null

@stof stof commented on the diff Oct 11, 2012

src/Composer/Command/LinkCommand.php
+
+ $command = sprintf("%s link", escapeshellarg($_SERVER['PHP_SELF'])); // todo: will this work in phar?
+ $out = NULL;
+ $process = new ProcessExecutor();
+ if (0 !== $process->execute($command, $out, $packageDir)) {
+ $output->writeln('<error>Cannot create link from ' . $packageDir . '.</error>');
+ $output->writeln('<error>' . $process->getErrorOutput() . '</error>');
+ return 1;
+ }
+ $output->writeln('<info>' . trim($out) . '</info>');
+
+ $jsonFile = new JsonFile($packageDir . '/composer.json');
+ $packageConfig = $jsonFile->read();
+ return $this->installFromLocalLink($input, $output, $packageConfig['name']);
+
+ } else {
@stof

stof Oct 11, 2012

Contributor

same here. Using else is not needed as the if returns

@stof stof commented on the diff Oct 11, 2012

src/Composer/Util/Filesystem.php
@@ -27,7 +27,10 @@ public function __construct(ProcessExecutor $executor = null)
public function removeDirectory($directory)
{
- if (!is_dir($directory)) {
+ if (is_link($directory)) {
+ return unlink($directory);
@stof

stof Oct 11, 2012

Contributor

This is not enough on windows.

Btw, this class should probably extend the one from Filesystem component (which supports removing symlinks properly for instance)

Contributor

fprochazka commented Oct 12, 2012

The state didn't changed... It's so long from I've written it, that I don't think I even remember what this does. I'm currently thinking about closing this PR, because somebody else, who understands the "Solver mess" could do it much faster than me.

mneuhaus commented Nov 9, 2012

This seems like it could be a way to solve my situation described in #1299, so +1 from me :)
Any idea/eta when or if this will be finished?

Contributor

fprochazka commented Nov 10, 2012

No idea... it's way too complex for me to solve it on my own.

Contributor

chEbba commented Nov 19, 2012

I had an idea to have a local system repository in #915 this is not a unique idea for package managers / dependency resolvers, ex. maven use such repository.
So i think this ideas can be merged:

  • Local system repository
  • Command to add package to this repository with --link flag
  • After package is installed as a dependency in another project use link command to change copy to symlink
  • Mark packages as "linked" in local repositories (local & devlocal)
  • Is installation type "link" really needed or it can be one of dist/source? And i think dir downloader from #1266 is ok
  • I don't see a pretty way to link package on installation because you need to define somewhere which packages should be linked and which should not . But some --use-links flag may be added for install/update commands.

BTW. I think this feature can be useful, but the most of problems that people want to solve with it can be solved (and should be soved) in another ways.
The main problem in composer-user community is a versioning: ton of packages with dev-stability which depends on dev packages.
More over. Problems with repeated composer update is a worflow problem and not the composer one.

Contributor

Petah commented Mar 26, 2013

Any progress?

glen-84 commented Sep 30, 2013

I also really need this, see my explanation here.

BTW, on Windows you need admin privs in order to create links, how will this be handled?

I hope this gets added soon!

@stof stof commented on the diff Sep 30, 2013

src/Composer/Installer.php
@@ -727,6 +745,17 @@ public function setUpdateWhitelist(array $packages)
}
/**
+ * @param array $packages
+ * @return Installer
+ */
+ public function setPreferLinks(array $packages)
+ {
+ $this->preferLinks = array_flip(array_map('strtolower', $packages));
@stof

stof Sep 30, 2013

Contributor

as all you are doing is iterating, you don't really need to flip it and then ignore values

@stof stof commented on the diff Sep 30, 2013

src/Composer/Repository/LocalLinksRepository.php
+ * @author Filip Procházka <filip.prochazka@kdyby.org>
+ */
+class LocalLinksRepository implements WritableRepositoryInterface
+{
+ private $config;
+ private $io;
+
+ private $linksJson;
+ private $packages;
+
+ public function __construct(Config $config = null, IOInterface $io = null)
+ {
+ $this->config = $config ?: Factory::createConfig();
+ $this->io = $io ?: new NullIO();
+
+ $this->linksJson = new JsonFile($this->config->get('home') . '/links.json');
@stof

stof Sep 30, 2013

Contributor

should links really be shared between projects ?

glen-84 commented Oct 4, 2013

@Seldaek, are you able to help @hosiplan with this?

Owner

Seldaek commented Nov 13, 2013

Able is one thing but I just don't have enough time these days to work on new stuff. I try to keep on top of new PRs/issues but it already takes me too much time.

mellors commented May 4, 2014

👍

Contributor

kaiwa commented Jun 11, 2014

👍

👍

me want 👍
Is there anything we can do to help with this feature ? This would be REALLY useful !

👍

I'll put myself on the list to say I'd love this :) 👍

fprochazka closed this Jan 10, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment