Coder Social home page Coder Social logo

bob's Introduction

Bob (The Bundler Butler)

Bob is the TypeScript build, bundle and verification tool used by almost all The Guild open source projects.

Scope:

  • Build: Build ESM and CommonJS compatible npm packages
  • Verify: Ensure all ESM and CommonJS imports within a npm package are usable
  • Bundle: Build a single executable for an application (experimental)

Requirements

  • Yarn workspace or single package project
  • TypeScript
  • It's so strict you shouldn't use it!

Setup

Setting up bob is currently undocumented. You can check GraphQL Code Generator repository (or any other The Guild repository).

Configuration

You can add a bob key to each package.json.

Disable bob for a single package

{
  "name": "graphql-lfg",
  "bob": false // exclude a single package from all things bob related
}

Disable build for a single package

{
  "name": "graphql-lfg",
  "bob": {
    "build": false
  }
}

Disable check for a single package

{
  "name": "graphql-lfg",
  "bob": {
    "check": false
  }
}

Disable check for a single export in a package

{
  "name": "graphql-lfg",
  "bob": {
    "check": {
      "skip": ["./foo"]
    }
  }
}

Usage

$ bob build
$ bob check

bob's People

Contributors

adriencohen avatar ardatan avatar dependabot[bot] avatar dimamachina avatar dotansimha avatar enisdenjo avatar gilgardosh avatar github-actions[bot] avatar kamilkisiela avatar n1ru4l avatar pabloszx avatar renovate[bot] avatar saihaj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bob's Issues

multi entrypoint support

having a package.json with multiple entrypoints defined is currently not possible:

{
  "exports": {
    ".": {
      "require": "./dist/index.cjs.js",
      "default": "./dist/index.mjs"
    },
    "./client": {
      "require": "./dist/client/index.cjs.js",
      "default": "./dist/client/index.mjs"
    },
    "./package.json": "./package.json"
  }
}

Maybe the exports map could also be auto-generated via the buildConfig.import option?

{
  "buildOptions": {
    "input": {
      "./": "./src/index.ts",
      "./client": "./client/index.ts"
    }
  },
}

Only build commonjs

It is currently possible to only build esm - it should also be possible to only build cjs.

support object workspaces property

"workspaces": {
  "packages": ["packages/*"],
  "nohoist": ["**/react-native", "**/react-native/**"]
}

Right now the bootstrap command can only deal with "workspaces": []. It should also be able to handle the object variant.

Runnify command fails on windows

Runnify command fails on windows

$ bob runnify --single
PrettyError: Cannot find C:\projects\hive\graphql-hive\packages\server\src\index.ts
    at normalizeOptions (C:\projects\hive\graphql-hive\node_modules\tsup\dist\index.js:1984:13)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async C:\projects\hive\graphql-hive\node_modules\tsup\dist\index.js:2014:21
    at async Promise.all (index 0)
    at async Object.build (C:\projects\hive\graphql-hive\node_modules\tsup\dist\index.js:2011:3)
    at async compile (C:\projects\hive\graphql-hive\node_modules\bob-the-bundler\dist\commands\runify.js:161:9)
    at async runify (C:\projects\hive\graphql-hive\node_modules\bob-the-bundler\dist\commands\runify.js:93:9) 

ESM/CJS resolution tests

When having a mono-repository it would be great to have a way of verifying that the loaded module tree is either pure ESM or pure CommonJS in order to prevent weird inter-op behavior.

integrity test strategy for CLI and "magic" packages

Some node_modules can raise errors when being required/imported outside a specific context.

One example of this is @jest/globals.

Error: Command failed with exit code 1: node -e require('/Users/laurinquast/Projects/graphql-code-generator/packages/utils/graphql-codegen-testing/dist/cjs/index.js');setTimeout(() => { throw new Error("The Node.js process hangs. There is probably some side-effects. All exports should be free of side effects.") }, 500).unref()
/Users/laurinquast/Projects/graphql-code-generator/node_modules/@jest/globals/build/index.js:23
throw new Error(
^

Error: Do not import `@jest/globals` outside of the Jest test environment
    at Object.<anonymous> (/Users/laurinquast/Projects/graphql-code-generator/node_modules/@jest/globals/build/index.js:23:7)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/laurinquast/Projects/graphql-code-generator/packages/utils/graphql-codegen-testing/dist/cjs/index.js:9:19)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at makeError (/Users/laurinquast/Projects/graphql-code-generator/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/Users/laurinquast/Projects/graphql-code-generator/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /Users/laurinquast/Projects/graphql-code-generator/node_modules/bob-the-bundler/dist/commands/check.js:95:32

We need a strategy for testing these kinds of modules...


Related:

bob build should run tsc

Right now for a mono repository configuring typescript projects properly and running tsc is mandatory to setup.

For a single package repository running tsc is not mandatory right now, as it uses rollup directly.

We should unify both ways (and remove bundling altogether see #48).

As discussed with @kamilkisiela we wanna do it the following way:

When running bob build it should run tsc and before doing so validate whether the tsconfig is properly set up for what we do.
bob build runs tsc twice. Once for regular commonjs (modules: cjs) and once for esm (modules: node16).
After running tsc bob build should make sure all the files are moved to the right place (e.g. what already happens today).

Only ESM or only CJS build option

Some packages only need cjs or esm. Thus it should be possible to specify that via the package.json config.

{
  "name": "fooo",
  "bob": {
    "cjs": false,
  }
}

Setting these options should also change the assertions for the package.json exports map. E.g. if "cjs" is false, a require should not be present in the exports map.

Better integration test suite

Right now we need to test the bob functionality manually within our other repositories. Having a in-repo integration test suite would help us iterate faster as we receive feedback earlier and also ensures things don't break.

Add renovate

we need renovate for consistent dependency updates

TypeScript config validation

Bob should probably check the tsconfig.json file within the projects and then yell at you in case you are doing something you probably should not do.

In a lot of projects we use the tsconfig.json and tsconfig.build.json pattern, tsconfig.build.json could potentially be completely life within bob.

exports map and .mjs extension

It seems like there is no mjs build being made and further, the exports map is completely stripped from the published package, despite being defined inside the repo package.json: https://github.com/n1ru4l/graphql-live-query/blob/933bd6d4a9d1b28ff5a090dc203632b9bf876bac/packages/in-memory-live-query-store/package.json#L37-L40 vs https://unpkg.com/browse/@n1ru4l/[email protected]/package.json

Also, the published bundle does not contain a .mjs module file (only .esm.js) https://unpkg.com/browse/@n1ru4l/[email protected]/ if not provided even in an esm (aka node 14) environment the commonjs version will be loaded.

TL;DR: The published package should contain an index.mjs file and the package.json should have an exports map property (same asthe in-repo package.json).

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency vitest to v1
  • fix(deps): update dependency yargs to v17.7.2
  • fix(deps): update dependency consola to v3.2.3
  • fix(deps): update dependency fs-extra to v11.2.0
  • fix(deps): update dependency globby to v13.2.2
  • fix(deps): update dependency tslib to v2.6.2
  • chore(deps): update actions/cache action to v4
  • chore(deps): update pnpm to v9
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yaml
  • actions/checkout v3
  • pnpm/action-setup v2
  • actions/cache v3
.github/workflows/pr.yml
.github/workflows/release.yml
npm
package.json
  • consola ^3.0.0
  • execa 7.1.1
  • fs-extra ^11.1.0
  • globby ^13.1.3
  • js-yaml ^4.1.0
  • lodash.get ^4.4.2
  • p-limit ^4.0.0
  • resolve.exports ^2.0.0
  • tslib ^2.0.0
  • yargs ^17.6.2
  • zod ^3.20.2
  • @changesets/changelog-github 0.4.8
  • @changesets/cli 2.26.2
  • @theguild/prettier-config 1.1.3
  • @types/fs-extra 11.0.1
  • @types/js-yaml 4.0.5
  • @types/lodash.get 4.4.7
  • @types/node 18.17.4
  • @types/yargs 17.0.24
  • @typescript-eslint/parser 5.61.0
  • eslint 8.44.0
  • eslint-plugin-import 2.27.5
  • jest-resolve 29.5.0
  • jest-snapshot-serializer-raw 1.2.0
  • prettier 2.8.8
  • rimraf 5.0.1
  • typescript 5.1.6
  • vitest 0.32.4
  • typescript ^5.0.0
  • node >=16
  • pnpm >=8
  • pnpm 8.6.6

  • Check this box to trigger a request for Renovate to run again on this repository

Only types build option (or auto-detect)

When building packages that contain only types (like @envelop/types), the resolution fields in package.json should contain:

{
  "main": "",
  "types": "index.d.ts"
}

without resolutions for module and other exports.

This aligns with how DefinitelyTyped packs types.

Additionally, this improvement would eradicate false positives for linting tools that check re-exports (like here).

TypeScript compiler exited with non-zero exit code

I am getting an error that TypeScript compiler exited with non-zero exit code. Meantime, tsc -b works well

Also, I noticed that bob doesn't respect my tsconfig compiler options. Maybe I am doing something wrong, but I was referring to graphql-codegen repo

BTW. Thank you for this tool. It looks amazing, especially bob bootstrap command.

Rethink mandatory package.json property strategy

As a library maintainer that adds bob to an existing project, you will run bob build multiple times until you fixed all the errors it throws at you.

It might make sense to solve this by either

  1. have an onboarding command, which adds/updates all the required package.json entries
  2. have an "easy" mode, that adds the required package.json entries only in the dist/package.json file

bob bootstrap should use AST instead if regex

bob bootstrap uses a regex for rewriting import paths which sometimes hits wrong code. We should move it to run on AST (e.g. babel instead). Furthermore, it needs to leverage to file system for correctly rewriting file paths that point to an index.js file.

Revisit --single flag for the build command

When running bob build within a non-monorepository nothing happens and the std output is an empty string.

The user experience is that you run it multiple times until you figure out that you actually have to run bob build --single.

Do we really need the --single flag? Could we instead just detect whether we are within a multi or single-package repository?

`bob build --incremental` for faster builds

Currently bob deletes the build folder on every build. This is important to have a 100% working clean build. But doing a lot of build during development can slow you down significantly.

Most of the build time is consumed by TS. Since deleting the folder removes tsbuildinfo files too, TS cannot perform a faster optimised/incremental build.

Add --incremental build option to keep the build folder and leverage tsbuildinfo for faster TS builds.

better feedback formatting for integrity tests

bob check only prints a single import/require failure. Instead, it should collect all failures and then print a list.

It should also print a "โŒ" with the package name:

โœ” Checked integrity of '@graphql-codegen/introspection'.
โŒ Failed integrity check of '@graphql-codegen/introspection'.

Upgrade rollup

The current rollup version does not support the latest ECMAScript language features such as optional chaining.

"rollup": "2.75.6" should be the version we depend upon for now. We should even consider using caret version ranges instead of pinned version ranges for libraries that follow semantic versioning/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.