Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

fix: register XML-only custom components #537

Merged
merged 3 commits into from
May 24, 2018
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
2 changes: 1 addition & 1 deletion dependencyManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function addDependency(deps, name, version, force) {

function getRequiredDeps(packageJson) {
const deps = {
"webpack": "~4.8.3",
"webpack": "~4.6.0",
"webpack-cli": "~2.1.3",
"webpack-bundle-analyzer": "~2.13.0",
"webpack-sources": "~1.1.0",
Expand Down
50 changes: 35 additions & 15 deletions xml-namespace-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,58 @@ module.exports = function(source) {
let namespaces = [];
const parser = new XmlParser((event) => {
const { namespace, elementName } = event;
const moduleName = `${namespace}/${elementName}`;

if (
namespace &&
!namespace.startsWith("http") &&
!namespaces.some(n => n.name === namespace)
!namespaces.some(n => n.name === moduleName)
) {
const localNamespacePath = join(this.rootContext, namespace);
const localModulePath = join(localNamespacePath, elementName);
const resolvedPath = tryResolve(localNamespacePath) ||
tryResolve(localModulePath) ||
namespace;
tryResolve(localModulePath);

if (!resolvedPath) {
const xml = tryResolve(`${localModulePath}.xml`);
if (!xml) {
namespaces.push({ name: namespace, path: namespace });
namespaces.push({ name: moduleName, path: namespace });

return;
} else {
namespaces.push({ name: `${moduleName}.xml`, path: xml });
namespaces.push({ name: moduleName, path: xml });
this.addDependency(xml);
}

const css = tryResolve(`${localModulePath}.css`);
if (css) {
namespaces.push({ name: `${moduleName}.css`, path: css });
this.addDependency(css);
}

return;
}

this.addDependency(resolvedPath);
namespaces.push({ name: namespace, path: resolvedPath });

const moduleName = `${namespace}/${elementName}`;
namespaces.push({ name: namespace, path: resolvedPath });
namespaces.push({ name: moduleName, path: resolvedPath });

const { dir, name } = parse(resolvedPath);
const noExtFilename = join(dir, name);

const xmlFile = `${noExtFilename}.xml`;
const xmlFileResolved = tryResolve(xmlFile);
if (xmlFileResolved) {
this.addDependency(xmlFileResolved);
namespaces.push({ name: `${moduleName}.xml`, path: xmlFileResolved });
const xml = tryResolve(`${noExtFilename}.xml`);
if (xml) {
this.addDependency(xml);
namespaces.push({ name: `${moduleName}.xml`, path: xml });
}

const cssFile = `${noExtFilename}.css`;
const cssFileResolved = tryResolve(cssFile);
if (cssFileResolved) {
this.addDependency(cssFileResolved);
namespaces.push({ name: `${moduleName}.css`, path: cssFileResolved });
const css = tryResolve(`${noExtFilename}.css`);
if (css) {
this.addDependency(css);
namespaces.push({ name: `${moduleName}.css`, path: css });
}
}
}, undefined, true);
Expand Down Expand Up @@ -72,3 +91,4 @@ function tryResolve(path) {
return;
}
}