Skip to content

Commit

Permalink
add svelte to packageImportFields (#1501)
Browse files Browse the repository at this point in the history
  • Loading branch information
firefish5000 committed Nov 5, 2020
1 parent 282ccf3 commit e3eca61
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions plugins/plugin-svelte/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = function plugin(snowpackConfig, pluginOptions = {}) {
snowpackConfig.installOptions.rollup.plugins.push(
svelteRollupPlugin({include: '**/node_modules/**', dev: isDev}),
);
// Support importing sharable Svelte components.
snowpackConfig.installOptions.packageLookupFields.push('svelte');

if (
pluginOptions.generate !== undefined ||
Expand Down
18 changes: 17 additions & 1 deletion plugins/plugin-svelte/test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ jest.mock('svelte/compiler', () => ({compile: mockCompiler, preprocess: mockPrep

const plugin = require('../plugin');

const mockConfig = {buildOptions: {sourceMaps: false}, installOptions: {rollup: {plugins: []}}};
let mockConfig;
const mockComponent = path.join(__dirname, 'Button.svelte');

describe('@snowpack/plugin-svelte (mocked)', () => {
beforeEach(()=>{
mockConfig = {
buildOptions: {sourceMaps: false},
installOptions: {
rollup: {plugins: []},
packageLookupFields: [],
},
};
})
afterEach(() => {
mockCompiler.mockClear();
mockPreprocessor.mockClear();
Expand Down Expand Up @@ -128,4 +137,11 @@ describe('@snowpack/plugin-svelte (mocked)', () => {
]
`);
});
it('supports importing svelte components', async () => {
plugin(mockConfig,{});
expect(mockConfig.installOptions.packageLookupFields).toEqual(['svelte']);
mockConfig.installOptions.packageLookupFields = ['module'];
plugin(mockConfig,{});
expect(mockConfig.installOptions.packageLookupFields).toEqual(['module', 'svelte']);
});
});

1 comment on commit e3eca61

@vercel
Copy link

@vercel vercel bot commented on e3eca61 Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.