chore: address deprecated Vite warnings

This commit is contained in:
Max Schmitt 2024-07-09 23:08:58 +02:00
parent f374f8db38
commit d3a5569290
9 changed files with 14 additions and 18 deletions

View file

@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
import fs, { existsSync } from 'fs'; import * as fs from 'fs';
import path from 'path'; import * as path from 'path';
import type { Plugin, UserConfig } from 'vite'; import type { Plugin, UserConfig } from 'vite';
export function bundle(): Plugin { export function bundle(): Plugin {
@ -26,7 +26,7 @@ export function bundle(): Plugin {
config = c; config = c;
}, },
transformIndexHtml: { transformIndexHtml: {
transform(html, ctx) { handler(html, ctx) {
if (!ctx || !ctx.bundle) if (!ctx || !ctx.bundle)
return html; return html;
html = html.replace(/(?=<!--)([\s\S]*?)-->/, ''); html = html.replace(/(?=<!--)([\s\S]*?)-->/, '');
@ -42,7 +42,7 @@ export function bundle(): Plugin {
}, },
}, },
closeBundle: () => { closeBundle: () => {
if (existsSync(path.join(config.build!.outDir!, 'index.html'))) { if (fs.existsSync(path.join(config.build!.outDir!, 'index.html'))) {
const targetDir = path.join(__dirname, '..', 'playwright-core', 'lib', 'vite', 'htmlReport'); const targetDir = path.join(__dirname, '..', 'playwright-core', 'lib', 'vite', 'htmlReport');
fs.mkdirSync(targetDir, { recursive: true }); fs.mkdirSync(targetDir, { recursive: true });
fs.copyFileSync( fs.copyFileSync(

View file

@ -2,6 +2,7 @@
"name": "html-reporter", "name": "html-reporter",
"private": true, "private": true,
"version": "0.0.0", "version": "0.0.0",
"type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build && tsc", "build": "vite build && tsc",

View file

@ -4,5 +4,5 @@
"module": "esnext", "module": "esnext",
"moduleResolution": "node" "moduleResolution": "node"
}, },
"include": ["vite.config.ts"] "include": ["vite.config.ts", "bundle.ts"]
} }

View file

@ -2,6 +2,7 @@
"name": "recorder", "name": "recorder",
"private": true, "private": true,
"version": "0.0.0", "version": "0.0.0",
"type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build && tsc", "build": "vite build && tsc",

View file

@ -14,23 +14,18 @@
* limitations under the License. * limitations under the License.
*/ */
/** import type { Plugin } from 'vite';
* @returns {import('vite').Plugin}
*/ export function bundle(): Plugin {
export function bundle() {
let config;
return { return {
name: 'playwright-bundle', name: 'playwright-bundle',
config(c) {
config = c;
},
transformIndexHtml: { transformIndexHtml: {
transform(html, ctx) { handler(html, ctx) {
if (!ctx || !ctx.bundle) if (!ctx || !ctx.bundle)
return html; return html;
// Workaround vite issue that we cannot exclude some scripts from preprocessing. // Workaround vite issue that we cannot exclude some scripts from preprocessing.
return html.replace(/(?=<!--)([\s\S]*?)-->/, '').replace('<!-- <script src="stall.js"></script> -->', '<script src="stall.js"></script>'); return html.replace(/(?=<!--)([\s\S]*?)-->/, '').replace('<!-- <script src="stall.js"></script> -->', '<script src="stall.js"></script>');
}, },
}, },
} };
} }

View file

@ -2,6 +2,7 @@
"name": "trace-viewer", "name": "trace-viewer",
"private": true, "private": true,
"version": "0.0.0", "version": "0.0.0",
"type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build && tsc", "build": "vite build && tsc",

View file

@ -4,5 +4,5 @@
"module": "esnext", "module": "esnext",
"moduleResolution": "node" "moduleResolution": "node"
}, },
"include": ["vite.config.ts"] "include": ["vite.config.ts", "bundle.ts"]
} }

View file

@ -16,7 +16,6 @@
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react'; import react from '@vitejs/plugin-react';
// @ts-ignore
import { bundle } from './bundle'; import { bundle } from './bundle';
import * as path from 'path'; import * as path from 'path';

View file

@ -16,7 +16,6 @@
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react'; import react from '@vitejs/plugin-react';
// @ts-ignore
import { bundle } from './bundle'; import { bundle } from './bundle';
import * as path from 'path'; import * as path from 'path';