Skip to content

Commit a3b0f0c

Browse files
authored
chore: address deprecated Vite warnings (microsoft#31618)
1 parent ba62f83 commit a3b0f0c

File tree

12 files changed

+27
-25
lines changed

12 files changed

+27
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"ct": "playwright test tests/components/test-all.spec.js --reporter=list",
3131
"test": "playwright test --config=tests/library/playwright.config.ts",
3232
"eslint": "eslint --cache --report-unused-disable-directives --ext ts,tsx,js,jsx,mjs .",
33-
"tsc": "tsc -p .",
33+
"tsc": "tsc -p . && tsc -p packages/html-reporter/",
3434
"build-installer": "babel -s --extensions \".ts\" --out-dir packages/playwright-core/lib/utils/ packages/playwright-core/src/utils",
3535
"doc": "node utils/doclint/cli.js",
3636
"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",

packages/html-reporter/bundle.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import fs, { existsSync } from 'fs';
17+
import fs from 'fs';
1818
import path from 'path';
1919
import type { Plugin, UserConfig } from 'vite';
2020

@@ -26,7 +26,7 @@ export function bundle(): Plugin {
2626
config = c;
2727
},
2828
transformIndexHtml: {
29-
transform(html, ctx) {
29+
handler(html, ctx) {
3030
if (!ctx || !ctx.bundle)
3131
return html;
3232
html = html.replace(/(?=<!--)([\s\S]*?)-->/, '');
@@ -42,7 +42,7 @@ export function bundle(): Plugin {
4242
},
4343
},
4444
closeBundle: () => {
45-
if (existsSync(path.join(config.build!.outDir!, 'index.html'))) {
45+
if (fs.existsSync(path.join(config.build!.outDir!, 'index.html'))) {
4646
const targetDir = path.join(__dirname, '..', 'playwright-core', 'lib', 'vite', 'htmlReport');
4747
fs.mkdirSync(targetDir, { recursive: true });
4848
fs.copyFileSync(

packages/html-reporter/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "html-reporter",
33
"private": true,
44
"version": "0.0.0",
5+
"type": "module",
56
"scripts": {
67
"dev": "vite",
78
"build": "vite build && tsc",

packages/html-reporter/playwright.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { devices, defineConfig } from '@playwright/experimental-ct-react';
1818
import path from 'path';
19+
import url from 'url';
1920

2021
export default defineConfig({
2122
testDir: 'src',
@@ -28,7 +29,7 @@ export default defineConfig({
2829
ctViteConfig: {
2930
resolve: {
3031
alias: {
31-
'@web': path.resolve(__dirname, '../web/src'),
32+
'@web': path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '../web/src'),
3233
},
3334
}
3435
},

packages/html-reporter/tsconfig.node.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"compilerOptions": {
33
"composite": true,
44
"module": "esnext",
5-
"moduleResolution": "node"
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
7+
"allowSyntheticDefaultImports": true
68
},
7-
"include": ["vite.config.ts"]
9+
"include": ["playwright.config.ts", "vite.config.ts", "bundle.ts"]
810
}

packages/recorder/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "recorder",
33
"private": true,
44
"version": "0.0.0",
5+
"type": "module",
56
"scripts": {
67
"dev": "vite",
78
"build": "vite build && tsc",

packages/trace-viewer/bundle.js renamed to packages/trace-viewer/bundle.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
/**
18-
* @returns {import('vite').Plugin}
19-
*/
20-
export function bundle() {
21-
let config;
17+
import type { Plugin } from 'vite';
18+
19+
export function bundle(): Plugin {
2220
return {
2321
name: 'playwright-bundle',
24-
config(c) {
25-
config = c;
26-
},
2722
transformIndexHtml: {
28-
transform(html, ctx) {
23+
handler(html, ctx) {
2924
if (!ctx || !ctx.bundle)
3025
return html;
3126
// Workaround vite issue that we cannot exclude some scripts from preprocessing.
3227
return html.replace(/(?=<!--)([\s\S]*?)-->/, '').replace('<!-- <script src="stall.js"></script> -->', '<script src="stall.js"></script>');
3328
},
3429
},
35-
}
30+
};
3631
}

packages/trace-viewer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "trace-viewer",
33
"private": true,
44
"version": "0.0.0",
5+
"type": "module",
56
"scripts": {
67
"dev": "vite",
78
"build": "vite build && tsc",

packages/trace-viewer/tsconfig.node.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"compilerOptions": {
33
"composite": true,
44
"module": "esnext",
5-
"moduleResolution": "node"
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
7+
"allowSyntheticDefaultImports": true
68
},
7-
"include": ["vite.config.ts"]
9+
"include": ["vite.config.ts", "vite.sw.config.ts", "bundle.ts"]
810
}

packages/trace-viewer/vite.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
import { defineConfig } from 'vite';
1818
import react from '@vitejs/plugin-react';
19-
// @ts-ignore
2019
import { bundle } from './bundle';
21-
import * as path from 'path';
20+
import path from 'path';
2221

2322
// https://vitejs.dev/config/
2423
export default defineConfig({

0 commit comments

Comments
 (0)