-
Notifications
You must be signed in to change notification settings - Fork 11.9k
fix(@angular/build): fix setup files duplicate modules #31791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,7 @@ export async function findTests( | |
| return [...resolvedTestFiles]; | ||
| } | ||
|
|
||
| interface TestEntrypointsOptions { | ||
| interface EntrypointsOptions { | ||
| projectSourceRoot: string; | ||
| workspaceRoot: string; | ||
| removeTestExtension?: boolean; | ||
|
|
@@ -89,15 +89,49 @@ interface TestEntrypointsOptions { | |
| */ | ||
| export function getTestEntrypoints( | ||
| testFiles: string[], | ||
| { projectSourceRoot, workspaceRoot, removeTestExtension }: TestEntrypointsOptions, | ||
| { projectSourceRoot, workspaceRoot, removeTestExtension }: EntrypointsOptions, | ||
| ): Map<string, string> { | ||
| return getEntrypoints(testFiles, { | ||
| projectSourceRoot, | ||
| workspaceRoot, | ||
| removeTestExtension, | ||
| prefix: 'spec', | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * @param setupFiles An array of absolute paths to setup files. | ||
| * @param options Configuration options for generating entry points. | ||
| * @returns A map where keys are the generated unique bundle names and values are the original file paths. | ||
| */ | ||
| export function getSetupEntrypoints( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not happy with this. |
||
| setupFiles: string[], | ||
| { projectSourceRoot, workspaceRoot, removeTestExtension }: EntrypointsOptions, | ||
| ): Map<string, string> { | ||
| return getEntrypoints(setupFiles, { | ||
| projectSourceRoot, | ||
| workspaceRoot, | ||
| removeTestExtension, | ||
| prefix: 'setup', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This produces bundles named |
||
| }); | ||
| } | ||
|
|
||
| function getEntrypoints( | ||
| files: string[], | ||
| { | ||
| projectSourceRoot, | ||
| workspaceRoot, | ||
| removeTestExtension, | ||
| prefix, | ||
| }: EntrypointsOptions & { prefix: string }, | ||
| ): Map<string, string> { | ||
| const seen = new Set<string>(); | ||
| const roots = [projectSourceRoot, workspaceRoot]; | ||
|
|
||
| return new Map( | ||
| Array.from(testFiles, (testFile) => { | ||
| const fileName = generateNameFromPath(testFile, roots, !!removeTestExtension); | ||
| const baseName = `spec-${fileName}`; | ||
| Array.from(files, (setupFile) => { | ||
| const fileName = generateNameFromPath(setupFile, roots, !!removeTestExtension); | ||
| const baseName = `${prefix}-${fileName}`; | ||
| let uniqueName = baseName; | ||
| let suffix = 2; | ||
| while (seen.has(uniqueName)) { | ||
|
|
@@ -106,7 +140,7 @@ export function getTestEntrypoints( | |
| } | ||
| seen.add(uniqueName); | ||
|
|
||
| return [uniqueName, testFile]; | ||
| return [uniqueName, setupFile]; | ||
| }), | ||
| ); | ||
| } | ||
|
|
@@ -136,7 +170,7 @@ function generateNameFromPath( | |
| let endIndex = relativePath.length; | ||
| if (removeTestExtension) { | ||
| const infixes = TEST_FILE_INFIXES.map((p) => p.substring(1)).join('|'); | ||
| const match = relativePath.match(new RegExp(`\\.(${infixes})\\.[^.]+$`)); | ||
| const match = relativePath.match(new RegExp(`\\.((${infixes})\\.)?[^.]+$`)); | ||
|
|
||
| if (match?.index) { | ||
| endIndex = match.index; | ||
|
|
||