mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	chore: commit generated types to the repository (#4826)
Also check them during `npm run lint` and regenerate during `npm run watch`.
This commit is contained in:
		
							parent
							
								
									277d255fc3
								
							
						
					
					
						commit
						9dd982c508
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -12,7 +12,6 @@ yarn.lock
 | 
				
			|||||||
/node6
 | 
					/node6
 | 
				
			||||||
/src/generated/*
 | 
					/src/generated/*
 | 
				
			||||||
lib/
 | 
					lib/
 | 
				
			||||||
/types/*
 | 
					 | 
				
			||||||
jest-report.json
 | 
					jest-report.json
 | 
				
			||||||
drivers/
 | 
					drivers/
 | 
				
			||||||
/docs/api.json
 | 
					/docs/api.json
 | 
				
			||||||
 | 
				
			|||||||
@ -19,13 +19,12 @@
 | 
				
			|||||||
    "tsc-installer": "tsc -p ./src/install/tsconfig.json",
 | 
					    "tsc-installer": "tsc -p ./src/install/tsconfig.json",
 | 
				
			||||||
    "doc": "node utils/doclint/cli.js",
 | 
					    "doc": "node utils/doclint/cli.js",
 | 
				
			||||||
    "test-infra": "folio utils/doclint/check_public_api/test/test.js && folio utils/doclint/preprocessor/test.js",
 | 
					    "test-infra": "folio utils/doclint/check_public_api/test/test.js && folio utils/doclint/preprocessor/test.js",
 | 
				
			||||||
    "lint": "npm run eslint && npm run tsc && npm run doc && npm run check-deps && npm run generate-channels && npm run test-types && npm run test-infra",
 | 
					    "lint": "npm run eslint && npm run tsc && npm run doc && npm run check-deps && npm run generate-channels && node utils/generate_types/ --check-clean && npm run test-types && npm run test-infra",
 | 
				
			||||||
    "clean": "rimraf lib && rimraf types",
 | 
					    "clean": "rimraf lib && rimraf types",
 | 
				
			||||||
    "prepare": "node install-from-github.js",
 | 
					    "prepare": "node install-from-github.js",
 | 
				
			||||||
    "build": "node utils/runWebpack.js --mode='development' && tsc -p . && npm run generate-types && npm run generate-api-json",
 | 
					    "build": "node utils/runWebpack.js --mode='development' && tsc -p . && npm run generate-api-json",
 | 
				
			||||||
    "watch": "node utils/watch.js",
 | 
					    "watch": "node utils/watch.js",
 | 
				
			||||||
    "test-types": "npm run generate-types && npx -p typescript@3.7.5 tsc -p utils/generate_types/test/tsconfig.json && npm run typecheck-tests",
 | 
					    "test-types": "node utils/generate_types/ && npx -p typescript@3.7.5 tsc -p utils/generate_types/test/tsconfig.json && npm run typecheck-tests",
 | 
				
			||||||
    "generate-types": "node utils/generate_types/",
 | 
					 | 
				
			||||||
    "generate-channels": "node utils/generate_channels.js",
 | 
					    "generate-channels": "node utils/generate_channels.js",
 | 
				
			||||||
    "generate-api-json": "node utils/doclint/generateApiJson.js > docs/api.json",
 | 
					    "generate-api-json": "node utils/doclint/generateApiJson.js > docs/api.json",
 | 
				
			||||||
    "typecheck-tests": "tsc -p ./test/",
 | 
					    "typecheck-tests": "tsc -p ./test/",
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										16834
									
								
								types/protocol.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										16834
									
								
								types/protocol.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										101
									
								
								types/trace.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								types/trace.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,101 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Copyright (c) Microsoft Corporation.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
				
			||||||
 | 
					 * you may not use this file except in compliance with the License.
 | 
				
			||||||
 | 
					 * You may obtain a copy of the License at
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Unless required by applicable law or agreed to in writing, software
 | 
				
			||||||
 | 
					 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
				
			||||||
 | 
					 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
				
			||||||
 | 
					 * See the License for the specific language governing permissions and
 | 
				
			||||||
 | 
					 * limitations under the License.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type ContextCreatedTraceEvent = {
 | 
				
			||||||
 | 
					  type: 'context-created',
 | 
				
			||||||
 | 
					  browserName: string,
 | 
				
			||||||
 | 
					  contextId: string,
 | 
				
			||||||
 | 
					  deviceScaleFactor: number,
 | 
				
			||||||
 | 
					  isMobile: boolean,
 | 
				
			||||||
 | 
					  viewportSize?: { width: number, height: number },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type ContextDestroyedTraceEvent = {
 | 
				
			||||||
 | 
					  type: 'context-destroyed',
 | 
				
			||||||
 | 
					  contextId: string,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type NetworkResourceTraceEvent = {
 | 
				
			||||||
 | 
					  type: 'resource',
 | 
				
			||||||
 | 
					  contextId: string,
 | 
				
			||||||
 | 
					  pageId: string,
 | 
				
			||||||
 | 
					  frameId: string,
 | 
				
			||||||
 | 
					  url: string,
 | 
				
			||||||
 | 
					  contentType: string,
 | 
				
			||||||
 | 
					  responseHeaders: { name: string, value: string }[],
 | 
				
			||||||
 | 
					  sha1: string,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type PageCreatedTraceEvent = {
 | 
				
			||||||
 | 
					  type: 'page-created',
 | 
				
			||||||
 | 
					  contextId: string,
 | 
				
			||||||
 | 
					  pageId: string,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type PageDestroyedTraceEvent = {
 | 
				
			||||||
 | 
					  type: 'page-destroyed',
 | 
				
			||||||
 | 
					  contextId: string,
 | 
				
			||||||
 | 
					  pageId: string,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type PageVideoTraceEvent = {
 | 
				
			||||||
 | 
					  type: 'page-video',
 | 
				
			||||||
 | 
					  contextId: string,
 | 
				
			||||||
 | 
					  pageId: string,
 | 
				
			||||||
 | 
					  fileName: string,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type ActionTraceEvent = {
 | 
				
			||||||
 | 
					  type: 'action',
 | 
				
			||||||
 | 
					  contextId: string,
 | 
				
			||||||
 | 
					  action: string,
 | 
				
			||||||
 | 
					  pageId?: string,
 | 
				
			||||||
 | 
					  selector?: string,
 | 
				
			||||||
 | 
					  label?: string,
 | 
				
			||||||
 | 
					  value?: string,
 | 
				
			||||||
 | 
					  startTime?: number,
 | 
				
			||||||
 | 
					  endTime?: number,
 | 
				
			||||||
 | 
					  logs?: string[],
 | 
				
			||||||
 | 
					  snapshot?: {
 | 
				
			||||||
 | 
					    sha1: string,
 | 
				
			||||||
 | 
					    duration: number,
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  stack?: string,
 | 
				
			||||||
 | 
					  error?: string,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type TraceEvent =
 | 
				
			||||||
 | 
					    ContextCreatedTraceEvent |
 | 
				
			||||||
 | 
					    ContextDestroyedTraceEvent |
 | 
				
			||||||
 | 
					    PageCreatedTraceEvent |
 | 
				
			||||||
 | 
					    PageDestroyedTraceEvent |
 | 
				
			||||||
 | 
					    PageVideoTraceEvent |
 | 
				
			||||||
 | 
					    NetworkResourceTraceEvent |
 | 
				
			||||||
 | 
					    ActionTraceEvent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type FrameSnapshot = {
 | 
				
			||||||
 | 
					  frameId: string,
 | 
				
			||||||
 | 
					  url: string,
 | 
				
			||||||
 | 
					  html: string,
 | 
				
			||||||
 | 
					  resourceOverrides: { url: string, sha1: string }[],
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type PageSnapshot = {
 | 
				
			||||||
 | 
					  viewportSize?: { width: number, height: number },
 | 
				
			||||||
 | 
					  // First frame is the main frame.
 | 
				
			||||||
 | 
					  frames: FrameSnapshot[],
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										7866
									
								
								types/types.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7866
									
								
								types/types.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -99,7 +99,7 @@ function checkSources(sources) {
 | 
				
			|||||||
          parent = parent.parent;
 | 
					          parent = parent.parent;
 | 
				
			||||||
        className = path.basename(parent.fileName,  '.js');
 | 
					        className = path.basename(parent.fileName,  '.js');
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      if (className && !excludeClasses.has(className) && !fileName.endsWith('/protocol.ts')) {
 | 
					      if (className && !excludeClasses.has(className) && !fileName.endsWith('/protocol.ts') && !fileName.endsWith('/protocol.d.ts') && !fileName.endsWith('/types.d.ts')) {
 | 
				
			||||||
        excludeClasses.add(className);
 | 
					        excludeClasses.add(className);
 | 
				
			||||||
        classes.push(serializeClass(className, symbol, node));
 | 
					        classes.push(serializeClass(className, symbol, node));
 | 
				
			||||||
        inheritance.set(className, parentClasses(node));
 | 
					        inheritance.set(className, parentClasses(node));
 | 
				
			||||||
 | 
				
			|||||||
@ -27,12 +27,14 @@ const objectDefinitions = [];
 | 
				
			|||||||
const handledMethods = new Set();
 | 
					const handledMethods = new Set();
 | 
				
			||||||
/** @type {Documentation} */
 | 
					/** @type {Documentation} */
 | 
				
			||||||
let documentation;
 | 
					let documentation;
 | 
				
			||||||
 | 
					let hadChanges = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(async function() {
 | 
					(async function() {
 | 
				
			||||||
  const typesDir = path.join(PROJECT_DIR, 'types');
 | 
					  const typesDir = path.join(PROJECT_DIR, 'types');
 | 
				
			||||||
  if (!fs.existsSync(typesDir))
 | 
					  if (!fs.existsSync(typesDir))
 | 
				
			||||||
    fs.mkdirSync(typesDir)
 | 
					    fs.mkdirSync(typesDir)
 | 
				
			||||||
  fs.writeFileSync(path.join(typesDir, 'protocol.d.ts'), fs.readFileSync(path.join(PROJECT_DIR, 'src', 'server', 'chromium', 'protocol.ts')), 'utf8');
 | 
					  writeFile(path.join(typesDir, 'protocol.d.ts'), fs.readFileSync(path.join(PROJECT_DIR, 'src', 'server', 'chromium', 'protocol.ts'), 'utf8'));
 | 
				
			||||||
  fs.writeFileSync(path.join(typesDir, 'trace.d.ts'), fs.readFileSync(path.join(PROJECT_DIR, 'src', 'trace', 'traceTypes.ts')), 'utf8');
 | 
					  writeFile(path.join(typesDir, 'trace.d.ts'), fs.readFileSync(path.join(PROJECT_DIR, 'src', 'trace', 'traceTypes.ts'), 'utf8'));
 | 
				
			||||||
  const browser = await chromium.launch();
 | 
					  const browser = await chromium.launch();
 | 
				
			||||||
  const page = await browser.newPage();
 | 
					  const page = await browser.newPage();
 | 
				
			||||||
  const api = await Source.readFile(path.join(PROJECT_DIR, 'docs', 'api.md'));
 | 
					  const api = await Source.readFile(path.join(PROJECT_DIR, 'docs', 'api.md'));
 | 
				
			||||||
@ -75,12 +77,22 @@ ${generateDevicesTypes()}
 | 
				
			|||||||
`;
 | 
					`;
 | 
				
			||||||
  for (const [key, value] of Object.entries(exported))
 | 
					  for (const [key, value] of Object.entries(exported))
 | 
				
			||||||
    output = output.replace(new RegExp('\\b' + key + '\\b', 'g'), value);
 | 
					    output = output.replace(new RegExp('\\b' + key + '\\b', 'g'), value);
 | 
				
			||||||
  fs.writeFileSync(path.join(typesDir, 'types.d.ts'), output, 'utf8');
 | 
					  writeFile(path.join(typesDir, 'types.d.ts'), output);
 | 
				
			||||||
 | 
					  process.exit(hadChanges && process.argv.includes('--check-clean') ? 1 : 0);
 | 
				
			||||||
})().catch(e => {
 | 
					})().catch(e => {
 | 
				
			||||||
  console.error(e);
 | 
					  console.error(e);
 | 
				
			||||||
  process.exit(1);
 | 
					  process.exit(1);
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function writeFile(filePath, content) {
 | 
				
			||||||
 | 
					  const existing = fs.readFileSync(filePath, 'utf8');
 | 
				
			||||||
 | 
					  if (existing === content)
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  hadChanges = true;
 | 
				
			||||||
 | 
					  console.error(`Writing //${path.relative(PROJECT_DIR, filePath)}`);
 | 
				
			||||||
 | 
					  fs.writeFileSync(filePath, content, 'utf8');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @param {string} overriddes
 | 
					 * @param {string} overriddes
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
				
			|||||||
@ -25,7 +25,13 @@ const spawns = [
 | 
				
			|||||||
process.on('exit', () => spawns.forEach(s => s.kill()));
 | 
					process.on('exit', () => spawns.forEach(s => s.kill()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
runOnChanges(['src/protocol/protocol.yml'], 'utils/generate_channels.js');
 | 
					runOnChanges(['src/protocol/protocol.yml'], 'utils/generate_channels.js');
 | 
				
			||||||
runOnChanges(['docs/api.md', 'utils/generate_types/overrides.d.ts', 'utils/generate_types/exported.json'], 'utils/generate_types/index.js');
 | 
					runOnChanges([
 | 
				
			||||||
 | 
					  'docs/api.md',
 | 
				
			||||||
 | 
					  'utils/generate_types/overrides.d.ts',
 | 
				
			||||||
 | 
					  'utils/generate_types/exported.json',
 | 
				
			||||||
 | 
					  'src/server/chromium/protocol.ts',
 | 
				
			||||||
 | 
					  'src/trace/traceTypes.ts',
 | 
				
			||||||
 | 
					], 'utils/generate_types/index.js');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @param {string[][]} paths
 | 
					 * @param {string[][]} paths
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user