|
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 util_exports = {}; |
|
f7eb47b…
|
lmata
|
30 |
__export(util_exports, { |
|
f7eb47b…
|
lmata
|
31 |
addSuffixToFilePath: () => addSuffixToFilePath, |
|
f7eb47b…
|
lmata
|
32 |
ansiRegex: () => import_utils2.ansiRegex, |
|
f7eb47b…
|
lmata
|
33 |
createFileFiltersFromArguments: () => createFileFiltersFromArguments, |
|
f7eb47b…
|
lmata
|
34 |
createFileMatcher: () => createFileMatcher, |
|
f7eb47b…
|
lmata
|
35 |
createFileMatcherFromArguments: () => createFileMatcherFromArguments, |
|
f7eb47b…
|
lmata
|
36 |
createTitleMatcher: () => createTitleMatcher, |
|
f7eb47b…
|
lmata
|
37 |
debugTest: () => debugTest, |
|
f7eb47b…
|
lmata
|
38 |
errorWithFile: () => errorWithFile, |
|
f7eb47b…
|
lmata
|
39 |
expectTypes: () => expectTypes, |
|
f7eb47b…
|
lmata
|
40 |
fileExistsAsync: () => fileExistsAsync, |
|
f7eb47b…
|
lmata
|
41 |
fileIsModule: () => fileIsModule, |
|
f7eb47b…
|
lmata
|
42 |
filterStackFile: () => filterStackFile, |
|
f7eb47b…
|
lmata
|
43 |
filterStackTrace: () => filterStackTrace, |
|
f7eb47b…
|
lmata
|
44 |
filteredStackTrace: () => filteredStackTrace, |
|
f7eb47b…
|
lmata
|
45 |
forceRegExp: () => forceRegExp, |
|
f7eb47b…
|
lmata
|
46 |
formatLocation: () => formatLocation, |
|
f7eb47b…
|
lmata
|
47 |
getContainedPath: () => getContainedPath, |
|
f7eb47b…
|
lmata
|
48 |
getPackageJsonPath: () => getPackageJsonPath, |
|
f7eb47b…
|
lmata
|
49 |
mergeObjects: () => mergeObjects, |
|
f7eb47b…
|
lmata
|
50 |
normalizeAndSaveAttachment: () => normalizeAndSaveAttachment, |
|
f7eb47b…
|
lmata
|
51 |
parseLocationArg: () => parseLocationArg, |
|
f7eb47b…
|
lmata
|
52 |
relativeFilePath: () => relativeFilePath, |
|
f7eb47b…
|
lmata
|
53 |
removeDirAndLogToConsole: () => removeDirAndLogToConsole, |
|
f7eb47b…
|
lmata
|
54 |
resolveImportSpecifierAfterMapping: () => resolveImportSpecifierAfterMapping, |
|
f7eb47b…
|
lmata
|
55 |
resolveReporterOutputPath: () => resolveReporterOutputPath, |
|
f7eb47b…
|
lmata
|
56 |
sanitizeFilePathBeforeExtension: () => sanitizeFilePathBeforeExtension, |
|
f7eb47b…
|
lmata
|
57 |
serializeError: () => serializeError, |
|
f7eb47b…
|
lmata
|
58 |
stripAnsiEscapes: () => import_utils2.stripAnsiEscapes, |
|
f7eb47b…
|
lmata
|
59 |
trimLongString: () => trimLongString, |
|
f7eb47b…
|
lmata
|
60 |
windowsFilesystemFriendlyLength: () => windowsFilesystemFriendlyLength |
|
f7eb47b…
|
lmata
|
61 |
}); |
|
f7eb47b…
|
lmata
|
62 |
module.exports = __toCommonJS(util_exports); |
|
f7eb47b…
|
lmata
|
63 |
var import_fs = __toESM(require("fs")); |
|
f7eb47b…
|
lmata
|
64 |
var import_path = __toESM(require("path")); |
|
f7eb47b…
|
lmata
|
65 |
var import_url = __toESM(require("url")); |
|
f7eb47b…
|
lmata
|
66 |
var import_util = __toESM(require("util")); |
|
f7eb47b…
|
lmata
|
67 |
var import_utils = require("playwright-core/lib/utils"); |
|
f7eb47b…
|
lmata
|
68 |
var import_utilsBundle = require("playwright-core/lib/utilsBundle"); |
|
f7eb47b…
|
lmata
|
69 |
var import_utils2 = require("playwright-core/lib/utils"); |
|
f7eb47b…
|
lmata
|
70 |
const PLAYWRIGHT_TEST_PATH = import_path.default.join(__dirname, ".."); |
|
f7eb47b…
|
lmata
|
71 |
const PLAYWRIGHT_CORE_PATH = import_path.default.dirname(require.resolve("playwright-core/package.json")); |
|
f7eb47b…
|
lmata
|
72 |
function filterStackTrace(e) { |
|
f7eb47b…
|
lmata
|
73 |
const name = e.name ? e.name + ": " : ""; |
|
f7eb47b…
|
lmata
|
74 |
const cause = e.cause instanceof Error ? filterStackTrace(e.cause) : void 0; |
|
f7eb47b…
|
lmata
|
75 |
if (process.env.PWDEBUGIMPL) |
|
f7eb47b…
|
lmata
|
76 |
return { message: name + e.message, stack: e.stack || "", cause }; |
|
f7eb47b…
|
lmata
|
77 |
const stackLines = (0, import_utils.stringifyStackFrames)(filteredStackTrace(e.stack?.split("\n") || [])); |
|
f7eb47b…
|
lmata
|
78 |
return { |
|
f7eb47b…
|
lmata
|
79 |
message: name + e.message, |
|
f7eb47b…
|
lmata
|
80 |
stack: `${name}${e.message}${stackLines.map((line) => "\n" + line).join("")}`, |
|
f7eb47b…
|
lmata
|
81 |
cause |
|
f7eb47b…
|
lmata
|
82 |
}; |
|
f7eb47b…
|
lmata
|
83 |
} |
|
f7eb47b…
|
lmata
|
84 |
function filterStackFile(file) { |
|
f7eb47b…
|
lmata
|
85 |
if (!process.env.PWDEBUGIMPL && file.startsWith(PLAYWRIGHT_TEST_PATH)) |
|
f7eb47b…
|
lmata
|
86 |
return false; |
|
f7eb47b…
|
lmata
|
87 |
if (!process.env.PWDEBUGIMPL && file.startsWith(PLAYWRIGHT_CORE_PATH)) |
|
f7eb47b…
|
lmata
|
88 |
return false; |
|
f7eb47b…
|
lmata
|
89 |
return true; |
|
f7eb47b…
|
lmata
|
90 |
} |
|
f7eb47b…
|
lmata
|
91 |
function filteredStackTrace(rawStack) { |
|
f7eb47b…
|
lmata
|
92 |
const frames = []; |
|
f7eb47b…
|
lmata
|
93 |
for (const line of rawStack) { |
|
f7eb47b…
|
lmata
|
94 |
const frame = (0, import_utils.parseStackFrame)(line, import_path.default.sep, !!process.env.PWDEBUGIMPL); |
|
f7eb47b…
|
lmata
|
95 |
if (!frame || !frame.file) |
|
f7eb47b…
|
lmata
|
96 |
continue; |
|
f7eb47b…
|
lmata
|
97 |
if (!filterStackFile(frame.file)) |
|
f7eb47b…
|
lmata
|
98 |
continue; |
|
f7eb47b…
|
lmata
|
99 |
frames.push(frame); |
|
f7eb47b…
|
lmata
|
100 |
} |
|
f7eb47b…
|
lmata
|
101 |
return frames; |
|
f7eb47b…
|
lmata
|
102 |
} |
|
f7eb47b…
|
lmata
|
103 |
function serializeError(error) { |
|
f7eb47b…
|
lmata
|
104 |
if (error instanceof Error) |
|
f7eb47b…
|
lmata
|
105 |
return filterStackTrace(error); |
|
f7eb47b…
|
lmata
|
106 |
return { |
|
f7eb47b…
|
lmata
|
107 |
value: import_util.default.inspect(error) |
|
f7eb47b…
|
lmata
|
108 |
}; |
|
f7eb47b…
|
lmata
|
109 |
} |
|
f7eb47b…
|
lmata
|
110 |
function parseLocationArg(arg) { |
|
f7eb47b…
|
lmata
|
111 |
const match = /^(.*?):(\d+):?(\d+)?$/.exec(arg); |
|
f7eb47b…
|
lmata
|
112 |
return { |
|
f7eb47b…
|
lmata
|
113 |
file: match ? match[1] : arg, |
|
f7eb47b…
|
lmata
|
114 |
line: match ? parseInt(match[2], 10) : null, |
|
f7eb47b…
|
lmata
|
115 |
column: match?.[3] ? parseInt(match[3], 10) : null |
|
f7eb47b…
|
lmata
|
116 |
}; |
|
f7eb47b…
|
lmata
|
117 |
} |
|
f7eb47b…
|
lmata
|
118 |
function createFileFiltersFromArguments(args) { |
|
f7eb47b…
|
lmata
|
119 |
return args.map((arg) => { |
|
f7eb47b…
|
lmata
|
120 |
const parsed = parseLocationArg(arg); |
|
f7eb47b…
|
lmata
|
121 |
return { re: forceRegExp(parsed.file), line: parsed.line, column: parsed.column }; |
|
f7eb47b…
|
lmata
|
122 |
}); |
|
f7eb47b…
|
lmata
|
123 |
} |
|
f7eb47b…
|
lmata
|
124 |
function createFileMatcherFromArguments(args) { |
|
f7eb47b…
|
lmata
|
125 |
const filters = createFileFiltersFromArguments(args); |
|
f7eb47b…
|
lmata
|
126 |
return createFileMatcher(filters.map((filter) => filter.re || filter.exact || "")); |
|
f7eb47b…
|
lmata
|
127 |
} |
|
f7eb47b…
|
lmata
|
128 |
function createFileMatcher(patterns) { |
|
f7eb47b…
|
lmata
|
129 |
const reList = []; |
|
f7eb47b…
|
lmata
|
130 |
const filePatterns = []; |
|
f7eb47b…
|
lmata
|
131 |
for (const pattern of Array.isArray(patterns) ? patterns : [patterns]) { |
|
f7eb47b…
|
lmata
|
132 |
if ((0, import_utils.isRegExp)(pattern)) { |
|
f7eb47b…
|
lmata
|
133 |
reList.push(pattern); |
|
f7eb47b…
|
lmata
|
134 |
} else { |
|
f7eb47b…
|
lmata
|
135 |
if (!pattern.startsWith("**/")) |
|
f7eb47b…
|
lmata
|
136 |
filePatterns.push("**/" + pattern); |
|
f7eb47b…
|
lmata
|
137 |
else |
|
f7eb47b…
|
lmata
|
138 |
filePatterns.push(pattern); |
|
f7eb47b…
|
lmata
|
139 |
} |
|
f7eb47b…
|
lmata
|
140 |
} |
|
f7eb47b…
|
lmata
|
141 |
return (filePath) => { |
|
f7eb47b…
|
lmata
|
142 |
for (const re of reList) { |
|
f7eb47b…
|
lmata
|
143 |
re.lastIndex = 0; |
|
f7eb47b…
|
lmata
|
144 |
if (re.test(filePath)) |
|
f7eb47b…
|
lmata
|
145 |
return true; |
|
f7eb47b…
|
lmata
|
146 |
} |
|
f7eb47b…
|
lmata
|
147 |
if (import_path.default.sep === "\\") { |
|
f7eb47b…
|
lmata
|
148 |
const fileURL = import_url.default.pathToFileURL(filePath).href; |
|
f7eb47b…
|
lmata
|
149 |
for (const re of reList) { |
|
f7eb47b…
|
lmata
|
150 |
re.lastIndex = 0; |
|
f7eb47b…
|
lmata
|
151 |
if (re.test(fileURL)) |
|
f7eb47b…
|
lmata
|
152 |
return true; |
|
f7eb47b…
|
lmata
|
153 |
} |
|
f7eb47b…
|
lmata
|
154 |
} |
|
f7eb47b…
|
lmata
|
155 |
for (const pattern of filePatterns) { |
|
f7eb47b…
|
lmata
|
156 |
if ((0, import_utilsBundle.minimatch)(filePath, pattern, { nocase: true, dot: true })) |
|
f7eb47b…
|
lmata
|
157 |
return true; |
|
f7eb47b…
|
lmata
|
158 |
} |
|
f7eb47b…
|
lmata
|
159 |
return false; |
|
f7eb47b…
|
lmata
|
160 |
}; |
|
f7eb47b…
|
lmata
|
161 |
} |
|
f7eb47b…
|
lmata
|
162 |
function createTitleMatcher(patterns) { |
|
f7eb47b…
|
lmata
|
163 |
const reList = Array.isArray(patterns) ? patterns : [patterns]; |
|
f7eb47b…
|
lmata
|
164 |
return (value) => { |
|
f7eb47b…
|
lmata
|
165 |
for (const re of reList) { |
|
f7eb47b…
|
lmata
|
166 |
re.lastIndex = 0; |
|
f7eb47b…
|
lmata
|
167 |
if (re.test(value)) |
|
f7eb47b…
|
lmata
|
168 |
return true; |
|
f7eb47b…
|
lmata
|
169 |
} |
|
f7eb47b…
|
lmata
|
170 |
return false; |
|
f7eb47b…
|
lmata
|
171 |
}; |
|
f7eb47b…
|
lmata
|
172 |
} |
|
f7eb47b…
|
lmata
|
173 |
function mergeObjects(a, b, c) { |
|
f7eb47b…
|
lmata
|
174 |
const result = { ...a }; |
|
f7eb47b…
|
lmata
|
175 |
for (const x of [b, c].filter(Boolean)) { |
|
f7eb47b…
|
lmata
|
176 |
for (const [name, value] of Object.entries(x)) { |
|
f7eb47b…
|
lmata
|
177 |
if (!Object.is(value, void 0)) |
|
f7eb47b…
|
lmata
|
178 |
result[name] = value; |
|
f7eb47b…
|
lmata
|
179 |
} |
|
f7eb47b…
|
lmata
|
180 |
} |
|
f7eb47b…
|
lmata
|
181 |
return result; |
|
f7eb47b…
|
lmata
|
182 |
} |
|
f7eb47b…
|
lmata
|
183 |
function forceRegExp(pattern) { |
|
f7eb47b…
|
lmata
|
184 |
const match = pattern.match(/^\/(.*)\/([gi]*)$/); |
|
f7eb47b…
|
lmata
|
185 |
if (match) |
|
f7eb47b…
|
lmata
|
186 |
return new RegExp(match[1], match[2]); |
|
f7eb47b…
|
lmata
|
187 |
return new RegExp(pattern, "gi"); |
|
f7eb47b…
|
lmata
|
188 |
} |
|
f7eb47b…
|
lmata
|
189 |
function relativeFilePath(file) { |
|
f7eb47b…
|
lmata
|
190 |
if (!import_path.default.isAbsolute(file)) |
|
f7eb47b…
|
lmata
|
191 |
return file; |
|
f7eb47b…
|
lmata
|
192 |
return import_path.default.relative(process.cwd(), file); |
|
f7eb47b…
|
lmata
|
193 |
} |
|
f7eb47b…
|
lmata
|
194 |
function formatLocation(location) { |
|
f7eb47b…
|
lmata
|
195 |
return relativeFilePath(location.file) + ":" + location.line + ":" + location.column; |
|
f7eb47b…
|
lmata
|
196 |
} |
|
f7eb47b…
|
lmata
|
197 |
function errorWithFile(file, message) { |
|
f7eb47b…
|
lmata
|
198 |
return new Error(`${relativeFilePath(file)}: ${message}`); |
|
f7eb47b…
|
lmata
|
199 |
} |
|
f7eb47b…
|
lmata
|
200 |
function expectTypes(receiver, types, matcherName) { |
|
f7eb47b…
|
lmata
|
201 |
if (typeof receiver !== "object" || !types.includes(receiver.constructor.name)) { |
|
f7eb47b…
|
lmata
|
202 |
const commaSeparated = types.slice(); |
|
f7eb47b…
|
lmata
|
203 |
const lastType = commaSeparated.pop(); |
|
f7eb47b…
|
lmata
|
204 |
const typesString = commaSeparated.length ? commaSeparated.join(", ") + " or " + lastType : lastType; |
|
f7eb47b…
|
lmata
|
205 |
throw new Error(`${matcherName} can be only used with ${typesString} object${types.length > 1 ? "s" : ""}`); |
|
f7eb47b…
|
lmata
|
206 |
} |
|
f7eb47b…
|
lmata
|
207 |
} |
|
f7eb47b…
|
lmata
|
208 |
const windowsFilesystemFriendlyLength = 60; |
|
f7eb47b…
|
lmata
|
209 |
function trimLongString(s, length = 100) { |
|
f7eb47b…
|
lmata
|
210 |
if (s.length <= length) |
|
f7eb47b…
|
lmata
|
211 |
return s; |
|
f7eb47b…
|
lmata
|
212 |
const hash = (0, import_utils.calculateSha1)(s); |
|
f7eb47b…
|
lmata
|
213 |
const middle = `-${hash.substring(0, 5)}-`; |
|
f7eb47b…
|
lmata
|
214 |
const start = Math.floor((length - middle.length) / 2); |
|
f7eb47b…
|
lmata
|
215 |
const end = length - middle.length - start; |
|
f7eb47b…
|
lmata
|
216 |
return s.substring(0, start) + middle + s.slice(-end); |
|
f7eb47b…
|
lmata
|
217 |
} |
|
f7eb47b…
|
lmata
|
218 |
function addSuffixToFilePath(filePath, suffix) { |
|
f7eb47b…
|
lmata
|
219 |
const ext = import_path.default.extname(filePath); |
|
f7eb47b…
|
lmata
|
220 |
const base = filePath.substring(0, filePath.length - ext.length); |
|
f7eb47b…
|
lmata
|
221 |
return base + suffix + ext; |
|
f7eb47b…
|
lmata
|
222 |
} |
|
f7eb47b…
|
lmata
|
223 |
function sanitizeFilePathBeforeExtension(filePath, ext) { |
|
f7eb47b…
|
lmata
|
224 |
ext ??= import_path.default.extname(filePath); |
|
f7eb47b…
|
lmata
|
225 |
const base = filePath.substring(0, filePath.length - ext.length); |
|
f7eb47b…
|
lmata
|
226 |
return (0, import_utils.sanitizeForFilePath)(base) + ext; |
|
f7eb47b…
|
lmata
|
227 |
} |
|
f7eb47b…
|
lmata
|
228 |
function getContainedPath(parentPath, subPath = "") { |
|
f7eb47b…
|
lmata
|
229 |
const resolvedPath = import_path.default.resolve(parentPath, subPath); |
|
f7eb47b…
|
lmata
|
230 |
if (resolvedPath === parentPath || resolvedPath.startsWith(parentPath + import_path.default.sep)) |
|
f7eb47b…
|
lmata
|
231 |
return resolvedPath; |
|
f7eb47b…
|
lmata
|
232 |
return null; |
|
f7eb47b…
|
lmata
|
233 |
} |
|
f7eb47b…
|
lmata
|
234 |
const debugTest = (0, import_utilsBundle.debug)("pw:test"); |
|
f7eb47b…
|
lmata
|
235 |
const folderToPackageJsonPath = /* @__PURE__ */ new Map(); |
|
f7eb47b…
|
lmata
|
236 |
function getPackageJsonPath(folderPath) { |
|
f7eb47b…
|
lmata
|
237 |
const cached = folderToPackageJsonPath.get(folderPath); |
|
f7eb47b…
|
lmata
|
238 |
if (cached !== void 0) |
|
f7eb47b…
|
lmata
|
239 |
return cached; |
|
f7eb47b…
|
lmata
|
240 |
const packageJsonPath = import_path.default.join(folderPath, "package.json"); |
|
f7eb47b…
|
lmata
|
241 |
if (import_fs.default.existsSync(packageJsonPath)) { |
|
f7eb47b…
|
lmata
|
242 |
folderToPackageJsonPath.set(folderPath, packageJsonPath); |
|
f7eb47b…
|
lmata
|
243 |
return packageJsonPath; |
|
f7eb47b…
|
lmata
|
244 |
} |
|
f7eb47b…
|
lmata
|
245 |
const parentFolder = import_path.default.dirname(folderPath); |
|
f7eb47b…
|
lmata
|
246 |
if (folderPath === parentFolder) { |
|
f7eb47b…
|
lmata
|
247 |
folderToPackageJsonPath.set(folderPath, ""); |
|
f7eb47b…
|
lmata
|
248 |
return ""; |
|
f7eb47b…
|
lmata
|
249 |
} |
|
f7eb47b…
|
lmata
|
250 |
const result = getPackageJsonPath(parentFolder); |
|
f7eb47b…
|
lmata
|
251 |
folderToPackageJsonPath.set(folderPath, result); |
|
f7eb47b…
|
lmata
|
252 |
return result; |
|
f7eb47b…
|
lmata
|
253 |
} |
|
f7eb47b…
|
lmata
|
254 |
function resolveReporterOutputPath(defaultValue, configDir, configValue) { |
|
f7eb47b…
|
lmata
|
255 |
if (configValue) |
|
f7eb47b…
|
lmata
|
256 |
return import_path.default.resolve(configDir, configValue); |
|
f7eb47b…
|
lmata
|
257 |
let basePath = getPackageJsonPath(configDir); |
|
f7eb47b…
|
lmata
|
258 |
basePath = basePath ? import_path.default.dirname(basePath) : process.cwd(); |
|
f7eb47b…
|
lmata
|
259 |
return import_path.default.resolve(basePath, defaultValue); |
|
f7eb47b…
|
lmata
|
260 |
} |
|
f7eb47b…
|
lmata
|
261 |
async function normalizeAndSaveAttachment(outputPath, name, options = {}) { |
|
f7eb47b…
|
lmata
|
262 |
if (options.path === void 0 && options.body === void 0) |
|
f7eb47b…
|
lmata
|
263 |
return { name, contentType: "text/plain" }; |
|
f7eb47b…
|
lmata
|
264 |
if ((options.path !== void 0 ? 1 : 0) + (options.body !== void 0 ? 1 : 0) !== 1) |
|
f7eb47b…
|
lmata
|
265 |
throw new Error(`Exactly one of "path" and "body" must be specified`); |
|
f7eb47b…
|
lmata
|
266 |
if (options.path !== void 0) { |
|
f7eb47b…
|
lmata
|
267 |
const hash = (0, import_utils.calculateSha1)(options.path); |
|
f7eb47b…
|
lmata
|
268 |
if (!(0, import_utils.isString)(name)) |
|
f7eb47b…
|
lmata
|
269 |
throw new Error('"name" should be string.'); |
|
f7eb47b…
|
lmata
|
270 |
const sanitizedNamePrefix = (0, import_utils.sanitizeForFilePath)(name) + "-"; |
|
f7eb47b…
|
lmata
|
271 |
const dest = import_path.default.join(outputPath, "attachments", sanitizedNamePrefix + hash + import_path.default.extname(options.path)); |
|
f7eb47b…
|
lmata
|
272 |
await import_fs.default.promises.mkdir(import_path.default.dirname(dest), { recursive: true }); |
|
f7eb47b…
|
lmata
|
273 |
await import_fs.default.promises.copyFile(options.path, dest); |
|
f7eb47b…
|
lmata
|
274 |
const contentType = options.contentType ?? (import_utilsBundle.mime.getType(import_path.default.basename(options.path)) || "application/octet-stream"); |
|
f7eb47b…
|
lmata
|
275 |
return { name, contentType, path: dest }; |
|
f7eb47b…
|
lmata
|
276 |
} else { |
|
f7eb47b…
|
lmata
|
277 |
const contentType = options.contentType ?? (typeof options.body === "string" ? "text/plain" : "application/octet-stream"); |
|
f7eb47b…
|
lmata
|
278 |
return { name, contentType, body: typeof options.body === "string" ? Buffer.from(options.body) : options.body }; |
|
f7eb47b…
|
lmata
|
279 |
} |
|
f7eb47b…
|
lmata
|
280 |
} |
|
f7eb47b…
|
lmata
|
281 |
function fileIsModule(file) { |
|
f7eb47b…
|
lmata
|
282 |
if (file.endsWith(".mjs") || file.endsWith(".mts")) |
|
f7eb47b…
|
lmata
|
283 |
return true; |
|
f7eb47b…
|
lmata
|
284 |
if (file.endsWith(".cjs") || file.endsWith(".cts")) |
|
f7eb47b…
|
lmata
|
285 |
return false; |
|
f7eb47b…
|
lmata
|
286 |
const folder = import_path.default.dirname(file); |
|
f7eb47b…
|
lmata
|
287 |
return folderIsModule(folder); |
|
f7eb47b…
|
lmata
|
288 |
} |
|
f7eb47b…
|
lmata
|
289 |
function folderIsModule(folder) { |
|
f7eb47b…
|
lmata
|
290 |
const packageJsonPath = getPackageJsonPath(folder); |
|
f7eb47b…
|
lmata
|
291 |
if (!packageJsonPath) |
|
f7eb47b…
|
lmata
|
292 |
return false; |
|
f7eb47b…
|
lmata
|
293 |
return require(packageJsonPath).type === "module"; |
|
f7eb47b…
|
lmata
|
294 |
} |
|
f7eb47b…
|
lmata
|
295 |
const packageJsonMainFieldCache = /* @__PURE__ */ new Map(); |
|
f7eb47b…
|
lmata
|
296 |
function getMainFieldFromPackageJson(packageJsonPath) { |
|
f7eb47b…
|
lmata
|
297 |
if (!packageJsonMainFieldCache.has(packageJsonPath)) { |
|
f7eb47b…
|
lmata
|
298 |
let mainField; |
|
f7eb47b…
|
lmata
|
299 |
try { |
|
f7eb47b…
|
lmata
|
300 |
mainField = JSON.parse(import_fs.default.readFileSync(packageJsonPath, "utf8")).main; |
|
f7eb47b…
|
lmata
|
301 |
} catch { |
|
f7eb47b…
|
lmata
|
302 |
} |
|
f7eb47b…
|
lmata
|
303 |
packageJsonMainFieldCache.set(packageJsonPath, mainField); |
|
f7eb47b…
|
lmata
|
304 |
} |
|
f7eb47b…
|
lmata
|
305 |
return packageJsonMainFieldCache.get(packageJsonPath); |
|
f7eb47b…
|
lmata
|
306 |
} |
|
f7eb47b…
|
lmata
|
307 |
const kExtLookups = /* @__PURE__ */ new Map([ |
|
f7eb47b…
|
lmata
|
308 |
[".js", [".jsx", ".ts", ".tsx"]], |
|
f7eb47b…
|
lmata
|
309 |
[".jsx", [".tsx"]], |
|
f7eb47b…
|
lmata
|
310 |
[".cjs", [".cts"]], |
|
f7eb47b…
|
lmata
|
311 |
[".mjs", [".mts"]], |
|
f7eb47b…
|
lmata
|
312 |
["", [".js", ".ts", ".jsx", ".tsx", ".cjs", ".mjs", ".cts", ".mts"]] |
|
f7eb47b…
|
lmata
|
313 |
]); |
|
f7eb47b…
|
lmata
|
314 |
function resolveImportSpecifierExtension(resolved) { |
|
f7eb47b…
|
lmata
|
315 |
if (fileExists(resolved)) |
|
f7eb47b…
|
lmata
|
316 |
return resolved; |
|
f7eb47b…
|
lmata
|
317 |
for (const [ext, others] of kExtLookups) { |
|
f7eb47b…
|
lmata
|
318 |
if (!resolved.endsWith(ext)) |
|
f7eb47b…
|
lmata
|
319 |
continue; |
|
f7eb47b…
|
lmata
|
320 |
for (const other of others) { |
|
f7eb47b…
|
lmata
|
321 |
const modified = resolved.substring(0, resolved.length - ext.length) + other; |
|
f7eb47b…
|
lmata
|
322 |
if (fileExists(modified)) |
|
f7eb47b…
|
lmata
|
323 |
return modified; |
|
f7eb47b…
|
lmata
|
324 |
} |
|
f7eb47b…
|
lmata
|
325 |
break; |
|
f7eb47b…
|
lmata
|
326 |
} |
|
f7eb47b…
|
lmata
|
327 |
} |
|
f7eb47b…
|
lmata
|
328 |
function resolveImportSpecifierAfterMapping(resolved, afterPathMapping) { |
|
f7eb47b…
|
lmata
|
329 |
const resolvedFile = resolveImportSpecifierExtension(resolved); |
|
f7eb47b…
|
lmata
|
330 |
if (resolvedFile) |
|
f7eb47b…
|
lmata
|
331 |
return resolvedFile; |
|
f7eb47b…
|
lmata
|
332 |
if (dirExists(resolved)) { |
|
f7eb47b…
|
lmata
|
333 |
const packageJsonPath = import_path.default.join(resolved, "package.json"); |
|
f7eb47b…
|
lmata
|
334 |
if (afterPathMapping) { |
|
f7eb47b…
|
lmata
|
335 |
const mainField = getMainFieldFromPackageJson(packageJsonPath); |
|
f7eb47b…
|
lmata
|
336 |
const mainFieldResolved = mainField ? resolveImportSpecifierExtension(import_path.default.resolve(resolved, mainField)) : void 0; |
|
f7eb47b…
|
lmata
|
337 |
return mainFieldResolved || resolveImportSpecifierExtension(import_path.default.join(resolved, "index")); |
|
f7eb47b…
|
lmata
|
338 |
} |
|
f7eb47b…
|
lmata
|
339 |
if (fileExists(packageJsonPath)) |
|
f7eb47b…
|
lmata
|
340 |
return resolved; |
|
f7eb47b…
|
lmata
|
341 |
const dirImport = import_path.default.join(resolved, "index"); |
|
f7eb47b…
|
lmata
|
342 |
return resolveImportSpecifierExtension(dirImport); |
|
f7eb47b…
|
lmata
|
343 |
} |
|
f7eb47b…
|
lmata
|
344 |
} |
|
f7eb47b…
|
lmata
|
345 |
function fileExists(resolved) { |
|
f7eb47b…
|
lmata
|
346 |
return import_fs.default.statSync(resolved, { throwIfNoEntry: false })?.isFile(); |
|
f7eb47b…
|
lmata
|
347 |
} |
|
f7eb47b…
|
lmata
|
348 |
async function fileExistsAsync(resolved) { |
|
f7eb47b…
|
lmata
|
349 |
try { |
|
f7eb47b…
|
lmata
|
350 |
const stat = await import_fs.default.promises.stat(resolved); |
|
f7eb47b…
|
lmata
|
351 |
return stat.isFile(); |
|
f7eb47b…
|
lmata
|
352 |
} catch { |
|
f7eb47b…
|
lmata
|
353 |
return false; |
|
f7eb47b…
|
lmata
|
354 |
} |
|
f7eb47b…
|
lmata
|
355 |
} |
|
f7eb47b…
|
lmata
|
356 |
function dirExists(resolved) { |
|
f7eb47b…
|
lmata
|
357 |
return import_fs.default.statSync(resolved, { throwIfNoEntry: false })?.isDirectory(); |
|
f7eb47b…
|
lmata
|
358 |
} |
|
f7eb47b…
|
lmata
|
359 |
async function removeDirAndLogToConsole(dir) { |
|
f7eb47b…
|
lmata
|
360 |
try { |
|
f7eb47b…
|
lmata
|
361 |
if (!import_fs.default.existsSync(dir)) |
|
f7eb47b…
|
lmata
|
362 |
return; |
|
f7eb47b…
|
lmata
|
363 |
console.log(`Removing ${await import_fs.default.promises.realpath(dir)}`); |
|
f7eb47b…
|
lmata
|
364 |
await import_fs.default.promises.rm(dir, { recursive: true, force: true }); |
|
f7eb47b…
|
lmata
|
365 |
} catch { |
|
f7eb47b…
|
lmata
|
366 |
} |
|
f7eb47b…
|
lmata
|
367 |
} |
|
f7eb47b…
|
lmata
|
368 |
// Annotate the CommonJS export names for ESM import in node: |
|
f7eb47b…
|
lmata
|
369 |
0 && (module.exports = { |
|
f7eb47b…
|
lmata
|
370 |
addSuffixToFilePath, |
|
f7eb47b…
|
lmata
|
371 |
ansiRegex, |
|
f7eb47b…
|
lmata
|
372 |
createFileFiltersFromArguments, |
|
f7eb47b…
|
lmata
|
373 |
createFileMatcher, |
|
f7eb47b…
|
lmata
|
374 |
createFileMatcherFromArguments, |
|
f7eb47b…
|
lmata
|
375 |
createTitleMatcher, |
|
f7eb47b…
|
lmata
|
376 |
debugTest, |
|
f7eb47b…
|
lmata
|
377 |
errorWithFile, |
|
f7eb47b…
|
lmata
|
378 |
expectTypes, |
|
f7eb47b…
|
lmata
|
379 |
fileExistsAsync, |
|
f7eb47b…
|
lmata
|
380 |
fileIsModule, |
|
f7eb47b…
|
lmata
|
381 |
filterStackFile, |
|
f7eb47b…
|
lmata
|
382 |
filterStackTrace, |
|
f7eb47b…
|
lmata
|
383 |
filteredStackTrace, |
|
f7eb47b…
|
lmata
|
384 |
forceRegExp, |
|
f7eb47b…
|
lmata
|
385 |
formatLocation, |
|
f7eb47b…
|
lmata
|
386 |
getContainedPath, |
|
f7eb47b…
|
lmata
|
387 |
getPackageJsonPath, |
|
f7eb47b…
|
lmata
|
388 |
mergeObjects, |
|
f7eb47b…
|
lmata
|
389 |
normalizeAndSaveAttachment, |
|
f7eb47b…
|
lmata
|
390 |
parseLocationArg, |
|
f7eb47b…
|
lmata
|
391 |
relativeFilePath, |
|
f7eb47b…
|
lmata
|
392 |
removeDirAndLogToConsole, |
|
f7eb47b…
|
lmata
|
393 |
resolveImportSpecifierAfterMapping, |
|
f7eb47b…
|
lmata
|
394 |
resolveReporterOutputPath, |
|
f7eb47b…
|
lmata
|
395 |
sanitizeFilePathBeforeExtension, |
|
f7eb47b…
|
lmata
|
396 |
serializeError, |
|
f7eb47b…
|
lmata
|
397 |
stripAnsiEscapes, |
|
f7eb47b…
|
lmata
|
398 |
trimLongString, |
|
f7eb47b…
|
lmata
|
399 |
windowsFilesystemFriendlyLength |
|
f7eb47b…
|
lmata
|
400 |
}); |