Skip to main content

JSON-only directives

If you want to use a JSON file, such as package.json, jko provides JSON-only directives—$extends and $installs—in addition to the script directives. Essentially, these directives ensure compatibility by allowing definitions from alternative sources to be used.

JSON-only Configuration:

  • $extends – Enables extending scripts from external sources.
  • $installs – Defines dependencies that should be installed automatically.
Using JSON-only Configuration Directives
 "$directiveName": "value"
warning

They are exclusively available when using .json file.

While these are provided for compatibility purposes, it is recommended to use jko.js instead.

$extends

To extend scripts in JSON, use the $extends directive, which allows you to inherit scripts from an external source.

{
"scripts": {
"$extends": "./path/to/script.js"
}
}
  • The external file contains predefined scripts that will be incorporated into the current configuration.
  • This ensures reusability and modular script management across multiple configurations.
info

File can be any .js, .mjs, .cjs or .json file.

warning

The file path must start with /, ./, or ../.

To extend from a package:

{
"scripts": {
"$extends": "somePackageName"
}
}
warning

The package must be available, i.e. it must be installed first.

danger

When jko is installed globally, only global packages will be available.

Solutions:


$installs

To set dependencies from an external source, use the $installs directive within the scripts object. This directive allows you to specify the file or package that contains the dependency definitions.

{
"scripts": {
"$installs" : "./some/path/dependencies.js",
}
}
info

File can be any .js, .mjs, .cjs or .json file.

warning

The file path must start with /, ./, or ../.

To use a package:

{
"scripts": {
"$installs" : "somePackageName",
}
}
warning

The package must be available, i.e. it must be installed first.

warning

For the specified $installs, only dependencies and devDependencies are parsed for installation; the packageManager setting is ignored. If you require a package manager other than the default, please use alternative configuration methods.

Was this content valuable?