Skip to content

Commit

Permalink
Merge pull request #26 from petebacondarwin/foo
Browse files Browse the repository at this point in the history
Foo
  • Loading branch information
petebacondarwin authored Dec 17, 2024
2 parents 0e9499e + 303d08a commit ba3eca8
Show file tree
Hide file tree
Showing 208 changed files with 10,239 additions and 0 deletions.
1 change: 1 addition & 0 deletions foo/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
37 changes: 37 additions & 0 deletions foo/.github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish prereleases

on:
push:
branches: [main]
pull_request:

jobs:
publish-prerelease:
if: ${{ github.repository_owner == 'flarelabs-net' }}
name: Publish prerelease
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Install Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'

- name: Install Dependencies
shell: bash
run: pnpm install --frozen-lockfile

- name: Publish to pkg-pr-new
run: pnpm exec pkg-pr-new publish --pnpm './packages/vite-plugin-cloudflare'
42 changes: 42 additions & 0 deletions foo/.github/workflows/pull-request-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Pull Request Checks

on: pull_request

jobs:
checks:
strategy:
fail-fast: false
matrix:
os: [macos-13, windows-2022, ubuntu-22.04]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Install Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'

- name: Install Dependencies
shell: bash
run: pnpm install --frozen-lockfile

- name: Install Playwright extras
shell: bash
run: pnpm playwright install

- name: Running checks
shell: bash
run: pnpm check

- name: Run tests
shell: bash
run: pnpm test
8 changes: 8 additions & 0 deletions foo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
pnpm-debug.log*
dist
.vscode
.DS_Store
**/*.tsbuildinfo
.wrangler
playground-temp
2 changes: 2 additions & 0 deletions foo/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pnpm-lock.yaml
worker-configuration.d.ts
36 changes: 36 additions & 0 deletions foo/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"useTabs": true,
"singleQuote": true,
"plugins": [
"@ianvs/prettier-plugin-sort-imports",
"prettier-plugin-packagejson"
],
"importOrder": [
"<BUILTIN_MODULES>",
"<THIRD_PARTY_MODULES>",
"^[.]{2}$",
"^[.]{2}/",
"^[.]/(?!index)",
"^[.]$",
"^[.]/index$",
"<TYPES>"
],
"importOrderTypeScriptVersion": "5.5.2",
"importOrderParserPlugins": [
"typescript",
"jsx",
"decorators",
"explicitResourceManagement"
],
"overrides": [
{
"files": "*.d.ts",
"options": {
"importOrderParserPlugins": [
"[\"typescript\", { \"dts\": true }]",
"decorators"
]
}
}
]
}
10 changes: 10 additions & 0 deletions foo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# vite-plugin-cloudflare

> [!WARNING]
> This is experimental.
## Install the latest version

```bash
npm install https://pkg.pr.new/flarelabs-net/vite-plugin-cloudflare/@flarelabs-net/vite-plugin-cloudflare@main --save-dev
```
37 changes: 37 additions & 0 deletions foo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@vite-plugin-cloudflare/root",
"private": true,
"description": "Monorepo for vite-plugin-cloudflare",
"type": "module",
"scripts": {
"check": "pnpm run check:types && pnpm run check:prettier",
"check:prettier": "prettier --check .",
"check:types": "tsc --build && pnpm -r check:types",
"fix": "pnpm run fix:prettier",
"fix:prettier": "prettier --write .",
"postinstall": "pnpm -F @flarelabs-net/vite-plugin-cloudflare build",
"test": "pnpm test-unit && pnpm test-serve && pnpm test-build",
"test-build": "cross-env VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
"test-serve": "vitest run -c vitest.config.e2e.ts",
"test-serve:watch": "vitest -c vitest.config.e2e.ts",
"test-unit": "vitest run",
"test-unit:watch": "vitest"
},
"dependencies": {
"cross-env": "^7.0.3"
},
"devDependencies": {
"@ianvs/prettier-plugin-sort-imports": "^4.3.1",
"@vite-plugin-cloudflare/typescript-config": "workspace:*",
"pkg-pr-new": "^0.0.33",
"playwright-chromium": "^1.48.1",
"prettier": "^3.3.3",
"prettier-plugin-packagejson": "^2.5.3",
"typescript": "catalog:default",
"vite": "catalog:default",
"vitest": "^2.1.3"
},
"engines": {
"pnpm": "^9.12.0"
}
}
18 changes: 18 additions & 0 deletions foo/packages/typescript-config/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"esModuleInterop": false,
"skipLibCheck": true,
"target": "ES2022",
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
"verbatimModuleSyntax": true,
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"module": "Preserve",
"lib": ["ES2022"],
"noEmit": true
}
}
7 changes: 7 additions & 0 deletions foo/packages/typescript-config/client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"lib": ["ES2022", "DOM", "DOM.Iterable"]
}
}
5 changes: 5 additions & 0 deletions foo/packages/typescript-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@vite-plugin-cloudflare/typescript-config",
"version": "0.0.0",
"private": true
}
8 changes: 8 additions & 0 deletions foo/packages/typescript-config/react.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./client.json",
"compilerOptions": {
"allowImportingTsExtensions": true,
"jsx": "react-jsx"
}
}
11 changes: 11 additions & 0 deletions foo/packages/typescript-config/worker-node-compat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"types": [
"@cloudflare/workers-types/experimental",
"vite/client",
"@types/node"
]
}
}
7 changes: 7 additions & 0 deletions foo/packages/typescript-config/worker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"types": ["@cloudflare/workers-types/experimental", "vite/client"]
}
}
57 changes: 57 additions & 0 deletions foo/packages/vite-plugin-cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@flarelabs-net/vite-plugin-cloudflare",
"version": "0.0.0",
"description": "Cloudflare plugin for Vite",
"keywords": [
"cloudflare",
"workers",
"cloudflare-workers",
"vite",
"vite-plugin"
],
"repository": {
"type": "git",
"url": "https://github.com/flarelabs-net/vite-plugin-cloudflare",
"directory": "packages/vite-plugin-cloudflare"
},
"license": "MIT",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsup",
"check:types": "tsc --build",
"test": "vitest run",
"watch": "tsup --watch"
},
"dependencies": {
"@hattip/adapter-node": "^0.0.49",
"miniflare": "3.20241205.0"
},
"devDependencies": {
"@cloudflare/workers-shared": "^0.7.0",
"@cloudflare/workers-types": "catalog:default",
"@types/node": "catalog:default",
"@vite-plugin-cloudflare/typescript-config": "workspace:*",
"magic-string": "^0.30.12",
"tsup": "^8.3.0",
"typescript": "catalog:default",
"unenv": "catalog:default",
"vite": "catalog:default",
"wrangler": "catalog:default"
},
"peerDependencies": {
"vite": "catalog:default",
"wrangler": "catalog:default"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @ts-ignore
import AssetWorker from '@cloudflare/workers-shared/dist/asset-worker.mjs';
import { UNKNOWN_HOST } from '../shared';
import type { WorkerEntrypoint } from 'cloudflare:workers';

interface Env {
__VITE_ASSET_EXISTS__: Fetcher;
__VITE_FETCH_ASSET__: Fetcher;
}

export default class CustomAssetWorker extends (AssetWorker as typeof WorkerEntrypoint<Env>) {
override async fetch(request: Request): Promise<Response> {
const response = await super.fetch!(request);
const modifiedResponse = new Response(response.body, response);
modifiedResponse.headers.delete('ETag');
modifiedResponse.headers.delete('Cache-Control');

return modifiedResponse;
}
async unstable_getByETag(
eTag: string,
): Promise<{ readableStream: ReadableStream; contentType: string }> {
const url = new URL(eTag, UNKNOWN_HOST);
const response = await this.env.__VITE_FETCH_ASSET__.fetch(url);

if (!response.body) {
throw new Error(`Unexpected error. No HTML found for ${eTag}.`);
}

return { readableStream: response.body, contentType: 'text/html' };
}
async unstable_exists(pathname: string): Promise<string | null> {
// We need this regex to avoid getting `//` as a pathname, which results in an invalid URL. Should this be fixed upstream?
const url = new URL(pathname.replace(/^\/{2,}/, '/'), UNKNOWN_HOST);
const response = await this.env.__VITE_ASSET_EXISTS__.fetch(url);
const exists = await response.json();

return exists ? pathname : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-ignore
import routerWorker from '@cloudflare/workers-shared/dist/router-worker.mjs';

export default routerWorker;
Loading

0 comments on commit ba3eca8

Please sign in to comment.