Skip to content

Conversation

@ShikChen
Copy link
Contributor

Summary

Update import statement to match the correct package name.

Test Plan

Verified using a local unit test as follows:

ruff.ts:

import initRuff, { Workspace } from "@astral-sh/ruff-wasm-web";

function noConsoleLog<T>(fn: () => T): T {
  const originalConsoleLog = console.log;
  console.log = () => {
    /* no-op */
  };
  try {
    return fn();
  } finally {
    console.log = originalConsoleLog;
  }
}

let initPromise: Promise<Workspace> | null = null;

function getWorkspace(): Promise<Workspace> {
  if (initPromise === null) {
    initPromise = (async () => {
      await initRuff();
      const workspace = noConsoleLog(() => new Workspace({}));
      return workspace;
    })();
  }
  return initPromise;
}

export async function format(code: string): Promise<string> {
  const workspace = await getWorkspace();
  const result = noConsoleLog(() => workspace.format(code));
  return result;
}

ruff.test.ts:

import { expect, test } from "bun:test";
import { format } from "./ruff";

test("format ok", async () => {
  const code = 'print(1+2)'
  const formatted = await format(code);
  expect(formatted).toBe('print(1 + 2)\n');
});

Notes

The noConsoleLog() wrapper is used to suppress verbose and unnecessary debug logs such as:

built glob set; 25 literals, 0 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
built glob set; 0 literals, 1 basenames, 3 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes

These logs also appear on the official Ruff playground (https://play.ruff.rs/), originating from the upstream Rust dependency globset.

Maybe we could consider disabling debug-level logging in future WASM builds?

Make it match the real package name.
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thank you

@MichaReiser MichaReiser added the documentation Improvements or additions to documentation label Sep 23, 2025
@MichaReiser MichaReiser enabled auto-merge (squash) September 23, 2025 16:53
@MichaReiser MichaReiser merged commit dbc5983 into astral-sh:main Sep 23, 2025
36 checks passed
@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

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

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants