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

Different behaviour when using Bun's runtime #661

Open
5 of 7 tasks
azizramdan opened this issue Feb 4, 2025 · 2 comments
Open
5 of 7 tasks

Different behaviour when using Bun's runtime #661

azizramdan opened this issue Feb 4, 2025 · 2 comments

Comments

@azizramdan
Copy link

Describe the bug

import { existsSync } from 'node:fs'
import { $ } from 'bun'

existsSync('foo')
$`echo "foo"`

That script is valid when using bunx eslint . but get error when force to use Bun's runtime bunx --bun eslint .

╭─velo@velotek ~/projects/eslint-config-bun ‹main●› 
╰─$ bunx eslint .
╭─velo@velotek ~/projects/eslint-config-bun ‹main› 
╰─$ bunx --bun eslint .

/home/velo/projects/eslint-config-bun/index.ts
  2:1  error  Expected "bun" to come before "node:fs"  perfectionist/sort-imports

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

This becomes inconsistent between vscode auto format and cli command.

References:

Reproduction

https://github.com/azizramdan/eslint-config-bun

System Info

System:
    OS: Linux 6.12 EndeavourOS
    CPU: (4) x64 Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz
    Memory: 3.66 GB / 15.51 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.13.1 - ~/.nvm/versions/node/v22.13.1/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v22.13.1/bin/npm
    bun: 1.2.2 - ~/.bun/bin/bun

Used Package Manager

bun

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Contributions

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests (actually just go ahead and do it, thanks!)
@SukkaW
Copy link

SukkaW commented Feb 4, 2025

I suspect perfectionist/sort-imports uses module.builtinModules or module.isBuiltin. On Node.js, bun is treated as an external module, but on Bun (--bunx enforces code to be run on Bun even with a #!/usr/bin/env node shebang) bun is a built-in module.

@azizramdan
Copy link
Author

You are right, perfectionist/sort-imports have config to choose environment https://perfectionist.dev/rules/sort-imports.html#environment

How to override antfu's config only for environment in perfectionist/sort-imports?

Currently, I am using the following approach but i don't think this is right way

import antfu, { perfectionist } from '@antfu/eslint-config'

const perfectionistRules = await perfectionist()

export default antfu({
  rules: {
    'perfectionist/sort-imports': [
      'error',
      {
        ...perfectionistRules[0].rules['perfectionist/sort-imports'][1],
        environment: 'bun',
      },
    ],
  },
})

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

No branches or pull requests

2 participants