From 0ec50af39f02ae24c9159045d8fd3a1c2b8bbca0 Mon Sep 17 00:00:00 2001 From: Zyie <24736175+Zyie@users.noreply.github.com> Date: Thu, 8 Sep 2022 18:20:51 +0100 Subject: [PATCH] Fix injectGlobalMixins script (#8634) --- scripts/injectGlobalMixins.ts | 46 +++++++++++++---------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/scripts/injectGlobalMixins.ts b/scripts/injectGlobalMixins.ts index baafa6c52c..15ec0e9058 100644 --- a/scripts/injectGlobalMixins.ts +++ b/scripts/injectGlobalMixins.ts @@ -50,30 +50,19 @@ async function getPackages(result: SimplePackageJson[] = []): Promise { - let pixiLocation: string; - let pixiLegacyLocation: string; - let pixiGlobalMixins = ''; - let pixiLegacyGlobalMixins = ''; - const packages = await getPackages(); - const legacyPackages = Object.keys(packages.find((pkg) => pkg.name === 'pixi.js-legacy').dependencies); - const pixiPackages = Object.keys(packages.find((pkg) => pkg.name === 'pixi.js').dependencies); + const bundles = packages.filter((p) => p.location.includes('bundles')).map((p) => p.name); + const locations = Array(bundles.length).fill(''); + const mixins = Array(bundles.length).fill(''); + const pkgs = bundles.map((bundle) => Object.keys(packages.find((pkg) => pkg.name === bundle).dependencies)); packages.forEach((pkg) => { const basePath = path.relative(process.cwd(), pkg.location); - if (pkg.name === 'pixi.js') - { - pixiLocation = pkg.location; - - return; - } - if (pkg.name === 'pixi.js-legacy') + if (bundles.includes(pkg.name)) { - pixiLegacyLocation = pkg.location; - - return; + locations[bundles.indexOf(pkg.name)] = pkg.location; } const globalDtsPath = path.resolve(basePath, './global.d.ts'); @@ -83,25 +72,24 @@ async function start(): Promise const pixiTypeData = `/// \n`; const packageTypeData = `/// \n`; - if (pixiPackages.includes(pkg.name)) - { - pixiGlobalMixins += pixiTypeData; - } - else if (legacyPackages.includes(pkg.name)) + pkgs.forEach((pixiPkgs, index) => { - pixiLegacyGlobalMixins += pixiTypeData; - } + if (pixiPkgs.includes(pkg.name)) + { + mixins[index] += pixiTypeData; + } + }); writeToIndex(basePath, packageTypeData); } }); - // write the total types to the main packages - let basePath = path.relative(process.cwd(), pixiLocation); + locations.forEach((location, index) => + { + const basePath = path.relative(process.cwd(), location); - writeToIndex(basePath, pixiGlobalMixins); - basePath = path.relative(process.cwd(), pixiLegacyLocation); - writeToIndex(basePath, pixiLegacyGlobalMixins); + writeToIndex(basePath, mixins[index]); + }); } start();