Handle resolving JSDOM promises better
This commit is contained in:
parent
acb0b75516
commit
71db01f9a2
@ -125,17 +125,17 @@ const resolveImportedSvg = {
|
||||
build.onLoad({ filter: /\.svg$/ }, async (args) => {
|
||||
const document = (await JSDOM.fromFile(args.path)).window.document;
|
||||
const externalResourceUseEls = Array.from(document.querySelectorAll('use[href*=".svg"'));
|
||||
const readFiles = {};
|
||||
|
||||
const files = [...new Set([...externalResourceUseEls.map(el =>
|
||||
el.getAttributeNS(null, 'href').match(/.+\.svg/).at(0)
|
||||
)])];
|
||||
|
||||
await Promise.all(files.map((filename) =>
|
||||
JSDOM
|
||||
.fromFile(path.join(path.dirname(args.path), filename))
|
||||
.then(dom => readFiles[filename] = dom.window.document)
|
||||
));
|
||||
const readFiles = await Promise.all(
|
||||
files.map(filename => JSDOM.fromFile(path.join(path.dirname(args.path), filename)))
|
||||
).then(result => result.reduce((acc, dom, index) => {
|
||||
acc[files[index]] = dom.window.document;
|
||||
return acc;
|
||||
}, {}));
|
||||
|
||||
const refs = {};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user