Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide page runtime parsing utils (#34922)
* parse runtime config * add test * fix typing * fix lint warning * change branch purging condition * dont fallback to global runtime
- Loading branch information
Showing
12 changed files
with
147 additions
and
32 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
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,7 @@ | ||
export function isWasm(): Promise<boolean> | ||
export function transform(src: string, options?: any): Promise<any> | ||
export function transformSync(src: string, options?: any): any | ||
export function minify(src: string, options: any): Promise<string> | ||
export function minifySync(src: string, options: any): string | ||
export function bundle(options: any): Promise<any> | ||
export function parse(src: string, options: any): any |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function getParserOptions(options: { | ||
filename: string | ||
jsConfig?: any | ||
[key: string]: any | ||
}): any | ||
export function getJestSWCOptions(...args: any[]): any | ||
export function getLoaderSWCOptions(...args: any[]): any |
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
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 |
---|---|---|
|
@@ -19,3 +19,7 @@ export default function Index() { | |
</div> | ||
) | ||
} | ||
|
||
export const config = { | ||
runtime: 'edge', | ||
} |
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,8 @@ | ||
export default function Edge() { | ||
return 'edge' | ||
} | ||
|
||
export const config = { | ||
runtime: 'edge', | ||
amp: false, | ||
} |
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,8 @@ | ||
export default function Nodejs() { | ||
return 'nodejs' | ||
} | ||
|
||
export const config = { | ||
amp: false, | ||
runtime: 'nodejs', | ||
} |
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,3 @@ | ||
export default function Static() { | ||
return 'static' | ||
} |
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,27 @@ | ||
import { getPageRuntime } from 'next/dist/build/entries' | ||
import { join } from 'path' | ||
|
||
const fixtureDir = join(__dirname, 'fixtures') | ||
|
||
describe('parse page runtime config', () => { | ||
it('should parse nodejs runtime correctly', async () => { | ||
const runtime = await getPageRuntime( | ||
join(fixtureDir, 'page-runtime/nodejs.js') | ||
) | ||
expect(runtime).toBe('nodejs') | ||
}) | ||
|
||
it('should parse edge runtime correctly', async () => { | ||
const runtime = await getPageRuntime( | ||
join(fixtureDir, 'page-runtime/edge.js') | ||
) | ||
expect(runtime).toBe('edge') | ||
}) | ||
|
||
it('should return undefined if no runtime is specified', async () => { | ||
const runtime = await getPageRuntime( | ||
join(fixtureDir, 'page-runtime/static.js') | ||
) | ||
expect(runtime).toBe(undefined) | ||
}) | ||
}) |