From c628ad7cbdafc0a9b533e60b998c9613c3e31b64 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Mon, 15 Jun 2020 07:28:12 -0700 Subject: [PATCH] Fixed check for requires outside of plugin folder when shared library is used Summary: There was a error on bundling plugins which references a shared lib, because of wrong check during babel transformation. Reviewed By: passy Differential Revision: D22041443 fbshipit-source-id: c157675c05e9d9653b65ed30293e3b8b09bae260 --- .../src/plugin-flipper-requires.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/desktop/babel-transformer/src/plugin-flipper-requires.ts b/desktop/babel-transformer/src/plugin-flipper-requires.ts index 41ae79e4d..d8217f86a 100644 --- a/desktop/babel-transformer/src/plugin-flipper-requires.ts +++ b/desktop/babel-transformer/src/plugin-flipper-requires.ts @@ -46,20 +46,21 @@ module.exports = () => ({ // require a file not a pacakge args[0].value.indexOf('/') > -1 && // in the plugin itself and not inside one of its dependencies - state.file.opts.filename.indexOf('node_modules') === -1 && + state.file.opts.filename.startsWith(state.file.opts.root) && // the resolved path for this file is outside the plugins root - !resolve( + !resolve(dirname(state.file.opts.filename), args[0].value).startsWith( state.file.opts.root, - dirname(state.file.opts.filename), - args[0].value, - ).startsWith(state.file.opts.root) + ) ) { throw new Error( - `Plugins cannot require files from outside their folder. Attempted to require ${resolve( - state.file.opts.root, - dirname(state.file.opts.filename), - args[0].value, - )} which isn't inside ${state.file.opts.root}`, + `Plugins cannot require files from outside their folder. ` + + `Attempted to require "${args[0].value}" ` + + `from file "${state.file.opts.filename}" resolved to ` + + `"${resolve( + dirname(state.file.opts.filename), + args[0].value, + )}" ` + + `which isn't inside plugin dir "${state.file.opts.root}".`, ); } }