From 51980bd5aa3ec1994c8f8250b2004cb210b79b1c Mon Sep 17 00:00:00 2001 From: SukkaW Date: Wed, 29 Nov 2023 11:34:42 +0800 Subject: [PATCH] fix(#58): guard plugin resolution w/ `include` and `exclude` --- src/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index f879b71..8fbb096 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import type { Plugin as RollupPlugin } from 'rollup'; import fs from 'fs'; -import { extname, resolve, dirname, join } from 'path'; +import { extname, resolve, dirname, join, sep } from 'path'; import { createFilter, type FilterPattern } from '@rollup/pluginutils'; import type { Options as SwcOptions, @@ -75,7 +75,13 @@ function swc(options: PluginOptions = {}): RollupPlugin { return null; } - if (importer && importee.startsWith('.')) { + // If the importer (the module that is importing the importee) should not be handled by this plugin, + // we skip the resolution to avoid the issue like https://github.com/SukkaW/rollup-plugin-swc/issues/58 + if (!filter(importer)) { + return null; + } + + if (importer && importee[0] === '.') { const resolved = resolve( importer ? dirname(importer) : process.cwd(), importee