(
esbuild: any,
entryFileName: string,
files: {[path: string]: string},
importMap: {[specifier: string]: string},
baseUrl: string,
)
| 143 | }; |
| 144 | |
| 145 | const getBundle = async ( |
| 146 | esbuild: any, |
| 147 | entryFileName: string, |
| 148 | files: {[path: string]: string}, |
| 149 | importMap: {[specifier: string]: string}, |
| 150 | baseUrl: string, |
| 151 | ): Promise<string> => |
| 152 | ( |
| 153 | ( |
| 154 | await esbuild.build({ |
| 155 | bundle: true, |
| 156 | format: 'esm', |
| 157 | jsx: 'automatic', |
| 158 | minify: false, |
| 159 | platform: 'browser', |
| 160 | target: 'esnext', |
| 161 | write: false, |
| 162 | stdin: { |
| 163 | contents: files[entryFileName] ?? '', |
| 164 | loader: 'js', |
| 165 | resolveDir: posix.dirname('/demo/' + entryFileName), |
| 166 | sourcefile: '/demo/' + entryFileName, |
| 167 | }, |
| 168 | plugins: [ |
| 169 | { |
| 170 | name: 'demo-files', |
| 171 | setup: (build: any) => { |
| 172 | build.onResolve({filter: /.*/}, (args: any) => { |
| 173 | if (args.path.startsWith('./') || args.path.startsWith('../')) { |
| 174 | return { |
| 175 | namespace: 'demo-files', |
| 176 | path: posix.normalize( |
| 177 | posix.join(args.resolveDir, args.path), |
| 178 | ), |
| 179 | }; |
| 180 | } |
| 181 | if (args.path.startsWith('/demo/')) { |
| 182 | return {namespace: 'demo-files', path: args.path}; |
| 183 | } |
| 184 | const mapped = getMappedImportUrl( |
| 185 | args.path, |
| 186 | importMap, |
| 187 | baseUrl, |
| 188 | ); |
| 189 | return mapped == null |
| 190 | ? undefined |
| 191 | : {external: true, path: mapped}; |
| 192 | }); |
| 193 | build.onLoad( |
| 194 | {filter: /.*/, namespace: 'demo-files'}, |
| 195 | (args: any) => { |
| 196 | const path = args.path.replace(/^\/demo\//, ''); |
| 197 | const contents = files[path]; |
| 198 | if (contents == null) { |
| 199 | throw new Error(`Missing file: ${path}`); |
| 200 | } |
| 201 | return { |
| 202 | contents, |
no test coverage detected
searching dependent graphs…