Skip to content

Commit

Permalink
docs(migration guide): explain what to do about this.options in custo…
Browse files Browse the repository at this point in the history
  • Loading branch information
apaleslimghost committed Jan 13, 2025
1 parent 0d4f2b4 commit 0103117
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions docs/migration-guides/v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,79 @@ tasks:

The keys in the `.toolkitrc.yml` are what determines the task name visible to Tool Kit, which was previously determined by the actual class name, so make sure they match.

### 2.2.3. Custom tasks with options

Your existing custom task may have been using `this.options` to reference options from your `.toolkitrc.yml`. Now that [we have separate plugin-wide and task-specific options](#12-move-options-to-optionsplugins), `this.options` in tasks refers to the task-specific options. You'll need to either change your task to reference `this.pluginOptions` to access the plugin-wide options, or move your `.toolkitrc.yml` options for your plugin to task-specific options. Which you choose depends on the use cases for your plugin's options:

<table>
<tr>
<th></th><th>task-specific options</th><th>plugin-wide options</th>
</tr>
<tr><td>when to use</td>
<td>options that could be different if the task could be reused for different use cases, e.g. a path to a config file</td>
<td>options that would be the same for every task in a plugin no matter when they're being run, e.g. a system code</td>
</tr>
<tr><td>

`.toolkitrc.yml`

</td><td>

```yml
options:
tasks:
CustomTask:
config: 'path/to/config.js'
commands:
build:local:
- CustomTask
build:ci:
- CustomTask:
config: 'path/to/ci-config.js'
```

</td><td>

```yml
options:
plugins:
'./tool-kit/custom-plugin':
systemCode: 'next-article'
```

</td></tr><tr><td>

your custom task

</td><td>

```js
class CustomTask extends Task {
run() {
// { config: "path/to/config.js" },
// or, if run from `build:ci`,
// { config: "path/to/ci-config.js" }
this.options
}
}
```

</td><td>

```js
class CustomTask extends Task {
run() {
// { systemCode: "next-article" }
this.pluginOptions
}
}
```

</td></tr></table>

It's possible to mix and match task-specific and plugin-wide options, so if you have some options that fall under one use case and some under the other, you should split the options up as appropriate.

### 2.3. Plugins with custom "placeholder" hooks

If you're defining a "placeholder hook" so that you have a custom Tool Kit command you can run, **this is no longer required**; commands can be defined in your repo's `.toolkitrc.yml`. A placeholder hook will look something like this:
Expand Down

0 comments on commit 0103117

Please sign in to comment.