diff --git a/karma.conf.ts b/karma.conf.ts index c10ac4b33..802b77af0 100644 --- a/karma.conf.ts +++ b/karma.conf.ts @@ -42,6 +42,7 @@ module.exports = (config: Config): void => { 'nimma/fallbacks': require.resolve('./node_modules/nimma/dist/legacy/cjs/fallbacks/index.js'), 'nimma/legacy': require.resolve('./node_modules/nimma/dist/legacy/cjs/index.js'), 'node-fetch': require.resolve('./__karma__/fetch'), + '^rollup$': 'rollup/dist/rollup.browser.js', fs: require.resolve('./__karma__/fs'), process: require.resolve('./__mocks__/process'), perf_hooks: require.resolve('./__karma__/perf_hooks'), diff --git a/packages/ruleset-bundler/src/plugins/virtualFs.ts b/packages/ruleset-bundler/src/plugins/virtualFs.ts index 6c64d851d..f5e737899 100644 --- a/packages/ruleset-bundler/src/plugins/virtualFs.ts +++ b/packages/ruleset-bundler/src/plugins/virtualFs.ts @@ -1,9 +1,9 @@ import { dirname, parse, join, normalize, isAbsolute, isURL } from '@stoplight/path'; -import type { Plugin, PluginContext } from 'rollup'; +import type { Plugin } from 'rollup'; import type { IO } from '../types'; export const virtualFs = ({ fs }: IO): Plugin => { - const recognized = new WeakMap(); + const recognized = new Set(); return { name: '@stoplight-spectral/virtual-fs', @@ -27,18 +27,12 @@ export const virtualFs = ({ fs }: IO): Plugin => { resolvedSource = join(dirname(importer), source); } - let existingEntries = recognized.get(this); - if (existingEntries === void 0) { - existingEntries = []; - recognized.set(this, existingEntries); - } - - existingEntries.push(resolvedSource); + recognized.add(resolvedSource); return resolvedSource; }, load(id): Promise | undefined { - if (!isURL(id) && recognized.get(this)?.includes(id) === true) { + if (!isURL(id) && recognized.has(id)) { return fs.promises.readFile(id, 'utf8'); }