Skip to content

Commit

Permalink
fix: fix bug #5267 (#5298)
Browse files Browse the repository at this point in the history
* fix: fix bug #5267

* fix: add changeset

* fix: on frozen lockfile

Co-authored-by: wuls <[email protected]>
  • Loading branch information
JerryWu1234 and wuls authored Nov 4, 2022
1 parent f20ff17 commit 247eb74
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-ties-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

have not founded style when srcDir was root
5 changes: 4 additions & 1 deletion examples/minimal/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({});
export default defineConfig({
srcDir: '.',
root: '.'
});
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function astro({ settings, logging }: AstroPluginOptions): vite.P

// Variables for determining if an id starts with /src...
const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
const isBrowserPath = (path: string) => path.startsWith(srcRootWeb);
const isBrowserPath = (path: string) => path.startsWith(srcRootWeb) && srcRootWeb !== '/';
const isFullFilePath = (path: string) =>
path.startsWith(prependForwardSlash(slash(fileURLToPath(config.root))));

Expand Down
7 changes: 7 additions & 0 deletions packages/astro/test/fixtures/root-srcdir-css/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
srcDir: '.',
root: '.'
});
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/root-srcdir-css/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/remote-css",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
12 changes: 12 additions & 0 deletions packages/astro/test/fixtures/root-srcdir-css/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
---
<html>
<head>
<style>
body { color: green; }
</style>
</head>
<body>
<h1>when the srcDir is root</h1>
</body>
</html>
24 changes: 24 additions & 0 deletions packages/astro/test/root-srcdir-css.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

describe('srcDir', () => {
let fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/root-srcdir-css/',
});
await fixture.build();
});

it('when the srcDir is "." which parser style in index.astro', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);

const relPath = $('link').attr('href');
const css = await fixture.readFile(relPath);
console.log(css)
expect(css).to.match(/body{color:green}/);
});
});
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.

0 comments on commit 247eb74

Please sign in to comment.