Skip to content

Commit eaeef05

Browse files
committed
fix(@angular-devkit/build-angular): disable glob mounting for patterns that start with a forward slash
By default, a glob pattern starting with a forward slash will be "mounted" onto the system root. This causes globs to escape the workspace root. With this change we configure disable glob "mounting". Closes angular#23467
1 parent 54551bb commit eaeef05

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

packages/angular_devkit/build_angular/src/builders/karma/tests/options/code-coverage-exclude_spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
3737
harness.expectFile(coveragePath).content.not.toContain('app.component.ts');
3838
});
3939

40+
it('should exclude file from coverage when set when glob starts with a forward slash', async () => {
41+
harness.useTarget('test', {
42+
...BASE_OPTIONS,
43+
codeCoverage: true,
44+
codeCoverageExclude: ['/**/app.component.ts'],
45+
});
46+
47+
const { result } = await harness.executeOnce();
48+
49+
expect(result?.success).toBeTrue();
50+
51+
await setTimeoutPromise(1000);
52+
harness.expectFile(coveragePath).content.not.toContain('app.component.ts');
53+
});
54+
4055
it('should not exclude file from coverage when set', async () => {
4156
harness.useTarget('test', {
4257
...BASE_OPTIONS,

packages/angular_devkit/build_angular/src/utils/copy-assets.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function copyAssets(
3737
cwd,
3838
dot: true,
3939
nodir: true,
40+
nomount: true,
4041
ignore: entry.ignore ? defaultIgnore.concat(entry.ignore) : defaultIgnore,
4142
follow: entry.followSymlinks,
4243
});

packages/angular_devkit/build_angular/src/webpack/utils/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export function getInstrumentationExcludedPaths(
128128

129129
for (const excludeGlob of excludedPaths) {
130130
glob
131-
.sync(excludeGlob, { nodir: true, cwd: sourceRoot })
131+
.sync(excludeGlob, { nodir: true, cwd: sourceRoot, nomount: true })
132132
.forEach((p) => excluded.add(path.join(sourceRoot, p)));
133133
}
134134

0 commit comments

Comments
 (0)