Skip to content

Commit b0e3922

Browse files
authored
fix: don't skip resolving files imported by other plugins (#365)
- previously the `allImportedFiles` Set was _basically_ used to skip any files that were imported by other plugins - it only filtered out on `importer` (not `importee`) - this is a bit of a problem though, as other plugins that create JS code, or `allowJs` JS code, or heck, even regular JS code that Rollup processes without plugins, may actually import TS files - and Rollup's plugin system is designed to handle that scenario, so rpt2 actually _should_ resolve those files - notably, rpt2 already _transforms_ those files, it just didn't resolve them - which is why using `@rollup/plugin-node-resolve` with a `.ts` extension solved this as a workaround - the file would be resolved by `node-resolve` then actually transformed by rpt2 - but rpt2 should resolve TS files itself, `node-resolve` shouldn't be necessary - this caused the issue that extensionless imports from such files wouldn't get resolved to TS files and may cause Rollup to error - in particular, this popped up with extensionless imports of TS files from Svelte files - `resolveId` is actually the last remaining place where `allImportedFiles` was used - so after removing it from here, we can just remove it entirely - which should be a small optimization - for reference: - `allImportedFiles` would be any `include`d files as well as TS files that have been transformed (at this point in the build) and their references - this is a pretty gigantic list as is, so I'm actually not sure that removing this is actually that big of a de-opt - and it only affects mixed TS / non-TS codebases too - this seems to have been added in b0a0ecb, but that commit doesn't actually seem to fix the issue it references - see my root cause analyses in the issues
1 parent 4ea7f10 commit b0e3922

File tree

1 file changed

+0
-12
lines changed

1 file changed

+0
-12
lines changed

src/index.ts

-12
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
3535
let service: tsTypes.LanguageService;
3636
let noErrors = true;
3737
const declarations: { [name: string]: { type: tsTypes.OutputFile; map?: tsTypes.OutputFile } } = {};
38-
const allImportedFiles = new Set<string>();
3938

4039
let _cache: TsCache;
4140
const cache = (): TsCache =>
@@ -103,8 +102,6 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
103102

104103
if (generateRound === 0)
105104
{
106-
parsedConfig.fileNames.map(allImportedFiles.add, allImportedFiles);
107-
108105
context.info(`typescript version: ${tsModule.version}`);
109106
context.info(`tslib version: ${tslibVersion}`);
110107
if (this.meta)
@@ -156,10 +153,6 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
156153

157154
importer = normalize(importer);
158155

159-
// avoiding trying to resolve ids for things imported from files unrelated to this plugin
160-
if (!allImportedFiles.has(importer))
161-
return;
162-
163156
// TODO: use module resolution cache
164157
const result = tsModule.nodeModuleNameResolver(importee, importer, parsedConfig.options, tsModule.sys);
165158
let resolved = result.resolvedModule?.resolvedFileName;
@@ -197,8 +190,6 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
197190
if (!filter(id))
198191
return undefined;
199192

200-
allImportedFiles.add(normalize(id));
201-
202193
const contextWrapper = new RollupContext(pluginOptions.verbosity, pluginOptions.abortOnError, this, "rpt2: ");
203194

204195
const snapshot = servicesHost.setSnapshot(id, code);
@@ -229,9 +220,6 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
229220
if (!result)
230221
return undefined;
231222

232-
if (result.references)
233-
result.references.map(normalize).map(allImportedFiles.add, allImportedFiles);
234-
235223
if (watchMode && this.addWatchFile && result.references)
236224
{
237225
if (tsConfigPath)

0 commit comments

Comments
 (0)