Skip to content

Commit

Permalink
fix: root link (#30)
Browse files Browse the repository at this point in the history
fix the potential issue of abnormal project dependency linking in npminstall mode.
  • Loading branch information
elrrrrrrr authored Sep 13, 2023
1 parent df2369f commit dc2e78c
Show file tree
Hide file tree
Showing 10 changed files with 1,944 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,4 @@ package-lock.json

# napi-rs generate wrong type ignore for tmp
packages/binding/index.d.ts
.DS_Store
15 changes: 14 additions & 1 deletion packages/cli/lib/npm_fs/tnpm_fs_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,21 @@ class TnpmFsBuilder {
}

// 创建打平到 node_modules 依赖信息
// 优先取项目依赖中的版本
createFlattenDepLinks(name, version, originName, blobId) {
if (this.latestVersions.get(name) !== version) return;
const projectVersion = this.projectVersions.get(name);
// 如果在项目中已声明了依赖
// 则只 link 项目中声明的版本
if (projectVersion && projectVersion !== version) {
return;
}

// 对于间接依赖
// 才创建最新版的软链
if (!projectVersion && this.latestVersions.get(name) !== version) {
return;
}

const displayName = Util.getDisplayName({ name: originName, version }, this.mode);
const linkPath = path.relative(path.dirname(path.join('node_modules', name)), path.join('node_modules', displayName));
this.fsMeta.addEntry(blobId, Util.generateSymbolLink(name, linkPath, this.uid, this.gid, true));
Expand Down
102 changes: 102 additions & 0 deletions packages/cli/test/fixtures/npm_fs/package_link_root/npm.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"bucket_1.stgz": {
"version": 1,
"entries": [
{
"name": "@[email protected]/a",
"type": "reg",
"size": 11,
"linkName": "",
"mode": 493,
"uid": 0,
"gid": 0,
"uname": "",
"gname": "",
"offset": 512,
"devMajor": 0,
"devMinor": 0,
"xattrs": {},
"digest": "sha256:0282f76a4dc18a92bd8961e754874bc456191edfd08455f4cef50dba1cadaa50",
"chunkOffset": 0,
"chunkSize": 0
},
{
"name": "@[email protected]/package.json",
"type": "reg",
"size": 327,
"linkName": "",
"mode": 420,
"uid": 0,
"gid": 0,
"uname": "",
"gname": "",
"offset": 1536,
"devMajor": 0,
"devMinor": 0,
"xattrs": {},
"digest": "sha256:9c48eda3d378812c177d3226879fcbd9e6889452e88f87a3017fefb57d225ca1",
"chunkOffset": 0,
"chunkSize": 0
}
]
},
"bucket_0.stgz": {
"version": 1,
"entries": [
{
"name": "[email protected]/dist/bin/uuid",
"type": "reg",
"size": 44,
"linkName": "",
"mode": 493,
"uid": 0,
"gid": 0,
"uname": "",
"gname": "",
"offset": 512,
"devMajor": 0,
"devMinor": 0,
"xattrs": {},
"digest": "sha256:30b5422b6c95ccdc402effd7d3354ca6a6bce621cf21d0379749ddf1f96c1ad7",
"chunkOffset": 0,
"chunkSize": 0
},
{
"name": "[email protected]/dist/bin/uuid",
"type": "reg",
"size": 44,
"linkName": "",
"mode": 493,
"uid": 0,
"gid": 0,
"uname": "",
"gname": "",
"offset": 512,
"devMajor": 0,
"devMinor": 0,
"xattrs": {},
"digest": "sha256:30b5422b6c95ccdc402effd7d3354ca6a6bce621cf21d0379749ddf1f96c1ad7",
"chunkOffset": 0,
"chunkSize": 0
},
{
"name": "[email protected]/dist/bin/uuid",
"type": "reg",
"size": 44,
"linkName": "",
"mode": 493,
"uid": 0,
"gid": 0,
"uname": "",
"gname": "",
"offset": 512,
"devMajor": 0,
"devMinor": 0,
"xattrs": {},
"digest": "sha256:30b5422b6c95ccdc402effd7d3354ca6a6bce621cf21d0379749ddf1f96c1ad7",
"chunkOffset": 0,
"chunkSize": 0
}
]
}
}

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Loading

0 comments on commit dc2e78c

Please sign in to comment.