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 import resolution logic #519

Merged
merged 1 commit into from
Jun 19, 2020
Merged

Conversation

FredKSchott
Copy link
Owner

Resolves #439, Resolves #443

This PR improves our ability to resolve a partial import (like src/components or src/components/index to import src/components/index.js). It solves a couple of bugs that users had been reporting, where behavior didn't match Node or Webpack's resolution logic (see resolved issues above).

@FredKSchott FredKSchott requested a review from drwpow June 19, 2020 15:36
@FredKSchott FredKSchott requested a review from a team as a code owner June 19, 2020 15:36
@vercel
Copy link

vercel bot commented Jun 19, 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/83srn5l89
✅ Preview: https://snowpack-git-improve-resolve-logic.pikapkg.vercel.app

const resolvedUrl = path.resolve(path.dirname(outPath), spec);
allProxiedFiles.add(resolvedUrl);
allProxiedFiles.add(
resolvedImportUrl.startsWith('/')
Copy link
Owner Author

Choose a reason for hiding this comment

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

bug fix: we weren't resolving /_dist_/ URLs properly, since they get handled as absolute paths by path.resolve

Copy link
Collaborator

Choose a reason for hiding this comment

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

👏

import srcFileExtensionMapping from './src-file-extension-mapping';

const cwd = process.cwd();
Copy link
Owner Author

Choose a reason for hiding this comment

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

how do you feel about adding cwd to the config object? We do this in a few different places around the codebase, but it would be good to start moving towards a configurable cwd.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that’s a great idea.

styleEl.type = 'text/css';

styleEl.appendChild(codeEl);
document.head.appendChild(styleEl);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes! This test will really come in handy for some upcoming work.

Copy link
Collaborator

@drwpow drwpow left a comment

Choose a reason for hiding this comment

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

Nice! This is looking pretty clean to me.

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.

Support importing JS files with multiple dots Folder imports not working with top-level imports
2 participants