From 816e33cd940844898b04e1c2101d2cfeb3879272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n?= Date: Fri, 7 Feb 2020 12:45:31 -0800 Subject: [PATCH] move ComposerPlugin.php out of src/ (#49) `bin/hh-autoload` tries to parse everything under `src/`, but this file is PHP, not Hack, so it can't be parsed. It was actually parseable until a few days ago, but that was just luck. Also removing `ComposerImporterTest` which relies on that file being parseable. New major release will remove all ComposerImporter stuff, but we want to release at least one more unbroken minor release. --- src/ComposerPlugin.php => ComposerPlugin.php | 0 composer.json | 2 +- tests/ComposerImporterTest.hack | 294 ------------------- 3 files changed, 1 insertion(+), 295 deletions(-) rename src/ComposerPlugin.php => ComposerPlugin.php (100%) delete mode 100644 tests/ComposerImporterTest.hack diff --git a/src/ComposerPlugin.php b/ComposerPlugin.php similarity index 100% rename from src/ComposerPlugin.php rename to ComposerPlugin.php diff --git a/composer.json b/composer.json index df1b2b8..80e1c3c 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ }, "autoload": { "classmap": [ - "src/ComposerPlugin.php" + "ComposerPlugin.php" ] }, "extra": { diff --git a/tests/ComposerImporterTest.hack b/tests/ComposerImporterTest.hack deleted file mode 100644 index d37f17c..0000000 --- a/tests/ComposerImporterTest.hack +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - */ - -namespace Facebook\AutoloadMap; - -use type Facebook\HackTest\DataProvider; -use function Facebook\FBExpect\expect; - -final class ComposerImporterTest extends BaseTest { - <> - public function testRootImportWithScannedFiles(Parser $parser): void { - $root = \realpath(__DIR__.'/../'); - $importer = new ComposerImporter( - $root.'/composer.json', - shape( - 'autoloadFilesBehavior' => AutoloadFilesBehavior::FIND_DEFINITIONS, - 'includeVendor' => false, - 'extraFiles' => ImmVector {}, - 'roots' => ImmVector {$root}, - 'devRoots' => ImmVector {}, - 'parser' => $parser, - 'relativeAutoloadRoot' => true, - 'failureHandler' => null, - 'devFailureHandler' => null, - ), - ); - expect($importer->getFiles())->toBeEmpty(); - } - - <> - public function testRootImportWithRequiredFiles(Parser $parser): void { - $root = \realpath(__DIR__.'/../'); - $importer = new ComposerImporter( - $root.'/composer.json', - shape( - 'autoloadFilesBehavior' => AutoloadFilesBehavior::EXEC_FILES, - 'includeVendor' => false, - 'extraFiles' => ImmVector {}, - 'roots' => ImmVector {$root}, - 'devRoots' => ImmVector {}, - 'parser' => $parser, - 'relativeAutoloadRoot' => true, - 'failureHandler' => null, - 'devFailureHandler' => null, - ), - ); - - $map = $importer->getAutoloadMap(); - expect($map['type'])->toBeEmpty(); - expect($importer->getAutoloadMap()['class'])->toContainKey( - "facebook\\autoloadmap\\composerplugin", - ); - } - - <> - public function testPSR4Import(Parser $parser): void { - $root = \realpath(__DIR__.'/fixtures/psr-4'); - $composer = $root.'/composer.json'; - expect(\file_exists($composer))->toBeTrue(); - - $composer_config = \json_decode( - \file_get_contents($composer), - /* as array = */ true, - ); - - $importer = new ComposerImporter( - $composer, - shape( - 'autoloadFilesBehavior' => AutoloadFilesBehavior::EXEC_FILES, - 'includeVendor' => false, - 'extraFiles' => ImmVector {}, - 'roots' => ImmVector {$root}, - 'devRoots' => ImmVector {}, - 'parser' => $parser, - 'relativeAutoloadRoot' => true, - 'failureHandler' => null, - 'devFailureHandler' => null, - ), - ); - - expect( - idx($importer->getAutoloadMap()['class'], 'psr4\testwithslash\psr4test'), - )->toBeSame($root.'/src-with-slash/PSR4Test.php'); - - expect(idx($importer->getAutoloadMap()['class'], 'psr4\test\hhpsr4test')) - ->toBeSame($root.'/src/HHPSR4Test.hh'); - } - - <> - public function testPSR4ImportNoTrailingSlash(Parser $parser): void { - $root = \realpath(__DIR__.'/fixtures/psr-4'); - $composer = $root.'/composer.json'; - expect(\file_exists($composer))->toBeTrue(); - - $composer_config = \json_decode( - \file_get_contents($composer), - /* as array = */ true, - ); - expect($composer_config['autoload']['psr-4'])->toNotBeEmpty(); - - $importer = new ComposerImporter( - $composer, - shape( - 'autoloadFilesBehavior' => AutoloadFilesBehavior::EXEC_FILES, - 'includeVendor' => false, - 'extraFiles' => ImmVector {}, - 'roots' => ImmVector {$root}, - 'devRoots' => ImmVector {}, - 'parser' => $parser, - 'relativeAutoloadRoot' => true, - 'failureHandler' => null, - 'devFailureHandler' => null, - ), - ); - - expect(idx($importer->getAutoloadMap()['class'], 'psr4\test\psr4test')) - ->toBeSame($root.'/src/PSR4Test.php'); - } - - <> - public function testPSR4ImportWithoutPrefix(Parser $parser): void { - $root = \realpath(__DIR__.'/fixtures/psr-4'); - $composer = $root.'/composer.json'; - expect(\file_exists($composer))->toBeTrue(); - - $composer_config = \json_decode( - \file_get_contents($composer), - /* as array = */ true, - ); - expect($composer_config['autoload']['psr-4'])->toNotBeEmpty(); - - $importer = new ComposerImporter( - $composer, - shape( - 'autoloadFilesBehavior' => AutoloadFilesBehavior::EXEC_FILES, - 'includeVendor' => false, - 'extraFiles' => ImmVector {}, - 'roots' => ImmVector {$root}, - 'devRoots' => ImmVector {}, - 'parser' => $parser, - 'relativeAutoloadRoot' => true, - 'failureHandler' => null, - 'devFailureHandler' => null, - ), - ); - - expect( - idx( - $importer->getAutoloadMap()['class'], - 'psr4\testwithoutprefix\psr4test', - ), - )->toBeSame( - $root.'/src-without-prefix/PSR4/TestWithoutPrefix/PSR4Test.php', - ); - } - - <> - public function testPSR0Import(Parser $parser): void { - $root = \realpath(__DIR__.'/fixtures/psr-0'); - $composer = $root.'/composer.json'; - expect(\file_exists($composer))->toBeTrue(); - - $composer_config = \json_decode( - \file_get_contents($composer), - /* as array = */ true, - ); - - $importer = new ComposerImporter( - $composer, - shape( - 'autoloadFilesBehavior' => AutoloadFilesBehavior::EXEC_FILES, - 'includeVendor' => false, - 'extraFiles' => ImmVector {}, - 'roots' => ImmVector {$root}, - 'devRoots' => ImmVector {}, - 'parser' => $parser, - 'relativeAutoloadRoot' => true, - 'failureHandler' => null, - 'devFailureHandler' => null, - ), - ); - expect(idx($importer->getAutoloadMap()['class'], 'psr0testwithslash')) - ->toBeSame($root.'/src-with-slash/PSR0TestWithSlash.php'); - } - - <> - public function testPSR0ImportNoTrailingSlash(Parser $parser): void { - $root = \realpath(__DIR__.'/fixtures/psr-0'); - $composer = $root.'/composer.json'; - expect(\file_exists($composer))->toBeTrue(); - - $composer_config = \json_decode( - \file_get_contents($composer), - /* as array = */ true, - ); - expect($composer_config['autoload']['psr-0'])->toNotBeEmpty(); - - $importer = new ComposerImporter( - $composer, - shape( - 'autoloadFilesBehavior' => AutoloadFilesBehavior::EXEC_FILES, - 'includeVendor' => false, - 'extraFiles' => ImmVector {}, - 'roots' => ImmVector {$root}, - 'devRoots' => ImmVector {}, - 'parser' => $parser, - 'relativeAutoloadRoot' => true, - 'failureHandler' => null, - 'devFailureHandler' => null, - ), - ); - - expect(idx($importer->getAutoloadMap()['class'], 'psr0test'))->toBeSame( - $root.'/src/PSR0Test.php', - ); - - expect(idx($importer->getAutoloadMap()['class'], 'psr0testinhh'))->toBeSame( - $root.'/src/PSR0TestInHH.hh', - ); - } - - <> - public function testPSR0ImportUnderscores(Parser $parser): void { - $root = \realpath(__DIR__.'/fixtures/psr-0'); - $composer = $root.'/composer.json'; - expect(\file_exists($composer))->toBeTrue(); - - $composer_config = \json_decode( - \file_get_contents($composer), - /* as array = */ true, - ); - - $importer = new ComposerImporter( - $composer, - shape( - 'autoloadFilesBehavior' => AutoloadFilesBehavior::EXEC_FILES, - 'includeVendor' => false, - 'extraFiles' => ImmVector {}, - 'roots' => ImmVector {$root}, - 'devRoots' => ImmVector {}, - 'parser' => $parser, - 'relativeAutoloadRoot' => true, - 'failureHandler' => null, - 'devFailureHandler' => null, - ), - ); - - expect( - idx( - $importer->getAutoloadMap()['class'], - 'psr0_test_with_underscores\\foo_bar', - ), - )->toBeSame( - $root.'/src-with-underscores/PSR0_Test_With_Underscores/Foo/Bar.php', - ); - } - - <> - public function testPSR0ImportWithoutPrefix(Parser $parser): void { - $root = \realpath(__DIR__.'/fixtures/psr-0'); - $composer = $root.'/composer.json'; - expect(\file_exists($composer))->toBeTrue(); - - $composer_config = \json_decode( - \file_get_contents($composer), - /* as array = */ true, - ); - expect($composer_config['autoload']['psr-0'])->toNotBeEmpty(); - - $importer = new ComposerImporter( - $composer, - shape( - 'autoloadFilesBehavior' => AutoloadFilesBehavior::EXEC_FILES, - 'includeVendor' => false, - 'extraFiles' => ImmVector {}, - 'roots' => ImmVector {$root}, - 'devRoots' => ImmVector {}, - 'parser' => $parser, - 'relativeAutoloadRoot' => true, - 'failureHandler' => null, - 'devFailureHandler' => null, - ), - ); - - expect(idx($importer->getAutoloadMap()['class'], 'psr0testwithoutprefix')) - ->toBeSame($root.'/src-without-prefix/PSR0TestWithoutPrefix.php'); - } -}