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

Enable Windows tests #1712

Merged
merged 1 commit into from
Nov 2, 2021
Merged

Enable Windows tests #1712

merged 1 commit into from
Nov 2, 2021

Conversation

drwpow
Copy link
Member

@drwpow drwpow commented Oct 29, 2021

Changes

Enables Windows tests, fixes Windows bugs.

Current status: dev is passing in Windows! 🎉 But build seems to still have an error. So the problem is halfway solved; it just seems like there’s an extra step in build that’s failing.

Testing

Tests should pass!

Vite-wise, Vite currently doesn’t have any tests for these code paths. We could look into adding them, but it’d be tough to do without adding new compile-to-HTML examples. Will look into it after this is passing.

Docs

No docs needed

@drwpow drwpow requested a review from a team as a code owner October 29, 2021 22:58
@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2021

⚠️ No Changeset found

Latest commit: f0c3d97

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@drwpow drwpow mentioned this pull request Oct 29, 2021
@drwpow drwpow force-pushed the windows-tests-2 branch 2 times, most recently from 58f7c4b to c9de0f7 Compare October 29, 2021 23:13
@drwpow drwpow changed the title Enable Windows tests [wip] Enable Windows tests Oct 29, 2021
"yellow": [255, 255, 0],
"yellowgreen": [154, 205, 50]
var colorName$1 = {
"aliceblue": [240, 248, 255],
Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea what my editor did here. Ignore the noise in this file.

@@ -46,7 +46,8 @@ export default function astro({ config, devServer }: AstroPluginOptions): vite.P
}
// pages and layouts should be transformed as full documents (implicit <head> <body> etc)
// everything else is treated as a fragment
const isPage = id.startsWith(fileURLToPath(config.pages)) || id.startsWith(fileURLToPath(config.layouts));
const normalizedID = fileURLToPath(new URL(`file:https://${id}`));
const isPage = normalizedID.startsWith(fileURLToPath(config.pages)) || id.startsWith(fileURLToPath(config.layouts));
Copy link
Member Author

Choose a reason for hiding this comment

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

Plugin change: id was a Windows path that didn’t match up to fileURLToPath(), so basically everything in Windows was being treated as a partial.

@@ -79,7 +79,8 @@ export async function ssr({ astroConfig, filePath, logging, mode, origin, pathna
// Important: This needs to happen first, in case a renderer provides polyfills.
const renderers = await resolveRenderers(viteServer, astroConfig);
// Load the module from the Vite SSR Runtime.
const mod = (await viteServer.ssrLoadModule(fileURLToPath(filePath))) as ComponentInstance;
const viteFriendlyURL = `/@fs${filePath.pathname}`;
const mod = (await viteServer.ssrLoadModule(viteFriendlyURL)) as ComponentInstance;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit of a hack, but it turns out Vite uses these URLs internally for Windows. TIL that this doesn’t necessarily have to be a “correct” path on disk; just a URL that Vite understands.

@drwpow drwpow force-pushed the windows-tests-2 branch 7 times, most recently from 569ab2d to 3ecd797 Compare November 2, 2021 01:45
@@ -142,7 +142,11 @@ class AstroBuilder {
target: 'es2020', // must match an esbuild target
},
plugins: [
rollupPluginHTML({ input, extractAssets: false }) as any, // "any" needed for CI; also we don’t need typedefs for this anyway
rollupPluginHTML({
rootDir: viteConfig.root,
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the other fix: @web/rollup-plugin-html needs rootDir for Windows. Otherwise it tries to guess (which for some reason works on unix but fails miserably on Windows).

@@ -21319,7 +21319,7 @@ function buildHtmlPlugin(config) {
.map((child) => child.content || '')
.join('');
// <script type="module">...</script>
const filePath = id.replace(config.root, '');
const filePath = id.replace(normalizePath$4(config.root), '')
Copy link
Member Author

Choose a reason for hiding this comment

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

Vite fix 1/2: normalize config.root

@@ -56977,14 +56976,14 @@ const devHtmlHook = async (html, { path: htmlPath, server, originalUrl }) => {
processNodeUrl(src, s, config, htmlPath, originalUrl);
}
else if (isModule) {
const url = filePath.replace(config.root, '');
const url = filePath.replace(normalizePath$4(config.root), '');
Copy link
Member Author

Choose a reason for hiding this comment

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

Vite fix 2/2: normalize root, and also use the full filePath below

@@ -21179,7 +21179,7 @@ function htmlInlineScriptProxyPlugin(config) {
if (proxyMatch) {
const index = Number(proxyMatch[1]);
const file = cleanUrl(id);
const url = file.replace(config.root, '');
const url = file.replace(normalizePath$4(config.root), '');
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a 3rd Vite fix that technically wasn’t needed for our fix, but I’m almost positive is needed elsewhere and can’t hurt because it’s the same action.

Copy link
Member

@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!

meta process review comment: this is now the second PR that has made changes to vendor/vite. Just confirming: are we maintaining our vite fork somewhere and tracking these upstream changes so that we don't lose them? If not, can you start with this PR?

@matthewp
Copy link
Contributor

matthewp commented Nov 2, 2021

lgtm, awesome work.

@drwpow drwpow changed the title [wip] Enable Windows tests Enable Windows tests Nov 2, 2021
@drwpow
Copy link
Member Author

drwpow commented Nov 2, 2021

are we maintaining our vite fork somewhere and tracking these upstream changes so that we don't lose them? If not, can you start with this PR?

Yup! Keeping track of these. We’re back down to this being our only change from Vite and I’ll open that PR on their end soon

@drwpow drwpow merged commit c0d9ed8 into main Nov 2, 2021
@drwpow drwpow deleted the windows-tests-2 branch November 2, 2021 14:13
@drwpow drwpow mentioned this pull request Nov 4, 2021
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
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