chore: address deprecated Vite warnings (#31618)

This commit is contained in:
Max Schmitt 2024-07-10 22:32:08 +02:00 committed by GitHub
parent ba62f83454
commit a3b0f0cba8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 27 additions and 25 deletions

View File

@ -30,7 +30,7 @@
"ct": "playwright test tests/components/test-all.spec.js --reporter=list", "ct": "playwright test tests/components/test-all.spec.js --reporter=list",
"test": "playwright test --config=tests/library/playwright.config.ts", "test": "playwright test --config=tests/library/playwright.config.ts",
"eslint": "eslint --cache --report-unused-disable-directives --ext ts,tsx,js,jsx,mjs .", "eslint": "eslint --cache --report-unused-disable-directives --ext ts,tsx,js,jsx,mjs .",
"tsc": "tsc -p .", "tsc": "tsc -p . && tsc -p packages/html-reporter/",
"build-installer": "babel -s --extensions \".ts\" --out-dir packages/playwright-core/lib/utils/ packages/playwright-core/src/utils", "build-installer": "babel -s --extensions \".ts\" --out-dir packages/playwright-core/lib/utils/ packages/playwright-core/src/utils",
"doc": "node utils/doclint/cli.js", "doc": "node utils/doclint/cli.js",
"lint": "npm run eslint && npm run tsc && npm run doc && npm run check-deps && node utils/generate_channels.js && node utils/generate_types/ && npm run lint-tests && npm run test-types && npm run lint-packages", "lint": "npm run eslint && npm run tsc && npm run doc && npm run check-deps && node utils/generate_channels.js && node utils/generate_types/ && npm run lint-tests && npm run test-types && npm run lint-packages",

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import fs, { existsSync } from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import type { Plugin, UserConfig } from 'vite'; import type { Plugin, UserConfig } from 'vite';
@ -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

@ -16,6 +16,7 @@
import { devices, defineConfig } from '@playwright/experimental-ct-react'; import { devices, defineConfig } from '@playwright/experimental-ct-react';
import path from 'path'; import path from 'path';
import url from 'url';
export default defineConfig({ export default defineConfig({
testDir: 'src', testDir: 'src',
@ -28,7 +29,7 @@ export default defineConfig({
ctViteConfig: { ctViteConfig: {
resolve: { resolve: {
alias: { alias: {
'@web': path.resolve(__dirname, '../web/src'), '@web': path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '../web/src'),
}, },
} }
}, },

View File

@ -2,7 +2,9 @@
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": true,
"module": "esnext", "module": "esnext",
"moduleResolution": "node" "moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}, },
"include": ["vite.config.ts"] "include": ["playwright.config.ts", "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

@ -2,7 +2,9 @@
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": true,
"module": "esnext", "module": "esnext",
"moduleResolution": "node" "moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}, },
"include": ["vite.config.ts"] "include": ["vite.config.ts", "vite.sw.config.ts", "bundle.ts"]
} }

View File

@ -16,9 +16,8 @@
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 path from 'path';
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({

View File

@ -16,9 +16,8 @@
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 path from 'path';
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({

View File

@ -24,7 +24,7 @@
"esModuleInterop": true, "esModuleInterop": true,
"strict": true, "strict": true,
"allowJs": false, "allowJs": false,
"jsx": "preserve", "jsx": "react-jsx",
"resolveJsonModule": true, "resolveJsonModule": true,
"noEmit": true, "noEmit": true,
"noImplicitOverride": true, "noImplicitOverride": true,
@ -35,5 +35,6 @@
"include": ["packages"], "include": ["packages"],
"exclude": [ "exclude": [
"packages/*/lib", "packages/*/lib",
], "packages/html-reporter/",
]
} }