-
Notifications
You must be signed in to change notification settings - Fork 11.9k
fix(@angular/build): remap metafile paths when workspace root is a symlink or junction #33584
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
Open
Arul1998
wants to merge
2
commits into
angular:main
Choose a base branch
from
Arul1998:fix/junction-workspace-root-metafile
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+179
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
packages/angular/build/src/tools/esbuild/bundler-context_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import type { Metafile } from 'esbuild'; | ||
| import { join, relative } from 'node:path'; | ||
| import { remapMetafileBasePath } from './bundler-context'; | ||
|
|
||
| describe('remapMetafileBasePath', () => { | ||
| // Simulates a workspace root accessed through a symbolic link or Windows | ||
| // directory junction (`toBase`) that resolves to a different real path | ||
| // (`fromBase`), as esbuild resolves its working directory through links. | ||
| const fromBase = join('/real', 'projects', 'demo'); | ||
| const toBase = join('/linked', 'demo'); | ||
|
|
||
| /** Creates a metafile path as esbuild would: relative to the resolved (real) base. */ | ||
| const fromBaseRelative = (filePath: string): string => relative(fromBase, join(toBase, filePath)); | ||
|
|
||
| it('remaps input and output paths onto the target base directory', () => { | ||
| const metafile: Metafile = { | ||
| inputs: { | ||
| [fromBaseRelative('src/main.ts')]: { bytes: 10, imports: [] }, | ||
| }, | ||
| outputs: { | ||
| [fromBaseRelative('main.js')]: { | ||
| bytes: 100, | ||
| inputs: { [fromBaseRelative('src/main.ts')]: { bytesInOutput: 10 } }, | ||
| imports: [{ path: fromBaseRelative('chunk-ABC.js'), kind: 'import-statement' }], | ||
| exports: [], | ||
| entryPoint: fromBaseRelative('src/main.ts'), | ||
| cssBundle: fromBaseRelative('main.css'), | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| remapMetafileBasePath(metafile, fromBase, toBase); | ||
|
|
||
| expect(Object.keys(metafile.inputs)).toEqual(['src/main.ts']); | ||
| expect(Object.keys(metafile.outputs)).toEqual(['main.js']); | ||
|
|
||
| const output = metafile.outputs['main.js']; | ||
| expect(output.entryPoint).toBe('src/main.ts'); | ||
| expect(output.cssBundle).toBe('main.css'); | ||
| expect(Object.keys(output.inputs)).toEqual(['src/main.ts']); | ||
| expect(output.imports[0].path).toBe('chunk-ABC.js'); | ||
| }); | ||
|
Comment on lines
+23
to
+50
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. Add a test assertion to verify that the it('remaps input and output paths onto the target base directory', () => {
const metafile: Metafile = {
inputs: {
[fromBaseRelative('src/main.ts')]: { bytes: 10, imports: [] },
},
outputs: {
[fromBaseRelative('main.js')]: {
bytes: 100,
inputs: { [fromBaseRelative('src/main.ts')]: { bytesInOutput: 10 } },
imports: [{ path: fromBaseRelative('chunk-ABC.js'), kind: 'import-statement' }],
exports: [],
entryPoint: fromBaseRelative('src/main.ts'),
cssBundle: fromBaseRelative('main.css'),
},
},
};
remapMetafileBasePath(metafile, fromBase, toBase);
expect(Object.keys(metafile.inputs)).toEqual(['src/main.ts']);
expect(Object.keys(metafile.outputs)).toEqual(['main.js']);
const output = metafile.outputs['main.js'];
expect(output.entryPoint).toBe('src/main.ts');
expect(output.cssBundle).toBe('main.css');
expect(Object.keys(output.inputs)).toEqual(['src/main.ts']);
expect(output.imports[0].path).toBe('chunk-ABC.js');
}); |
||
|
|
||
| it('does not modify virtual and namespaced files', () => { | ||
| const metafile: Metafile = { | ||
| inputs: { | ||
| 'angular:polyfills': { | ||
| bytes: 10, | ||
| imports: [{ path: '<runtime>', kind: 'import-statement' }], | ||
| }, | ||
| }, | ||
| outputs: { | ||
| [fromBaseRelative('polyfills.js')]: { | ||
| bytes: 100, | ||
| inputs: { 'angular:polyfills': { bytesInOutput: 10 } }, | ||
| imports: [], | ||
| exports: [], | ||
| entryPoint: 'angular:polyfills', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| remapMetafileBasePath(metafile, fromBase, toBase); | ||
|
|
||
| expect(Object.keys(metafile.inputs)).toEqual(['angular:polyfills']); | ||
| expect(metafile.inputs['angular:polyfills'].imports[0].path).toBe('<runtime>'); | ||
|
|
||
| const output = metafile.outputs['polyfills.js']; | ||
| expect(output.entryPoint).toBe('angular:polyfills'); | ||
| expect(Object.keys(output.inputs)).toEqual(['angular:polyfills']); | ||
| }); | ||
|
|
||
| it('does not modify external imports', () => { | ||
| const externalPath = 'https://example.com/module.js'; | ||
| const metafile: Metafile = { | ||
| inputs: {}, | ||
| outputs: { | ||
| [fromBaseRelative('main.js')]: { | ||
| bytes: 100, | ||
| inputs: {}, | ||
| imports: [{ path: externalPath, kind: 'import-statement', external: true }], | ||
| exports: [], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| remapMetafileBasePath(metafile, fromBase, toBase); | ||
|
|
||
| expect(metafile.outputs['main.js'].imports[0].path).toBe(externalPath); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
cssBundleproperty in esbuild's metafile outputs contains a relative path to the generated CSS bundle from the working directory. WhenpreserveSymlinksis enabled, this path will also be relative to the resolved base directory (fromBase) rather than the workspace root (toBase). We should remapcssBundleas well to ensure all relative paths in the metafile are correctly remapped.