Skip to content

Commit

Permalink
fix: rewrite rules when user defined rules are array
Browse files Browse the repository at this point in the history
  • Loading branch information
aiji42 committed Jul 4, 2021
1 parent f73360c commit 313f9f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
18 changes: 10 additions & 8 deletions src/merge-rewrites.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('mergeRewrites', () => {
})

describe('originalRewrite is array type rewrite', () => {
it('must return merged array rules', () => {
it('must return merged object type rules', () => {
expect(
mergeRewrites(
[
Expand All @@ -32,13 +32,15 @@ describe('mergeRewrites', () => {
],
newRewrites
)
).toEqual([
...newRewrites,
{
destination: '/foo/',
source: '/bar'
}
])
).toEqual({
beforeFiles: newRewrites,
afterFiles: [
{
destination: '/foo/',
source: '/bar'
}
]
})
})
})

Expand Down
9 changes: 5 additions & 4 deletions src/merge-rewrites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ export const mergeRewrites = (
if (!originalRules) return {
beforeFiles: newRules
}
if (Array.isArray(originalRules)) return [
...newRules,
...originalRules
]

if (Array.isArray(originalRules)) return {
beforeFiles: newRules,
afterFiles: originalRules
}

return {
...originalRules,
Expand Down

0 comments on commit 313f9f1

Please sign in to comment.