Skip to content

Commit 3a4d753

Browse files
committed
fmt
1 parent 3f3dd03 commit 3a4d753

78 files changed

Lines changed: 1239 additions & 1231 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.oxfmtrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"ignorePatterns": [
4+
"packages/cli/binding/index.d.ts",
5+
"packages/cli/binding/index.js"
6+
],
7+
"singleQuote": true
8+
}

bench/generate-monorepo.ts

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as fs from "node:fs";
2-
import * as path from "node:path";
3-
import { fileURLToPath } from "node:url";
1+
import * as fs from 'node:fs';
2+
import * as path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
44

55
interface Package {
66
name: string;
@@ -9,23 +9,23 @@ interface Package {
99
hasVitePlusConfig: boolean;
1010
}
1111

12-
const __dirname = path.join(fileURLToPath(import.meta.url), "..");
12+
const __dirname = path.join(fileURLToPath(import.meta.url), '..');
1313

1414
class MonorepoGenerator {
1515
private packages: Map<string, Package> = new Map();
1616
private readonly PACKAGE_COUNT = 1000;
1717
private readonly MAX_DEPS_PER_PACKAGE = 8;
1818
private readonly MIN_DEPS_PER_PACKAGE = 2;
1919
private readonly SCRIPT_NAMES = [
20-
"build",
21-
"test",
22-
"lint",
23-
"dev",
24-
"start",
25-
"prepare",
26-
"compile",
20+
'build',
21+
'test',
22+
'lint',
23+
'dev',
24+
'start',
25+
'prepare',
26+
'compile',
2727
];
28-
private readonly CATEGORIES = ["core", "util", "feature", "service", "app"];
28+
private readonly CATEGORIES = ['core', 'util', 'feature', 'service', 'app'];
2929

3030
constructor(private rootDir: string) {}
3131

@@ -39,7 +39,7 @@ class MonorepoGenerator {
3939

4040
private generatePackageName(index: number): string {
4141
const category = this.getRandomElement(this.CATEGORIES);
42-
const paddedIndex = index.toString().padStart(2, "0");
42+
const paddedIndex = index.toString().padStart(2, '0');
4343
return `${category}-${paddedIndex}`;
4444
}
4545

@@ -66,7 +66,7 @@ class MonorepoGenerator {
6666
selectedCommands.push(this.getRandomElement(commands));
6767
}
6868

69-
return selectedCommands.join(" && ");
69+
return selectedCommands.join(' && ');
7070
}
7171

7272
private generateScripts(packageName: string): Record<string, string> {
@@ -100,7 +100,7 @@ class MonorepoGenerator {
100100
// Create a complex graph by selecting dependencies from different layers
101101
// Prefer packages with lower indices (creates deeper dependency chains)
102102
const eligiblePackages = availablePackages.filter((pkg) => {
103-
const pkgIndex = parseInt(pkg.split("-")[1]);
103+
const pkgIndex = parseInt(pkg.split('-')[1]);
104104
return pkgIndex < currentIndex;
105105
});
106106

@@ -119,8 +119,8 @@ class MonorepoGenerator {
119119
// Add some cross-category dependencies for complexity
120120
if (Math.random() > 0.3) {
121121
const crossCategoryDeps = availablePackages.filter((pkg) => {
122-
const category = pkg.split("-")[0];
123-
return category !== currentIndex.toString().split("-")[0];
122+
const category = pkg.split('-')[0];
123+
return category !== currentIndex.toString().split('-')[0];
124124
});
125125

126126
if (crossCategoryDeps.length > 0) {
@@ -196,74 +196,74 @@ class MonorepoGenerator {
196196
}
197197

198198
private writePackage(pkg: Package): void {
199-
const packageDir = path.join(this.rootDir, "packages", pkg.name);
199+
const packageDir = path.join(this.rootDir, 'packages', pkg.name);
200200

201201
// Create directory structure
202202
fs.mkdirSync(packageDir, { recursive: true });
203-
fs.mkdirSync(path.join(packageDir, "src"), { recursive: true });
203+
fs.mkdirSync(path.join(packageDir, 'src'), { recursive: true });
204204

205205
// Write package.json
206206
const packageJson = {
207207
name: `@monorepo/${pkg.name}`,
208-
version: "1.0.0",
209-
main: "src/index.js",
208+
version: '1.0.0',
209+
main: 'src/index.js',
210210
scripts: pkg.scripts,
211211
dependencies: pkg.dependencies.reduce(
212212
(deps, dep) => {
213-
deps[`@monorepo/${dep}`] = "workspace:*";
213+
deps[`@monorepo/${dep}`] = 'workspace:*';
214214
return deps;
215215
},
216216
{} as Record<string, string>,
217217
),
218218
};
219219

220220
fs.writeFileSync(
221-
path.join(packageDir, "package.json"),
221+
path.join(packageDir, 'package.json'),
222222
JSON.stringify(packageJson, null, 2),
223223
);
224224

225225
// Write source file
226226
const indexContent = `// ${pkg.name} module
227-
export function ${pkg.name.replace("-", "_")}() {
227+
export function ${pkg.name.replace('-', '_')}() {
228228
console.log('Executing ${pkg.name}');
229-
${pkg.dependencies.map((dep) => ` require('@monorepo/${dep}');`).join("\n")}
229+
${pkg.dependencies.map((dep) => ` require('@monorepo/${dep}');`).join('\n')}
230230
}
231231
232-
module.exports = { ${pkg.name.replace("-", "_")} };
232+
module.exports = { ${pkg.name.replace('-', '_')} };
233233
`;
234234

235-
fs.writeFileSync(path.join(packageDir, "src", "index.js"), indexContent);
235+
fs.writeFileSync(path.join(packageDir, 'src', 'index.js'), indexContent);
236236

237237
// Write vite-plus.json if needed
238238
if (pkg.hasVitePlusConfig) {
239239
const vitePlusConfig = {
240-
extends: "../../vite-plus.json",
240+
extends: '../../vite-plus.json',
241241
tasks: {
242242
build: {
243243
cache: true,
244244
env: {
245-
NODE_ENV: "production",
245+
NODE_ENV: 'production',
246246
},
247247
},
248248
},
249249
};
250250

251251
fs.writeFileSync(
252-
path.join(packageDir, "vite-plus.json"),
252+
path.join(packageDir, 'vite-plus.json'),
253253
JSON.stringify(vitePlusConfig, null, 2),
254254
);
255255
}
256256
}
257257

258258
public generate(): void {
259-
console.log("Generating monorepo structure...");
259+
console.log('Generating monorepo structure...');
260260

261261
// Clean and create root directory
262262
if (fs.existsSync(this.rootDir)) {
263263
fs.rmSync(this.rootDir, { recursive: true, force: true });
264264
}
265265
fs.mkdirSync(this.rootDir, { recursive: true });
266-
fs.mkdirSync(path.join(this.rootDir, "packages"), { recursive: true });
266+
fs.mkdirSync(path.join(this.rootDir, 'packages'), { recursive: true });
267267

268268
// Generate packages
269269
this.generatePackages();
@@ -280,22 +280,22 @@ module.exports = { ${pkg.name.replace("-", "_")} };
280280

281281
// Write root package.json
282282
const rootPackageJson = {
283-
name: "monorepo-benchmark",
284-
version: "1.0.0",
283+
name: 'monorepo-benchmark',
284+
version: '1.0.0',
285285
private: true,
286-
workspaces: ["packages/*"],
286+
workspaces: ['packages/*'],
287287
scripts: {
288-
"build:all": "vite run build",
289-
"test:all": "vite run test",
290-
"lint:all": "vite run lint",
288+
'build:all': 'vite run build',
289+
'test:all': 'vite run test',
290+
'lint:all': 'vite run lint',
291291
},
292292
devDependencies: {
293-
"@voidzero-dev/vite-plus": "*",
293+
'@voidzero-dev/vite-plus': '*',
294294
},
295295
};
296296

297297
fs.writeFileSync(
298-
path.join(this.rootDir, "package.json"),
298+
path.join(this.rootDir, 'package.json'),
299299
JSON.stringify(rootPackageJson, null, 2),
300300
);
301301

@@ -304,7 +304,7 @@ module.exports = { ${pkg.name.replace("-", "_")} };
304304
- 'packages/*'
305305
`;
306306
fs.writeFileSync(
307-
path.join(this.rootDir, "pnpm-workspace.yaml"),
307+
path.join(this.rootDir, 'pnpm-workspace.yaml'),
308308
pnpmWorkspace,
309309
);
310310

@@ -327,7 +327,7 @@ module.exports = { ${pkg.name.replace("-", "_")} };
327327
};
328328

329329
fs.writeFileSync(
330-
path.join(this.rootDir, "vite-plus.json"),
330+
path.join(this.rootDir, 'vite-plus.json'),
331331
JSON.stringify(rootVitePlusConfig, null, 2),
332332
);
333333

@@ -359,7 +359,7 @@ module.exports = { ${pkg.name.replace("-", "_")} };
359359
}
360360
}
361361

362-
console.log("\nStatistics:");
362+
console.log('\nStatistics:');
363363
console.log(`- Total packages: ${this.packages.size}`);
364364
console.log(
365365
`- Average dependencies per package: ${(
@@ -368,14 +368,14 @@ module.exports = { ${pkg.name.replace("-", "_")} };
368368
);
369369
console.log(`- Max dependencies in a package: ${maxDeps}`);
370370
console.log(`- Packages with vite-plus.json: ${packagesWithVitePlus}`);
371-
console.log("- Script distribution:");
371+
console.log('- Script distribution:');
372372
for (const [script, count] of scriptCounts) {
373373
console.log(` - ${script}: ${count} packages`);
374374
}
375375
}
376376
}
377377

378378
// Main execution
379-
const outputDir = path.join(__dirname, "fixtures", "monorepo");
379+
const outputDir = path.join(__dirname, 'fixtures', 'monorepo');
380380
const generator = new MonorepoGenerator(outputDir);
381381
generator.generate();

packages/cli/binding/__tests__/detect-workspace.spec.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
import { tmpdir } from "node:os";
2-
import path from "node:path";
1+
import { tmpdir } from 'node:os';
2+
import path from 'node:path';
33

4-
import { expect, test } from "vitest";
4+
import { expect, test } from 'vitest';
55

6-
import { detectWorkspace } from "../index.js";
6+
import { detectWorkspace } from '../index.js';
77

8-
const fixtures = path.join(import.meta.dirname, "fixtures");
8+
const fixtures = path.join(import.meta.dirname, 'fixtures');
99

10-
test("should detect pnpm monorepo workspace successfully", async () => {
11-
const cwd = path.join(fixtures, "pnpm-monorepo");
10+
test('should detect pnpm monorepo workspace successfully', async () => {
11+
const cwd = path.join(fixtures, 'pnpm-monorepo');
1212
const result = await detectWorkspace(cwd);
13-
expect(result.packageManagerName).toBe("pnpm");
14-
expect(result.packageManagerVersion).toBe("10.19.0");
13+
expect(result.packageManagerName).toBe('pnpm');
14+
expect(result.packageManagerVersion).toBe('10.19.0');
1515
expect(result.isMonorepo).toBe(true);
1616
expect(result.root).toBe(cwd);
1717

1818
// detect from sub directory
19-
const subCwd = path.join(cwd, "packages", "sub-package");
19+
const subCwd = path.join(cwd, 'packages', 'sub-package');
2020
const subResult = await detectWorkspace(subCwd);
21-
expect(subResult.packageManagerName).toBe("pnpm");
22-
expect(subResult.packageManagerVersion).toBe("10.19.0");
21+
expect(subResult.packageManagerName).toBe('pnpm');
22+
expect(subResult.packageManagerVersion).toBe('10.19.0');
2323
expect(subResult.isMonorepo).toBe(true);
2424
expect(subResult.root).toBe(cwd);
2525
});
2626

27-
test("should detect npm monorepo workspace successfully", async () => {
28-
const cwd = path.join(fixtures, "npm-monorepo");
27+
test('should detect npm monorepo workspace successfully', async () => {
28+
const cwd = path.join(fixtures, 'npm-monorepo');
2929
const result = await detectWorkspace(cwd);
30-
expect(result.packageManagerName).toBe("npm");
31-
expect(result.packageManagerVersion).toBe("10.19.0");
30+
expect(result.packageManagerName).toBe('npm');
31+
expect(result.packageManagerVersion).toBe('10.19.0');
3232
expect(result.isMonorepo).toBe(true);
3333
expect(result.root).toBe(cwd);
3434
});
3535

3636
// FIXME: currently it will always find vite-plus, there is a problem here
37-
test.skip("should detect npm project successfully", async () => {
38-
const cwd = path.join(fixtures, "npm-project");
37+
test.skip('should detect npm project successfully', async () => {
38+
const cwd = path.join(fixtures, 'npm-project');
3939
const result = await detectWorkspace(cwd);
40-
expect(result.packageManagerName).toBe("npm");
41-
expect(result.packageManagerVersion).toBe("10.19.0");
40+
expect(result.packageManagerName).toBe('npm');
41+
expect(result.packageManagerVersion).toBe('10.19.0');
4242
expect(result.isMonorepo).toBe(false);
4343
expect(result.root).toBe(cwd);
4444
});
4545

46-
test("should detect workspace failed with not exists directory", async () => {
47-
const result = await detectWorkspace(path.join(tmpdir(), "not-exists"));
46+
test('should detect workspace failed with not exists directory', async () => {
47+
const result = await detectWorkspace(path.join(tmpdir(), 'not-exists'));
4848
expect(result.packageManagerName).toBeUndefined();
4949
expect(result.packageManagerVersion).toBeUndefined();
5050
expect(result.isMonorepo).toBe(false);

packages/cli/binding/__tests__/download-package-manager.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { expect, test } from "vitest";
1+
import { expect, test } from 'vitest';
22

3-
import { downloadPackageManager } from "../index.js";
3+
import { downloadPackageManager } from '../index.js';
44

5-
test("should download package manager successfully", async () => {
5+
test('should download package manager successfully', async () => {
66
const result = await downloadPackageManager({
7-
name: "pnpm",
8-
version: "latest",
7+
name: 'pnpm',
8+
version: 'latest',
99
});
10-
expect(result.name).toBe("pnpm");
11-
expect(result.packageName).toBe("pnpm");
10+
expect(result.name).toBe('pnpm');
11+
expect(result.packageName).toBe('pnpm');
1212
expect(result.version).toMatch(/^\d+\.\d+\.\d+$/);
1313
expect(result.installDir).toBeTruthy();
1414
expect(result.binPrefix).toMatch(/bin$/);

0 commit comments

Comments
 (0)