Skip to content

Commit d920980

Browse files
teemingcChew Tee Mingbenmccann
authored
chore: check WORKERS_CI env variable to determine if we're building for Cloudflare Workers (#13733)
Inspired by unjs/std-env#156 ~This PR detects the `WORKERS_CI` environment variable so that `adapter-auto` and `adapter-cloudflare` can work with Cloudflare's [Workers Git integration](https://developers.cloudflare.com/workers/ci-cd/builds/) to build the app without requiring a wrangler configuration from the user.~ I've changed the scope of the PR to focus on only the Cloudflare adapter because we'll may end up deprecating adapter-auto. Also, it doesn't work well with adapter-auto since it requires a wrangler config file. --- ### Please don't delete this checklist! Before submitting the PR, please make sure you do the following: - [x] 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 - [x] This message body should clearly illustrate what problems it solves. - [x] 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 - [x] 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:`. ### Edits - [x] Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed. --------- Co-authored-by: Chew Tee Ming <chew.tee.ming@nindatech.com> Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
1 parent 7ea8afe commit d920980

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changeset/plenty-cougars-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-cloudflare': patch
3+
---
4+
5+
chore: check the `WORKERS_CI` environment variable to determine if we're building for Cloudflare Workers

packages/adapter-cloudflare/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function is_building_for_cloudflare_pages(wrangler_config) {
99
return true;
1010
}
1111

12-
if (wrangler_config.main || wrangler_config.assets) {
12+
if (!!process.env.WORKERS_CI || wrangler_config.main || wrangler_config.assets) {
1313
return false;
1414
}
1515

packages/adapter-cloudflare/utils.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ describe('detects Cloudflare Workers project', () => {
6868
)
6969
).toBe(false);
7070
});
71+
72+
test('WORKERS_CI environment variable', () => {
73+
vi.stubEnv('WORKERS_CI', '1');
74+
const result = is_building_for_cloudflare_pages(
75+
/** @type {import('wrangler').Unstable_Config} */ ({})
76+
);
77+
vi.unstubAllEnvs();
78+
expect(result).toBe(false);
79+
});
7180
});
7281

7382
describe('validates Wrangler config', () => {

0 commit comments

Comments
 (0)