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 for hoisted scripts in project with spaces in the file path #5756

Merged
merged 3 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-planes-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix for hoisted scripts in project with spaces in the file path
4 changes: 3 additions & 1 deletion packages/astro/src/vite-plugin-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
appendForwardSlash,
removeLeadingForwardSlashWindows,
} from '../core/path.js';
import { viteID } from '../core/util.js';

/**
* Converts the first dot in `import.meta.env` to its Unicode escape sequence,
Expand Down Expand Up @@ -47,7 +48,8 @@ export function normalizeFilename(filename: string, config: AstroConfig) {
if (filename.startsWith('/@fs')) {
filename = filename.slice('/@fs'.length);
} else if (filename.startsWith('/') && !ancestor(filename, config.root.pathname)) {
filename = new URL('.' + filename, config.root).pathname;
const url = new URL('.' + filename, config.root);
filename = viteID(url);
}
return removeLeadingForwardSlashWindows(filename);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/space-in-folder-name",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>
<title>Project with spaces in the folder name</title>
</head>
<body>
<h1>Testing</h1>
<script>
console.log('hi');
</script>
</body>
</html>
33 changes: 33 additions & 0 deletions packages/astro/test/space-in-folder-name.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

describe('Projects with a space in the folder name', () => {
let fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/space in folder name/app/',
});
});

describe('dev', () => {
/** @type {import('./test-utils').Fixture} */
let devServer;

before(async () => {
devServer = await fixture.startDevServer();
});

after(async () => {
await devServer.stop();
});

it('Work with hoisted scripts', async () => {
const html = await fixture.fetch('/').then(r => r.text());
const $ = cheerio.load(html);

expect($('script[src*="space in folder name"]')).to.have.a.lengthOf(1);
});
});
});
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.