Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Smart Features

Sketch provides some additional features that may come in handy when dealing with a typescript project.

Converting latest to a range

When the npm-versions feature is enabled, by default, all versions marked as latest will be converted to a version range (minor by default, but can be customized) that starts from the actual latest version for that package.

This means that you can easily reuse your presets over time to start new projects, without needing to manually bump all versions, and while also avoiding latest, which is not suitable for stability.

Sketch uses the npm api to fetch the latest version for any given package. It sends a maximum of 10 parallel requests, but depending on how many requests are made in a given timeframe, you might still be rate limited by the api, causing an error.

typescript:
  # Default
  no_convert_latest_to_range: false

  # Default
  version_range: minor

Adding dependencies to the catalog

If you set up your package manager to be pnpm (which is the default) or bun and set catalog to true, whenever you try to generate a new package that has dependencies marked with catalog:, each package that is not present in the target catalog (inside pnpm-workspace.yaml for pnpm, and inside package.json for bun) will be added automatically to it.

Example

Let's say that we are starting with a basic pnpm-workspace.yaml config like this one:

  pnpm_presets:
    base:
      # All the dirs listed here will be created automatically
      # when new monorepos are created
      packages:
        - packages/*
      onlyBuiltDependencies:
        - esbuild
      minimumReleaseAge: 1440

and we generate a package that has catalog dependencies, which are currently absent from their target catalogs:

typescript:
  no_default_deps: true

  catalog: true

  # Default
  package_manager: pnpm

  package_presets:
    with_catalog:
      name: with_catalog
      package_json:
        devDependencies:
          # Named catalog
          svelte: catalog:svelte
          # Default catalog
          hono: "catalog:"

After running

sketch ts package --preset with_catalog with-catalog

We can see that the pnpm-workspace.yaml file has been updated with the new named catalog and dependencies:

packages:
- packages/*
catalog:
  hono: ^4.11.9
catalogs:
  svelte:
    svelte: ^5.51.2
onlyBuiltDependencies:
- esbuild
minimumReleaseAge: 1440