jsqrt / bun-bundler

Bun-Bundler: Modern, Simple, and Ultra-Fast HTML Bundler. Bun | Pug/HTML | SCSS/CSS | JS | SVG Sprite | Image optimizations
MIT License
4 stars 0 forks source link

Error compiling pug files: EISDIR is a directory #2

Closed karneaud closed 1 month ago

karneaud commented 2 months ago

When compiling pug files in folder and there are empty folders I get the subject error:-

HTML compilation Error compiling pug file Error: EISDIR : is a directory

Which causes the compilation to terminate. Had to hack a workaround by changing this

    async compilePug() {
        this.debugLog('HTML compilation');
        try {
            await this.compile({
                filePaths: this.config.htmlFiles,
                extensionSkip: '.html',
                type: 'Pug',
                newFileExt: '.html',
                dist: this.config.distDir,
                renderFn: (filePath) => {
                    return pug.renderFile(filePath, {
                        pretty: false,
                        cache: false,
                        compileDebug: this.config.debug,
                        sitemap: this.config.htmlFiles.map((file) =>
                            path.basename(path.resolve(file).replace(/\.pug$/, '.html')),
                        ),
                        readFileSync,
                    });
                },
            });
        } catch (error) {
            this.errLog('Error while compiling pug files');
            this.errThrow(error);
        }
    }

with this


async compilePug() {
    this.debugLog('HTML compilation');
    try {
        await this.compile({
            filePaths: this.config.htmlFiles,
            extensionSkip: '.html',
            type: 'Pug',
            newFileExt: '.html',
            dist: this.config.distDir,
            renderFn: (filePath) => {
                // Check if filePath is a file and not a directory
                const fullPath = path.resolve(filePath);

                // Only render if it's a file
                if (fs.lstatSync(fullPath).isFile()) {
                    return pug.renderFile(fullPath, {
                        pretty: false,
                        cache: false,
                        compileDebug: this.config.debug,
                        sitemap: this.config.htmlFiles
                            .filter((file) => fs.lstatSync(file).isFile())  // Filter directories from sitemap too
                            .map((file) => path.basename(file).replace(/\.pug$/, '.html')),
                        readFileSync,
                    });
                } else {
                    this.debugLog(`Skipping: ${fullPath} is a directory`);
                }
            },
        });
    } catch (error) {
        this.errLog('Error while compiling pug files');
        this.errThrow(error);
    }
}
jsqrt commented 1 month ago

@karneaud fixed, thanks for pointing out ❤️