Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hack for @frostoven/libsquoosh #3

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
20 changes: 1 addition & 19 deletions squoosh.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
import module from 'node:module'
import * as path from 'node:path'
import url from 'node:url'
import os from 'node:os'
import fs from 'node:fs/promises'

const LIB_SQUOOSH_HACK_CODE = 'var fetch;'

async function importLibrarySquoosh() {
const libsquooshEntry = module
.createRequire(import.meta.url)
.resolve('@frostoven/libsquoosh')
const content = await fs.readFile(libsquooshEntry, 'utf8')

if (!content.startsWith(LIB_SQUOOSH_HACK_CODE)) {
await fs.writeFile(libsquooshEntry, LIB_SQUOOSH_HACK_CODE + content)
}

return import(url.pathToFileURL(libsquooshEntry).href)
}

const encoders = new Map([
['.jpg', 'mozjpeg'],
Expand All @@ -38,7 +20,7 @@ async function squooshImages(files) {
return []
}

const {ImagePool} = await importLibrarySquoosh()
const {ImagePool} = await import('@frostoven/libsquoosh')
const imagePool = new ImagePool(os.cpus().length)

let result
Expand Down
Loading