@sveltejs/adapter-cloudflare
Advanced tools
Comparing version 4.0.2 to 4.1.0
86
index.js
@@ -6,2 +6,17 @@ import { writeFileSync } from 'node:fs'; | ||
// list from https://developers.cloudflare.com/workers/runtime-apis/nodejs/ | ||
const compatible_node_modules = [ | ||
'assert', | ||
'async_hooks', | ||
'buffer', | ||
'crypto', | ||
'diagnostics_channel', | ||
'events', | ||
'path', | ||
'process', | ||
'stream', | ||
'string_decoder', | ||
'util' | ||
]; | ||
/** @type {import('./index.js').default} */ | ||
@@ -57,17 +72,58 @@ export default function (options = {}) { | ||
await esbuild.build({ | ||
platform: 'browser', | ||
conditions: ['worker', 'browser'], | ||
sourcemap: 'linked', | ||
target: 'es2022', | ||
entryPoints: [`${tmp}/_worker.js`], | ||
outfile: `${dest}/_worker.js`, | ||
allowOverwrite: true, | ||
format: 'esm', | ||
bundle: true, | ||
loader: { | ||
'.wasm': 'copy' | ||
}, | ||
external: ['cloudflare:*'] | ||
}); | ||
const external = ['cloudflare:*', ...compatible_node_modules.map((id) => `node:${id}`)]; | ||
try { | ||
const result = await esbuild.build({ | ||
platform: 'browser', | ||
conditions: ['worker', 'browser'], | ||
sourcemap: 'linked', | ||
target: 'es2022', | ||
entryPoints: [`${tmp}/_worker.js`], | ||
outfile: `${dest}/_worker.js`, | ||
allowOverwrite: true, | ||
format: 'esm', | ||
bundle: true, | ||
loader: { | ||
'.wasm': 'copy' | ||
}, | ||
external, | ||
alias: Object.fromEntries(compatible_node_modules.map((id) => [id, `node:${id}`])), | ||
logLevel: 'silent' | ||
}); | ||
if (result.warnings.length > 0) { | ||
const formatted = await esbuild.formatMessages(result.warnings, { | ||
kind: 'warning', | ||
color: true | ||
}); | ||
console.error(formatted.join('\n')); | ||
} | ||
} catch (error) { | ||
for (const e of error.errors) { | ||
for (const node of e.notes) { | ||
const match = | ||
/The package "(.+)" wasn't found on the file system but is built into node/.exec( | ||
node.text | ||
); | ||
if (match) { | ||
node.text = `Cannot use "${match[1]}" when deploying to Cloudflare.`; | ||
} | ||
} | ||
} | ||
const formatted = await esbuild.formatMessages(error.errors, { | ||
kind: 'error', | ||
color: true | ||
}); | ||
console.error(formatted.join('\n')); | ||
throw new Error( | ||
`Bundling with esbuild failed with ${error.errors.length} ${ | ||
error.errors.length === 1 ? 'error' : 'errors' | ||
}` | ||
); | ||
} | ||
} | ||
@@ -74,0 +130,0 @@ }; |
{ | ||
"name": "@sveltejs/adapter-cloudflare", | ||
"version": "4.0.2", | ||
"version": "4.1.0", | ||
"description": "Adapter for building SvelteKit applications on Cloudflare Pages with Workers integration", | ||
@@ -36,3 +36,3 @@ "repository": { | ||
"typescript": "^5.3.3", | ||
"@sveltejs/kit": "^2.3.5" | ||
"@sveltejs/kit": "^2.4.0" | ||
}, | ||
@@ -39,0 +39,0 @@ "peerDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13639
328