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

feat: bun as packageManager option #1309

Merged
merged 16 commits into from
Sep 13, 2023
Merged

Conversation

ImBIOS
Copy link
Contributor

@ImBIOS ImBIOS commented Jul 22, 2023

@Jarred-Sumner @oven-sh need your help and review

@raineorshine
Copy link
Owner

Hi, thanks for the contribution. This looks good to me. Just need to get the tests passing.

@ImBIOS
Copy link
Contributor Author

ImBIOS commented Jul 25, 2023

One file left needs some work, it's the bun package manager spawner file. I'm making this PR, but I do not yet understand the bare minimum requirement for that file.

@raineorshine
Copy link
Owner

The minimum packageManager file just needs a function to return the latest version:

{
  latest: (packageName: string,
  currentVersion: string) =>
    { error?: string, version?: number }
}

Additional targets (patch, minor, newest, greatest) can be added by defining their respective functions, which have the same signature. You may also consider defining a list function to add support for global mode.

The full PackageManager type is here: https://github.com/raineorshine/npm-check-updates/blob/main/src/types/PackageManager.ts

@ImBIOS
Copy link
Contributor Author

ImBIOS commented Aug 16, 2023

@raineorshine I just implemented the basic bun spawner

.gitignore Outdated Show resolved Hide resolved
/**
* (Bun) Fetches the list of all installed packages.
*/
export const list = npmList
Copy link
Owner

Choose a reason for hiding this comment

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

You should spawn bun for the list command, as npm may have a different global install directory than bun.

Hopefully bun has a --json option, otherwise you'll have to parse the results.

src/package-managers/bun.ts Outdated Show resolved Hide resolved

describe('bun', function () {
it('list', async () => {
const versionObject = await bun.list({ cwd: __dirname })
Copy link
Owner

Choose a reason for hiding this comment

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

Though there are some old tests remaining that operate on test files in the project directory tree, I prefer a dynamic setup in a temp directory as seen here:

it('read --packageFile', async () => {
const stub = stubNpmView('99.9.9', { spawn: true })
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
const pkgFile = path.join(tempDir, 'package.json')
await fs.writeFile(pkgFile, JSON.stringify({ dependencies: { express: '1' } }), 'utf-8')
try {
const text = await spawn('node', [bin, '--jsonUpgraded', '--packageFile', pkgFile])
const pkgData = JSON.parse(text)
pkgData.should.have.property('express')
} finally {
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})

It makes the tests slightly more verbose, but I've found it easier to manage by having everything related to a test contained in the test file. Plus cleanup is easier because you can just delete the temp directory rather than having to do a precise restore.

@raineorshine raineorshine changed the title feat: init bun as packageManager option feat: bun as packageManager option Aug 16, 2023
@raineorshine
Copy link
Owner

Hi, have you had a chance to review the requested changes?

Just wanted to check in since some merge conflicts are accumulating as this sits.

@ImBIOS
Copy link
Contributor Author

ImBIOS commented Sep 12, 2023

@raineorshine I've fixed the conflict and delivered 2 change requests. But, I have no idea how to deliver the other 2 requests you made. Can I request for your help?

@raineorshine
Copy link
Owner

raineorshine commented Sep 12, 2023

I added the other targets (minor, patch, semver, greatest, newest), and implemented the list command which is needed for -g functionality. The bun cli does not have a --json option, so we just parse the cli output. Please see 15775ad for details.

Basic doctor mode works now. Also, I have bun installed conditionally in the CI environment and skip the tests on Windows.

I think we can merge this as an initial implementation. Additional functionality can be added in separate PR's. Let me know if there's anything else you'd like to add before I merge. Thanks!

@ImBIOS
Copy link
Contributor Author

ImBIOS commented Sep 13, 2023

@raineorshine Nah, All good. Looks Good To Me. Thanks a lot for your help adding bun 🙏 😄

@raineorshine raineorshine merged commit 0c25e3a into raineorshine:main Sep 13, 2023
9 checks passed
@ImBIOS ImBIOS deleted the feat/bun branch September 13, 2023 00:55
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.

2 participants