From e3eca61fcb9e48df3f6560aedbdbe509e7039387 Mon Sep 17 00:00:00 2001 From: FireFish5000 <1813610+firefish5000@users.noreply.github.com> Date: Wed, 4 Nov 2020 23:53:47 -0600 Subject: [PATCH] add svelte to packageImportFields (#1501) --- plugins/plugin-svelte/plugin.js | 2 ++ plugins/plugin-svelte/test/plugin.test.js | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/plugin-svelte/plugin.js b/plugins/plugin-svelte/plugin.js index 969d4c36de..866b1e7194 100644 --- a/plugins/plugin-svelte/plugin.js +++ b/plugins/plugin-svelte/plugin.js @@ -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 || diff --git a/plugins/plugin-svelte/test/plugin.test.js b/plugins/plugin-svelte/test/plugin.test.js index 8521549ddf..6aa7422bb4 100644 --- a/plugins/plugin-svelte/test/plugin.test.js +++ b/plugins/plugin-svelte/test/plugin.test.js @@ -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(); @@ -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']); + }); });