-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
adapters shouldn't pass arbitrary options to esbuild #4639
Conversation
🦋 Changeset detectedLatest commit: 8916210 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
fyi @pzuraq also mentioned a need for external here #4276 (comment) |
this would definitely be a breaking change for us, however I am going to investigate an alternative approach that encapsulates my build requirements at the vite configuration level. after initial investigation im not 100% sure this is going to be possible. ideally for myself, exposing a unified interface for all adapters that allows people to hook into the esbuild process is extremely useful for getting out of some sticky jams to do with your target environment. my vote goes for the shape @Rich-Harris hinted at above, something like i will update here once ive been able to fully test if we can achieve what we need without this requirement |
I would also strongly prefer the |
Many adapters don't use If someone can provide a repro of a problem that is currently solved via |
makes sense, just waiting on the pre-rendering fix to land before we migrate our apps to the Module Worker pattern |
I just cut a new release |
This could be related to the way I'll try to make a reproduction when I have time. |
after a few hours of messing around with custom rollup/vite plugins, i've been unable to get a complete solution for the i got mostly there, resolving the node internal packages to browserify alternatives. however, it appears i'm hitting a similar issue to @pzuraq. no matter what i try, the i feel like i'm close, but i also feel like it's a set of magic incantations to get this to work through vite plugin (shimming node built-ins) - as far as i can tell this worksimport { resolve, join } from 'path';
import findWorkspaceRoot from 'find-yarn-workspace-root';
const root = findWorkspaceRoot(process.cwd());
const nm = join(root, 'node_modules');
export function stripePre() {
return {
name: 'vite-plugin-stripe-cloudflare-workers',
enforce: 'pre',
resolveId(importee, ...rest) {
if (
importee.startsWith('\0child_process')
|| importee.startsWith('\0http')
|| importee.startsWith('\0https')
) {
return {
id: resolve(nm, '@package/build-tools/stub.js'),
};
}
if (importee.startsWith('\0buffer')) {
return {
id: resolve(nm, 'buffer/index.js'),
};
}
if (importee.startsWith('\0crypto')) {
return {
id: resolve(nm, 'crypto-browserify/index.js'),
};
}
if (importee.startsWith('\0events')) {
return {
id: resolve(nm, 'events/events.js'),
};
}
if (importee.startsWith('\0path')) {
return {
id: resolve(nm, 'path-browserify/index.js'),
};
}
if (importee.startsWith('\0stream')) {
return {
id: resolve(nm, 'stream-browserify/index.js'),
};
}
if (importee.startsWith('\x00util')) {
return {
id: resolve(nm, 'util/util.js'),
};
}
},
};
} vite plugin (overwriting references to process.env) - this is not showing up in output, however it _is_ run. this is simply an alternative trying to make `define`export function stripePost() {
return {
name: 'vite-plugin-stripe-cloudflare-workers-post',
enforce: 'post',
transform(code, id) {
let transformed = false;
let output = code;
if (output.includes('process.env.NODE_ENV')) {
output = output.replaceAll('process.env.NODE_ENV', '"production"');
transformed = true;
}
if (output.includes('process.env.NODE_DEBUG')) {
output = output.replaceAll('process.env.NODE_DEBUG', 'false');
transformed = true;
}
if (transformed) return { code: output, map: null };
}
}
} i also still need to work out injection of globals, these are unfortunately globals required by |
@f5io — you might find this useful: cloudflare/workers-sdk#869 |
Added a check that immediately throws an error if someone passes |
See #4626 (comment) for a previous discussion about this. Currently,
adapter-cloudflare
andadapter-cloudflare-workers
both pass their own options to esbuild.This is bad API design — it's brittle and leaky. Beyond that, I'm not convinced it's even necessary. The cases where people want to manipulate the build output in some way (shimming node built-ins, etc) are all cases where the manipulation should probably happen long before the adapter gets involved. Assuming we manage to pull off #3535, that will become important anyway.
This PR removes the options altogether. If people report issues, we could consider adding the options back, but with a different API (like
{ esbuild: {...} }
, or exposing individual options likeexternal
the way we do foradapter-vercel
, not that I'd expect that to make any sense in the Cloudflare context).Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0