-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a00910
commit c3f36b0
Showing
21 changed files
with
372 additions
and
38 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 | ||
--- | ||
|
||
chore: rename `--script-path` to `--outfile` for `wrangler pages functions build` command. |
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 | ||
--- | ||
|
||
feature: Adds a `--plugin` option to `wrangler pages functions build` which compiles a Pages Plugin. More information about Pages Plugins can be found [here](https://developers.cloudflare.com/pages/platform/functions/plugins/). This wrangler build is required for both the development of, and inclusion of, plugins. |
Validating CODEOWNERS rules …
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# Global owners | ||
* @threepointone @petebacondarwin | ||
/packages/wrangler/pages/ @GregBrimble |
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
examples/pages-functions-app/functions/mounted-plugin/_middleware.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,3 @@ | ||
import examplePlugin from "../../../pages-plugin-example"; | ||
|
||
export const onRequest = examplePlugin({ footerText: "Set from a Plugin!" }); |
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
<h1>Hello, world!</h1> | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<h1>Hello, world!</h1> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
<h1>An asset</h1> | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<h1>An asset</h1> | ||
</body> | ||
</html> |
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
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 @@ | ||
/index.js |
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 @@ | ||
class BodyHandler { | ||
footerText: string; | ||
|
||
constructor({ footerText }) { | ||
this.footerText = footerText; | ||
} | ||
|
||
element(element) { | ||
// Don't actually set HTML like this! | ||
element.append(`<footer>${this.footerText}</footer>`, { html: true }); | ||
} | ||
} | ||
|
||
export const onRequest = async ({ next, pluginArgs }) => { | ||
const response = await next(); | ||
|
||
return new HTMLRewriter() | ||
.on("body", new BodyHandler({ footerText: pluginArgs.footerText })) | ||
.transform(response); | ||
}; |
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 @@ | ||
export const onRequest = () => { | ||
return new Response("I'm a fixed response"); | ||
}; |
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,13 @@ | ||
{ | ||
"name": "pages-plugin-example", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"tsconfig.json" | ||
], | ||
"scripts": { | ||
"build": "npx wrangler pages functions build --plugin --outfile=index.js" | ||
} | ||
} |
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
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,55 @@ | ||
import { resolve } from "node:path"; | ||
import { build } from "esbuild"; | ||
|
||
type Options = { | ||
routesModule: string; | ||
outfile: string; | ||
minify?: boolean; | ||
sourcemap?: boolean; | ||
watch?: boolean; | ||
onEnd?: () => void; | ||
}; | ||
|
||
export function buildPlugin({ | ||
routesModule, | ||
outfile = "bundle.js", | ||
minify = false, | ||
sourcemap = false, | ||
watch = false, | ||
onEnd = () => {}, | ||
}: Options) { | ||
return build({ | ||
entryPoints: [resolve(__dirname, "../pages/functions/template-plugin.ts")], | ||
inject: [routesModule], | ||
bundle: true, | ||
format: "esm", | ||
target: "esnext", | ||
outfile, | ||
minify, | ||
sourcemap, | ||
watch, | ||
allowOverwrite: true, | ||
plugins: [ | ||
{ | ||
name: "wrangler notifier and monitor", | ||
setup(pluginBuild) { | ||
pluginBuild.onEnd((result) => { | ||
if (result.errors.length > 0) { | ||
console.error( | ||
`${result.errors.length} error(s) and ${result.warnings.length} warning(s) when compiling Worker.` | ||
); | ||
} else if (result.warnings.length > 0) { | ||
console.warn( | ||
`${result.warnings.length} warning(s) when compiling Worker.` | ||
); | ||
onEnd(); | ||
} else { | ||
console.log("Compiled Worker successfully."); | ||
onEnd(); | ||
} | ||
}); | ||
}, | ||
}, | ||
], | ||
}); | ||
} |
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
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
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
Oops, something went wrong.