Skip to content

fix(@angular-devkit/build-angular): disable glob mounting for patterns that start with a forward slash #23472

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

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ async function findMatchingTests(

return globPromise(normalizedPattern, {
cwd: projectSourceRoot,
root: projectSourceRoot,
nomount: true,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
harness.expectFile(coveragePath).content.not.toContain('app.component.ts');
});

it('should exclude file from coverage when set when glob starts with a forward slash', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
codeCoverage: true,
codeCoverageExclude: ['/**/app.component.ts'],
});

const { result } = await harness.executeOnce();

expect(result?.success).toBeTrue();

await setTimeoutPromise(1000);
harness.expectFile(coveragePath).content.not.toContain('app.component.ts');
});

it('should not exclude file from coverage when set', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
test: 'glob with spec suffix',
input: ['**/*.pipe.spec.ts', '**/*.pipe.spec.ts', '**/*test.service.spec.ts'],
},
{
test: 'glob with forward slash and spec suffix',
input: ['/**/*test.service.spec.ts'],
},
].forEach((options, index) => {
it(`should work with ${options.test} (${index})`, async () => {
await harness.writeFiles({
Expand Down
11 changes: 5 additions & 6 deletions packages/angular_devkit/build_angular/src/utils/copy-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
import * as fs from 'fs';
import glob from 'glob';
import * as path from 'path';
import { promisify } from 'util';

function globAsync(pattern: string, options: glob.IOptions) {
return new Promise<string[]>((resolve, reject) =>
glob(pattern, options, (e, m) => (e ? reject(e) : resolve(m))),
);
}
const globPromise = promisify(glob);

export async function copyAssets(
entries: {
Expand All @@ -33,10 +30,12 @@ export async function copyAssets(

for (const entry of entries) {
const cwd = path.resolve(root, entry.input);
const files = await globAsync(entry.glob, {
const files = await globPromise(entry.glob, {
cwd,
dot: true,
nodir: true,
root: cwd,
nomount: true,
ignore: entry.ignore ? defaultIgnore.concat(entry.ignore) : defaultIgnore,
follow: entry.followSymlinks,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ export function assetNameTemplateFactory(hashFormat: HashFormat): (resourcePath:
}

export function getInstrumentationExcludedPaths(
sourceRoot: string,
root: string,
excludedPaths: string[],
): Set<string> {
const excluded = new Set<string>();

for (const excludeGlob of excludedPaths) {
glob
.sync(excludeGlob, { nodir: true, cwd: sourceRoot })
.forEach((p) => excluded.add(path.join(sourceRoot, p)));
.sync(excludeGlob, { nodir: true, cwd: root, root, nomount: true })
.forEach((p) => excluded.add(path.join(root, p)));
}

return excluded;
Expand Down