Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Build breaking after adding bun adapter #6059

Closed
wants to merge 2 commits into from
Closed

fix: Build breaking after adding bun adapter #6059

wants to merge 2 commits into from

Conversation

Twiggeh
Copy link
Contributor

@Twiggeh Twiggeh commented Mar 27, 2024

Overview

What is it?

  • Feature / enhancement
  • Bug
  • Docs / tests / types / typos

Description

Issue
When running the adapter for adding bun, it misses adding the types to tsconfig.json (this is also not detailed in the documentation for bun). When these types are missing the build fails.

I used lodash to do a deep merge over the jsons, I am sorry if there was another merging mechanism in place. I only found @typescript-eslint/utils which had a deepMerge, but that balooned the output of the cli.js to over 110k lines, so I opted to use lodash instead, which already is a peer dependency.

Use cases and why

  • I don't expect to check which files the cli didn't modify after adding the adapter

Checklist:

  • My code follows the developer guidelines of this project
  • I have performed a self-review of my own code
  • [-] I have made corresponding changes to the documentation
  • [-] Added new tests to cover the fix / functionality

I tried the existing utility (@typescript-eslint/utils) for merging, but that balloned the cli.js to
110k lines, so I chose to use lodash for the merge, as it was already a peer dependency. I am sorry
if there was another merging utility already in place, I didn't find it :(

fix #6058
Copy link

netlify bot commented Mar 27, 2024

👷 Deploy request for qwik-insights pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 18200bb

@Twiggeh Twiggeh changed the title Fix Build breaking after adding bun adapter Fix: Build breaking after adding bun adapter Mar 27, 2024
@Twiggeh Twiggeh changed the title Fix: Build breaking after adding bun adapter fix: Build breaking after adding bun adapter Mar 27, 2024
Copy link
Member

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Twiggeh for your help

@@ -0,0 +1,3 @@
{
"compilerOptions": { "types": ["bun-types"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent the extra dependency we can define all the "types" (dafault + bun ) in the bun tsconfig.json
This revert some of your changes as well

Copy link
Contributor

@octet-stream octet-stream Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or types can be moved into a .d.ts file instead, like in Nuxt or Remix and then referenced in includes field. This way typescript will be able to pick types from $PWD/node_modules/@types. Also, this way TypeScript should pick bun types from @types/bun package without any additional configuration

See the documentation: https://www.typescriptlang.org/tsconfig#types

If types field specified, then TS won't pick anything that is not included in the list:

This tsconfig.json file will only include ./node_modules/@types/node, ./node_modules/@types/jest and ./node_modules/@types/express. Other packages under node_modules/@types/* will not be included.

So my suggestion is to create a file, let's call it qwik.env.d.ts for example, where we reference vite/client types, and then add it to the includes.

The template would look like this:

In qwik.env.d.ts:

/// <reference types="vite/client" />

Then in tsconfig.json:

{
  "include": ["qwik.env.d.ts", "**/*.ts", "**/*.tsx"]
}

Then for those who want to keep using bun-types (as they might be updated more frequently, aligned with the runtime releases) instead of @types/bun, they can just remove @types/bun after they installed the adapter and reference bun-types same way in qwik.env.d.ts

@@ -97,6 +98,7 @@
"execa": "8.0.1",
"express": "4.18.3",
"install": "^0.13.0",
"lodash": "^4.17.21",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no smaller dependency? Or just few lines of helper code?

At the very least you should use lodash-es

@@ -86,11 +87,15 @@ async function mergeJsons(fileUpdates: FsUpdates, srcPath: string, destPath: str
try {
const srcPkgJson = JSON.parse(srcContent);
const destPkgJson = JSON.parse(await fs.promises.readFile(destPath, 'utf-8'));
Object.assign(srcPkgJson, destPkgJson);
const mergedJson = mergeWith(srcPkgJson, destPkgJson, (value, srcValue) => {
if (Array.isArray(value)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems dangerous to do for unknown fields

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants