Skip to content

Commit b1e4cb5

Browse files
authored
chore: remove package.json export warning (#272)
1 parent 6d3c707 commit b1e4cb5

File tree

3 files changed

+9
-25
lines changed

3 files changed

+9
-25
lines changed

.changeset/famous-pets-tell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
don't warn if dependency doesn't export package.json

packages/vite-plugin-svelte/src/index.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin {
2727
}
2828
validateInlineOptions(inlineOptions);
2929
const cache = new VitePluginSvelteCache();
30-
const pkg_resolve_errors = new Set();
3130
// updated in configResolved hook
3231
let requestParser: IdParser;
3332
let options: ResolvedOptions;
@@ -136,14 +135,10 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin {
136135
return resolvedSvelteSSR;
137136
}
138137

139-
try {
140-
const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
141-
if (resolved) {
142-
log.debug(`resolveId resolved ${resolved} via package.json svelte field of ${importee}`);
143-
return resolved;
144-
}
145-
} catch (err) {
146-
pkg_resolve_errors.add(importee);
138+
const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
139+
if (resolved) {
140+
log.debug(`resolveId resolved ${resolved} via package.json svelte field of ${importee}`);
141+
return resolved;
147142
}
148143
},
149144

@@ -191,20 +186,6 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin {
191186
if (svelteRequest) {
192187
return handleHotUpdate(compileSvelte, ctx, svelteRequest, cache, options);
193188
}
194-
},
195-
196-
/**
197-
* All resolutions done; display warnings wrt `package.json` access.
198-
*/
199-
// TODO generateBundle isn't called by vite, is buildEnd enough or should it be logged once per violation in resolve
200-
buildEnd() {
201-
if (pkg_resolve_errors.size > 0) {
202-
log.warn(
203-
`vite-plugin-svelte was unable to find package.json of the following packages and wasn't able to resolve via their "svelte" field.
204-
If you had difficulties importing svelte components from a package, then please contact the author and ask them to export the package.json file.
205-
${Array.from(pkg_resolve_errors, (s) => `- ${s}`).join('\n')}`.replace(/\t/g, '')
206-
);
207-
}
208189
}
209190
};
210191
}

packages/vite-plugin-svelte/src/utils/resolve.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export function resolveViaPackageJsonSvelte(
2727
cache.setResolvedSvelteField(importee, importer, result);
2828
return result;
2929
}
30-
} else {
31-
throw new Error(`failed to resolve package.json of ${importee} imported by ${importer}`);
3230
}
3331
}
3432
}

0 commit comments

Comments
 (0)