summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/integrations/cloudflare/src/index.ts13
-rw-r--r--packages/integrations/cloudflare/src/utils/index.ts8
-rw-r--r--packages/integrations/cloudflare/src/utils/non-server-chunk-detector.ts2
3 files changed, 21 insertions, 2 deletions
diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts
index 8e98a192b..a575b9b0a 100644
--- a/packages/integrations/cloudflare/src/index.ts
+++ b/packages/integrations/cloudflare/src/index.ts
@@ -367,8 +367,17 @@ export default function createIntegration(args?: Options): AstroIntegration {
// Those modules are build only for prerendering routes.
const chunksToDelete = chunkAnalyzer.getNonServerChunks();
for (const chunk of chunksToDelete) {
- // Chunks are located on `./_worker.js` directory inside of the output directory
- await unlink(new URL(`./_worker.js/${chunk}`, _config.outDir));
+ try {
+ // Chunks are located on `./_worker.js` directory inside of the output directory
+ await unlink(new URL(`./_worker.js/${chunk}`, _config.outDir));
+ } catch (error) {
+ logger.warn(
+ `Issue while trying to delete unused file from server bundle: ${new URL(
+ `./_worker.js/${chunk}`,
+ _config.outDir
+ ).toString()}`
+ );
+ }
}
},
},
diff --git a/packages/integrations/cloudflare/src/utils/index.ts b/packages/integrations/cloudflare/src/utils/index.ts
index 639e0e761..3221a25bc 100644
--- a/packages/integrations/cloudflare/src/utils/index.ts
+++ b/packages/integrations/cloudflare/src/utils/index.ts
@@ -22,6 +22,14 @@ export function mutatePageMapInPlace(
if (arrayExpression.start && arrayExpression.end) {
// @ts-expect-error - @types/estree seem to be wrong
s.remove(arrayExpression.start, arrayExpression.end);
+
+ // We need to check if there are any leftover commas, which are not part of the `ArrayExpression` node
+ // @ts-expect-error - @types/estree seem to be wrong
+ const endChar = s.slice(arrayExpression.end, arrayExpression.end + 1);
+ if (endChar.includes(',')) {
+ // @ts-expect-error - @types/estree seem to be wrong
+ s.remove(arrayExpression.end, arrayExpression.end + 1);
+ }
}
}
}
diff --git a/packages/integrations/cloudflare/src/utils/non-server-chunk-detector.ts b/packages/integrations/cloudflare/src/utils/non-server-chunk-detector.ts
index c7e766802..26061c347 100644
--- a/packages/integrations/cloudflare/src/utils/non-server-chunk-detector.ts
+++ b/packages/integrations/cloudflare/src/utils/non-server-chunk-detector.ts
@@ -15,6 +15,8 @@ export class NonServerChunkDetector {
return {
name: 'non-server-chunk-detector',
generateBundle: (_, bundle) => {
+ // Skip if we bundle for client
+ if (!bundle['index.js']) return;
this.processBundle(bundle);
},
};