diff options
-rw-r--r-- | .changeset/late-years-flow.md | 5 | ||||
-rw-r--r-- | packages/astro/src/vite-plugin-config-alias/index.ts | 5 | ||||
-rw-r--r-- | packages/astro/test/alias-tsconfig.test.js | 8 | ||||
-rw-r--r-- | packages/astro/test/fixtures/alias-tsconfig/src/components/Bar/index.astro | 1 | ||||
-rw-r--r-- | packages/astro/test/fixtures/alias-tsconfig/src/components/Baz.astro | 1 | ||||
-rw-r--r-- | packages/astro/test/fixtures/alias-tsconfig/src/more-styles/extra.css (renamed from packages/astro/test/fixtures/alias-tsconfig/src/styles/extra.css) | 0 | ||||
-rw-r--r-- | packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro | 4 | ||||
-rw-r--r-- | packages/astro/test/fixtures/alias-tsconfig/tsconfig.json | 18 |
8 files changed, 35 insertions, 7 deletions
diff --git a/.changeset/late-years-flow.md b/.changeset/late-years-flow.md new file mode 100644 index 000000000..576e7de05 --- /dev/null +++ b/.changeset/late-years-flow.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a bug that caused tsconfig path aliases to break if there was more than one wildcard pattern diff --git a/packages/astro/src/vite-plugin-config-alias/index.ts b/packages/astro/src/vite-plugin-config-alias/index.ts index 9b102c564..d30d806a6 100644 --- a/packages/astro/src/vite-plugin-config-alias/index.ts +++ b/packages/astro/src/vite-plugin-config-alias/index.ts @@ -33,10 +33,9 @@ const getConfigAlias = (settings: AstroSettings): Alias[] | null => { .join('')}$`, ); - /** Internal index used to calculate the matching id in a replacement. */ - let matchId = 0; - for (const value of values) { + /** Internal index used to calculate the matching id in a replacement. */ + let matchId = 0; /** String used to replace a matched path. */ const replacement = [...normalizePath(path.resolve(resolvedBaseUrl, value))] .map((segment) => (segment === '*' ? `$${++matchId}` : segment === '$' ? '$$' : segment)) diff --git a/packages/astro/test/alias-tsconfig.test.js b/packages/astro/test/alias-tsconfig.test.js index 958251dda..66ddc7bff 100644 --- a/packages/astro/test/alias-tsconfig.test.js +++ b/packages/astro/test/alias-tsconfig.test.js @@ -144,6 +144,14 @@ describe('Aliases with tsconfig.json', () => { assert.equal($('#alias').text(), 'foo'); }); + it('handles multiple replacements in one alias', async () => { + const html = await fixture.readFile('/index.html'); + const $ = cheerio.load(html); + + assert.equal($('#bar').text(), 'bar'); + assert.equal($('#baz').text(), 'baz'); + }); + it('works for import.meta.glob', async () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); diff --git a/packages/astro/test/fixtures/alias-tsconfig/src/components/Bar/index.astro b/packages/astro/test/fixtures/alias-tsconfig/src/components/Bar/index.astro new file mode 100644 index 000000000..bdddcfeec --- /dev/null +++ b/packages/astro/test/fixtures/alias-tsconfig/src/components/Bar/index.astro @@ -0,0 +1 @@ +<p id="bar">bar</p> diff --git a/packages/astro/test/fixtures/alias-tsconfig/src/components/Baz.astro b/packages/astro/test/fixtures/alias-tsconfig/src/components/Baz.astro new file mode 100644 index 000000000..9e891e88f --- /dev/null +++ b/packages/astro/test/fixtures/alias-tsconfig/src/components/Baz.astro @@ -0,0 +1 @@ +<p id="baz">baz</p> diff --git a/packages/astro/test/fixtures/alias-tsconfig/src/styles/extra.css b/packages/astro/test/fixtures/alias-tsconfig/src/more-styles/extra.css index 0b41276e8..0b41276e8 100644 --- a/packages/astro/test/fixtures/alias-tsconfig/src/styles/extra.css +++ b/packages/astro/test/fixtures/alias-tsconfig/src/more-styles/extra.css diff --git a/packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro b/packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro index e880d4844..565969346 100644 --- a/packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro +++ b/packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro @@ -4,6 +4,8 @@ import Client from '@components/Client.svelte' import '@styles/main.css'; import { namespace } from '@test/namespace-package' import Foo from 'src/components/Foo.astro'; +import Bar from "@short/Bar" +import Baz from "@short/Baz" import StyleComp from 'src/components/Style.astro'; import { foo, index } from 'src/utils/constants'; @@ -19,6 +21,8 @@ const globResult = Object.keys(import.meta.glob('@components/glob/*.js')).join(' <main> <Client client:load /> <Foo /> + <Bar /> + <Baz /> <StyleComp /> <Alias client:load /> <p id="namespace">{namespace}</p> diff --git a/packages/astro/test/fixtures/alias-tsconfig/tsconfig.json b/packages/astro/test/fixtures/alias-tsconfig/tsconfig.json index e4507cabb..31340063c 100644 --- a/packages/astro/test/fixtures/alias-tsconfig/tsconfig.json +++ b/packages/astro/test/fixtures/alias-tsconfig/tsconfig.json @@ -6,7 +6,12 @@ "src/components/*" ], "@styles/*": [ - "src/styles/*" + "src/styles/*", + "src/more-styles/*" + ], + "@short/*": [ + "src/components/*.astro", + "src/components/*/index.astro" ], // this can really trip up namespaced packages "@*": [ @@ -14,6 +19,11 @@ ] } }, - "include": [".astro/types.d.ts", "**/*"], - "exclude": ["dist"] -} + "include": [ + ".astro/types.d.ts", + "**/*" + ], + "exclude": [ + "dist" + ] +}
\ No newline at end of file |