Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e4a12c3
feat: add decompress option support with Fastly decompressGzip mappin…
claude Nov 19, 2025
c66a807
test: add decompress-test fixture for real-world testing
claude Nov 19, 2025
6c8fe08
fix: update copyright year to 2025
claude Nov 19, 2025
3e3b5d9
test: add tests for decompress-test fixture
claude Nov 19, 2025
840a8a6
fix: use single quotes in test assertion
claude Nov 19, 2025
c0ae542
fix: skip decompress-test build test temporarily
claude Nov 19, 2025
ba5e5a1
fix: skip decompress-test integration test
claude Nov 19, 2025
1a2de31
test: unskip decompress-test tests to investigate failures
claude Nov 20, 2025
155fde3
fix: correct zip path for decompress-test build
claude Nov 20, 2025
0a4957a
fix(test): remove update-package parameter from integration test
claude Nov 20, 2025
7cf2a6e
feat: implement context.log with Fastly logger multiplexing and Cloud…
claude Nov 19, 2025
0ed688a
refactor: address PR review feedback for context.log implementation
claude Nov 19, 2025
7a8b3bd
fix: add eslint exceptions for intentional console usage and fastly:l…
claude Nov 19, 2025
71de7c3
test: add integration tests for logging-example fixture
claude Nov 19, 2025
8f80c76
fix: add required package.params to logging-example integration tests
claude Nov 20, 2025
d1a82ea
fix: add action parameter to logging-example integration tests
claude Nov 20, 2025
64febd2
fix: use minified JSON in logging-example fixture
claude Nov 20, 2025
2166e72
chore(release): 1.2.0 [skip ci]
semantic-release-bot Nov 19, 2025
7d7b61f
test(integration): enable Cloudflare integration tests in CI (#87)
claude Nov 20, 2025
005310e
fix: enable workers.dev subdomain after deployment
claude Nov 20, 2025
572fdbe
test: add subdomain mock to CloudflareDeployer tests
claude Nov 20, 2025
c8633e3
test: update assertion for minivelos subdomain
claude Nov 20, 2025
83ca122
chore(release): 1.2.1 [skip ci]
semantic-release-bot Nov 24, 2025
ed54796
test: enable Cloudflare integration tests for decompress and logging
claude Nov 24, 2025
8bc8a39
fix: add missing semicolons in test files
claude Nov 24, 2025
dc408e7
fix: add missing cloudflare-auth parameter to integration tests
claude Nov 24, 2025
6bd5bc0
fix: add null-safe check for Cloudflare KV namespace results
claude Nov 24, 2025
673c81d
fix: add error handling for KV namespace creation
claude Nov 24, 2025
09024fd
fix: correct const/let usage in KV namespace creation
claude Nov 24, 2025
9b2decc
Merge main and skip failing Cloudflare tests
claude Nov 24, 2025
2d3eee9
test: unskip Cloudflare integration tests
claude Nov 24, 2025
1dbc188
Merge main: resolve test conflicts
claude Nov 26, 2025
c737dcf
Merge main: combine CacheOverride and decompress features
claude Nov 26, 2025
a1a7150
fix: resolve linting errors in fetch polyfill
claude Nov 26, 2025
278c36f
fix: use reassignment instead of mutation in wrappedFetch
claude Nov 26, 2025
5bd9988
fix: make fetch polyfill testable and preserve options correctly
claude Nov 26, 2025
c9a5da9
fix: strip Fastly-specific options on Cloudflare
claude Nov 26, 2025
50241ab
fix: use single underscore for unused destructured vars
claude Nov 26, 2025
b6d2e53
fix: refactor Fastly option stripping to satisfy linter
claude Nov 26, 2025
6f84815
fix: prioritize Fastly detection over Cloudflare in platform check
claude Nov 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/CloudflareDeployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,24 @@ export default class CloudflareDeployer extends BaseDeployer {
title: name,
},
});
let { result } = await postres.json();
const postData = await postres.json();
let { result } = postData;
const { errors } = postData;
if (!result) {
if (errors) {
this.log.debug(`KV namespace creation returned errors: ${JSON.stringify(errors)}`);
}
const listres = await this.fetch(`https://api.cloudflare.com/client/v4/accounts/${this._cfg.accountID}/storage/kv/namespaces`, {
method: 'GET',
headers: {
Authorization: `Bearer ${this._cfg.auth}`,
},
});
const { result: results } = await listres.json();
result = results.find((r) => r.title === name);
result = results?.find((r) => r.title === name);
}
if (!result) {
throw new Error(`Failed to create or find KV namespace: ${name}`);
}
return result;
}
Expand Down
88 changes: 57 additions & 31 deletions src/template/polyfills/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,57 +171,83 @@ class UnifiedCacheOverride {
}
}

// Store original fetch and other APIs
const originalFetch = globalThis.fetch;
// Store other APIs (but not fetch - we'll call it dynamically for testability)
const {
Request: OriginalRequest,
Response: OriginalResponse,
Headers: OriginalHeaders,
} = globalThis;

/**
* Wrapped fetch that supports the cacheOverride option
* Wrapped fetch that supports both cacheOverride and decompress options
* @param {string|Request} resource - URL or Request object
* @param {object} [options] - Fetch options with cacheOverride
* @param {object} [options] - Fetch options with cacheOverride and/or decompress
* @param {object} [options.cacheOverride] - CacheOverride instance for cache control
* @param {boolean} [options.decompress=true] - Whether to decompress gzip responses
* @param {object} [options.fastly] - Fastly-specific options
* @returns {Promise<Response>} Fetch response
*/
async function wrappedFetch(resource, options = {}) {
// Check for Cloudflare dynamically (for testability)
// Prioritize Fastly detection - if we successfully loaded fastly:cache-override, we're on Fastly
const isInCloudflare = !isFastly && typeof caches !== 'undefined' && caches.default !== undefined;

// On Cloudflare, strip out Fastly-specific options that aren't supported
const { cacheOverride, ...restOptions } = options;

if (!cacheOverride) {
// No cache override, use original fetch
return originalFetch(resource, restOptions);
// Strip Fastly-specific options when on Cloudflare
let fetchOptions;
if (isInCloudflare) {
// eslint-disable-next-line no-unused-vars
const { backend, cacheKey, ...cloudflareOptions } = restOptions;
fetchOptions = cloudflareOptions;
} else {
fetchOptions = restOptions;
}

// Initialize native CacheOverride on Fastly if needed
if (fastlyModulePromise || isFastly) {
await cacheOverride.initNative();
}
// Handle cacheOverride
if (cacheOverride) {
// Initialize native CacheOverride on Fastly if needed
if (fastlyModulePromise || isFastly) {
await cacheOverride.initNative();
}

if (isFastly && cacheOverride.native) {
// On Fastly, use native CacheOverride
return originalFetch(resource, {
...restOptions,
cacheOverride: cacheOverride.native,
});
if (isFastly && cacheOverride.native) {
// On Fastly, use native CacheOverride
fetchOptions = {
...fetchOptions,
cacheOverride: cacheOverride.native,
};
} else if (isCloudflare) {
// On Cloudflare, convert to cf options
const cfOptions = cacheOverride.toCloudflareOptions();
if (cfOptions) {
fetchOptions = {
...fetchOptions,
cf: {
...(fetchOptions.cf || {}),
...cfOptions,
},
};
}
}
}

if (isCloudflare) {
// On Cloudflare, convert to cf options
const cfOptions = cacheOverride.toCloudflareOptions();
if (cfOptions) {
return originalFetch(resource, {
...restOptions,
cf: {
...(restOptions.cf || {}),
...cfOptions,
},
});
}
// Handle decompress option
// On Cloudflare: pass through as-is (Cloudflare auto-decompresses)
// On Fastly/Node.js: map decompress to fastly.decompressGzip (default: true)
if (!isInCloudflare) {
const { decompress = true, fastly, ...otherOptions } = fetchOptions;
fetchOptions = {
...otherOptions,
fastly: {
decompressGzip: decompress,
...fastly, // explicit fastly options override
},
};
}

// Fallback: just use original fetch without cache override
return originalFetch(resource, restOptions);
return globalThis.fetch(resource, fetchOptions);
}

// Export as default for clean import syntax
Expand Down
35 changes: 35 additions & 0 deletions test/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async function assertZipEntries(zipPath, entries) {
}

const PROJECT_PURE = path.resolve(__rootdir, 'test', 'fixtures', 'pure-action');
const PROJECT_DECOMPRESS = path.resolve(__rootdir, 'test', 'fixtures', 'decompress-test');

describe('Edge Build Test', () => {
let testRoot;
Expand Down Expand Up @@ -136,4 +137,38 @@ describe('Edge Build Test', () => {
*/
})
.timeout(50000);

it('generates the bundle for decompress-test fixture', async () => {
await fse.remove(testRoot);
testRoot = await createTestRoot();
await fse.copy(PROJECT_DECOMPRESS, testRoot);

// need to change .cwd() for yargs to pickup `wsk` in package.json
process.chdir(testRoot);
process.env.WSK_AUTH = 'foobar';
process.env.WSK_NAMESPACE = 'foobar';
process.env.WSK_APIHOST = 'https://example.com';
process.env.__OW_ACTION_NAME = '/namespace/package/name@version';
const builder = await new CLI()
.prepare([
'--target', 'wsk',
'--plugin', path.resolve(__rootdir, 'src', 'index.js'),
'--bundler', 'webpack',
'--esm', 'false',
'--arch', 'edge',
'--verbose',
'--directory', testRoot,
'--entryFile', 'src/index.js',
]);

await builder.run();

// The zip is created in dist/{package-name}/ not dist/default/
await assertZipEntries(path.resolve(testRoot, 'dist', 'decompress-package', 'decompress-test.zip'), [
'index.js',
'package.json',
'wrangler.toml',
]);
})
.timeout(50000);
});
40 changes: 36 additions & 4 deletions test/cloudflare.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,38 @@ describe('Cloudflare Integration Test', () => {
assert.ok(out.indexOf('https://simple-package--simple-project.minivelos.workers.dev') > 0, out);
}).timeout(10000000);

it.skip('Deploy logging example to Cloudflare', async () => {
it('Deploy decompress-test fixture to Cloudflare', async () => {
await fse.copy(path.resolve(__rootdir, 'test', 'fixtures', 'decompress-test'), testRoot);
process.chdir(testRoot);
const builder = await new CLI()
.prepare([
'--build',
'--verbose',
'--deploy',
'--target', 'cloudflare',
'--plugin', path.resolve(__rootdir, 'src', 'index.js'),
'--arch', 'edge',
'--cloudflare-email', 'lars@trieloff.net',
'--cloudflare-account-id', '155ec15a52a18a14801e04b019da5e5a',
'--cloudflare-test-domain', 'minivelos',
'--cloudflare-auth', process.env.CLOUDFLARE_AUTH,
'--update-package', 'true',
'--test', '/gzip',
'--directory', testRoot,
'--entryFile', 'src/index.js',
'--bundler', 'webpack',
'--esm', 'false',
]);
builder.cfg._logger = new TestLogger();

const res = await builder.run();
assert.ok(res);
const out = builder.cfg._logger.output;
assert.ok(out.indexOf('decompress-package--decompress-test.minivelos.workers.dev') > 0, out);
assert.ok(out.indexOf('"test":"decompress-true"') > 0 || out.indexOf('"isDecompressed":true') > 0, `The function output should indicate decompression worked: ${out}`);
}).timeout(10000000);

it('Deploy logging example to Cloudflare', async () => {
await fse.copy(path.resolve(__rootdir, 'test', 'fixtures', 'logging-example'), testRoot);
process.chdir(testRoot);
const builder = await new CLI()
Expand All @@ -80,8 +111,9 @@ describe('Cloudflare Integration Test', () => {
'--plugin', path.resolve(__rootdir, 'src', 'index.js'),
'--arch', 'edge',
'--cloudflare-email', 'lars@trieloff.net',
'--cloudflare-account-id', 'b4adf6cfdac0918eb6aa5ad033da0747',
'--cloudflare-test-domain', 'rockerduck',
'--cloudflare-account-id', '155ec15a52a18a14801e04b019da5e5a',
'--cloudflare-test-domain', 'minivelos',
'--cloudflare-auth', process.env.CLOUDFLARE_AUTH,
'--package.name', 'logging-test',
'--package.params', 'TEST=logging',
'--update-package', 'true',
Expand All @@ -97,7 +129,7 @@ describe('Cloudflare Integration Test', () => {
const res = await builder.run();
assert.ok(res);
const out = builder.cfg._logger.output;
assert.ok(out.indexOf('rockerduck.workers.dev') > 0, out);
assert.ok(out.indexOf('minivelos.workers.dev') > 0, out);
assert.ok(out.indexOf('"status":"ok"') > 0, 'Response should include status ok');
assert.ok(out.indexOf('"logging":"enabled"') > 0, 'Response should indicate logging is enabled');
}).timeout(10000000);
Expand Down
34 changes: 34 additions & 0 deletions test/computeatedge.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,40 @@ describe('Fastly Compute@Edge Integration Test', () => {
assert.ok(keyText.indexOf('cacheKey=test-key') > 0, 'Should include cache key parameter');
}).timeout(10000000);

it('Deploy decompress-test fixture to Compute@Edge', async () => {
const serviceID = '1yv1Wl7NQCFmNBkW4L8htc';

await fse.copy(path.resolve(__rootdir, 'test', 'fixtures', 'decompress-test'), testRoot);
process.chdir(testRoot);
const builder = await new CLI()
.prepare([
'--build',
'--plugin', resolve(__rootdir, 'src', 'index.js'),
'--verbose',
'--deploy',
'--target', 'c@e',
'--arch', 'edge',
'--compute-service-id', serviceID,
'--compute-test-domain', 'possibly-working-sawfish',
'--package.name', 'DecompressTest',
'--fastly-gateway', 'deploy-test.anywhere.run',
'--fastly-service-id', '4u8SAdblhzzbXntBYCjhcK',
'--test', '/gzip',
'--directory', testRoot,
'--entryFile', 'src/index.js',
'--bundler', 'webpack',
'--esm', 'false',
]);
builder.cfg._logger = new TestLogger();

const res = await builder.run();
assert.ok(res);
const out = builder.cfg._logger.output;
assert.ok(out.indexOf('possibly-working-sawfish.edgecompute.app') > 0, out);
assert.ok(out.indexOf('"test":"decompress-true"') > 0 || out.indexOf('"isDecompressed":true') > 0, `The function output should indicate decompression worked: ${out}`);
assert.ok(out.indexOf('dist/DecompressTest/fastly-bundle.tar.gz') > 0, out);
}).timeout(10000000);

it('Deploy logging example to Compute@Edge', async () => {
const serviceID = '1yv1Wl7NQCFmNBkW4L8htc';

Expand Down
Loading
Loading