@vitest/utils
Advanced tools
| interface ExtractedSourceMap { | ||
| map: any; | ||
| } | ||
| declare function extractSourcemapFromFile(code: string, filePath: string): ExtractedSourceMap | undefined; | ||
| export { extractSourcemapFromFile }; |
| import { existsSync, readFileSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import convertSourceMap from 'convert-source-map'; | ||
| // based on vite | ||
| // https://github.com/vitejs/vite/blob/84079a84ad94de4c1ef4f1bdb2ab448ff2c01196/packages/vite/src/node/server/sourcemap.ts#L149 | ||
| function extractSourcemapFromFile(code, filePath) { | ||
| const map = (convertSourceMap.fromSource(code) || convertSourceMap.fromMapFileSource(code, createConvertSourceMapReadMap(filePath)))?.toObject(); | ||
| return map ? { map } : undefined; | ||
| } | ||
| function createConvertSourceMapReadMap(originalFileName) { | ||
| return (filename) => { | ||
| // convertSourceMap can detect invalid filename from comments. | ||
| // fallback to empty source map to avoid errors. | ||
| const targetPath = path.resolve(path.dirname(originalFileName), filename); | ||
| if (existsSync(targetPath)) { | ||
| return readFileSync(targetPath, "utf-8"); | ||
| } | ||
| return "{}"; | ||
| }; | ||
| } | ||
| export { extractSourcemapFromFile }; |
+11
-2
| { | ||
| "name": "@vitest/utils", | ||
| "type": "module", | ||
| "version": "4.1.0-beta.4", | ||
| "version": "4.1.0-beta.5", | ||
| "description": "Shared Vitest utility functions", | ||
@@ -59,2 +59,6 @@ "license": "MIT", | ||
| }, | ||
| "./source-map/node": { | ||
| "types": "./dist/source-map/node.d.ts", | ||
| "default": "./dist/source-map/node.js" | ||
| }, | ||
| "./serialize": { | ||
@@ -73,2 +77,5 @@ "types": "./dist/serialize.d.ts", | ||
| "dist/source-map.d.ts" | ||
| ], | ||
| "source-map/node": [ | ||
| "dist/source-map/node.d.ts" | ||
| ] | ||
@@ -82,7 +89,9 @@ } | ||
| "dependencies": { | ||
| "convert-source-map": "^2.0.0", | ||
| "tinyrainbow": "^3.0.3", | ||
| "@vitest/pretty-format": "4.1.0-beta.4" | ||
| "@vitest/pretty-format": "4.1.0-beta.5" | ||
| }, | ||
| "devDependencies": { | ||
| "@jridgewell/trace-mapping": "0.3.31", | ||
| "@types/convert-source-map": "^2.0.3", | ||
| "@types/estree": "^1.0.8", | ||
@@ -89,0 +98,0 @@ "diff-sequences": "^29.6.3", |
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
166076
0.85%33
6.45%4611
0.57%3
50%5
25%+ Added
+ Added
+ Added
- Removed