Link shared libs to allow re-using them in both in public and fb-internal plugins

Summary:
Link plugin shared libraries to the "plugins/node_modules" dir so they can be used as peer dependencies by both public and fb-internal plugins.

```
plugins
- node_modules
-- fb_shared_lib (symlink pointing to "plugins/fb/fb_shared_lib")
-- public_shared_lib (symlink pointing to "plugins/public/public_shared_lib")
- fb
-- fb_shared_lib
-- fb_plugin (can now use both fb_shared_lib and public_shared_lib as peer dependencies)
- public
-- public_shared_lib
-- public_plugin (can now use both public_shared_lib and fb_shared_lib (optionally if it's an fb-internal repo) as peer dependencies)
```

Reviewed By: passy

Differential Revision: D27034936

fbshipit-source-id: 68ee5312060ff57649ae061dd7dd14f8beb6d4a1
This commit is contained in:
Anton Nikolaev
2021-04-09 05:15:14 -07:00
committed by Facebook GitHub Bot
parent 4997cb9847
commit e5261967cb
3 changed files with 64 additions and 1 deletions

View File

@@ -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()