Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 15 additions & 4 deletions packages/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import pkgJson from './package.json' with { type: 'json' };
import viteRolldownConfig from './vite-rolldown.config';

const projectDir = join(fileURLToPath(import.meta.url), '..');
const rolldownViteSourceDir = resolve(projectDir, '..', '..', 'rolldown-vite', 'packages', 'vite');

// Main build orchestration
await buildCli();
Expand Down Expand Up @@ -45,8 +46,8 @@ async function buildNapiBinding() {

async function buildCli() {
await build({
input: ['./src/bin.ts', './src/index.ts', './src/test.ts'],
external: [/^node:/, 'vitest'],
input: ['./src/bin.ts', './src/index.ts', './src/test.ts', './src/config.ts'],
external: [/^node:/, 'vitest', './vitest/dist/config.js'],
plugins: [
{
name: 'rewrite-import-path',
Expand All @@ -66,6 +67,15 @@ async function buildCli() {
return { id, external: true };
}
},
renderChunk(code) {
if (code.includes('import * as Rolldown from "rolldown"')) {
return code.replaceAll(
`import * as Rolldown from "rolldown"`,
`import * as Rolldown from "${pkgJson.name}/rolldown"`,
);
}
return code;
Comment thread
Brooooooklyn marked this conversation as resolved.
},
Comment thread
Brooooooklyn marked this conversation as resolved.
},
dts(),
],
Expand All @@ -77,6 +87,8 @@ async function buildCli() {
nativeMagicString: true,
},
});

await cp(join(rolldownViteSourceDir, 'client.d.ts'), join(projectDir, 'dist', 'vite', 'client.d.ts'));
}

async function buildVite() {
Expand Down Expand Up @@ -179,7 +191,6 @@ async function buildVite() {
await build(newViteRolldownConfig as BuildOptions[]);

// Copy additional vite files
const rolldownViteSourceDir = resolve(projectDir, '..', '..', 'rolldown-vite', 'packages', 'vite');

await cp(join(rolldownViteSourceDir, 'misc'), join(projectDir, 'dist/vite/misc'), {
recursive: true,
Expand Down Expand Up @@ -384,7 +395,7 @@ async function bundleVitest() {
).replaceAll(`import 'vite';`, `import '${pkgJson.name}/vite';`).replaceAll(
`'vite/module-runner'`,
`'${pkgJson.name}/module-runner'`,
);
).replaceAll(`declare module "vite"`, `declare module "${pkgJson.name}/vite"`);
await writeFile(destPath, content, 'utf-8');
} else {
await copyFile(file, destPath);
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
"default": "./dist/vitest/browser/context.js"
},
"./client": {
"types": "./dist/client.d.ts"
"types": "./dist/vite/client.d.ts"
},
"./config": {
"types": "./dist/vitest/config.d.ts",
"require": "./dist/vitest/dist/config.cjs",
"default": "./dist/vitest/dist/config.js"
"types": "./dist/config.d.ts",
"default": "./dist/config.js"
},
"./coverage": {
"types": "./dist/vitest/coverage.d.ts",
Expand Down
17 changes: 11 additions & 6 deletions packages/cli/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ async function resolveUniversalViteConfig(err: null | Error, viteConfigCwd: stri
if (err) {
throw err;
}
const { resolveConfig } = await import('./index.js');
const config = await resolveConfig({ root: viteConfigCwd }, 'build');
try {
const { resolveConfig } = await import('./config.js');
const config = await resolveConfig({ root: viteConfigCwd }, 'build');

return Promise.resolve(JSON.stringify({
lint: config.lint,
fmt: config.fmt,
}));
return Promise.resolve(JSON.stringify({
lint: config.lint,
fmt: config.fmt,
}));
} catch (err) {
console.error('[vite+] resolve universal vite config error:', err);
throw err;
}
}

// Initialize the CLI with tool resolvers
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/src/client.ts

This file was deleted.

28 changes: 28 additions & 0 deletions packages/cli/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// replace it with the real oxlint config in the future
export type LintConfig = {
rules: {
[key: string]: string;
};
};

export type FmtConfig = {
rules: {
[key: string]: string;
};
};

declare module '@voidzero-dev/vite-plus/vite' {
interface UserConfig {
/**
* Options for oxlint
*/
lint?: LintConfig;

Comment thread
Brooooooklyn marked this conversation as resolved.
fmt?: FmtConfig;
}
}

Comment thread
Brooooooklyn marked this conversation as resolved.
// @ts-expect-error
Comment thread
Brooooooklyn marked this conversation as resolved.
Comment thread
Brooooooklyn marked this conversation as resolved.
export * from './vitest/dist/config.js';

export { resolveConfig } from '@voidzero-dev/vite-plus/vite';
Loading
Loading