Skip to content

Commit

Permalink
fix: improve bun support
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Aug 15, 2024
1 parent feda7cb commit b31fa33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/generators/packageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ async function core(config: PackageConfig, rootConfig: PackageConfig, skipAdding
) {
if (config.isBun) {
devDependencies.push('@biomejs/biome', '@willbooster/biome-config');
delete jsonObj.devDependencies['eslint'];
delete jsonObj.devDependencies['micromatch'];
delete jsonObj.devDependencies['@typescript-eslint/parser'];
} else {
devDependencies.push('[email protected]', 'micromatch');
// TODO: not needed anymore?
Expand Down Expand Up @@ -363,7 +366,7 @@ async function core(config: PackageConfig, rootConfig: PackageConfig, skipAdding
if (!skipAddingDeps) {
// We cannot add dependencies which are already included in devDependencies.
dependencies = dependencies.filter((dep) => !jsonObj.devDependencies?.[dep]);
const packageManager = rootConfig.isBun ? 'bun' : 'yarn';
const packageManager = config.isBun ? 'bun' : 'yarn';
if (dependencies.length > 0) {
spawnSync(packageManager, ['add', ...new Set(dependencies)], config.dirPath);
}
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ async function main(): Promise<void> {
}
const abbreviationPromise = fixTypos(rootConfig);

const nullableSubPackageConfigs = await Promise.all(subDirPaths.map((subDirPath) => getPackageConfig(subDirPath)));
const nullableSubPackageConfigs = await Promise.all(
subDirPaths.map((subDirPath) => getPackageConfig(subDirPath, rootConfig))
);
const subPackageConfigs = nullableSubPackageConfigs.filter((config) => !!config) as PackageConfig[];
const allPackageConfigs = [rootConfig, ...subPackageConfigs];

Expand Down
7 changes: 5 additions & 2 deletions src/packageConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ const wbfyJsonSchema = z.object({
.optional(),
});

export async function getPackageConfig(dirPath: string): Promise<PackageConfig | undefined> {
export async function getPackageConfig(
dirPath: string,
rootConfig?: PackageConfig
): Promise<PackageConfig | undefined> {
const packageJsonPath = path.resolve(dirPath, 'package.json');
try {
const doesContainsPackageJson = fs.existsSync(packageJsonPath);
Expand Down Expand Up @@ -156,7 +159,7 @@ export async function getPackageConfig(dirPath: string): Promise<PackageConfig |
isPublicRepo: repoInfo?.private === false,
isReferredByOtherRepo: !!packageJson.files,
repository: repoInfo?.full_name ? `github:${repoInfo?.full_name}` : undefined,
isBun: fs.existsSync(path.join(dirPath, 'bunfig.toml')),
isBun: rootConfig?.isBun || fs.existsSync(path.join(dirPath, 'bunfig.toml')),
isEsmPackage: esmPackage,
isWillBoosterConfigs: packageJsonPath.includes(`${path.sep}willbooster-configs`),
doesContainsSubPackageJsons: containsAny('packages/**/package.json', dirPath),
Expand Down

0 comments on commit b31fa33

Please sign in to comment.