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

Pass external to esbuild in the Cloudflare adapters #10424

Closed
wants to merge 2 commits into from
Closed

Pass external to esbuild in the Cloudflare adapters #10424

wants to merge 2 commits into from

Conversation

cimnine
Copy link

@cimnine cimnine commented Jul 23, 2023

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.

Sorry, something went wrong.

@changeset-bot
Copy link

changeset-bot bot commented Jul 23, 2023

🦋 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
Contributor

Related
#10214
#10110

@cimnine
Copy link
Author

cimnine commented Jul 23, 2023

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

CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
@cimnine
Copy link
Author

cimnine commented Aug 2, 2023

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
Member

Related
#10214
#10110

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

}
};
```

### Custom config
Copy link
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

Verified

This commit was signed with the committer’s verified signature.
manimaul William Kamp
Co-authored-by: Ben McCann <[email protected]>
Co-authored-by: Ben McCann <[email protected]>
@benmccann
Copy link
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.

None yet

3 participants