Skip to content

Commit 738ac9d

Browse files
authored
Merge pull request #283 from snyk/fix/add-alias-in-graph-yarn
fix: add missing alias labels in yarn [SOSE-22]
2 parents 924740d + 621f791 commit 738ac9d

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

lib/dep-graph-builders/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export const getChildNode = (
163163
dependencies: {},
164164
isDev: depInfo.isDev,
165165
missingLockFileEntry: true,
166+
alias: depInfo.alias,
166167
};
167168
}
168169
} else {
@@ -180,6 +181,7 @@ export const getChildNode = (
180181
version: depData.version,
181182
dependencies: { ...dependencies, ...optionalDependencies },
182183
isDev: depInfo.isDev,
184+
alias: depInfo.alias,
183185
};
184186
}
185187

lib/dep-graph-builders/yarn-lock-v1/build-depgraph-simple.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ const dfsVisit = async (
109109
...(node.missingLockFileEntry && {
110110
missingLockFileEntry: 'true',
111111
}),
112+
...(childNode.alias && {
113+
alias: `${childNode.alias.aliasName}=>${childNode.alias.aliasTargetDepName}@${childNode.version}`,
114+
}),
112115
},
113116
},
114117
);
@@ -128,6 +131,9 @@ const dfsVisit = async (
128131
...(node.missingLockFileEntry && {
129132
missingLockFileEntry: 'true',
130133
}),
134+
...(childNode.alias && {
135+
alias: `${childNode.alias.aliasName}=>${childNode.alias.aliasTargetDepName}@${childNode.version}`,
136+
}),
131137
},
132138
},
133139
);

lib/dep-graph-builders/yarn-lock-v2/build-depgraph-simple.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ const dfsVisit = async (
123123
...(node.missingLockFileEntry && {
124124
missingLockFileEntry: 'true',
125125
}),
126+
...(childNode.alias && {
127+
alias: `${childNode.alias.aliasName}=>${childNode.alias.aliasTargetDepName}@${childNode.version}`,
128+
}),
126129
},
127130
},
128131
);
@@ -142,6 +145,9 @@ const dfsVisit = async (
142145
...(node.missingLockFileEntry && {
143146
missingLockFileEntry: 'true',
144147
}),
148+
...(childNode.alias && {
149+
alias: `${childNode.alias.aliasName}=>${childNode.alias.aliasTargetDepName}@${childNode.version}`,
150+
}),
145151
},
146152
},
147153
);

test/jest/dep-graph-builders/aliases.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ describe('Testing aliases for yarn', () => {
3636
const pkgs = newDepGraph.getPkgs();
3737
expect(pkgs.some((x) => x.name === 'pkg')).toBeFalsy();
3838
expect(pkgs.some((x) => x.name === '@yao-pkg/pkg')).toBeTruthy();
39+
expect(JSON.stringify(newDepGraph)).toContain(
40+
'"alias":"pkg=>@yao-pkg/[email protected]"',
41+
);
3942
});
4043

4144
it('match aliased package also used in transitive deps - yarn-lock-v1', async () => {
@@ -170,6 +173,9 @@ describe('Testing aliases for yarn', () => {
170173
const pkgs = newDepGraph.getPkgs();
171174
expect(pkgs.some((x) => x.name === 'pkg')).toBeFalsy();
172175
expect(pkgs.some((x) => x.name === '@yao-pkg/pkg')).toBeTruthy();
176+
expect(JSON.stringify(newDepGraph)).toContain(
177+
'"alias":"pkg=>@yao-pkg/[email protected]"',
178+
);
173179
});
174180

175181
it('match aliased package also used in transitive deps - yarn-lock-v2', async () => {

test/jest/dep-graph-builders/fixtures/yarn-lock-v2/real/git-remote-url/expected.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,8 @@
13301330
"deps": [],
13311331
"info": {
13321332
"labels": {
1333-
"scope": "prod"
1333+
"scope": "prod",
1334+
"alias": "ms=>[email protected]"
13341335
}
13351336
}
13361337
},

0 commit comments

Comments
 (0)