profiler-md 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -5,6 +5,7 @@ import { dirname, resolve } from "node:path";
5
5
  import { pathToFileURL } from "node:url";
6
6
  import { promisify } from "node:util";
7
7
  import { brotliDecompress, gunzip } from "node:zlib";
8
+ import convertSourceMap from "convert-source-map";
8
9
  import meow from "meow";
9
10
  import picomatch from "picomatch";
10
11
  import { Profile } from "pprof-format";
@@ -2200,7 +2201,8 @@ const cli = meow(`
2200
2201
  --third-party <glob> Mark URLs matching this glob as third-party
2201
2202
  (repeatable; default: node_modules)
2202
2203
  --source-maps <glob> Apply source maps matching this glob to profile
2203
- locations (repeatable)
2204
+ locations; files may be source map JSON or contain
2205
+ inline source map comments (repeatable)
2204
2206
  --help Show this help message
2205
2207
  `, {
2206
2208
  importMeta: import.meta,
@@ -2231,6 +2233,17 @@ const cli = meow(`
2231
2233
  });
2232
2234
  const gunzipAsync = promisify(gunzip);
2233
2235
  const brotliDecompressAsync = promisify(brotliDecompress);
2236
+ /**
2237
+ * Pre-resolves relative source paths against the map file's directory so that `source-map-js` returns
2238
+ * absolute URLs.
2239
+ */
2240
+ const resolveSourceMapSources = (sourceMap, path) => {
2241
+ if (sourceMap.sourceRoot) return sourceMap;
2242
+ return {
2243
+ ...sourceMap,
2244
+ sources: sourceMap.sources.map((source) => makeFileReference(source).type === `absolute` ? source : new URL(source, pathToFileURL(resolve(dirname(path)))).href)
2245
+ };
2246
+ };
2234
2247
  const decompressData = async (data, filePath) => {
2235
2248
  if (filePath?.endsWith(`.br`)) return brotliDecompressAsync(data);
2236
2249
  if (data[0] === 31 && data[1] === 139) return gunzipAsync(data);
@@ -2273,12 +2286,11 @@ try {
2273
2286
  cwd,
2274
2287
  isThirdPartyEntry,
2275
2288
  sourceMaps: await Promise.all(sourceMapPaths.map(async (path) => {
2276
- const sourceMap = JSON.parse(await readFile(path, `utf8`));
2277
- if (sourceMap.sourceRoot) return sourceMap;
2278
- return {
2279
- ...sourceMap,
2280
- sources: sourceMap.sources.map((source) => makeFileReference(source).type === `absolute` ? source : new URL(source, pathToFileURL(resolve(dirname(path)))).href)
2281
- };
2289
+ const content = await readFile(path, `utf8`);
2290
+ const inlineSourceMap = convertSourceMap.fromSource(content)?.toObject();
2291
+ if (!inlineSourceMap) return resolveSourceMapSources(JSON.parse(content), path);
2292
+ inlineSourceMap.file ??= pathToFileURL(resolve(path)).href;
2293
+ return resolveSourceMapSources(inlineSourceMap, path);
2282
2294
  }))
2283
2295
  };
2284
2296
  let markdown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "profiler-md",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "author": {
5
5
  "name": "Tomer Aberbach",
6
6
  "email": "tomer@aberba.ch",
@@ -62,6 +62,7 @@
62
62
  },
63
63
  "prettier": "@tomer/prettier-config",
64
64
  "dependencies": {
65
+ "convert-source-map": "^2.0.0",
65
66
  "meow": "^14.1.0",
66
67
  "picomatch": "^4.0.4",
67
68
  "plur": "^6.0.0",
@@ -75,6 +76,7 @@
75
76
  "@rollup/plugin-terser": "^1.0.0",
76
77
  "@tomer/eslint-config": "^5.0.0",
77
78
  "@tomer/prettier-config": "^4.0.1",
79
+ "@types/convert-source-map": "^2.0.3",
78
80
  "@types/picomatch": "^4.0.3",
79
81
  "@vitest/coverage-v8": "^4.1.5",
80
82
  "diff": "^9.0.0",
package/readme.md CHANGED
@@ -67,7 +67,8 @@ $ profiler-md --help
67
67
  --third-party <glob> Mark URLs matching this glob as third-party
68
68
  (repeatable; default: node_modules)
69
69
  --source-maps <glob> Apply source maps matching this glob to profile
70
- locations (repeatable)
70
+ locations; files may be source map JSON or contain
71
+ inline source map comments (repeatable)
71
72
  --help Show this help message
72
73
  ```
73
74