Skip to content

Commit

Permalink
Merge pull request #721 from Financial-Times/node-watch
Browse files Browse the repository at this point in the history
Node watch
  • Loading branch information
apaleslimghost authored Dec 2, 2024
2 parents c750eb3 + 41e6a62 commit c84315e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 6 additions & 0 deletions lib/schemas/src/tasks/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export const NodeSchema = z
.default([3001, 3002, 3003])
.describe(
"ports to try to bind to for this application. set to `false` for an entry point that wouldn't bind to a port, such as a worker process or one-off script."
),
watch: z
.boolean()
.optional()
.describe(
'run Node in watch mode, which restarts your application when the entrypoint or any imported files are changed. **nb** this option is experimental in versions of Node before v20.13.'
)
})
.describe('Run a Node.js application for local development.')
Expand Down
13 changes: 7 additions & 6 deletions plugins/node/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ plugins:
Run a Node.js application for local development.
#### Task options

| Property | Description | Type | Default |
| :----------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------- | :------------------ |
| `entry` | path to the node application | `string` | `'./server/app.js'` |
| `args` | additional arguments to pass to your application | `Array<string>` | |
| `useDoppler` | whether to run the application with environment variables from Doppler | `boolean` | `true` |
| `ports` | ports to try to bind to for this application. set to `false` for an entry point that wouldn't bind to a port, such as a worker process or one-off script. | `Array<number> \| false` | `[3001,3002,3003]` |
| Property | Description | Type | Default |
| :----------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------- | :------------------ |
| `entry` | path to the node application | `string` | `'./server/app.js'` |
| `args` | additional arguments to pass to your application | `Array<string>` | |
| `useDoppler` | whether to run the application with environment variables from Doppler | `boolean` | `true` |
| `ports` | ports to try to bind to for this application. set to `false` for an entry point that wouldn't bind to a port, such as a worker process or one-off script. | `Array<number> \| false` | `[3001,3002,3003]` |
| `watch` | run Node in watch mode, which restarts your application when the entrypoint or any imported files are changed. **nb** this option is experimental in versions of Node before v20.13. | `boolean` | |

_All properties are optional._
<!-- end autogenerated docs -->
13 changes: 12 additions & 1 deletion plugins/node/src/tasks/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ export default class Node extends Task<{ task: typeof NodeSchema }> {
let dopplerEnv = {}

if (useDoppler) {
const doppler = new DopplerEnvVars(this.logger, 'dev', config.pluginOptions['@dotcom-tool-kit/doppler']?.options)
const doppler = new DopplerEnvVars(
this.logger,
'dev',
config.pluginOptions['@dotcom-tool-kit/doppler']?.options
)

dopplerEnv = await doppler.get()
}

const execArgv = [...process.execArgv]

if (this.options.watch) {
execArgv.push('--watch')
}

const port = ports
? Number(process.env.PORT) ||
(await getPort({
Expand All @@ -34,6 +44,7 @@ export default class Node extends Task<{ task: typeof NodeSchema }> {
PORT: port.toString(),
...process.env
},
execArgv,
silent: true,
cwd
})
Expand Down

0 comments on commit c84315e

Please sign in to comment.