File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ const stdlib = require('node-stdlib-browser')
99const importPath = require ( './esbuild-import-path' )
1010const correctSet = require ( './esbuild-correct-set' )
1111const vendorSourceMap = require ( './esbuild-vendor-sourcemap' )
12+ const dirnameAndFilenameSupport = require ( './esbuild-dirname-and-filename' )
1213
1314const client = ( ) => {
1415 const make = async ( format ) => {
@@ -45,6 +46,7 @@ const client = () => {
4546 importPath ,
4647 correctSet ,
4748 vendorSourceMap ,
49+ dirnameAndFilenameSupport
4850 ] ,
4951 external : [ 'fontkit-next' ] ,
5052 } )
@@ -79,6 +81,7 @@ const node = () => {
7981 importPath ,
8082 correctSet ,
8183 vendorSourceMap ,
84+ dirnameAndFilenameSupport
8285 ] ,
8386 external : [ 'fontkit-next' , 'pdfkit' ] , // TODO: Remove external pdfkit
8487 } )
Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const path = require ( "path" ) ;
3+
4+ const nodeModules = new RegExp ( / ^ (?: .* [ \\ \/ ] ) ? n o d e _ m o d u l e s (?: [ \\ \/ ] .* ) ? $ / ) ;
5+
6+ module . exports = {
7+ name : "dirname" ,
8+ setup ( build ) {
9+ build . onLoad ( { filter : / .* / } , ( { path : filePath } ) => {
10+ if ( ! filePath . match ( nodeModules ) ) {
11+ let contents = fs . readFileSync ( filePath , "utf8" ) ;
12+ const loader = path . extname ( filePath ) . substring ( 1 ) ;
13+ const dirname = path . dirname ( filePath ) ;
14+ contents = contents
15+ . replace ( "__dirname" , `"${ dirname } "` )
16+ . replace ( "__filename" , `"${ filePath } "` ) ;
17+ return {
18+ contents,
19+ loader,
20+ } ;
21+ }
22+ } ) ;
23+ } ,
24+ } ;
You can’t perform that action at this time.
0 commit comments