Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 14x 14x 14x | import process from 'node:process'; import fs from 'node:fs'; import path from 'node:path'; import { glob, escapePath } from 'tinyglobby'; import { parse } from 'error-stack-parser-es/lite'; import picomatch from 'picomatch'; const isWindows = typeof process !== "undefined" && process.platform === "win32"; function camelCase(name) { return name.replace(/-(\w)/g, (_, c) => c.toUpperCase()); } const WindowsSlashRE = /\\/g; const WindowsDiskRE = /^[a-z]?:(?:\/|\\\\)/i; const ColorStringRE = /\x1B[[(?);]{0,2}(;?\d)*./g; function slash(p) { return p.replace(WindowsSlashRE, "/"); } function normalizePath(id) { return path.posix.normalize(isWindows ? slash(id) : id); } function getCommonBase(globsResolved) { const bases = globsResolved.filter((g) => g[0] !== "!").map((glob) => { let { base } = picomatch.scan(glob); if (path.posix.basename(base).includes(".")) base = path.posix.dirname(base); return base; }); if (!bases.length) return null; let commonAncestor = ""; const dirS = bases[0].split("/"); for (let i = 0; i < dirS.length; i++) { const candidate = dirS.slice(0, i + 1).join("/"); if (bases.every((base) => base.startsWith(candidate))) commonAncestor = candidate; else break; } if (!commonAncestor) commonAncestor = "/"; return commonAncestor; } function parseAbsolute(pathStr) { if (!pathStr) return pathStr; pathStr = slash(pathStr); return isWindows && pathStr.startsWith("/") && pathStr.slice(1).match(WindowsDiskRE) ? pathStr.slice(1) : pathStr; } function getCallerPath(depth = 2) { const error = new Error("get-caller-path"); const stacks = parse(error); const filesList = Array.from(new Set(stacks.map((i) => i.file || null))); const linePattern = /^((?:file|https?):\/\/)?(?<file>.*?)(?::\d+)?(?::\d+)?$/; const targetIndex = depth; const targetLine = filesList[targetIndex] || filesList.at(-1); const match = targetLine?.match(linePattern)?.groups?.file; return parseAbsolute(match) || null; } const forceDefaultAs = ["raw", "url"]; const allowImportExt = [".js", ".ts", ".mjs", ".mts", ".cjs", ".cts"]; const importGlob = async function(pattern, options) { const { eager = false, import: importName, query, as, exhaustive = false, // ProjectOptions root: rootPath = process.cwd(), callerId = getCallerPath(), fallback = false } = options || {}; if (!callerId) { throw new Error("CallerId is null"); } const id = slash(callerId); const root = slash(rootPath); const dir = path.dirname(id); const patterns = Array.isArray(pattern) ? pattern : [pattern]; const globsResolved = patterns.map((glob) => toAbsoluteGlob(glob, root, id)); const cwd = getCommonBase(globsResolved) ?? root; const isRelative = patterns.every((i) => ".!".includes(i[0] || "")); const files = (await glob(globsResolved, { absolute: true, cwd, dot: exhaustive, expandDirectories: false, ignore: exhaustive ? [] : ["**/node_modules/**"] })).filter((file) => file !== id).sort(); const resolvePaths = (file) => { if (!dir) { if (isRelative) { throw new Error( "In virtual modules, all globs must start with '/'" ); } const filePath2 = `/${path.relative(root, file)}`; return { filePath: filePath2, importPath: filePath2 }; } let importPath = path.relative(dir, file); if (importPath[0] !== ".") importPath = `./${importPath}`; let filePath; if (isRelative) { filePath = importPath; } else { filePath = path.relative(root, file); if (filePath[0] !== ".") filePath = `/${filePath}`; } return { filePath, importPath }; }; const imports = {}; for (const file of files) { const paths = resolvePaths(file); const importPath = paths.importPath; const importKey = importName && importName !== "*" ? importName : void 0; const targetType = as && forceDefaultAs.includes(as) ? as : void 0; try { if (eager) { const module = await dynamicImport(importPath, { dir, as }); imports[file] = importKey && !targetType ? module[importKey] : module; } else { imports[file] = async () => { const module = await dynamicImport(importPath, { dir, as }); return importKey && !targetType ? module[importKey] : module; }; } } catch (error) { const ext = path.extname(file); if (fallback && ext && !allowImportExt.includes(ext)) { imports[file] = fs.readFileSync(file, "utf-8"); } else { throw error; } } } return imports; }; async function dynamicImport(modulePath, options = {}) { let targetPath = modulePath; if (options.dir && !path.isAbsolute(modulePath) && path.isAbsolute(options.dir)) { targetPath = path.join(options.dir, targetPath); } const targetType = options.as && forceDefaultAs.includes(options.as) ? options.as : void 0; if (options.as && targetType) { if (targetType === "url") { return slash(targetPath); } else if (targetType === "raw") { return fs.readFileSync(targetPath, "utf-8"); } } return await import(targetPath); } function toAbsoluteGlob(glob, root, importer) { let prefix = ""; if (glob.startsWith("!")) { prefix = "!"; glob = glob.slice(1); } if (!glob) { throw new Error("Glob pattern cannot be empty"); } if (!path.isAbsolute(root)) { throw new Error("Root path must be an absolute path"); } if (glob.startsWith("**")) { return prefix + glob; } const baseDir = importer ? globSafePath(path.dirname(importer)) : root; if (glob.startsWith("/")) { return prefix + path.posix.join(root, glob.slice(1)); } else if (glob.startsWith("./")) { return prefix + path.posix.join(baseDir, glob.slice(2)); } else if (glob.startsWith("../")) { return prefix + path.posix.join(baseDir, glob); } else { return prefix + path.posix.join(baseDir, glob); } } function globSafePath(path2) { return escapePath(normalizePath(path2)); } function isStream(stream, { checkOpen = true } = {}) { return stream !== null && typeof stream === "object" && !!(stream.writable || stream.readable || !checkOpen || stream.writable === void 0 && stream.readable === void 0) && typeof stream.pipe === "function"; } function strEnum(o) { return o.reduce((res, key) => { res[key] = key; return res; }, /* @__PURE__ */ Object.create(null)); } function numEnum(arr) { return arr.reduce((acc, key, index) => { acc[key] = index; return acc; }, {}); } function isNil(value, emptyStringCheck = false) { const checkList = [void 0, null, ""]; if (emptyStringCheck !== true) { checkList.pop(); } return checkList.includes(value); } export { ColorStringRE, WindowsDiskRE, WindowsSlashRE, camelCase, getCallerPath, getCommonBase, globSafePath, importGlob, isNil, isStream, isWindows, normalizePath, numEnum, parseAbsolute, slash, strEnum, toAbsoluteGlob }; |