react-notion-x icon indicating copy to clipboard operation
react-notion-x copied to clipboard

#429 Migrate to turbo and pnpm

Open FranciscoMoretti opened this issue 2 years ago • 2 comments
trafficstars

Description

Replaced Lerna and Yarn with Turbo and Pnpm.

Changes:

  • More tsup and less tsc
    • tsup is the recommended tool in turbo docs
    • tsup --watch replaces all the watch tasks. It automatically re-builds a package when in development tasks. Docs
    • tsup now generates the type definitions with the config dts: true on tsup.config.ts Docs
  • tsconfig's composite is not supported by tsup, so I've changed it to false https://github.com/egoist/tsup/issues/571.
    • This is also the recommended config on the turbo docs
  • dependencies are linked internally with "workspace:*". They should get replaced by the actual version when publishing Pnpm workspaces.
  • Documentation updates (Readme files)
  • Organized tasks to match turborepo pattern
    • This pattern parallelizes tasks and only runs what's needed turbo tasks docs
    • Lint tasks moved to each workspace. turbo linting docs
    • Test task dependencies coordinated through turbo pipeline (turbo.json)
    • "pre" tasks are defined in pipeline as dependencies. Therefore, they were removed from package.json
    • publish tasks moved to workspaces and dependencies defined in turbo.json.
      • Defined dependencies only for workspaces that use publish because of this bug https://github.com/vercel/turbo/issues/2988
  • Renamed deploy task to vercel-deploy in examples to avoid confusion with pnpm deploy
    • Now running pnpm vercel-deploy and pnpm run vercel-deploy are valid from an example directory
    • The alternative is to keep the deploy name but that would only work with pnpm run deploy because pnpm deploy is an existent pnpm command.
  • Configured tasks caches with turbo caching.

Benefits

This change has the following advantages:

  • Simplifies processes: E.g. You can now run dev with a single command
  • Faster re-builds: Turbo auto caches builds per package
  • Faster builds, lint, test: Turbo runs things in parallel whenever possible
  • Faster re-installs: Pnpm auto caches node modules
  • Modern tools: Using these new tools is a better developer experience overall and they have better documentation.

Turbo Examples

The configuration was inspired by Turborepo official examples

  • Basic example: https://github.com/vercel/turbo/tree/main/examples/basic

  • CRA example: https://github.com/vercel/turbo/tree/main/examples/with-create-react-app

  • Kitchen sink example; https://github.com/vercel/turbo/tree/main/examples/kitchen-sink

  • This bugfix was needed for a correct build of notion-x-example-full https://github.com/NotionX/react-notion-x/pull/459

Tests

[x] Installing

pnpm i

[x] Running a global build:

turbo build

[x] Running a build from the package dir

cd packages/notion-utils
pnpm build

[x] Running every dev task

turbo dev

[x] Running tests execute unit eslint and prettier.

turbo test

[x] Running dev in a single example, modifying a dependency, and verifying it rebuilds it

turbo dev --filter=notion-x-example-minimal...

[x] Connecting with nextjs-notion-starter-kit.

  • yarn link and the contributing docs from that repo are still valid after this change https://github.com/transitive-bullshit/nextjs-notion-starter-kit/blob/main/contributing.md

[x] Running publish executed the correct tasks

turbo publish

[x] Running vercel deploy

cd examples/minimal
pnpm run vercel-deploy

[x] The cache works as expected in all tasks

FranciscoMoretti avatar Apr 08 '23 09:04 FranciscoMoretti

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
react-notion-x ❌ Failed (Inspect) Apr 8, 2023 9:45am
react-notion-x-minimal-demo ❌ Failed (Inspect) Apr 8, 2023 9:45am

vercel[bot] avatar Apr 08 '23 09:04 vercel[bot]

Feedback is encouraged. I had to make a few choices here and there and I'm unsure if they are the best.

Also, it seems like deployments are failing and I can't inspect or check details. @transitive-bullshit let me know if there is anything I can do to fix them.

FranciscoMoretti avatar Apr 08 '23 09:04 FranciscoMoretti