File tree Expand file tree Collapse file tree 3 files changed +13
-16
lines changed
Expand file tree Collapse file tree 3 files changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -143,12 +143,11 @@ import { bundleFile } from 'subscript/util/bundle.js'
143143console .log (await bundleFile (' jessie.js' ))
144144
145145// Browser / custom sources
146- import { bundle , fromSources } from ' subscript/util/bundle.js'
147- const read = fromSources ( {
146+ import { bundle } from ' subscript/util/bundle.js'
147+ console . log ( await bundle ( ' main.js ' , {
148148 ' main.js' : ` import { x } from './lib.js'; export default x * 2` ,
149149 ' lib.js' : ` export const x = 21`
150- })
151- console .log (await bundle (' main.js' , read))
150+ }))
152151// → "const x = 21;\nexport { x as default }"
153152```
154153
Original file line number Diff line number Diff line change 9595
9696- [x] ~~ Warn Jessie on bad ASI~~ no complaints
9797
98- - [ ] Better error pointers
98+ - [x ] Better error pointers
9999
100100- [ ] Bundle itself instead of esbuild
101101
Original file line number Diff line number Diff line change @@ -292,9 +292,17 @@ const resolvePath = (from, to) => {
292292/**
293293 * Bundle ES modules into single file
294294 * @param {string } entry - Entry file path
295- * @param {(path: string) => string|Promise<string> } read - File reader
295+ * @param {Object|Function } read - Source map {path: code} or reader function
296296 */
297297export async function bundle ( entry , read ) {
298+ // Accept object as source map
299+ if ( typeof read === 'object' ) {
300+ const sources = read ;
301+ read = path => {
302+ if ( ! ( path in sources ) ) throw Error ( `Module not found: ${ path } ` ) ;
303+ return sources [ path ] ;
304+ } ;
305+ }
298306 const modules = new Map ( ) ;
299307 const order = [ ] ;
300308
@@ -485,16 +493,6 @@ export async function bundle(entry, read) {
485493 return result ;
486494}
487495
488- /**
489- * Create a read function from a map of path → source code
490- * @param {Object<string, string> } sources - Map of path to source code
491- * @returns {(path: string) => string }
492- */
493- export const fromSources = sources => path => {
494- if ( ! ( path in sources ) ) throw Error ( `Module not found: ${ path } ` ) ;
495- return sources [ path ] ;
496- } ;
497-
498496/**
499497 * Bundle with Node.js fs (only available in Node.js environment)
500498 * Dynamically imports fs/path to avoid browser errors
You can’t perform that action at this time.
0 commit comments