( esbuild: any, executables: ResolvedExecutables, baseUrl: string, )
| 215 | .trim(); |
| 216 | |
| 217 | const getDemoDoc = async ( |
| 218 | esbuild: any, |
| 219 | executables: ResolvedExecutables, |
| 220 | baseUrl: string, |
| 221 | ): Promise<string> => { |
| 222 | const {files, html, less, tsx} = executables; |
| 223 | const importMap = getImportMap(html); |
| 224 | const react = |
| 225 | importMap.react != null || |
| 226 | importMap['react-dom/client'] != null || |
| 227 | importMap['react/jsx-runtime'] != null; |
| 228 | const solid = |
| 229 | importMap['solid-js'] != null || importMap['solid-js/web'] != null; |
| 230 | const allFiles = { |
| 231 | ...files, |
| 232 | ...(tsx == '' || Object.keys(files).some((path) => JS_FILE_REGEX.test(path)) |
| 233 | ? {} |
| 234 | : {[react || solid ? 'src/main.jsx' : 'src/main.js']: tsx}), |
| 235 | }; |
| 236 | const entryFileName = getEntryFileName(allFiles); |
| 237 | let extraCss = less == '' ? '' : getCss(less); |
| 238 | const moduleFiles: {[path: string]: string} = {}; |
| 239 | |
| 240 | Object.entries(allFiles).forEach(([path, source]) => { |
| 241 | if (STYLE_FILE_REGEX.test(path)) { |
| 242 | extraCss += path.endsWith('.css') ? source : getCss(source); |
| 243 | return; |
| 244 | } |
| 245 | if (SVELTE_FILE_REGEX.test(path)) { |
| 246 | const compiled = compile(source, {filename: path, generate: 'client'}); |
| 247 | extraCss += compiled.css?.code ?? ''; |
| 248 | moduleFiles[path] = compiled.js.code; |
| 249 | return; |
| 250 | } |
| 251 | if (JS_FILE_REGEX.test(path)) { |
| 252 | moduleFiles[path] = getJs(esbuild, path, source, solid); |
| 253 | } |
| 254 | }); |
| 255 | |
| 256 | const js = await getBundle( |
| 257 | esbuild, |
| 258 | entryFileName, |
| 259 | moduleFiles, |
| 260 | importMap, |
| 261 | baseUrl, |
| 262 | ); |
| 263 | |
| 264 | return getHtmlDoc(` |
| 265 | <html> |
| 266 | <head> |
| 267 | ${ |
| 268 | html |
| 269 | .match(SCRIPTS_REGEX) |
| 270 | ?.filter( |
| 271 | (script) => !/<script\b[^>]*type=["']importmap["']/.test(script), |
| 272 | ) |
| 273 | .join('') |
| 274 | ?.trim() ?? '' |
no test coverage detected
searching dependent graphs…