Skip to content

Commit

Permalink
feat: update vite to 4.5.0, typescript 5.3.2
Browse files Browse the repository at this point in the history
Update chalk, commander. Also update dev dependencies.
  • Loading branch information
MatthewPattell committed Nov 24, 2023
1 parent 3e3f87f commit 64f4c7f
Show file tree
Hide file tree
Showing 15 changed files with 1,575 additions and 1,305 deletions.
2,698 changes: 1,477 additions & 1,221 deletions package-lock.json

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,47 @@
"prepare": "husky install"
},
"dependencies": {
"chalk": "^5.2.0",
"commander": "^10.0.1",
"chalk": "^5.3.0",
"commander": "^11.1.0",
"compression": "^1.7.4",
"express": "^4.18.2",
"hjson": "^3.2.2",
"hoist-non-react-statics": "^3.3.2"
},
"devDependencies": {
"@commitlint/cli": "^17.6.5",
"@commitlint/config-conventional": "^17.6.5",
"@lomray/eslint-config": "^3.0.0",
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@lomray/eslint-config": "^4.0.1",
"@lomray/prettier-config": "^1.2.0",
"@rollup/plugin-terser": "^0.4.3",
"@types/compression": "^1.7.2",
"@types/hjson": "^2.4.3",
"@types/hoist-non-react-statics": "^3.3.1",
"@rollup/plugin-terser": "^0.4.4",
"@types/compression": "^1.7.5",
"@types/hjson": "^2.4.6",
"@types/hoist-non-react-statics": "^3.3.5",
"@types/react-dom": "^18.2.5",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@zerollup/ts-transform-paths": "^1.7.18",
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-prettier": "^5.0.1",
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"prettier": "^2.8.8",
"lint-staged": "^15.1.0",
"prettier": "^3.1.0",
"rollup": "^3.25.1",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-folder-input": "^1.0.1",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-preserve-shebangs": "^0.2.0",
"rollup-plugin-ts": "^3.2.0",
"semantic-release": "^21.0.5",
"typescript": "^4.9.5"
"rollup-plugin-ts": "^3.4.5",
"semantic-release": "^21.1.2",
"typescript": "^5.3.2"
},
"peerDependencies": {
"@types/express": "^4.17.17",
"@types/express": "^4.17.21",
"react-dom": ">=18.2.0",
"react-router-dom": ">=6.12.1",
"vite": "^4.4.6"
"vite": "^4.5.0"
},
"bin": {
"ssr-boost": "cli.js"
Expand Down
14 changes: 7 additions & 7 deletions src/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ async function build({
);

if (!isWatch) {
const exitCode = (await clientProcess) as number;
const exitCode = await clientProcess.promise;

processStop(exitCode, true);
}

let serverProcess: Promise<unknown> | undefined;
let serverProcess: ReturnType<Build['promisifyProcess']> | null = null;

/**
* Build server
Expand All @@ -97,7 +97,7 @@ async function build({
);

if (!isWatch) {
const exitCode = (await serverProcess) as number;
const exitCode = await serverProcess.promise;

processStop(exitCode, true);
await buildService.buildManifest();
Expand Down Expand Up @@ -126,8 +126,8 @@ async function build({
buildCount -= 1;

if (!buildCount) {
clientProcess['command'].stdout.removeListener('data', listener);
serverProcess?.['command'].stdout.removeListener('data', listener);
clientProcess.command.stdout?.removeListener('data', listener);
serverProcess?.command.stdout?.removeListener('data', listener);
createDevMarker(buildService.isProd, buildService.viteConfig);
onFinish?.();
}
Expand All @@ -137,8 +137,8 @@ async function build({
/**
* Listen output for call onFinish
*/
clientProcess['command'].stdout.on('data', listener);
serverProcess?.['command'].stdout.on('data', listener);
clientProcess.command.stdout?.on('data', listener);
serverProcess?.command.stdout?.on('data', listener);

return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/get-server-state.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* Get server state on the client side
*/
const getServerState = (name: string, shouldRemove = true): Record<string, any> => {
const data = window[name] as Record<string, any>;
const getServerState = <TP = Record<string, any>>(name: string, shouldRemove = true): TP => {
const data = (window as Record<any, any>)[name] as TP;

if (shouldRemove && data) {
delete window[name];
delete (window as Record<any, any>)[name];
}

return data ?? {};
return (data ?? {}) as TP;
};

export default getServerState;
11 changes: 6 additions & 5 deletions src/helpers/import-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { keys } from '@interfaces/fc-route';

export type IDynamicRoute = () => Promise<{ default: FCRoute | FCCRoute<any> }>;

export type IAsyncRoute =
export type IAsyncRoute = { pathId?: string } & (
| Omit<IndexRouteObject, ImmutableRouteKey>
| Omit<NonIndexRouteObject, ImmutableRouteKey>;
| Omit<NonIndexRouteObject, ImmutableRouteKey>
);

/**
* Import dynamic route
Expand All @@ -17,16 +18,16 @@ const importRoute = async (route: IDynamicRoute, id?: string): Promise<IAsyncRou
const resolved = await route();

// fallback to react router export style
if (resolved['Component']) {
if ('Component' in resolved) {
return { ...resolved, pathId: id } as IAsyncRoute;
}

const Component = resolved.default;
const result = { Component, pathId: id };
const result: IAsyncRoute = { Component, pathId: id };

keys.forEach((key) => {
if (Component[key]) {
result[key] = Component[key];
result[key] = Component[key] as any;
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/obtain-stream-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface IObtainStreamErrorOut {
* Get react stream error
*/
const obtainStreamError = (err: unknown): IObtainStreamErrorOut => {
const message = (err?.['message'] ?? 'Unknown.').replace('Error: ', '');
const message = ((err as Record<string, any>)?.message ?? 'Unknown.').replace('Error: ', '');

if (message === 'The render was aborted by the server without a reason.') {
return {
Expand Down
7 changes: 4 additions & 3 deletions src/helpers/plugin-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export interface IPluginConfig extends Required<IPluginOptions> {
* Get plugin config from vite config
*/
function getPluginConfig(viteConfig: ResolvedConfig): IPluginConfig {
const pluginOptions = viteConfig.plugins.find((plugin) => plugin.name === PLUGIN_NAME)?.[
'pluginOptions'
] as unknown as IPluginConfig;
const pluginConfig = viteConfig.plugins.find(
(plugin) => plugin.name === PLUGIN_NAME,
) as ResolvedConfig['plugins'][number] & { pluginOptions?: IPluginConfig };
const pluginOptions = pluginConfig?.pluginOptions;

if (!pluginOptions) {
throw new Error(
Expand Down
7 changes: 5 additions & 2 deletions src/helpers/print-server-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'node:fs';
import type { Server } from 'node:net';
import { performance } from 'node:perf_hooks';
import chalk from 'chalk';
import type { ResolvedConfig } from 'vite';
import CliActions from '@constants/cli-actions';
import cliName from '@constants/cli-name';
import { getMarkerFile } from '@helpers/dev-marker';
Expand Down Expand Up @@ -38,12 +39,14 @@ async function printServerInfo(
{ clear: !Logger.hasWarned },
);

const viteConfig = config.getVite()?.config;
const viteConfig = config.getVite()?.config as
| (ResolvedConfig & { rawBase?: string })
| undefined;
const isProdBuild = !viteConfig?.mode && !fs.existsSync(devMarker);
const resolvedUrls = await resolveServerUrls(server, {
host,
isHttps: typeof viteConfig?.server.https === 'boolean' ? viteConfig?.server.https : false,
rawBase: viteConfig?.['rawBase'],
rawBase: viteConfig?.rawBase,
});
const mode =
viteConfig?.mode || isProdBuild
Expand Down
12 changes: 9 additions & 3 deletions src/helpers/process-stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import process from 'node:process';
/**
* Stop node process
*/
const processStop = (code = 0, isOnlyError = false) => {
if (isOnlyError && code === 0) {
const processStop = (code: number | string | null = 0, isOnlyError = false): void => {
if (isOnlyError && (code === 0 || code === null)) {
return;
}

process.exit(code);
if (typeof code === 'string') {
console.error(code);

return process.exit(1);
}

process.exit(code === null ? 0 : code);
};

export default processStop;
3 changes: 2 additions & 1 deletion src/node/create-fetch-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ function createFetchRequest(req: ExpressRequest): Request {
method: req.method,
headers,
signal: controller.signal,
body: undefined,
};

if (req.method !== 'GET' && req.method !== 'HEAD') {
init['body'] = req.body;
init.body = req.body;
}

return new Request(url.href, init);
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function ViteSsrBoostPlugin(options: IPluginOptions = {}): Plugin[] {
const dirInfo = new URL(import.meta.url);
const action = (global.viteBoostAction || process.env.SSR_BOOST_ACTION) as CliActions;
const mergedOptions: IPluginOptions = { ...defaultOptions, ...options };
const isSSR = process.env.SSR_BOOST_IS_SSR === '1' || action === 'dev';
const isSSR = process.env.SSR_BOOST_IS_SSR === '1' || action === CliActions.dev;
const isBuild = action === CliActions.build;

const plugins: Plugin[] = [
Expand Down
8 changes: 3 additions & 5 deletions src/services/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class Build {
public promisifyProcess(
command: childProcess.ChildProcess,
isRejectWarnings = false,
): Promise<unknown> {
const promise = new Promise((resolve, reject) => {
): { promise: Promise<number | null | string>; command: childProcess.ChildProcess } {
const promise = new Promise<number | null | string>((resolve, reject) => {
command.on('exit', (code) => {
resolve(code);
});
Expand All @@ -123,9 +123,7 @@ class Build {
command.stdout?.pipe(process.stdout);
command.stderr?.pipe(process.stderr);

promise['command'] = command;

return promise;
return { promise, command };
}

/**
Expand Down
Loading

0 comments on commit 64f4c7f

Please sign in to comment.