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
feat(api): Adds unstable_pages module to JS API #2526
Conversation
🦋 Changeset detectedLatest commit: b0a9a06 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/runs/3960423685/npm-package-wrangler-2526 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/prs/2526/npm-package-wrangler-2526 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/runs/3960423685/npm-package-wrangler-2526 dev path/to/script.js Additional artifacts:npm install https://prerelease-registry.devprod.cloudflare.dev/runs/3960423685/npm-package-cloudflare-pages-shared-2526 |
Codecov Report
@@ Coverage Diff @@
## main #2526 +/- ##
==========================================
+ Coverage 73.05% 73.12% +0.07%
==========================================
Files 156 159 +3
Lines 9770 9785 +15
Branches 2575 2576 +1
==========================================
+ Hits 7137 7155 +18
+ Misses 2633 2630 -3
|
78216fb
to
1252d3b
Compare
I will pull this down and test it tomorrow, unless someone else gets to it first. At a quick glance it seems like just turning the current code programmatic and moving it under the |
16ebff7
to
4d4f73b
Compare
*/ | ||
let builtFunctions: string | undefined = undefined; | ||
const functionsDirectory = | ||
customFunctionsDirectory || join(cwd(), "functions"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added this new customFunctionsDirectory
property that allows consumers to pass in a path to the functions directory, instead of relying on current working directory (like the CLI does)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have thoughts and feelings on this for when we think about stabilising this API, but totally fine right now since it's unstable.
4d4f73b
to
795bc16
Compare
*/ | ||
functionsDirectory?: string; | ||
|
||
// TODO: Allow passing in the API key and plumb it through |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is unstable, I'm happy for this to just be done in a follow-up if you can work around it in your client right now. If you want to do it, go ahead, but it's not blocking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. But would be good to get someone from Wrangler proper to sign off on us adding this API before merging.
837333d
to
403951b
Compare
403951b
to
6c9cfdc
Compare
6c9cfdc
to
b0a9a06
Compare
value: "ZnVuYw==", | ||
expect(Object.keys(requestMap).length).toBe(3); | ||
|
||
expect(requestMap["95dedb64e6d4940fc2e0f11f711cc2f4"]).toMatchObject({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GregBrimble I found it more reliable to not sort the requests and lookup by index. But rather key the requests by the key
property and lookup by said key
property
@@ -1,2 +1,3 @@ | |||
export { unstable_dev } from "./dev"; | |||
export type { UnstableDevWorker, UnstableDevOptions } from "./dev"; | |||
export { unstable_pages } from "./pages"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to export the types for unstable_pages
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't mind, I'd like to hold off on that rabbit hole. There's a lot of types involved and I'd like to move more code around to export all of the relevant bits. If a consumer needs the type of the argument to publish
or the return type, then they can easily infer it:
type PublishOptions = typeof unstable_pages.publish extends (options: infer P) => any ? P : never
type PublishResult = typeof unstable_pages.publish extends (options: any) => infer P ? P : never
I - being the only consumer of this code so far - don't actually need that yet :)
What this PR solves / how to test:
This PR refactors the existing Pages publish code into its own exportable function and exports it in the wrangler API under the
unstable_pages
object. This will allow folks to run thepublish
function in a scriptable JS environment and will get the entire deployment response as a variable.Associated docs issues/PR:
Author has included the following, where applicable:
TestsReviewer has performed the following, where applicable: