forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from petebacondarwin/foo
Foo
- Loading branch information
Showing
208 changed files
with
10,239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pnpm-lock.yaml | ||
worker-configuration.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
foo/packages/vite-plugin-cloudflare/src/asset-workers/asset-worker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
foo/packages/vite-plugin-cloudflare/src/asset-workers/router-worker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.