Skip to content

Commit

Permalink
fix: add types to fix some TS warnings in vite.generated.ts (#20270) (#…
Browse files Browse the repository at this point in the history
…20320)

Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
  • Loading branch information
vaadin-bot and web-padawan authored Oct 23, 2024
1 parent e15bb33 commit 6d299d3
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions flow-server/src/main/resources/vite.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This file will be overwritten on every run. Any custom changes should be made to vite.config.ts
*/
import path from 'path';
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'fs';
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, Stats } from 'fs';
import { createHash } from 'crypto';
import * as net from 'net';

Expand All @@ -23,7 +23,7 @@ import {
ResolvedConfig,
UserConfigFn
} from 'vite';
import { getManifest } from 'workbox-build';
import { getManifest, type ManifestTransform } from 'workbox-build';

import * as rollup from 'rollup';
import brotli from 'rollup-plugin-brotli';
Expand Down Expand Up @@ -90,7 +90,7 @@ console.trace = () => {};
console.debug = () => {};

function injectManifestToSWPlugin(): rollup.Plugin {
const rewriteManifestIndexHtmlUrl = (manifest) => {
const rewriteManifestIndexHtmlUrl: ManifestTransform = (manifest) => {
const indexEntry = manifest.find((entry) => entry.url === 'index.html');
if (indexEntry) {
indexEntry.url = appShellUrl;
Expand All @@ -117,11 +117,11 @@ function injectManifestToSWPlugin(): rollup.Plugin {
};
}

function buildSWPlugin(opts): PluginOption {
function buildSWPlugin(opts: { devMode: boolean }): PluginOption {
let config: ResolvedConfig;
const devMode = opts.devMode;

const swObj = {};
const swObj: { code?: string, map?: rollup.SourceMap | null } = {};

async function build(action: 'generate' | 'write', additionalPlugins: rollup.Plugin[] = []) {
const includedPluginNames = [
Expand Down Expand Up @@ -563,15 +563,15 @@ export { ${bindings.map(getExportBinding).join(', ')} };`;
};
}

function themePlugin(opts): PluginOption {
function themePlugin(opts: { devMode: boolean }): PluginOption {
const fullThemeOptions = { ...themeOptions, devMode: opts.devMode };
return {
name: 'vaadin:theme',
config() {
processThemeResources(fullThemeOptions, console);
},
configureServer(server) {
function handleThemeFileCreateDelete(themeFile, stats) {
function handleThemeFileCreateDelete(themeFile: string, stats?: Stats) {
if (themeFile.startsWith(themeFolder)) {
const changed = path.relative(themeFolder, themeFile);
console.debug('Theme file ' + (!!stats ? 'created' : 'deleted'), changed);
Expand Down Expand Up @@ -632,8 +632,8 @@ function themePlugin(opts): PluginOption {
};
}

function runWatchDog(watchDogPort, watchDogHost) {
const client = net.Socket();
function runWatchDog(watchDogPort: number, watchDogHost: string | undefined) {
const client = new net.Socket();
client.setEncoding('utf8');
client.on('error', function (err) {
console.log('Watchdog connection error. Terminating vite process...', err);
Expand Down Expand Up @@ -692,7 +692,7 @@ export const vaadinConfig: UserConfigFn = (env) => {
if (devMode && process.env.watchDogPort) {
// Open a connection with the Java dev-mode handler in order to finish
// vite when it exits or crashes.
runWatchDog(process.env.watchDogPort, process.env.watchDogHost);
runWatchDog(parseInt(process.env.watchDogPort), process.env.watchDogHost);
}

return {
Expand Down Expand Up @@ -728,13 +728,13 @@ export const vaadinConfig: UserConfigFn = (env) => {

...(hasExportedWebComponents ? { webcomponenthtml: path.resolve(frontendFolder, 'web-component.html') } : {})
},
onwarn: (warning: rollup.RollupWarning, defaultHandler: rollup.WarningHandler) => {
onwarn: (warning: rollup.RollupLog, defaultHandler: rollup.LoggingFunction) => {
const ignoreEvalWarning = [
'generated/jar-resources/FlowClient.js',
'generated/jar-resources/vaadin-spreadsheet/spreadsheet-export.js',
'@vaadin/charts/src/helpers.js'
];
if (warning.code === 'EVAL' && warning.id && !!ignoreEvalWarning.find((id) => warning.id.endsWith(id))) {
if (warning.code === 'EVAL' && warning.id && !!ignoreEvalWarning.find((id) => warning.id?.endsWith(id))) {
return;
}
defaultHandler(warning);
Expand Down

0 comments on commit 6d299d3

Please sign in to comment.