New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

playwright

Package Overview
Dependencies
Maintainers
0
Versions
4845
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

playwright - npm Package Compare versions

Comparing version

to
1.52.0-alpha-2025-03-11

31

lib/common/config.js

@@ -102,3 +102,3 @@ "use strict";

version: require('../../package.json').version,
workers: 0,
workers: resolveWorkers(takeFirst(configCLIOverrides.debug ? 1 : undefined, configCLIOverrides.workers, userConfig.workers, '50%')),
webServer: null

@@ -110,13 +110,2 @@ };

this.config[configInternalSymbol] = this;
const workers = takeFirst(configCLIOverrides.debug ? 1 : undefined, configCLIOverrides.workers, userConfig.workers, '50%');
if (typeof workers === 'string') {
if (workers.endsWith('%')) {
const cpus = _os.default.cpus().length;
this.config.workers = Math.max(1, Math.floor(cpus * (parseInt(workers, 10) / 100)));
} else {
this.config.workers = parseWorkers(workers);
}
} else {
this.config.workers = workers;
}
const webServers = takeFirst(userConfig.webServer, null);

@@ -167,2 +156,3 @@ if (Array.isArray(webServers)) {

this.ignoreSnapshots = void 0;
this.workers = void 0;
this.id = '';

@@ -201,2 +191,4 @@ this.deps = [];

this.ignoreSnapshots = takeFirst(configCLIOverrides.ignoreSnapshots, projectConfig.ignoreSnapshots, config.ignoreSnapshots, false);
this.workers = projectConfig.workers ? resolveWorkers(projectConfig.workers) : undefined;
if (configCLIOverrides.debug && this.workers) this.workers = 1;
}

@@ -224,6 +216,13 @@ }

}
function parseWorkers(workers) {
const parsedWorkers = parseInt(workers, 10);
if (isNaN(parsedWorkers)) throw new Error(`Workers ${workers} must be a number or percentage.`);
return parsedWorkers;
function resolveWorkers(workers) {
if (typeof workers === 'string') {
if (workers.endsWith('%')) {
const cpus = _os.default.cpus().length;
return Math.max(1, Math.floor(cpus * (parseInt(workers, 10) / 100)));
}
const parsedWorkers = parseInt(workers, 10);
if (isNaN(parsedWorkers)) throw new Error(`Workers ${workers} must be a number or percentage.`);
return parsedWorkers;
}
return workers;
}

@@ -230,0 +229,0 @@ function resolveProjectDependencies(projects) {

@@ -210,5 +210,2 @@ "use strict";

}
if ('workers' in config && config.workers !== undefined) {
if (typeof config.workers === 'number' && config.workers <= 0) throw (0, _util.errorWithFile)(file, `config.workers must be a positive number`);else if (typeof config.workers === 'string' && !config.workers.endsWith('%')) throw (0, _util.errorWithFile)(file, `config.workers must be a number or percentage`);
}
if ('tsconfig' in config && config.tsconfig !== undefined) {

@@ -257,2 +254,5 @@ if (typeof config.tsconfig !== 'string') throw (0, _util.errorWithFile)(file, `config.tsconfig must be a string`);

}
if ('workers' in project && project.workers !== undefined) {
if (typeof project.workers === 'number' && project.workers <= 0) throw (0, _util.errorWithFile)(file, `${title}.workers must be a positive number`);else if (typeof project.workers === 'string' && !project.workers.endsWith('%')) throw (0, _util.errorWithFile)(file, `${title}.workers must be a number or percentage`);
}
}

@@ -259,0 +259,0 @@ function resolveConfigLocation(configFile) {

@@ -31,2 +31,3 @@ "use strict";

this._queue = [];
this._workerLimitPerProjectId = new Map();
this._queuedOrRunningHashCount = new Map();

@@ -43,19 +44,37 @@ this._finished = new _utils.ManualPromise();

this._failureTracker = failureTracker;
for (const project of config.projects) {
if (project.workers) this._workerLimitPerProjectId.set(project.id, project.workers);
}
}
async _scheduleJob() {
// 1. Find a job to run.
if (this._isStopped || !this._queue.length) return;
const job = this._queue[0];
// 1. Find a job/worker combination to run.
if (this._isStopped) return;
let jobIndex = -1;
let workerIndex = -1;
for (let index = 0; index < this._queue.length; index++) {
const job = this._queue[index];
// 2. Find a worker with the same hash, or just some free worker.
let index = this._workerSlots.findIndex(w => !w.busy && w.worker && w.worker.hash() === job.workerHash && !w.worker.didSendStop());
if (index === -1) index = this._workerSlots.findIndex(w => !w.busy);
// No workers available, bail out.
if (index === -1) return;
// 2.1 Respect the project worker limit.
const projectIdWorkerLimit = this._workerLimitPerProjectId.get(job.projectId);
if (projectIdWorkerLimit) {
const runningWorkersWithSameProjectId = this._workerSlots.filter(w => w.busy && w.worker && w.worker.projectId() === job.projectId).length;
if (runningWorkersWithSameProjectId >= projectIdWorkerLimit) continue;
}
// 2.2. Find a worker with the same hash, or just some free worker.
workerIndex = this._workerSlots.findIndex(w => !w.busy && w.worker && w.worker.hash() === job.workerHash && !w.worker.didSendStop());
if (workerIndex === -1) workerIndex = this._workerSlots.findIndex(w => !w.busy);
jobIndex = index;
break;
}
// 2.3. No workers available, bail out.
if (jobIndex === -1) return;
// 3. Claim both the job and the worker, run the job and release the worker.
this._queue.shift();
this._workerSlots[index].busy = true;
await this._startJobInWorker(index, job);
this._workerSlots[index].busy = false;
const job = this._queue[jobIndex];
this._queue.splice(jobIndex, 1);
this._workerSlots[workerIndex].busy = true;
await this._startJobInWorker(workerIndex, job);
this._workerSlots[workerIndex].busy = false;

@@ -62,0 +81,0 @@ // 4. Check the "finished" condition.

@@ -81,2 +81,5 @@ "use strict";

}
projectId() {
return this._params.projectId;
}
didFail() {

@@ -83,0 +86,0 @@ return this._didFail;

{
"name": "playwright",
"version": "1.52.0-alpha-2025-03-10",
"version": "1.52.0-alpha-2025-03-11",
"description": "A high-level API to automate web browsers",

@@ -59,3 +59,3 @@ "repository": {

"dependencies": {
"playwright-core": "1.52.0-alpha-2025-03-10"
"playwright-core": "1.52.0-alpha-2025-03-11"
},

@@ -62,0 +62,0 @@ "optionalDependencies": {

Sorry, the diff of this file is too big to display