Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve support for svelte npm packages #1908

Merged
merged 1 commit into from
Dec 11, 2020

Conversation

FredKSchott
Copy link
Owner

Changes

Testing

  • Tests added.

Docs

  • N/A

@vercel
Copy link

vercel bot commented Dec 11, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/62czmr771
✅ Preview: https://snowpack-git-svelte-plugin-esinstall-fix.pikapkg.vercel.app

@@ -45,7 +45,7 @@ export {printStats} from './stats';

type DependencyLoc =
| {
type: 'JS';
type: 'BUNDLE';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Iiiiiinteresting

@@ -359,7 +359,7 @@ export async function install(
cwd,
packageLookupFields,
});
if (resolvedResult.type === 'JS') {
if (resolvedResult.type === 'BUNDLE') {
Copy link
Collaborator

@drwpow drwpow Dec 11, 2020

Choose a reason for hiding this comment

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

Do we not need JS handling anymore? Edit: oh nvm; it was just renamed

Copy link
Owner Author

Choose a reason for hiding this comment

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

yea, renamed to something more inclusive of files like .svelte. Basically: should this be bundled by Rollup, or should this be copied over 1:1 as an asset and not passed through rollup.

return 'BUNDLE';
}
// All other files should be treated as assets (copied over directly).
return 'ASSET';
Copy link
Collaborator

Choose a reason for hiding this comment

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

So do we not need to handle JSX/TSX because of built-in support from esbuild? Curious if that’s really a different strategy than this (though JSX not carrying CSS seems different enough on its own)

Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't think we have a real use-case for a user publishing JSX/TSX in a package. Remember, this is just a way to properly categorize npm package entrypoints.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we have a real use-case for a user publishing JSX/TSX in a package.

I can say myself that I’ve tried, and been punished by webpack 😅 . I think just as a consequence of the ecosystem I’d guess most popular React packages have been forced to prebundle JSX and this statement is correct

Copy link
Owner Author

Choose a reason for hiding this comment

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

yea that's fair enough, and we want that error to be reported instead of the JSX file copied over 1:1 as if it were an image.

+1 for a PR to add JS, JSX, TS, and TSX here to this function AND add a curated JSX found, add this plugin to support error message like we have for Vue and Svelte.

).rejects.toThrowError(`Install failed.`);
// TODO:
// Assert the reason: Failed to load ../../../node_modules/simple-svelte-autocomplete/src/SimpleAutocomplete.svelte
// Try installing rollup-plugin-svelte and adding it to Snowpack (https://www.snowpack.dev/#custom-rollup-plugins)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏻

Should we add the reason in this PR? Or does that require a bigger change?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I could have made this more clear: that is currently what running esinstall will log, but it does so in a separate console.error call instead of the actual throw error. This is that issue i'd mentioned at standup today.

I think my vote would be to add these currently-console-error'd messages as a error.reason property, but we can tackle in a future PR

@FredKSchott FredKSchott merged commit 6ef4a1d into main Dec 11, 2020
@FredKSchott FredKSchott deleted the svelte-plugin-esinstall-fix branch December 11, 2020 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants