Skip to content

Commit

Permalink
Merge branch 'main' into penalosa/no-bundle-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa committed Mar 27, 2023
2 parents 203e212 + 191b23f commit 88e98c4
Show file tree
Hide file tree
Showing 151 changed files with 4,897 additions and 2,614 deletions.
7 changes: 7 additions & 0 deletions .changeset/cool-cobras-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

Fix: Pages Dev incorrectly allowing people to turn off local mode

Local mode is not currently supported in Pages Dev, and errors when people attempt to use it. Previously, wrangler hid the "toggle local mode" button when using Pages dev, but this got broken somewhere along the line.
11 changes: 0 additions & 11 deletions .changeset/grumpy-pillows-cheat.md

This file was deleted.

6 changes: 6 additions & 0 deletions .changeset/lovely-ways-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@cloudflare/pages-shared": minor
"wrangler": minor
---

chore: upgrade `miniflare` to [`2.13.0`](https://github.com/cloudflare/miniflare/releases/tag/v2.13.0)
7 changes: 0 additions & 7 deletions .changeset/rare-houses-rest.md

This file was deleted.

15 changes: 15 additions & 0 deletions .changeset/tame-bats-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"wrangler": minor
---

feat: add support for send email bindings

Support send email bindings in order to send emails from a worker. There
are three types of bindings:

- Unrestricted: can send email to any verified destination address.
- Restricted: can only send email to the supplied destination address (which
does not need to be specified when sending the email but also needs to be a
verified destination address).
- Allowlist: can only send email to the supplied list of verified destination
addresses.
14 changes: 7 additions & 7 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
What this PR solves / how to test:
Fixes # [insert GH or internal issue number(s)].

Associated docs issues/PR:
**What this PR solves / how to test:**

**Associated docs issue(s)/PR(s):**

- [insert associated docs issue(s)/PR(s)]

Author has included the following, where applicable:
**Author has included the following, where applicable:**

- [ ] Tests
- [ ] Changeset
- [ ] Changeset ([Changeset guidelines](https://github.com/cloudflare/workers-sdk/blob/main/CONTRIBUTING.md#changesets))

Reviewer has performed the following, where applicable:
**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

Fixes # [insert issue number].
55 changes: 55 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Main branch

# This flow will re-run tests on the main branch after a PR has been merged.

on:
push:
branches:
- main

jobs:
test:
if: ${{ github.repository_owner == 'cloudflare' }}
name: "Tests"
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use Node.js 16.13
uses: actions/setup-node@v3
with:
node-version: 16.13
cache: "npm" # cache ~/.npm in case 'npm ci' needs to run

- name: Install workerd Dependencies
if: ${{ runner.os == 'Linux' }}
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install -y libc++1
- name: Install NPM Dependencies
run: npm ci

- name: Run builds
run: npm run build
env:
NODE_ENV: "production"

- name: Check for errors
run: npm run check
env:
NODE_OPTIONS: "--max_old_space_size=8192"

- name: Run tests
run: npm run test:ci
env:
TMP_CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
TMP_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
NODE_OPTIONS: "--max_old_space_size=8192"
41 changes: 34 additions & 7 deletions .github/workflows/pullrequests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Pull Request

on: pull_request

env:
node-version: 16.13
jobs:
check:
name: "Checks"
Expand All @@ -12,13 +14,14 @@ jobs:
with:
fetch-depth: 0

- name: Use Node.js 16.13
- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v3
with:
node-version: 16.13
node-version: ${{ env.node-version }}
cache: "npm" # cache ~/.npm in case 'npm ci' needs to run

- uses: actions/cache@v3
- name: ESlint and Typescript caching
uses: actions/cache@v3
id: eslint-cache
with:
path: |
Expand All @@ -33,7 +36,19 @@ jobs:
sudo apt-get update
sudo apt-get install -y libc++1
- name: Install NPM Dependencies
# Attempt to cache all the node_modules directories based on the OS and package lock.
- name: Cache node_modules
id: npm-cache
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
key: ${{ runner.os }}-${{ env.node-version }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
path: "**/node_modules"

# If the cache missed then install using `npm ci` to follow package lock exactly
- if: ${{ steps.npm-cache.outputs.cache-hit != 'true'}}
name: Install NPM Dependencies
run: npm ci

- name: Build
Expand All @@ -56,10 +71,10 @@ jobs:
with:
fetch-depth: 0

- name: Use Node.js 16.13
- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v3
with:
node-version: 16.13
node-version: ${{ env.node-version }}
cache: "npm" # cache ~/.npm in case 'npm ci' needs to run

- name: Install workerd Dependencies
Expand All @@ -69,7 +84,19 @@ jobs:
sudo apt-get update
sudo apt-get install -y libc++1
- name: Install NPM Dependencies
# Attempt to cache all the node_modules directories based on the OS and package lock.
- name: Cache node_modules
id: npm-cache
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
key: ${{ runner.os }}-${{ env.node-version }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
path: "**/node_modules"

# If the cache missed then install using `npm ci` to follow package lock exactly
- if: ${{ steps.npm-cache.outputs.cache-hit != 'true'}}
name: Install NPM Dependencies
run: npm ci

- name: Run builds
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ dist
wrangler-dist/
miniflare-dist
packages/wrangler/wrangler.toml
packages/prerelease-registry/_worker.js
packages/prerelease-registry/_worker.bundle
packages/wranglerjs-compat-webpack-plugin/lib
.wrangler-1-cache
emitted-types/
Expand Down
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ packages/wrangler/emitted-types/
packages/wrangler/coverage/
packages/wrangler/CHANGELOG.md
packages/jest-environment-wrangler/CHANGELOG.md
packages/prerelease-registry/_worker.js
packages/prerelease-registry/dist/
packages/jest-environment-wrangler/dist/
packages/wranglerjs-compat-webpack-plugin/lib
packages/wrangler-devtools/built-devtools
fixtures/pages-plugin-example/index.js
fixtures/pages-plugin-example/dist/
fixtures/remix-pages-app/build/
fixtures/remix-pages-app/public/build/
fixtures/worker-app/dist/
Expand Down
1 change: 1 addition & 0 deletions fixtures/local-mode-tests/tests/headers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "path";
import { describe, it, beforeAll, afterAll, expect } from "vitest";
import { unstable_dev } from "wrangler";
import type { UnstableDevWorker } from "wrangler";

Expand Down
1 change: 1 addition & 0 deletions fixtures/local-mode-tests/tests/module.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "path";
import { describe, it, beforeAll, afterAll, expect } from "vitest";
import { unstable_dev } from "wrangler";
import type { UnstableDevWorker } from "wrangler";

Expand Down
1 change: 1 addition & 0 deletions fixtures/local-mode-tests/tests/nodeBuiltinPackage.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "path";
import { describe, it, beforeAll, afterAll, expect } from "vitest";
import { unstable_dev } from "wrangler";
import type { UnstableDevWorker } from "wrangler";

Expand Down
1 change: 1 addition & 0 deletions fixtures/local-mode-tests/tests/ports.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "path";
import { describe, it, beforeAll, afterAll, expect } from "vitest";
import { unstable_dev } from "wrangler";
import type { UnstableDevWorker } from "wrangler";

Expand Down
1 change: 1 addition & 0 deletions fixtures/local-mode-tests/tests/sw.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "path";
import { describe, it, beforeAll, afterAll, expect } from "vitest";
import { unstable_dev } from "wrangler";
import type { UnstableDevWorker } from "wrangler";

Expand Down
2 changes: 1 addition & 1 deletion fixtures/local-mode-tests/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"]
"types": ["node"]
},
"include": ["**/*.ts"],
"exclude": []
Expand Down
3 changes: 2 additions & 1 deletion fixtures/local-mode-tests/tests/unstableDev.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from "path";
import { describe, it, beforeAll, afterAll, expect } from "vitest";
import { unstable_dev } from "wrangler";
import type { UnstableDevWorker } from "wrangler";
jest.setTimeout(30_000);

// TODO: add test for `experimentalLocal: true` once issue with dynamic
// `import()` and `npx-import` resolved:
// https://github.com/cloudflare/workers-sdk/pull/1940#issuecomment-1261166695
Expand Down
4 changes: 2 additions & 2 deletions fixtures/pages-functions-wasm-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"sideEffects": false,
"scripts": {
"check:type": "tsc",
"dev": "npx wrangler pages dev public --experimental-worker-bundle=true --port 8776",
"publish": "npx wrangler pages publish public --experimental-worker-bundle=true",
"dev": "npx wrangler pages dev public --port 8776",
"publish": "npx wrangler pages publish public",
"test": "npx vitest",
"test:ci": "npx vitest"
},
Expand Down
6 changes: 3 additions & 3 deletions fixtures/pages-functions-wasm-app/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe.concurrent("Pages Functions with wasm module imports", () => {
({ ip, port, stop } = await runWranglerPagesDev(
resolve(__dirname, ".."),
"public",
["--port=0", "--experimental-worker-bundle=true"]
["--port=0"]
));
});

Expand All @@ -25,8 +25,8 @@ describe.concurrent("Pages Functions with wasm module imports", () => {
it("should resolve any wasm module imports and render /meaning-of-life", async ({
expect,
}) => {
let response = await fetch(`http://${ip}:${port}/meaning-of-life`);
let text = await response.text();
const response = await fetch(`http://${ip}:${port}/meaning-of-life`);
const text = await response.text();
expect(text).toEqual("Hello WASM World! The meaning of life is 21");
});
});
19 changes: 13 additions & 6 deletions fixtures/pages-plugin-example/functions/_middleware.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import type { PluginArgs } from "..";

type ExamplePagesPluginFunction<
Env = unknown,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Params extends string = any,
Data extends Record<string, unknown> = Record<string, unknown>
> = PagesPluginFunction<Env, Params, Data, PluginArgs>;

class BodyHandler {
footerText: string;

Expand All @@ -11,12 +20,10 @@ class BodyHandler {
}
}

export const onRequest: PagesPluginFunction<
unknown,
never,
Record<string, unknown>,
{ footerText: string }
> = async ({ next, pluginArgs }) => {
export const onRequest: ExamplePagesPluginFunction = async ({
next,
pluginArgs,
}) => {
const response = await next();

return new HTMLRewriter()
Expand Down
5 changes: 5 additions & 0 deletions fixtures/pages-plugin-example/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type PluginArgs = {
footerText: string;
};

export default function (args: PluginArgs): PagesFunction;
6 changes: 3 additions & 3 deletions fixtures/pages-plugin-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"name": "pages-plugin-example",
"version": "0.0.0",
"private": true,
"main": "index.js",
"main": "dist/index.js",
"types": "index.d.ts",
"files": [
"index.js",
"dist/",
"index.d.ts",
"tsconfig.json",
"public/"
],
"scripts": {
"build": "npx wrangler pages functions build --plugin --outfile=index.js",
"build": "npx wrangler pages functions build --plugin --outdir=dist",
"check:type": "tsc"
}
}
2 changes: 1 addition & 1 deletion fixtures/pages-plugin-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["functions"],
"include": ["functions", "index.d.ts"],
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
Expand Down
Loading

0 comments on commit 88e98c4

Please sign in to comment.