From b6481cb63b83f07a772f3af129452b9fe913b358 Mon Sep 17 00:00:00 2001 From: Huckleberry Date: Thu, 26 Dec 2024 16:40:33 +0900 Subject: [PATCH] feat: add includes babel plugin option for node module whitelist --- plugin/import.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugin/import.js b/plugin/import.js index f6c827a3..43829fc8 100644 --- a/plugin/import.js +++ b/plugin/import.js @@ -63,7 +63,19 @@ function addUnistylesImport(t, path, state) { nodesToRemove.forEach(node => path.node.body.splice(path.node.body.indexOf(node), 1)) } -const isInsideNodeModules = state => state.file.opts.filename.includes('node_modules') +const isInsideNodeModules = (state) => { + const isNodeModule = state.file.opts.filename.includes('node_modules'); + + if (Array.isArray(state.opts.includes) && isNodeModule) { + const isIncludedNodeModule = state.opts.includes.some((pkg) => + state.file.opts.filename.includes(`node_modules/${pkg}`), + ); + + return !isIncludedNodeModule; + } + + return isNodeModule; +}; module.exports = { isInsideNodeModules,