Link Search Menu Expand Document

Packages Configuration in Root

Sometimes when building a project with several dependencies, we might have the need to change the Composer Assets Compiler behavior for installed dependencies.

That might include:

  • compile assets for packages that don’t have Composer Assets Compiler configuration
  • don’t compile assets for packages that have Composer Assets Compiler configuration
  • change packages’ Composer Assets Compiler configuration

All the above can be obtained with configuration in the root package via a packages setting.

Add or change configuration

Let’s take the example:

{
  "extra": {
    "composer-asset-compiler": {
      "packages": {
        "acme/something": {
          "script": "build",
          "package-manager": "yarn"
        }
      }
    }
  }
}

In the above example, we have provided configuration for the "acme/something" package. If that package didn’t have any configuration, we’ve now added it. If that package had any configuration, we’ve overwritten it.

Disable packages processing

We can prevent Composer Assets Compiler to process packages that have some configuration by setting to false their in the packages property.

{
  "extra": {
    "composer-asset-compiler": {
      "packages": {
        "acme/something": false
      }
    }
  }
}

Patterns

Packages’ settings might be set also via patterns, for example:

{
  "extra": {
    "composer-asset-compiler": {
      "packages": {
        "acme/*": false
      }
    }
  }
}

Defaults

More often than not, when defining Composer Assets Compiler configuration in the root package, the configuration is the same for all packages. That means we’re going to have a lot of duplication.

For example:

{
  "extra": {
    "composer-asset-compiler": {
      "packages": {
        "acme/foo": {
          "script": "build",
          "package-manager": "yarn"
        },
        "acme/bar": {
          "script": "build",
          "package-manager": "yarn"
        },
        "acme/baz": {
          "script": "build",
          "package-manager": "yarn"
        }
      }
    }
  }
}

In such cases, Composer Assets Compiler allow us to have a more compact configuration via the usage of defaults.

For example:

{
  "extra": {
    "composer-asset-compiler": {
      "defaults": {
        "script": "build",
        "package-manager": "yarn"
      },
      "packages": {
        "acme/*": "$force-defaults",
        "foo/bar": true
      }
    }
  }
}

Above, we have defined the configuration once in the "defaults" property, and then instructed Composer Assets Compiler to use that configuration for the listed packages.

To do that, for each package we can use either "$force-defaults" or true.

  • true means: “if the package has a configuration, use it, otherwise use the defaults”
  • $force-defaults means: “process the assets for this package always using defaults”

Root package is a package

Please note that the root package is a package. Which means it might have assets to compile, and so it supports “normal” Composer Assets Compiler such as "script", "dependencies", and such.

{
  "extra": {
    "composer-asset-compiler": {
      "script": "build",
      "package-manager": "yarn",
      "defaults": {
        "script": "build",
        "package-manager": "yarn"
      },
      "packages": {
        "acme/foo": "$force-defaults",
        "acme/bar": "$force-defaults"
      }
    }
  }
}

Root-only

By default, when the root package have dependencies listed in packages property, it will process them in addition to packages that have configuration defined at package level.

It might be desirable to compile only packages listed in the packages property (if any), beside the root package’s assets.

To obtain that, it is possible to use the auto-discover setting with a value of false.

Root “default-env”

In the “Script” chapter, we have seen how it is possible to define default values for environment variables used in script via the default-env setting.

Root package is a package, so we can have a default-env setting also in root package.

However, default-env defined in the root package has a “special” meaning, because it would provide a default also for dependencies, in the case dependencies don’t define default-env for missing environment variables.