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

Ensure that the import resolver respects installOptions.externalPackage. #1070

Merged
merged 2 commits into from Sep 20, 2020

Conversation

pkaminski
Copy link
Contributor

@pkaminski pkaminski commented Sep 17, 2020

This makes the dev import resolver pass through any imported packages that are on the installOptions.externalPackage list. Fixes #1067.

Testing

I added a test to ensure that building respects external packages. The option also affects the output of dev mode but I'm not sure how to test that -- could you point me to an example?


This change is Reviewable

@vercel
Copy link

vercel bot commented Sep 17, 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/itj0r5ack
✅ Preview: https://snowpack-git-fork-pkaminski-import-resolver-externals.pikapkg.vercel.app

@@ -56,7 +56,7 @@ export function createImportResolver({
config,
}: ImportResolverOptions) {
return function importResolver(spec: string): string | false {
if (URL_HAS_PROTOCOL_REGEX.test(spec)) {
if (URL_HAS_PROTOCOL_REGEX.test(spec) || config.installOptions.externalPackage?.includes(spec)) {
Copy link
Owner

Choose a reason for hiding this comment

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

ha, this looks like an outdated version of what we use in build.ts. Can you replace both here and build.ts with:

// Ignore "http://*" imports
if (url.parse(spec).protocol) {
  return spec;
}

// Ignore packages marked as external
if (this.config.installOptions.externalPackage?.includes(spec)) {
    return spec;
}

It's definitely a little more verbose, but these functions are notoriously buggy so good documentation is important.

Copy link
Owner

Choose a reason for hiding this comment

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

Otherwise, LGTM!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, done!

@MoonBall
Copy link
Contributor

I feel that the added test doesn't cover your use case.
The added test will pass when I commented all your change in the pr.

@pkaminski
Copy link
Contributor Author

Hmm, you're right. I'm not sure what happened -- it was definitely failing when I first created the PR. I'll dig into it.

@pkaminski
Copy link
Contributor Author

So it turns out that while the build (and dev) log an error, the error is actually ignored and the build completes "successfully" making my test a no-op. Is there some way to test Snowpack's console output for errors? If not, I'm not sure how to make a test for this PR, since in the end it only affects non-fatal error output.

@FredKSchott
Copy link
Owner

I actually believe that this was fixed by #1072, I can't reproduce when rebasing off of master now that errors always propagate up to the build.

I'll merge onto master to confirm, if there is still an error here then it's in the test runner, and not this test itself

@FredKSchott FredKSchott merged commit 21610bc into FredKSchott:master Sep 20, 2020
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.

External packages should not ignore Node.js builtins (ex: 'fs')
3 participants