Skip to content
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

Merged
merged 4 commits into from Jan 20, 2023
Merged

Conversation

jrf0110
Copy link
Member

@jrf0110 jrf0110 commented Jan 10, 2023

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 the publish 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:

  • Tests
  • Changeset

Reviewer has performed the following, where applicable:

  • Checked for inclusion of relevant tests
  • Checked for inclusion of a relevant changeset
  • Checked for creation of associated docs updates
  • Manually pulled down the changes and spot-tested

@jrf0110 jrf0110 requested review from a team as code owners January 10, 2023 21:50
@changeset-bot
Copy link

changeset-bot bot commented Jan 10, 2023

🦋 Changeset detected

Latest commit: b0a9a06

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

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

@github-actions
Copy link
Contributor

github-actions bot commented Jan 10, 2023

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 with this latest build directly:

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
Copy link

codecov bot commented Jan 10, 2023

Codecov Report

Merging #2526 (b0a9a06) into main (5c1c93b) will increase coverage by 0.07%.
The diff coverage is 86.66%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
packages/wrangler/src/api/pages/publish.tsx 82.69% <82.69%> (ø)
packages/wrangler/src/pages/buildFunctions.ts 94.44% <94.44%> (ø)
packages/wrangler/src/api/index.ts 100.00% <100.00%> (ø)
packages/wrangler/src/api/pages/index.ts 100.00% <100.00%> (ø)
packages/wrangler/src/pages/build.ts 76.66% <100.00%> (-8.82%) ⬇️
packages/wrangler/src/pages/dev.ts 18.94% <100.00%> (ø)
packages/wrangler/src/pages/publish.tsx 47.61% <100.00%> (-17.94%) ⬇️
packages/wrangler/src/git-client.ts 81.25% <0.00%> (+4.16%) ⬆️
...ackages/wrangler/src/__tests__/helpers/mock-bin.ts 100.00% <0.00%> (+5.26%) ⬆️

@JacobMGEvans
Copy link
Contributor

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 /api which as long as the tests are passing should be a confident refactor.

@jrf0110 jrf0110 force-pushed the unstable-pages-api branch 3 times, most recently from 16ebff7 to 4d4f73b Compare January 10, 2023 23:43
*/
let builtFunctions: string | undefined = undefined;
const functionsDirectory =
customFunctionsDirectory || join(cwd(), "functions");
Copy link
Member Author

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)

Copy link
Member

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.

*/
functionsDirectory?: string;

// TODO: Allow passing in the API key and plumb it through
Copy link
Member

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.

Copy link
Member

@GregBrimble GregBrimble left a 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.

@jrf0110 jrf0110 force-pushed the unstable-pages-api branch 3 times, most recently from 837333d to 403951b Compare January 18, 2023 18:55
value: "ZnVuYw==",
expect(Object.keys(requestMap).length).toBe(3);

expect(requestMap["95dedb64e6d4940fc2e0f11f711cc2f4"]).toMatchObject({
Copy link
Member Author

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";
Copy link
Contributor

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?

Copy link
Member Author

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 :)

@jrf0110 jrf0110 merged commit 69d379a into main Jan 20, 2023
@jrf0110 jrf0110 deleted the unstable-pages-api branch January 20, 2023 22:54
@github-actions github-actions bot mentioned this pull request Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants