Skip to content

Pass external to esbuild in the Cloudflare adapters#10424

Closed
cimnine wants to merge 2 commits into
sveltejs:masterfrom
cimnine:cf_esbuild_external
Closed

Pass external to esbuild in the Cloudflare adapters#10424
cimnine wants to merge 2 commits into
sveltejs:masterfrom
cimnine:cf_esbuild_external

Conversation

@cimnine

@cimnine cimnine commented Jul 23, 2023

Copy link
Copy Markdown

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Some external modules rely on NodeJS modules, such as fs. This causes problems during npm run build, even if my code does not rely on the respective code-path that requires any problematic modules (like fs). For me, this is the case with ical-generator.

This change is inspired by the already existing functionality in the Vercel adapter, that accomplished the same:

export interface EdgeConfig {
/**
* Whether to use [Edge Functions](https://vercel.com/docs/concepts/functions/edge-functions) or [Serverless Functions](https://vercel.com/docs/concepts/functions/serverless-functions)
*/
runtime?: 'edge';
/**
* To which regions to deploy the app. A list of regions or `'all'`.
* More info: https://vercel.com/docs/concepts/edge-network/regions
*/
regions?: string[] | 'all';
/**
* List of packages that should not be bundled into the Edge Function.
* Edge only.
*/
external?: string[];
/**
* If `true`, this route will always be deployed as its own separate function
*/
split?: boolean;
}

Respectively:

await esbuild.build({
entryPoints: [`${tmp}/edge.js`],
outfile: `${dirs.functions}/${name}.func/index.js`,
target: 'es2020', // TODO verify what the edge runtime supports
bundle: true,
platform: 'browser',
format: 'esm',
external: config.external,
sourcemap: 'linked',
banner: { js: 'globalThis.global = globalThis;' },
loader: {
'.wasm': 'copy'
}
});

The only related issue that I've found was #6547, which was resolved because Stripe changed their implementation. This is the ideal resolution, I admit, but the world is not ideal as far as I'm concerned.

@changeset-bot

changeset-bot Bot commented Jul 23, 2023

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3c767a7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@sveltejs/adapter-cloudflare-workers Minor
@sveltejs/adapter-cloudflare Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gtm-nayan

Copy link
Copy Markdown
Contributor

Related
#10214
#10110

@cimnine

cimnine commented Jul 23, 2023

Copy link
Copy Markdown
Author

Oh, I didn't check the PRs before 😅 At least, there seems to be a need.

Comment thread CONTRIBUTING.md Outdated
Comment thread documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md Outdated
Comment thread .github/PULL_REQUEST_TEMPLATE.md Outdated
Comment thread CONTRIBUTING.md Outdated
@cimnine

cimnine commented Aug 2, 2023

Copy link
Copy Markdown
Author

I've applied the requested changes and rebased onto the latest master.

@cimnine cimnine requested a review from benmccann August 2, 2023 21:55
@benmccann

Copy link
Copy Markdown
Member

Related
#10214
#10110

Thanks for tracking those down. I've closed them in favor of this PR, which seems closest to being ready

Comment thread .github/PULL_REQUEST_TEMPLATE.md Outdated
Comment thread .changeset/popular-cats-own.md Outdated
Comment thread documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md Outdated
Comment thread documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md Outdated
Comment thread documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md Outdated
Comment thread documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md Outdated
};
```

### Custom config

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I change this one to config as well, like:

Suggested change
### Custom config
### `config`

That would be consistent with the other file, IMO.

cimnine and others added 2 commits August 10, 2023 08:18
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
@benmccann

Copy link
Copy Markdown
Member

Closing this in favor of #10521

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants