Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/cli/bin/oxfmt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ if (!process.argv.includes('--lsp')) {
}

import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';
import { pathToFileURL } from 'node:url';

// The bin/oxfmt subpath is not exported in oxfmt's package.json exports,
// so we resolve the main entry point and derive the bin path from it.
const require = createRequire(import.meta.url);
const oxfmtBin = require.resolve('oxfmt/bin/oxfmt');
const oxfmtMainPath = require.resolve('oxfmt');
const oxfmtPackageRoot = dirname(dirname(oxfmtMainPath));
const oxfmtBin = join(oxfmtPackageRoot, 'bin', 'oxfmt');

await import(pathToFileURL(oxfmtBin).href);
4 changes: 2 additions & 2 deletions packages/cli/src/create/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export function inferParentDir(
workspaceInfo: WorkspaceInfoOptional,
): string | undefined {
if (workspaceInfo.parentDirs.length === 0) {
return;
return undefined;
}
// apps/applications by default
let rule = /app/i;
Expand All @@ -237,5 +237,5 @@ export function inferParentDir(
return parentDir;
}
}
return;
return undefined;
}
4 changes: 2 additions & 2 deletions packages/cli/src/create/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export async function promptPackageNameAndTargetDir(
defaultValue: defaultPackageName,
validate: (value) => {
if (value == null || value.length === 0) {
return;
return undefined;
}
const result = value ? validateNpmPackageName(value) : null;
if (result?.validForNewPackages) {
return;
return undefined;
}
return result?.errors?.[0] ?? result?.warnings?.[0] ?? 'Invalid package name';
},
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/migration/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function confirmEslintMigration(interactive: boolean): Promise<boolean> {
if (prompts.isCancel(confirmed)) {
cancelAndExit();
}
return !!confirmed;
return confirmed;
}
return true;
}
Expand Down Expand Up @@ -145,7 +145,7 @@ async function confirmPrettierMigration(interactive: boolean): Promise<boolean>
if (prompts.isCancel(confirmed)) {
cancelAndExit();
}
return !!confirmed;
return confirmed;
}
prompts.log.info('Prettier configuration detected. Auto-migrating to Oxfmt...');
return true;
Expand Down Expand Up @@ -199,7 +199,7 @@ async function confirmNodeVersionFileMigration(
if (prompts.isCancel(confirmed)) {
cancelAndExit();
}
return !!confirmed;
return confirmed;
}
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/migration/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1917,16 +1917,16 @@ export function installGitHooks(
export function getOldHooksDir(rootDir: string): string | undefined {
const packageJsonPath = path.join(rootDir, 'package.json');
if (!fs.existsSync(packageJsonPath)) {
return;
return undefined;
}
const pkg = readJsonFile<{ scripts?: { prepare?: string } }>(packageJsonPath);
if (!pkg.scripts?.prepare) {
return;
return undefined;
}
const prepare = collapseHuskyInstall(pkg.scripts.prepare);
const match = prepare.match(/\bhusky(?:\s+([\w./-]+))?/);
if (!match) {
return;
return undefined;
}
return match[1] ?? '.husky';
}
Expand Down Expand Up @@ -2231,7 +2231,7 @@ export function createPreCommitHook(projectPath: string, dir = '.vite-hooks'): v
export function rewritePrepareScript(rootDir: string): string | undefined {
const packageJsonPath = path.join(rootDir, 'package.json');
if (!fs.existsSync(packageJsonPath)) {
return;
return undefined;
}

let oldDir: string | undefined;
Expand Down
12 changes: 10 additions & 2 deletions packages/cli/src/resolve-fmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* provides high-performance code formatting capabilities.
*/

import { dirname, join } from 'node:path';

import { DEFAULT_ENVS, resolve } from './utils/constants.ts';

/**
Expand All @@ -27,8 +29,14 @@ export async function fmt(): Promise<{
binPath: string;
envs: Record<string, string>;
}> {
// Resolve the oxfmt binary directly (it's a native executable)
const binPath = resolve('oxfmt/bin/oxfmt');
// Resolve the oxfmt package path first, then navigate to the bin file.
// The bin/oxfmt subpath is not exported in package.json exports, so we
// resolve the main entry point and derive the bin path from it.
// resolve('oxfmt') returns .../oxfmt/dist/index.js, so we need to go up
// two directories (past 'dist') to reach the package root.
const oxfmtMainPath = resolve('oxfmt');
const oxfmtPackageRoot = dirname(dirname(oxfmtMainPath));
const binPath = join(oxfmtPackageRoot, 'bin', 'oxfmt');

return {
binPath,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/__tests__/agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ beforeEach(async () => {
await mockFs.unlink(filePath);
});
vi.spyOn(fsPromises, 'writeFile').mockImplementation(async (filePath, data) => {
await mockFs.writeFile(filePath as fs.PathLike, String(data as string));
await mockFs.writeFile(filePath as fs.PathLike, data as string);
});

await mockFs.writeFile(path.join(pkgRoot, 'AGENTS.md'), AGENT_TEMPLATE);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const fixVersionsPathPlugin = {
if (source === '../versions.js') {
return { id: './versions.js', external: true };
}
return undefined;
},
};

Expand Down
8 changes: 4 additions & 4 deletions packages/core/build-support/find-create-require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ function findCreateRequireInStaticImports(
return value === 'node:module' || value === 'module';
});
if (!importFromModule) {
return;
return undefined;
}

// Find the createRequire import entry
const createRequireEntry = importFromModule.entries.find((entry) => {
return entry.importName.name === 'createRequire';
});
if (!createRequireEntry) {
return;
return undefined;
}

const createRequireLocalName = createRequireEntry.localName.value;
Expand All @@ -175,7 +175,7 @@ function findCreateRequireInStaticImports(
varVisitor.visit(ast.program);

if (!requireVarName) {
return;
return undefined;
}

// Find all calls to the require variable
Expand Down Expand Up @@ -277,7 +277,7 @@ function findCreateRequireInGlobalModule(
visitor.visit(ast.program);

if (!requireVarName) {
return;
return undefined;
}

// Find all calls to the require variable
Expand Down
1 change: 1 addition & 0 deletions packages/core/build-support/rewrite-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const RewriteImportsPlugin: Plugin = {
external: true,
};
}
return undefined;
},
},
};
9 changes: 6 additions & 3 deletions packages/core/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ async function buildVite() {
};
}
}
return undefined;
},
},
{
Expand Down Expand Up @@ -194,19 +195,20 @@ async function buildVite() {
};
}
}
return undefined;
},
},
{
name: 'suppress-vite-version-only-reporter-line',
transform(code, id) {
if (!id.endsWith(join('vite', 'src', 'node', 'plugins', 'reporter.ts'))) {
return;
return undefined;
}

// Upstream native reporter can emit a redundant standalone "vite vX.Y.Z" line.
// Filter it at source so snapshots and CLI output remain stable.
if (code.includes('VITE_VERSION_ONLY_LINE_RE')) {
return;
return undefined;
}

const constLine =
Expand All @@ -215,7 +217,7 @@ async function buildVite() {
' logInfo: shouldLogInfo ? (msg) => env.logger.info(msg) : undefined,';

if (!code.includes(constLine) || !code.includes(logInfoLine)) {
return;
return undefined;
}

return {
Expand Down Expand Up @@ -404,6 +406,7 @@ async function bundleTsdown() {
}
return { code: updatedCode };
}
return undefined;
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"@tsdown/exe": "0.21.7",
"@types/node": "^20.19.0 || >=22.12.0",
"@vitejs/devtools": "^0.1.0",
"esbuild": "^0.28.0",
"esbuild": "^0.27.0 || ^0.28.0",
"jiti": ">=1.21.0",
"less": "^4.0.0",
"publint": "^0.3.0",
Expand Down Expand Up @@ -217,7 +217,7 @@
"node": "^20.19.0 || >=22.12.0"
},
"bundledVersions": {
"vite": "8.0.5",
"vite": "8.0.6",
"rolldown": "1.0.0-rc.13",
"tsdown": "0.21.7"
}
Expand Down
8 changes: 4 additions & 4 deletions packages/prompts/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const S_ERROR = unicodeOr('■', 'x');

export const completeColor = (value: string) => color.gray(value);

export const symbol = (state: State) => {
export const symbol = (state: State): string => {
switch (state) {
case 'initial':
case 'active':
Expand All @@ -53,12 +53,12 @@ export const symbol = (state: State) => {
return color.red(S_STEP_CANCEL);
case 'error':
return color.yellow(S_STEP_ERROR);
case 'submit':
default:
return completeColor(S_STEP_SUBMIT);
}
};

export const symbolBar = (state: State) => {
export const symbolBar = (state: State): string => {
switch (state) {
case 'initial':
case 'active':
Expand All @@ -67,7 +67,7 @@ export const symbolBar = (state: State) => {
return color.red(S_BAR);
case 'error':
return color.yellow(S_BAR);
case 'submit':
default:
return completeColor(S_BAR);
}
};
Expand Down
1 change: 1 addition & 0 deletions packages/prompts/src/group-multi-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
),
)}`;
}
return undefined;
},
render() {
const title = `${hasGuide ? `${color.gray(S_BAR)}\n` : ''}${symbol(this.state)} ${opts.message}\n`;
Expand Down
1 change: 1 addition & 0 deletions packages/prompts/src/multi-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
),
)}`;
}
return undefined;
},
render() {
const hasGuide = opts.withGuide ?? false;
Expand Down
2 changes: 1 addition & 1 deletion packages/prompts/src/select-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const selectKey = <Value extends string>(opts: SelectKeyOptions<Value>) =
option: Option<Value>,
state: 'inactive' | 'active' | 'selected' | 'cancelled' = 'inactive',
) => {
const label = option.label ?? String(option.value);
const label = option.label ?? option.value;
if (state === 'selected') {
return color.dim(label);
}
Expand Down
36 changes: 22 additions & 14 deletions packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,17 @@
"@blazediff/core": "1.9.1",
"@oxc-node/cli": "catalog:",
"@oxc-node/core": "catalog:",
"@vitest/browser": "4.1.2",
"@vitest/browser-playwright": "4.1.2",
"@vitest/browser-preview": "4.1.2",
"@vitest/browser-webdriverio": "4.1.2",
"@vitest/expect": "4.1.2",
"@vitest/mocker": "4.1.2",
"@vitest/pretty-format": "4.1.2",
"@vitest/runner": "4.1.2",
"@vitest/snapshot": "4.1.2",
"@vitest/spy": "4.1.2",
"@vitest/utils": "4.1.2",
"@vitest/browser": "4.1.3",
"@vitest/browser-playwright": "4.1.3",
"@vitest/browser-preview": "4.1.3",
"@vitest/browser-webdriverio": "4.1.3",
"@vitest/expect": "4.1.3",
"@vitest/mocker": "4.1.3",
"@vitest/pretty-format": "4.1.3",
"@vitest/runner": "4.1.3",
"@vitest/snapshot": "4.1.3",
"@vitest/spy": "4.1.3",
"@vitest/utils": "4.1.3",
"chai": "^6.2.1",
"convert-source-map": "^2.0.0",
"estree-walker": "^3.0.3",
Expand All @@ -316,14 +316,16 @@
"rolldown": "workspace:*",
"rolldown-plugin-dts": "catalog:",
"tinyrainbow": "^3.1.0",
"vitest-dev": "^4.1.2",
"vitest-dev": "^4.1.3",
"why-is-node-running": "^2.3.0"
},
"peerDependencies": {
"@edge-runtime/vm": "*",
"@opentelemetry/api": "^1.9.0",
"@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0",
"@vitest/ui": "4.1.2",
"@vitest/coverage-istanbul": "4.1.3",
"@vitest/coverage-v8": "4.1.3",
"@vitest/ui": "4.1.3",
"happy-dom": "*",
"jsdom": "*",
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
Expand All @@ -338,6 +340,12 @@
"@types/node": {
"optional": true
},
"@vitest/coverage-istanbul": {
"optional": true
},
"@vitest/coverage-v8": {
"optional": true
},
"@vitest/ui": {
"optional": true
},
Expand All @@ -355,6 +363,6 @@
"node": "^20.0.0 || ^22.0.0 || >=24.0.0"
},
"bundledVersions": {
"vitest": "4.1.2"
"vitest": "4.1.3"
}
}
2 changes: 1 addition & 1 deletion packages/tools/.upstream-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"vite": {
"repo": "https://github.com/vitejs/vite.git",
"branch": "main",
"hash": "1a12d4ca4c62eedaeaf734d722b27ab17b5b1dd0"
"hash": "7b3086fae4170252e4cd53f3988f207a943ac5cb"
}
}
Loading
Loading