Writing custom Task runner using esm modules and/or typescript.
- [ ] I'd be willing to implement this feature (contributing guide)
Description
I'm using custom tasks runner in order to customize cache. And it works fine, but I see 2 issues
-
it only supports cjs modules. Because uses
requireimport. -
I don't want to publish my plugin for my perspective it should be local. Could Nx support executor written on TS?
How I currently reference plugin in nx.json
"tasksRunnerOptions": {
"default": {
"runner": "./libs/nx-task-runner",
"options": {
"captureStderr": true
}
}
},
libs/nx-task-runner/package.json content:
...
"main": "lib/index.js",
...
Motivation
Publishing task runner package is additional step and slows down the process of making any changes in it.
Suggested Implementation
Probably somehow using ts-node will help to launch code from ts package.
Alternate Implementations
¯\(ツ)/¯
ESM support for plugins is tracked here: #15682, no ETA on that. We could look into typescript for the tasks runner though, could be interesting.
Temporary solution, add a script to your package.json to compile it from TS to JS and commit:
"scripts": {
"build:custom-runner": "tsc tools/task-runners/custom-runner/index.ts",
@khludenevav you can register runtime ts transpiler(ts-node or swc) via index.js like
require('ts-node').register({ /* options */ });
module.exports = require('./src/index.ts');