Skip to content

Commit 59bc9f8

Browse files
committed
Revert "fix: avoid static napi cli type resolution"
This reverts commit 1083043.
1 parent 1083043 commit 59bc9f8

1 file changed

Lines changed: 7 additions & 20 deletions

File tree

packages/cli/build.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,16 @@ import { dirname, join, relative } from 'node:path';
2626
import { fileURLToPath } from 'node:url';
2727
import { parseArgs } from 'node:util';
2828

29+
import { createBuildCommand, NapiCli } from '@napi-rs/cli';
2930
import { format } from 'oxfmt';
3031

3132
import { generateLicenseFile } from '../../scripts/generate-license.js';
3233
import corePkg from '../core/package.json' with { type: 'json' };
3334

3435
const projectDir = dirname(fileURLToPath(import.meta.url));
35-
const requireFromBuildScript = createRequire(import.meta.url);
3636
const TEST_PACKAGE_NAME = 'vitest';
3737
const CORE_PACKAGE_NAME = '@voidzero-dev/vite-plus-core';
3838

39-
type NapiBuildOptions = Record<string, unknown> & { dtsHeader?: string };
40-
type NapiBuildOutput = { kind: string; path: string };
41-
type NapiBuildCommand = { getOptions(): NapiBuildOptions };
42-
type NapiCliInstance = {
43-
build(options: NapiBuildOptions): Promise<{ task: Promise<NapiBuildOutput[]> }>;
44-
};
45-
46-
const napiRsCli = requireFromBuildScript('@napi-rs/cli') as {
47-
createBuildCommand(this: void, args: string[]): NapiBuildCommand;
48-
NapiCli: new () => NapiCliInstance;
49-
};
50-
5139
// Browser providers projected under ./test/* and ./test/browser/providers/* so the
5240
// public surface matches what the deleted `@voidzero-dev/vite-plus-test` wrapper exposed.
5341
// Each entry maps the upstream package name to the short provider name used in the
@@ -155,10 +143,10 @@ await copyBundledDocs();
155143
await syncReadmeFromRoot();
156144

157145
async function buildNapiBinding() {
158-
const buildCommand = napiRsCli.createBuildCommand(napiArgs);
146+
const buildCommand = createBuildCommand(napiArgs);
159147
const passedInOptions = buildCommand.getOptions();
160148

161-
const cli = new napiRsCli.NapiCli();
149+
const cli = new NapiCli();
162150

163151
const bindingFeatures = ['rolldown'];
164152
const { dtsHeader } = (
@@ -363,7 +351,8 @@ async function syncTestPackageExports() {
363351

364352
// Resolve vitest's package.json via Node's resolver so we always read the
365353
// currently installed copy — packages/test/ no longer exists.
366-
const testPkgPath = requireFromBuildScript.resolve(`${TEST_PACKAGE_NAME}/package.json`, {
354+
const require = createRequire(import.meta.url);
355+
const testPkgPath = require.resolve(`${TEST_PACKAGE_NAME}/package.json`, {
367356
paths: [projectDir],
368357
});
369358
const cliPkgPath = join(projectDir, 'package.json');
@@ -418,9 +407,7 @@ async function syncTestPackageExports() {
418407
for (const { pkg, short } of BROWSER_PROVIDER_PACKAGES) {
419408
let providerPkgPath: string;
420409
try {
421-
providerPkgPath = requireFromBuildScript.resolve(`${pkg}/package.json`, {
422-
paths: [projectDir],
423-
});
410+
providerPkgPath = require.resolve(`${pkg}/package.json`, { paths: [projectDir] });
424411
} catch (err) {
425412
console.warn(` Skipping ${pkg} — not installed: ${(err as Error).message}`);
426413
continue;
@@ -491,7 +478,7 @@ async function syncTestPackageExports() {
491478
// `oxlint-plugin.ts` autofixes `@vitest/browser/client` →
492479
// `vite-plus/test/client` and `@vitest/browser/locators` →
493480
// `vite-plus/test/locators`, so the runtime targets MUST resolve.
494-
const bareBrowserShims = await createBareBrowserShims(requireFromBuildScript, testDistDir);
481+
const bareBrowserShims = await createBareBrowserShims(require, testDistDir);
495482
for (const [cliPath, exportValue] of Object.entries(bareBrowserShims)) {
496483
generatedExports[cliPath] = exportValue;
497484
console.log(` Created ${cliPath}`);

0 commit comments

Comments
 (0)