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

Recovers webpack magic comments and adds to import #1243

Merged
merged 1 commit into from
Oct 8, 2020

Conversation

N8-B
Copy link
Contributor

@N8-B N8-B commented Oct 7, 2020

This is my first contribution to snowpack. Please, let me know if there is anything missing from this PR. πŸ™‡β€β™‚οΈ

Changes

https://github.com/pikapkg/snowpack/blob/b21848be11041ad87656617b6b56a5084023e054/snowpack/src/rewrite-imports.ts#L36
matchDynamicImportValue strips the magic comments and the result spec is passed to the replaceImport handler.

The process begins in the buildFile method of the build command:
https://github.com/pikapkg/snowpack/blob/75ad50315d18d7d4deac0c6efc649b2b650282a8/snowpack/src/commands/build.ts#L195

This PR extracts Webpack's magic comments from dynamic imports before the spec is passed to matchDynamicImportValue. If a match is found for these types of comments, they are appended to the rewritten import.

Testing

All tests pass locally. The snapshot for build.test.js has been updated. Please, review this change as I am not sure if will affect snowpack's treeshaking logic.

Docs

No docs were added for this change.

Webpack's magic comments must be extracted from dynamic imports before the spec is passed to `matchDynamicImportValue`. If a match is found for these types of comments, they are appended to the rewritten import.
@N8-B N8-B requested a review from a team as a code owner October 7, 2020 19:40
@vercel
Copy link

vercel bot commented Oct 7, 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/emywb5bu6
βœ… Preview: https://snowpack-git-075cda18bc537298c5225072ba0c99d7b4d41ff3.pikapkg.vercel.app

Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for fixing!

@@ -602,7 +602,7 @@ import def, {
all/* , */,
} from '../web_modules/async.js';
console.log(def, waterfall, all);
import(\\"../web_modules/array-flatten.js\\")"
Copy link
Owner

Choose a reason for hiding this comment

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

I forgot we added this broken test case, way back when!

@FredKSchott FredKSchott merged commit 55fb2f7 into FredKSchott:master Oct 8, 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.

2 participants