Skip to content

Commit

Permalink
fix: aliases not flattened
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Jun 2, 2024
1 parent c48b294 commit 60aafa7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/client/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function resolveAlias(config: UserConfig): AliasOptions {
if (Array.isArray(config.resolve?.alias)) {
return [
...(config.resolve?.alias ?? []),
Object.entries(defaultAlias).map(([find, replacement]) => ({ find, replacement })),
...Object.entries(defaultAlias).map(([find, replacement]) => ({ find, replacement })),
]
}

Expand Down
15 changes: 15 additions & 0 deletions tests/client/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ test.group('Vite plugin', () => {
})
})

test('flatten existing aliases', async ({ assert }) => {
const plugin = adonisjs({ entrypoints: ['./resources/js/app.ts'] })[1] as Plugin

// @ts-ignore
const config = plugin!.config!(
{ resolve: { alias: [{ find: '@test/', replacement: '/test/' }] } },
{ command: 'build' }
)

assert.deepEqual(config.resolve.alias, [
{ find: '@test/', replacement: '/test/' },
{ find: '@/', replacement: '/resources/js/' },
])
})

test('user should be able to override the default alias', async ({ assert }) => {
const plugin = adonisjs({ entrypoints: ['./resources/js/app.ts'] })[1] as Plugin

Expand Down

0 comments on commit 60aafa7

Please sign in to comment.