Skip to content

Commit

Permalink
Merge branch 'cloudflare:main' into new-template-repo
Browse files Browse the repository at this point in the history
  • Loading branch information
dotysan authored May 12, 2023
2 parents 3cc591f + 4d7781f commit 49fd1dd
Show file tree
Hide file tree
Showing 114 changed files with 3,631 additions and 1,421 deletions.
9 changes: 9 additions & 0 deletions .changeset/gentle-yaks-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
---

Fix: fix local registry server closed

Closes [#1920](https://github.com/cloudflare/workers-sdk/issues/1920). Sometimes start the local dev server will kill
the devRegistry server so that the devRegistry server can't be used. We can listen the devRegistry server close event
and reset server to `null`. When registerWorker is called, we can check if the server is `null` and start a new server.
7 changes: 7 additions & 0 deletions .changeset/serious-crews-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

[wrangler] fix: constellation command help

Changed `name` to `projectName` in some Constellation commands that interacted with projects. Also added the possibility to specify a model description when uploading it.
5 changes: 5 additions & 0 deletions .changeset/sour-timers-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solarflare-theme": patch
---

Adjusted the text color inside formatted curly brackets. Color was #eeffff is now #62676A which is uniform with the rest of the light theme.
5 changes: 5 additions & 0 deletions .changeset/stale-onions-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

feat: (alpha) - make it possible to give D1 a hint on where it should create the database
15 changes: 15 additions & 0 deletions .changeset/tough-snails-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"wrangler": minor
---

[wrangler] feat: Support for Constellation bindings

Added support for a new type of safe bindings called "Constellation"
that allows interacting with uploaded models in the context of these
projects.

```toml
[[constellation]]
binding = 'AI'
project_id = '9d478427-dea6-4988-9b16-f6f8888d974c'
```
8 changes: 8 additions & 0 deletions .changeset/twenty-donkeys-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"wrangler": minor
---

[wrangler] feat: Support for Browser Workers

These bindings allow one to use puppeteer to control a browser
in a worker script.
6 changes: 6 additions & 0 deletions .changeset/wild-olives-compete.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.14.0`](https://github.com/cloudflare/miniflare/releases/tag/v2.14.0)
10 changes: 5 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Fixes # [insert GH or internal issue number(s)].
- [ ] Tests
- [ ] Changeset ([Changeset guidelines](https://github.com/cloudflare/workers-sdk/blob/main/CONTRIBUTING.md#changesets))

**Reviewer has performed the following, where applicable:**
**Reviewer is to perform the following, as 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
- 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
21 changes: 2 additions & 19 deletions fixtures/local-mode-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,8 @@
"main": "index.js",
"scripts": {
"check:type": "tsc && tsc -p tests/tsconfig.json",
"test": "cross-env NODE_ENV=local-testing NODE_OPTIONS=--experimental-vm-modules npx jest --forceExit",
"test:ci": "cross-env NODE_ENV=local-testing NODE_OPTIONS=--experimental-vm-modules npx jest --forceExit"
},
"jest": {
"restoreMocks": true,
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
"testTimeout": 30000,
"transform": {
"^.+\\.c?(t|j)sx?$": [
"esbuild-jest",
{
"sourcemap": true
}
]
},
"transformIgnorePatterns": [
"node_modules/(?!find-up|locate-path|p-locate|p-limit|p-timeout|p-queue|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)",
"wrangler-dist/cli.js"
]
"test": "npx vitest",
"test:ci": "npx vitest"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1",
Expand Down
8 changes: 8 additions & 0 deletions fixtures/pages-simple-assets/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,13 @@ describe.concurrent("Pages Functions", () => {
expect(response.status).toEqual(308);
expect(response.headers.get("Location")).toEqual("/www.example.com/");
}
{
const response = await fetch(
`http://${ip}:${port}/%09/www.example.com/index/`,
{ redirect: "manual" }
);
expect(response.status).toEqual(308);
expect(response.headers.get("Location")).toEqual("/www.example.com/");
}
});
});
18 changes: 18 additions & 0 deletions fixtures/pages-workerjs-directory/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "pages-workerjs-directory",
"version": "0.0.0",
"private": true,
"sideEffects": false,
"scripts": {
"check:type": "tsc",
"dev": "npx wrangler pages dev public --port 8794",
"test": "npx vitest",
"test:ci": "npx vitest"
},
"devDependencies": {
"undici": "^5.9.1"
},
"engines": {
"node": ">=16.13"
}
}
Binary file not shown.
23 changes: 23 additions & 0 deletions fixtures/pages-workerjs-directory/public/_worker.js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import staticMod from "./static.js";
import add from "./add.wasm";

export default {
async fetch(request, env) {
const { pathname } = new URL(request.url);

if (pathname === "/wasm") {
const addModule = await WebAssembly.instantiate(add);
return new Response(addModule.exports.add(1, 2).toString());
}

if (pathname === "/static") {
return new Response(staticMod);
}

if (pathname !== "/") {
return new Response((await import(`./${pathname.slice(1)}`)).default);
}

return env.ASSETS.fetch(request);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "test";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "static";
1 change: 1 addition & 0 deletions fixtures/pages-workerjs-directory/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello, world!</h1>
45 changes: 45 additions & 0 deletions fixtures/pages-workerjs-directory/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { execSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path, { join, resolve } from "node:path";
import { fetch } from "undici";
import { describe, it } from "vitest";
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";

describe.concurrent("Pages _worker.js/ directory", () => {
it("should support non-bundling with 'dev'", async ({ expect }) => {
const { ip, port, stop } = await runWranglerPagesDev(
resolve(__dirname, ".."),
"public",
["--port=0"]
);
await expect(
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
).resolves.toContain("Hello, world!");
await expect(
fetch(`http://${ip}:${port}/wasm`).then((resp) => resp.text())
).resolves.toContain("3");
await expect(
fetch(`http://${ip}:${port}/static`).then((resp) => resp.text())
).resolves.toContain("static");
await expect(
fetch(`http://${ip}:${port}/other-script`).then((resp) => resp.text())
).resolves.toContain("test");
await stop();
});

it("should bundle", async ({ expect }) => {
const dir = tmpdir();
const file = join(dir, "./_worker.bundle");

execSync(
`npx wrangler pages functions build --build-output-directory public --outfile ${file} --bindings="{\\"d1_databases\\":{\\"FOO\\":{}}}"`,
{
cwd: path.resolve(__dirname, ".."),
}
);

expect(readFileSync(file, "utf-8")).toContain("D1_ERROR");
expect(readFileSync(file, "utf-8")).toContain('"static"');
});
});
12 changes: 12 additions & 0 deletions fixtures/pages-workerjs-directory/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ES2020",
"esModuleInterop": true,
"module": "CommonJS",
"lib": ["ES2020"],
"types": ["node"],
"moduleResolution": "node",
"noEmit": true
},
"include": ["tests", "../../node-types.d.ts"]
}
1 change: 1 addition & 0 deletions fixtures/sites-app/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
name = "sites-app"
site = { bucket = "./public" }
main = "src/modules.js"
13 changes: 13 additions & 0 deletions fixtures/worker-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "worker-ts",
"version": "0.0.0",
"private": true,
"scripts": {
"deploy": "wrangler publish",
"start": "wrangler dev"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230419.0",
"wrangler": "2.20.0"
}
}
34 changes: 34 additions & 0 deletions fixtures/worker-ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run `wrangler dev src/index.ts` in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run `wrangler publish src/index.ts --name my-worker` to publish your worker
*
* Learn more at https://developers.cloudflare.com/workers/
*/
export interface Env {
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
// MY_KV_NAMESPACE: KVNamespace;
//
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
// MY_DURABLE_OBJECT: DurableObjectNamespace;
//
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
// MY_BUCKET: R2Bucket;
//
// Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
// MY_SERVICE: Fetcher;
}

export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
const url = new URL(request.url);
if (url.pathname === "/error") throw new Error("Hello Error");
return new Response("Hello World!");
},
};
13 changes: 13 additions & 0 deletions fixtures/worker-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2021",
"lib": ["es2021"],
"module": "es2022",
"types": ["@cloudflare/workers-types/2022-11-30"],
"noEmit": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
3 changes: 3 additions & 0 deletions fixtures/worker-ts/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "worker-ts"
main = "src/index.ts"
compatibility_date = "2023-05-04"
Loading

0 comments on commit 49fd1dd

Please sign in to comment.