How to use the command 'turbo' (with examples)

How to use the command 'turbo' (with examples)

The ’turbo’ command is a high-performance build system for JavaScript and TypeScript codebases. It provides a streamlined way to build projects, run tasks, and manage dependencies. In this article, we will explore various use cases of the ’turbo’ command with examples.

Use case 1: Log in using the default web browser with a Vercel account

Code:

turbo login

Motivation: The ’turbo login’ command allows you to log in to your Vercel account using the default web browser. This is useful when you want to authenticate and access the features and services provided by Vercel.

Explanation: The ’turbo login’ command opens the default web browser and prompts you to log in to your Vercel account. Once you provide your credentials and successfully log in, you will be able to access Vercel’s features and services.

Example output:

Opening default web browser to log in...
Successfully logged in!

Code:

turbo link

Motivation: The ’turbo link’ command is used to link the current directory to a Vercel organization. This allows you to associate your project with a Vercel team or organization, enabling collaboration and remote caching for faster build times.

Explanation: When you run the ’turbo link’ command, it establishes a connection between the current directory and a Vercel organization. This association allows you to leverage the remote caching feature, which can significantly improve build times by reusing previously built artifacts.

Example output:

Successfully linked current directory to Vercel organization.
Remote caching enabled.

Use case 3: Build the current project

Code:

turbo run build

Motivation: The ’turbo run build’ command is used to build the current project. Building a project involves compiling the source code, resolving dependencies, and generating the final output files.

Explanation: When you execute the ’turbo run build’ command, the build process is triggered. This involves invoking the build configuration defined in your project and generating the output files, which can be web assets like HTML, CSS, and JavaScript.

Example output:

Starting build process...
Build completed successfully.

Use case 4: Run a task without concurrency

Code:

turbo run task_name --concurrency=1

Motivation: Sometimes, you may need to run a task that requires exclusive access to resources and should not be run concurrently. The ‘–concurrency=1’ argument ensures that the task is executed in a non-concurrent manner.

Explanation: By specifying the ‘–concurrency=1’ argument, the ’turbo run’ command ensures that the task specified by ’task_name’ is executed without concurrency. This is useful when the task relies on shared resources or requires sequential execution.

Example output:

Running task 'task_name' with a concurrency level of 1...
Task completed successfully.

Use case 5: Run a task ignoring cached artifacts and forcibly re-execute all tasks

Code:

turbo run task_name --force

Motivation: In certain scenarios, you may want to ignore cached artifacts and force the re-execution of all tasks. The ‘–force’ argument ensures that all tasks are executed from scratch, disregarding any previously cached artifacts.

Explanation: When you append the ‘–force’ argument to the ’turbo run’ command, it instructs the build system to ignore any cached artifacts and forcibly re-execute all tasks involved in the build process. This can be useful when you want to ensure a completely clean build.

Example output:

Forcing re-execution of all tasks...
Task 'task_name' completed successfully.

Use case 6: Run a task in parallel across packages

Code:

turbo run task_name --parallel --no-cache

Motivation: Running a task in parallel across packages can improve build performance by utilizing all available CPU cores. The ‘–parallel’ argument enables parallel execution, and the ‘–no-cache’ argument disables the use of cached artifacts.

Explanation: By using the ‘–parallel’ argument, the ’turbo run’ command executes the specified task, ’task_name’, in parallel across multiple packages in your codebase. This maximizes the utilization of CPU cores, speeding up the overall build process. The ‘–no-cache’ argument ensures that no cached artifacts are used during the parallel execution.

Example output:

Running task 'task_name' in parallel across packages...
Task completed successfully.

Code:

turbo unlink

Motivation: The ’turbo unlink’ command is used to unlink the current directory from a Vercel organization. This is helpful when you want to disassociate your project from a specific Vercel team or organization and disable remote caching.

Explanation: When you execute the ’turbo unlink’ command, it removes the association between the current directory and the Vercel organization. This prevents any further collaboration and disables remote caching, resulting in slower build times.

Example output:

Successfully unlinked current directory from Vercel organization.
Remote caching disabled.

Use case 8: Generate a Dot graph of a specific task execution

Code:

turbo run task_name --graph=path/to/file.html|jpg|json|pdf|png|svg

Motivation: The ’turbo run task_name –graph’ command allows you to generate a visualization of a specific task’s execution using the Dot graph format. This can help you analyze the dependencies and flow of the task in a graphical format.

Explanation: By specifying the ‘–graph=path/to/file.html|jpg|json|pdf|png|svg’ argument, the ’turbo run’ command generates a Dot graph representing the execution of the specified task, ’task_name’. The format of the output file can be controlled by specifying the desired extension, such as ‘html’, ‘jpg’, ‘json’, ‘pdf’, ‘png’, or ‘svg’. This graph can provide valuable insights into the task’s execution flow and dependencies.

Example output:

Generating Dot graph of task 'task_name'...
Dot graph saved to 'path/to/file.png'.

Conclusion:

In this article, we have explored different use cases of the ’turbo’ command. From logging into a Vercel account to running tasks with various options and generating visualization graphs, the ’turbo’ command offers a wide range of functionalities for building JavaScript and TypeScript codebases efficiently. By understanding these use cases and their corresponding commands, you can leverage ’turbo’ to streamline your development workflow and optimize your project builds.

Related Posts

How to use the command 'unlink' (with examples)

How to use the command 'unlink' (with examples)

The unlink command is used to remove a link to a file from the filesystem.

Read More
How to use the command unsquashfs (with examples)

How to use the command unsquashfs (with examples)

Unsquashfs is a command-line tool used to uncompress, extract, and list files in squashfs filesystems.

Read More
How to use the command ksvgtopng5 (with examples)

How to use the command ksvgtopng5 (with examples)

The ksvgtopng5 command is a utility that allows you to convert Scalable Vector Graphics (SVG) files to Portable Network Graphics (PNG) format.

Read More