Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade vite 5 #526

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-test-env
- name: Build JS
run: pnpm build
- name: Run Lint
run: pnpm run lint

Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
packages =
rec {
bash = pkgs.bash;
nodejs = pkgs.nodejs-18_x;
nodejs = pkgs.nodejs_20;
pnpm = pkgs.nodePackages.pnpm;
};

Expand Down
3 changes: 0 additions & 3 deletions jest.config.js

This file was deleted.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"lint:fix": "prettier --loglevel warn --write \"packages/**/*.{ts,tsx}\" && eslint \"packages/**/*.{ts,tsx}\" --quiet --fix",
"release": "pnpm -F=fastify-renderer publish",
"preinstall": "npx only-allow pnpm",
"prerelease": "pnpm -F=fastify-renderer run gitpkg publish",
"test": "jest --forceExit -w=1",
"test:debug": "cross-env FR_DEBUG_SERVE=1 node --inspect-brk ./node_modules/.bin/jest --forceExit"
"prerelease": "pnpm -F=fastify-renderer exec gitpkg publish",
"test": "vitest --pool=forks --run"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -44,9 +43,8 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"expect-playwright": "^0.8.0",
"fs-extra": "^11.1.0",
"jest": "^29.7.0",
"vitest": "^1.0.4",
"playwright-chromium": "^1.39.0",
"prettier": "^2.8.8",
"prettier-plugin-organize-imports": "^3.2.3",
Expand Down
196 changes: 0 additions & 196 deletions packages/fastify-renderer/jest.config.js

This file was deleted.

22 changes: 13 additions & 9 deletions packages/fastify-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{
"name": "fastify-renderer",
"version": "0.4.2",
"version": "0.5.0",
"description": "Simple, high performance client side app renderer for Fastify.",
"exports": {
".": {
"require": "./node/index.js"
"default": "./node/index.js",
"import": "./node/index.js"
},
"./client/react": {
"default": "./client/react/index.js"
"default": "./client/react/index.js",
"import": "./client/react/index.js"
},
"./client/react/DefaultLayout": {
"default": "./client/react/DefaultLayout.js",
"import": "./client/react/DefaultLayout.js"
},
"./package": "./package.json",
"./package.json": "./package.json"
Expand All @@ -29,7 +35,7 @@
"lint:fix": "prettier --loglevel warn --write \"{src,test}/**/*.{ts,tsx}\" && eslint \"{src,test}/**/*.{ts,tsx}\" --quiet --fix",
"prepublishOnly": "npm run build",
"test": "run-s build test:unit lint",
"test:unit": "jest"
"test:unit": "vitest --run"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -67,8 +73,8 @@
"path-to-regexp": "^6.2.1",
"sanitize-filename": "^1.6.3",
"stream-template": "^0.0.10",
"vite": "^2.9.15",
"wouter": "^2.7.5"
"vite": "^5.3.1",
"wouter": "^2.11.0"
},
"peerDependencies": {
"fastify": "^4.24.2",
Expand All @@ -77,9 +83,7 @@
},
"devDependencies": {
"@swc/core": "^1.3.95",
"@swc/jest": "^0.2.29",
"@types/connect": "^3.4.35",
"@types/jest": "^29.5.6",
"@types/node": "^18.11.9",
"@types/react": "^17.0.43",
"@types/react-dom": "^17.0.11",
Expand All @@ -95,7 +99,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"fastify": "^4.24.2",
"gitpkg": "^1.0.0-beta.2",
"jest": "^29.7.0",
"vitest": "^0.34.6",
"npm-run-all": "^4.1.5",
"pino-pretty": "^8.1.0",
"prettier": "^2.7.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify-renderer/src/client/react/matcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Key, pathToRegexp } from 'path-to-regexp'
import { MatcherFn } from 'wouter'
import { MatcherFn } from 'wouter/matcher'

/*
* This function specifies how strings like /app/:users/:items* are transformed into regular expressions to pass into path-to-regexp.
Expand Down
6 changes: 5 additions & 1 deletion packages/fastify-renderer/src/client/react/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"sideEffects": false,
"module": "./index.js"
"type": "module",
"exports": {
".": "./index.js",
"./DefaultLayout": "./DefaultLayout.js"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'wouter'

declare module 'wouter' {
export interface RouterProps {
export interface RouterObject {
navigationHistory?: NavigationHistory
}

Expand Down
4 changes: 2 additions & 2 deletions packages/fastify-renderer/src/node/Plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/require-await */
import '@fastify/middie'
import fs from 'fs'
import fs from 'node:fs'
import path from 'path'
import { InlineConfig } from 'vite'
import { Template } from './DocumentTemplate'
Expand Down Expand Up @@ -39,7 +39,7 @@ export class FastifyRendererPlugin {
registeredComponents: Record<ImperativeRenderable, RenderableRegistration> = {}

constructor(incomingOptions: FastifyRendererOptions) {
this.devMode = incomingOptions.devMode ?? process.env.NODE_ENV != 'production'
this.devMode = incomingOptions.devMode ?? (process.env.NODE_ENV != 'production' || process.env.TEST == 'true')

this.vite = incomingOptions.vite || {}
this.vite.base ??= '/.vite/'
Expand Down
5 changes: 3 additions & 2 deletions packages/fastify-renderer/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import '@fastify/middie'
import fastifyStatic from '@fastify/static'
import { FastifyInstance, FastifyPluginAsync, FastifyReply } from 'fastify'
import fp from 'fastify-plugin'
import { promises as fs } from 'fs'
import { promises as fs } from 'node:fs'
import path from 'path'
import { resolveConfig, build as viteBuild, createServer, ResolvedConfig, ViteDevServer } from 'vite'
import { DefaultDocumentTemplate } from './DocumentTemplate'
Expand Down Expand Up @@ -53,7 +53,7 @@ const plugin: FastifyPluginAsync<FastifyRendererOptions> = async (fastify, incom

fastify.setRenderConfig({
base: incomingOptions.base || '',
layout: incomingOptions.layout || require.resolve('./renderers/react/DefaultLayout'),
layout: incomingOptions.layout || require.resolve('fastify-renderer/client/react/DefaultLayout'),
document: incomingOptions.document || DefaultDocumentTemplate,
})

Expand Down Expand Up @@ -149,6 +149,7 @@ const plugin: FastifyPluginAsync<FastifyRendererOptions> = async (fastify, incom
fastify.addHook('onReady', async () => {
fastify[kRendererViteOptions] = {
clearScreen: false,
appType: 'custom',
...plugin.vite,
plugins: [...(plugin.vite?.plugins || []), ...plugin.renderer.vitePlugins()],
server: {
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify-renderer/src/node/renderers/Renderer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyReply, FastifyRequest } from 'fastify'
import { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
import { Template } from '../DocumentTemplate'

/** The options configuring a plugin encapsulation context's renders */
Expand Down
Loading
Loading