Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Bolt's Journal

## 2024-05-22 - [Example Entry]
**Learning:** [Example Insight]
**Action:** [Example Action]
23 changes: 8 additions & 15 deletions packages/core/src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/**
* Module dependencies.
*/
import fs from "node:fs";
import type {
CompressorOptions,
MinifierOptions,
Expand Down Expand Up @@ -48,7 +47,7 @@ export async function compress<T extends CompressorOptions = CompressorOptions>(
}

if (settings.output) {
createDirectory(settings.output);
await createDirectory(settings.output);
}

// Handle array outputs (from user input or created internally by checkOutput when processing $1 pattern)
Expand Down Expand Up @@ -96,14 +95,15 @@ async function compressArrayOfFiles<
* Create folder of the target file.
* @param filePath Full path of the file (can be string or array when $1 pattern is used)
*/
function createDirectory(filePath: string | string[]) {
async function createDirectory(filePath: string | string[]) {
// Early return if no file path provided
if (!filePath) {
return;
}

// Handle array (created internally by checkOutput when processing $1 pattern)
const paths = Array.isArray(filePath) ? filePath : [filePath];
const uniqueDirs = new Set<string>();

for (const path of paths) {
if (typeof path !== "string") {
Expand All @@ -118,18 +118,11 @@ function createDirectory(filePath: string | string[]) {
continue;
}

// Create directory if it doesn't exist
if (!directoryExists(dirPath)) {
mkdirp.sync(dirPath);
}
uniqueDirs.add(dirPath);
}
}

// Helper function to check if directory exists
function directoryExists(path: string): boolean {
try {
return fs.statSync(path).isDirectory();
} catch {
return false;
}
// Create directories in parallel
await Promise.all(
Array.from(uniqueDirs).map((dir) => mkdirp(dir))
);
}