diff --git a/.changeset/two-ties-tap.md b/.changeset/two-ties-tap.md new file mode 100644 index 000000000..15ccf7287 --- /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 882e6515a..48d20ba67 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 40f89be7c..fd9b1805d 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 000000000..48d20ba67 --- /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 000000000..15f2f8943 --- /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 000000000..630adcf06 --- /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 000000000..ae3671788 --- /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 42aec0e4c..39f0200b7 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:*