Skip to content

Fix a compilation error that occurs when the "paths" option is not set but "baseUrl" is #9673

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

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 19 additions & 17 deletions packages/@ngtools/webpack/src/paths-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,25 @@ export function resolveWithPaths(
}

// check if any path mapping rules are relevant
const isPathMapped = compilerOptions.paths && Object.keys(compilerOptions.paths)
.some(pattern => {
// can only contain zero or one
const starIndex = pattern.indexOf('*');
if (starIndex === -1) {
return pattern === request.request;
} else if (starIndex === pattern.length - 1) {
return request.request.startsWith(pattern.slice(0, -1));
} else {
const [prefix, suffix] = pattern.split('*');
return request.request.startsWith(prefix) && request.request.endsWith(suffix);
}
});

if (!isPathMapped) {
callback(null, request);
return;
if (compilerOptions.paths) {
const isPathMapped = Object.keys(compilerOptions.paths)
.some(pattern => {
// can only contain zero or one
const starIndex = pattern.indexOf('*');
if (starIndex === -1) {
return pattern === request.request;
} else if (starIndex === pattern.length - 1) {
return request.request.startsWith(pattern.slice(0, -1));
} else {
const [prefix, suffix] = pattern.split('*');
return request.request.startsWith(prefix) && request.request.endsWith(suffix);
}
});

if (!isPathMapped) {
callback(null, request);
return;
}
}

const moduleResolver = ts.resolveModuleName(
Expand Down