Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
branches:
- dev
pull_request:
branches:
- dev

permissions:
contents: read
Expand All @@ -20,21 +18,21 @@ jobs:

strategy:
matrix:
node-version: [22.x]
node-version: [22.x, 24.x, 25.x]

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
persist-credentials: false

- name: Install pnpm
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
with:
version: 10.17.0+sha512.fce8a3dd29a4ed2ec566fb53efbb04d8c44a0f05bc6f24a73046910fb9c3ce7afa35a0980500668fa3573345bd644644fa98338fa168235c80f4aa17aa17fbef

- name: Set up Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
cache: "pnpm"
check-latest: true
Expand All @@ -44,4 +42,5 @@ jobs:
run: pnpm install --ignore-scripts

- name: Run tests
shell: 'script --return --quiet --command "bash {0}"'
run: pnpm test
2 changes: 1 addition & 1 deletion examples/vue-vanilla-ts/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'node:test'
import { makeBuildTest, makeIndexTest } from '../test-factories.mjs'
import { main } from './server.js'
import { main } from './src/server.ts'

const cwd = import.meta.dirname

Expand Down
4 changes: 2 additions & 2 deletions packages/fastify-react/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { createHtmlTemplates } from './templating.js'
// from the renderToPipeableStream() onShellReady event
export function onShellReady(app) {
const duplex = new Minipass()
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
try {
const pipeable = renderToPipeableStream(app, {
onShellReady() {
Expand All @@ -30,7 +30,7 @@ export function onShellReady(app) {
// from the renderToPipeableStream() onAllReady event
export function onAllReady(app) {
const duplex = new Minipass()
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
try {
const pipeable = renderToPipeableStream(app, {
onAllReady() {
Expand Down
35 changes: 23 additions & 12 deletions packages/fastify-vite/mode/production.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { join, resolve } = require('node:path')
const { join, resolve, isAbsolute } = require('node:path')
const FastifyStatic = require('@fastify/static')
const { parse, resolveIfRelative, read, exists } = require('../ioutils.cjs')

Expand All @@ -17,6 +17,10 @@ function fileUrl(str) {
return encodeURI(`file://${pathName}`)
}

function adaptPath(path) {
return process.platform === 'win32' ? new URL(fileUrl(path)) : path
}

async function setup(config) {
const { spa, vite } = config
let clientOutDir
Expand Down Expand Up @@ -124,16 +128,26 @@ async function setup(config) {

return { client, routes: client?.routes }

async function loadBundle(viteRoot, distOutDir, entryPath) {
function retrievePath(viteConfig, env, serverFile) {
const viteRoot = viteConfig.root
const distOutDir = viteConfig.fastify.outDirs[env]
if (viteConfig.fastify.usePathsRelativeToAppRoot) {
return resolve(distOutDir, serverFile)
}
if (isAbsolute(distOutDir)) {
return resolve(distOutDir, serverFile)
}
return resolve(viteRoot, distOutDir, serverFile)
}

async function loadBundle(viteConfig, env, entryPath) {
const parsedNamed = parse(entryPath).name
const bundleFiles = [`${parsedNamed}.js`, `${parsedNamed}.mjs`]
let bundlePath
for (const serverFile of bundleFiles) {
const path = retrievePath(viteConfig, env, serverFile)
// Use file path on Windows
bundlePath =
process.platform === 'win32'
? new URL(fileUrl(resolve(viteRoot, distOutDir, serverFile)))
: resolve(viteRoot, distOutDir, serverFile)
bundlePath = adaptPath(path)
if (exists(bundlePath)) {
break
}
Expand Down Expand Up @@ -164,18 +178,15 @@ async function setup(config) {
ssrManifestPath = manifestPath
}
}
const ssrManifest =
process.platform === 'win32'
? new URL(fileUrl(ssrManifestPath))
: ssrManifestPath
const ssrManifest = adaptPath(ssrManifestPath)

const entries = {}
for (const [env, entryPath] of Object.entries(
config.vite.fastify.entryPaths,
)) {
entries[env] = await loadBundle(
config.vite.root,
config.vite.fastify.outDirs[env],
config.vite,
env,
entryPath,
)
}
Expand Down