diff options
author | 2022-11-04 21:09:55 +0800 | |
---|---|---|
committer | 2022-11-04 09:09:55 -0400 | |
commit | 247eb7411f429317e5cd7d401a6660ee73641313 (patch) | |
tree | b7274d139e279e612c6117dedd6801afad6c963c | |
parent | f20ff17aa37619b70257f3ef6453bfe22f4276b0 (diff) | |
download | astro-247eb7411f429317e5cd7d401a6660ee73641313.tar.gz astro-247eb7411f429317e5cd7d401a6660ee73641313.tar.zst astro-247eb7411f429317e5cd7d401a6660ee73641313.zip |
fix: fix bug #5267 (#5298)
* fix: fix bug #5267
* fix: add changeset
* fix: on frozen lockfile
Co-authored-by: wuls <linsheng.wu@beantechs.com>
-rw-r--r-- | .changeset/two-ties-tap.md | 5 | ||||
-rw-r--r-- | examples/minimal/astro.config.mjs | 5 | ||||
-rw-r--r-- | packages/astro/src/vite-plugin-astro/index.ts | 2 | ||||
-rw-r--r-- | packages/astro/test/fixtures/root-srcdir-css/astro.config.mjs | 7 | ||||
-rw-r--r-- | packages/astro/test/fixtures/root-srcdir-css/package.json | 8 | ||||
-rw-r--r-- | packages/astro/test/fixtures/root-srcdir-css/pages/index.astro | 12 | ||||
-rw-r--r-- | packages/astro/test/root-srcdir-css.test.js | 24 | ||||
-rw-r--r-- | pnpm-lock.yaml | 6 |
8 files changed, 67 insertions, 2 deletions
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 @@ +--- +--- +<html> +<head> + <style> + body { color: green; } + </style> +</head> +<body> + <h1>when the srcDir is root</h1> +</body> +</html> 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:* |