|
f7eb47b…
|
lmata
|
1 |
"use strict"; |
|
f7eb47b…
|
lmata
|
2 |
var __create = Object.create; |
|
f7eb47b…
|
lmata
|
3 |
var __defProp = Object.defineProperty; |
|
f7eb47b…
|
lmata
|
4 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
|
f7eb47b…
|
lmata
|
5 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
|
f7eb47b…
|
lmata
|
6 |
var __getProtoOf = Object.getPrototypeOf; |
|
f7eb47b…
|
lmata
|
7 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
|
f7eb47b…
|
lmata
|
8 |
var __export = (target, all) => { |
|
f7eb47b…
|
lmata
|
9 |
for (var name in all) |
|
f7eb47b…
|
lmata
|
10 |
__defProp(target, name, { get: all[name], enumerable: true }); |
|
f7eb47b…
|
lmata
|
11 |
}; |
|
f7eb47b…
|
lmata
|
12 |
var __copyProps = (to, from, except, desc) => { |
|
f7eb47b…
|
lmata
|
13 |
if (from && typeof from === "object" || typeof from === "function") { |
|
f7eb47b…
|
lmata
|
14 |
for (let key of __getOwnPropNames(from)) |
|
f7eb47b…
|
lmata
|
15 |
if (!__hasOwnProp.call(to, key) && key !== except) |
|
f7eb47b…
|
lmata
|
16 |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
|
f7eb47b…
|
lmata
|
17 |
} |
|
f7eb47b…
|
lmata
|
18 |
return to; |
|
f7eb47b…
|
lmata
|
19 |
}; |
|
f7eb47b…
|
lmata
|
20 |
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
|
f7eb47b…
|
lmata
|
21 |
// If the importer is in node compatibility mode or this is not an ESM |
|
f7eb47b…
|
lmata
|
22 |
// file that has been converted to a CommonJS file using a Babel- |
|
f7eb47b…
|
lmata
|
23 |
// compatible transform (i.e. "__esModule" has not been set), then set |
|
f7eb47b…
|
lmata
|
24 |
// "default" to the CommonJS "module.exports" for node compatibility. |
|
f7eb47b…
|
lmata
|
25 |
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
|
f7eb47b…
|
lmata
|
26 |
mod |
|
f7eb47b…
|
lmata
|
27 |
)); |
|
f7eb47b…
|
lmata
|
28 |
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
|
f7eb47b…
|
lmata
|
29 |
var rebase_exports = {}; |
|
f7eb47b…
|
lmata
|
30 |
__export(rebase_exports, { |
|
f7eb47b…
|
lmata
|
31 |
addSuggestedRebaseline: () => addSuggestedRebaseline, |
|
f7eb47b…
|
lmata
|
32 |
applySuggestedRebaselines: () => applySuggestedRebaselines, |
|
f7eb47b…
|
lmata
|
33 |
clearSuggestedRebaselines: () => clearSuggestedRebaselines |
|
f7eb47b…
|
lmata
|
34 |
}); |
|
f7eb47b…
|
lmata
|
35 |
module.exports = __toCommonJS(rebase_exports); |
|
f7eb47b…
|
lmata
|
36 |
var import_fs = __toESM(require("fs")); |
|
f7eb47b…
|
lmata
|
37 |
var import_path = __toESM(require("path")); |
|
f7eb47b…
|
lmata
|
38 |
var import_utils = require("playwright-core/lib/utils"); |
|
f7eb47b…
|
lmata
|
39 |
var import_utils2 = require("playwright-core/lib/utils"); |
|
f7eb47b…
|
lmata
|
40 |
var import_utilsBundle = require("playwright-core/lib/utilsBundle"); |
|
f7eb47b…
|
lmata
|
41 |
var import_projectUtils = require("./projectUtils"); |
|
f7eb47b…
|
lmata
|
42 |
var import_babelBundle = require("../transform/babelBundle"); |
|
f7eb47b…
|
lmata
|
43 |
const t = import_babelBundle.types; |
|
f7eb47b…
|
lmata
|
44 |
const suggestedRebaselines = new import_utils.MultiMap(); |
|
f7eb47b…
|
lmata
|
45 |
function addSuggestedRebaseline(location, suggestedRebaseline) { |
|
f7eb47b…
|
lmata
|
46 |
suggestedRebaselines.set(location.file, { location, code: suggestedRebaseline }); |
|
f7eb47b…
|
lmata
|
47 |
} |
|
f7eb47b…
|
lmata
|
48 |
function clearSuggestedRebaselines() { |
|
f7eb47b…
|
lmata
|
49 |
suggestedRebaselines.clear(); |
|
f7eb47b…
|
lmata
|
50 |
} |
|
f7eb47b…
|
lmata
|
51 |
async function applySuggestedRebaselines(config, reporter) { |
|
f7eb47b…
|
lmata
|
52 |
if (config.config.updateSnapshots === "none") |
|
f7eb47b…
|
lmata
|
53 |
return; |
|
f7eb47b…
|
lmata
|
54 |
if (!suggestedRebaselines.size) |
|
f7eb47b…
|
lmata
|
55 |
return; |
|
f7eb47b…
|
lmata
|
56 |
const [project] = (0, import_projectUtils.filterProjects)(config.projects, config.cliProjectFilter); |
|
f7eb47b…
|
lmata
|
57 |
if (!project) |
|
f7eb47b…
|
lmata
|
58 |
return; |
|
f7eb47b…
|
lmata
|
59 |
const patches = []; |
|
f7eb47b…
|
lmata
|
60 |
const files = []; |
|
f7eb47b…
|
lmata
|
61 |
const gitCache = /* @__PURE__ */ new Map(); |
|
f7eb47b…
|
lmata
|
62 |
const patchFile = import_path.default.join(project.project.outputDir, "rebaselines.patch"); |
|
f7eb47b…
|
lmata
|
63 |
for (const fileName of [...suggestedRebaselines.keys()].sort()) { |
|
f7eb47b…
|
lmata
|
64 |
const source = await import_fs.default.promises.readFile(fileName, "utf8"); |
|
f7eb47b…
|
lmata
|
65 |
const lines = source.split("\n"); |
|
f7eb47b…
|
lmata
|
66 |
const replacements = suggestedRebaselines.get(fileName); |
|
f7eb47b…
|
lmata
|
67 |
const fileNode = (0, import_babelBundle.babelParse)(source, fileName, true); |
|
f7eb47b…
|
lmata
|
68 |
const ranges = []; |
|
f7eb47b…
|
lmata
|
69 |
(0, import_babelBundle.traverse)(fileNode, { |
|
f7eb47b…
|
lmata
|
70 |
CallExpression: (path2) => { |
|
f7eb47b…
|
lmata
|
71 |
const node = path2.node; |
|
f7eb47b…
|
lmata
|
72 |
if (node.arguments.length < 1) |
|
f7eb47b…
|
lmata
|
73 |
return; |
|
f7eb47b…
|
lmata
|
74 |
if (!t.isMemberExpression(node.callee)) |
|
f7eb47b…
|
lmata
|
75 |
return; |
|
f7eb47b…
|
lmata
|
76 |
const argument = node.arguments[0]; |
|
f7eb47b…
|
lmata
|
77 |
if (!t.isStringLiteral(argument) && !t.isTemplateLiteral(argument)) |
|
f7eb47b…
|
lmata
|
78 |
return; |
|
f7eb47b…
|
lmata
|
79 |
const prop = node.callee.property; |
|
f7eb47b…
|
lmata
|
80 |
if (!prop.loc || !argument.start || !argument.end) |
|
f7eb47b…
|
lmata
|
81 |
return; |
|
f7eb47b…
|
lmata
|
82 |
for (const replacement of replacements) { |
|
f7eb47b…
|
lmata
|
83 |
if (prop.loc.start.line !== replacement.location.line) |
|
f7eb47b…
|
lmata
|
84 |
continue; |
|
f7eb47b…
|
lmata
|
85 |
if (prop.loc.start.column + 1 !== replacement.location.column) |
|
f7eb47b…
|
lmata
|
86 |
continue; |
|
f7eb47b…
|
lmata
|
87 |
const indent = lines[prop.loc.start.line - 1].match(/^\s*/)[0]; |
|
f7eb47b…
|
lmata
|
88 |
const newText = replacement.code.replace(/\{indent\}/g, indent); |
|
f7eb47b…
|
lmata
|
89 |
ranges.push({ start: argument.start, end: argument.end, oldText: source.substring(argument.start, argument.end), newText }); |
|
f7eb47b…
|
lmata
|
90 |
break; |
|
f7eb47b…
|
lmata
|
91 |
} |
|
f7eb47b…
|
lmata
|
92 |
} |
|
f7eb47b…
|
lmata
|
93 |
}); |
|
f7eb47b…
|
lmata
|
94 |
ranges.sort((a, b) => b.start - a.start); |
|
f7eb47b…
|
lmata
|
95 |
let result = source; |
|
f7eb47b…
|
lmata
|
96 |
for (const range of ranges) |
|
f7eb47b…
|
lmata
|
97 |
result = result.substring(0, range.start) + range.newText + result.substring(range.end); |
|
f7eb47b…
|
lmata
|
98 |
const relativeName = import_path.default.relative(process.cwd(), fileName); |
|
f7eb47b…
|
lmata
|
99 |
files.push(relativeName); |
|
f7eb47b…
|
lmata
|
100 |
if (config.config.updateSourceMethod === "overwrite") { |
|
f7eb47b…
|
lmata
|
101 |
await import_fs.default.promises.writeFile(fileName, result); |
|
f7eb47b…
|
lmata
|
102 |
} else if (config.config.updateSourceMethod === "3way") { |
|
f7eb47b…
|
lmata
|
103 |
await import_fs.default.promises.writeFile(fileName, applyPatchWithConflictMarkers(source, result)); |
|
f7eb47b…
|
lmata
|
104 |
} else { |
|
f7eb47b…
|
lmata
|
105 |
const gitFolder = findGitRoot(import_path.default.dirname(fileName), gitCache); |
|
f7eb47b…
|
lmata
|
106 |
const relativeToGit = import_path.default.relative(gitFolder || process.cwd(), fileName); |
|
f7eb47b…
|
lmata
|
107 |
patches.push(createPatch(relativeToGit, source, result)); |
|
f7eb47b…
|
lmata
|
108 |
} |
|
f7eb47b…
|
lmata
|
109 |
} |
|
f7eb47b…
|
lmata
|
110 |
const fileList = files.map((file) => " " + import_utils2.colors.dim(file)).join("\n"); |
|
f7eb47b…
|
lmata
|
111 |
reporter.onStdErr(` |
|
f7eb47b…
|
lmata
|
112 |
New baselines created for: |
|
f7eb47b…
|
lmata
|
113 |
|
|
f7eb47b…
|
lmata
|
114 |
${fileList} |
|
f7eb47b…
|
lmata
|
115 |
`); |
|
f7eb47b…
|
lmata
|
116 |
if (config.config.updateSourceMethod === "patch") { |
|
f7eb47b…
|
lmata
|
117 |
await import_fs.default.promises.mkdir(import_path.default.dirname(patchFile), { recursive: true }); |
|
f7eb47b…
|
lmata
|
118 |
await import_fs.default.promises.writeFile(patchFile, patches.join("\n")); |
|
f7eb47b…
|
lmata
|
119 |
reporter.onStdErr(` |
|
f7eb47b…
|
lmata
|
120 |
` + import_utils2.colors.cyan("git apply " + import_path.default.relative(process.cwd(), patchFile)) + "\n"); |
|
f7eb47b…
|
lmata
|
121 |
} |
|
f7eb47b…
|
lmata
|
122 |
} |
|
f7eb47b…
|
lmata
|
123 |
function createPatch(fileName, before, after) { |
|
f7eb47b…
|
lmata
|
124 |
const file = fileName.replace(/\\/g, "/"); |
|
f7eb47b…
|
lmata
|
125 |
const text = import_utilsBundle.diff.createPatch(file, before, after, void 0, void 0, { context: 3 }); |
|
f7eb47b…
|
lmata
|
126 |
return [ |
|
f7eb47b…
|
lmata
|
127 |
"diff --git a/" + file + " b/" + file, |
|
f7eb47b…
|
lmata
|
128 |
"--- a/" + file, |
|
f7eb47b…
|
lmata
|
129 |
"+++ b/" + file, |
|
f7eb47b…
|
lmata
|
130 |
...text.split("\n").slice(4) |
|
f7eb47b…
|
lmata
|
131 |
].join("\n"); |
|
f7eb47b…
|
lmata
|
132 |
} |
|
f7eb47b…
|
lmata
|
133 |
function findGitRoot(dir, cache) { |
|
f7eb47b…
|
lmata
|
134 |
const result = cache.get(dir); |
|
f7eb47b…
|
lmata
|
135 |
if (result !== void 0) |
|
f7eb47b…
|
lmata
|
136 |
return result; |
|
f7eb47b…
|
lmata
|
137 |
const gitPath = import_path.default.join(dir, ".git"); |
|
f7eb47b…
|
lmata
|
138 |
if (import_fs.default.existsSync(gitPath) && import_fs.default.lstatSync(gitPath).isDirectory()) { |
|
f7eb47b…
|
lmata
|
139 |
cache.set(dir, dir); |
|
f7eb47b…
|
lmata
|
140 |
return dir; |
|
f7eb47b…
|
lmata
|
141 |
} |
|
f7eb47b…
|
lmata
|
142 |
const parentDir = import_path.default.dirname(dir); |
|
f7eb47b…
|
lmata
|
143 |
if (dir === parentDir) { |
|
f7eb47b…
|
lmata
|
144 |
cache.set(dir, null); |
|
f7eb47b…
|
lmata
|
145 |
return null; |
|
f7eb47b…
|
lmata
|
146 |
} |
|
f7eb47b…
|
lmata
|
147 |
const parentResult = findGitRoot(parentDir, cache); |
|
f7eb47b…
|
lmata
|
148 |
cache.set(dir, parentResult); |
|
f7eb47b…
|
lmata
|
149 |
return parentResult; |
|
f7eb47b…
|
lmata
|
150 |
} |
|
f7eb47b…
|
lmata
|
151 |
function applyPatchWithConflictMarkers(oldText, newText) { |
|
f7eb47b…
|
lmata
|
152 |
const diffResult = import_utilsBundle.diff.diffLines(oldText, newText); |
|
f7eb47b…
|
lmata
|
153 |
let result = ""; |
|
f7eb47b…
|
lmata
|
154 |
let conflict = false; |
|
f7eb47b…
|
lmata
|
155 |
diffResult.forEach((part) => { |
|
f7eb47b…
|
lmata
|
156 |
if (part.added) { |
|
f7eb47b…
|
lmata
|
157 |
if (conflict) { |
|
f7eb47b…
|
lmata
|
158 |
result += part.value; |
|
f7eb47b…
|
lmata
|
159 |
result += ">>>>>>> SNAPSHOT\n"; |
|
f7eb47b…
|
lmata
|
160 |
conflict = false; |
|
f7eb47b…
|
lmata
|
161 |
} else { |
|
f7eb47b…
|
lmata
|
162 |
result += "<<<<<<< HEAD\n"; |
|
f7eb47b…
|
lmata
|
163 |
result += part.value; |
|
f7eb47b…
|
lmata
|
164 |
result += "=======\n"; |
|
f7eb47b…
|
lmata
|
165 |
conflict = true; |
|
f7eb47b…
|
lmata
|
166 |
} |
|
f7eb47b…
|
lmata
|
167 |
} else if (part.removed) { |
|
f7eb47b…
|
lmata
|
168 |
result += "<<<<<<< HEAD\n"; |
|
f7eb47b…
|
lmata
|
169 |
result += part.value; |
|
f7eb47b…
|
lmata
|
170 |
result += "=======\n"; |
|
f7eb47b…
|
lmata
|
171 |
conflict = true; |
|
f7eb47b…
|
lmata
|
172 |
} else { |
|
f7eb47b…
|
lmata
|
173 |
if (conflict) { |
|
f7eb47b…
|
lmata
|
174 |
result += ">>>>>>> SNAPSHOT\n"; |
|
f7eb47b…
|
lmata
|
175 |
conflict = false; |
|
f7eb47b…
|
lmata
|
176 |
} |
|
f7eb47b…
|
lmata
|
177 |
result += part.value; |
|
f7eb47b…
|
lmata
|
178 |
} |
|
f7eb47b…
|
lmata
|
179 |
}); |
|
f7eb47b…
|
lmata
|
180 |
if (conflict) |
|
f7eb47b…
|
lmata
|
181 |
result += ">>>>>>> SNAPSHOT\n"; |
|
f7eb47b…
|
lmata
|
182 |
return result; |
|
f7eb47b…
|
lmata
|
183 |
} |
|
f7eb47b…
|
lmata
|
184 |
// Annotate the CommonJS export names for ESM import in node: |
|
f7eb47b…
|
lmata
|
185 |
0 && (module.exports = { |
|
f7eb47b…
|
lmata
|
186 |
addSuggestedRebaseline, |
|
f7eb47b…
|
lmata
|
187 |
applySuggestedRebaselines, |
|
f7eb47b…
|
lmata
|
188 |
clearSuggestedRebaselines |
|
f7eb47b…
|
lmata
|
189 |
}); |