@@ -8,7 +8,6 @@ import type {
8
8
} from '@qiankunjs/shared' ;
9
9
import { Deferred , prepareDeferredQueue , QiankunError } from '@qiankunjs/shared' ;
10
10
import { createTagTransformStream } from './TagTransformStream' ;
11
- import { isUrlHasOwnProtocol } from './utils' ;
12
11
import WritableDOMStream from './writable-dom' ;
13
12
14
13
type HTMLEntry = string ;
@@ -42,10 +41,15 @@ const isDeferScript = (script: HTMLScriptElement): boolean => {
42
41
* @param container
43
42
* @param opts
44
43
*/
45
- export async function loadEntry < T > ( entry : Entry , container : HTMLElement , opts : LoaderOpts ) : Promise < T | void > {
44
+ export async function loadEntry < T > (
45
+ entry : Entry | { url : string ; res : Response } ,
46
+ container : HTMLElement ,
47
+ opts : LoaderOpts ,
48
+ ) : Promise < T | void > {
46
49
const { fetch, streamTransformer, sandbox, nodeTransformer } = opts ;
47
50
48
- const res = isUrlHasOwnProtocol ( entry ) ? await fetch ( entry ) : new Response ( entry , { status : 200 , statusText : 'OK' } ) ;
51
+ const entryUrl = typeof entry === 'string' ? entry : entry . url ;
52
+ const res = typeof entry === 'string' ? await fetch ( entry ) : entry . res ;
49
53
if ( res . body ) {
50
54
let foundEntryScript = false ;
51
55
const entryScriptLoadedDeferred = new Deferred < T | void > ( ) ;
@@ -120,7 +124,7 @@ export async function loadEntry<T>(entry: Entry, container: HTMLElement, opts: L
120
124
if ( isEntryScript ( script ) ) {
121
125
if ( foundEntryScript ) {
122
126
throw new QiankunError (
123
- `You should not set multiply entry script in one entry html, but ${ entry } has at least 2 entry scripts ` ,
127
+ `You should not include more than 1 entry scripts in a single HTML entry ${ entryUrl } ! ` ,
124
128
) ;
125
129
}
126
130
@@ -139,7 +143,7 @@ export async function loadEntry<T>(entry: Entry, container: HTMLElement, opts: L
139
143
} else {
140
144
entryScriptLoadedDeferred . reject (
141
145
new QiankunError (
142
- `entry ${ entry } load failed as entry script ${ script . dataset . src || script . src } load failed}` ,
146
+ `Entry ${ entryUrl } load failed as entry script ${ script . dataset . src || script . src } load failed}` ,
143
147
) ,
144
148
) ;
145
149
}
@@ -176,5 +180,5 @@ export async function loadEntry<T>(entry: Entry, container: HTMLElement, opts: L
176
180
return entryScriptLoadedDeferred . promise ;
177
181
}
178
182
179
- throw new QiankunError ( `entry ${ entry } response body is empty!` ) ;
183
+ throw new QiankunError ( `The response body of entry ${ entryUrl } is empty!` ) ;
180
184
}
0 commit comments