Skip to content

Commit fcd5f82

Browse files
committed
Initial commit
0 parents  commit fcd5f82

17 files changed

+8620
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
.mf

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Miniflare Example Project
2+
3+
This is an example [Cloudflare Workers](https://workers.cloudflare.com/) project that uses [Miniflare](https://github.com/cloudflare/miniflare) for local development, [TypeScript](https://www.typescriptlang.org/), [esbuild](https://github.com/evanw/esbuild) for bundling, and [Jest](https://jestjs.io/) for testing, using [Miniflare's custom Jest environment](https://v2.miniflare.dev/jest.html).
4+
5+
```shell
6+
# Install dependencies
7+
$ npm install
8+
# Start local development server with live reload
9+
$ npm run dev
10+
# Run tests
11+
$ npm test
12+
# Run type checking
13+
$ npm run types:check
14+
```

bindings.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface Bindings {
2+
COUNTER: DurableObjectNamespace;
3+
}

build.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import fs from "fs/promises";
2+
import path from "path";
3+
import { fileURLToPath } from "url";
4+
import { build } from "esbuild";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
export async function* walk(rootPath) {
10+
for (const fileName of await fs.readdir(rootPath)) {
11+
const filePath = path.join(rootPath, fileName);
12+
if ((await fs.stat(filePath)).isDirectory()) {
13+
yield* walk(filePath);
14+
} else {
15+
yield filePath;
16+
}
17+
}
18+
}
19+
20+
const src = path.join(__dirname, "src", "index.ts");
21+
const entryPoints = [src];
22+
if (process.argv[2] === "test") {
23+
for await (const test of walk(path.join(__dirname, "test"))) {
24+
if (test.endsWith(".spec.ts")) entryPoints.push(test);
25+
}
26+
}
27+
28+
try {
29+
await build({
30+
bundle: true,
31+
sourcemap: true,
32+
format: "esm",
33+
outdir: path.join(__dirname, "dist"),
34+
outbase: __dirname,
35+
outExtension: { ".js": ".mjs" },
36+
entryPoints,
37+
});
38+
} catch {
39+
process.exitCode = 1;
40+
}

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defaults } from "jest-config";
2+
3+
export default {
4+
testEnvironment: "miniflare",
5+
testMatch: ["**/dist/test/**/*.mjs"],
6+
moduleFileExtensions: [...defaults.moduleFileExtensions, "mjs"],
7+
};

0 commit comments

Comments
 (0)