0.1.1 • Published 7 months ago

@rnx-kit/tools-typescript v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@rnx-kit/tools-typescript

Build npm version

🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧

THIS TOOL IS EXPERIMENTAL — USE WITH CAUTION

🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧

A package that helps with building typescript, particularly for react-native. It leverages the @rnx-kit/typescript-service package to build using the language service rather than using the compiler directly. This allows for custom resolution strategies (among other things). The compilation and type-checking are still done by typescript but this drives some convenient custom configurations.

In particular the buildTypeScript command can do things like:

  • multiplex a build in a directory, to build for multiple react-native platforms at the same time. The files will be split such that the minimal build can be performed.
  • detect which react-native platforms should be built based on rnx-kit bundle configs or react-native.config.js settings.
  • successfully build with the module suffixes without throwing up a ton of bogus unresolved reference errors.
  • share caches where possible to speed up compilations within the same node process.

Motivation

The current story for building typescript for react-native is sub-par, and typescript itself is particularly restrictive with module resolution. This addresses the ability to build react-native better right now, but also creates a framework for experimenting with different resolvers.

Things to do

  • Look at watch mode behavior, add invalidation for caching layers
  • Look at routing host creation in metro-plugin-typescript through here
  • Evaluate alternative resolvers

Installation

yarn add @rnx-kit/tools-typescript --dev

or if you're using npm

npm add --save-dev @rnx-kit/tools-typescript

Usage

CategoryType NameDescription
typesAsyncThrottlerInterface for capping the max number of async operations that happen at any given time. This allows for multiple AsyncWriter instances to be used in parallel while still limiting the max number of concurrent operations
typesAsyncWriterInterface for handling async file writing. There is a synchronous write function then a finish function that will wait for all writes to complete
typesBuildOptionsOptions that control how the buildTypeScript command should be configured
typesPlatformInfoInformation about each available platform
typesReporterInterface for reporting logging and timing information
CategoryFunctionDescription
buildbuildTypeScript(options)Execute a build (or just typechecking) for the given package. This can be configured with standard typescript options, but can also be directed to split builds to build and type-check multiple platforms as efficiently as possible.
filescreateAsyncThrottler(maxActive, rebalanceAt)Creates an AsyncThrottler that can be used to limit the number of concurrent operations that happen at any given time.
filescreateAsyncWriter(root, throttler, reporter)Create an AsyncWriter that can be used to write files asynchronously and wait on the results
hostopenProject(context)Open a typescript project for the given context. Can handle react-native specific projects and will share cache information where possible given the configuration
platformsloadPkgPlatformInfo(pkgRoot, manifest, platformOverride)Load platform info for available platforms for a given package
platformsparseSourceFileDetails(file, ignoreSuffix)Take a file path and return the base file name, the platform extension if one exists, and the file extension.
reportercreateReporter(name, logging, tracing)Create a reporter that can log, time, and report errors