-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix remaining cloudflare tests #14912
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9a09692
Fix remaining cloudflare tests
matthewp 844e11e
testing
matthewp 58c2db5
just a test
matthewp afdab2e
try this
matthewp 684c959
lean into cloudflare:workers
matthewp 489a6fe
add types
matthewp 8eac286
completely remove the platform proxy stuff
matthewp a1fb870
Merge branch 'feat/environment-api' into tests/env-cloudflare-2
matthewp d6af253
changeset stuff
matthewp 2686535
prime the preloading
matthewp b4bcdb1
fix windows
matthewp 88b0eee
pr comments
matthewp 6774d26
change to cfContext
matthewp aa49219
update the changeset
matthewp d0b4ca3
add export
matthewp 40324f5
fix build
matthewp 1555879
fix linting
matthewp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
packages/integrations/cloudflare/src/entrypoints/middleware.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import { createReadStream, writeFileSync } from 'node:fs'; | |
| import { appendFile, stat } from 'node:fs/promises'; | ||
| import { createRequire } from 'node:module'; | ||
| import { createInterface } from 'node:readline/promises'; | ||
| import { pathToFileURL } from 'node:url'; | ||
| import { pathToFileURL, fileURLToPath } from 'node:url'; | ||
| import { | ||
| appendForwardSlash, | ||
| prependForwardSlash, | ||
|
|
@@ -16,12 +16,9 @@ import type { | |
| HookParameters, | ||
| IntegrationResolvedRoute, | ||
| } from 'astro'; | ||
| import { AstroError } from 'astro/errors'; | ||
| import type { PluginOption } from 'vite'; | ||
| import { defaultClientConditions } from 'vite'; | ||
| import { type GetPlatformProxyOptions, getPlatformProxy } from 'wrangler'; | ||
| import { cloudflareModuleLoader } from './utils/cloudflare-module-loader.js'; | ||
| import { createGetEnv } from './utils/env.js'; | ||
| import { createRoutesFile, getParts } from './utils/generate-routes-json.js'; | ||
| import { type ImageService, setImageConfig } from './utils/image-config.js'; | ||
| import { createConfigPlugin } from './vite-plugin-config.js'; | ||
|
|
@@ -56,13 +53,6 @@ export type Options = { | |
| }[]; | ||
| }; | ||
| }; | ||
| /** | ||
| * Proxy configuration for the platform. | ||
| */ | ||
| platformProxy?: GetPlatformProxyOptions & { | ||
| /** Toggle the proxy. Default `undefined`, which equals to `true`. */ | ||
| enabled?: boolean; | ||
| }; | ||
|
|
||
| /** | ||
| * Allow bundling cloudflare worker specific file types as importable modules. Defaults to true. | ||
|
|
@@ -143,19 +133,6 @@ function wrapWithSlashes(path: string): string { | |
| return prependForwardSlash(appendForwardSlash(path)); | ||
| } | ||
|
|
||
| function setProcessEnv(config: AstroConfig, env: Record<string, unknown>) { | ||
| const getEnv = createGetEnv(env); | ||
|
|
||
| if (config.env?.schema) { | ||
| for (const key of Object.keys(config.env.schema)) { | ||
| const value = getEnv(key); | ||
| if (value !== undefined) { | ||
| process.env[key] = value; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default function createIntegration(args?: Options): AstroIntegration { | ||
| let _config: AstroConfig; | ||
| let finalBuildOutput: HookParameters<'astro:config:done'>['buildOutput']; | ||
|
|
@@ -177,7 +154,6 @@ export default function createIntegration(args?: Options): AstroIntegration { | |
| updateConfig, | ||
| logger, | ||
| addWatchFile, | ||
| addMiddleware, | ||
| createCodegenDir, | ||
| }) => { | ||
| let session = config.session; | ||
|
|
@@ -215,7 +191,7 @@ export default function createIntegration(args?: Options): AstroIntegration { | |
| const codegenDir = createCodegenDir(); | ||
| const cachedFile = new URL('wrangler.json', codegenDir); | ||
| writeFileSync(cachedFile, wranglerTemplate(), 'utf-8'); | ||
| cfPluginConfig.configPath = cachedFile.pathname; | ||
| cfPluginConfig.configPath = fileURLToPath(cachedFile); | ||
| } | ||
|
|
||
| updateConfig({ | ||
|
|
@@ -227,6 +203,13 @@ export default function createIntegration(args?: Options): AstroIntegration { | |
| }, | ||
| session, | ||
| vite: { | ||
| ssr: { | ||
| optimizeDeps: { | ||
| // Disabled to prevent "prebundle" errors on first dev | ||
| // This can be removed when the issue is resolved with Cloudflare | ||
| noDiscovery: true, | ||
| }, | ||
| }, | ||
| plugins: [ | ||
| cfVitePlugin(cfPluginConfig), | ||
| // https://developers.cloudflare.com/pages/functions/module-support/ | ||
|
|
@@ -262,26 +245,23 @@ export default function createIntegration(args?: Options): AstroIntegration { | |
| image: setImageConfig(args?.imageService ?? 'compile', config.image, command, logger), | ||
| }); | ||
|
|
||
| if (args?.platformProxy?.configPath) { | ||
| addWatchFile(new URL(args.platformProxy.configPath, config.root)); | ||
| } else { | ||
| addWatchFile(new URL('./wrangler.toml', config.root)); | ||
| addWatchFile(new URL('./wrangler.json', config.root)); | ||
| addWatchFile(new URL('./wrangler.jsonc', config.root)); | ||
| } | ||
| addWatchFile(new URL('./wrangler.toml', config.root)); | ||
| addWatchFile(new URL('./wrangler.json', config.root)); | ||
| addWatchFile(new URL('./wrangler.jsonc', config.root)); | ||
|
|
||
| addMiddleware({ | ||
| entrypoint: '@astrojs/cloudflare/entrypoints/middleware.js', | ||
| order: 'pre', | ||
| }); | ||
| }, | ||
| 'astro:routes:resolved': ({ routes }) => { | ||
| _routes = routes; | ||
| }, | ||
| 'astro:config:done': ({ setAdapter, config, buildOutput }) => { | ||
| 'astro:config:done': ({ setAdapter, config, buildOutput, injectTypes }) => { | ||
| _config = config; | ||
| finalBuildOutput = buildOutput; | ||
|
|
||
| injectTypes({ | ||
| filename: 'cloudflare.d.ts', | ||
| content: '/// <reference types="@astrojs/cloudflare/types.d.ts" />', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may need to update the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, thanks |
||
| }); | ||
|
|
||
| let customWorkerEntryPoint: URL | undefined; | ||
| if (args?.workerEntryPoint && typeof args.workerEntryPoint.path === 'string') { | ||
| const require = createRequire(config.root); | ||
|
|
@@ -318,40 +298,6 @@ export default function createIntegration(args?: Options): AstroIntegration { | |
| }, | ||
| }); | ||
| }, | ||
| 'astro:server:setup': async ({ server }) => { | ||
| if ((args?.platformProxy?.enabled ?? true) === true) { | ||
| const platformProxy = await getPlatformProxy(args?.platformProxy); | ||
|
|
||
| // Ensures the dev server doesn't hang | ||
| server.httpServer?.on('close', async () => { | ||
| await platformProxy.dispose(); | ||
| }); | ||
|
|
||
| setProcessEnv(_config, platformProxy.env); | ||
|
|
||
| const clientLocalsSymbol = Symbol.for('astro.locals'); | ||
|
|
||
| server.middlewares.use(async function middleware(req, _res, next) { | ||
| Reflect.set(req, clientLocalsSymbol, { | ||
| runtime: { | ||
| env: platformProxy.env, | ||
| cf: platformProxy.cf, | ||
| caches: platformProxy.caches, | ||
| ctx: { | ||
| waitUntil: (promise: Promise<any>) => platformProxy.ctx.waitUntil(promise), | ||
| // Currently not available: https://developers.cloudflare.com/pages/platform/known-issues/#pages-functions | ||
| passThroughOnException: () => { | ||
| throw new AstroError( | ||
| '`passThroughOnException` is currently not available in Cloudflare Pages. See https://developers.cloudflare.com/pages/platform/known-issues/#pages-functions.', | ||
| ); | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| next(); | ||
| }); | ||
| } | ||
| }, | ||
| 'astro:build:setup': ({ vite, target }) => { | ||
| if (target === 'server') { | ||
| vite.resolve ||= {}; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
packages/integrations/cloudflare/test/fixtures/astro-dev-platform/src/pages/index.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,12 @@ | ||
| --- | ||
| const runtime = Astro.locals.runtime; | ||
| const request = Astro.request; | ||
| --- | ||
| <html> | ||
| <head> | ||
| <title>Testing</title> | ||
| </head> | ||
| <body> | ||
| <h1>Testing</h1> | ||
| <div id="hasRuntime">{!!runtime}</div> | ||
| <div id="hasCF">{!!runtime.cf?.colo}</div> | ||
| <div id="hasCF">{!!request.cf?.colo}</div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.