npm i --global-style

未关闭
#124 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
领域
tooling

调研方向

从 dependency-tree 作为入口开始,并使用报告中显示的 dist/src/index.js、dist/node_modules/package2/index.js 以及嵌套的 package1 路径来复现调用。将结果与 Node.js 的模块解析行为进行比较,并跟踪目录和文件名参数的解析方式。当依赖树反映出预期输出中描述的最近的嵌套 node_modules 布局时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

Hello!

Maybe I'm creating an issue in the wrong repository and real problem hides somewhere in dependencies. But I use dependency-tree as an entry point, so ... it looks like a good start.

Let's imagine that we have the following directory layout:

<project>
  |
  - package.json
  - node_modules
  |    |
  |    - package1
  |         |
  |         - index.js
  |
  - dist <- dependency-tree `directory` argument
       |
       - package.json
       - src
            |
            - index.js  <- dependency-tree `filename` argument (path.join(..., 'dist', 'src', 'index.js'))
       - node_modules
            |
            - package2
                 |
                 - index.js
                 - node_modules
                      |
                      - package1
                           |
                           - index.js                      

I invoke dependency-tree with the following arguments:

{
  directory: path.join(<project>, 'dist'),
  filename: path.join(<project>, 'dist/src/index.js')
}

And index.js requires package2 module. Which, respectively, requires package1 module. The folder where package2 resides was initiated by the following command: npm i --global-style, i.e. dependencies of modules from package.json are put into local node_modules folders of each package. In other words - I want to maintain old-style node_modules directory layout (let's pretend that I like duplicates :) ), where each top-level module holds its modules with itself.

And here is the problem. Top level directory () also contains node_modules with package1. And when I receive output from dependency-tree I have something like this:

.../dist/src/index.js
.../dist/node_modules/package2/index.js
.../node_modules/package1/index.js

NOT:

.../dist/src/index.js
.../dist/node_modules/package2/index.js
.../dist/node_modules/package2/node_modules/package1/index.js

If I'm not mistaken this algorithm assumes the second variant (it starts to look at the nearest node_modules folder and traverses to the root of the file system).

Am I wrong or something works not as expected? I have some checks after receiving list from dependency-tree. One of them is confirmation that common directory for all imports is dist folder. And this check started to fall when I tried to use npm i command inside dist folder with --global-style argument. Without it (when package1 folder resides at the same level as package2) all works as expected.

Can you confirm that I'm wrong :) or help to resolve the issue?
Thanks in advance! CC: @mrjoelkemp

主要语言
JavaScript
星标
776
派生
82
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

dependents/node-dependency-tree 的其他 Issue

查看 dependents/node-dependency-tree 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。