Skip to content

Commit 6e6d0de

Browse files
committed
feat(ruleset-bundler): skypack plugin accepts ignore list (#2318)
1 parent caedff1 commit 6e6d0de

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

packages/ruleset-bundler/src/plugins/__tests__/skypack.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,38 @@ fs.writeFileSync(path.join(__dirname, './output.js'), 'export default {}');
124124
`);
125125
});
126126
});
127+
128+
it('should respect ignore list', async () => {
129+
serveAssets({
130+
'/tmp/input.js': `import { createRulesetFunction } from '@stoplight/spectral-core/ruleset/validation';
131+
import { parse } from '@stoplight/yaml';
132+
import { isPlainObject } from '@stoplight/json';
133+
134+
export default createRulesetFunction({}, input => {
135+
assert.ok(isPlainObject(parse(input)));
136+
})
137+
`,
138+
});
139+
140+
const code = await bundleRuleset('/tmp/input.js', {
141+
target: 'browser',
142+
plugins: [
143+
skypack({
144+
ignoreList: [/^@stoplight\/spectral-/, '@stoplight/json'],
145+
}),
146+
virtualFs(io),
147+
],
148+
});
149+
150+
expect(code).toEqual(`import { createRulesetFunction } from '@stoplight/spectral-core/ruleset/validation';
151+
import { parse } from 'https://cdn.skypack.dev/@stoplight/yaml';
152+
import { isPlainObject } from '@stoplight/json';
153+
154+
var input = createRulesetFunction({}, input => {
155+
assert.ok(isPlainObject(parse(input)));
156+
});
157+
158+
export { input as default };
159+
`);
160+
});
127161
});

packages/ruleset-bundler/src/plugins/skypack.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ import { isURL } from '@stoplight/path';
44

55
const DATA_URIS = /^(?:data|node|file):/;
66

7-
export const skypack = (): Plugin => ({
8-
name: '@stoplight-spectral/skypack',
9-
resolveId(id) {
10-
if (DATA_URIS.test(id) || isURL(id)) return;
7+
export const skypack = (opts?: { ignoreList?: (string | RegExp)[] }): Plugin => {
8+
return <Plugin>{
9+
name: '@stoplight-spectral/skypack',
10+
resolveId(id) {
11+
if (DATA_URIS.test(id) || isURL(id)) return;
1112

12-
if (isPackageImport(id)) {
13-
return `https://cdn.skypack.dev/${id}`;
14-
}
13+
const isIgnored =
14+
opts?.ignoreList !== void 0 &&
15+
opts.ignoreList.some(ignored => (typeof ignored === 'string' ? ignored === id : ignored.test(id)));
1516

16-
return;
17-
},
18-
});
17+
if (!isIgnored && isPackageImport(id)) {
18+
return `https://cdn.skypack.dev/${id}`;
19+
}
20+
21+
return;
22+
},
23+
};
24+
};

0 commit comments

Comments
 (0)