fix(webpack): xml-namespace-loader incorrect dependency mapping (#9780)

This commit is contained in:
Igor Randjelovic
2022-03-03 09:38:27 +01:00
committed by GitHub
parent d3674de882
commit 151d6e8c85

View File

@@ -75,16 +75,22 @@ async function parseXML(content: string): Promise<ParseResult> {
const resolvePaths = [ const resolvePaths = [
localNamespacePath, localNamespacePath,
localModulePath, localModulePath,
`${localModulePath}.xml`,
moduleName, moduleName,
namespace, namespace,
`${moduleName}.xml`,
`~/${moduleName}`, `~/${moduleName}`,
`~/${namespace}`, `~/${namespace}`,
];
// fallbacks for codeless namespaces
const fallbackResolvePaths = [
`${localModulePath}.xml`,
`${moduleName}.xml`,
`~/${moduleName}.xml`, `~/${moduleName}.xml`,
]; ];
DEBUG && console.log({ resolvePaths });
DEBUG && console.log({ resolvePaths, fallbackResolvePaths });
let resolvedPath; let resolvedPath;
let isFallbackPath = false;
for (const p of resolvePaths) { for (const p of resolvePaths) {
resolvedPath = await resolveAsync(this.context, p).catch(noop); resolvedPath = await resolveAsync(this.context, p).catch(noop);
@@ -95,7 +101,23 @@ async function parseXML(content: string): Promise<ParseResult> {
} }
} }
DEBUG && console.log({ resolvedPath }); if (!resolvedPath) {
for (const p of fallbackResolvePaths) {
resolvedPath = await resolveAsync(this.context, p).catch(noop);
// break on first match
if (resolvedPath) {
isFallbackPath = true;
break;
}
}
}
DEBUG &&
console.log({
resolvedPath,
isFallbackPath,
});
// bail if we haven't resolved a path // bail if we haven't resolved a path
if (!resolvedPath) { if (!resolvedPath) {
@@ -104,10 +126,15 @@ async function parseXML(content: string): Promise<ParseResult> {
const { dir, name } = parse(resolvedPath); const { dir, name } = parse(resolvedPath);
// register resolved path + short name DEBUG && console.log({ namespace, moduleName });
namespaces.push({ name: namespace, path: resolvedPath });
namespaces.push({ name: moduleName, path: resolvedPath }); // check if we are not in a fallback path, in which case we shouldn't register it as a namespace
this.addDependency(resolvedPath); if (!isFallbackPath) {
// register resolved path + short name
namespaces.push({ name: namespace, path: resolvedPath });
namespaces.push({ name: moduleName, path: resolvedPath });
this.addDependency(resolvedPath);
}
const noExtFilename = join(dir, name); const noExtFilename = join(dir, name);