diff --git a/composer.json b/composer.json
index cac758e28a..34ae179c4f 100644
--- a/composer.json
+++ b/composer.json
@@ -50,8 +50,6 @@
     "scripts": {
         "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
         "post-autoload-dump": "Drupal\\Core\\Composer\\Composer::ensureHtaccess",
-        "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
-        "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
         "drupal-phpunit-upgrade-check": "Drupal\\Core\\Composer\\Composer::upgradePHPUnit",
         "drupal-phpunit-upgrade": "@composer update phpunit/phpunit phpspec/prophecy symfony/yaml --with-dependencies --no-progress",
         "phpcs": "phpcs --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --",
diff --git a/composer.lock b/composer.lock
index 8d08c52617..70db1da84a 100644
--- a/composer.lock
+++ b/composer.lock
@@ -1401,16 +1401,16 @@
         },
         {
             "name": "psr/log",
-            "version": "1.0.2",
+            "version": "1.1.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/php-fig/log.git",
-                "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
+                "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
-                "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
+                "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
+                "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
                 "shasum": ""
             },
             "require": {
@@ -1444,7 +1444,7 @@
                 "psr",
                 "psr-3"
             ],
-            "time": "2016-10-10T12:19:37+00:00"
+            "time": "2018-11-20T15:27:04+00:00"
         },
         {
             "name": "stack/builder",
@@ -3321,6 +3321,246 @@
             ],
             "time": "2018-01-07T19:17:08+00:00"
         },
+        {
+            "name": "composer/ca-bundle",
+            "version": "1.1.4",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/composer/ca-bundle.git",
+                "reference": "558f321c52faeb4828c03e7dc0cfe39a09e09a2d"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/composer/ca-bundle/zipball/558f321c52faeb4828c03e7dc0cfe39a09e09a2d",
+                "reference": "558f321c52faeb4828c03e7dc0cfe39a09e09a2d",
+                "shasum": ""
+            },
+            "require": {
+                "ext-openssl": "*",
+                "ext-pcre": "*",
+                "php": "^5.3.2 || ^7.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5",
+                "psr/log": "^1.0",
+                "symfony/process": "^2.5 || ^3.0 || ^4.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Composer\\CaBundle\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Jordi Boggiano",
+                    "email": "j.boggiano@seld.be",
+                    "homepage": "http://seld.be"
+                }
+            ],
+            "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.",
+            "keywords": [
+                "cabundle",
+                "cacert",
+                "certificate",
+                "ssl",
+                "tls"
+            ],
+            "time": "2019-01-28T09:30:10+00:00"
+        },
+        {
+            "name": "composer/composer",
+            "version": "1.8.5",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/composer/composer.git",
+                "reference": "949b116f9e7d98d8d276594fed74b580d125c0e6"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/composer/composer/zipball/949b116f9e7d98d8d276594fed74b580d125c0e6",
+                "reference": "949b116f9e7d98d8d276594fed74b580d125c0e6",
+                "shasum": ""
+            },
+            "require": {
+                "composer/ca-bundle": "^1.0",
+                "composer/semver": "^1.0",
+                "composer/spdx-licenses": "^1.2",
+                "composer/xdebug-handler": "^1.1",
+                "justinrainbow/json-schema": "^3.0 || ^4.0 || ^5.0",
+                "php": "^5.3.2 || ^7.0",
+                "psr/log": "^1.0",
+                "seld/jsonlint": "^1.4",
+                "seld/phar-utils": "^1.0",
+                "symfony/console": "^2.7 || ^3.0 || ^4.0",
+                "symfony/filesystem": "^2.7 || ^3.0 || ^4.0",
+                "symfony/finder": "^2.7 || ^3.0 || ^4.0",
+                "symfony/process": "^2.7 || ^3.0 || ^4.0"
+            },
+            "conflict": {
+                "symfony/console": "2.8.38"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.8.35 || ^5.7",
+                "phpunit/phpunit-mock-objects": "^2.3 || ^3.0"
+            },
+            "suggest": {
+                "ext-openssl": "Enabling the openssl extension allows you to access https URLs for repositories and packages",
+                "ext-zip": "Enabling the zip extension allows you to unzip archives",
+                "ext-zlib": "Allow gzip compression of HTTP requests"
+            },
+            "bin": [
+                "bin/composer"
+            ],
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.8-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Composer\\": "src/Composer"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Nils Adermann",
+                    "email": "naderman@naderman.de",
+                    "homepage": "http://www.naderman.de"
+                },
+                {
+                    "name": "Jordi Boggiano",
+                    "email": "j.boggiano@seld.be",
+                    "homepage": "http://seld.be"
+                }
+            ],
+            "description": "Composer helps you declare, manage and install dependencies of PHP projects, ensuring you have the right stack everywhere.",
+            "homepage": "https://getcomposer.org/",
+            "keywords": [
+                "autoload",
+                "dependency",
+                "package"
+            ],
+            "time": "2019-04-09T15:46:48+00:00"
+        },
+        {
+            "name": "composer/spdx-licenses",
+            "version": "1.5.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/composer/spdx-licenses.git",
+                "reference": "a1aa51cf3ab838b83b0867b14e56fc20fbd55b3d"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/composer/spdx-licenses/zipball/a1aa51cf3ab838b83b0867b14e56fc20fbd55b3d",
+                "reference": "a1aa51cf3ab838b83b0867b14e56fc20fbd55b3d",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^5.3.2 || ^7.0 || ^8.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.8.35 || ^5.7 || 6.5 - 7"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Composer\\Spdx\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Nils Adermann",
+                    "email": "naderman@naderman.de",
+                    "homepage": "http://www.naderman.de"
+                },
+                {
+                    "name": "Jordi Boggiano",
+                    "email": "j.boggiano@seld.be",
+                    "homepage": "http://seld.be"
+                },
+                {
+                    "name": "Rob Bast",
+                    "email": "rob.bast@gmail.com",
+                    "homepage": "http://robbast.nl"
+                }
+            ],
+            "description": "SPDX licenses list and validation library.",
+            "keywords": [
+                "license",
+                "spdx",
+                "validator"
+            ],
+            "time": "2019-03-26T10:23:26+00:00"
+        },
+        {
+            "name": "composer/xdebug-handler",
+            "version": "1.3.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/composer/xdebug-handler.git",
+                "reference": "d17708133b6c276d6e42ef887a877866b909d892"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/d17708133b6c276d6e42ef887a877866b909d892",
+                "reference": "d17708133b6c276d6e42ef887a877866b909d892",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^5.3.2 || ^7.0",
+                "psr/log": "^1.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Composer\\XdebugHandler\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "John Stevenson",
+                    "email": "john-stevenson@blueyonder.co.uk"
+                }
+            ],
+            "description": "Restarts a process without xdebug.",
+            "keywords": [
+                "Xdebug",
+                "performance"
+            ],
+            "time": "2019-01-28T20:25:53+00:00"
+        },
         {
             "name": "doctrine/instantiator",
             "version": "1.0.5",
@@ -3754,12 +3994,12 @@
             "version": "v1.6.5",
             "source": {
                 "type": "git",
-                "url": "https://github.com/mikey179/vfsStream.git",
+                "url": "https://github.com/bovigo/vfsStream.git",
                 "reference": "d5fec95f541d4d71c4823bb5e30cf9b9e5b96145"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/mikey179/vfsStream/zipball/d5fec95f541d4d71c4823bb5e30cf9b9e5b96145",
+                "url": "https://api.github.com/repos/bovigo/vfsStream/zipball/d5fec95f541d4d71c4823bb5e30cf9b9e5b96145",
                 "reference": "d5fec95f541d4d71c4823bb5e30cf9b9e5b96145",
                 "shasum": ""
             },
@@ -4656,6 +4896,99 @@
             "homepage": "https://github.com/sebastianbergmann/version",
             "time": "2015-06-21T13:59:46+00:00"
         },
+        {
+            "name": "seld/jsonlint",
+            "version": "1.7.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/Seldaek/jsonlint.git",
+                "reference": "d15f59a67ff805a44c50ea0516d2341740f81a38"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/d15f59a67ff805a44c50ea0516d2341740f81a38",
+                "reference": "d15f59a67ff805a44c50ea0516d2341740f81a38",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^5.3 || ^7.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0"
+            },
+            "bin": [
+                "bin/jsonlint"
+            ],
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Seld\\JsonLint\\": "src/Seld/JsonLint/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Jordi Boggiano",
+                    "email": "j.boggiano@seld.be",
+                    "homepage": "http://seld.be"
+                }
+            ],
+            "description": "JSON Linter",
+            "keywords": [
+                "json",
+                "linter",
+                "parser",
+                "validator"
+            ],
+            "time": "2018-01-24T12:46:19+00:00"
+        },
+        {
+            "name": "seld/phar-utils",
+            "version": "1.0.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/Seldaek/phar-utils.git",
+                "reference": "7009b5139491975ef6486545a39f3e6dad5ac30a"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/Seldaek/phar-utils/zipball/7009b5139491975ef6486545a39f3e6dad5ac30a",
+                "reference": "7009b5139491975ef6486545a39f3e6dad5ac30a",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.3"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Seld\\PharUtils\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Jordi Boggiano",
+                    "email": "j.boggiano@seld.be"
+                }
+            ],
+            "description": "PHAR file format utilities, for when PHP phars you up",
+            "keywords": [
+                "phra"
+            ],
+            "time": "2015-10-13T18:44:15+00:00"
+        },
         {
             "name": "squizlabs/php_codesniffer",
             "version": "3.4.1",
@@ -4874,6 +5207,105 @@
             "homepage": "https://symfony.com",
             "time": "2019-02-23T15:06:07+00:00"
         },
+        {
+            "name": "symfony/filesystem",
+            "version": "v4.2.5",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/symfony/filesystem.git",
+                "reference": "e16b9e471703b2c60b95f14d31c1239f68f11601"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/symfony/filesystem/zipball/e16b9e471703b2c60b95f14d31c1239f68f11601",
+                "reference": "e16b9e471703b2c60b95f14d31c1239f68f11601",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^7.1.3",
+                "symfony/polyfill-ctype": "~1.8"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "4.2-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Symfony\\Component\\Filesystem\\": ""
+                },
+                "exclude-from-classmap": [
+                    "/Tests/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Fabien Potencier",
+                    "email": "fabien@symfony.com"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "https://symfony.com/contributors"
+                }
+            ],
+            "description": "Symfony Filesystem Component",
+            "homepage": "https://symfony.com",
+            "time": "2019-02-07T11:40:08+00:00"
+        },
+        {
+            "name": "symfony/finder",
+            "version": "v4.2.5",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/symfony/finder.git",
+                "reference": "267b7002c1b70ea80db0833c3afe05f0fbde580a"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/symfony/finder/zipball/267b7002c1b70ea80db0833c3afe05f0fbde580a",
+                "reference": "267b7002c1b70ea80db0833c3afe05f0fbde580a",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^7.1.3"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "4.2-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Symfony\\Component\\Finder\\": ""
+                },
+                "exclude-from-classmap": [
+                    "/Tests/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Fabien Potencier",
+                    "email": "fabien@symfony.com"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "https://symfony.com/contributors"
+                }
+            ],
+            "description": "Symfony Finder Component",
+            "homepage": "https://symfony.com",
+            "time": "2019-02-23T15:42:05+00:00"
+        },
         {
             "name": "symfony/phpunit-bridge",
             "version": "v3.4.24",
@@ -4962,7 +5394,8 @@
         "ext-spl": "*",
         "ext-tokenizer": "*",
         "ext-xml": "*",
-        "php": "^5.5.9|>=7.0.8"
+        "php": "^5.5.9|>=7.0.8",
+        "composer-plugin-api": "^1.0.0"
     },
     "platform-dev": []
 }
diff --git a/core/composer.json b/core/composer.json
index 2cd89a7b82..5b206475f2 100644
--- a/core/composer.json
+++ b/core/composer.json
@@ -198,6 +198,7 @@
                 "core/lib/Drupal/Component/Plugin/composer.json",
                 "core/lib/Drupal/Component/ProxyBuilder/composer.json",
                 "core/lib/Drupal/Component/Render/composer.json",
+                "core/lib/Drupal/Component/Scaffold/composer.json",
                 "core/lib/Drupal/Component/Serialization/composer.json",
                 "core/lib/Drupal/Component/Transliteration/composer.json",
                 "core/lib/Drupal/Component/Utility/composer.json",
diff --git a/core/lib/Drupal/Component/Scaffold/CommandProvider.php b/core/lib/Drupal/Component/Scaffold/CommandProvider.php
new file mode 100644
index 0000000000..d78b486a8c
--- /dev/null
+++ b/core/lib/Drupal/Component/Scaffold/CommandProvider.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Drupal\Component\Scaffold;
+
+use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
+
+/**
+ * List of all commands provided by this package.
+ */
+class CommandProvider implements CommandProviderCapability {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCommands() {
+    return [
+      new ComposerScaffoldCommand(),
+    ];
+  }
+
+}
diff --git a/core/lib/Drupal/Component/Scaffold/ComposerScaffoldCommand.php b/core/lib/Drupal/Component/Scaffold/ComposerScaffoldCommand.php
new file mode 100644
index 0000000000..f5b792ad1c
--- /dev/null
+++ b/core/lib/Drupal/Component/Scaffold/ComposerScaffoldCommand.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Drupal\Component\Scaffold;
+
+use Composer\Command\BaseCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * The "composer:scaffold" command class.
+ *
+ * Composer scaffold files and generates the autoload.php file.
+ */
+class ComposerScaffoldCommand extends BaseCommand {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function configure() {
+    parent::configure();
+    $this
+      ->setName('composer:scaffold')
+      ->setDescription('Update the Composer scaffold files.');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function execute(InputInterface $input, OutputInterface $output) {
+    $handler = new Handler($this->getComposer(), $this->getIO());
+    $handler->scaffold();
+    // Generate the autoload.php file after generating the scaffold files.
+    $handler->generateAutoload();
+  }
+
+}
diff --git a/core/lib/Drupal/Component/Scaffold/Handler.php b/core/lib/Drupal/Component/Scaffold/Handler.php
new file mode 100644
index 0000000000..b05380dc3b
--- /dev/null
+++ b/core/lib/Drupal/Component/Scaffold/Handler.php
@@ -0,0 +1,591 @@
+<?php
+
+declare(strict_types = 1);
+
+namespace Drupal\Component\Scaffold;
+
+use Composer\Package\PackageInterface;
+use Composer\Script\Event;
+use Composer\Composer;
+use Composer\EventDispatcher\EventDispatcher;
+use Composer\IO\IOInterface;
+use Composer\Util\Filesystem;
+use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
+
+/**
+ * Core class of the plugin, contains all logic which files should be fetched.
+ */
+class Handler {
+
+  const PRE_COMPOSER_SCAFFOLD_CMD = 'pre-composer-scaffold-cmd';
+  const POST_COMPOSER_SCAFFOLD_CMD = 'post-composer-scaffold-cmd';
+
+  /**
+   * The Composer service.
+   *
+   * @var \Composer\Composer
+   */
+  protected $composer;
+
+  /**
+   * Composer's I/O service.
+   *
+   * @var \Composer\IO\IOInterface
+   */
+  protected $io;
+
+  /**
+   * An array of allowed packages keyed by package name.
+   *
+   * @var \Composer\Package\Package[]
+   */
+  protected $allowedPackages;
+
+  /**
+   * Handler constructor.
+   *
+   * @param \Composer\Composer $composer
+   *   The Composer service.
+   * @param \Composer\IO\IOInterface $io
+   *   The Composer I/O service.
+   */
+  public function __construct(Composer $composer, IOInterface $io) {
+    $this->composer = $composer;
+    $this->io = $io;
+  }
+
+  /**
+   * Post install command event to execute the scaffolding.
+   *
+   * @param \Composer\Script\Event $event
+   *   The Composer event.
+   */
+  public function onPostCmdEvent(Event $event) {
+    $this->scaffold();
+  }
+
+  /**
+   * Gets the array of file mappings provided by a given package.
+   *
+   * @param \Composer\Package\PackageInterface $package
+   *   The Composer package from which to get the file mappings.
+   *
+   * @return array
+   *   An associative array of file mappings, keyed by relative source file
+   *   path. Items that are specified as 'false' are converted to an empty string.
+   *   For example:
+   *   [
+   *     'path/to/source/file' => 'path/to/destination',
+   *     'path/to/source/file' => '',
+   *   ]
+   */
+  public function getPackageFileMappings(PackageInterface $package) : array {
+    $package_extra = $package->getExtra();
+
+    if (isset($package_extra['composer-scaffold']['file-mapping'])) {
+      $package_file_mappings = $package_extra['composer-scaffold']['file-mapping'];
+      return $this->validatePackageFileMappings($package_file_mappings);
+    }
+    else {
+      $this->io->writeError("The allowed package {$package->getName()} does not provide a file mapping for Composer Scaffold.");
+      return [];
+    }
+  }
+
+  /**
+   * Validate the package file mappings.
+   *
+   * Throw an exception if there are invalid values, and normalize the value otherwise.
+   *
+   * @param string[] $package_file_mappings
+   *   An array of destination => source scaffold file mappings.
+   *
+   * @return string[]
+   *   The provided $package_file_mappings with its array values normalized.
+   */
+  protected function validatePackageFileMappings(array $package_file_mappings) {
+    $result = [];
+
+    foreach ($package_file_mappings as $key => $value) {
+      $result[$key] = $this->normalizeMapping($value);
+    }
+
+    return $result;
+  }
+
+  /**
+   * Normalize a value from the package file mappings.
+   *
+   * Currently, the valid values are:
+   *   (bool) FALSE: Remove the scaffold file rather than scaffold it.
+   *   'relative/path': Path to the file to place, relative to the package root.
+   *
+   * In the future, we want to normalize to:
+   *   [
+   *      'path' => 'relative/path',
+   *      'mode' => 'copy/prepend/append' // n.b. "copy" could make a symlink
+   *   ]
+   *
+   * @param string|bool $value
+   *   The value to normalize.
+   *
+   * @return string
+   *   The normalized value.
+   */
+  protected function normalizeMapping($value) {
+    if (is_bool($value)) {
+      if (!$value) {
+        return '';
+      }
+      throw new \Exception("File mapping $key cannot be given the value 'true'.");
+    }
+    if (empty($value)) {
+      throw new \Exception("File mapping $key cannot be an empty string.");
+    }
+    return $value;
+  }
+
+  /**
+   * Copies all scaffold files from source to destination.
+   */
+  public function scaffold() {
+    // Call any pre-scaffold scripts that may be defined.
+    $dispatcher = new EventDispatcher($this->composer, $this->io);
+    $dispatcher->dispatch(self::PRE_COMPOSER_SCAFFOLD_CMD);
+
+    $interpolator = $this->getLocationReplacements();
+
+    $this->allowedPackages = $this->getAllowedPackages();
+    $file_mappings = $this->getFileMappingsFromPackages($this->allowedPackages);
+
+    list($list_of_scaffold_files, $resolved_file_mappings) = $this->collateScaffoldFiles($file_mappings, $interpolator);
+
+    $this->scaffoldPackageFiles($list_of_scaffold_files, $resolved_file_mappings);
+
+    // Generate an autoload file in the document root that includes
+    // the autoload.php file in the vendor directory, wherever that is.
+    // Drupal requires this in order to easily locate relocated vendor dirs.
+    $this->generateAutoload();
+
+    // Call post-scaffold scripts.
+    $dispatcher->dispatch(self::POST_COMPOSER_SCAFFOLD_CMD);
+  }
+
+  /**
+   * Generate the autoload file at the project root.
+   *
+   * Include the autoload file that Composer generated.
+   */
+  public function generateAutoload() {
+    $vendorPath = $this->getVendorPath();
+    $webroot = $this->getWebRoot();
+
+    // Calculate the relative path from the webroot (location of the project
+    // autoload.php) to the vendor directory.
+    $fs = new SymfonyFilesystem();
+    $relativeVendorPath = $fs->makePathRelative($vendorPath, realpath($webroot));
+
+    $fs->dumpFile($webroot . "/autoload.php", $this->autoLoadContents($relativeVendorPath));
+  }
+
+  /**
+   * Build the contents of the autoload file.
+   *
+   * @return string
+   *   Return the contents for the autoload.php.
+   */
+  protected function autoLoadContents(string $relativeVendorPath) : string {
+    $relativeVendorPath = rtrim($relativeVendorPath, '/');
+
+    return <<<EOF
+<?php
+
+/**
+ * @file
+ * Includes the autoloader created by Composer.
+ *
+ * This file was generated by composer-scaffold.
+ *.
+ * @see composer.json
+ * @see index.php
+ * @see core/install.php
+ * @see core/rebuild.php
+ * @see core/modules/statistics/statistics.php
+ */
+
+return require __DIR__ . '/$relativeVendorPath/autoload.php';
+
+EOF;
+  }
+
+  /**
+   * Get the path to the 'vendor' directory.
+   *
+   * @return string
+   *   The file path of the vendor directory.
+   */
+  public function getVendorPath() {
+    $vendorDir = $this->composer->getConfig()->get('vendor-dir');
+    $filesystem = new Filesystem();
+    $filesystem->ensureDirectoryExists($vendorDir);
+    return $filesystem->normalizePath(realpath($vendorDir));
+  }
+
+  /**
+   * Retrieve the path to the web root.
+   *
+   * @return string
+   *   The file path of the web root.
+   *
+   * @throws \Exception
+   */
+  public function getWebRoot() {
+    $options = $this->getOptions();
+    // @todo Allow packages to set web root location?
+    if (empty($options['locations']['web-root'])) {
+      throw new \Exception("The extra.composer-scaffold.location.web-root is not set in composer.json.");
+    }
+    return $options['locations']['web-root'];
+  }
+
+  /**
+   * Retrieve a package from the current composer process.
+   *
+   * @param string $name
+   *   Name of the package to get from the current composer installation.
+   *
+   * @return \Composer\Package\PackageInterface|null
+   *   The Composer package.
+   */
+  protected function getPackage(string $name) {
+    $package = $this->composer->getRepositoryManager()->getLocalRepository()->findPackage($name, '*');
+    if (is_null($package)) {
+      $this->io->write("<comment>Composer Scaffold could not find installed package `$name`.</comment>");
+    }
+
+    return $package;
+  }
+
+  /**
+   * Retrieve options from optional "extra" configuration.
+   *
+   * @return array
+   *   The composer-scaffold configuration array.
+   */
+  protected function getOptions() : array {
+    $extra = $this->composer->getPackage()->getExtra() + ['composer-scaffold' => []];
+
+    return $extra['composer-scaffold'] + [
+      "allowed-packages" => [],
+      "locations" => [],
+      "symlink" => FALSE,
+      "file-mapping" => [],
+    ];
+  }
+
+  /**
+   * Merges arrays recursively while preserving.
+   *
+   * @param array $array1
+   *   The first array.
+   * @param array $array2
+   *   The second array.
+   *
+   * @return array
+   *   The merged array.
+   *
+   * @see http://php.net/manual/en/function.array-merge-recursive.php#92195
+   * @todo: Remove
+   */
+  public static function arrayMergeRecursiveDistinct(array &$array1, array &$array2) : array {
+    $merged = $array1;
+    foreach ($array2 as $key => &$value) {
+      if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
+        $merged[$key] = self::arrayMergeRecursiveDistinct($merged[$key], $value);
+      }
+      else {
+        $merged[$key] = $value;
+      }
+    }
+    return $merged;
+  }
+
+  /**
+   * GetLocationReplacements creates an interpolator for the 'locations' element.
+   *
+   * The interpolator returned will replace a path string with the tokens
+   * defined in the 'locations' element.
+   *
+   * @return Interpolator
+   *   Object that will do replacements in a string using tokens in 'locations' element.
+   */
+  public function getLocationReplacements() {
+    $interpolator = new Interpolator();
+
+    $fs = new Filesystem();
+    $options = $this->getOptions();
+    $locations = $options['locations'] + ['web_root' => './'];
+    $locations = array_map(
+      function ($location) use ($fs) {
+        $fs->ensureDirectoryExists($location);
+        $location = realpath($location);
+        return $location;
+      },
+      $locations
+    );
+
+    return $interpolator->setData($locations);
+  }
+
+  /**
+   * Copy all files, as defined by $file_mappings.
+   *
+   * @param array $file_mappings
+   *   An multidimensional array of file mappings, as returned by
+   *   self::getFileMappingsFromPackages().
+   * @param Interpolator $interpolator
+   *   An object with the location mappings (e.g. [web-root]).
+   *
+   * @return array
+   *   - $list_of_scaffold_files: a list of all of the files to scaffold
+   *   - $resolved_file_mappings original $file_mappings by package, with
+   *     values converted to ScaffoldFileInfo objects
+   */
+  protected function collateScaffoldFiles(array $file_mappings, Interpolator $interpolator) {
+    $resolved_file_mappings = [];
+    $resolved_package_file_list = [];
+    foreach ($file_mappings as $package_name => $package_file_mappings) {
+      if (!$this->getAllowedPackage($package_name)) {
+        // It should no longer be possible to get here.
+        $this->io->writeError("The package <comment>$package_name</comment> is listed in file-mappings, but not an allowed package. Skipping.");
+        continue;
+      }
+      $package_path = $this->getPackagePath($package_name);
+      foreach ($package_file_mappings as $destination_rel_path => $source_rel_path) {
+        $src_full_path = $this->resolveSourceLocation($package_name, $package_path, $source_rel_path);
+        $dest_full_path = $interpolator->interpolate($destination_rel_path);
+
+        $scaffold_file = (new ScaffoldFileInfo())
+          ->setPackageName($package_name)
+          ->setDestinationRelativePath($destination_rel_path)
+          ->setSourceRelativePath($source_rel_path)
+          ->setDestinationFullPath($dest_full_path)
+          ->setSourceFullPath($src_full_path);
+
+        $list_of_scaffold_files[$destination_rel_path] = $scaffold_file;
+        $resolved_file_mappings[$package_name][$destination_rel_path] = $scaffold_file;
+      }
+    }
+    return [$list_of_scaffold_files, $resolved_file_mappings];
+  }
+
+  /**
+   * Gets an allowed package from $this->allowedPackages array.
+   *
+   * @param string $package_name
+   *   The Composer package name. E.g., drupal/core.
+   *
+   * @return \Composer\Package\Package|null
+   *   The allowed Composer package, if it exists.
+   */
+  protected function getAllowedPackage($package_name) {
+    if (array_key_exists($package_name, $this->allowedPackages)) {
+      return $this->allowedPackages[$package_name];
+    }
+
+    return NULL;
+  }
+
+  /**
+   * Gets a consolidated list of file mappings from all allowed packages.
+   *
+   * @param \Composer\Package\Package[] $allowed_packages
+   *   A multidimensional array of file mappings, as returned by
+   *   self::getAllowedPackages().
+   *
+   * @return array
+   *   An multidimensional array of file mappings, which looks like this:
+   *   [
+   *     'drupal/core' => [
+   *       'path/to/source/file' => 'path/to/destination',
+   *       'path/to/source/file' => false,
+   *     ],
+   *     'some/package' => [
+   *       'path/to/source/file' => 'path/to/destination',
+   *     ],
+   *   ]
+   */
+  protected function getFileMappingsFromPackages(array $allowed_packages) : array {
+    $file_mappings = [];
+    foreach ($allowed_packages as $name => $package) {
+      $package_file_mappings = $this->getPackageFileMappings($package);
+      $file_mappings[$name] = $package_file_mappings;
+    }
+    return $file_mappings;
+  }
+
+  /**
+   * Gets a list of all packages that are allowed to copy scaffold files.
+   *
+   * Configuration for packages specified later will override configuration
+   * specified by packages listed earlier. In other words, the last listed
+   * package has the highest priority. The root package will always be returned
+   * at the end of the list.
+   *
+   * @return \Composer\Package\PackageInterface[]
+   *   An array of allowed Composer packages.
+   */
+  protected function getAllowedPackages(): array {
+    $root_package = $this->composer->getPackage();
+    $options = $this->getOptions() + [
+      'allowed-packages' => [],
+      'file-mapping' => [],
+    ];
+    $allowed_packages = [];
+    foreach ($options['allowed-packages'] as $name) {
+      if ($root_package->getName() === $name) {
+        continue;
+      }
+      $package = $this->getPackage($name);
+      if ($package instanceof PackageInterface) {
+        $allowed_packages[$name] = $package;
+      }
+    }
+
+    // Add root package at the end so that it overrides all the preceding
+    // package.
+    $allowed_packages[$root_package->getName()] = $root_package;
+
+    return $allowed_packages;
+  }
+
+  /**
+   * Gets the file path of a package.
+   *
+   * @param string $package_name
+   *   The package name.
+   *
+   * @return string
+   *   The file path.
+   */
+  protected function getPackagePath(string $package_name) : string {
+    if ($package_name == $this->composer->getPackage()->getName()) {
+      // This will respect the --working-dir option if Composer is invoked with
+      // it. There is no API or method to determine the filesystem path of
+      // a package's composer.json file.
+      return getcwd();
+    }
+    else {
+      return $this->composer->getInstallationManager()->getInstallPath($this->getPackage($package_name));
+    }
+  }
+
+  /**
+   * ResolveSourceLocation converts the relative source path into an absolute path.
+   *
+   * The path returned will be relative to the package installation location.
+   *
+   * @param string $package_name
+   *   Name of the package containing the source file.
+   * @param string $package_path
+   *   Path to the root of the named package.
+   * @param string $source
+   *   Source location provided as a relative path.
+   *
+   * @return string
+   *   Source location converted to an absolute path, or empty if removed.
+   */
+  public function resolveSourceLocation(string $package_name, string $package_path, string $source) {
+    if (empty($source)) {
+      return '';
+    }
+
+    $source_path = $package_path . '/' . $source;
+
+    if (!file_exists($source_path)) {
+      throw new \Exception("Could not find source file <comment>$source_path</comment> for package <comment>$package_name</comment>\n");
+    }
+    if (is_dir($source_path)) {
+      throw new \Exception("<comment>$source_path</comment> in <comment>$package_name</comment> is a directory; only files may be scaffolded.");
+    }
+
+    return $source_path;
+  }
+
+  /**
+   * Scaffolds the files for a specific package.
+   *
+   * @param array $list_of_scaffold_files
+   *   An associative array of destination file mappings.
+   * @param array $resolved_file_mappings
+   *   An associative array of package name to [dest => scaffold info mappings].
+   */
+  protected function scaffoldPackageFiles(array $list_of_scaffold_files, array $resolved_file_mappings) {
+    $options = $this->getOptions();
+    $symlink = $options['symlink'];
+
+    // We could simply scaffold all of the files from $list_of_scaffold_files,
+    // which contain only the list of files to be processed. We iterate over
+    // $resolved_file_mappings instead so that we can print out all of the
+    // scaffold files grouped by the package that provided them, including
+    // those not being scaffolded (because they were overridden or removed
+    // by some later package).
+    foreach ($resolved_file_mappings as $package_name => $package_scaffold_files) {
+      $this->io->write("Scaffolding files for <comment>$package_name</comment>:");
+      foreach ($package_scaffold_files as $dest_rel_path => $scaffold_file) {
+        $overriding_package = $scaffold_file->findProvidingPackage($list_of_scaffold_files);
+        if ($scaffold_file->overridden($overriding_package)) {
+          $this->io->write($scaffold_file->interpolate("  - <info>[dest-rel-path]</info> overridden in <comment>$overriding_package</comment>"));
+        }
+        else {
+          $this->process($scaffold_file, $symlink);
+        }
+      }
+    }
+  }
+
+  /**
+   * Moves a single scaffold file from source to destination.
+   *
+   * @param ScaffoldFileInfo $scaffold_file
+   *   The scaffold file to be processed.
+   * @param bool $symlink
+   *   Whether the destination should be a symlink.
+   *
+   * @throws \Exception
+   */
+  protected function process(ScaffoldFileInfo $scaffold_file, bool $symlink) {
+    $fs = new Filesystem();
+
+    if ($scaffold_file->removed()) {
+      return;
+    }
+
+    $destination_path = $scaffold_file->getDestinationFullPath();
+    $source_path = $scaffold_file->getSourceFullPath();
+
+    // Get rid of the destination if it exists, and make sure that
+    // the directory where it's going to be placed exists.
+    @unlink($destination_path);
+    $fs->ensureDirectoryExists(dirname($destination_path));
+    $success = FALSE;
+    if ($symlink) {
+      try {
+        $success = $fs->relativeSymlink($source_path, $destination_path);
+      }
+      catch (\Exception $e) {
+      }
+    }
+    else {
+      $success = copy($source_path, $destination_path);
+    }
+    $verb = $symlink ? 'symlink' : 'copy';
+    if (!$success) {
+      throw new \Exception($scaffold_file->interpolate("Could not $verb source file <info>[src-rel-path]</info> to <info>[dest-rel-path]</info>!"));
+    }
+    else {
+      $this->io->write($scaffold_file->interpolate("  - $verb source file <info>[src-rel-path]</info> to <info>[dest-rel-path]</info>"));
+    }
+  }
+
+}
diff --git a/core/lib/Drupal/Component/Scaffold/Interpolator.php b/core/lib/Drupal/Component/Scaffold/Interpolator.php
new file mode 100644
index 0000000000..02b70e1842
--- /dev/null
+++ b/core/lib/Drupal/Component/Scaffold/Interpolator.php
@@ -0,0 +1,144 @@
+<?php
+
+namespace Drupal\Component\Scaffold;
+
+/**
+ * Inject config values from an associative array into a string.
+ */
+class Interpolator {
+
+  protected $startToken;
+  protected $endToken;
+  protected $data;
+
+  /**
+   * Interpolator constructor.
+   *
+   * @param string $startToken
+   *   The start marker for a token, e.g. '['.
+   * @param string $endToken
+   *   The end marker for a token, e.g. ']'.
+   */
+  public function __construct($startToken = '\[', $endToken = '\]') {
+    $this->startToken = $startToken;
+    $this->endToken = $endToken;
+    $this->data = [];
+  }
+
+  /**
+   * GetData fetches the data set used by this interpolator.
+   */
+  public function getData() {
+    return $this->data;
+  }
+
+  /**
+   * SetData allows the client to associate a standard data set to use when interpolating.
+   */
+  public function setData($data) {
+    $this->data = $data;
+    return $this;
+  }
+
+  /**
+   * Interpolate a message using the standard data set provided via self::setData().
+   */
+  public function interpolate($message, $default = '') {
+    return $this->interpolateData($this->data, $message, $default = '');
+  }
+
+  /**
+   * Interpolate replaces tokens in a string with values from an associative array.
+   *
+   * Tokens are surrounded by double curley braces, e.g. "[key]". The characters
+   * that surround the key may be defined when the Interpolator is constructed.
+   *
+   * Example:
+   * If the message is 'Hello, [user.name]', then the value of the user.name
+   * item is fetched from the array, and the token [user.name] is
+   * replaced with the result.
+   *
+   * @param mixed|array $data
+   *   Data to use for interpolation.
+   * @param string $message
+   *   Message containing tokens to be replaced.
+   * @param string|bool $default
+   *   The value to substitute for tokens that
+   *   are not found in the data. If `false`, then missing
+   *   tokens are not replaced.
+   *
+   * @return string
+   *   The message after replacements have been made.
+   */
+  public function interpolateData($data, $message, $default = '') {
+    $replacements = $this->replacements($data, $message, $default);
+    return strtr($message, $replacements);
+  }
+
+  /**
+   * Throw if any tokens remain after interpolation.
+   */
+  public function mustInterpolate($data, $message) {
+    $result = $this->interpolate($data, $message, FALSE);
+    $tokens = $this->findTokens($result);
+    if (!empty($tokens)) {
+      throw new \Exception('The following required keys were not found in configuration: ' . implode(',', $tokens));
+    }
+    return $result;
+  }
+
+  /**
+   * FindTokens finds all of the tokens in the provided message.
+   *
+   * @param string $message
+   *   String with tokens.
+   *
+   * @return string[]
+   *   map of token to key, e.g. {{key}} => key
+   */
+  public function findTokens($message) {
+    $regEx = '#' . $this->startToken . '([a-zA-Z0-9._-]+)' . $this->endToken . '#';
+
+    if (!preg_match_all($regEx, $message, $matches, PREG_SET_ORDER)) {
+      return [];
+    }
+
+    $tokens = [];
+    foreach ($matches as $matchSet) {
+      list($sourceText, $key) = $matchSet;
+      $tokens[$sourceText] = $key;
+    }
+    return $tokens;
+  }
+
+  /**
+   * Replacements finds the tokens that exist in a message and builds a replacement array.
+   *
+   * All of the replacements in the data array are looked up given the token
+   * keys from the provided message. Keys that do not exist in the configuration
+   * are replaced with the default value.
+   */
+  public function replacements($data, $message, $default = '') {
+    $tokens = $this->findTokens($message);
+
+    $replacements = [];
+    foreach ($tokens as $sourceText => $key) {
+      $replacementText = $this->get($data, $key, $default);
+      if ($replacementText !== FALSE) {
+        $replacements[$sourceText] = $replacementText;
+      }
+    }
+    return $replacements;
+  }
+
+  /**
+   * Get a value from an array. Throw if the type is wrong.
+   */
+  protected function get($data, $key, $default) {
+    if (is_array($data)) {
+      return array_key_exists($key, $data) ? $data[$key] : $default;
+    }
+    throw new \Exception('Bad data type provided to Interpolator');
+  }
+
+}
diff --git a/core/lib/Drupal/Component/Scaffold/LICENSE.txt b/core/lib/Drupal/Component/Scaffold/LICENSE.txt
new file mode 100644
index 0000000000..94fb84639c
--- /dev/null
+++ b/core/lib/Drupal/Component/Scaffold/LICENSE.txt
@@ -0,0 +1,339 @@
+        GNU GENERAL PUBLIC LICENSE
+           Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+          Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+        GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+          NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+         END OF TERMS AND CONDITIONS
+
+      How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/core/lib/Drupal/Component/Scaffold/Plugin.php b/core/lib/Drupal/Component/Scaffold/Plugin.php
new file mode 100644
index 0000000000..e394bc88c3
--- /dev/null
+++ b/core/lib/Drupal/Component/Scaffold/Plugin.php
@@ -0,0 +1,65 @@
+<?php
+
+namespace Drupal\Component\Scaffold;
+
+use Composer\Script\Event;
+use Composer\Composer;
+use Composer\EventDispatcher\EventSubscriberInterface;
+use Composer\IO\IOInterface;
+use Composer\Plugin\Capable;
+use Composer\Plugin\PluginInterface;
+use Composer\Script\ScriptEvents;
+use Drupal\Component\Scaffold\CommandProvider;
+
+/**
+ * Composer plugin for handling drupal scaffold.
+ */
+class Plugin implements PluginInterface, EventSubscriberInterface, Capable {
+
+  /**
+   * The Composer Scaffold handler.
+   *
+   * @var \Drupal\Component\Scaffold\Handler
+   */
+  protected $handler;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function activate(Composer $composer, IOInterface $io) {
+    // We use a separate PluginScripts object. This way we separate
+    // functionality and also avoid some debug issues with the plugin being
+    // copied on initialisation.
+    // @see \Composer\Plugin\PluginManager::registerPackage()
+    $this->handler = new Handler($composer, $io);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCapabilities() {
+    return [
+      'Composer\Plugin\Capability\CommandProvider' => CommandProvider::class,
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getSubscribedEvents() {
+    return [
+      ScriptEvents::POST_UPDATE_CMD => 'postCmd',
+    ];
+  }
+
+  /**
+   * Post command event callback.
+   *
+   * @param \Composer\Script\Event $event
+   *   The Composer event.
+   */
+  public function postCmd(Event $event) {
+    $this->handler->onPostCmdEvent($event);
+  }
+
+}
diff --git a/core/lib/Drupal/Component/Scaffold/README.md b/core/lib/Drupal/Component/Scaffold/README.md
new file mode 100644
index 0000000000..59723fc6a6
--- /dev/null
+++ b/core/lib/Drupal/Component/Scaffold/README.md
@@ -0,0 +1,134 @@
+The Drupal Composer Scaffold Plugin
+
+Thanks for using this Drupal component.
+
+You can participate in its development on Drupal.org, through our issue system:
+https://www.drupal.org/project/issues/drupal
+
+You can get the full Drupal repo here:
+https://www.drupal.org/project/drupal/git-instructions
+
+You can browse the full Drupal repo here:
+http://cgit.drupalcode.org/drupal
+
+Sample composer.json for a project that relies on packages that use composer-scaffold:
+```
+{
+  "name": "my/project",
+  "require": {
+    "drupal/composer-scaffold": "*",
+    "composer/installers": "^1.2",
+    "cweagans/composer-patches": "^1.6.5",
+    "drupal/core": "^8.8.x-dev",
+    "pantheon-systems/d8-scaffold-files": "^1"
+  },
+  "config": {
+    "optimize-autoloader": true,
+    "sort-packages": true
+  },
+  "extra": {
+    "composer-scaffold": {
+      "allowed-packages": [
+        "drupal/core",
+      ],
+      "locations": {
+        "web-root": "./docroot"
+      },
+      "symlink": true,
+      "file-mapping": {
+        "[web-root]/.htaccess": false,
+        "[web-root]/robots.txt": "assets/robots-default.txt"
+      }
+    }
+  }
+}
+```
+
+Sample composer.json for composer-scaffold files in drupal/core:
+
+```
+{
+  "name": "drupal/core",
+  "extra": {
+    "composer-scaffold": {
+      "file-mapping": {
+        "[web-root]/.csslintrc": "assets/.csslintrc",
+        "[web-root]/.editorconfig": "assets/.editorconfig",
+        "[web-root]/.eslintignore": "assets/.eslintignore",
+        "[web-root]/.eslintrc.json": "assets/.eslintrc.json",
+        "[web-root]/.gitattributes": "assets/.gitattributes",
+        "[web-root]/.ht.router.php": "assets/.ht.router.php",
+        "[web-root]/.htaccess": "assets/.htaccess",
+        "[web-root]/sites/default/default.services.yml": "assets/default.services.yml",
+        "[web-root]/sites/default/default.settings.php": "assets/default.settings.php",
+        "[web-root]/sites/example.settings.local.php": "assets/example.settings.local.php",
+        "[web-root]/sites/example.sites.php": "assets/example.sites.php",
+        "[web-root]/index.php": "assets/index.php",
+        "[web-root]/robots.txt": "assets/robots.txt",
+        "[web-root]/update.php": "assets/update.php",
+        "[web-root]/web.config": "assets/web.config"
+      }
+    }
+  }
+}
+```
+
+@todo: drupal/core can move assets to a different project:
+
+```
+{
+  "name": "drupal/core",
+  "extra": {
+    "composer-scaffold": {
+      "allowed-packages": [
+        "drupal/assets",
+      ]
+    }
+  }
+}
+```
+
+Sample composer.json for a library that implements composer-scaffold:
+
+```
+{
+  "name": "pantheon-systems/d8-scaffold-files",
+  "extra": {
+      "composer-scaffold": {
+        "file-mapping": {
+            "[web-root]/sites/default/settings.php": "assets/sites/default/settings.php"
+        }
+      }
+    }
+  }
+}
+```
+
+@todo: Append to robots.txt:
+
+```
+{
+  "name": "pantheon-systems/d8-scaffold-files",
+  "extra": {
+      "composer-scaffold": {
+        "file-mapping": {
+            "[web-root]/robots.txt": {
+              "path": "assets/my-robots-additions.txt",
+              "mode": "append"
+            }
+        }
+      }
+    }
+  }
+}
+```
+
+With the enhancement above, `false` will expand to `"mode": "remove"`, and a simple string will expand to `"mode": "copy"`, with the string's value being placed in "path". This will therefore retain backwards compatibility with the current implementation, and also will maintain brief, descriptive file mappings for the most common cases (copy and remove).
+
+Patch a file after it's copied:
+
+```
+"post-composer-scaffold-cmd": [
+  "cd docroot && patch -p1 <../patches/htaccess-ssl.patch"
+]
+```
\ No newline at end of file
diff --git a/core/lib/Drupal/Component/Scaffold/ScaffoldFileInfo.php b/core/lib/Drupal/Component/Scaffold/ScaffoldFileInfo.php
new file mode 100644
index 0000000000..27df81578f
--- /dev/null
+++ b/core/lib/Drupal/Component/Scaffold/ScaffoldFileInfo.php
@@ -0,0 +1,198 @@
+<?php
+
+declare(strict_types = 1);
+
+namespace Drupal\Component\Scaffold;
+
+/**
+ * Data file that keeps track of one scaffold file's source, destination, and package.
+ */
+class ScaffoldFileInfo {
+
+  protected $packageName;
+  protected $destinationRelPath;
+  protected $destinationFullPath;
+  protected $sourceRelPath;
+  protected $sourceFullPath;
+
+  /**
+   * Set the package name.
+   *
+   * @param string $packageName
+   *   The name of the package this scaffold file info was collected from.
+   *
+   * @return $this
+   */
+  public function setPackageName(string $packageName) {
+    $this->packageName = $packageName;
+    return $this;
+  }
+
+  /**
+   * Get the package name.
+   *
+   * @return string
+   *   The name of the package this scaffold file info was collected from.
+   */
+  public function getPackageName() {
+    return $this->packageName;
+  }
+
+  /**
+   * Set the relative path to the destination.
+   *
+   * @param string $destinationRelPath
+   *   The relative path to the destination file.
+   *
+   * @return $this
+   */
+  public function setDestinationRelativePath(string $destinationRelPath) {
+    $this->destinationRelPath = $destinationRelPath;
+    return $this;
+  }
+
+  /**
+   * Get the relative path to the destination.
+   *
+   * @return string
+   *   The relative path to the destination file.
+   */
+  public function getDestinationRelativePath() {
+    return $this->destinationRelPath;
+  }
+
+  /**
+   * Set the relative path to the source.
+   *
+   * @param string $sourceRelPath
+   *   The relative path to the source file.
+   *
+   * @return $this
+   */
+  public function setSourceRelativePath(string $sourceRelPath) {
+    $this->sourceRelPath = $sourceRelPath;
+    return $this;
+  }
+
+  /**
+   * Get the relative path to the source.
+   *
+   * @return string
+   *   The relative path to the source file.
+   */
+  public function getSourceRelativePath() {
+    return $this->sourceRelPath;
+  }
+
+  /**
+   * Set the full path to the destination.
+   *
+   * @param string $destinationFullPath
+   *   The full path to the destination file.
+   *
+   * @return $this
+   */
+  public function setDestinationFullPath(string $destinationFullPath) {
+    $this->destinationFullPath = $destinationFullPath;
+    return $this;
+  }
+
+  /**
+   * Get the full path to the destination.
+   *
+   * @return string
+   *   The full path to the destination file.
+   */
+  public function getDestinationFullPath() {
+    return $this->destinationFullPath;
+  }
+
+  /**
+   * Set the full path to the source.
+   *
+   * @param string $sourceFullPath
+   *   The full path to the source file.
+   *
+   * @return $this
+   */
+  public function setSourceFullPath(string $sourceFullPath) {
+    $this->sourceFullPath = $sourceFullPath;
+    return $this;
+  }
+
+  /**
+   * Get the full path to the source.
+   *
+   * @return string
+   *   The full path to the source file.
+   */
+  public function getSourceFullPath() {
+    return $this->sourceFullPath;
+  }
+
+  /**
+   * Return the package name that provides the scaffold file info at this destination path.
+   *
+   * Given the list of all scaffold file info objects, return the package that
+   * provides the scaffold file info for the scaffold file that will be placed
+   * at the destination that this scaffold file would be placed at. Note that
+   * this will be the same as $this->getPackageName() unless this scaffold file
+   * has been overridden or removed by some other package.
+   *
+   * @param string[] $list_of_scaffold_files
+   *   The list of all scaffold file info objects, keyed by destination path
+   *   (and therefore containing only those files being processed)
+   *
+   * @return string
+   *   The name of the package that provided the scaffold file information.
+   */
+  public function findProvidingPackage(array $list_of_scaffold_files) {
+    if (!array_key_exists($this->getDestinationRelativePath(), $list_of_scaffold_files)) {
+      throw new \Exception("Scaffold file not found in list of all scaffold files.");
+    }
+    $scaffold_file = $list_of_scaffold_files[$this->getDestinationRelativePath()];
+    return $scaffold_file->getPackageName();
+  }
+
+  /**
+   * Determine whether this scaffold file info is for a destination path that was removed.
+   *
+   * @return bool
+   *   True if this scaffold file was removed.
+   */
+  public function removed() {
+    return empty($this->getSourceRelativePath());
+  }
+
+  /**
+   * Determine if this scaffold file has been overridden by another package.
+   *
+   * @param string $providing_package
+   *   The name of the package that provides the scaffold file at this location,
+   *   as returned by self::findProvidingPackage()
+   *
+   * @return bool
+   *   Whether this scaffold file if overridden or removed.
+   */
+  public function overridden(string $providing_package) {
+    return $this->getPackageName() !== $providing_package;
+  }
+
+  /**
+   * Interpolate a string using the data from this scaffold file info.
+   */
+  public function interpolate(string $message, array $extra = [], $default = FALSE) {
+    $interploator = new Interpolator();
+
+    $data = [
+      'package-name' => $this->getPackageName(),
+      'dest-rel-path' => $this->getDestinationRelativePath(),
+      'src-rel-path' => $this->getSourceRelativePath(),
+      'dest-full-path' => $this->getDestinationFullPath(),
+      'src-full-path' => $this->getSourceFullPath(),
+    ] + $extra;
+
+    return $interploator->interpolateData($data, $message, $default);
+  }
+
+}
diff --git a/core/lib/Drupal/Component/Scaffold/TESTING.txt b/core/lib/Drupal/Component/Scaffold/TESTING.txt
new file mode 100644
index 0000000000..3186f0f901
--- /dev/null
+++ b/core/lib/Drupal/Component/Scaffold/TESTING.txt
@@ -0,0 +1,18 @@
+HOW-TO: Test this Drupal component
+
+In order to test this component, you'll need to get the entire Drupal repo and
+run the tests there.
+
+You'll find the tests under core/tests/Drupal/Tests/Component.
+
+You can get the full Drupal repo here:
+https://www.drupal.org/project/drupal/git-instructions
+
+You can find more information about running PHPUnit tests with Drupal here:
+https://www.drupal.org/node/2116263
+
+Each component in the Drupal\Component namespace has its own annotated test
+group. You can use this group to run only the tests for this component. Like
+this:
+
+$ ./vendor/bin/phpunit -c core --group Scaffold
diff --git a/core/lib/Drupal/Component/Scaffold/composer.json b/core/lib/Drupal/Component/Scaffold/composer.json
new file mode 100644
index 0000000000..6f4c17fce0
--- /dev/null
+++ b/core/lib/Drupal/Component/Scaffold/composer.json
@@ -0,0 +1,24 @@
+{
+  "name": "drupal/drupal-scaffold",
+  "description": "Test for Composer Scaffold.",
+  "type": "composer-plugin",
+  "license": "GPL-2.0-or-later",
+  "require": {
+    "php": ">=7.0.8",
+    "composer-plugin-api": "^1.0.0"
+  },
+  "minimum-stability": "dev",
+  "prefer-stable": true,
+  "autoload": {
+    "psr-4": {
+      "Drupal\\Component\\Scaffold\\": ""
+    }
+  },
+  "extra": {
+    "class": "Drupal\\Component\\Scaffold\\Plugin"
+  },
+  "require-dev": {
+    "composer/composer": "^1.0",
+    "phpunit/phpunit": "^4.8.35 || ^6.5"
+  }
+}
diff --git a/core/lib/Drupal/Core/Composer/Composer.php b/core/lib/Drupal/Core/Composer/Composer.php
index 21c318a92a..00de330311 100644
--- a/core/lib/Drupal/Core/Composer/Composer.php
+++ b/core/lib/Drupal/Core/Composer/Composer.php
@@ -15,64 +15,6 @@
  */
 class Composer {
 
-  protected static $packageToCleanup = [
-    'behat/mink' => ['tests', 'driver-testsuite'],
-    'behat/mink-browserkit-driver' => ['tests'],
-    'behat/mink-goutte-driver' => ['tests'],
-    'drupal/coder' => ['coder_sniffer/Drupal/Test', 'coder_sniffer/DrupalPractice/Test'],
-    'doctrine/cache' => ['tests'],
-    'doctrine/collections' => ['tests'],
-    'doctrine/common' => ['tests'],
-    'doctrine/inflector' => ['tests'],
-    'doctrine/instantiator' => ['tests'],
-    'egulias/email-validator' => ['documentation', 'tests'],
-    'fabpot/goutte' => ['Goutte/Tests'],
-    'guzzlehttp/promises' => ['tests'],
-    'guzzlehttp/psr7' => ['tests'],
-    'jcalderonzumba/gastonjs' => ['docs', 'examples', 'tests'],
-    'jcalderonzumba/mink-phantomjs-driver' => ['tests'],
-    'masterminds/html5' => ['test'],
-    'mikey179/vfsStream' => ['src/test'],
-    'paragonie/random_compat' => ['tests'],
-    'pear/archive_tar' => ['tests'],
-    'pear/console_getopt' => ['tests'],
-    'pear/pear-core-minimal' => ['tests'],
-    'pear/pear_exception' => ['tests'],
-    'phpdocumentor/reflection-docblock' => ['tests'],
-    'phpunit/php-code-coverage' => ['tests'],
-    'phpunit/php-timer' => ['tests'],
-    'phpunit/php-token-stream' => ['tests'],
-    'phpunit/phpunit' => ['tests'],
-    'phpunit/php-mock-objects' => ['tests'],
-    'sebastian/comparator' => ['tests'],
-    'sebastian/diff' => ['tests'],
-    'sebastian/environment' => ['tests'],
-    'sebastian/exporter' => ['tests'],
-    'sebastian/global-state' => ['tests'],
-    'sebastian/recursion-context' => ['tests'],
-    'stack/builder' => ['tests'],
-    'symfony/browser-kit' => ['Tests'],
-    'symfony/class-loader' => ['Tests'],
-    'symfony/console' => ['Tests'],
-    'symfony/css-selector' => ['Tests'],
-    'symfony/debug' => ['Tests'],
-    'symfony/dependency-injection' => ['Tests'],
-    'symfony/dom-crawler' => ['Tests'],
-    // @see \Drupal\Tests\Component\EventDispatcher\ContainerAwareEventDispatcherTest
-    // 'symfony/event-dispatcher' => ['Tests'],
-    'symfony/http-foundation' => ['Tests'],
-    'symfony/http-kernel' => ['Tests'],
-    'symfony/process' => ['Tests'],
-    'symfony/psr-http-message-bridge' => ['Tests'],
-    'symfony/routing' => ['Tests'],
-    'symfony/serializer' => ['Tests'],
-    'symfony/translation' => ['Tests'],
-    'symfony/validator' => ['Tests', 'Resources'],
-    'symfony/yaml' => ['Tests'],
-    'symfony-cmf/routing' => ['Test', 'Tests'],
-    'twig/twig' => ['doc', 'ext', 'test'],
-  ];
-
   /**
    * Add vendor classes to Composer's static classmap.
    */
@@ -196,84 +138,18 @@ public static function upgradePHPUnitCheck($phpunit_version) {
    * @param \Composer\Installer\PackageEvent $event
    *   A PackageEvent object to get the configured composer vendor directories
    *   from.
+   *
+   * @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0.
    */
   public static function vendorTestCodeCleanup(PackageEvent $event) {
-    $vendor_dir = $event->getComposer()->getConfig()->get('vendor-dir');
     $io = $event->getIO();
-    $op = $event->getOperation();
-    if ($op->getJobType() == 'update') {
-      $package = $op->getTargetPackage();
-    }
-    else {
-      $package = $op->getPackage();
-    }
-    $package_key = static::findPackageKey($package->getName());
-    $message = sprintf("    Processing <comment>%s</comment>", $package->getPrettyName());
+    // @see https://www.drupal.org/node/3041017
+    $message = __METHOD__ . '() has been deprecated. Remove the script calls in your project composer.json';
     if ($io->isVeryVerbose()) {
-      $io->write($message);
-    }
-    if ($package_key) {
-      foreach (static::$packageToCleanup[$package_key] as $path) {
-        $dir_to_remove = $vendor_dir . '/' . $package_key . '/' . $path;
-        $print_message = $io->isVeryVerbose();
-        if (is_dir($dir_to_remove)) {
-          if (static::deleteRecursive($dir_to_remove)) {
-            $message = sprintf("      <info>Removing directory '%s'</info>", $path);
-          }
-          else {
-            // Always display a message if this fails as it means something has
-            // gone wrong. Therefore the message has to include the package name
-            // as the first informational message might not exist.
-            $print_message = TRUE;
-            $message = sprintf("      <error>Failure removing directory '%s'</error> in package <comment>%s</comment>.", $path, $package->getPrettyName());
-          }
-        }
-        else {
-          // If the package has changed or the --prefer-dist version does not
-          // include the directory this is not an error.
-          $message = sprintf("      Directory '%s' does not exist", $path);
-        }
-        if ($print_message) {
-          $io->write($message);
-        }
-      }
-
-      if ($io->isVeryVerbose()) {
-        // Add a new line to separate this output from the next package.
-        $io->write("");
-      }
+      $io->write('<comment>' . $message . '</comment>');
     }
   }
 
-  /**
-   * Find the array key for a given package name with a case-insensitive search.
-   *
-   * @param string $package_name
-   *   The package name from composer. This is always already lower case.
-   *
-   * @return string|null
-   *   The string key, or NULL if none was found.
-   */
-  protected static function findPackageKey($package_name) {
-    $package_key = NULL;
-    // In most cases the package name is already used as the array key.
-    if (isset(static::$packageToCleanup[$package_name])) {
-      $package_key = $package_name;
-    }
-    else {
-      // Handle any mismatch in case between the package name and array key.
-      // For example, the array key 'mikey179/vfsStream' needs to be found
-      // when composer returns a package name of 'mikey179/vfsstream'.
-      foreach (static::$packageToCleanup as $key => $dirs) {
-        if (strtolower($key) === $package_name) {
-          $package_key = $key;
-          break;
-        }
-      }
-    }
-    return $package_key;
-  }
-
   /**
    * Removes Composer's timeout so that scripts can run indefinitely.
    */
@@ -281,31 +157,4 @@ public static function removeTimeout() {
     ProcessExecutor::setTimeout(0);
   }
 
-  /**
-   * Helper method to remove directories and the files they contain.
-   *
-   * @param string $path
-   *   The directory or file to remove. It must exist.
-   *
-   * @return bool
-   *   TRUE on success or FALSE on failure.
-   */
-  protected static function deleteRecursive($path) {
-    if (is_file($path) || is_link($path)) {
-      return unlink($path);
-    }
-    $success = TRUE;
-    $dir = dir($path);
-    while (($entry = $dir->read()) !== FALSE) {
-      if ($entry == '.' || $entry == '..') {
-        continue;
-      }
-      $entry_path = $path . '/' . $entry;
-      $success = static::deleteRecursive($entry_path) && $success;
-    }
-    $dir->close();
-
-    return rmdir($path) && $success;
-  }
-
 }
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/HandlerTest.php b/core/tests/Drupal/Tests/Component/Scaffold/HandlerTest.php
new file mode 100644
index 0000000000..d26b9843c7
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/HandlerTest.php
@@ -0,0 +1,161 @@
+<?php
+
+namespace Drupal\Tests\Component\Scaffold;
+
+use Composer\Composer;
+use Composer\IO\IOInterface;
+use Composer\Package\PackageInterface;
+use Drupal\Component\Scaffold\Handler;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @coversDefaultClass \Drupal\Component\Scaffold\Handler
+ *
+ * @group Scaffold
+ */
+class HandlerTest extends TestCase {
+
+  /**
+   * The Composer service.
+   *
+   * @var \Composer\IO\IOInterface
+   */
+  protected $composer;
+
+  /**
+   * The Composer IO service.
+   *
+   * @var \Composer\IO\IOInterface
+   */
+  protected $io;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->composer = $this->prophesize(Composer::class);
+    $this->io = $this->prophesize(IOInterface::class);
+  }
+
+  /**
+   * @covers ::getPackageFileMappings
+   */
+  public function testGetPackageFileMappingsErrors() {
+    // Check missing parameters sets appropriate error.
+    $package = $this->prophesize(PackageInterface::class);
+    $package->getExtra()->willReturn([]);
+    $package->getName()->willReturn('foo/bar');
+    $this->io->writeError('The allowed package foo/bar does not provide a file mapping for Composer Scaffold.')->shouldBeCalled();
+    $fixture = new Handler($this->composer->reveal(), $this->io->reveal());
+    $this->assertSame([], $fixture->getPackageFileMappings($package->reveal()));
+
+    // With only one of the required parameters.
+    $package->getExtra()->willReturn(['composer-scaffold' => []]);
+    $this->assertSame([], $fixture->getPackageFileMappings($package->reveal()));
+  }
+
+  /**
+   * @covers ::getPackageFileMappings
+   */
+  public function testGetPackageFileMappings() {
+    $expected = [
+      'self' => [
+        'assets/.htaccess' => FALSE,
+        'assets/robots-default.txt' => '[web-root]/robots.txt',
+      ],
+    ];
+
+    $package = $this->prophesize(PackageInterface::class);
+    $package->getExtra()->willReturn(['composer-scaffold' => ['file-mapping' => $expected]]);
+    $fixture = new Handler($this->composer->reveal(), $this->io->reveal());
+    $this->assertSame($expected, $fixture->getPackageFileMappings($package->reveal()));
+  }
+
+  /**
+   * @covers ::getWebRoot
+   * @covers ::getOptions
+   */
+  public function testGetWebRoot() {
+    $expected = './build/docroot';
+    $extra = [
+      'composer-scaffold' => [
+        'locations' => [
+          'web-root' => $expected,
+        ],
+      ],
+    ];
+
+    $package = $this->prophesize(PackageInterface::class);
+    $package->getExtra()->willReturn($extra);
+
+    $this->composer->getPackage()->willReturn($package->reveal());
+
+    $fixture = new Handler($this->composer->reveal(), $this->io->reveal());
+    $this->assertSame($expected, $fixture->getWebRoot());
+
+    // Verify correct errors.
+    $this->expectException(\Exception::class);
+    $this->expectExceptionMessage('The extra.composer-scaffold.location.web-root is not set in composer.json.');
+    $extra = [
+      'allowed-packages' => [
+        'foo/bar',
+      ],
+    ];
+    $package->getExtra()->willReturn($extra);
+    $this->composer->getPackage()->willReturn($package->reveal());
+    $fixture = new Handler($this->composer->reveal(), $this->io->reveal());
+    $fixture->getWebRoot();
+  }
+
+  /**
+   * Tests ArrayManipulator::arrayMergeRecursiveExceptEmpty().
+   *
+   * @dataProvider providerTestArrayMergeRecursiveDistinct
+   *
+   * @covers ::getWebRoot
+   */
+  public function testArrayMergeRecursiveDistinct(
+    array $array1,
+    array $array2,
+    array $expected_array
+  ) {
+    $this->assertSame(Handler::arrayMergeRecursiveDistinct($array1,
+      $array2), $expected_array);
+  }
+
+  /**
+   * Provides values to testArrayMergeRecursiveDistinct().
+   *
+   * @return array
+   *   An array of values to test.
+   */
+  public function providerTestArrayMergeRecursiveDistinct() :array {
+    return [
+      [
+        [
+          "drupal/core" => [
+            "assets/.htaccess" => "[web-root]/.htaccess",
+            "assets/robots-default.txt" => "[web-root]/robots.txt",
+            "assets/index.php" => "[web-root]/index.php",
+          ],
+        ],
+        [
+          "drupal/core" => [
+            "assets/.htaccess" => FALSE,
+            "assets/robots-default.txt" => "[web-root]/robots.txt.bak",
+          ],
+        ],
+        [
+          "drupal/core" => [
+            "assets/.htaccess" => FALSE,
+            "assets/robots-default.txt" => "[web-root]/robots.txt.bak",
+            "assets/index.php" => "[web-root]/index.php",
+          ],
+        ],
+      ],
+    ];
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/ScaffoldTest.php b/core/tests/Drupal/Tests/Component/Scaffold/ScaffoldTest.php
new file mode 100644
index 0000000000..b5240d27ee
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/ScaffoldTest.php
@@ -0,0 +1,230 @@
+<?php
+
+namespace Drupal\Tests\Component\Scaffold;
+
+use Composer\Util\Filesystem;
+use Drupal\Component\Scaffold\Interpolator;
+use PHPUnit\Framework\TestCase;
+use Symfony\Component\Process\Process;
+
+/**
+ * Tests Composer Scaffold.
+ *
+ * @group Scaffold
+ *
+ * @todo Convert to build test after
+ *   https://www.drupal.org/project/drupal/issues/3031379 and/or
+ *   https://www.drupal.org/project/drupal/issues/2984031.
+ */
+class ScaffoldTest extends TestCase {
+
+  /**
+   * The root of this project.
+   *
+   * @var string
+   */
+  protected $projectRoot;
+
+  /**
+   * Directory to perform the tests in.
+   *
+   * @var string
+   */
+  protected $fixtures;
+
+  /**
+   * The file path to the system under test.
+   *
+   * @var string
+   */
+  protected $sut;
+
+  /**
+   * The Symfony FileSystem component.
+   *
+   * @var \Symfony\Component\Filesystem\Filesystem
+   */
+  protected $fileSystem;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    $this->fileSystem = new Filesystem();
+
+    $this->projectRoot = realpath(__DIR__ . '/../../../../../lib/Drupal/Component/Scaffold');
+    $this->fixtures = sys_get_temp_dir() . '/composer-scaffold-test-' . md5($this->getName() . microtime());
+  }
+
+  /**
+   * Create the System-Under-Test.
+   */
+  protected function createSut($topLevelProjectDir, $replacements = []) {
+    $replacements += [
+      'SYMLINK' => 'true',
+    ];
+    $interpolator = new Interpolator('__', '__', TRUE);
+    $interpolator->setData($replacements);
+    $projectRoot = dirname(__DIR__);
+    $this->sut = $this->fixtures . '/' . $topLevelProjectDir;
+
+    $this->fileSystem->copy(realpath(__DIR__ . '/fixtures'), $this->fixtures);
+
+    $composer_json_templates = glob($this->fixtures . "/*/composer.json.tmpl");
+    foreach ($composer_json_templates as $composer_json_tmpl) {
+      // Inject replacements into composer.json.
+      if (file_exists($composer_json_tmpl)) {
+        $composer_json_contents = file_get_contents($composer_json_tmpl);
+        $composer_json_contents = $interpolator->interpolate($composer_json_contents, FALSE);
+        file_put_contents(dirname($composer_json_tmpl) . "/composer.json", $composer_json_contents);
+        @unlink($composer_json_tmpl);
+      }
+    }
+
+    return $this->sut;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function tearDown() {
+    // Remove the fixture filesystem.
+    $this->fileSystem->remove($this->fixtures);
+  }
+
+  /**
+   * Data provider for testScaffoldFixturesThatThrow().
+   */
+  public function scaffoldFixturesThatMakeErrors() {
+    return [
+      'missing-robots-txt' => [
+        'drupal-drupal-missing-scaffold-file',
+        '_no_assertion_',
+        TRUE,
+      ],
+    ];
+  }
+
+  /**
+   * Tests that scaffold files return nonzero when they have bad values.
+   *
+   * @dataProvider scaffoldFixturesThatMakeErrors
+   */
+  public function testScaffoldFixturesError($topLevelProjectDir, $scaffoldAssertions, $is_link) {
+    $sut = $this->createSut($topLevelProjectDir, [
+      'SYMLINK' => $is_link ? 'true' : 'false',
+      'PROJECT_ROOT' => $this->projectRoot,
+    ]);
+
+    // Test composer install. Expect an error.
+    // @todo: assert output contains too.
+    $this->runComposer("install", 1, 'Could not find source file');
+  }
+
+  /**
+   * Data provider for testComposerInstallScaffold and testScaffoldCommand.
+   */
+  public function scaffoldTestValues() {
+    return [
+      [
+        'drupal-composer-drupal-project',
+        'assertDrupalProjectSutWasScaffolded',
+        TRUE,
+      ],
+      [
+        'drupal-drupal',
+        'assertDrupalDrupalSutWasScaffolded',
+        FALSE,
+      ],
+    ];
+  }
+
+  /**
+   * Tests that scaffold files are correctly moved by the plugin.
+   *
+   * @dataProvider scaffoldTestValues
+   */
+  public function testScaffoldPlugin($topLevelProjectDir, $scaffoldAssertions, $is_link) {
+    $sut = $this->createSut($topLevelProjectDir, [
+      'SYMLINK' => $is_link ? 'true' : 'false',
+      'PROJECT_ROOT' => $this->projectRoot,
+    ]);
+
+    // Test composer install.
+    $this->runComposer('install');
+    call_user_func([$this, $scaffoldAssertions], $sut, $is_link, $topLevelProjectDir);
+
+    // Test composer:scaffold.
+    $this->runComposer('composer:scaffold');
+    call_user_func([$this, $scaffoldAssertions], $sut, $is_link, $topLevelProjectDir);
+  }
+
+  /**
+   * Runs a `composer` command.
+   */
+  protected function runComposer($cmd, $expectedExitCode = 0, $expectedContents = '') {
+    $process = new Process("composer $cmd", $this->sut);
+    $process->setTimeout(300)->setIdleTimeout(300)->run();
+    if (!empty($expectedContents)) {
+      $this->assertContains($expectedContents, $process->getOutput() . "\n" . $process->getErrorOutput());
+    }
+    $this->assertSame($expectedExitCode, $process->getExitCode(), $process->getErrorOutput());
+  }
+
+  /**
+   * Asserts that scaffold files were correctly moved.
+   */
+  protected function assertDrupalProjectSutWasScaffolded($sut, $is_link, $project_name) {
+    $this->assertDrupalRootWasScaffolded($sut . '/docroot', $is_link, $project_name);
+  }
+
+  /**
+   * Asserts that scaffold files were correctly moved.
+   */
+  protected function assertDrupalDrupalSutWasScaffolded($sut, $is_link, $project_name) {
+    $this->assertDrupalRootWasScaffolded($sut, $is_link, $project_name);
+  }
+
+  /**
+   * Assert that the scaffold files are placed as we expect them to be.
+   */
+  protected function assertDrupalRootWasScaffolded($docroot, $is_link, $project_name) {
+    $from_project = "scaffolded from \"file-mappings\" in $project_name composer.json fixture";
+    $from_scaffold_override = 'scaffolded from the scaffold-override-fixture';
+    $from_core = 'from drupal/core';
+
+    // Ensure that the autoload.php file was written.
+    $this->assertFileExists($docroot . '/autoload.php');
+
+    // Assert other scaffold files are written in the correct locations.
+    $this->assertScaffoldedFile($docroot . '/.csslintrc', $is_link, $from_core);
+    $this->assertScaffoldedFile($docroot . '/.editorconfig', $is_link, $from_core);
+    $this->assertScaffoldedFile($docroot . '/.eslintignore', $is_link, $from_core);
+    $this->assertScaffoldedFile($docroot . '/.eslintrc.json', $is_link, $from_core);
+    $this->assertScaffoldedFile($docroot . '/.gitattributes', $is_link, $from_core);
+    $this->assertScaffoldedFile($docroot . '/.ht.router.php', $is_link, $from_core);
+    $this->assertScaffoldedFile($docroot . '/sites/default/default.services.yml', $is_link, $from_core);
+    $this->assertScaffoldedFile($docroot . '/sites/default/default.settings.php', $is_link, $from_scaffold_override);
+    $this->assertScaffoldedFile($docroot . '/sites/example.settings.local.php', $is_link, $from_core);
+    $this->assertScaffoldedFile($docroot . '/sites/example.sites.php', $is_link, $from_core);
+    $this->assertScaffoldedFile($docroot . '/index.php', $is_link, $from_core);
+    $this->assertScaffoldedFile($docroot . '/robots.txt', $is_link, $from_project);
+    $this->assertScaffoldedFile($docroot . '/update.php', $is_link, $from_core);
+    $this->assertScaffoldedFile($docroot . '/web.config', $is_link, $from_core);
+
+    // Ensure that the .htaccess.txt file was not written, as our
+    // top-level composer.json excludes it from the files to scaffold.
+    $this->assertFileNotExists($docroot . '/.htaccess');
+  }
+
+  /**
+   * Asserts that a given file exists and is/is not a symlink.
+   */
+  protected function assertScaffoldedFile($path, $is_link, $contents_contains) {
+    $this->assertFileExists($path);
+    $contents = file_get_contents($path);
+    $this->assertContains($contents_contains, basename($path) . ': ' . $contents);
+    $this->assertSame($is_link, is_link($path));
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/README.md b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/README.md
new file mode 100644
index 0000000000..dd4d9c73e8
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/README.md
@@ -0,0 +1,5 @@
+# Fixtures README
+
+To use these fixtures, copy them to a temporary directory located next to the project directory.
+
+Alternately, copy them to any other location, and then fix up the path to composer-scaffold in the composer.json file in the fixture being tested (e.g. drupal-composer-drupal-project).
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-composer-drupal-project/assets/robots-default.txt b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-composer-drupal-project/assets/robots-default.txt
new file mode 100644
index 0000000000..c29217ef39
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-composer-drupal-project/assets/robots-default.txt
@@ -0,0 +1 @@
+# robots.txt fixture scaffolded from "file-mappings" in drupal-composer-drupal-project composer.json fixture.
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-composer-drupal-project/composer.json.tmpl b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-composer-drupal-project/composer.json.tmpl
new file mode 100644
index 0000000000..0cf5baf548
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-composer-drupal-project/composer.json.tmpl
@@ -0,0 +1,65 @@
+{
+  "name": "my/project",
+  "type": "project",
+  "minimum-stability": "dev",
+  "prefer-stable": true,
+  "repositories": {
+    "composer-scaffold": {
+      "type": "path",
+      "url": "__PROJECT_ROOT__",
+      "options": {
+        "symlink": true
+      }
+    },
+    "drupal-core-fixture": {
+      "type": "path",
+      "url": "../drupal-core-fixture",
+      "options": {
+        "symlink": true
+      }
+    },
+    "scaffold-override-fixture": {
+      "type": "path",
+      "url": "../scaffold-override-fixture",
+      "options": {
+        "symlink": true
+      }
+    },
+    "drupal": {
+      "type": "composer",
+      "url": "https://packages.drupal.org/8"
+    }
+  },
+  "require": {
+    "drupal/drupal-scaffold": "*",
+    "fixtures/drupal-core-fixture": "*",
+    "fixtures/scaffold-override-fixture": "*"
+  },
+  "extra": {
+    "composer-scaffold": {
+      "allowed-packages": [
+        "fixtures/drupal-core-fixture",
+        "fixtures/scaffold-override-fixture"
+      ],
+      "locations": {
+        "web-root": "./docroot"
+      },
+      "symlink": __SYMLINK__,
+      "file-mapping": {
+        "[web-root]/.htaccess": false,
+        "[web-root]/robots.txt": "assets/robots-default.txt"
+      }
+    },
+    "installer-paths": {
+      "docroot/core": ["type:drupal-core"],
+      "docroot/modules/contrib/{$name}": ["type:drupal-module"],
+      "docroot/modules/custom/{$name}": ["type:drupal-custom-module"],
+      "docroot/profiles/contrib/{$name}": ["type:drupal-profile"],
+      "docroot/profiles/custom/{$name}": ["type:drupal-custom-profile"],
+      "docroot/themes/contrib/{$name}": ["type:drupal-theme"],
+      "docroot/themes/custom/{$name}": ["type:drupal-custom-theme"],
+      "docroot/libraries/{$name}": ["type:drupal-library"],
+      "drush/Commands/contrib/{$name}": ["type:drupal-drush"]
+    }
+  }
+}
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.csslintrc b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.csslintrc
new file mode 100644
index 0000000000..f5bca65208
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.csslintrc
@@ -0,0 +1 @@
+# Test version of .csslintrc from drupal/core.
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.editorconfig b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.editorconfig
new file mode 100644
index 0000000000..dcf0c98bbf
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.editorconfig
@@ -0,0 +1 @@
+# Test version of .editorconfig from drupal/core.
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.eslintignore b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.eslintignore
new file mode 100644
index 0000000000..f0405c03ad
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.eslintignore
@@ -0,0 +1 @@
+# Test version of .eslintignore from drupal/core.
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.eslintrc.json b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.eslintrc.json
new file mode 100644
index 0000000000..6391fb0c6e
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.eslintrc.json
@@ -0,0 +1 @@
+// Test version of .eslintrc.json from drupal/core.
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.gitattributes b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.gitattributes
new file mode 100644
index 0000000000..03436baebc
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.gitattributes
@@ -0,0 +1 @@
+# Test version of .gitattributes from drupal/core.
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.ht.router.php b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.ht.router.php
new file mode 100644
index 0000000000..0cd34ad7ad
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.ht.router.php
@@ -0,0 +1,2 @@
+<?php
+// Test version of .ht.router.php from drupal/core.
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.htaccess b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.htaccess
new file mode 100644
index 0000000000..4cfce848ab
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/.htaccess
@@ -0,0 +1 @@
+# Test version of .htaccess from drupal/core.
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/default.services.yml b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/default.services.yml
new file mode 100644
index 0000000000..cdfdd0a9f6
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/default.services.yml
@@ -0,0 +1 @@
+# Test version of default.services.yml from drupal/core.
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/default.settings.php b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/default.settings.php
new file mode 100644
index 0000000000..82b1cb21e1
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/default.settings.php
@@ -0,0 +1,6 @@
+<?php
+
+/**
+ * @file
+ * Test version of default.settings.php from drupal/core.
+ */
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/example.settings.local.php b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/example.settings.local.php
new file mode 100644
index 0000000000..074efa4648
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/example.settings.local.php
@@ -0,0 +1,6 @@
+<?php
+
+/**
+ * @file
+ * Test version of example.settings.local.php from drupal/core.
+ */
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/example.sites.php b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/example.sites.php
new file mode 100644
index 0000000000..d0e0e01005
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/example.sites.php
@@ -0,0 +1,6 @@
+<?php
+
+/**
+ * @file
+ * Test version of example.sites.php from drupal/core.
+ */
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/index.php b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/index.php
new file mode 100644
index 0000000000..6dd96fde33
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/index.php
@@ -0,0 +1,6 @@
+<?php
+
+/**
+ * @file
+ * Test version of index.php from drupal/core.
+ */
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/robots.txt b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/robots.txt
new file mode 100644
index 0000000000..19d2a6b087
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/robots.txt
@@ -0,0 +1 @@
+# Test version of robots.txt from drupal/core.
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/update.php b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/update.php
new file mode 100644
index 0000000000..3ccf1cb1b0
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/update.php
@@ -0,0 +1,6 @@
+<?php
+
+/**
+ * @file
+ * Test version of update.php from drupal/core.
+ */
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/web.config b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/web.config
new file mode 100644
index 0000000000..f3344d0a20
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/assets/web.config
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Test version of web.config from drupal/core. -->
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/composer.json b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/composer.json
new file mode 100644
index 0000000000..bff69c4436
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-core-fixture/composer.json
@@ -0,0 +1,24 @@
+{
+  "name": "fixtures/drupal-core-fixture",
+  "extra": {
+    "composer-scaffold": {
+      "file-mapping": {
+        "[web-root]/.csslintrc": "assets/.csslintrc",
+        "[web-root]/.editorconfig": "assets/.editorconfig",
+        "[web-root]/.eslintignore": "assets/.eslintignore",
+        "[web-root]/.eslintrc.json": "assets/.eslintrc.json",
+        "[web-root]/.gitattributes": "assets/.gitattributes",
+        "[web-root]/.ht.router.php": "assets/.ht.router.php",
+        "[web-root]/.htaccess": "assets/.htaccess",
+        "[web-root]/sites/default/default.services.yml": "assets/default.services.yml",
+        "[web-root]/sites/default/default.settings.php": "assets/default.settings.php",
+        "[web-root]/sites/example.settings.local.php": "assets/example.settings.local.php",
+        "[web-root]/sites/example.sites.php": "assets/example.sites.php",
+        "[web-root]/index.php": "assets/index.php",
+        "[web-root]/robots.txt": "assets/robots.txt",
+        "[web-root]/update.php": "assets/update.php",
+        "[web-root]/web.config": "assets/web.config"
+      }
+    }
+  }
+}
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-missing-scaffold-file/composer.json.tmpl b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-missing-scaffold-file/composer.json.tmpl
new file mode 100644
index 0000000000..e91c781e03
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-missing-scaffold-file/composer.json.tmpl
@@ -0,0 +1,65 @@
+{
+  "name": "my/project",
+  "type": "project",
+  "minimum-stability": "dev",
+  "prefer-stable": true,
+  "repositories": {
+    "drupal-scaffold": {
+      "type": "path",
+      "url": "__PROJECT_ROOT__",
+      "options": {
+        "symlink": true
+      }
+    },
+    "drupal-core-fixture": {
+      "type": "path",
+      "url": "../drupal-core-fixture",
+      "options": {
+        "symlink": true
+      }
+    },
+    "scaffold-override-fixture": {
+      "type": "path",
+      "url": "../scaffold-override-fixture",
+      "options": {
+        "symlink": true
+      }
+    },
+    "drupal": {
+      "type": "composer",
+      "url": "https://packages.drupal.org/8"
+    }
+  },
+  "require": {
+    "drupal/drupal-scaffold": "*",
+    "fixtures/drupal-core-fixture": "*",
+    "fixtures/scaffold-override-fixture": "*"
+  },
+  "extra": {
+    "composer-scaffold": {
+      "allowed-packages": [
+        "fixtures/drupal-core-fixture",
+        "fixtures/scaffold-override-fixture"
+      ],
+      "locations": {
+        "web-root": "./"
+      },
+      "symlink": __SYMLINK__,
+      "file-mapping": {
+        "[web-root]/.htaccess": false,
+        "[web-root]/robots.txt": "assets/missing-robots-default.txt"
+      }
+    },
+    "installer-paths": {
+      "core": ["type:drupal-core"],
+      "modules/contrib/{$name}": ["type:drupal-module"],
+      "modules/custom/{$name}": ["type:drupal-custom-module"],
+      "profiles/contrib/{$name}": ["type:drupal-profile"],
+      "profiles/custom/{$name}": ["type:drupal-custom-profile"],
+      "themes/contrib/{$name}": ["type:drupal-theme"],
+      "themes/custom/{$name}": ["type:drupal-custom-theme"],
+      "libraries/{$name}": ["type:drupal-library"],
+      "drush/Commands/contrib/{$name}": ["type:drupal-drush"]
+    }
+  }
+}
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal/assets/robots-default.txt b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal/assets/robots-default.txt
new file mode 100644
index 0000000000..6eb30e86aa
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal/assets/robots-default.txt
@@ -0,0 +1 @@
+# robots.txt fixture scaffolded from "file-mappings" in drupal-drupal composer.json fixture.
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal/composer.json.tmpl b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal/composer.json.tmpl
new file mode 100644
index 0000000000..dc026c6bfd
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal/composer.json.tmpl
@@ -0,0 +1,65 @@
+{
+  "name": "my/project",
+  "type": "project",
+  "minimum-stability": "dev",
+  "prefer-stable": true,
+  "repositories": {
+    "composer-scaffold": {
+      "type": "path",
+      "url": "__PROJECT_ROOT__",
+      "options": {
+        "symlink": true
+      }
+    },
+    "drupal-core-fixture": {
+      "type": "path",
+      "url": "../drupal-core-fixture",
+      "options": {
+        "symlink": true
+      }
+    },
+    "scaffold-override-fixture": {
+      "type": "path",
+      "url": "../scaffold-override-fixture",
+      "options": {
+        "symlink": true
+      }
+    },
+    "drupal": {
+      "type": "composer",
+      "url": "https://packages.drupal.org/8"
+    }
+  },
+  "require": {
+    "drupal/drupal-scaffold": "*",
+    "fixtures/drupal-core-fixture": "*",
+    "fixtures/scaffold-override-fixture": "*"
+  },
+  "extra": {
+    "composer-scaffold": {
+      "allowed-packages": [
+        "fixtures/drupal-core-fixture",
+        "fixtures/scaffold-override-fixture"
+      ],
+      "locations": {
+        "web-root": "./"
+      },
+      "symlink": __SYMLINK__,
+      "file-mapping": {
+        "[web-root]/.htaccess": false,
+        "[web-root]/robots.txt": "assets/robots-default.txt"
+      }
+    },
+    "installer-paths": {
+      "core": ["type:drupal-core"],
+      "modules/contrib/{$name}": ["type:drupal-module"],
+      "modules/custom/{$name}": ["type:drupal-custom-module"],
+      "profiles/contrib/{$name}": ["type:drupal-profile"],
+      "profiles/custom/{$name}": ["type:drupal-custom-profile"],
+      "themes/contrib/{$name}": ["type:drupal-theme"],
+      "themes/custom/{$name}": ["type:drupal-custom-theme"],
+      "libraries/{$name}": ["type:drupal-library"],
+      "drush/Commands/contrib/{$name}": ["type:drupal-drush"]
+    }
+  }
+}
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/scaffold-override-fixture/assets/override-settings.php b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/scaffold-override-fixture/assets/override-settings.php
new file mode 100644
index 0000000000..f37a684279
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/scaffold-override-fixture/assets/override-settings.php
@@ -0,0 +1,6 @@
+<?php
+
+/**
+ * @file
+ * This is a settings.php fixture file scaffolded from the scaffold-override-fixture.
+ */
diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/scaffold-override-fixture/composer.json b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/scaffold-override-fixture/composer.json
new file mode 100644
index 0000000000..977af8a76e
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/scaffold-override-fixture/composer.json
@@ -0,0 +1,10 @@
+{
+  "name": "fixtures/scaffold-override-fixture",
+  "extra": {
+    "composer-scaffold": {
+      "file-mapping": {
+        "[web-root]/sites/default/default.settings.php": "assets/override-settings.php"
+      }
+    }
+  }
+}
