Skip to content

Replace existing env validations from codemods

Latest

Choose a tag to compare

@github-actions github-actions released this 18 Oct 12:02
Immutable release. Only release title and notes can be modified.

This release lets packages replace an env validation that already exists in start/env.ts. It also fixes invalid code generated next to trailing comments, and speeds up route invalidation.

Features

defineEnvValidations accepts a new overwrite option. When it is enabled, the validation of a variable already defined in start/env.ts is replaced instead of being kept. Comments around the existing validation are preserved. The option is off by default, so validations edited by users are kept. Configure hooks can pass their --force flag to it.

await codemods.defineEnvValidations({
  leadingComment: 'Variables for configuring session package',
  overwrite: command.force,
  variables: {
    SESSION_DRIVER: `Env.schema.enum(['redis'] as const)`,
  },
})

Before this change, running node ace configure @adonisjs/session --force --store=redis regenerated config/session.ts but left the old SESSION_DRIVER enum in place, which broke type-checking.

defineEnvValidations now also returns the variables that were kept with a different validation, because overwrite was not enabled. Variables whose validation is already identical are left out, ignoring whitespace, so callers can warn users without producing noise on repeated runs.

Fixes

Adding a validation no longer produces a double comma (PORT: Env.schema.number(),,) when the last property of Env.create has a trailing comma and is followed by a comment block. This happened when a variable was removed by hand and its leading comment was left behind.

Performance

Route invalidation now parses a controller once for all of its routes, instead of once per route (#117).

Dependencies

ip-address was updated to 10.7.2 (#116).