Friday, February 2, 2024

AdonisJS version 6 is Released, This is the Change


In a significant stride towards modernization, AdonisJS has proudly released version 6, introducing a multitude of enhancements and refinements. The impetus behind this update was a strategic move to ESM (ECMAScript Modules) and a profound revamping of the IoC container, aiming for simplicity and reduced responsibilities.

This extensive overhaul transcended every facet of the framework, addressing longstanding issues, refining user experience, and reconstructing packages from the ground up.

Migrating to ESM:

The debate between ESM and CJS (CommonJS) has been a persistent theme among JavaScript developers. AdonisJS v6 unequivocally adopts ESM as it aligns with the specification. This strategic choice enables compatibility with the latest versions of packages and ensures access to vital security fixes.

Every new AdonisJS application in v6 will now utilize TypeScript and ESM, with backward compatibility allowing the incorporation of CJS packages.

Elimination of TypeScript Compiler Hooks:

AdonisJS v6 bids farewell to the TypeScript compiler hooks that were previously employed in v5. The reliance on these hooks for importing modules prefixed with the @ioc keyword is replaced with conventional JavaScript imports. This not only enhances compatibility with various JIT tools but also simplifies the overall process.

Type-Safe Routes and Controllers Binding:

Magic strings for binding controllers to routes have become obsolete in v6. Instead, developers can now directly import controllers and bind them to routes by reference, ushering in type-safe and error-resistant coding practices.

Type-Safe Named Middleware Reference:

In v6, the referencing of named middleware undergoes a type-safe transformation. Middleware is now defined by reference, providing improved type-safety compared to the string-based approach in AdonisJS v5.

Type-Safe AdonisRC File:

The configuration file (.adonisrc.json) transitions to a TypeScript-based file (adonisrc.ts). This evolution allows direct imports of service providers, commands, and preload files, facilitating enhanced TypeScript support and better IntelliSense.

Type-Safe Event Emitter:

AdonisJS v6 introduces type-safe event emitters by defining a list of known events through TypeScript interfaces. Additionally, class-based events provide a structured approach to encapsulating event identifiers and related data.

Vite Integration for Frontend Assets:

Embracing Vite as the standard for frontend applications, AdonisJS v6 delivers an official integration. While Webpack Encore remains supported for existing v5 projects, Vite is recommended for new endeavors.

New Scaffolding System and Codemods API:

The scaffolding system and Codemods API receive an overhaul, enhancing package configuration and resource scaffolding capabilities. This evolution ensures streamlined package setup and Ace command scaffolding.

New Validation Library - VineJS:

A fresh validation library, VineJS, takes the reins in AdonisJS v6, addressing limitations observed in the previous version. Offering enhanced speed and flexibility, VineJS supports the creation of custom rules and schema types for validating complex structures.

Framework-Agnostic Packages:

AdonisJS expands its horizon by introducing more framework-agnostic packages, fostering compatibility with various Node.js frameworks. Noteworthy packages include Japa, Edge, VineJS, Bento Cache, and Verrou.

Improved Documentation:

AdonisJS v6 rectifies documentation lapses witnessed in its predecessor. Comprehensive coverage of IoC container usage, Edge helpers, available commands, events, and exceptions is now available. The documentation also delves into creating and testing commands, extending the framework, HTTP request flow, middleware usage, and more.

Enhanced Testing Experience:

Testing remains a top priority for AdonisJS, reflected in the provision of first-class assertion APIs for testing emitted events. The framework now facilitates testing Ace commands, logger output assertions, and the trapping of prompts. Browser tests using Playwright are also supported, along with a dedicated VSCode extension for running Japa tests seamlessly.

Changes to Folder Structure:

While 80% of the folder structure remains consistent with v5, AdonisJS v6 adopts snake_case for file and folder naming. This decision is aligned with established conventions, providing clarity and consistency.

MJML Support and Additional Mail Transports:

The @adonisjs/mail package gains momentum with added transports for Resend and Brevo mail services. MJML support is introduced through the @mjml Edge tag, offering a convenient way to craft email content using the MJML markup language.

Sunsetting Packages:

Several packages, such as @adonisjs/encore, @adonisjs/validator, @adonisjs/sink, @adonisjs/require-ts, and @adonisjs/view, are gracefully sunsetted with the advent of AdonisJS v6. Users are encouraged to transition to the recommended alternatives, ushering in a more streamlined and optimized ecosystem.

Various additional changes mark the v6 release, including support for loading additional

0 comments:

Post a Comment