Skip to content

Commit 331c659

Browse files
wrangler pages publish (#790)
* wip * wip * wip * Ignore _worker.js, _redirects, _headers, .DS_Store * Update package-lock.json * Add more TODO comments for future me * Ignore node_modules * Ignore symlinks * Git stuff * Alias 'wrangler pages publish' with 'wrangler pages deployment create' * Attach meta files * Test 'pages deployment create' * Add changeset for 'wrangler pages publish' Co-authored-by: Greg Brimble <[email protected]>
1 parent 0c582be commit 331c659

File tree

6 files changed

+553
-8
lines changed

6 files changed

+553
-8
lines changed

.changeset/hungry-pandas-report.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
feature: Adds 'wrangler pages publish' (alias 'wrangler pages deployment create') command.

package-lock.json

+77
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/wrangler/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"cli"
3737
],
3838
"dependencies": {
39+
"blake3-wasm": "^2.1.5",
3940
"esbuild": "0.14.34",
4041
"miniflare": "2.4.0",
4142
"path-to-regexp": "^6.2.0",
@@ -75,13 +76,15 @@
7576
"ignore": "^5.2.0",
7677
"ink": "^3.2.0",
7778
"ink-select-input": "^4.2.1",
79+
"ink-spinner": "^4.0.3",
7880
"ink-table": "^3.0.0",
7981
"ink-testing-library": "^2.1.0",
8082
"ink-text-input": "^4.0.3",
8183
"jest-fetch-mock": "^3.0.3",
8284
"jest-websocket-mock": "^2.3.0",
8385
"mime": "^3.0.0",
8486
"open": "^8.4.0",
87+
"pretty-bytes": "^6.0.0",
8588
"prompts": "^2.4.2",
8689
"react": "^17.0.2",
8790
"react-error-boundary": "^3.1.4",
@@ -124,7 +127,7 @@
124127
"testTimeout": 30000,
125128
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
126129
"transformIgnorePatterns": [
127-
"node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color)"
130+
"node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color|pretty-bytes)"
128131
],
129132
"moduleNameMapper": {
130133
"clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",

packages/wrangler/scripts/bundle.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ async function run() {
1515
external: [
1616
"fsevents",
1717
"esbuild",
18+
"blake3-wasm",
1819
"miniflare",
1920
"@miniflare/core",
2021
"selfsigned",

packages/wrangler/src/__tests__/pages.test.ts

+101-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import { writeFileSync } from "node:fs";
12
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
23
import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
34
import { mockConsoleMethods } from "./helpers/mock-console";
45
import { runInTempDir } from "./helpers/run-in-tmp";
56
import { runWrangler } from "./helpers/run-wrangler";
67
import type { Project, Deployment } from "../pages";
8+
import type { File, FormData } from "undici";
79

8-
describe("subcommand implicit help ran on incomplete command execution", () => {
10+
describe("pages", () => {
911
runInTempDir();
1012
const std = mockConsoleMethods();
1113
function endEventLoop() {
@@ -25,6 +27,7 @@ describe("subcommand implicit help ran on incomplete command execution", () => {
2527
wrangler pages dev [directory] [-- command] 🧑‍💻 Develop your full-stack Pages application locally
2628
wrangler pages project ⚡️ Interact with your Pages projects
2729
wrangler pages deployment 🚀 Interact with the deployments of a project
30+
wrangler pages publish [directory] 🆙 Publish a directory of static assets as a Pages deployment
2831
2932
Flags:
3033
-c, --config Path to .toml configuration file [string]
@@ -49,8 +52,6 @@ describe("subcommand implicit help ran on incomplete command execution", () => {
4952
);
5053
});
5154

52-
// Note that `wrangler pages functions` does nothing...
53-
5455
it("should display for pages:functions:build", async () => {
5556
await expect(runWrangler("pages functions build")).rejects.toThrowError();
5657

@@ -67,6 +68,7 @@ describe("subcommand implicit help ran on incomplete command execution", () => {
6768
afterEach(() => {
6869
unsetAllMocks();
6970
});
71+
7072
function mockListRequest(projects: unknown[]) {
7173
const requests = { count: 0 };
7274
setMockResponse(
@@ -249,4 +251,100 @@ describe("subcommand implicit help ran on incomplete command execution", () => {
249251
expect(requests.count).toBe(1);
250252
});
251253
});
254+
255+
describe("deployment create", () => {
256+
let actualProcessEnvCI: string | undefined;
257+
258+
mockAccountId();
259+
mockApiToken();
260+
runInTempDir();
261+
262+
beforeEach(() => {
263+
actualProcessEnvCI = process.env.CI;
264+
process.env.CI = "true";
265+
});
266+
267+
afterEach(() => {
268+
unsetAllMocks();
269+
process.env.CI = actualProcessEnvCI;
270+
});
271+
272+
it("should be aliased with 'wrangler pages publish'", async () => {
273+
await runWrangler("pages publish --help");
274+
await endEventLoop();
275+
276+
expect(std.out).toMatchInlineSnapshot(`
277+
"wrangler pages publish [directory]
278+
279+
🆙 Publish a directory of static assets as a Pages deployment
280+
281+
Positionals:
282+
directory The directory of Pages Functions [string] [default: \\"functions\\"]
283+
284+
Flags:
285+
-c, --config Path to .toml configuration file [string]
286+
-h, --help Show help [boolean]
287+
-v, --version Show version number [boolean]
288+
--legacy-env Use legacy environments [boolean]
289+
290+
Options:
291+
--project The name of the project you want to list deployments for [string]
292+
--branch The branch of the project you want to list deployments for [string]
293+
--commit-hash The branch of the project you want to list deployments for [string]
294+
--commit-message The branch of the project you want to list deployments for [string]
295+
--commit-dirty The branch of the project you want to list deployments for [boolean]
296+
297+
🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
298+
`);
299+
});
300+
301+
it("should upload a directory of files", async () => {
302+
writeFileSync("logo.png", "foobar");
303+
304+
setMockResponse(
305+
"/accounts/:accountId/pages/projects/foo/file",
306+
async ([_url, accountId], init) => {
307+
expect(accountId).toEqual("some-account-id");
308+
expect(init.method).toEqual("POST");
309+
const body = init.body as FormData;
310+
const logoPNGFile = body.get("file") as File;
311+
expect(await logoPNGFile.text()).toEqual("foobar");
312+
expect(logoPNGFile.name).toEqual("logo.png");
313+
314+
return {
315+
id: "2082190357cfd3617ccfe04f340c6247d4b47484797840635feb491447bcd81c",
316+
};
317+
}
318+
);
319+
320+
setMockResponse(
321+
"/accounts/:accountId/pages/projects/foo/deployment",
322+
async ([_url, accountId], init) => {
323+
expect(accountId).toEqual("some-account-id");
324+
expect(init.method).toEqual("POST");
325+
const body = init.body as FormData;
326+
const manifest = JSON.parse(body.get("manifest") as string);
327+
expect(manifest).toMatchInlineSnapshot(`
328+
Object {
329+
"logo.png": "2082190357cfd3617ccfe04f340c6247d4b47484797840635feb491447bcd81c",
330+
}
331+
`);
332+
333+
return {
334+
url: "https://abcxyz.foo.pages.dev/",
335+
};
336+
}
337+
);
338+
339+
await runWrangler("pages publish . --project=foo");
340+
341+
// TODO: Unmounting somehow loses this output
342+
343+
// expect(std.out).toMatchInlineSnapshot(`
344+
// "✨ Success! Uploaded 1 files (TIMINGS)
345+
346+
// ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
347+
// `);
348+
});
349+
});
252350
});

0 commit comments

Comments
 (0)