Skip to content

Commit 937c976

Browse files
Merge pull request #16 from snyk/fix/support-project-name-for-umbrella-projects
fix: support --project-name for umbrella projects
2 parents 55e7f6a + 81be8c5 commit 937c976

File tree

6 files changed

+2633
-214
lines changed

6 files changed

+2633
-214
lines changed

lib/inspect.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface Options {
66
debug?: boolean;
77
dev?: boolean;
88
file?: string;
9+
'project-name'?: string;
910
allProjects?: boolean; // if true, will not resolve apps if tested manifest is an umbrella project
1011
}
1112

@@ -28,18 +29,19 @@ export async function inspect(
2829
targetFile: string,
2930
options: Options = {},
3031
): Promise<MultiProjectResult> {
31-
const { debug, dev, allProjects } = options;
32+
const { debug, dev, allProjects, 'project-name': projectName } = options;
3233

3334
const [scanResult, pluginVersion] = await Promise.all([
34-
scan({ debug, dev, allProjects, path: root, targetFile }),
35+
scan({ debug, dev, allProjects, projectName, path: root, targetFile }),
3536
getPluginVersion(),
3637
]);
3738

3839
const scannedProjects = scanResult.scanResults.map(
39-
({ identity, facts: [{ data: depGraph }] }) => ({
40+
({ identity, facts: [{ data: depGraph }], name }) => ({
4041
packageManager: 'hex',
4142
targetFile: identity.targetFile!,
4243
depGraph,
44+
...(name ? { meta: { projectName: name } } : {}),
4345
}),
4446
);
4547

lib/scan.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,26 @@ export async function scan(options: Options): Promise<PluginResponse> {
4141
const scanResults = Object.entries(depGraphMap).map(
4242
([name, depGraph], index) => {
4343
const isRoot = index === 0;
44+
const relativePathToManifest = getRelativePathToManifest(
45+
options,
46+
targetFile,
47+
isRoot,
48+
name,
49+
);
4450
return {
4551
identity: {
4652
type: 'hex',
47-
targetFile: normalizePath(
48-
path.relative(
49-
options.path,
50-
path.resolve(targetFile.dir, isRoot ? '' : name, targetFile.base),
51-
),
52-
),
53+
targetFile: relativePathToManifest,
5354
},
5455
facts: [
5556
{
5657
type: 'depGraph',
5758
data: depGraph,
5859
},
5960
],
60-
...(isRoot && options.projectName ? { name: options.projectName } : {}),
61+
...(options.projectName
62+
? { name: getProjectNamePath(options, relativePathToManifest) }
63+
: {}),
6164
};
6265
},
6366
);
@@ -108,3 +111,24 @@ function normalizePath(filePath: string) {
108111
const parts = filePath.split(path.sep);
109112
return parts.join(path.posix.sep);
110113
}
114+
115+
function getRelativePathToManifest(
116+
options: Options,
117+
targetFile: path.ParsedPath,
118+
isRoot: boolean,
119+
name: string,
120+
) {
121+
return normalizePath(
122+
path.relative(
123+
options.path,
124+
path.resolve(targetFile.dir, isRoot ? '' : name, targetFile.base),
125+
),
126+
);
127+
}
128+
129+
function getProjectNamePath(options: Options, relativePathToManifest: string) {
130+
return [
131+
options.projectName,
132+
...relativePathToManifest.split('/').slice(1, -1),
133+
].join('/');
134+
}

0 commit comments

Comments
 (0)