Skip to content

Commit 1600692

Browse files
committed
feat(core): pass projectName to export-data
1 parent 4c5c873 commit 1600692

3 files changed

Lines changed: 46 additions & 15 deletions

File tree

packages/core/src/lib/api/get-project-data.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type ProjectDataEntry = {
1111
imports: string[];
1212
externalLibraries?: string[];
1313
unresolvedImports: string[];
14+
projectName: string;
1415
};
1516

1617
/**
@@ -77,6 +78,7 @@ function calcOrGetTags(
7778
*/
7879
export function getProjectData(
7980
entryFileAbsolute: string,
81+
projectName: string,
8082
options?: Options,
8183
): ProjectData;
8284
/**
@@ -112,28 +114,37 @@ export function getProjectData(
112114
export function getProjectData(
113115
entryFileRelative: string,
114116
cwd: string,
117+
projectName: string,
115118
options?: Options,
116119
): ProjectData;
117120

118121
export function getProjectData(
119122
entryFile: string,
120-
cwdOrOptions?: string | Options,
123+
cwdOrProjectName: string,
124+
projectNameOrOptions?: string | Options,
121125
optionalOptions?: Options,
122126
): ProjectData {
123127
const fs = getFs();
124-
const absoluteEntryFile =
125-
cwdOrOptions === undefined
126-
? entryFile
127-
: typeof cwdOrOptions === 'string'
128-
? fs.join(cwdOrOptions, entryFile)
129-
: entryFile;
130-
131-
const cwd = typeof cwdOrOptions === 'string' ? cwdOrOptions : undefined;
132-
const options = optionalOptions
133-
? optionalOptions
134-
: typeof cwdOrOptions === 'object'
135-
? cwdOrOptions
136-
: {};
128+
let absoluteEntryFile: string;
129+
let cwd: string | undefined;
130+
let projectName: string;
131+
let options: Options;
132+
133+
if (typeof cwdOrProjectName === 'string' && typeof projectNameOrOptions === 'string') {
134+
// Called with: (entryFile, cwd, projectName, options?)
135+
absoluteEntryFile = fs.join(cwdOrProjectName, entryFile);
136+
cwd = cwdOrProjectName;
137+
projectName = projectNameOrOptions;
138+
options = optionalOptions || {};
139+
} else if (typeof cwdOrProjectName === 'string' && typeof projectNameOrOptions === 'object') {
140+
// Called with: (entryFile, projectName, options)
141+
absoluteEntryFile = entryFile;
142+
cwd = undefined;
143+
projectName = cwdOrProjectName;
144+
options = projectNameOrOptions || {};
145+
} else {
146+
throw new Error('Invalid arguments to getProjectData');
147+
}
137148

138149
const projectInfo = init(toFsPath(absoluteEntryFile));
139150

@@ -147,6 +158,7 @@ export function getProjectData(
147158
tags: calcOrGetTags(fileInfo.moduleInfo.path, projectInfo, tagsCache),
148159
imports: fileInfo.imports.map((fileInfo) => fileInfo.path),
149160
unresolvedImports: fileInfo.unresolvableImports,
161+
projectName: projectName,
150162
};
151163

152164
if (options.includeExternalLibraries) {
@@ -183,6 +195,7 @@ function relativizeIfRequired(
183195
relative(toFsPath(importPath)),
184196
),
185197
unresolvedImports: moduleData.unresolvedImports,
198+
projectName: moduleData.projectName,
186199
};
187200

188201
if (options.includeExternalLibraries) {

packages/core/src/lib/cli/export-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function exportData(...args: string[]): void {
88
const projectEntries = getEntriesFromCliOrConfig(args[0], false);
99

1010
for (const entry of projectEntries) {
11-
const data = getProjectData(entry.entry, fs.cwd(), {
11+
const data = getProjectData(entry.entry, fs.cwd(), entry.projectName, {
1212
includeExternalLibraries: true,
1313
});
1414
cli.log(JSON.stringify(data, null, ' '));

packages/core/src/lib/cli/tests/__snapshots__/export-data.spec.ts.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ exports[`export data > should also work with a sheriff.config.ts > sheriff-confi
1313
"src/customers/index.ts"
1414
],
1515
"unresolvedImports": [],
16+
"projectName": "default",
1617
"externalLibraries": []
1718
},
1819
"src/holidays/index.ts": {
@@ -23,6 +24,7 @@ exports[`export data > should also work with a sheriff.config.ts > sheriff-confi
2324
],
2425
"imports": [],
2526
"unresolvedImports": [],
27+
"projectName": "default",
2628
"externalLibraries": []
2729
},
2830
"src/customers/index.ts": {
@@ -33,6 +35,7 @@ exports[`export data > should also work with a sheriff.config.ts > sheriff-confi
3335
],
3436
"imports": [],
3537
"unresolvedImports": [],
38+
"projectName": "default",
3639
"externalLibraries": []
3740
}
3841
}"
@@ -51,6 +54,7 @@ exports[`export data > should avoid circular dependencies > circular-dependencie
5154
"src/app2.service.ts"
5255
],
5356
"unresolvedImports": [],
57+
"projectName": "default",
5458
"externalLibraries": []
5559
},
5660
"src/app1.service.ts": {
@@ -63,6 +67,7 @@ exports[`export data > should avoid circular dependencies > circular-dependencie
6367
"src/app2.service.ts"
6468
],
6569
"unresolvedImports": [],
70+
"projectName": "default",
6671
"externalLibraries": []
6772
},
6873
"src/app2.service.ts": {
@@ -75,6 +80,7 @@ exports[`export data > should avoid circular dependencies > circular-dependencie
7580
"src/app1.service.ts"
7681
],
7782
"unresolvedImports": [],
83+
"projectName": "default",
7884
"externalLibraries": []
7985
}
8086
}"
@@ -92,6 +98,7 @@ exports[`export data > should show unresolved imports > unresolved-imports 1`] =
9298
"unresolvedImports": [
9399
"my-module"
94100
],
101+
"projectName": "default",
95102
"externalLibraries": []
96103
}
97104
}"
@@ -109,6 +116,7 @@ exports[`export data > should skip not reachable files > not-reachable-files 1`]
109116
"src/app1.service.ts"
110117
],
111118
"unresolvedImports": [],
119+
"projectName": "default",
112120
"externalLibraries": []
113121
},
114122
"src/app1.service.ts": {
@@ -119,6 +127,7 @@ exports[`export data > should skip not reachable files > not-reachable-files 1`]
119127
],
120128
"imports": [],
121129
"unresolvedImports": [],
130+
"projectName": "default",
122131
"externalLibraries": []
123132
}
124133
}"
@@ -136,6 +145,7 @@ exports[`export data > should test a simple application > simple-application 1`]
136145
"src/holidays/feature/index.ts"
137146
],
138147
"unresolvedImports": [],
148+
"projectName": "default",
139149
"externalLibraries": []
140150
},
141151
"src/holidays/feature/index.ts": {
@@ -149,6 +159,7 @@ exports[`export data > should test a simple application > simple-application 1`]
149159
"src/holidays/feature/holidays-container.component.ts"
150160
],
151161
"unresolvedImports": [],
162+
"projectName": "default",
152163
"externalLibraries": []
153164
},
154165
"src/holidays/feature/holidays-container.component.ts": {
@@ -164,6 +175,7 @@ exports[`export data > should test a simple application > simple-application 1`]
164175
"src/holidays/model/index.ts"
165176
],
166177
"unresolvedImports": [],
178+
"projectName": "default",
167179
"externalLibraries": [
168180
"@angular/common",
169181
"@angular/core",
@@ -181,6 +193,7 @@ exports[`export data > should test a simple application > simple-application 1`]
181193
"src/holidays/data/holidays-store.ts"
182194
],
183195
"unresolvedImports": [],
196+
"projectName": "default",
184197
"externalLibraries": []
185198
},
186199
"src/holidays/data/holidays-store.ts": {
@@ -194,6 +207,7 @@ exports[`export data > should test a simple application > simple-application 1`]
194207
"src/holidays/model/index.ts"
195208
],
196209
"unresolvedImports": [],
210+
"projectName": "default",
197211
"externalLibraries": [
198212
"@ngrx/signals"
199213
]
@@ -209,6 +223,7 @@ exports[`export data > should test a simple application > simple-application 1`]
209223
"src/holidays/model/holiday.ts"
210224
],
211225
"unresolvedImports": [],
226+
"projectName": "default",
212227
"externalLibraries": []
213228
},
214229
"src/holidays/model/holiday.ts": {
@@ -220,6 +235,7 @@ exports[`export data > should test a simple application > simple-application 1`]
220235
],
221236
"imports": [],
222237
"unresolvedImports": [],
238+
"projectName": "default",
223239
"externalLibraries": []
224240
},
225241
"src/holidays/ui/index.ts": {
@@ -233,6 +249,7 @@ exports[`export data > should test a simple application > simple-application 1`]
233249
"src/holidays/ui/holidays.component.ts"
234250
],
235251
"unresolvedImports": [],
252+
"projectName": "default",
236253
"externalLibraries": []
237254
},
238255
"src/holidays/ui/holidays.component.ts": {
@@ -246,6 +263,7 @@ exports[`export data > should test a simple application > simple-application 1`]
246263
"src/holidays/model/index.ts"
247264
],
248265
"unresolvedImports": [],
266+
"projectName": "default",
249267
"externalLibraries": []
250268
}
251269
}"

0 commit comments

Comments
 (0)