@@ -31,7 +31,7 @@ const merge = mergeOptions.bind({
3131 */
3232export const defaultOptions = {
3333 cwd : process . cwd ( ) ,
34- assets : '' ,
34+ assets : undefined ,
3535 browser : 'chromium' ,
3636 debug : false ,
3737 mode : 'main' , // worker
@@ -592,13 +592,21 @@ function getPort(port = 3000, host = '127.0.0.1') {
592592 *
593593 * @param {string } dir - Runner directory
594594 * @param {string } cwd - Current working directory
595- * @param {string } assets - Assets directory
595+ * @param {string[]| undefined } assets - Assets directories
596596 * @returns {Promise<{ url: string; server: import('http').Server }> }
597597 */
598598export async function createPolka ( dir , cwd , assets ) {
599599 const host = '127.0.0.1'
600600 const port = await getPort ( 0 , host )
601601 const url = `http://${ host } :${ port } /`
602+ if ( typeof assets === 'string' ) {
603+ assets = [ assets ]
604+ } else if ( assets === undefined || assets === null ) {
605+ assets = [ ]
606+ }
607+ if ( ! assets . includes ( cwd ) ) {
608+ assets . push ( cwd )
609+ }
602610 return new Promise ( ( resolve , reject ) => {
603611 const { server } = polka ( )
604612 . use (
@@ -618,22 +626,24 @@ export async function createPolka(dir, cwd, assets) {
618626 )
619627 . use (
620628 // @ts -ignore
621- sirv ( path . join ( cwd , assets ) , {
622- dev : true ,
623- setHeaders : (
624- /** @type {{ setHeader: (arg0: string, arg1: string) => void; } } */ rsp ,
625- /** @type {string } */ pathname
626- ) => {
627- // workaround for https://github.com/lukeed/sirv/issues/158 - we
628- // can't unset the `Content-Encoding` header because sirv sets it
629- // after this function is invoked and will only set it if it's not
630- // already set, so we need to set it to a garbage value that will be
631- // ignored by browsers
632- if ( pathname . endsWith ( '.gz' ) ) {
633- rsp . setHeader ( 'Content-Encoding' , 'unsupported-encoding' )
634- }
635- } ,
636- } )
629+ ...assets . map ( ( dir ) =>
630+ sirv ( dir , {
631+ dev : true ,
632+ setHeaders : (
633+ /** @type {{ setHeader: (arg0: string, arg1: string) => void; } } */ rsp ,
634+ /** @type {string } */ pathname
635+ ) => {
636+ // workaround for https://github.com/lukeed/sirv/issues/158 - we
637+ // can't unset the `Content-Encoding` header because sirv sets it
638+ // after this function is invoked and will only set it if it's not
639+ // already set, so we need to set it to a garbage value that will be
640+ // ignored by browsers
641+ if ( pathname . endsWith ( '.gz' ) ) {
642+ rsp . setHeader ( 'Content-Encoding' , 'unsupported-encoding' )
643+ }
644+ } ,
645+ } )
646+ )
637647 )
638648 . listen ( port , host , ( /** @type {Error } */ err ) => {
639649 if ( err ) {
0 commit comments