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

fix: $env/*/private throws for client-side imports on Windows and Tailwind doesn't freak out #5739

Merged
merged 10 commits into from
Jul 29, 2022

Conversation

elliott-with-the-longest-name-on-github
Copy link
Contributor

Closes #5723 and closes #5747.

The paths for both Vite and Rollup's module graphs needed to be normalized, along with the illegal import paths.

Because Tailwind needs to analyze basically every file in your project, Vite thinks it imports all of them, meaning it'll almost always import $env/*/private, causing our helpful module analysis to be, well, unhelpful. In dev, we now ignore non-js|ts|svelte files. Rollup doesn't have this problem (because it doesn't have to worry about HMR), so we can be stricter and just analyze all imports. I think this strikes a happy medium. "Provide armor against footguns in dev, and provide even better armor when we try to go to prod."

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Jul 28, 2022

🦋 Changeset detected

Latest commit: 00fbfeb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dominikg
Copy link
Member

is it possible to use vite's normalizePath here? https://vitejs.dev/guide/api-plugin.html#path-normalization

@elliott-with-the-longest-name-on-github
Copy link
Contributor Author

I was hoping someone more knowledgeable would come along and make my day.

@benmccann
Copy link
Member

I'm surprised none of the browser tests failed on Windows. Maybe we need one that uses $env/*/private?

@elliott-with-the-longest-name-on-github
Copy link
Contributor Author

I'm surprised none of the browser tests failed on Windows. Maybe we need one that uses $env/*/private?

The problem is that these are buildtime/dev-time errors, meaning we'd need a test project dedicated to attempting to build and ensuring the build fails. There are a number of things that'd be useful for -- I'm happy to put an implementation together, but probably not for this PR?

@benmccann
Copy link
Member

I'm not sure you'd need anything too special or a separate test app. If you fail the build on one of the existing test apps it should turn the CI red

@elliott-with-the-longest-name-on-github
Copy link
Contributor Author

I'm not sure you'd need anything too special or a separate test app. If you fail the build on one of the existing test apps it should turn the CI red

Yes, but we're trying to verify that the build does fail, and the build needs to not fail in order for the rest of the tests to be able to run. Hence, the "metaproject" that tries to build purposefully-failing projects and verifies that they actually do fail.

@benmccann
Copy link
Member

Oh, right. Yeah, that'd be kind of a pain to test

@elliott-with-the-longest-name-on-github
Copy link
Contributor Author

Rich, there's another env var bug I want to work on tonight, but it might step on this one's toes. Easier to merge this one first, if you think it looks good.

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github changed the title fix: $env/*/private throws for client-side imports on Windows fix: $env/*/private throws for client-side imports on Windows and Tailwind doesn't freak out Jul 29, 2022
@elliott-with-the-longest-name-on-github
Copy link
Contributor Author

Heads up @Rich-Harris -- I went ahead and fixed the other bug in this PR as well. It was a pretty simple change.

@elliott-with-the-longest-name-on-github
Copy link
Contributor Author

Okay, once we see the green christmas tree list we should be GTM @Rich-Harris

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

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

we need a snake_case lint rule!

packages/kit/src/vite/utils.js Outdated Show resolved Hide resolved
packages/kit/src/vite/utils.js Outdated Show resolved Hide resolved
packages/kit/src/vite/utils.js Outdated Show resolved Hide resolved
packages/kit/src/vite/utils.js Outdated Show resolved Hide resolved
packages/kit/src/vite/utils.js Outdated Show resolved Hide resolved
packages/kit/src/vite/utils.js Outdated Show resolved Hide resolved
packages/kit/src/vite/utils.js Outdated Show resolved Hide resolved
packages/kit/src/vite/utils.js Outdated Show resolved Hide resolved
packages/kit/src/vite/utils.js Outdated Show resolved Hide resolved
packages/kit/src/vite/utils.js Outdated Show resolved Hide resolved
@Rich-Harris
Copy link
Member

actually i rescind my approval until i'm confident that the firefox tests are just flaking

@Rich-Harris Rich-Harris merged commit 05c6ad8 into master Jul 29, 2022
@Rich-Harris Rich-Harris deleted the sejohnson-fix-env-private-imports branch July 29, 2022 21:55
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.

new env handling seems to break tailwindcss $env/static/private can be imported in client modules
6 participants