diff --git a/desktop/plugins/package.json b/desktop/plugins/package.json index eef280b6d..b190ca7f5 100644 --- a/desktop/plugins/package.json +++ b/desktop/plugins/package.json @@ -7,7 +7,8 @@ "url": "https://fb.workplace.com/groups/flippersupport/" }, "devDependencies": { - "fs-extra": "^9.0.1" + "fs-extra": "^9.0.1", + "p-map": "^4.0.0" }, "scripts": { "postinstall": "../ts-node ./postinstall.ts" diff --git a/desktop/plugins/postinstall.ts b/desktop/plugins/postinstall.ts index a0206a9d2..3c35a5148 100644 --- a/desktop/plugins/postinstall.ts +++ b/desktop/plugins/postinstall.ts @@ -10,6 +10,7 @@ import {execSync} from 'child_process'; import path from 'path'; import fs from 'fs-extra'; +import pmap from 'p-map'; async function postinstall() { const publicPluginsDir = path.join(__dirname, 'public'); @@ -24,6 +25,42 @@ async function postinstall() { stdio: 'inherit', }); } + const [publicPackages, fbPackages] = await Promise.all([ + fs.readdir(publicPluginsDir), + fs.readdir(fbPluginsDir).catch(() => [] as string[]), + ]); + const packages = [ + ...publicPackages.map((p) => path.join(publicPluginsDir, p)), + ...fbPackages.map((p) => path.join(fbPluginsDir, p)), + ]; + const modulesDir = path.join(__dirname, 'node_modules'); + await pmap(packages, async (packageDir) => { + const packageJsonPath = path.join(packageDir, 'package.json'); + if (!(await fs.pathExists(packageJsonPath))) { + return; + } + const packageJson = await fs.readJson( + path.join(packageDir, 'package.json'), + ); + if ( + packageJson.keywords && + packageJson.keywords.includes('flipper-plugin') + ) { + return; + } + const destPath = path.join(modulesDir, packageJson.name); + console.log( + `linking ${path.relative(__dirname, destPath)} to ${path.relative( + __dirname, + packageDir, + )}`, + ); + if (await fs.pathExists(destPath)) { + return; + } + await fs.ensureDir(path.dirname(destPath)); + await fs.symlink(packageDir, destPath, 'junction'); + }); } postinstall() diff --git a/desktop/plugins/yarn.lock b/desktop/plugins/yarn.lock index 42cbe29ab..97e51c0a0 100644 --- a/desktop/plugins/yarn.lock +++ b/desktop/plugins/yarn.lock @@ -2,11 +2,24 @@ # yarn lockfile v1 +aggregate-error@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/aggregate-error/-/aggregate-error-3.1.0.tgz#92670ff50f5359bdb7a3e0d40d0ec30c5737687a" + integrity sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA== + dependencies: + clean-stack "^2.0.0" + indent-string "^4.0.0" + at-least-node@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2" integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg== +clean-stack@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b" + integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A== + fs-extra@^9.0.1: version "9.0.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc" @@ -22,6 +35,11 @@ graceful-fs@^4.1.6, graceful-fs@^4.2.0: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb" integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw== +indent-string@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-4.0.0.tgz#624f8f4497d619b2d9768531d58f4122854d7251" + integrity sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg== + jsonfile@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.0.1.tgz#98966cba214378c8c84b82e085907b40bf614179" @@ -31,6 +49,13 @@ jsonfile@^6.0.1: optionalDependencies: graceful-fs "^4.1.6" +p-map@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/p-map/-/p-map-4.0.0.tgz#bb2f95a5eda2ec168ec9274e06a747c3e2904d2b" + integrity sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ== + dependencies: + aggregate-error "^3.0.0" + universalify@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d"