-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: function entry matcher utility * test: function entry matcher * chore: changeset * chore: prefer forEach over test.each * chore: clearer parameter names
- Loading branch information
1 parent
2b97f9d
commit c6c8818
Showing
6 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@cloudflare/next-on-pages": patch | ||
--- | ||
|
||
Handle route handler function entries. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { normalizePath } from "./paths"; | ||
export { normalizePath } from './paths'; | ||
export { matchFunctionEntry } from './transform'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { matchFunctionEntry } from './manifest'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Check if a function file name matches an entry in the manifest. | ||
* | ||
* @param entryName Manifest entry name. | ||
* @param fileName Function file name. | ||
* @returns Whether the function file name matches the manifest entry name. | ||
*/ | ||
export const matchFunctionEntry = (entryName: string, fileName: string) => { | ||
// app directory | ||
if (entryName.startsWith('app/')) { | ||
const type = entryName.endsWith('/route') ? '/route' : '/page'; | ||
return ( | ||
`app${fileName !== 'index' ? `/${fileName}` : ''}${type}` === entryName | ||
); | ||
} | ||
|
||
// pages directory | ||
return entryName.startsWith('pages/') && `pages/${fileName}` === entryName; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { describe, test, expect, suite } from 'vitest'; | ||
import { matchFunctionEntry } from '../src/utils'; | ||
|
||
const manifestEntries = [ | ||
{ name: 'app dir - normal page', entry: 'app/test/page', file: 'test' }, | ||
{ name: 'app dir - dynamic page', entry: 'app/[id]/page', file: '[id]' }, | ||
{ name: 'app dir - nested page', entry: 'app/1/2/3/page', file: '1/2/3' }, | ||
{ name: 'app dir - index page', entry: 'app/page', file: 'index' }, | ||
{ name: 'app dir - route handler', entry: 'app/test/route', file: 'test' }, | ||
{ name: 'pages dir - page', entry: 'pages/api/hello', file: 'api/hello' }, | ||
]; | ||
|
||
suite('manifest utils', () => { | ||
describe('match function entries', () => { | ||
manifestEntries.forEach(({ name, entry, file }) => { | ||
test(name, () => { | ||
expect(matchFunctionEntry(entry, file)).toEqual(true); | ||
}); | ||
}); | ||
}); | ||
}); |