Repository navigation
Scope Cloudflare adapter process banner to SSR and prerender environments only #18213
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@astrojs/cloudflare': patch | ||
| --- | ||
|
|
||
| Fixes the `globalThis.process` shim being prepended to client-side scripts. The shim is now only added to the server output. |
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
15 changes: 13 additions & 2 deletions
15
packages/integrations/cloudflare/test/server-entry.test.ts
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,21 +1,32 @@ | ||
| import { describe, it } from 'node:test'; | ||
| import { before, describe, it } from 'node:test'; | ||
| import { type Fixture, loadFixture } from './test-utils.ts'; | ||
| import assert from 'node:assert/strict'; | ||
| import { existsSync } from 'node:fs'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| describe('Server entry', () => { | ||
| let fixture: Fixture; | ||
| it('should load the custom entry when using legacy entrypoint', async () => { | ||
|
|
||
| before(async () => { | ||
| fixture = await loadFixture({ | ||
| root: './fixtures/server-entry', | ||
| output: 'server', | ||
| }); | ||
|
|
||
| await fixture.build(); | ||
| }); | ||
|
|
||
| it('should load the custom entry when using legacy entrypoint', async () => { | ||
| const itExits = existsSync(fileURLToPath(new URL('server/custom.mjs', fixture.config.outDir))); | ||
|
|
||
| assert.ok(itExits); | ||
| }); | ||
|
|
||
| it('prepends the process shim banner to the server entry', async () => { | ||
| const entry = await fixture.readFile('/server/custom.mjs'); | ||
| assert.ok( | ||
| entry.startsWith('globalThis.process ??= {};'), | ||
| 'Expected the process shim at the top of the server entry', | ||
| ); | ||
| }); | ||
| }); |
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,20 +1,33 @@ | ||
| import { describe, it } from 'node:test'; | ||
| import { before, describe, it } from 'node:test'; | ||
| import { type Fixture, loadFixture } from './test-utils.ts'; | ||
| import assert from 'node:assert/strict'; | ||
| import { existsSync } from 'node:fs'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| describe('Static output', () => { | ||
| let fixture: Fixture; | ||
| it('should not output a _worker.js directory for fully static sites', async () => { | ||
|
|
||
| before(async () => { | ||
| fixture = await loadFixture({ | ||
| root: './fixtures/static', | ||
| }); | ||
|
|
||
| await fixture.build(); | ||
| }); | ||
|
|
||
| it('should not output a _worker.js directory for fully static sites', async () => { | ||
| const workerExists = existsSync(fileURLToPath(new URL('_worker.js', fixture.config.outDir))); | ||
|
|
||
| assert.ok(!workerExists, '_worker.js directory should not exist for static sites'); | ||
| }); | ||
|
|
||
| it('does not prepend the process shim banner to client scripts', async () => { | ||
| const html = await fixture.readFile('/client/index.html'); | ||
| assert.ok(html.includes('data-ready'), 'Expected the client script to be in the output'); | ||
| assert.ok(!html.includes('globalThis.process')); | ||
| for (const file of await fixture.glob('client/_astro/*.js')) { | ||
| const js = await fixture.readFile('/' + file); | ||
| assert.ok(!js.includes('globalThis.process'), `${file} should not contain the process shim`); | ||
| } | ||
| }); | ||
| }); | ||
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.