@frida/mold-source-map

中文文档
1.0.0发布于 2021/06/16MIT近 30 天下载 2191

Mold a source map that is almost perfect for you into one that is.

原始使用文档
文档目录7 节
  1. About
  2. Installation
  3. API
  4. Transforms
  5. Convenience Transforms
  6. transformSourcesRelativeTo(root : String)
  7. Unstable API

mold-source-map

Fork maintained by the Frida project until upstream gets around to merging pending PRs.

About

Mold a source map that is almost perfect for you into one that is.

browserify()
  .require(require.resolve('./project/js/main.js'), { entry: true })
  .bundle({ debug: true })

  // will show all source files relative to jsRoot inside devtools
  .pipe(mold.transformSourcesRelativeTo(jsRoot))
  .pipe(fs.createWriteStream(bundlePath));

Full example here.

Installation

npm install mold-source-map

API

Transforms

Transforms return a duplex stream and are therefore easily threaded into a bundler that streams the generated bundle, like browserify.

transform(function map(sourcemap[, callback]) {})

This is the most generic and powerfull feature as it allows replacing the entire sourcemap comment with another String.

It takes a map function as input whose sourcemap argument has all information and lots of functions regarding the existing source map.

The optional callback can be used to call back with the final source map comment. If it is given, the transform will invoke the function asynchronously, otherwise you may just return the final source map comment.

Here is a snippet from an example showing how to use this in order to write out an external map file and point the browser to it:

function mapFileUrlComment(sourcemap, cb) {
  
  // make source files appear under the following paths:
  // /js
  //    foo.js
  //    main.js
  // /js/wunder
  //    bar.js 
  
  sourcemap.sourceRoot('file://'); 
  sourcemap.mapSources(mold.mapPathRelativeTo(jsRoot));

  // write map file and return a sourceMappingUrl that points to it
  fs.writeFile(mapFilePath, sourcemap.toJSON(2), 'utf-8', function (err) {
    if (err) return console.error(err);
    cb('//@ sourceMappingURL=' + path.basename(mapFilePath));
  });
}

browserify()
  .require(require.resolve('./project/js/main.js'), { entry: true })
  .bundle({ debug: true })
  .pipe(mold.transform(mapFileUrlComment))
  .pipe(fs.createWriteStream(bundlePath));

This example achieves the same using sync operations.

Convenience Transforms

The below transforms addressing special use cases. These cases all could be implemented with the generic transform as well.

transformSourcesRelativeTo(root : String)

/**
 * Adjusts all sources paths inside the source map contained in the content that is piped to it.
 *
 * Example: bundleStream.pipe(mold.sourcesRelative(root)).pipe(fs.createWriteStream(bundlePath))
 *
 * @name sourcesRelative
 * @function
 * @param root {String} The path to make sources relative to.
 * @return {Stream} A duplex stream that writes out content with source map that had all sources paths adjusted.
 */

Unstable API

A more custom/advanced API will be/is exposed, however it is still in high fluctuation.

Take a look at the index.js to get an idea of what's coming/already there.

版本与发布记录

@frida/mold-source-map 共发布 1 个版本,首次发布于 2021/06/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2021/06/165 年前

关于 @frida/mold-source-map 的常见问题

@frida/mold-source-map 是什么?

Mold a source map that is almost perfect for you into one that is.

如何安装 @frida/mold-source-map?

在项目目录运行 npm install @frida/mold-source-map,或使用 pnpm add / yarn add / bun add。

@frida/mold-source-map 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/frida__mold-source-map 是否存在。

@frida/mold-source-map 可以商用吗?

@frida/mold-source-map 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@frida/mold-source-map 的下载量有多少?

根据 npm 官方下载统计,@frida/mold-source-map 在 2026/10/16 – 2026/11/14 这 30 天内被下载 2,191 次,日均约 73 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@frida/mold-source-map 还在维护吗?

最新版本 1.0.0 发布于 2021/06/16(5 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/06/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。