build(deps): bump playwright from 1.49.1 to 1.50.1

This commit is contained in:
2025-02-21 17:22:03 -07:00
parent 79c9869e65
commit dc6d9c68a9
174 changed files with 3064 additions and 1955 deletions

View File

@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
});
exports.addSuggestedRebaseline = addSuggestedRebaseline;
exports.applySuggestedRebaselines = applySuggestedRebaselines;
exports.clearSuggestedRebaselines = clearSuggestedRebaselines;
var _path = _interopRequireDefault(require("path"));
var _fs = _interopRequireDefault(require("fs"));
var _babelBundle = require("../transform/babelBundle");
@@ -36,13 +37,18 @@ function addSuggestedRebaseline(location, suggestedRebaseline) {
code: suggestedRebaseline
});
}
function clearSuggestedRebaselines() {
suggestedRebaselines.clear();
}
async function applySuggestedRebaselines(config, reporter) {
if (config.config.updateSnapshots !== 'all' && config.config.updateSnapshots !== 'missing') return;
if (config.config.updateSnapshots === 'none') return;
if (!suggestedRebaselines.size) return;
const [project] = (0, _projectUtils.filterProjects)(config.projects, config.cliProjectFilter);
if (!project) return;
const patches = [];
const files = [];
const gitCache = new Map();
const patchFile = _path.default.join(project.project.outputDir, 'rebaselines.patch');
for (const fileName of [...suggestedRebaselines.keys()].sort()) {
const source = await _fs.default.promises.readFile(fileName, 'utf8');
const lines = source.split('\n');
@@ -52,21 +58,24 @@ async function applySuggestedRebaselines(config, reporter) {
(0, _babelBundle.traverse)(fileNode, {
CallExpression: path => {
const node = path.node;
if (node.arguments.length !== 1) return;
if (node.arguments.length < 1) return;
if (!t.isMemberExpression(node.callee)) return;
const argument = node.arguments[0];
if (!t.isStringLiteral(argument) && !t.isTemplateLiteral(argument)) return;
const matcher = node.callee.property;
const prop = node.callee.property;
if (!prop.loc || !argument.start || !argument.end) return;
// Replacements are anchored by the location of the call expression.
// However, replacement text is meant to only replace the first argument.
for (const replacement of replacements) {
// In Babel, rows are 1-based, columns are 0-based.
if (matcher.loc.start.line !== replacement.location.line) continue;
if (matcher.loc.start.column + 1 !== replacement.location.column) continue;
const indent = lines[matcher.loc.start.line - 1].match(/^\s*/)[0];
if (prop.loc.start.line !== replacement.location.line) continue;
if (prop.loc.start.column + 1 !== replacement.location.column) continue;
const indent = lines[prop.loc.start.line - 1].match(/^\s*/)[0];
const newText = replacement.code.replace(/\{indent\}/g, indent);
ranges.push({
start: matcher.start,
end: node.end,
oldText: source.substring(matcher.start, node.end),
start: argument.start,
end: argument.end,
oldText: source.substring(argument.start, argument.end),
newText
});
// We can have multiple, hopefully equal, replacements for the same location,
@@ -81,15 +90,25 @@ async function applySuggestedRebaselines(config, reporter) {
for (const range of ranges) result = result.substring(0, range.start) + range.newText + result.substring(range.end);
const relativeName = _path.default.relative(process.cwd(), fileName);
files.push(relativeName);
patches.push(createPatch(relativeName, source, result));
if (config.config.updateSourceMethod === 'overwrite') {
await _fs.default.promises.writeFile(fileName, result);
} else if (config.config.updateSourceMethod === '3way') {
await _fs.default.promises.writeFile(fileName, applyPatchWithConflictMarkers(source, result));
} else {
const gitFolder = findGitRoot(_path.default.dirname(fileName), gitCache);
const relativeToGit = _path.default.relative(gitFolder || process.cwd(), fileName);
patches.push(createPatch(relativeToGit, source, result));
}
}
const patchFile = _path.default.join(project.project.outputDir, 'rebaselines.patch');
await _fs.default.promises.mkdir(_path.default.dirname(patchFile), {
recursive: true
});
await _fs.default.promises.writeFile(patchFile, patches.join('\n'));
const fileList = files.map(file => ' ' + _utilsBundle.colors.dim(file)).join('\n');
reporter.onStdErr(`\nNew baselines created for:\n\n${fileList}\n\n ` + _utilsBundle.colors.cyan('git apply ' + _path.default.relative(process.cwd(), patchFile)) + '\n');
reporter.onStdErr(`\nNew baselines created for:\n\n${fileList}\n`);
if (config.config.updateSourceMethod === 'patch') {
await _fs.default.promises.mkdir(_path.default.dirname(patchFile), {
recursive: true
});
await _fs.default.promises.writeFile(patchFile, patches.join('\n'));
reporter.onStdErr(`\n ` + _utilsBundle.colors.cyan('git apply ' + _path.default.relative(process.cwd(), patchFile)) + '\n');
}
}
function createPatch(fileName, before, after) {
const file = fileName.replace(/\\/g, '/');
@@ -97,4 +116,53 @@ function createPatch(fileName, before, after) {
context: 3
});
return ['diff --git a/' + file + ' b/' + file, '--- a/' + file, '+++ b/' + file, ...text.split('\n').slice(4)].join('\n');
}
function findGitRoot(dir, cache) {
const result = cache.get(dir);
if (result !== undefined) return result;
const gitPath = _path.default.join(dir, '.git');
if (_fs.default.existsSync(gitPath) && _fs.default.lstatSync(gitPath).isDirectory()) {
cache.set(dir, dir);
return dir;
}
const parentDir = _path.default.dirname(dir);
if (dir === parentDir) {
cache.set(dir, null);
return null;
}
const parentResult = findGitRoot(parentDir, cache);
cache.set(dir, parentResult);
return parentResult;
}
function applyPatchWithConflictMarkers(oldText, newText) {
const diffResult = _utilsBundle.diff.diffLines(oldText, newText);
let result = '';
let conflict = false;
diffResult.forEach(part => {
if (part.added) {
if (conflict) {
result += part.value;
result += '>>>>>>> SNAPSHOT\n';
conflict = false;
} else {
result += '<<<<<<< HEAD\n';
result += part.value;
result += '=======\n';
conflict = true;
}
} else if (part.removed) {
result += '<<<<<<< HEAD\n';
result += part.value;
result += '=======\n';
conflict = true;
} else {
if (conflict) {
result += '>>>>>>> SNAPSHOT\n';
conflict = false;
}
result += part.value;
}
});
if (conflict) result += '>>>>>>> SNAPSHOT\n';
return result;
}