Skip to content

Commit

Permalink
Fix image integration not working on Node 18+ (#5871)
Browse files Browse the repository at this point in the history
* fix(image): Remove unnecessary polyfill now that we dropped Node 14

* fix(squoosh): Remove fetch of local wasm binary since undici doesn't support that

* chore: changeset
  • Loading branch information
Princesseuh committed Jan 17, 2023
1 parent 998f412 commit 1bd42c6
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 215 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-mirrors-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/image': patch
---

Fix the integration failing to work properly on Node 18+
3 changes: 1 addition & 2 deletions packages/integrations/image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
"kleur": "^4.1.5",
"magic-string": "^0.25.9",
"mime": "^3.0.0",
"slash": "^4.0.0",
"web-streams-polyfill": "^3.2.1"
"slash": "^4.0.0"
},
"devDependencies": {
"@types/http-cache-semantics": "^4.0.1",
Expand Down
1 change: 0 additions & 1 deletion packages/integrations/image/src/utils/workerPool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* tslint-disable ban-types */
import { TransformStream } from 'web-streams-polyfill';
import { parentPort, Worker } from 'worker_threads';

function uuid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,22 +384,6 @@ var Module = (function () {
}
}
function getBinaryPromise() {
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
if (typeof fetch === 'function') {
return fetch(wasmBinaryFile, { credentials: 'same-origin' })
.then(function (response) {
if (!response['ok']) {
throw (
"failed to load wasm binary file at '" + wasmBinaryFile + "'"
)
}
return response['arrayBuffer']()
})
.catch(function () {
return getBinary(wasmBinaryFile)
})
}
}
return Promise.resolve().then(function () {
return getBinary(wasmBinaryFile)
})
Expand Down Expand Up @@ -431,25 +415,7 @@ var Module = (function () {
})
}
function instantiateAsync() {
if (
!wasmBinary &&
typeof WebAssembly.instantiateStreaming === 'function' &&
!isDataURI(wasmBinaryFile) &&
typeof fetch === 'function'
) {
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(
function (response) {
var result = WebAssembly.instantiateStreaming(response, info)
return result.then(receiveInstantiationResult, function (reason) {
err('wasm streaming compile failed: ' + reason)
err('falling back to ArrayBuffer instantiation')
return instantiateArrayBuffer(receiveInstantiationResult)
})
}
)
} else {
return instantiateArrayBuffer(receiveInstantiationResult)
}
return instantiateArrayBuffer(receiveInstantiationResult)
}
if (Module['instantiateWasm']) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,22 +384,6 @@ var Module = (function () {
}
}
function getBinaryPromise() {
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
if (typeof fetch === 'function') {
return fetch(wasmBinaryFile, { credentials: 'same-origin' })
.then(function (response) {
if (!response['ok']) {
throw (
"failed to load wasm binary file at '" + wasmBinaryFile + "'"
)
}
return response['arrayBuffer']()
})
.catch(function () {
return getBinary(wasmBinaryFile)
})
}
}
return Promise.resolve().then(function () {
return getBinary(wasmBinaryFile)
})
Expand Down Expand Up @@ -431,25 +415,7 @@ var Module = (function () {
})
}
function instantiateAsync() {
if (
!wasmBinary &&
typeof WebAssembly.instantiateStreaming === 'function' &&
!isDataURI(wasmBinaryFile) &&
typeof fetch === 'function'
) {
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(
function (response) {
var result = WebAssembly.instantiateStreaming(response, info)
return result.then(receiveInstantiationResult, function (reason) {
err('wasm streaming compile failed: ' + reason)
err('falling back to ArrayBuffer instantiation')
return instantiateArrayBuffer(receiveInstantiationResult)
})
}
)
} else {
return instantiateArrayBuffer(receiveInstantiationResult)
}
return instantiateArrayBuffer(receiveInstantiationResult)
}
if (Module['instantiateWasm']) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,22 +391,6 @@ var Module = (function () {
}
}
function getBinaryPromise() {
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
if (typeof fetch === 'function') {
return fetch(wasmBinaryFile, { credentials: 'same-origin' })
.then(function (response) {
if (!response['ok']) {
throw (
"failed to load wasm binary file at '" + wasmBinaryFile + "'"
)
}
return response['arrayBuffer']()
})
.catch(function () {
return getBinary(wasmBinaryFile)
})
}
}
return Promise.resolve().then(function () {
return getBinary(wasmBinaryFile)
})
Expand Down Expand Up @@ -438,25 +422,7 @@ var Module = (function () {
})
}
function instantiateAsync() {
if (
!wasmBinary &&
typeof WebAssembly.instantiateStreaming === 'function' &&
!isDataURI(wasmBinaryFile) &&
typeof fetch === 'function'
) {
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(
function (response) {
var result = WebAssembly.instantiateStreaming(response, info)
return result.then(receiveInstantiationResult, function (reason) {
err('wasm streaming compile failed: ' + reason)
err('falling back to ArrayBuffer instantiation')
return instantiateArrayBuffer(receiveInstantiationResult)
})
}
)
} else {
return instantiateArrayBuffer(receiveInstantiationResult)
}
return instantiateArrayBuffer(receiveInstantiationResult)
}
if (Module['instantiateWasm']) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,22 +391,6 @@ var Module = (function () {
}
}
function getBinaryPromise() {
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
if (typeof fetch === 'function') {
return fetch(wasmBinaryFile, { credentials: 'same-origin' })
.then(function (response) {
if (!response['ok']) {
throw (
"failed to load wasm binary file at '" + wasmBinaryFile + "'"
)
}
return response['arrayBuffer']()
})
.catch(function () {
return getBinary(wasmBinaryFile)
})
}
}
return Promise.resolve().then(function () {
return getBinary(wasmBinaryFile)
})
Expand Down Expand Up @@ -438,25 +422,7 @@ var Module = (function () {
})
}
function instantiateAsync() {
if (
!wasmBinary &&
typeof WebAssembly.instantiateStreaming === 'function' &&
!isDataURI(wasmBinaryFile) &&
typeof fetch === 'function'
) {
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(
function (response) {
var result = WebAssembly.instantiateStreaming(response, info)
return result.then(receiveInstantiationResult, function (reason) {
err('wasm streaming compile failed: ' + reason)
err('falling back to ArrayBuffer instantiation')
return instantiateArrayBuffer(receiveInstantiationResult)
})
}
)
} else {
return instantiateArrayBuffer(receiveInstantiationResult)
}
return instantiateArrayBuffer(receiveInstantiationResult)
}
if (Module['instantiateWasm']) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,22 +367,6 @@ var Module = (function () {
}
}
function getBinaryPromise() {
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
if (typeof fetch === 'function') {
return fetch(wasmBinaryFile, { credentials: 'same-origin' })
.then(function (response) {
if (!response['ok']) {
throw (
"failed to load wasm binary file at '" + wasmBinaryFile + "'"
)
}
return response['arrayBuffer']()
})
.catch(function () {
return getBinary(wasmBinaryFile)
})
}
}
return Promise.resolve().then(function () {
return getBinary(wasmBinaryFile)
})
Expand Down Expand Up @@ -414,25 +398,7 @@ var Module = (function () {
})
}
function instantiateAsync() {
if (
!wasmBinary &&
typeof WebAssembly.instantiateStreaming === 'function' &&
!isDataURI(wasmBinaryFile) &&
typeof fetch === 'function'
) {
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(
function (response) {
var result = WebAssembly.instantiateStreaming(response, info)
return result.then(receiveInstantiationResult, function (reason) {
err('wasm streaming compile failed: ' + reason)
err('falling back to ArrayBuffer instantiation')
return instantiateArrayBuffer(receiveInstantiationResult)
})
}
)
} else {
return instantiateArrayBuffer(receiveInstantiationResult)
}
return instantiateArrayBuffer(receiveInstantiationResult)
}
if (Module['instantiateWasm']) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,22 +367,6 @@ var Module = (function () {
}
}
function getBinaryPromise() {
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
if (typeof fetch === 'function') {
return fetch(wasmBinaryFile, { credentials: 'same-origin' })
.then(function (response) {
if (!response['ok']) {
throw (
"failed to load wasm binary file at '" + wasmBinaryFile + "'"
)
}
return response['arrayBuffer']()
})
.catch(function () {
return getBinary(wasmBinaryFile)
})
}
}
return Promise.resolve().then(function () {
return getBinary(wasmBinaryFile)
})
Expand Down Expand Up @@ -414,25 +398,7 @@ var Module = (function () {
})
}
function instantiateAsync() {
if (
!wasmBinary &&
typeof WebAssembly.instantiateStreaming === 'function' &&
!isDataURI(wasmBinaryFile) &&
typeof fetch === 'function'
) {
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(
function (response) {
var result = WebAssembly.instantiateStreaming(response, info)
return result.then(receiveInstantiationResult, function (reason) {
err('wasm streaming compile failed: ' + reason)
err('falling back to ArrayBuffer instantiation')
return instantiateArrayBuffer(receiveInstantiationResult)
})
}
)
} else {
return instantiateArrayBuffer(receiveInstantiationResult)
}
return instantiateArrayBuffer(receiveInstantiationResult)
}
if (Module['instantiateWasm']) {
try {
Expand Down
2 changes: 0 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1bd42c6

Please sign in to comment.