Skip to content

Commit

Permalink
fix(ruleset-bundler): virtualFs plugin not recognizing files (#2271)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip authored Oct 21, 2022
1 parent 921eb57 commit 4bc38b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
1 change: 1 addition & 0 deletions karma.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
14 changes: 4 additions & 10 deletions packages/ruleset-bundler/src/plugins/virtualFs.ts
Original file line number Diff line number Diff line change
@@ -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<PluginContext, string[]>();
const recognized = new Set();

return {
name: '@stoplight-spectral/virtual-fs',
Expand All @@ -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<string> | undefined {
if (!isURL(id) && recognized.get(this)?.includes(id) === true) {
if (!isURL(id) && recognized.has(id)) {
return fs.promises.readFile(id, 'utf8');
}

Expand Down

0 comments on commit 4bc38b3

Please sign in to comment.