Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sveltejs/adapter-cloudflare-workers

Package Overview
Dependencies
Maintainers
4
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sveltejs/adapter-cloudflare-workers - npm Package Compare versions

Comparing version 2.0.3 to 2.1.0

6

index.d.ts
import { Adapter } from '@sveltejs/kit';
import './ambient.js';
export default function plugin(options?: { config?: string }): Adapter;
export default function plugin(options?: AdapterOptions): Adapter;
export interface AdapterOptions {
config?: string;
}

@@ -14,5 +14,21 @@ import { existsSync, readFileSync, writeFileSync } from 'node:fs';

* }
* compatibility_flags?: string[];
* }} WranglerConfig
*/
// 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} */

@@ -24,3 +40,3 @@ export default function ({ config = 'wrangler.toml' } = {}) {

async adapt(builder) {
const { main, site } = validate_config(builder, config);
const { main, site, compatibility_flags } = validate_config(builder, config);

@@ -66,17 +82,61 @@ const files = fileURLToPath(new URL('./files', import.meta.url).href);

await esbuild.build({
platform: 'browser',
conditions: ['worker', 'browser'],
sourcemap: 'linked',
target: 'es2022',
entryPoints: [`${tmp}/entry.js`],
outfile: main,
bundle: true,
external: ['__STATIC_CONTENT_MANIFEST', 'cloudflare:*'],
format: 'esm',
loader: {
'.wasm': 'copy'
const external = ['__STATIC_CONTENT_MANIFEST', 'cloudflare:*'];
if (compatibility_flags && compatibility_flags.includes('nodejs_compat')) {
external.push(...compatible_node_modules.map((id) => `node:${id}`));
}
try {
const result = await esbuild.build({
platform: 'browser',
conditions: ['worker', 'browser'],
sourcemap: 'linked',
target: 'es2022',
entryPoints: [`${tmp}/entry.js`],
outfile: main,
bundle: true,
external,
alias: Object.fromEntries(compatible_node_modules.map((id) => [id, `node:${id}`])),
format: 'esm',
loader: {
'.wasm': 'copy'
},
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'
}`
);
}
builder.log.minor('Copying assets...');

@@ -83,0 +143,0 @@ const bucket_dir = `${site.bucket}${builder.config.kit.paths.base}`;

4

package.json
{
"name": "@sveltejs/adapter-cloudflare-workers",
"version": "2.0.3",
"version": "2.1.0",
"description": "SvelteKit adapter that creates a Cloudflare Workers site using a function for dynamic server rendering",

@@ -36,3 +36,3 @@ "repository": {

"typescript": "^5.3.3",
"@sveltejs/kit": "^2.3.3"
"@sveltejs/kit": "^2.4.0"
},

@@ -39,0 +39,0 @@ "peerDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc