@cljs-oss/module-deps

中文文档
1.1.1发布于 2017/08/16MITCommonJS近 30 天下载 8637

将依赖图行走以生成可以输入浏览器包的 json 输出

中文使用文档
文档目录6 节
  1. var d = mdeps (opts ) (中文(简体) )
  2. d.on (' transform', 函数 (tr, 文件) ) qq)
  3. d.on('file',函数 (file) * )
  4. d.on ('missing', 函数 (id, 父) qq)
  5. d.on('package',函数 (pkg) * )
  6. 软件包.json 变换键

模块数据

将依赖图走动以生成可输入的 json 输出 浏览器软件包

build status

实例

var mdeps = require('module-deps');
var JSONStream = require('JSONStream');

var md = mdeps();
md.pipe(JSONStream.stringify()).pipe(process.stdout);
md.end({ file: __dirname + '/files/main.js' });

输出 :

$ node example/deps.js
[
{"id":"/home/substack/projects/module-deps/example/files/main.js","source":"var foo = require('./foo');\nconsole.log('main: ' + foo(5));\n","entry":true,"deps":{"./foo":"/home/substack/projects/module-deps/example/files/foo.js"}}
,
{"id":"/home/substack/projects/module-deps/example/files/foo.js","source":"var bar = require('./bar');\n\nmodule.exports = function (n) {\n    return n * 111 + bar(n);\n};\n","deps":{"./bar":"/home/substack/projects/module-deps/example/files/bar.js"}}
,
{"id":"/home/substack/projects/module-deps/example/files/bar.js","source":"module.exports = function (n) {\n    return n * 100;\n};\n","deps":{}}
]

您可以将 json 数据输入 浏览器软件包数字 :

$ node example/deps.js | browser-pack | node
main: 1055

使用量

usage: module-deps [files]

  generate json output from each entry file

方法

var mdeps = require('module-deps')

var d = mdeps (opts ) (中文(简体) )

返回对象变换流 d 需要条目文件名或 { id: ..., file: ... } 对象作为输入,并为每个对象生成对象 依赖自递归模块作为输出.

每个文件在 files 可以是字符串文件名或流.

可以选择通过一些 opts数字 :

  • opts.transform - 字符串或数组的字符串变换(见下文)

  • opts.transformKey - 显示查找位置的字符串阵列路径 package.json 用于源变换. 如果发作,不要看 包裹。 json 一点都没有.

  • opts.resolve - 使用 opts.resolve(id, parent, cb) 签名 浏览器解析 已经

  • opts.filter - 跳过某些模块解析的函数( id) id 字符串. 如果定义, opts.filter(id) 应返回真实性,以便包含所有编号 和假的,所有ids跳过.

  • opts.postFilter - 之后被调用的函数(id、文件、pkg) id 已经 已经解决。 返回错误以跳过此文件 .

  • opts.packageFilter - 在使用前将已解析的软件包进行转换 价值观. opts.packageFilter(pkg, dir) 应该返回新的 pkg 对象 使用时.

  • opts.noParse - 一系列绝对路径,不分析依赖性。 使用 这对像jquery或3j这样的大型依赖性来说是需要永久解析的.

  • opts.cache - 对象映射文件名以文件对象以跳过昂贵的io

  • opts.packageCache - 对象映射文件名到他们的父软件包.json 浏览器字段、主要条目和变换的内容

  • opts.fileCache - 对象映射文件名到原始来源以避免读取 从磁盘.

  • opts.persistentCache - 一个复杂的缓存处理器,允许同步和持续 隐藏数据。 A 类 persistentCache 需要遵循此接口 :

    function persistentCache (
        file, // the path to the file that is loaded
        id,   // the id that is used to reference this file
        pkg,  // the package that this file belongs to fallback
        fallback, // async fallback handler to be called if the cache doesn't hold the given file 
        cb    // callback handler that receives the cache data
    ) {
        if (hasError()) {
            return cb(error) // Pass any error to the callback
        }
    
        var fileData = fs.readFileSync(file)
        var key = keyFromFile(file, fileData)
    
        if (db.has(key)) {
            return cb(null, {
                source: db.get(key).toString(),
                package: pkg, // The package for housekeeping
                deps: {
                    'id':  // id that is used to reference a required file
                    'file' // file path to the required file
                }
            })
        }
        //
        // The fallback will process the file in case the file is not
        // in cache.
        //
        // Note that if your implementation doesn't need the file data
        // then you can pass `null` instead of the source and the fallback will
        // fetch the data by itself.
        //
        fallback(fileData, function (error, cacheableEntry) {
            if (error) {
                return cb(error)
            }
            db.addToCache(key, cacheableEntry)
            cb(null, cacheableEntry)
        })
    }
    
  • opts.paths - 搜索的全球路径。 默认拆分于 ':' 内 process.env.NODE_PATH

  • opts.ignoreMissing - 忽略未能解决的文件

输入对象

输入对象应为带有这些参数的字符串文件名或对象:

  • row.file - 文件名
  • row.expose - 名称应作为
  • row.noparse 当属实时, 不分析文件内容的依赖性

或对象可以指定变换:

  • row.transform - 字符串名称、路径或函数
  • row.options - 将选项转换为对象
  • row.global - 布尔,无论转变是全球性的

事件

d.on (' transform', 函数 (tr, 文件) ) qq)

每次变换都应用到 file页:1 'transform' 发生火灾 即时变流 tr。 。 。 .

d.on('file',函数 (file) * )

每次读取文件时,此事件都会随文件路径起火.

d.on ('missing', 函数 (id, 父) qq)

何时 opts.ignoreMissing 启用,此事件为每个缺失的软件包起火.

d.on('package',函数 (pkg) * )

每次读到一个包,这个事件就会起火. 该目录名称 软件包可用于 pkg.__dirname。 。 。 .

变换

模块解析器可以配置为在文件前运行源转换 解析 require() 打电话 这些变换如果你想的话是有用的 编译语言 咖啡纸 苍蝇或 如果您想要将静态资产装入捆绑中, 请解析 AST fs.readFileSync() 打电话.

如果变换是一个函数,它应该采取 file 名称作为参数 返回将写入文件内容并输出的流 新建已转换的文件内容 .

如果变换为字符串, 它将被作为模块名称处理 到一个模块,预计将遵循此格式:

var through = require('through2');
module.exports = function (file, opts) { return through() };

你不必用这个 通过2 模块创建 可读/ 可写过滤流, 用于转换文件内容, 但是这是 很简单.

当你打电话 mdeps() 带有 opts.transform,改变你 指定不会运行节点 模块/中的任何文件 。 这是因为模块 包括你 应该是自成一体 不需要担心守卫 面对上游可能发生的转变.

模块可以通过设置转换管道来应用自己的转换 他们的包裹 opts.transformKey 路径。 这些转变 仅适用于模块本身中直接的文件,而不是模块的 受抚养人或受抚养人.

软件包.json 变换键

变形键活在包中的可配置位置. json 表示为 页:1 opts.transformKey 阵列.

变形金库 ['foo','bar'],转换键可以是单个字符串 (单位:千美元)"fff":

{
  "foo": {
    "bar": "fff"
  }
}

或字符串数组( r)["fff","ggg"]:

{
  "foo": {
    "bar": ["fff","ggg"]
  }
}

如果您想要将选项传递到变换中, 您可以使用 2 元素阵列 在主阵列内。 给 fff 获取选项对象 {"x":3} 财务报告和审定财务报表 ggg 获得 {"y":4}数字 :

{
  "foo": {
    "bar": [["fff",{"x":3}],["ggg",{"y":4}]]
  }
}

发送给模块解析构建器的选项也在下面提供 opts._flags。这些选项有时需要,如果您的转换 当浏览器以调试模式运行时, 需要做一些不同的事情 实例.

使用量

module-deps [FILES] OPTIONS

  Generate json output for the entry point FILES.

OPTIONS are:

  -t TRANSFORM  Apply a TRANSFORM.
  -g TRANSFORM  Apply a global TRANSFORM.

安装

与 无,使模块完成:

npm install module-deps

并获得 module-deps 命令执行 :

npm install -g module-deps

许可证

麻省理工学院

版本与发布记录

@cljs-oss/module-deps 共发布 3 个版本,首次发布于 2017/07/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.1latest2017/08/169 年前
1.1.02017/08/159 年前
1.0.02017/07/309 年前

关于 @cljs-oss/module-deps 的常见问题

@cljs-oss/module-deps 是什么?

将依赖图行走以生成可以输入浏览器包的 json 输出

如何安装 @cljs-oss/module-deps?

在项目目录运行 npm install @cljs-oss/module-deps,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 module-deps,可以用 npx module-deps 直接运行。

@cljs-oss/module-deps 支持 TypeScript 吗?

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

@cljs-oss/module-deps 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cljs-oss/module-deps 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 0.6。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cljs-oss/module-deps 可以商用吗?

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

@cljs-oss/module-deps 的下载量有多少?

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

@cljs-oss/module-deps 还在维护吗?

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