Skip to content

Commit

Permalink
Avoid uploading the 'functions' directory as part of 'wrangler pages …
Browse files Browse the repository at this point in the history
…publish'
  • Loading branch information
GregBrimble committed Oct 31, 2022
1 parent 2a81cae commit ea8d918
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .changeset/cool-nails-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
---

fix: Don't upload `functions/` directory as part of `wrangler pages publish`

If the root directory of a project was the same as the build output directory, we were previously uploading the `functions/` directory as static assets. This PR now ensures that the `functions/` files are only used to create Pages Functions and are no longer uploaded as static assets.

Additionally, we also now _do_ upload `_worker.js`, `_headers`, `_redirects` and `_routes.json` if they aren't immediate children of the build output directory. Previously, we'd ignore all files with this name regardless of location. For example, if you have a `public/blog/how-to-use-pages/_headers` file (where `public` is your build output directory), we will now upload the `_headers` file as a static asset.
41 changes: 41 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"jest-fetch-mock": "^3.0.3",
"jest-websocket-mock": "^2.3.0",
"mime": "^3.0.0",
"minimatch": "^5.1.0",
"msw": "^0.47.1",
"npx-import": "^1.1.3",
"open": "^8.4.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/wrangler/src/is-interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* or you're piping values from / to another process, etc
*/
export default function isInteractive(): boolean {
if (process.env.CF_PAGES === "1") {
return false;
}

try {
return Boolean(process.stdin.isTTY && process.stdout.isTTY);
} catch {
Expand Down
22 changes: 14 additions & 8 deletions packages/wrangler/src/pages/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { dirname, join, relative, resolve, sep } from "node:path";
import { render, Text } from "ink";
import Spinner from "ink-spinner";
import { getType } from "mime";
import { Minimatch } from "minimatch";
import PQueue from "p-queue";
import prettyBytes from "pretty-bytes";
import React from "react";
Expand All @@ -20,6 +21,7 @@ import { hashFile } from "./hash";
import { pagesBetaWarning } from "./utils";
import type { UploadPayloadFile, YargsOptionsToInterface } from "./types";
import type { Argv } from "yargs";
import isInteractive from "../is-interactive";

type UploadArgs = YargsOptionsToInterface<typeof Options>;

Expand Down Expand Up @@ -96,10 +98,11 @@ export const upload = async (
"_redirects",
"_headers",
"_routes.json",
".DS_Store",
"node_modules",
".git",
];
"functions",
"**/.DS_Store",
"**/node_modules",
"**/.git",
].map((pattern) => new Minimatch(pattern));

const directory = resolve(args.directory);

Expand All @@ -121,10 +124,13 @@ export const upload = async (
await Promise.all(
files.map(async (file) => {
const filepath = join(dir, file);
const relativeFilepath = relative(startingDir, filepath);
const filestat = await stat(filepath);

if (IGNORE_LIST.includes(file)) {
return;
for (const mm of IGNORE_LIST) {
if (mm.match(relativeFilepath)) {
return;
}
}

if (filestat.isSymbolicLink()) {
Expand All @@ -134,7 +140,7 @@ export const upload = async (
if (filestat.isDirectory()) {
fileMap = await walk(filepath, fileMap, startingDir);
} else {
const name = relative(startingDir, filepath).split(sep).join("/");
const name = relativeFilepath.split(sep).join("/");

if (filestat.size > 25 * 1024 * 1024) {
throw new FatalError(
Expand Down Expand Up @@ -390,7 +396,7 @@ function Progress({ done, total }: { done: number; total: number }) {
return (
<>
<Text>
<Spinner type="earth" />
{isInteractive() ? <Spinner type="earth" /> : null}
{` Uploading... (${done}/${total})\n`}
</Text>
</>
Expand Down

0 comments on commit ea8d918

Please sign in to comment.