Skip to content

Commit

Permalink
Use fileUrlToPath to fix path on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sondr3 committed Dec 29, 2022
1 parent cef27ed commit d9d04eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ const filterFile = (file: string): boolean => {
);
};

export const gzip = async (dir: URL): Promise<void> => {
export const gzip = async (dir: string): Promise<void> => {
const start = hrtime.bigint();

let counter = 0;
for await (const file of walkDir(dir.pathname)) {
for await (const file of walkDir(dir)) {
counter += 1;
const source = createReadStream(file);
const destination = createWriteStream(`${file}.gz`);
Expand All @@ -41,11 +41,11 @@ export const gzip = async (dir: URL): Promise<void> => {
Logger.success(`finished gzip of ${counter} files in ${(end - start) / 1000000n}ms`);
};

export const brotli = async (dir: URL): Promise<void> => {
export const brotli = async (dir: string): Promise<void> => {
const start = hrtime.bigint();

let counter = 0;
for await (const file of walkDir(dir.pathname)) {
for await (const file of walkDir(dir)) {
counter += 1;
const source = createReadStream(file);
const destination = createWriteStream(`${file}.br`);
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AstroIntegration } from "astro";
import { fileURLToPath } from "url";

import { brotli, gzip } from "./compress.js";
import { Logger } from "./logger.js";
Expand All @@ -8,7 +9,8 @@ export const createCompressionPlugin = (): AstroIntegration => {
name: "astro-compressor",
hooks: {
"astro:build:done": async ({ dir }) => {
await Promise.allSettled([gzip(dir), brotli(dir)]);
const path = fileURLToPath(dir);
await Promise.allSettled([gzip(path), brotli(path)]);
Logger.success("Compression finished\n");
},
},
Expand Down

0 comments on commit d9d04eb

Please sign in to comment.