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

docs: update readme to include bun install #505

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Electroid
Copy link

Updates the readme to add bun install instructions alongside npm and yarn.

Copy link

salesforce-cla bot commented Mar 6, 2025

Thanks for the contribution! Before we can merge this, we need @Electroid to sign the Salesforce Inc. Contributor License Agreement.

@Electroid
Copy link
Author

Thanks for the contribution! Before we can merge this, we need @Electroid to sign the Salesforce Inc. Contributor License Agreement.

Screenshot 2025-03-06 at 3 24 24 PM

@colincasey
Copy link
Contributor

Closing and reopening to trigger the salesforce-cla bot to refresh

@colincasey colincasey closed this Mar 7, 2025
@colincasey colincasey reopened this Mar 7, 2025
@colincasey colincasey self-assigned this Mar 7, 2025
@wjhsf
Copy link
Contributor

wjhsf commented Mar 7, 2025

@Electroid thanks for this suggestion! However, bun is not currently a runtime that we support, and we don't want to give a false impression by including it in the readme.

That being said, we are open to supporting bun, but we'd need a guarantee that the package works in that environment. We'd be happy accept a contribution that runs our unit tests in bun to provide that guarantee.

@Electroid
Copy link
Author

@Electroid thanks for this suggestion! However, bun is not currently a runtime that we support, and we don't want to give a false impression by including it in the readme.

That being said, we are open to supporting bun, but we'd need a guarantee that the package works in that environment. We'd be happy accept a contribution that runs our unit tests in bun to provide that guarantee.

Hi @wjhsf, totally understand. I did try using Bun with your package and it does work!

Snippet using tough-cookie
// Example of using tough-cookie with Bun
import { Cookie, CookieJar } from 'tough-cookie';

async function main() {
  console.log('Testing tough-cookie with Bun...');
  
  // Create a cookie jar
  const cookieJar = new CookieJar();
  console.log('Cookie jar created');
  
  // Set some cookies
  await cookieJar.setCookie(
    'sessionId=abc123; Domain=example.com; Path=/; Secure; HttpOnly',
    'https://example.com/login'
  );
  
  await cookieJar.setCookie(
    'user=johndoe; Domain=example.com; Path=/; Expires=Tue, 21 Oct 2030 00:00:00 GMT',
    'https://example.com/profile'
  );
  
  await cookieJar.setCookie(
    '__Secure-theme=dark; Domain=example.com; Path=/; Secure',
    'https://example.com/settings'
  );
  
  // Get cookies for a specific URL
  const cookies = await cookieJar.getCookies('https://example.com/dashboard');
  console.log('Cookies for https://example.com/dashboard:');
  cookies.forEach(cookie => {
    console.log(`  - ${cookie.key}=${cookie.value}`);
  });
  
  // Parse a Set-Cookie header
  const setCookieHeader = 'preference=language=en; Domain=example.com; Path=/; Max-Age=31536000';
  const parsedCookie = Cookie.parse(setCookieHeader);
  console.log('\nParsed cookie from header:');
  console.log(`  Key: ${parsedCookie.key}`);
  console.log(`  Value: ${parsedCookie.value}`);
  console.log(`  Domain: ${parsedCookie.domain}`);
  console.log(`  Path: ${parsedCookie.path}`);
  console.log(`  Expires: ${parsedCookie.expires}`);
  
  // Generate a Set-Cookie header
  const newCookie = new Cookie({
    key: 'visited',
    value: 'true',
    domain: 'example.com',
    path: '/',
    secure: true,
    httpOnly: true,
    maxAge: 86400 // 1 day in seconds
  });
  
  console.log('\nGenerated Set-Cookie header:');
  console.log(newCookie.toString());
  
  // SameSite example
  await cookieJar.setCookie(
    'strict=authorized; SameSite=strict; Domain=example.com; Path=/',
    'https://example.com/'
  );
  
  await cookieJar.setCookie(
    'lax=okay; SameSite=lax; Domain=example.com; Path=/',
    'https://example.com/'
  );
  
  const laxCookies = await cookieJar.getCookies('https://example.com/', {
    sameSiteContext: 'lax'
  });
  
  console.log('\nCookies with sameSiteContext=lax:');
  laxCookies.forEach(cookie => {
    console.log(`  - ${cookie.key}=${cookie.value} (SameSite=${cookie.sameSite || 'none'})`);
  });
}

main().catch(err => console.error('Error:', err));
Output using Bun
❯ bun example.js
Testing tough-cookie with Bun...
Cookie jar created
Cookies for https://example.com/dashboard:
  - sessionId=abc123
  - user=johndoe
  - __Secure-theme=dark

Parsed cookie from header:
  Key: preference
  Value: language=en
  Domain: example.com
  Path: /
  Expires: Infinity

Generated Set-Cookie header:
visited=true; Max-Age=86400; Domain=example.com; Path=/; Secure; HttpOnly

Cookies with sameSiteContext=lax:
  - sessionId=abc123 (SameSite=none)
  - user=johndoe (SameSite=none)
  - __Secure-theme=dark (SameSite=none)
  - lax=okay (SameSite=lax)

Bun has a built-in test runner that's compatible with Jest, but we don't yet support jest.advanceTimersByTime(), so I'd love to submit another PR to run your tests in CI when we do support it.

I did run your test/scripts/vows.js in Bun, and it does work.

Screenshot 2025-03-07 at 3 47 30 PM

The last thing I was gonna mention was that you actually can use bun install with Node.js as your runtime. In fact, we have a lot of developers that start this way, especially if there's a runtime feature we haven't implemented in Bun yet.

@wjhsf
Copy link
Contributor

wjhsf commented Mar 10, 2025

Bun has a built-in test runner that's compatible with Jest, but we don't yet support jest.advanceTimersByTime(), so I'd love to submit another PR to run your tests in CI when we do support it.

I did run your test/scripts/vows.js in Bun, and it does work.

I'd imagine that it doesn't make much of a difference, but just as a footnote we'll be switching to vitest soon. I'm working on a PR for after we switch to ESM (#506, which also removes the CJS-only vows tests).

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

Successfully merging this pull request may close these issues.

3 participants