From 247eb7411f429317e5cd7d401a6660ee73641313 Mon Sep 17 00:00:00 2001 From: wulinsheng123 <409187100@qq.com> Date: Fri, 4 Nov 2022 21:09:55 +0800 Subject: [PATCH] fix: fix bug #5267 (#5298) * fix: fix bug #5267 * fix: add changeset * fix: on frozen lockfile Co-authored-by: wuls --- .changeset/two-ties-tap.md | 5 ++++ examples/minimal/astro.config.mjs | 5 +++- packages/astro/src/vite-plugin-astro/index.ts | 2 +- .../fixtures/root-srcdir-css/astro.config.mjs | 7 ++++++ .../fixtures/root-srcdir-css/package.json | 8 +++++++ .../root-srcdir-css/pages/index.astro | 12 ++++++++++ packages/astro/test/root-srcdir-css.test.js | 24 +++++++++++++++++++ pnpm-lock.yaml | 6 +++++ 8 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 .changeset/two-ties-tap.md create mode 100644 packages/astro/test/fixtures/root-srcdir-css/astro.config.mjs create mode 100644 packages/astro/test/fixtures/root-srcdir-css/package.json create mode 100644 packages/astro/test/fixtures/root-srcdir-css/pages/index.astro create mode 100644 packages/astro/test/root-srcdir-css.test.js diff --git a/.changeset/two-ties-tap.md b/.changeset/two-ties-tap.md new file mode 100644 index 000000000000..15ccf728774d --- /dev/null +++ b/.changeset/two-ties-tap.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +have not founded style when srcDir was root diff --git a/examples/minimal/astro.config.mjs b/examples/minimal/astro.config.mjs index 882e6515a67e..48d20ba675e6 100644 --- a/examples/minimal/astro.config.mjs +++ b/examples/minimal/astro.config.mjs @@ -1,4 +1,7 @@ import { defineConfig } from 'astro/config'; // https://astro.build/config -export default defineConfig({}); +export default defineConfig({ + srcDir: '.', + root: '.' +}); diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index 40f89be7c30a..fd9b1805d314 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -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)))); diff --git a/packages/astro/test/fixtures/root-srcdir-css/astro.config.mjs b/packages/astro/test/fixtures/root-srcdir-css/astro.config.mjs new file mode 100644 index 000000000000..48d20ba675e6 --- /dev/null +++ b/packages/astro/test/fixtures/root-srcdir-css/astro.config.mjs @@ -0,0 +1,7 @@ +import { defineConfig } from 'astro/config'; + +// https://astro.build/config +export default defineConfig({ + srcDir: '.', + root: '.' +}); diff --git a/packages/astro/test/fixtures/root-srcdir-css/package.json b/packages/astro/test/fixtures/root-srcdir-css/package.json new file mode 100644 index 000000000000..15f2f89436d4 --- /dev/null +++ b/packages/astro/test/fixtures/root-srcdir-css/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/remote-css", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/root-srcdir-css/pages/index.astro b/packages/astro/test/fixtures/root-srcdir-css/pages/index.astro new file mode 100644 index 000000000000..630adcf06a96 --- /dev/null +++ b/packages/astro/test/fixtures/root-srcdir-css/pages/index.astro @@ -0,0 +1,12 @@ +--- +--- + + + + + +

when the srcDir is root

+ + diff --git a/packages/astro/test/root-srcdir-css.test.js b/packages/astro/test/root-srcdir-css.test.js new file mode 100644 index 000000000000..ae36717885f5 --- /dev/null +++ b/packages/astro/test/root-srcdir-css.test.js @@ -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}/); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 42aec0e4c65c..39f0200b700e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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:*