Skip to content

Commit

Permalink
Merge branch 'fork-releases' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb authored Jan 18, 2023
2 parents 935d5bc + 1e64714 commit 83ae592
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 364 deletions.
2 changes: 1 addition & 1 deletion example/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
MiddlewareRequest,
MiddlewareResponse,
MiddlewareFetchEvent,
} from "vite-vercel/server"
} from "@cycraft/vite-vercel/server"

export default (req: MiddlewareRequest, event: MiddlewareFetchEvent) => {
const url = new URL(req.url)
Expand Down
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "vite build"
},
"devDependencies": {
"vite": "2.9.7",
"vite-vercel": "workspace:*"
"vite": "3.1.8",
"@cycraft/vite-vercel": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion example/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from "vite"
import vercel from "vite-vercel"
import vercel from "@cycraft/vite-vercel"

export default defineConfig({
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"bumpp": "^8.2.1",
"turbo": "^1.4.4"
},
"version": "0.1.15",
"version": "0.1.16-fork.5",
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": [
Expand Down
6 changes: 3 additions & 3 deletions packages/vercel-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vercel-utils",
"version": "0.1.15",
"name": "@cycraft/vercel-utils",
"version": "0.1.16-fork.5",
"description": "Some utils to work with vercel edge function and serverless function",
"scripts": {
"prepublishOnly": "pnpm build",
Expand All @@ -11,7 +11,7 @@
"dist",
"/*.d.ts"
],
"repository": "github:egoist-labs/vite-vercel",
"repository": "github:cycraft/vite-vercel",
"exports": {
"./server": {
"import": "./dist/server.mjs",
Expand Down
12 changes: 6 additions & 6 deletions packages/vite-vercel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-vercel",
"version": "0.1.15",
"name": "@cycraft/vite-vercel",
"version": "0.1.16-fork.5",
"description": "Adding Vercel middleware support to your Vite project",
"publishConfig": {
"access": "public"
Expand All @@ -20,7 +20,7 @@
"import": "./dist/server.mjs"
}
},
"repository": "github:egoist-labs/vite-vercel",
"repository": "github:cycraft/vite-vercel",
"scripts": {
"build-fast": "tsup --shims",
"build": "pnpm run build-fast -- --dts-resolve",
Expand All @@ -36,13 +36,13 @@
"prettier": "2.7.1",
"tsup": "6.2.3",
"typescript": "4.8.2",
"vite": "^3.0.9",
"vite": "^3.1.8",
"vitest": "0.22.1"
},
"dependencies": {
"@cycraft/vercel-utils": "workspace:*",
"fs-extra": "^10.1.0",
"resolve-from": "^5.0.0",
"vercel-utils": "workspace:*"
"resolve-from": "^5.0.0"
},
"peerDependencies": {
"vite": "^3 || ^4"
Expand Down
23 changes: 13 additions & 10 deletions packages/vite-vercel/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ export const plugin = (options: Options = {}): Plugin => {
// at /node_modules/.pnpm/[email protected]/node_modules/fetch-blob/streams.cjs:16:17
external: ["node-fetch", "@web-std/file"],
// No sure why sometimes this is externalized
noExternal: [/vite-vercel/],
noExternal: [/vite-vercel/, /@cycraft\/vite-vercel/],
},
resolve: {
alias: {
"vercel-utils": path.dirname(resolve("vercel-utils/polyfills")),
"@cycraft/vercel-utils": path.dirname(
resolve("@cycraft/vercel-utils/polyfills"),
),
},
},
}
Expand All @@ -56,14 +58,16 @@ export const plugin = (options: Options = {}): Plugin => {
configureServer(server) {
if (!middlewarePath || process.env.VITE_VERCEL_BUILD) return

let serverNode: typeof import("vercel-utils/server-node") | undefined
let serverNode:
| typeof import("@cycraft/vercel-utils/server-node")
| undefined

server.middlewares.use(async (req, res, next) => {
if (serverNode) return next()

await server.ssrLoadModule("vercel-utils/polyfills")
await server.ssrLoadModule("@cycraft/vercel-utils/polyfills")
serverNode = (await server.ssrLoadModule(
"vercel-utils/server-node",
"@cycraft/vercel-utils/server-node",
)) as any
next()
})
Expand Down Expand Up @@ -135,25 +139,24 @@ export const plugin = (options: Options = {}): Plugin => {
entrypoint: "index.js",
})
}

writeJson(".vercel/output/config.json", {
version: 3,
routes: [
{
src: `/assets/.+`,
src: `/assets/(.+)`,
headers: {
"cache-control": "public, immutable, max-age=31536000",
"Cache-Control": "public, immutable, max-age=31536000",
},
},
{
handle: "filesystem",
},
middlewarePath && {
src: "/.*",
src: "/(.*)",
middlewarePath: "main",
continue: true,
},
{ src: "/.*", dest: "/index.html" },
{ src: "/(.*)", dest: "/index.html" },
].filter(Boolean),
})
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-vercel/src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import "vercel-utils/polyfills"
import "@cycraft/vercel-utils/polyfills"
2 changes: 1 addition & 1 deletion packages/vite-vercel/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export {
MiddlewareFetchEvent,
MiddlewareRequest,
MiddlewareResponse,
} from "vercel-utils/server"
} from "@cycraft/vercel-utils/server"
Loading

0 comments on commit 83ae592

Please sign in to comment.