cherry-pick(#17367): chore: rebuild components on new vite

This commit is contained in:
Pavel Feldman 2022-09-15 15:24:01 -07:00 committed by Andrey Lushnikov
parent e1681a3a89
commit 8a8c89bea8
3 changed files with 12 additions and 6 deletions

View file

@ -75,7 +75,7 @@ export function getClientLanguage(): { langName: string, langVersion: string } {
return { langName, langVersion };
}
export function getPlaywrightVersion(majorMinorOnly = false) {
export function getPlaywrightVersion(majorMinorOnly = false): string {
const packageJson = require('./../../package.json');
return majorMinorOnly ? packageJson.version.split('.').slice(0, 2).join('.') : packageJson.version;
}

View file

@ -26,9 +26,10 @@ import { collectComponentUsages, componentInfo } from '../tsxTransform';
import type { FullConfig } from '../types';
import { assert, calculateSha1 } from 'playwright-core/lib/utils';
import type { AddressInfo } from 'net';
import { getPlaywrightVersion } from 'playwright-core/lib/common/userAgent';
let stoppableServer: any;
const VERSION = 6;
const playwrightVersion = getPlaywrightVersion();
type CtConfig = {
ctPort?: number;
@ -65,14 +66,17 @@ export function createPlugin(
const registerSource = await fs.promises.readFile(registerSourceFile, 'utf-8');
const registerSourceHash = calculateSha1(registerSource);
const { version: viteVersion } = require('vite/package.json');
try {
buildInfo = JSON.parse(await fs.promises.readFile(buildInfoFile, 'utf-8')) as BuildInfo;
assert(buildInfo.version === VERSION);
assert(buildInfo.version === playwrightVersion);
assert(buildInfo.viteVersion === viteVersion);
assert(buildInfo.registerSourceHash === registerSourceHash);
buildExists = true;
} catch (e) {
buildInfo = {
version: VERSION,
version: playwrightVersion,
viteVersion,
registerSourceHash,
components: [],
tests: {},
@ -156,7 +160,8 @@ export function createPlugin(
}
type BuildInfo = {
version: number,
version: string,
viteVersion: string,
registerSourceHash: string,
sources: {
[key: string]: {

View file

@ -37,7 +37,8 @@ test('should work with the empty component list', async ({ runInlineTest }, test
expect(output.replace(/\\+/g, '/')).toContain('playwright/.cache/playwright/index.html');
const metainfo = JSON.parse(fs.readFileSync(testInfo.outputPath('playwright/.cache/metainfo.json'), 'utf-8'));
expect(metainfo.version).toEqual(expect.any(Number));
expect(metainfo.version).toEqual(require('playwright-core/package.json').version);
expect(metainfo.viteVersion).toEqual(require('vite/package.json').version);
expect(Object.entries(metainfo.tests)).toHaveLength(1);
expect(Object.entries(metainfo.sources)).toHaveLength(8);
});