fix: fix bug #5267 (#5298)

* fix: fix bug #5267

* fix: add changeset

* fix: on frozen lockfile

Co-authored-by: wuls <linsheng.wu@beantechs.com>
This commit is contained in:
wulinsheng123 2022-11-04 21:09:55 +08:00 committed by GitHub
parent f20ff17aa3
commit 247eb7411f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
have not founded style when srcDir was root

View file

@ -1,4 +1,7 @@
import { defineConfig } from 'astro/config';
// https://astro.build/config
export default defineConfig({});
export default defineConfig({
srcDir: '.',
root: '.'
});

View file

@ -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))));

View file

@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
// https://astro.build/config
export default defineConfig({
srcDir: '.',
root: '.'
});

View file

@ -0,0 +1,8 @@
{
"name": "@test/remote-css",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,12 @@
---
---
<html>
<head>
<style>
body { color: green; }
</style>
</head>
<body>
<h1>when the srcDir is root</h1>
</body>
</html>

View file

@ -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}/);
});
});

View file

@ -2079,6 +2079,12 @@ importers:
dependencies:
astro: link:../../..
packages/astro/test/fixtures/root-srcdir-css:
specifiers:
astro: workspace:*
dependencies:
astro: link:../../..
packages/astro/test/fixtures/route-manifest:
specifiers:
astro: workspace:*