-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix requiring unenv aliased packages (#8021)
- Loading branch information
1 parent
ca3cbc4
commit 28b1dc7
Showing
10 changed files
with
126 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
fix: prevent \_\_cf_cjs name collision in the hybrid Nodejs compat plugin |
10 changes: 10 additions & 0 deletions
10
fixtures/pages-functions-unenv-alias/functions/[[path]].ts
This file contains 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,10 @@ | ||
const fetch = require("cross-fetch"); | ||
|
||
export const onRequest = () => { | ||
const supportsDefaultExports = typeof fetch === "function"; | ||
const supportsNamedExports = typeof fetch.Headers === "function"; | ||
|
||
return new Response( | ||
supportsDefaultExports && supportsNamedExports ? "OK!" : "KO!" | ||
); | ||
}; |
This file contains 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,25 @@ | ||
{ | ||
"name": "pages-functions-unenv-alias", | ||
"private": true, | ||
"sideEffects": false, | ||
"scripts": { | ||
"check:type": "tsc", | ||
"dev:functions-app": "wrangler pages dev --port 8792", | ||
"test:ci": "vitest run", | ||
"test:watch": "vitest", | ||
"type:tests": "tsc -p ./tests/tsconfig.json" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-tsconfig": "workspace:^", | ||
"typescript": "catalog:default", | ||
"undici": "catalog:default", | ||
"vitest": "catalog:default", | ||
"wrangler": "workspace:*" | ||
}, | ||
"engines": { | ||
"node": ">=16.13" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
} | ||
} |
This file contains 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,21 @@ | ||
import { resolve } from "node:path"; | ||
import { fetch } from "undici"; | ||
import { describe, it } from "vitest"; | ||
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived"; | ||
|
||
describe("Pages functions with unenv aliased packages", () => { | ||
it("should run dev server when requiring an unenv aliased package", async ({ | ||
expect, | ||
onTestFinished, | ||
}) => { | ||
const { ip, port, stop } = await runWranglerPagesDev( | ||
resolve(__dirname, ".."), | ||
"./functions", | ||
["--port=0", "--inspector-port=0"] | ||
); | ||
onTestFinished(stop); | ||
const response = await fetch(`http://${ip}:${port}/`); | ||
const body = await response.text(); | ||
expect(body).toEqual(`OK!`); | ||
}); | ||
}); |
This file contains 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,7 @@ | ||
{ | ||
"extends": "@cloudflare/workers-tsconfig/tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["node"] | ||
}, | ||
"include": ["**/*.ts", "../../../node-types.d.ts"] | ||
} |
This file contains 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,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"esModuleInterop": true, | ||
"module": "CommonJS", | ||
"lib": ["ES2020"], | ||
"types": ["node", "@cloudflare/workers-types"], | ||
"moduleResolution": "node", | ||
"noEmit": true, | ||
"skipLibCheck": true, | ||
"checkJs": true | ||
}, | ||
"include": [ | ||
"apps/workerjs-directory/_worker.js/index.js", | ||
"apps/workerjs-file/_worker.js", | ||
"functions/[[path]].ts", | ||
"tests", | ||
"../../node-types.d.ts" | ||
] | ||
} |
This file contains 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,9 @@ | ||
import { defineProject, mergeConfig } from "vitest/config"; | ||
import configShared from "../../vitest.shared"; | ||
|
||
export default mergeConfig( | ||
configShared, | ||
defineProject({ | ||
test: {}, | ||
}) | ||
); |
This file contains 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,3 @@ | ||
name = "pages-functions-unenv-alias" | ||
compatibility_date = "2024-12-30" | ||
compatibility_flags = ["nodejs_compat"] |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.