Skip to content

Commit d0e2c43

Browse files
Izhakiaurelien-reevesdavidjgoss
authored
Docs: Better typescript cli docs (cucumber#1382)
* Docs: Better typescript cli docs * Reorganize docs/cli transpilation chapter * Update docs/cli.md Co-authored-by: David Goss <[email protected]> Co-authored-by: aurelien-reeves <[email protected]> Co-authored-by: David Goss <[email protected]>
1 parent 1109951 commit d0e2c43

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ node_modules
1111
tmp/
1212
usage.txt
1313
yarn-error.log
14+
.vscode

docs/cli.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,31 +174,43 @@ For instance, for ES6 support with [Babel](https://babeljs.io/) 7 add:
174174

175175
This will effectively call `require('@babel/register')` prior to requiring any support files.
176176

177-
### Non JS files
177+
If your files end with an extension other than `js`, make sure to also include the `--require` option to state the required support files. For example, if using [CoffeeScript](https://www.npmjs.com/package/coffeescript):
178178

179-
If your files end in an extension other than `js`, make sure to also include the `--require` option to state the support files to require.
179+
```
180+
--require-module coffeescript/register --require 'features/**/*.coffee'
181+
```
182+
183+
### Typescript
180184

181-
For example, with [TypeScript](https://www.typescriptlang.org/):
185+
#### With ts-node
186+
187+
If you are using [ts-node](https://github.com/TypeStrong/ts-node):
182188

183189
```
184190
--require-module ts-node/register --require 'step-definitions/**/*.ts'
185191
```
186192

187-
or [CoffeeScript](https://www.npmjs.com/package/coffeescript):
193+
> ⚠️ Some TypeScript setups use `esnext` modules by default,
194+
> which doesn't marry well with Node. You may consider using commonjs instead.
195+
> See how to add [extra configuration](#extra-configuration) below.
196+
197+
#### With babel
198+
199+
If you are using babel with [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript):
188200

189201
```
190-
--require-module coffeescript/register --require 'features/**/*.coffee'
202+
--require-module @babel/register --require 'step-definitions/**/*.ts'
191203
```
192204

193-
### Extra configuration
205+
### Extra Configuration
194206

195-
Sometimes the required module (say `@ts-node/register`) needs extra configuration (e.g. you might want to configure it such that it prevents the compiled JS being written out to files, and pass some compiler options). In such cases, create a script (say, `tests.setup.js`):
207+
Sometimes the required module (say `@ts-node/register`) needs extra configuration. For example, you might want to configure it such that it prevents the compiled JS being written out to files, and pass some compiler options. In such cases, create a script (say, `tests.setup.js`):
196208

197209
```js
198210
require('ts-node').register({
199211
transpileOnly: true,
200212
compilerOptions: {
201-
// your compiler options here
213+
"module": "commonjs",
202214
},
203215
});
204216
```

0 commit comments

Comments
 (0)